mirror of https://github.com/fairyglade/ly.git
Add brightness control support with brightnessctl (#626)
* Added key binds to control brightness I added keybinds to control brightness with brightnessctl. F5 to decrease brightness. f6 to increase brightness. * Update src/main.zig Co-authored-by: ShiningLea <anerruption@disroot.org> * added proper keybinds and configs for brightness control * Update src/main.zig Co-authored-by: ShiningLea <anerruption@disroot.org> * code improvement and changes * updated en.ini --------- Co-authored-by: ShiningLea <anerruption@disroot.org>
This commit is contained in:
parent
cbe7b37564
commit
dc8d143fac
|
@ -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
|
|
@ -2,6 +2,7 @@ authenticating = authenticating...
|
|||
capslock = capslock
|
||||
err_alloc = failed memory allocation
|
||||
err_bounds = out-of-bounds index
|
||||
err_brightness_change = failed to change brightness
|
||||
err_chdir = failed to open home folder
|
||||
err_console_dev = failed to access console
|
||||
err_dgn_oob = log message
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -2,6 +2,7 @@ authenticating: []const u8 = "authenticating...",
|
|||
capslock: []const u8 = "capslock",
|
||||
err_alloc: []const u8 = "failed memory allocation",
|
||||
err_bounds: []const u8 = "out-of-bounds index",
|
||||
err_brightness_change: []const u8 = "failed to change brightness",
|
||||
err_chdir: []const u8 = "failed to open home folder",
|
||||
err_console_dev: []const u8 = "failed to access console",
|
||||
err_dgn_oob: []const u8 = "log message",
|
||||
|
@ -54,3 +55,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 brightness",
|
||||
|
|
|
@ -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;
|
||||
|
|
35
src/main.zig
35
src/main.zig
|
@ -21,6 +21,7 @@ const utils = @import("tui/utils.zig");
|
|||
|
||||
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 {
|
||||
|
@ -245,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;
|
||||
|
@ -388,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;
|
||||
|
@ -482,6 +501,22 @@ pub fn main() !void {
|
|||
var sleep = std.ChildProcess.init(&[_][]const u8{ "/bin/sh", "-c", sleep_cmd }, allocator);
|
||||
_ = sleep.spawnAndWait() catch .{};
|
||||
}
|
||||
} else if (pressed_key == brightness_down_key and unistd.access(&config.brightnessctl[0], unistd.X_OK) == 0) brightness_change: {
|
||||
const brightness_str = std.fmt.allocPrint(allocator, "{s}%-", .{config.brightness_change}) catch {
|
||||
try info_line.setText(lang.err_brightness_change);
|
||||
break :brightness_change;
|
||||
};
|
||||
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 == brightness_up_key and unistd.access(&config.brightnessctl[0], unistd.X_OK) == 0) brightness_change: {
|
||||
const brightness_str = std.fmt.allocPrint(allocator, "+{s}%", .{config.brightness_change}) catch {
|
||||
try info_line.setText(lang.err_brightness_change);
|
||||
break :brightness_change;
|
||||
};
|
||||
defer allocator.free(brightness_str);
|
||||
var brightness = std.ChildProcess.init(&[_][]const u8{ config.brightnessctl, "-q", "s", brightness_str }, allocator);
|
||||
_ = brightness.spawnAndWait() catch .{};
|
||||
}
|
||||
},
|
||||
termbox.TB_KEY_CTRL_C => run = false,
|
||||
|
|
Loading…
Reference in New Issue