Add option to change shutdown/reboot keys (#487)

Include options in the configuration to change which function keys to use for shutdown and reboot.
Fix config.map_len size in src/config.c.
Add missing defaults in config_defaults() in src/config.c.
pull/522/head
lolicon0930 11 months ago committed by GitHub
parent 0edb0012ab
commit 42bf929756
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,7 +16,7 @@ Ly is a lightweight TUI (ncurses-like) display manager for Linux and BSD.
- tput
- shutdown
On Debian-based distros running `apt install build-essential libpam0g-dev libxcb-xkb-dev` as root should install all the dependencies for you.
On Debian-based distros running `apt install build-essential libpam0g-dev libxcb-xkb-dev` as root should install all the dependencies for you.
For Fedora try running `dnf install make automake gcc gcc-c++ kernel-devel pam-devel libxcb-devel`
## Support
@ -27,7 +27,7 @@ The following desktop environments were tested with success
- budgie
- cinnamon
- deepin
- dwm
- dwm
- enlightenment
- gnome
- i3
@ -36,12 +36,12 @@ The following desktop environments were tested with success
- lxde
- lxqt
- mate
- maxx
- maxx
- pantheon
- qtile
- spectrwm
- sway
- windowmaker
- windowmaker
- xfce
- xmonad
@ -121,7 +121,7 @@ $ make
# ln -s /etc/sv/ly /var/service/
```
By default, ly will run on tty2. To change the tty it must be set in `/etc/ly/config.ini`
By default, ly will run on tty2. To change the tty it must be set in `/etc/ly/config.ini`
You should as well disable your existing display manager service if needed, e.g.:

@ -3,7 +3,7 @@
# The active animation
# 0 -> PSX DOOM fire (default)
# 1 -> CMatrix
# 1 -> CMatrix
#animation = 0
# format string for clock in top right corner (see strftime specification)
@ -29,12 +29,12 @@
#define TB_CYAN 0x07
#define TB_WHITE 0x08
#
# Setting both to zero makes `bg` black and `fg` white. To set the actual color palette you are encouraged to use another tool
# such as [mkinitcpio-colors](https://github.com/evanpurkhiser/mkinitcpio-colors). Note that the color palette defined with
# `mkinitcpio-colors` takes 16 colors (0-15), only values 0-8 are valid for `ly` config and these values do not correspond
# exactly. For instance, in defining palettes with `mkinitcpio-colors` the order is black, dark red, dark green, brown, dark
# blue, dark purple, dark cyan, light gray, dark gray, bright red, bright green, yellow, bright blue, bright purple, bright
# cyan, and white, indexed in that order 0 through 15. For example, the color defined for white (indexed at 15 in the mkinitcpio
# Setting both to zero makes `bg` black and `fg` white. To set the actual color palette you are encouraged to use another tool
# such as [mkinitcpio-colors](https://github.com/evanpurkhiser/mkinitcpio-colors). Note that the color palette defined with
# `mkinitcpio-colors` takes 16 colors (0-15), only values 0-8 are valid for `ly` config and these values do not correspond
# exactly. For instance, in defining palettes with `mkinitcpio-colors` the order is black, dark red, dark green, brown, dark
# blue, dark purple, dark cyan, light gray, dark gray, bright red, bright green, yellow, bright blue, bright purple, bright
# cyan, and white, indexed in that order 0 through 15. For example, the color defined for white (indexed at 15 in the mkinitcpio
# config) will be used by `ly` for `fg = 8`.
# Background color id
@ -76,13 +76,19 @@
#save_file = /etc/ly/save
# Remove F1/F2 command hints
#hide_f1_commands = false
# Remove power management command hints
#hide_key_hints = false
# Command executed when pressing F1
# Specifies the key used for shutdown
#shutdown_key = F1
# Specifies the key used for restart
#restart_key = F2
# Command executed when pressing shutdown_key
#shutdown_cmd = /sbin/shutdown -a now
# Command executed when pressing F2
# Command executed when pressing restart_key
#restart_cmd = /sbin/shutdown -r now

@ -1,5 +1,5 @@
capslock = Bloq Majús
err_alloc = falla d'assignació de memòria
err_alloc = falla d'assignació de memòria
err_bounds = índex fora de límit
err_chdir = error al obrir carpeta home
err_console_dev = error al accedir a la consola
@ -34,12 +34,12 @@ err_user_init = error al inicialitzar usuari
err_user_uid = error al establir el UID de l'usuari
err_xsessions_dir = error al cercar la carpeta de sessions
err_xsessions_open = error al obrir la carpeta de sessions
f1 = F1 aturar
f2 = F2 reiniciar
login = iniciar sessió
logout = tancar sessió
numlock = Bloq Num
password = Clau
restart = reiniciar
shell = shell
shutdown = aturar
wayland = wayland
xinitrc = xinitrc

@ -34,12 +34,12 @@ err_user_init = inicializace uživatele selhala
err_user_uid = nastavení UID uživateli selhalo
err_xsessions_dir = nepodařilo se najít složku relací
err_xsessions_open = nepodařilo se otevřít složku relací
f1 = F1 vypnout
f2 = F2 restartovat
login = uživatel
logout = odhlášen
numlock = numlock
password = heslo
restart = restartovat
shell = příkazový řádek
shutdown = vypnout
wayland = wayland
xinitrc = xinitrc

@ -34,12 +34,12 @@ err_user_init = Initialisierung des Nutzers fehlgeschlagen
err_user_uid = Setzen der Benutzer Id fehlgeschlagen
err_xsessions_dir = Fehler beim finden des Sitzungsordners
err_xsessions_open = Fehler beim öffnen des Sitzungsordners
f1 = F1 Herunterfahren
f2 = F2 Neustarten
login = Anmelden
logout = Abgemeldet
numlock = Numtaste
password = Passwort
restart = Neustarten
shell = shell
shutdown = Herunterfahren
wayland = wayland
xinitrc = xinitrc

@ -34,12 +34,12 @@ err_user_init = failed to initialize user
err_user_uid = failed to set user UID
err_xsessions_dir = failed to find sessions folder
err_xsessions_open = failed to open sessions folder
f1 = F1 shutdown
f2 = F2 reboot
login = login
logout = logged out
numlock = numlock
password = password
restart = reboot
shell = shell
shutdown = shutdown
wayland = wayland
xinitrc = xinitrc

@ -34,12 +34,12 @@ err_user_init = error al inicializar usuario
err_user_uid = error al establecer el UID del usuario
err_xsessions_dir = error al buscar la carpeta de sesiones
err_xsessions_open = error al abrir la carpeta de sesiones
f1 = F1 apagar
f2 = F2 reiniciar
login = iniciar sesión
logout = cerrar sesión
numlock = Bloq Num
numlock = Bloq Num
password = contraseña
restart = reiniciar
shell = shell
shutdown = apagar
wayland = wayland
xinitrc = xinitrc

@ -20,7 +20,7 @@ err_pam_cred_expired = identifiants expirés
err_pam_cred_insufficient = identifiants insuffisants
err_pam_cred_unavail = échec de l'obtention des identifiants
err_pam_maxtries = limite d'essais atteinte
err_pam_perm_denied = permission refusée
err_pam_perm_denied = permission refusée
err_pam_session = erreur de session
err_pam_sys = erreur système
err_pam_user_unknown = utilisateur inconnu
@ -34,12 +34,12 @@ err_user_init = échec d'initialisation de l'utilisateur
err_user_uid = échec de modification du UID
err_xsessions_dir = échec de la recherche du dossier de sessions
err_xsessions_open = échec de l'ouverture du dossier de sessions
f1 = F1 éteindre
f2 = F2 redémarrer
login = identifiant
logout = déconnection
numlock = verr.num
password = mot de passe
restart = redémarrer
shell = shell
shutdown = éteindre
wayland = wayland
xinitrc = xinitrc

@ -34,12 +34,12 @@ err_user_init = impossibile inizializzare utente
err_user_uid = impossible impostare UID utente
err_xsessions_dir = impossibile localizzare cartella sessioni
err_xsessions_open = impossibile aprire cartella sessioni
f1 = F1 arresto
f2 = F2 riavvio
login = username
logout = scollegato
numlock = numlock
password = password
restart = riavvio
shell = shell
shutdown = arresto
wayland = wayland
xinitrc = xinitrc

@ -34,12 +34,12 @@ err_user_init = nie udało się zainicjalizować użytkownika
err_user_uid = nie udało się ustawić UID użytkownika
err_xsessions_dir = nie udało się znaleźć folderu sesji
err_xsessions_open = nie udało się otworzyć folderu sesji
f1 = F1 wyłącz
f2 = F2 uruchom ponownie
login = login
logout = wylogowano
numlock = numlock
password = hasło
restart = uruchom ponownie
shell = powłoka
shutdown = wyłącz
wayland = wayland
xinitrc = xinitrc

@ -34,12 +34,12 @@ err_user_init = erro ao iniciar o utilizador
err_user_uid = erro ao definir o UID do utilizador
err_xsessions_dir = erro ao localizar a pasta das sessões
err_xsessions_open = erro ao abrir a pasta das sessões
f1 = F1 encerrar
f2 = F2 reiniciar
login = iniciar sessão
logout = terminar sessão
numlock = numlock
password = palavra-passe
restart = reiniciar
shell = shell
shutdown = encerrar
wayland = wayland
xinitrc = xinitrc

@ -34,12 +34,12 @@ 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_xsessions_dir = não foi possível encontrar a pasta das sessões
err_xsessions_open = não foi possível abrir a pasta das sessões
f1 = F1 desligar
f2 = F2 reiniciar
login = conectar
logout = desconectado
numlock = numlock
password = senha
restart = reiniciar
shell = shell
shutdown = desligar
wayland = wayland
xinitrc = xinitrc

@ -34,12 +34,12 @@ err_perm_user = nu s-a putut face downgrade permisiunilor de utilizator
f1 = F1 opreşte sistemul
f2 = F2 resetează
login = utilizator
logout = opreşte sesiunea
numlock = numlock
password = parolă
restart = resetează
shell = shell
shutdown = opreşte sistemul
wayland = wayland
xinitrc = xinitrc

@ -34,12 +34,12 @@ err_user_init = не удалось инициализировать польз
err_user_uid = не удалось установить UID пользователя
err_xsessions_dir = не удалось найти сессионную папку
err_xsessions_open = не удалось открыть сессионную папку
f1 = F1 выключить
f2 = F2 перезагрузить
login = логин
logout = logged out
numlock = numlock
password = пароль
restart = перезагрузить
shell = shell
shutdown = выключить
wayland = wayland
xinitrc = xinitrc

@ -25,7 +25,7 @@ err_pam_session = greska sesije
err_pam_sys = greska sistema
err_pam_user_unknown = nepoznat korisnik
err_path = neuspjelo postavljanje path-a
err_perm_dir = neuspjelo mijenjanje foldera
err_perm_dir = neuspjelo mijenjanje foldera
err_perm_group = neuspjesno snizavanje dozvola grupe
err_perm_user = neuspijesno snizavanje dozvola korisnika
err_pwnam = neuspijesno skupljanje informacija o korisniku
@ -33,13 +33,13 @@ err_user_gid = neuspijesno postavljanje korisničkog GID-a
err_user_init = neuspijensa inicijalizacija korisnika
err_user_uid = neuspijesno postavljanje UID-a korisnika
err_xsessions_dir = neuspijesno pronalazenje foldera sesija
err_xsessions_open = neuspijesno otvaranje foldera sesija
f1 = F1 ugasi
f2 = F2 ponovo pokreni
err_xsessions_open = neuspijesno otvaranje foldera sesija
login = korisnik
logout = izlogovan
numlock = numlock
password = lozinka
restart = ponovo pokreni
shell = shell
shutdown = ugasi
wayland = wayland
xinitrc = xinitrc

@ -6,7 +6,7 @@ err_console_dev = misslyckades att komma åt konsol
err_dgn_oob = loggmeddelande
err_domain = okänd domän
err_hostname = misslyckades att hämta värdnamn
err_mlock = misslyckades att låsa lösenordsminne
err_mlock = misslyckades att låsa lösenordsminne
err_null = nullpekare
err_pam = pam-transaktion misslyckades
err_pam_abort = pam-transaktion avbröts
@ -34,12 +34,12 @@ err_user_init = misslyckades att initialisera användaren
err_user_uid = misslyckades att ställa in användar-UID
err_xsessions_dir = misslyckades att hitta sessionskatalog
err_xsessions_open = misslyckades att öppna sessionskatalog
f1 = F1 stäng av
f2 = F2 starta om
login = inloggning
logout = utloggad
numlock = numlock
password = lösenord
restart = starta om
shell = skal
shutdown = stäng av
wayland = wayland
xinitrc = xinitrc

@ -34,12 +34,12 @@ err_user_init = kullanici oturumu baslatilamadi
err_user_uid = kullanici icin UID ayarlanamadi
err_xsessions_dir = oturumlar klasoru bulunamadi
err_xsessions_open = oturumlar klasoru acilamadi
f1 = F1 makineyi kapat
f2 = F2 yeniden baslat
login = kullanici
logout = oturumdan cikis yapildi
numlock = numlock
password = sifre
restart = yeniden baslat
shell = shell
shutdown = makineyi kapat
wayland = wayland
xinitrc = xinitrc

@ -34,12 +34,12 @@ err_user_init = не вдалося ініціалізувати користу
err_user_uid = не вдалося змінити UID користувача
err_xsessions_dir = не вдалося знайти каталог сесій
err_xsessions_open = не вдалося відкрити каталог сесій
f1 = F1 вимкнути
f2 = F2 перезавантажити
login = логін
logout = вийти
numlock = numlock
password = пароль
restart = перезавантажити
shell = оболонка
shutdown = вимкнути
wayland = wayland
xinitrc = xinitrc

@ -113,13 +113,13 @@ void lang_load()
{"err_user_uid", &lang.err_user_uid, lang_handle},
{"err_xsessions_dir", &lang.err_xsessions_dir, lang_handle},
{"err_xsessions_open", &lang.err_xsessions_open, lang_handle},
{"f1", &lang.f1, lang_handle},
{"f2", &lang.f2, lang_handle},
{"login", &lang.login, lang_handle},
{"logout", &lang.logout, lang_handle},
{"numlock", &lang.numlock, lang_handle},
{"password", &lang.password, lang_handle},
{"restart", &lang.restart, lang_handle},
{"shell", &lang.shell, lang_handle},
{"shutdown", &lang.shutdown, lang_handle},
{"wayland", &lang.wayland, lang_handle},
{"xinitrc", &lang.xinitrc, lang_handle},
};
@ -169,7 +169,7 @@ void config_load(const char *cfg_path)
{"default_input", &config.default_input, config_handle_u8},
{"fg", &config.fg, config_handle_u8},
{"hide_borders", &config.hide_borders, config_handle_bool},
{"hide_f1_commands", &config.hide_f1_commands, config_handle_bool},
{"hide_key_hints", &config.hide_key_hints, config_handle_bool},
{"input_len", &config.input_len, config_handle_u8},
{"lang", &config.lang, config_handle_str},
{"load", &config.load, config_handle_bool},
@ -182,10 +182,12 @@ void config_load(const char *cfg_path)
{"min_refresh_delta", &config.min_refresh_delta, config_handle_u16},
{"path", &config.path, config_handle_str},
{"restart_cmd", &config.restart_cmd, config_handle_str},
{"restart_key", &config.restart_key, config_handle_str},
{"save", &config.save, config_handle_bool},
{"save_file", &config.save_file, config_handle_str},
{"service_name", &config.service_name, config_handle_str},
{"shutdown_cmd", &config.shutdown_cmd, config_handle_str},
{"shutdown_key", &config.shutdown_key, config_handle_str},
{"term_reset_cmd", &config.term_reset_cmd, config_handle_str},
{"tty", &config.tty, config_handle_u8},
{"wayland_cmd", &config.wayland_cmd, config_handle_str},
@ -198,7 +200,7 @@ void config_load(const char *cfg_path)
{"xsessions", &config.xsessions, config_handle_str},
};
uint16_t map_len[] = {34};
uint16_t map_len[] = {41};
struct configator_param* map[] =
{
map_no_section,
@ -254,13 +256,13 @@ void lang_defaults()
lang.err_user_uid = strdup("failed to set user UID");
lang.err_xsessions_dir = strdup("failed to find sessions folder");
lang.err_xsessions_open = strdup("failed to open sessions folder");
lang.f1 = strdup("F1 shutdown");
lang.f2 = strdup("F2 reboot");
lang.login = strdup("login:");
lang.logout = strdup("logged out");
lang.numlock = strdup("numlock");
lang.password = strdup("password:");
lang.restart = strdup("reboot");
lang.shell = strdup("shell");
lang.shutdown = strdup("shutdown");
lang.wayland = strdup("wayland");
lang.xinitrc = strdup("xinitrc");
}
@ -279,6 +281,7 @@ void config_defaults()
config.default_input = LOGIN_INPUT;
config.fg = 9;
config.hide_borders = false;
config.hide_key_hints = false;
config.input_len = 34;
config.lang = strdup("en");
config.load = true;
@ -291,10 +294,12 @@ void config_defaults()
config.min_refresh_delta = 5;
config.path = strdup("/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin");
config.restart_cmd = strdup("/sbin/shutdown -r now");
config.restart_key = strdup("F2");
config.save = true;
config.save_file = strdup("/etc/ly/save");
config.service_name = strdup("ly");
config.shutdown_cmd = strdup("/sbin/shutdown -a now");
config.shutdown_key = strdup("F1");
config.term_reset_cmd = strdup("/usr/bin/tput reset");
config.tty = 2;
config.wayland_cmd = strdup(DATADIR "/wsetup.sh");
@ -345,13 +350,13 @@ void lang_free()
free(lang.err_user_uid);
free(lang.err_xsessions_dir);
free(lang.err_xsessions_open);
free(lang.f1);
free(lang.f2);
free(lang.login);
free(lang.logout);
free(lang.numlock);
free(lang.password);
free(lang.restart);
free(lang.shell);
free(lang.shutdown);
free(lang.wayland);
free(lang.xinitrc);
}
@ -364,9 +369,11 @@ void config_free()
free(config.mcookie_cmd);
free(config.path);
free(config.restart_cmd);
free(config.restart_key);
free(config.save_file);
free(config.service_name);
free(config.shutdown_cmd);
free(config.shutdown_key);
free(config.term_reset_cmd);
free(config.wayland_cmd);
free(config.waylandsessions);

@ -48,13 +48,13 @@ struct lang
char* err_user_uid;
char* err_xsessions_dir;
char* err_xsessions_open;
char* f1;
char* f2;
char* login;
char* logout;
char* numlock;
char* password;
char* restart;
char* shell;
char* shutdown;
char* wayland;
char* xinitrc;
};
@ -73,7 +73,7 @@ struct config
uint8_t default_input;
uint8_t fg;
bool hide_borders;
bool hide_f1_commands;
bool hide_key_hints;
uint8_t input_len;
char* lang;
bool load;
@ -86,10 +86,12 @@ struct config
uint16_t min_refresh_delta;
char* path;
char* restart_cmd;
char* restart_key;
bool save;
char* save_file;
char* service_name;
char* shutdown_cmd;
char* shutdown_key;
char* term_reset_cmd;
uint8_t tty;
char* wayland_cmd;

@ -192,7 +192,7 @@ char* time_str(char* fmt, int maxlen)
{
buffer[0] = '\0';
}
return buffer;
}
@ -373,30 +373,54 @@ void draw_labels(struct term_buf* buf) // throws
}
}
void draw_f_commands()
void draw_key_hints()
{
struct tb_cell* f1 = str_cell(lang.f1);
struct tb_cell* shutdown_key = str_cell(config.shutdown_key);
int len = strlen(config.shutdown_key);
if (dgn_catch())
{
dgn_reset();
}
else
{
tb_blit(0, 0, len, 1, shutdown_key);
free(shutdown_key);
}
struct tb_cell* shutdown = str_cell(lang.shutdown);
len += 1;
if (dgn_catch())
{
dgn_reset();
}
else
{
tb_blit(0, 0, strlen(lang.f1), 1, f1);
free(f1);
tb_blit(len, 0, strlen(lang.shutdown), 1, shutdown);
free(shutdown);
}
struct tb_cell* f2 = str_cell(lang.f2);
struct tb_cell* restart_key = str_cell(config.restart_key);
len += strlen(lang.shutdown) + 1;
if (dgn_catch())
{
dgn_reset();
}
else
{
tb_blit(len, 0, strlen(config.restart_key), 1, restart_key);
free(restart_key);
}
struct tb_cell* restart = str_cell(lang.restart);
len += strlen(config.restart_key) + 1;
if (dgn_catch())
{
dgn_reset();
}
else
{
tb_blit(strlen(lang.f1) + 1, 0, strlen(lang.f2), 1, f2);
free(f2);
tb_blit(len, 0, strlen(lang.restart), 1, restart);
free(restart);
}
}
@ -962,7 +986,7 @@ bool cascade(struct term_buf* term_buf, uint8_t* fails)
}
c_under = buf[(i + 1) * width + k].ch;
if (!isspace(c_under))
{
continue;
@ -983,7 +1007,7 @@ bool cascade(struct term_buf* term_buf, uint8_t* fails)
}
}
// stop force-updating
// stop force-updating
if (!changes)
{
sleep(7);

@ -70,7 +70,7 @@ struct tb_cell* strn_cell(char* s, uint16_t len);
struct tb_cell* str_cell(char* s);
void draw_labels(struct term_buf* buf);
void draw_f_commands();
void draw_key_hints();
void draw_lock_state(struct term_buf* buf);
void draw_desktop(struct desktop* target);
void draw_input(struct text* input);

@ -136,7 +136,7 @@ int main(int argc, char** argv)
// init visible elements
struct tb_event event;
struct term_buf buf;
//Place the curser on the login field if there is no saved username, if there is, place the curser on the password field
uint8_t active_input;
if (config.default_input == LOGIN_INPUT && login.text != login.end){
@ -192,8 +192,8 @@ int main(int argc, char** argv)
draw_box(&buf);
draw_clock(&buf);
draw_labels(&buf);
if(!config.hide_f1_commands)
draw_f_commands();
if(!config.hide_key_hints)
draw_key_hints();
draw_lock_state(&buf);
position_input(&buf, &desktop, &login, &password);
draw_desktop(&desktop);
@ -242,15 +242,40 @@ int main(int argc, char** argv)
if (event.type == TB_EVENT_KEY)
{
char shutdown_key[4];
memset(shutdown_key, '\0', sizeof(shutdown_key));
strcpy(shutdown_key, config.shutdown_key);
memcpy(shutdown_key, "0", 1);
char restart_key[4];
memset(restart_key, '\0', sizeof(restart_key));
strcpy(restart_key, config.restart_key);
memcpy(restart_key, "0", 1);
switch (event.key)
{
case TB_KEY_F1:
shutdown = true;
run = false;
break;
case TB_KEY_F2:
reboot = true;
run = false;
case TB_KEY_F3:
case TB_KEY_F4:
case TB_KEY_F5:
case TB_KEY_F6:
case TB_KEY_F7:
case TB_KEY_F8:
case TB_KEY_F9:
case TB_KEY_F10:
case TB_KEY_F11:
case TB_KEY_F12:
if( 0xFFFF - event.key + 1 == atoi(shutdown_key) )
{
shutdown = true;
run = false;
}
if( 0xFFFF - event.key + 1 == atoi(restart_key) )
{
reboot = true;
run = false;
}
break;
case TB_KEY_CTRL_C:
run = false;

Loading…
Cancel
Save