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 increase command
|
||||||
brightness_down_cmd = $PREFIX_DIRECTORY/bin/brightnessctl -q s 10%-
|
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_down_key = F5
|
||||||
|
|
||||||
# Brightness increase command
|
# Brightness increase command
|
||||||
brightness_up_cmd = $PREFIX_DIRECTORY/bin/brightnessctl -q s +10%
|
brightness_up_cmd = $PREFIX_DIRECTORY/bin/brightnessctl -q s +10%
|
||||||
|
|
||||||
# Brightness increase key
|
# Brightness increase key, or null to disable
|
||||||
brightness_up_key = F6
|
brightness_up_key = F6
|
||||||
|
|
||||||
# Erase password input on failure
|
# Erase password input on failure
|
||||||
|
|
|
@ -16,9 +16,9 @@ blank_box: bool = true,
|
||||||
border_fg: u32 = 0x00FFFFFF,
|
border_fg: u32 = 0x00FFFFFF,
|
||||||
box_title: ?[]const u8 = null,
|
box_title: ?[]const u8 = null,
|
||||||
brightness_down_cmd: [:0]const u8 = build_options.prefix_directory ++ "/bin/brightnessctl -q s 10%-",
|
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_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,
|
clear_password: bool = false,
|
||||||
clock: ?[:0]const u8 = null,
|
clock: ?[:0]const u8 = null,
|
||||||
cmatrix_fg: u32 = 0x0000FF00,
|
cmatrix_fg: u32 = 0x0000FF00,
|
||||||
|
|
66
src/main.zig
66
src/main.zig
|
@ -357,9 +357,9 @@ pub fn main() !void {
|
||||||
const restart_len = try utils.strWidth(lang.restart);
|
const restart_len = try utils.strWidth(lang.restart);
|
||||||
const sleep_key = try std.fmt.parseInt(u8, config.sleep_key[1..], 10);
|
const sleep_key = try std.fmt.parseInt(u8, config.sleep_key[1..], 10);
|
||||||
const sleep_len = try utils.strWidth(lang.sleep);
|
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_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);
|
const brightness_up_len = try utils.strWidth(lang.brightness_up);
|
||||||
|
|
||||||
var event: termbox.tb_event = undefined;
|
var event: termbox.tb_event = undefined;
|
||||||
|
@ -503,19 +503,23 @@ pub fn main() !void {
|
||||||
length += sleep_len + 1;
|
length += sleep_len + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.drawLabel(config.brightness_down_key, length, 0);
|
if (config.brightness_down_key) |key| {
|
||||||
length += config.brightness_down_key.len + 1;
|
buffer.drawLabel(key, length, 0);
|
||||||
buffer.drawLabel(" ", length - 1, 0);
|
length += key.len + 1;
|
||||||
|
buffer.drawLabel(" ", length - 1, 0);
|
||||||
|
|
||||||
buffer.drawLabel(lang.brightness_down, length, 0);
|
buffer.drawLabel(lang.brightness_down, length, 0);
|
||||||
length += brightness_down_len + 1;
|
length += brightness_down_len + 1;
|
||||||
|
}
|
||||||
|
|
||||||
buffer.drawLabel(config.brightness_up_key, length, 0);
|
if (config.brightness_up_key) |key| {
|
||||||
length += config.brightness_up_key.len + 1;
|
buffer.drawLabel(key, length, 0);
|
||||||
buffer.drawLabel(" ", length - 1, 0);
|
length += key.len + 1;
|
||||||
|
buffer.drawLabel(" ", length - 1, 0);
|
||||||
|
|
||||||
buffer.drawLabel(lang.brightness_up, length, 0);
|
buffer.drawLabel(lang.brightness_up, length, 0);
|
||||||
length += brightness_up_len + 1;
|
length += brightness_up_len + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.box_title) |title| {
|
if (config.box_title) |title| {
|
||||||
|
@ -627,21 +631,14 @@ pub fn main() !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (pressed_key == brightness_down_key or pressed_key == brightness_up_key) {
|
} else if (brightness_down_key != null and pressed_key == brightness_down_key.?) {
|
||||||
const cmd = if (pressed_key == brightness_down_key) config.brightness_down_cmd else config.brightness_up_cmd;
|
adjustBrightness(allocator, config.brightness_down_cmd) catch {
|
||||||
|
try info_line.addMessage(lang.err_brightness_change, config.error_bg, config.error_fg);
|
||||||
var brightness = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", cmd }, allocator);
|
};
|
||||||
brightness.stdout_behavior = .Ignore;
|
} else if (brightness_up_key != null and pressed_key == brightness_up_key.?) {
|
||||||
brightness.stderr_behavior = .Ignore;
|
adjustBrightness(allocator, config.brightness_up_cmd) catch {
|
||||||
|
try info_line.addMessage(lang.err_brightness_change, config.error_bg, config.error_fg);
|
||||||
handle_brightness_cmd: {
|
};
|
||||||
const process_result = brightness.spawnAndWait() catch {
|
|
||||||
break :handle_brightness_cmd;
|
|
||||||
};
|
|
||||||
if (process_result.Exited != 0) {
|
|
||||||
try info_line.addMessage(lang.err_brightness_change, config.error_bg, config.error_fg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
termbox.TB_KEY_CTRL_C => run = false,
|
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 {
|
fn getAuthErrorMsg(err: anyerror, lang: Lang) []const u8 {
|
||||||
return switch (err) {
|
return switch (err) {
|
||||||
error.GetPasswordNameFailed => lang.err_pwnam,
|
error.GetPasswordNameFailed => lang.err_pwnam,
|
||||||
|
|
Loading…
Reference in New Issue