mirror of https://github.com/fairyglade/ly.git
Allow disabling the brightness control commands (closes #664)
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
parent
9c79137c9f
commit
6079c01a4b
|
@ -58,13 +58,13 @@ box_title = null
|
|||
# Brightness increase command
|
||||
brightness_down_cmd = $PREFIX_DIRECTORY/bin/brightnessctl -q s 10%-
|
||||
|
||||
# Brightness decrease key
|
||||
# Brightness decrease key, or null to disable
|
||||
brightness_down_key = F5
|
||||
|
||||
# Brightness increase command
|
||||
brightness_up_cmd = $PREFIX_DIRECTORY/bin/brightnessctl -q s +10%
|
||||
|
||||
# Brightness increase key
|
||||
# Brightness increase key, or null to disable
|
||||
brightness_up_key = F6
|
||||
|
||||
# Erase password input on failure
|
||||
|
|
|
@ -16,9 +16,9 @@ blank_box: bool = true,
|
|||
border_fg: u32 = 0x00FFFFFF,
|
||||
box_title: ?[]const u8 = null,
|
||||
brightness_down_cmd: [:0]const u8 = build_options.prefix_directory ++ "/bin/brightnessctl -q s 10%-",
|
||||
brightness_down_key: []const u8 = "F5",
|
||||
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",
|
||||
brightness_up_key: ?[]const u8 = "F6",
|
||||
clear_password: bool = false,
|
||||
clock: ?[:0]const u8 = null,
|
||||
cmatrix_fg: u32 = 0x0000FF00,
|
||||
|
|
52
src/main.zig
52
src/main.zig
|
@ -357,9 +357,9 @@ pub fn main() !void {
|
|||
const restart_len = try utils.strWidth(lang.restart);
|
||||
const sleep_key = try std.fmt.parseInt(u8, config.sleep_key[1..], 10);
|
||||
const sleep_len = try utils.strWidth(lang.sleep);
|
||||
const brightness_down_key = try std.fmt.parseInt(u8, config.brightness_down_key[1..], 10);
|
||||
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 utils.strWidth(lang.brightness_down);
|
||||
const brightness_up_key = try std.fmt.parseInt(u8, config.brightness_up_key[1..], 10);
|
||||
const brightness_up_key = if (config.brightness_down_key) |key| try std.fmt.parseInt(u8, key[1..], 10) else null;
|
||||
const brightness_up_len = try utils.strWidth(lang.brightness_up);
|
||||
|
||||
var event: termbox.tb_event = undefined;
|
||||
|
@ -503,20 +503,24 @@ pub fn main() !void {
|
|||
length += sleep_len + 1;
|
||||
}
|
||||
|
||||
buffer.drawLabel(config.brightness_down_key, length, 0);
|
||||
length += config.brightness_down_key.len + 1;
|
||||
if (config.brightness_down_key) |key| {
|
||||
buffer.drawLabel(key, length, 0);
|
||||
length += 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;
|
||||
if (config.brightness_up_key) |key| {
|
||||
buffer.drawLabel(key, length, 0);
|
||||
length += key.len + 1;
|
||||
buffer.drawLabel(" ", length - 1, 0);
|
||||
|
||||
buffer.drawLabel(lang.brightness_up, length, 0);
|
||||
length += brightness_up_len + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (config.box_title) |title| {
|
||||
buffer.drawConfinedLabel(title, buffer.box_x, buffer.box_y - 1, buffer.box_width);
|
||||
|
@ -627,21 +631,14 @@ pub fn main() !void {
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (pressed_key == brightness_down_key or pressed_key == brightness_up_key) {
|
||||
const cmd = if (pressed_key == brightness_down_key) config.brightness_down_cmd else config.brightness_up_cmd;
|
||||
|
||||
var brightness = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", cmd }, allocator);
|
||||
brightness.stdout_behavior = .Ignore;
|
||||
brightness.stderr_behavior = .Ignore;
|
||||
|
||||
handle_brightness_cmd: {
|
||||
const process_result = brightness.spawnAndWait() catch {
|
||||
break :handle_brightness_cmd;
|
||||
};
|
||||
if (process_result.Exited != 0) {
|
||||
} else if (brightness_down_key != null and pressed_key == brightness_down_key.?) {
|
||||
adjustBrightness(allocator, config.brightness_down_cmd) catch {
|
||||
try info_line.addMessage(lang.err_brightness_change, config.error_bg, config.error_fg);
|
||||
}
|
||||
}
|
||||
};
|
||||
} else if (brightness_up_key != null and pressed_key == brightness_up_key.?) {
|
||||
adjustBrightness(allocator, config.brightness_up_cmd) catch {
|
||||
try info_line.addMessage(lang.err_brightness_change, config.error_bg, config.error_fg);
|
||||
};
|
||||
}
|
||||
},
|
||||
termbox.TB_KEY_CTRL_C => run = false,
|
||||
|
@ -832,6 +829,21 @@ pub fn main() !void {
|
|||
}
|
||||
}
|
||||
|
||||
fn adjustBrightness(allocator: std.mem.Allocator, cmd: []const u8) !void {
|
||||
var brightness = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", cmd }, allocator);
|
||||
brightness.stdout_behavior = .Ignore;
|
||||
brightness.stderr_behavior = .Ignore;
|
||||
|
||||
handle_brightness_cmd: {
|
||||
const process_result = brightness.spawnAndWait() catch {
|
||||
break :handle_brightness_cmd;
|
||||
};
|
||||
if (process_result.Exited != 0) {
|
||||
return error.BrightnessChangeFailed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn getAuthErrorMsg(err: anyerror, lang: Lang) []const u8 {
|
||||
return switch (err) {
|
||||
error.GetPasswordNameFailed => lang.err_pwnam,
|
||||
|
|
Loading…
Reference in New Issue