diff --git a/res/config.ini b/res/config.ini index 68a39bb..2738c01 100644 --- a/res/config.ini +++ b/res/config.ini @@ -160,3 +160,8 @@ xauth_cmd = /usr/bin/xauth # Xorg desktop environments xsessions = /usr/share/xsessions + +# Brightness control +brightness_down_key = F5 +brightness_up_key = F6 +Brightness_change = 10 \ No newline at end of file diff --git a/src/config/Config.zig b/src/config/Config.zig index bddda19..e7d2c83 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -51,3 +51,7 @@ xinitrc: ?[]const u8 = "~/.xinitrc", x_cmd_setup: []const u8 = build_options.data_directory ++ "/xsetup.sh", xauth_cmd: []const u8 = "/usr/bin/xauth", xsessions: []const u8 = "/usr/share/xsessions", +brightness_down_key: []const u8 = "F5", +brightness_up_key: []const u8 = "F6", +brightnessctl: []const u8 = "/usr/bin/brightnessctl", +brightness_change: []const u8 = "10", diff --git a/src/config/Lang.zig b/src/config/Lang.zig index 8c4051c..cced3e6 100644 --- a/src/config/Lang.zig +++ b/src/config/Lang.zig @@ -54,3 +54,5 @@ sleep: []const u8 = "sleep", wayland: []const u8 = "wayland", xinitrc: [:0]const u8 = "xinitrc", x11: []const u8 = "x11", +brightness_down: []const u8 = "decrease brightness", +brightness_up: []const u8 = "increase brigthness", diff --git a/src/interop.zig b/src/interop.zig index 14ce55a..b378f34 100644 --- a/src/interop.zig +++ b/src/interop.zig @@ -16,6 +16,10 @@ pub const xcb = @cImport({ @cInclude("xcb/xcb.h"); }); +pub const unistd = @cImport({ + @cInclude("unistd.h"); +}); + pub const c_size = u64; pub const c_uid = u32; pub const c_gid = u32; diff --git a/src/main.zig b/src/main.zig index 2d3a747..5fdd554 100644 --- a/src/main.zig +++ b/src/main.zig @@ -18,12 +18,10 @@ const Save = @import("config/Save.zig"); const migrator = @import("config/migrator.zig"); const SharedError = @import("SharedError.zig"); const utils = @import("tui/utils.zig"); -const unistd = @cImport({ - @cInclude("unistd.h"); -}); const Ini = ini.Ini; const termbox = interop.termbox; +const unistd = interop.unistd; var session_pid: std.posix.pid_t = -1; pub fn signalHandler(i: c_int) callconv(.C) void { @@ -248,6 +246,10 @@ pub fn main() !void { const restart_key = try std.fmt.parseInt(u8, config.restart_key[1..], 10); const restart_len = try utils.strWidth(lang.restart); const sleep_key = try std.fmt.parseInt(u8, config.sleep_key[1..], 10); + const brightness_down_key = try std.fmt.parseInt(u8, config.brightness_down_key[1..], 10); + const brightness_down_len = try utils.strWidth(lang.brightness_down); + const brightness_up_key = try std.fmt.parseInt(u8, config.brightness_up_key[1..], 10); + const brightness_up_len = try utils.strWidth(lang.brightness_up); var event: termbox.tb_event = undefined; var run = true; @@ -391,6 +393,20 @@ pub fn main() !void { buffer.drawLabel(lang.restart, length, 0); length += restart_len + 1; + buffer.drawLabel(config.brightness_down_key, length, 0); + length += config.brightness_down_key.len + 1; + buffer.drawLabel(" ", length - 1, 0); + + buffer.drawLabel(lang.brightness_down, length, 0); + length += brightness_down_len + 1; + + buffer.drawLabel(config.brightness_up_key, length, 0); + length += config.brightness_up_key.len + 1; + buffer.drawLabel(" ", length - 1, 0); + + buffer.drawLabel(lang.brightness_up, length, 0); + length += brightness_up_len + 1; + if (config.sleep_cmd != null) { buffer.drawLabel(config.sleep_key, length, 0); length += config.sleep_key.len + 1; @@ -485,15 +501,19 @@ pub fn main() !void { var sleep = std.ChildProcess.init(&[_][]const u8{ "/bin/sh", "-c", sleep_cmd }, allocator); _ = sleep.spawnAndWait() catch .{}; } - } else if (pressed_key == 5) { - if (c_import.access("/usr/bin/brightnessctl", c_import.X_OK) == 0) { - var brightness = std.ChildProcess.init(&[_][]const u8{ "/usr/bin/brightnessctl", "-q", "s", "5%-" }, allocator); - _ = brightness.spawnAndWait()catch.{}; + } else if (pressed_key == brightness_down_key) { + if (unistd.access(&config.brightnessctl[0], unistd.X_OK) == 0) { + const brightness_str = std.fmt.allocPrint(allocator, "{s}%-", .{config.brightness_change}) catch unreachable; + defer allocator.free(brightness_str); + var brightness = std.ChildProcess.init(&[_][]const u8{ config.brightnessctl, "-q", "s", brightness_str }, allocator); + _ = brightness.spawnAndWait() catch .{}; } - } else if (pressed_key == 6) { - if (c_import.access("/usr/bin/brightnessctl", c_import.X_OK) == 0) { - var brightness = std.ChildProcess.init(&[_][]const u8{ "/usr/bin/brightnessctl", "-q", "s", "+5%" }, allocator); - _ = brightness.spawnAndWait()catch.{}; + } else if (pressed_key == brightness_up_key) { + if (unistd.access(&config.brightnessctl[0], unistd.X_OK) == 0) { + const brightness_str = std.fmt.allocPrint(allocator, "+{s}%", .{config.brightness_change}) catch unreachable; + defer allocator.free(brightness_str); + var brightness = std.ChildProcess.init(&[_][]const u8{ config.brightnessctl, "-q", "s", brightness_str }, allocator); + _ = brightness.spawnAndWait() catch .{}; } } },