added proper keybinds and configs for brightness control

This commit is contained in:
Ebutuğrab Kızmaz 2024-07-03 20:42:16 +03:00
parent ea941be3ba
commit a24347380f
5 changed files with 46 additions and 11 deletions

View File

@ -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

View File

@ -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",

View File

@ -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",

View File

@ -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;

View File

@ -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 .{};
}
}
},