mirror of
https://github.com/fairyglade/ly.git
synced 2026-05-06 15:20:36 +00:00
Fix: battery label positioning, custom keybinds not disappearing on hide_key_hints = false (#970)
## What are the changes about? Fixes battery label positioning in regards to custom binds. Since the label was on the top-left, it only accounted for the first line of built-in keybinds, and it didn't account for the other lines of custom ones. This also fixes the custom keybinds not disappearing on `hide_key_hints = false`, which is my bad. whoops. Also, with https://codeberg.org/fairyglade/ly/pulls/963 being a thing, we should probably think about deprecating this hardcoded battery label in favor of a custom label command, top-left by default. ## What existing issue does this resolve? N/A ## Pre-requisites - [x] I have tested & confirmed the changes work locally - [x] I have run `zig fmt` throughout my changes Reviewed-on: https://codeberg.org/fairyglade/ly/pulls/970 Reviewed-by: AnErrupTion <anerruption+codeberg@disroot.org>
This commit is contained in:
18
src/main.zig
18
src/main.zig
@@ -1153,6 +1153,11 @@ pub fn main(init: std.process.Init) !void {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var iter = custom.binds.iterator();
|
var iter = custom.binds.iterator();
|
||||||
|
defer for (state.custom_binds.items) |*i| {
|
||||||
|
i.lbl.deinit();
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!state.config.hide_key_hints) {
|
||||||
while (iter.next()) |i| {
|
while (iter.next()) |i| {
|
||||||
var concat = try std.mem.concat(state.allocator, u8, &[_][]const u8{ i.key_ptr.*, " ", i.value_ptr.name });
|
var concat = try std.mem.concat(state.allocator, u8, &[_][]const u8{ i.key_ptr.*, " ", i.value_ptr.name });
|
||||||
inline for (@typeInfo(Lang).@"struct".fields) |lang_key| {
|
inline for (@typeInfo(Lang).@"struct".fields) |lang_key| {
|
||||||
@@ -1175,11 +1180,6 @@ pub fn main(init: std.process.Init) !void {
|
|||||||
});
|
});
|
||||||
state.custom_binds.items[state.custom_binds.items.len - 1].lbl.allocator = state.allocator;
|
state.custom_binds.items[state.custom_binds.items.len - 1].lbl.allocator = state.allocator;
|
||||||
}
|
}
|
||||||
defer for (state.custom_binds.items) |*i| {
|
|
||||||
i.lbl.deinit();
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!state.config.hide_key_hints) {
|
|
||||||
try layer2.append(state.allocator, state.shutdown_label.widget());
|
try layer2.append(state.allocator, state.shutdown_label.widget());
|
||||||
try layer2.append(state.allocator, state.restart_label.widget());
|
try layer2.append(state.allocator, state.restart_label.widget());
|
||||||
if (state.config.sleep_cmd != null) {
|
if (state.config.sleep_cmd != null) {
|
||||||
@@ -1940,6 +1940,11 @@ fn updateSessionSpecifier(self: *Label, ptr: *anyopaque) !void {
|
|||||||
fn positionWidgets(ptr: *anyopaque) !void {
|
fn positionWidgets(ptr: *anyopaque) !void {
|
||||||
var state: *UiState = @ptrCast(@alignCast(ptr));
|
var state: *UiState = @ptrCast(@alignCast(ptr));
|
||||||
|
|
||||||
|
// Offsets for custom bind placement. Declared here instead of the
|
||||||
|
// below if stmt as we need these for `battery_label` positioning.
|
||||||
|
var x_offset: usize = 0;
|
||||||
|
// To account for the first row of built-in key hints
|
||||||
|
var y_offset: usize = 1;
|
||||||
if (!state.config.hide_key_hints) {
|
if (!state.config.hide_key_hints) {
|
||||||
state.shutdown_label.positionX(state.edge_margin
|
state.shutdown_label.positionX(state.edge_margin
|
||||||
.add(TerminalBuffer.START_POSITION));
|
.add(TerminalBuffer.START_POSITION));
|
||||||
@@ -1973,8 +1978,6 @@ fn positionWidgets(ptr: *anyopaque) !void {
|
|||||||
state.brightness_up_label.positionXY(last_label
|
state.brightness_up_label.positionXY(last_label
|
||||||
.childrenPosition()
|
.childrenPosition()
|
||||||
.addX(1));
|
.addX(1));
|
||||||
var x_offset: usize = 0;
|
|
||||||
var y_offset: usize = 1;
|
|
||||||
for (state.custom_binds.items) |*item| {
|
for (state.custom_binds.items) |*item| {
|
||||||
item.lbl.positionXY(state.edge_margin
|
item.lbl.positionXY(state.edge_margin
|
||||||
.addY(y_offset)
|
.addY(y_offset)
|
||||||
@@ -1998,6 +2001,7 @@ fn positionWidgets(ptr: *anyopaque) !void {
|
|||||||
state.battery_label.positionXY(state.edge_margin
|
state.battery_label.positionXY(state.edge_margin
|
||||||
.add(TerminalBuffer.START_POSITION)
|
.add(TerminalBuffer.START_POSITION)
|
||||||
.addYFromIf(state.brightness_up_label.childrenPosition(), !state.config.hide_key_hints)
|
.addYFromIf(state.brightness_up_label.childrenPosition(), !state.config.hide_key_hints)
|
||||||
|
.addYIf(y_offset, !state.config.hide_key_hints)
|
||||||
.removeYFromIf(state.edge_margin, !state.config.hide_key_hints));
|
.removeYFromIf(state.edge_margin, !state.config.hide_key_hints));
|
||||||
|
|
||||||
const tty_label_width = if (state.config.show_tty) TerminalBuffer.strWidth(state.tty_label.text) else 0;
|
const tty_label_width = if (state.config.show_tty) TerminalBuffer.strWidth(state.tty_label.text) else 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user