mirror of
https://github.com/fairyglade/ly.git
synced 2025-12-20 19:24:53 +00:00
Fix merge conflict
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
@@ -18,9 +18,9 @@ bigclock_seconds: bool = false,
|
||||
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_cmd: [:0]const u8 = build_options.prefix_directory ++ "/bin/brightnessctl -q -n s 10%-",
|
||||
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 -n s +10%",
|
||||
brightness_up_key: ?[]const u8 = "F6",
|
||||
clear_password: bool = false,
|
||||
clock: ?[:0]const u8 = null,
|
||||
@@ -49,6 +49,7 @@ gameoflife_initial_density: f32 = 0.4,
|
||||
hide_borders: bool = false,
|
||||
hide_version_string: bool = false,
|
||||
hide_key_hints: bool = false,
|
||||
battery_id: ?[]const u8 = "BAT0",
|
||||
initial_info_text: ?[]const u8 = null,
|
||||
input_len: u8 = 34,
|
||||
lang: []const u8 = "en",
|
||||
|
||||
@@ -47,6 +47,7 @@ err_perm_group: []const u8 = "failed to downgrade group permissions",
|
||||
err_perm_user: []const u8 = "failed to downgrade user permissions",
|
||||
err_pwnam: []const u8 = "failed to get user info",
|
||||
err_sleep: []const u8 = "failed to execute sleep command",
|
||||
err_battery: []const u8 = "failed to load battery status",
|
||||
err_switch_tty: []const u8 = "failed to switch tty",
|
||||
err_tty_ctrl: []const u8 = "tty control transfer failed",
|
||||
err_no_users: []const u8 = "no users found",
|
||||
|
||||
37
src/main.zig
37
src/main.zig
@@ -33,7 +33,7 @@ const DisplayServer = enums.DisplayServer;
|
||||
const Entry = Environment.Entry;
|
||||
const termbox = interop.termbox;
|
||||
const temporary_allocator = std.heap.page_allocator;
|
||||
const ly_top_str = "Ly version " ++ build_options.version;
|
||||
const ly_version_str = "Ly version " ++ build_options.version;
|
||||
|
||||
var session_pid: std.posix.pid_t = -1;
|
||||
fn signalHandler(i: c_int) callconv(.c) void {
|
||||
@@ -589,8 +589,23 @@ pub fn main() !void {
|
||||
if (!animation_timed_out) animation.draw();
|
||||
|
||||
if (!config.hide_version_string) {
|
||||
buffer.drawLabel(ly_top_str, length, 0);
|
||||
length += ly_top_str.len + 1;
|
||||
buffer.drawLabel(ly_version_str, 0, buffer.height - 1);
|
||||
}
|
||||
|
||||
var battery_bar_shown = false;
|
||||
if (config.battery_id) |id| draw_battery: {
|
||||
const battery_percentage = getBatteryPercentage(id) catch |err| {
|
||||
try log_writer.print("failed to get battery percentage: {s}\n", .{@errorName(err)});
|
||||
try info_line.addMessage(lang.err_battery, config.error_bg, config.error_fg);
|
||||
break :draw_battery;
|
||||
};
|
||||
|
||||
var battery_buf: [16:0]u8 = undefined;
|
||||
const battery_str = std.fmt.bufPrintZ(&battery_buf, "BAT: {d}%", .{battery_percentage}) catch break :draw_battery;
|
||||
|
||||
const battery_y: usize = if (config.hide_key_hints) 0 else 1;
|
||||
buffer.drawLabel(battery_str, 0, battery_y);
|
||||
battery_bar_shown = true;
|
||||
}
|
||||
|
||||
if (config.bigclock != .none and buffer.box_height + (bigclock.HEIGHT + 2) * 2 < buffer.height) {
|
||||
@@ -1194,6 +1209,22 @@ fn adjustBrightness(allocator: std.mem.Allocator, cmd: []const u8) !void {
|
||||
}
|
||||
}
|
||||
|
||||
fn getBatteryPercentage(battery_id: []const u8) !u8 {
|
||||
const path = try std.fmt.allocPrint(temporary_allocator, "/sys/class/power_supply/{s}/capacity", .{battery_id});
|
||||
defer temporary_allocator.free(path);
|
||||
|
||||
const battery_file = try std.fs.cwd().openFile(path, .{});
|
||||
defer battery_file.close();
|
||||
|
||||
var buffer: [8]u8 = undefined;
|
||||
const bytes_read = try battery_file.read(&buffer);
|
||||
const capacity_str = buffer[0..bytes_read];
|
||||
|
||||
const trimmed = std.mem.trimRight(u8, capacity_str, "\n\r");
|
||||
|
||||
return try std.fmt.parseInt(u8, trimmed, 10);
|
||||
}
|
||||
|
||||
fn getAuthErrorMsg(err: anyerror, lang: Lang) []const u8 {
|
||||
return switch (err) {
|
||||
error.GetPasswordNameFailed => lang.err_pwnam,
|
||||
|
||||
Reference in New Issue
Block a user