mirror of
https://github.com/fairyglade/ly.git
synced 2026-03-21 22:43:38 +00:00
Add toggle visibility to password (#938)
## What are the changes about? I have add a keybinding to toggle the visibility of the password ## What existing issue does this resolve? N/A ## Pre-requisites - [x] I have tested & confirmed the changes work locally Reviewed-on: https://codeberg.org/fairyglade/ly/pulls/938 Reviewed-by: AnErrupTion <anerruption+codeberg@disroot.org> Co-authored-by: Luna <luna-39@noreply.codeberg.org> Co-committed-by: Luna <luna-39@noreply.codeberg.org>
This commit is contained in:
@@ -325,6 +325,9 @@ session_log = .local/state/ly-session.log
|
|||||||
# Setup command
|
# Setup command
|
||||||
setup_cmd = $CONFIG_DIRECTORY/ly/setup.sh
|
setup_cmd = $CONFIG_DIRECTORY/ly/setup.sh
|
||||||
|
|
||||||
|
# Specifies the key combination used for showing the password
|
||||||
|
show_password_key = F7
|
||||||
|
|
||||||
# Command executed when pressing shutdown_key
|
# Command executed when pressing shutdown_key
|
||||||
shutdown_cmd = /sbin/shutdown $PLATFORM_SHUTDOWN_ARG now
|
shutdown_cmd = /sbin/shutdown $PLATFORM_SHUTDOWN_ARG now
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ restart = اعادة التشغيل
|
|||||||
shell = shell
|
shell = shell
|
||||||
shutdown = ايقاف التشغيل
|
shutdown = ايقاف التشغيل
|
||||||
sleep = وضع السكون
|
sleep = وضع السكون
|
||||||
|
|
||||||
wayland = wayland
|
wayland = wayland
|
||||||
x11 = x11
|
x11 = x11
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ restart = рестартиране
|
|||||||
shell = обвивка
|
shell = обвивка
|
||||||
shutdown = изключване
|
shutdown = изключване
|
||||||
sleep = заспиване
|
sleep = заспиване
|
||||||
|
|
||||||
wayland = wayland
|
wayland = wayland
|
||||||
x11 = x11
|
x11 = x11
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
|
|||||||
@@ -73,6 +73,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
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ restart = restartovat
|
|||||||
shell = příkazový řádek
|
shell = příkazový řádek
|
||||||
shutdown = vypnout
|
shutdown = vypnout
|
||||||
|
|
||||||
|
|
||||||
wayland = wayland
|
wayland = wayland
|
||||||
|
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
|
|||||||
@@ -73,6 +73,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
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ restart = reboot
|
|||||||
shell = shell
|
shell = shell
|
||||||
shutdown = shutdown
|
shutdown = shutdown
|
||||||
sleep = sleep
|
sleep = sleep
|
||||||
|
toggle_password = toggle password
|
||||||
wayland = wayland
|
wayland = wayland
|
||||||
x11 = x11
|
x11 = x11
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ restart = reiniciar
|
|||||||
shell = shell
|
shell = shell
|
||||||
shutdown = apagar
|
shutdown = apagar
|
||||||
sleep = suspender
|
sleep = suspender
|
||||||
|
|
||||||
wayland = wayland
|
wayland = wayland
|
||||||
|
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
|
|||||||
@@ -73,6 +73,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
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ restart = riavvio
|
|||||||
shell = shell
|
shell = shell
|
||||||
shutdown = arresto
|
shutdown = arresto
|
||||||
|
|
||||||
|
|
||||||
wayland = wayland
|
wayland = wayland
|
||||||
|
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ restart = 再起動
|
|||||||
shell = シェル
|
shell = シェル
|
||||||
shutdown = シャットダウン
|
shutdown = シャットダウン
|
||||||
sleep = スリープ
|
sleep = スリープ
|
||||||
|
|
||||||
wayland = Wayland
|
wayland = Wayland
|
||||||
x11 = X11
|
x11 = X11
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ restart = ji nû ve bide destpêkirin
|
|||||||
shell = shell
|
shell = shell
|
||||||
shutdown = vemirîne
|
shutdown = vemirîne
|
||||||
sleep = têxîne xewê
|
sleep = têxîne xewê
|
||||||
|
|
||||||
wayland = wayland
|
wayland = wayland
|
||||||
x11 = x11
|
x11 = x11
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
|
|||||||
@@ -73,6 +73,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
|
||||||
|
|||||||
@@ -73,6 +73,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
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ restart = reiniciar
|
|||||||
shell = shell
|
shell = shell
|
||||||
shutdown = encerrar
|
shutdown = encerrar
|
||||||
|
|
||||||
|
|
||||||
wayland = wayland
|
wayland = wayland
|
||||||
|
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ restart = reiniciar
|
|||||||
shell = shell
|
shell = shell
|
||||||
shutdown = desligar
|
shutdown = desligar
|
||||||
|
|
||||||
|
|
||||||
wayland = wayland
|
wayland = wayland
|
||||||
|
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ restart = resetează
|
|||||||
shell = shell
|
shell = shell
|
||||||
shutdown = opreşte sistemul
|
shutdown = opreşte sistemul
|
||||||
|
|
||||||
|
|
||||||
wayland = wayland
|
wayland = wayland
|
||||||
|
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ restart = перезагрузить
|
|||||||
shell = оболочка
|
shell = оболочка
|
||||||
shutdown = выключить
|
shutdown = выключить
|
||||||
sleep = сон
|
sleep = сон
|
||||||
|
|
||||||
wayland = wayland
|
wayland = wayland
|
||||||
x11 = x11
|
x11 = x11
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ restart = ponovo pokreni
|
|||||||
shell = shell
|
shell = shell
|
||||||
shutdown = ugasi
|
shutdown = ugasi
|
||||||
|
|
||||||
|
|
||||||
wayland = wayland
|
wayland = wayland
|
||||||
|
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ restart = starta om
|
|||||||
shell = shell
|
shell = shell
|
||||||
shutdown = stäng av
|
shutdown = stäng av
|
||||||
sleep = viloläge
|
sleep = viloläge
|
||||||
|
|
||||||
wayland = wayland
|
wayland = wayland
|
||||||
x11 = x11
|
x11 = x11
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
@@ -73,6 +73,7 @@ restart = yeniden baslat
|
|||||||
shell = shell
|
shell = shell
|
||||||
shutdown = makineyi kapat
|
shutdown = makineyi kapat
|
||||||
sleep = uykuya al
|
sleep = uykuya al
|
||||||
|
|
||||||
wayland = wayland
|
wayland = wayland
|
||||||
|
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
@@ -73,6 +73,7 @@ restart = перезавантажити
|
|||||||
shell = оболонка
|
shell = оболонка
|
||||||
shutdown = вимкнути
|
shutdown = вимкнути
|
||||||
|
|
||||||
|
|
||||||
wayland = wayland
|
wayland = wayland
|
||||||
|
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ password = 密码
|
|||||||
shell = shell
|
shell = shell
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
wayland = wayland
|
wayland = wayland
|
||||||
x11 = x11
|
x11 = x11
|
||||||
xinitrc = xinitrc
|
xinitrc = xinitrc
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ save: bool = true,
|
|||||||
service_name: [:0]const u8 = "ly",
|
service_name: [:0]const u8 = "ly",
|
||||||
session_log: ?[]const u8 = "ly-session.log",
|
session_log: ?[]const u8 = "ly-session.log",
|
||||||
setup_cmd: []const u8 = build_options.config_directory ++ "/ly/setup.sh",
|
setup_cmd: []const u8 = build_options.config_directory ++ "/ly/setup.sh",
|
||||||
|
show_password_key: []const u8 = "F7",
|
||||||
shutdown_cmd: []const u8 = "/sbin/shutdown -a now",
|
shutdown_cmd: []const u8 = "/sbin/shutdown -a now",
|
||||||
shutdown_key: []const u8 = "F1",
|
shutdown_key: []const u8 = "F1",
|
||||||
sleep_cmd: ?[]const u8 = null,
|
sleep_cmd: ?[]const u8 = null,
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ restart: []const u8 = "reboot",
|
|||||||
shell: [:0]const u8 = "shell",
|
shell: [:0]const u8 = "shell",
|
||||||
shutdown: []const u8 = "shutdown",
|
shutdown: []const u8 = "shutdown",
|
||||||
sleep: []const u8 = "sleep",
|
sleep: []const u8 = "sleep",
|
||||||
|
toggle_password: []const u8 = "toggle password",
|
||||||
wayland: []const u8 = "wayland",
|
wayland: []const u8 = "wayland",
|
||||||
x11: []const u8 = "x11",
|
x11: []const u8 = "x11",
|
||||||
xinitrc: [:0]const u8 = "xinitrc",
|
xinitrc: [:0]const u8 = "xinitrc",
|
||||||
|
|||||||
34
src/main.zig
34
src/main.zig
@@ -76,6 +76,7 @@ const UiState = struct {
|
|||||||
restart_label: Label,
|
restart_label: Label,
|
||||||
sleep_label: Label,
|
sleep_label: Label,
|
||||||
hibernate_label: Label,
|
hibernate_label: Label,
|
||||||
|
toggle_password_label: Label,
|
||||||
brightness_down_label: Label,
|
brightness_down_label: Label,
|
||||||
brightness_up_label: Label,
|
brightness_up_label: Label,
|
||||||
numlock_label: Label,
|
numlock_label: Label,
|
||||||
@@ -393,6 +394,16 @@ pub fn main() !void {
|
|||||||
);
|
);
|
||||||
defer state.hibernate_label.deinit();
|
defer state.hibernate_label.deinit();
|
||||||
|
|
||||||
|
state.toggle_password_label = Label.init(
|
||||||
|
"",
|
||||||
|
null,
|
||||||
|
state.buffer.fg,
|
||||||
|
state.buffer.bg,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
defer state.toggle_password_label.deinit();
|
||||||
|
|
||||||
state.brightness_down_label = Label.init(
|
state.brightness_down_label = Label.init(
|
||||||
"",
|
"",
|
||||||
null,
|
null,
|
||||||
@@ -424,6 +435,11 @@ pub fn main() !void {
|
|||||||
"{s} {s}",
|
"{s} {s}",
|
||||||
.{ state.config.restart_key, state.lang.restart },
|
.{ state.config.restart_key, state.lang.restart },
|
||||||
);
|
);
|
||||||
|
try state.toggle_password_label.setTextAlloc(
|
||||||
|
state.allocator,
|
||||||
|
"{s} {s}",
|
||||||
|
.{ state.config.show_password_key, state.lang.toggle_password },
|
||||||
|
);
|
||||||
if (state.config.sleep_cmd != null) {
|
if (state.config.sleep_cmd != null) {
|
||||||
try state.sleep_label.setTextAlloc(
|
try state.sleep_label.setTextAlloc(
|
||||||
state.allocator,
|
state.allocator,
|
||||||
@@ -1019,6 +1035,10 @@ pub fn main() !void {
|
|||||||
if (state.config.sleep_cmd != null) {
|
if (state.config.sleep_cmd != null) {
|
||||||
try layer2.append(state.allocator, state.sleep_label.widget());
|
try layer2.append(state.allocator, state.sleep_label.widget());
|
||||||
}
|
}
|
||||||
|
if (state.config.hibernate_cmd != null) {
|
||||||
|
try layer2.append(state.allocator, state.hibernate_label.widget());
|
||||||
|
}
|
||||||
|
try layer2.append(state.allocator, state.toggle_password_label.widget());
|
||||||
if (state.config.brightness_down_key != null) {
|
if (state.config.brightness_down_key != null) {
|
||||||
try layer2.append(state.allocator, state.brightness_down_label.widget());
|
try layer2.append(state.allocator, state.brightness_down_label.widget());
|
||||||
}
|
}
|
||||||
@@ -1074,6 +1094,7 @@ pub fn main() !void {
|
|||||||
|
|
||||||
try state.buffer.registerKeybind(state.config.shutdown_key, &shutdownCmd, &state);
|
try state.buffer.registerKeybind(state.config.shutdown_key, &shutdownCmd, &state);
|
||||||
try state.buffer.registerKeybind(state.config.restart_key, &restartCmd, &state);
|
try state.buffer.registerKeybind(state.config.restart_key, &restartCmd, &state);
|
||||||
|
try state.buffer.registerKeybind(state.config.show_password_key, &togglePasswordMask, &state);
|
||||||
if (state.config.sleep_cmd != null) try state.buffer.registerKeybind(state.config.sleep_key, &sleepCmd, &state);
|
if (state.config.sleep_cmd != null) try state.buffer.registerKeybind(state.config.sleep_key, &sleepCmd, &state);
|
||||||
if (state.config.hibernate_cmd != null) try state.buffer.registerKeybind(state.config.hibernate_key, &hibernateCmd, &state);
|
if (state.config.hibernate_cmd != null) try state.buffer.registerKeybind(state.config.hibernate_key, &hibernateCmd, &state);
|
||||||
if (state.config.brightness_down_key) |key| try state.buffer.registerKeybind(key, &decreaseBrightnessCmd, &state);
|
if (state.config.brightness_down_key) |key| try state.buffer.registerKeybind(key, &decreaseBrightnessCmd, &state);
|
||||||
@@ -1201,6 +1222,14 @@ fn clearPassword(ptr: *anyopaque) !bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn togglePasswordMask(ptr: *anyopaque) !bool {
|
||||||
|
var state: *UiState = @ptrCast(@alignCast(ptr));
|
||||||
|
|
||||||
|
state.password.toggleMask();
|
||||||
|
state.buffer.drawNextFrame(true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
fn quit(ptr: *anyopaque) !bool {
|
fn quit(ptr: *anyopaque) !bool {
|
||||||
var state: *UiState = @ptrCast(@alignCast(ptr));
|
var state: *UiState = @ptrCast(@alignCast(ptr));
|
||||||
|
|
||||||
@@ -1666,7 +1695,10 @@ fn positionWidgets(ptr: *anyopaque) !void {
|
|||||||
state.hibernate_label.positionX(state.sleep_label
|
state.hibernate_label.positionX(state.sleep_label
|
||||||
.childrenPosition()
|
.childrenPosition()
|
||||||
.addX(1));
|
.addX(1));
|
||||||
state.brightness_down_label.positionX(state.hibernate_label
|
state.toggle_password_label.positionX(state.hibernate_label
|
||||||
|
.childrenPosition()
|
||||||
|
.addX(1));
|
||||||
|
state.brightness_down_label.positionX(state.toggle_password_label
|
||||||
.childrenPosition()
|
.childrenPosition()
|
||||||
.addX(1));
|
.addX(1));
|
||||||
state.brightness_up_label.positionXY(state.brightness_down_label
|
state.brightness_up_label.positionXY(state.brightness_down_label
|
||||||
|
|||||||
@@ -96,6 +96,10 @@ pub fn clear(self: *Text) void {
|
|||||||
self.visible_start = 0;
|
self.visible_start = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn toggleMask(self: *Text) void {
|
||||||
|
self.masked = !self.masked;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn handle(self: *Text, maybe_key: ?keyboard.Key, insert_mode: bool) !void {
|
pub fn handle(self: *Text, maybe_key: ?keyboard.Key, insert_mode: bool) !void {
|
||||||
if (maybe_key) |key| {
|
if (maybe_key) |key| {
|
||||||
if (key.left or (!insert_mode and (key.h or key.backspace))) {
|
if (key.left or (!insert_mode and (key.h or key.backspace))) {
|
||||||
|
|||||||
Reference in New Issue
Block a user