code improvement and changes

This commit is contained in:
Ebutuğrab Kızmaz 2024-07-03 22:10:02 +03:00
parent a09086c2b2
commit 77f62c69b6
2 changed files with 11 additions and 9 deletions

View File

@ -2,6 +2,7 @@ authenticating: []const u8 = "authenticating...",
capslock: []const u8 = "capslock", capslock: []const u8 = "capslock",
err_alloc: []const u8 = "failed memory allocation", err_alloc: []const u8 = "failed memory allocation",
err_bounds: []const u8 = "out-of-bounds index", 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_chdir: []const u8 = "failed to open home folder",
err_console_dev: []const u8 = "failed to access console", err_console_dev: []const u8 = "failed to access console",
err_dgn_oob: []const u8 = "log message", err_dgn_oob: []const u8 = "log message",
@ -55,4 +56,4 @@ wayland: []const u8 = "wayland",
xinitrc: [:0]const u8 = "xinitrc", xinitrc: [:0]const u8 = "xinitrc",
x11: []const u8 = "x11", x11: []const u8 = "x11",
brightness_down: []const u8 = "decrease brightness", brightness_down: []const u8 = "decrease brightness",
brightness_up: []const u8 = "increase brigthness", brightness_up: []const u8 = "increase brightness",

View File

@ -501,16 +501,17 @@ pub fn main() !void {
var sleep = std.ChildProcess.init(&[_][]const u8{ "/bin/sh", "-c", sleep_cmd }, allocator); var sleep = std.ChildProcess.init(&[_][]const u8{ "/bin/sh", "-c", sleep_cmd }, allocator);
_ = sleep.spawnAndWait() catch .{}; _ = sleep.spawnAndWait() catch .{};
} }
} else if (pressed_key == brightness_down_key) { } else if (pressed_key == brightness_down_key and unistd.access(&config.brightnessctl[0], unistd.X_OK) == 0) brightness_change: {
if (unistd.access(&config.brightnessctl[0], unistd.X_OK) == 0) { const brightness_str = std.fmt.allocPrint(allocator, "{s}%-", .{config.brightness_change}) catch {
const brightness_str = std.fmt.allocPrint(allocator, "{s}%-", .{config.brightness_change}) catch unreachable; try info_line.setText(lang.err_brightness_change);
defer allocator.free(brightness_str); break :brightness_change;
var brightness = std.ChildProcess.init(&[_][]const u8{ config.brightnessctl, "-q", "s", brightness_str }, allocator); };
_ = brightness.spawnAndWait() catch .{}; 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: { } 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 { const brightness_str = std.fmt.allocPrint(allocator, "+{s}%", .{config.brightness_change}) catch {
try info_line.setText(lang.err_alloc); try info_line.setText(lang.err_brightness_change);
break :brightness_change; break :brightness_change;
}; };
defer allocator.free(brightness_str); defer allocator.free(brightness_str);