Refactor brightness handling code

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion
2024-08-06 18:40:24 +02:00
parent f0869f0e13
commit 096b1a7d44
3 changed files with 11 additions and 21 deletions

View File

@@ -53,18 +53,18 @@ border_fg = 8
# If set to null, none will be shown
box_title = null
# Brightness +/- percentage in one step
brightness_change = 10
# Brightness increase command
brightness_down_cmd = $PREFIX_DIRECTORY/bin/brightnessctl -q s 10%-
# Brightness decrease key
brightness_down_key = F5
# Brightness increase command
brightness_up_cmd = $PREFIX_DIRECTORY/bin/brightnessctl -q s +10%
# Brightness increase key
brightness_up_key = F6
# Brightness control command
brightnessctl = $PREFIX_DIRECTORY/bin/brightnessctl
# Erase password input on failure
clear_password = false

View File

@@ -14,10 +14,10 @@ bigclock: bool = false,
blank_box: bool = true,
border_fg: u16 = 8,
box_title: ?[]const u8 = null,
brightness_change: []const u8 = "10",
brightness_down_cmd: [:0]const u8 = build_options.prefix_directory ++ "/bin/brightnessctl -q s 10%-",
brightness_down_key: []const u8 = "F5",
brightness_up_cmd: [:0]const u8 = build_options.prefix_directory ++ "/bin/brightnessctl -q s +10%",
brightness_up_key: []const u8 = "F6",
brightnessctl: [:0]const u8 = build_options.prefix_directory ++ "/bin/brightnessctl",
clear_password: bool = false,
clock: ?[:0]const u8 = null,
cmatrix_fg: u16 = 3,

View File

@@ -582,21 +582,11 @@ pub fn main() !void {
var sleep = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", sleep_cmd }, allocator);
_ = sleep.spawnAndWait() catch .{};
}
} else if (pressed_key == brightness_down_key and unistd.access(config.brightnessctl, unistd.X_OK) == 0) brightness_change: {
const brightness_str = std.fmt.allocPrint(allocator, "{s}%-", .{config.brightness_change}) catch {
try info_line.addMessage(lang.err_brightness_change, config.error_bg, config.error_fg);
break :brightness_change;
};
defer allocator.free(brightness_str);
var brightness = std.process.Child.init(&[_][]const u8{ config.brightnessctl, "-q", "s", brightness_str }, allocator);
} else if (pressed_key == brightness_down_key) {
var brightness = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", config.brightness_down_cmd }, allocator);
_ = brightness.spawnAndWait() catch .{};
} else if (pressed_key == brightness_up_key and unistd.access(config.brightnessctl, unistd.X_OK) == 0) brightness_change: {
const brightness_str = std.fmt.allocPrint(allocator, "+{s}%", .{config.brightness_change}) catch {
try info_line.addMessage(lang.err_brightness_change, config.error_bg, config.error_fg);
break :brightness_change;
};
defer allocator.free(brightness_str);
var brightness = std.process.Child.init(&[_][]const u8{ config.brightnessctl, "-q", "s", brightness_str }, allocator);
} else if (pressed_key == brightness_up_key) {
var brightness = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", config.brightness_up_cmd }, allocator);
_ = brightness.spawnAndWait() catch .{};
}
},