Feature: Added option for hibernate between sleep and brightness down (#867) (closes #866)

Reviewed-on: https://codeberg.org/fairyglade/ly/pulls/867
Reviewed-by: AnErrupTion <anerruption@disroot.org>
Co-authored-by: ebits <tspamiitesh@gmail.com>
Co-committed-by: ebits <tspamiitesh@gmail.com>
This commit is contained in:
ebits
2025-11-28 19:05:17 +01:00
committed by AnErrupTion
parent 816be7449f
commit 1980b2e479
24 changed files with 78 additions and 1 deletions

View File

@@ -212,6 +212,12 @@ gameoflife_frame_delay = 6
# 0.7+ -> Dense, chaotic patterns # 0.7+ -> Dense, chaotic patterns
gameoflife_initial_density = 0.4 gameoflife_initial_density = 0.4
# Command executed when pressing hibernate key (can be null)
hibernate_cmd = null
# Specifies the key used for hibernate (F1-F12)
hibernate_key = F4
# Remove main box borders # Remove main box borders
hide_borders = false hide_borders = false

View File

@@ -42,6 +42,7 @@ err_perm_dir = فشل في تغيير المجلد الحالي
err_perm_group = فشل في تخفيض صلاحيات المجموعة (Group permissions) err_perm_group = فشل في تخفيض صلاحيات المجموعة (Group permissions)
err_perm_user = فشل في تخفيض صلاحيات المستخدم (User permissions) err_perm_user = فشل في تخفيض صلاحيات المستخدم (User permissions)
err_pwnam = فشل في جلب معلومات المستخدم err_pwnam = فشل في جلب معلومات المستخدم
err_sleep = فشل في تنفيذ أمر sleep err_sleep = فشل في تنفيذ أمر sleep
@@ -66,6 +67,7 @@ restart = اعادة التشغيل
shell = shell shell = shell
shutdown = ايقاف التشغيل shutdown = ايقاف التشغيل
sleep = وضع السكون sleep = وضع السكون
wayland = wayland wayland = wayland
x11 = x11 x11 = x11
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -47,6 +47,7 @@ err_pwnam = error en obtenir la informació de l'usuari
err_user_gid = error en establir el GID de l'usuari err_user_gid = error en establir el GID de l'usuari
err_user_init = error en inicialitzar usuari err_user_init = error en inicialitzar usuari
err_user_uid = error en establir l'UID de l'usuari err_user_uid = error en establir l'UID de l'usuari
@@ -66,6 +67,7 @@ restart = reiniciar
shell = shell shell = shell
shutdown = aturar shutdown = aturar
sleep = suspendre sleep = suspendre
wayland = wayland wayland = wayland
x11 = x11 x11 = x11
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -47,6 +47,7 @@ err_pwnam = nelze získat informace o uživateli
err_user_gid = nastavení GID uživatele selhalo err_user_gid = nastavení GID uživatele selhalo
err_user_init = inicializace uživatele selhala err_user_init = inicializace uživatele selhala
err_user_uid = nastavení UID uživateli selhalo err_user_uid = nastavení UID uživateli selhalo
@@ -66,6 +67,7 @@ restart = restartovat
shell = příkazový řádek shell = příkazový řádek
shutdown = vypnout shutdown = vypnout
wayland = wayland wayland = wayland
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -42,6 +42,7 @@ err_perm_dir = Ordnerwechsel fehlgeschlagen
err_perm_group = Fehler beim Heruntersetzen der Gruppenberechtigungen err_perm_group = Fehler beim Heruntersetzen der Gruppenberechtigungen
err_perm_user = Fehler beim Heruntersetzen der Nutzerberechtigungen err_perm_user = Fehler beim Heruntersetzen der Nutzerberechtigungen
err_pwnam = Abrufen der Benutzerinformationen fehlgeschlagen err_pwnam = Abrufen der Benutzerinformationen fehlgeschlagen
err_sleep = Sleep-Befehl fehlgeschlagen err_sleep = Sleep-Befehl fehlgeschlagen
@@ -66,6 +67,7 @@ restart = Neustarten
shell = Shell shell = Shell
shutdown = Herunterfahren shutdown = Herunterfahren
sleep = Sleep sleep = Sleep
wayland = wayland wayland = wayland
x11 = X11 x11 = X11
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -42,7 +42,8 @@ err_perm_dir = failed to change current directory
err_perm_group = failed to downgrade group permissions err_perm_group = failed to downgrade group permissions
err_perm_user = failed to downgrade user permissions err_perm_user = failed to downgrade user permissions
err_pwnam = failed to get user info err_pwnam = failed to get user info
err_sleep = failed to execute sleep command
err_battery = failed to load battery status err_battery = failed to load battery status
err_switch_tty = failed to switch tty err_switch_tty = failed to switch tty
err_tty_ctrl = tty control transfer failed err_tty_ctrl = tty control transfer failed
@@ -66,6 +67,7 @@ restart = reboot
shell = shell shell = shell
shutdown = shutdown shutdown = shutdown
sleep = sleep sleep = sleep
wayland = wayland wayland = wayland
x11 = x11 x11 = x11
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -47,6 +47,7 @@ err_pwnam = error al obtener la información del usuario
err_user_gid = error al establecer el GID del usuario err_user_gid = error al establecer el GID del usuario
err_user_init = error al inicializar usuario err_user_init = error al inicializar usuario
err_user_uid = error al establecer el UID del usuario err_user_uid = error al establecer el UID del usuario
@@ -66,6 +67,7 @@ restart = reiniciar
shell = shell shell = shell
shutdown = apagar shutdown = apagar
sleep = suspender sleep = suspender
wayland = wayland wayland = wayland
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -42,6 +42,7 @@ err_perm_dir = échec de changement de répertoire
err_perm_group = échec du déclassement des permissions de groupe err_perm_group = échec du déclassement des permissions de groupe
err_perm_user = échec du déclassement des permissions utilisateur err_perm_user = échec du déclassement des permissions utilisateur
err_pwnam = échec de lecture des infos utilisateur err_pwnam = échec de lecture des infos utilisateur
err_sleep = échec de l'exécution de la commande de veille err_sleep = échec de l'exécution de la commande de veille
err_battery = échec de lecture de l'état de la batterie err_battery = échec de lecture de l'état de la batterie
err_switch_tty = échec du changement de terminal err_switch_tty = échec du changement de terminal
@@ -66,6 +67,7 @@ restart = redémarrer
shell = shell shell = shell
shutdown = éteindre shutdown = éteindre
sleep = veille sleep = veille
wayland = wayland wayland = wayland
x11 = x11 x11 = x11
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -47,6 +47,7 @@ err_pwnam = impossibile ottenere dati utente
err_user_gid = impossibile impostare GID utente err_user_gid = impossibile impostare GID utente
err_user_init = impossibile inizializzare utente err_user_init = impossibile inizializzare utente
err_user_uid = impossible impostare UID utente err_user_uid = impossible impostare UID utente
@@ -66,6 +67,7 @@ restart = riavvio
shell = shell shell = shell
shutdown = arresto shutdown = arresto
wayland = wayland wayland = wayland
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -42,6 +42,7 @@ err_perm_dir = カレントディレクトリの変更に失敗しました
err_perm_group = グループ権限のダウングレードに失敗しました err_perm_group = グループ権限のダウングレードに失敗しました
err_perm_user = ユーザー権限のダウングレードに失敗しました err_perm_user = ユーザー権限のダウングレードに失敗しました
err_pwnam = ユーザー情報の取得に失敗しました err_pwnam = ユーザー情報の取得に失敗しました
err_sleep = スリープコマンドの実行に失敗しました err_sleep = スリープコマンドの実行に失敗しました
@@ -66,6 +67,7 @@ restart = 再起動
shell = シェル shell = シェル
shutdown = シャットダウン shutdown = シャットダウン
sleep = スリープ sleep = スリープ
wayland = Wayland wayland = Wayland
x11 = X11 x11 = X11
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -42,6 +42,7 @@ err_perm_dir = neizdevās mainīt pašreizējo mapi
err_perm_group = neizdevās pazemināt grupas atļaujas err_perm_group = neizdevās pazemināt grupas atļaujas
err_perm_user = neizdevās pazemināt lietotāja atļaujas err_perm_user = neizdevās pazemināt lietotāja atļaujas
err_pwnam = neizdevās iegūt lietotāja informāciju err_pwnam = neizdevās iegūt lietotāja informāciju
err_sleep = neizdevās izpildīt miega komandu err_sleep = neizdevās izpildīt miega komandu
err_battery = neizdevās ielādēt akumulatora stāvokli err_battery = neizdevās ielādēt akumulatora stāvokli
err_switch_tty = neizdevās pārslēgt tty err_switch_tty = neizdevās pārslēgt tty
@@ -66,6 +67,7 @@ restart = restartēt
shell = terminālis shell = terminālis
shutdown = izslēgt shutdown = izslēgt
sleep = snauda sleep = snauda
wayland = wayland wayland = wayland
x11 = x11 x11 = x11
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -42,6 +42,7 @@ err_perm_dir = nie udało się zmienić obecnego katalogu
err_perm_group = nie udało się obniżyć uprawnień grupy err_perm_group = nie udało się obniżyć uprawnień grupy
err_perm_user = nie udało się obniżyć uprawnień użytkownika err_perm_user = nie udało się obniżyć uprawnień użytkownika
err_pwnam = nie udało się uzyskać informacji o użytkowniku err_pwnam = nie udało się uzyskać informacji o użytkowniku
err_sleep = nie udało się wykonać polecenia sleep err_sleep = nie udało się wykonać polecenia sleep
err_battery = nie udało się sprawdzić statusu baterii err_battery = nie udało się sprawdzić statusu baterii
err_switch_tty = nie można przełączyć tty err_switch_tty = nie można przełączyć tty
@@ -66,6 +67,7 @@ restart = uruchom ponownie
shell = powłoka shell = powłoka
shutdown = wyłącz shutdown = wyłącz
sleep = uśpij sleep = uśpij
wayland = wayland wayland = wayland
x11 = x11 x11 = x11
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -47,6 +47,7 @@ err_pwnam = erro ao obter informação do utilizador
err_user_gid = erro ao definir o GID do utilizador err_user_gid = erro ao definir o GID do utilizador
err_user_init = erro ao iniciar o utilizador err_user_init = erro ao iniciar o utilizador
err_user_uid = erro ao definir o UID do utilizador err_user_uid = erro ao definir o UID do utilizador
@@ -66,6 +67,7 @@ restart = reiniciar
shell = shell shell = shell
shutdown = encerrar shutdown = encerrar
wayland = wayland wayland = wayland
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -47,6 +47,7 @@ err_pwnam = não foi possível obter informações do usuário
err_user_gid = não foi possível definir o GID do usuário err_user_gid = não foi possível definir o GID do usuário
err_user_init = não foi possível iniciar o usuário err_user_init = não foi possível iniciar o usuário
err_user_uid = não foi possível definir o UID do usuário err_user_uid = não foi possível definir o UID do usuário
@@ -66,6 +67,7 @@ restart = reiniciar
shell = shell shell = shell
shutdown = desligar shutdown = desligar
wayland = wayland wayland = wayland
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -55,6 +55,7 @@ err_perm_user = nu s-a putut face downgrade permisiunilor de utilizator
login = utilizator login = utilizator
logout = opreşte sesiunea logout = opreşte sesiunea
@@ -66,6 +67,7 @@ restart = resetează
shell = shell shell = shell
shutdown = opreşte sistemul shutdown = opreşte sistemul
wayland = wayland wayland = wayland
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -42,6 +42,7 @@ err_perm_dir = не удалось изменить текущий катало
err_perm_group = не удалось понизить права доступа группы err_perm_group = не удалось понизить права доступа группы
err_perm_user = не удалось понизить права доступа пользователя err_perm_user = не удалось понизить права доступа пользователя
err_pwnam = не удалось получить информацию о пользователе err_pwnam = не удалось получить информацию о пользователе
err_sleep = не удалось выполнить команду sleep err_sleep = не удалось выполнить команду sleep
err_battery = не удалось получить статус батареи err_battery = не удалось получить статус батареи
err_switch_tty = не удалось переключить tty err_switch_tty = не удалось переключить tty
@@ -66,6 +67,7 @@ restart = перезагрузить
shell = оболочка shell = оболочка
shutdown = выключить shutdown = выключить
sleep = сон sleep = сон
wayland = wayland wayland = wayland
x11 = x11 x11 = x11
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -47,6 +47,7 @@ err_pwnam = neuspijesno skupljanje informacija o korisniku
err_user_gid = neuspijesno postavljanje korisničkog GID-a err_user_gid = neuspijesno postavljanje korisničkog GID-a
err_user_init = neuspijensa inicijalizacija korisnika err_user_init = neuspijensa inicijalizacija korisnika
err_user_uid = neuspijesno postavljanje UID-a korisnika err_user_uid = neuspijesno postavljanje UID-a korisnika
@@ -66,6 +67,7 @@ restart = ponovo pokreni
shell = shell shell = shell
shutdown = ugasi shutdown = ugasi
wayland = wayland wayland = wayland
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -47,6 +47,7 @@ err_pwnam = misslyckades att hämta användarinfo
err_user_gid = misslyckades att ställa in användar-GID err_user_gid = misslyckades att ställa in användar-GID
err_user_init = misslyckades att initialisera användaren err_user_init = misslyckades att initialisera användaren
err_user_uid = misslyckades att ställa in användar-UID err_user_uid = misslyckades att ställa in användar-UID
@@ -66,6 +67,7 @@ restart = starta om
shell = skal shell = skal
shutdown = stäng av shutdown = stäng av
wayland = wayland wayland = wayland
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -47,6 +47,7 @@ err_pwnam = kullanici bilgileri alinamadi
err_user_gid = kullanici icin GID ayarlanamadi err_user_gid = kullanici icin GID ayarlanamadi
err_user_init = kullanici oturumu baslatilamadi err_user_init = kullanici oturumu baslatilamadi
err_user_uid = kullanici icin UID ayarlanamadi err_user_uid = kullanici icin UID ayarlanamadi
@@ -66,6 +67,7 @@ restart = yeniden baslat
shell = shell shell = shell
shutdown = makineyi kapat shutdown = makineyi kapat
wayland = wayland wayland = wayland
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -47,6 +47,7 @@ err_pwnam = не вдалося отримати дані користувача
err_user_gid = не вдалося змінити GID користувача err_user_gid = не вдалося змінити GID користувача
err_user_init = не вдалося ініціалізувати користувача err_user_init = не вдалося ініціалізувати користувача
err_user_uid = не вдалося змінити UID користувача err_user_uid = не вдалося змінити UID користувача
@@ -66,6 +67,7 @@ restart = перезавантажити
shell = оболонка shell = оболонка
shutdown = вимкнути shutdown = вимкнути
wayland = wayland wayland = wayland
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -47,6 +47,7 @@ err_pwnam = 获取用户信息失败
err_user_gid = 设置用户GID失败 err_user_gid = 设置用户GID失败
err_user_init = 初始化用户失败 err_user_init = 初始化用户失败
err_user_uid = 设置用户UID失败 err_user_uid = 设置用户UID失败
@@ -66,6 +67,7 @@ password = 密码
shell = shell shell = shell
wayland = wayland wayland = wayland
x11 = x11 x11 = x11
xinitrc = xinitrc xinitrc = xinitrc

View File

@@ -51,6 +51,8 @@ gameoflife_fg: u32 = 0x0000FF00,
gameoflife_entropy_interval: usize = 10, gameoflife_entropy_interval: usize = 10,
gameoflife_frame_delay: usize = 6, gameoflife_frame_delay: usize = 6,
gameoflife_initial_density: f32 = 0.4, gameoflife_initial_density: f32 = 0.4,
hibernate_cmd: ?[]const u8 = null,
hibernate_key: []const u8 = "F4",
hide_borders: bool = false, hide_borders: bool = false,
hide_key_hints: bool = false, hide_key_hints: bool = false,
hide_keyboard_locks: bool = false, hide_keyboard_locks: bool = false,

View File

@@ -20,6 +20,7 @@ err_domain: []const u8 = "invalid domain",
err_empty_password: []const u8 = "empty password not allowed", err_empty_password: []const u8 = "empty password not allowed",
err_envlist: []const u8 = "failed to get envlist", err_envlist: []const u8 = "failed to get envlist",
err_get_active_tty: []const u8 = "failed to get active tty", err_get_active_tty: []const u8 = "failed to get active tty",
err_hibernate: []const u8 = "failed to execute hibernate command",
err_hostname: []const u8 = "failed to get hostname", err_hostname: []const u8 = "failed to get hostname",
err_lock_state: []const u8 = "failed to get lock state", err_lock_state: []const u8 = "failed to get lock state",
err_log: []const u8 = "failed to open log file", err_log: []const u8 = "failed to open log file",
@@ -59,6 +60,7 @@ err_xauth: []const u8 = "xauth command failed",
err_xcb_conn: []const u8 = "xcb connection failed", err_xcb_conn: []const u8 = "xcb connection failed",
err_xsessions_dir: []const u8 = "failed to find sessions folder", err_xsessions_dir: []const u8 = "failed to find sessions folder",
err_xsessions_open: []const u8 = "failed to open sessions folder", err_xsessions_open: []const u8 = "failed to open sessions folder",
hibernate: []const u8 = "hibernate",
insert: []const u8 = "insert", insert: []const u8 = "insert",
login: []const u8 = "login", login: []const u8 = "login",
logout: []const u8 = "logged out", logout: []const u8 = "logged out",

View File

@@ -540,6 +540,8 @@ pub fn main() !void {
const restart_len = try TerminalBuffer.strWidth(lang.restart); const restart_len = try TerminalBuffer.strWidth(lang.restart);
const sleep_key = try std.fmt.parseInt(u8, config.sleep_key[1..], 10); const sleep_key = try std.fmt.parseInt(u8, config.sleep_key[1..], 10);
const sleep_len = try TerminalBuffer.strWidth(lang.sleep); const sleep_len = try TerminalBuffer.strWidth(lang.sleep);
const hibernate_key = try std.fmt.parseInt(u8, config.hibernate_key[1..], 10);
const hibernate_len = try TerminalBuffer.strWidth(lang.hibernate);
const brightness_down_key = if (config.brightness_down_key) |key| try std.fmt.parseInt(u8, key[1..], 10) else null; const brightness_down_key = if (config.brightness_down_key) |key| try std.fmt.parseInt(u8, key[1..], 10) else null;
const brightness_down_len = try TerminalBuffer.strWidth(lang.brightness_down); const brightness_down_len = try TerminalBuffer.strWidth(lang.brightness_down);
const brightness_up_key = if (config.brightness_up_key) |key| try std.fmt.parseInt(u8, key[1..], 10) else null; const brightness_up_key = if (config.brightness_up_key) |key| try std.fmt.parseInt(u8, key[1..], 10) else null;
@@ -727,6 +729,15 @@ pub fn main() !void {
length += sleep_len + 1; length += sleep_len + 1;
} }
if (config.hibernate_cmd != null) {
buffer.drawLabel(config.hibernate_key, length, config.edge_margin);
length += config.hibernate_key.len + 1;
buffer.drawLabel(" ", length - 1, config.edge_margin);
buffer.drawLabel(lang.hibernate, length, config.edge_margin);
length += hibernate_len + 1;
}
if (config.brightness_down_key) |key| { if (config.brightness_down_key) |key| {
buffer.drawLabel(key, length, config.edge_margin); buffer.drawLabel(key, length, config.edge_margin);
length += key.len + 1; length += key.len + 1;
@@ -857,6 +868,22 @@ pub fn main() !void {
} }
} }
} }
} else if (pressed_key == hibernate_key) {
if (config.hibernate_cmd) |hibernate_cmd| {
var hibernate = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", hibernate_cmd }, allocator);
hibernate.stdout_behavior = .Ignore;
hibernate.stderr_behavior = .Ignore;
handle_hibernate_cmd: {
const process_result = hibernate.spawnAndWait() catch {
break :handle_hibernate_cmd;
};
if (process_result.Exited != 0) {
try info_line.addMessage(lang.err_hibernate, config.error_bg, config.error_fg);
try log_writer.print("failed to execute hibernate command: exit code {d}\n", .{process_result.Exited});
}
}
}
} else if (brightness_down_key != null and pressed_key == brightness_down_key.?) { } else if (brightness_down_key != null and pressed_key == brightness_down_key.?) {
adjustBrightness(allocator, config.brightness_down_cmd) catch |err| { adjustBrightness(allocator, config.brightness_down_cmd) catch |err| {
try info_line.addMessage(lang.err_brightness_change, config.error_bg, config.error_fg); try info_line.addMessage(lang.err_brightness_change, config.error_bg, config.error_fg);