mirror of
https://codeberg.org/fairyglade/ly.git
synced 2026-08-23 05:54:20 +02:00
Merge branch 'master' into custom-commands
This commit is contained in:
commit
2155c3723f
29 changed files with 203 additions and 97 deletions
|
|
@ -82,6 +82,7 @@ save: bool = true,
|
|||
service_name: [:0]const u8 = "ly",
|
||||
session_log: ?[]const u8 = "ly-session.log",
|
||||
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_key: []const u8 = "F1",
|
||||
sleep_cmd: ?[]const u8 = null,
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ restart: []const u8 = "reboot",
|
|||
shell: [:0]const u8 = "shell",
|
||||
shutdown: []const u8 = "shutdown",
|
||||
sleep: []const u8 = "sleep",
|
||||
toggle_password: []const u8 = "toggle password",
|
||||
wayland: []const u8 = "wayland",
|
||||
x11: []const u8 = "x11",
|
||||
xinitrc: [:0]const u8 = "xinitrc",
|
||||
|
|
|
|||
56
src/main.zig
56
src/main.zig
|
|
@ -41,7 +41,6 @@ const Session = @import("tui/components/Session.zig");
|
|||
const Text = @import("tui/components/Text.zig");
|
||||
const UserList = @import("tui/components/UserList.zig");
|
||||
const TerminalBuffer = @import("tui/TerminalBuffer.zig");
|
||||
const termbox = TerminalBuffer.termbox;
|
||||
const Widget = @import("tui/Widget.zig");
|
||||
|
||||
const ly_version_str = "Ly version " ++ build_options.version;
|
||||
|
|
@ -88,6 +87,7 @@ const UiState = struct {
|
|||
restart_label: Label,
|
||||
sleep_label: Label,
|
||||
hibernate_label: Label,
|
||||
toggle_password_label: Label,
|
||||
brightness_down_label: Label,
|
||||
brightness_up_label: Label,
|
||||
numlock_label: Label,
|
||||
|
|
@ -430,6 +430,16 @@ pub fn main() !void {
|
|||
);
|
||||
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(
|
||||
"",
|
||||
null,
|
||||
|
|
@ -461,6 +471,11 @@ pub fn main() !void {
|
|||
"{s} {s}",
|
||||
.{ 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) {
|
||||
try state.sleep_label.setTextAlloc(
|
||||
state.allocator,
|
||||
|
|
@ -1113,6 +1128,10 @@ pub fn main() !void {
|
|||
if (state.config.sleep_cmd != null) {
|
||||
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) {
|
||||
try layer2.append(state.allocator, state.brightness_down_label.widget());
|
||||
}
|
||||
|
|
@ -1170,6 +1189,7 @@ pub fn main() !void {
|
|||
try state.buffer.registerKeybind("Ctrl+C", &quit, &state);
|
||||
|
||||
// TODO: Make this generic for any Text widget present in the UI
|
||||
// TODO: Per-widget keybinds, will fix insert_mode hack too
|
||||
try state.buffer.registerKeybind("Ctrl+U", &clearPassword, &state);
|
||||
|
||||
try state.buffer.registerKeybind("K", &viMoveCursorUp, &state);
|
||||
|
|
@ -1179,6 +1199,7 @@ pub fn main() !void {
|
|||
|
||||
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.show_password_key, &togglePasswordMask, &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.brightness_down_key) |key| try state.buffer.registerKeybind(key, &decreaseBrightnessCmd, &state);
|
||||
|
|
@ -1306,6 +1327,14 @@ fn clearPassword(ptr: *anyopaque) !bool {
|
|||
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 {
|
||||
var state: *UiState = @ptrCast(@alignCast(ptr));
|
||||
|
||||
|
|
@ -1833,19 +1862,34 @@ fn positionWidgets(ptr: *anyopaque) !void {
|
|||
if (!state.config.hide_key_hints) {
|
||||
state.shutdown_label.positionX(state.edge_margin
|
||||
.add(TerminalBuffer.START_POSITION));
|
||||
state.restart_label.positionX(state.shutdown_label
|
||||
var last_label = state.shutdown_label;
|
||||
state.restart_label.positionX(last_label
|
||||
.childrenPosition()
|
||||
.addX(1));
|
||||
state.sleep_label.positionX(state.restart_label
|
||||
last_label = state.restart_label;
|
||||
state.sleep_label.positionX(last_label
|
||||
.childrenPosition()
|
||||
.addX(1));
|
||||
state.hibernate_label.positionX(state.sleep_label
|
||||
if (state.config.sleep_cmd != null) {
|
||||
last_label = state.sleep_label;
|
||||
}
|
||||
state.hibernate_label.positionX(last_label
|
||||
.childrenPosition()
|
||||
.addX(1));
|
||||
state.brightness_down_label.positionX(state.hibernate_label
|
||||
if (state.config.hibernate_cmd != null) {
|
||||
last_label = state.hibernate_label;
|
||||
}
|
||||
state.toggle_password_label.positionX(last_label
|
||||
.childrenPosition()
|
||||
.addX(1));
|
||||
state.brightness_up_label.positionXY(state.brightness_down_label
|
||||
last_label = state.toggle_password_label;
|
||||
state.brightness_down_label.positionX(last_label
|
||||
.childrenPosition()
|
||||
.addX(1));
|
||||
if (state.config.brightness_down_key != null) {
|
||||
last_label = state.brightness_down_label;
|
||||
}
|
||||
state.brightness_up_label.positionXY(last_label
|
||||
.childrenPosition()
|
||||
.addX(1));
|
||||
for (state.custom_binds.items) |*item| {
|
||||
|
|
|
|||
|
|
@ -96,6 +96,10 @@ pub fn clear(self: *Text) void {
|
|||
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 {
|
||||
if (maybe_key) |key| {
|
||||
if (key.left or (!insert_mode and (key.h or key.backspace))) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue