mirror of
https://github.com/fairyglade/ly.git
synced 2025-12-20 19:24:53 +00:00
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:
@@ -51,6 +51,8 @@ gameoflife_fg: u32 = 0x0000FF00,
|
||||
gameoflife_entropy_interval: usize = 10,
|
||||
gameoflife_frame_delay: usize = 6,
|
||||
gameoflife_initial_density: f32 = 0.4,
|
||||
hibernate_cmd: ?[]const u8 = null,
|
||||
hibernate_key: []const u8 = "F4",
|
||||
hide_borders: bool = false,
|
||||
hide_key_hints: bool = false,
|
||||
hide_keyboard_locks: bool = false,
|
||||
|
||||
@@ -20,6 +20,7 @@ err_domain: []const u8 = "invalid domain",
|
||||
err_empty_password: []const u8 = "empty password not allowed",
|
||||
err_envlist: []const u8 = "failed to get envlist",
|
||||
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_lock_state: []const u8 = "failed to get lock state",
|
||||
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_xsessions_dir: []const u8 = "failed to find sessions folder",
|
||||
err_xsessions_open: []const u8 = "failed to open sessions folder",
|
||||
hibernate: []const u8 = "hibernate",
|
||||
insert: []const u8 = "insert",
|
||||
login: []const u8 = "login",
|
||||
logout: []const u8 = "logged out",
|
||||
|
||||
27
src/main.zig
27
src/main.zig
@@ -540,6 +540,8 @@ pub fn main() !void {
|
||||
const restart_len = try TerminalBuffer.strWidth(lang.restart);
|
||||
const sleep_key = try std.fmt.parseInt(u8, config.sleep_key[1..], 10);
|
||||
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_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;
|
||||
@@ -727,6 +729,15 @@ pub fn main() !void {
|
||||
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| {
|
||||
buffer.drawLabel(key, length, config.edge_margin);
|
||||
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.?) {
|
||||
adjustBrightness(allocator, config.brightness_down_cmd) catch |err| {
|
||||
try info_line.addMessage(lang.err_brightness_change, config.error_bg, config.error_fg);
|
||||
|
||||
Reference in New Issue
Block a user