mirror of
https://github.com/fairyglade/ly.git
synced 2026-05-06 07:10:36 +00:00
fix: custom label and bind ordering (#951)
## What are the changes about? Fixes the order of custom labels and binds because of a HashMap shenanigan (no guaranteed order), so we use `ArrayHashMap` instead which preserves insertion order. They should now be shown in the order they are declared in the config.   ## What existing issue does this resolve? !950 ## 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/951 Reviewed-by: AnErrupTion <anerruption+codeberg@disroot.org> Co-authored-by: RadsammyT <radsammyt@gmail.com> Co-committed-by: RadsammyT <radsammyt@gmail.com>
This commit is contained in:
@@ -21,5 +21,5 @@ pub const CustomCommandInfo = struct {
|
|||||||
counter: u32 = 0,
|
counter: u32 = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub var binds: std.StringHashMap(CustomCommandBind) = undefined;
|
pub var binds: std.StringArrayHashMap(CustomCommandBind) = undefined;
|
||||||
pub var labels: std.StringHashMap(CustomCommandInfo) = undefined;
|
pub var labels: std.StringArrayHashMap(CustomCommandInfo) = undefined;
|
||||||
|
|||||||
36
src/main.zig
36
src/main.zig
@@ -225,20 +225,20 @@ pub fn main() !void {
|
|||||||
var config_parser = try IniParser(Config).init(state.allocator, config_path, migrator.configFieldHandler);
|
var config_parser = try IniParser(Config).init(state.allocator, config_path, migrator.configFieldHandler);
|
||||||
defer config_parser.deinit();
|
defer config_parser.deinit();
|
||||||
defer if (!shutdown or !restart) {
|
defer if (!shutdown or !restart) {
|
||||||
var iter = custom.binds.iterator();
|
var iter = custom.binds.iterator();
|
||||||
while (iter.next()) |i| {
|
while (iter.next()) |i| {
|
||||||
temporary_allocator.free(i.key_ptr.*);
|
temporary_allocator.free(i.key_ptr.*);
|
||||||
temporary_allocator.free(i.value_ptr.*.cmd);
|
temporary_allocator.free(i.value_ptr.*.cmd);
|
||||||
temporary_allocator.free(i.value_ptr.*.name);
|
temporary_allocator.free(i.value_ptr.*.name);
|
||||||
}
|
}
|
||||||
custom.binds.deinit();
|
custom.binds.deinit();
|
||||||
var labelIter = custom.labels.iterator();
|
var labelIter = custom.labels.iterator();
|
||||||
while (labelIter.next()) |i| {
|
while (labelIter.next()) |i| {
|
||||||
temporary_allocator.free(i.key_ptr.*);
|
temporary_allocator.free(i.key_ptr.*);
|
||||||
if (i.value_ptr.cmd) |cmd|
|
if (i.value_ptr.cmd) |cmd|
|
||||||
temporary_allocator.free(cmd);
|
temporary_allocator.free(cmd);
|
||||||
}
|
}
|
||||||
custom.labels.deinit();
|
custom.labels.deinit();
|
||||||
};
|
};
|
||||||
|
|
||||||
state.config = config_parser.structure;
|
state.config = config_parser.structure;
|
||||||
@@ -1096,7 +1096,7 @@ pub fn main() !void {
|
|||||||
latest.info.counter = 1;
|
latest.info.counter = 1;
|
||||||
}
|
}
|
||||||
defer for (state.custom_info.items) |*item| {
|
defer for (state.custom_info.items) |*item| {
|
||||||
item.lbl.deinit();
|
item.lbl.deinit();
|
||||||
};
|
};
|
||||||
|
|
||||||
var iter = custom.binds.iterator();
|
var iter = custom.binds.iterator();
|
||||||
@@ -1122,7 +1122,7 @@ pub fn main() !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| {
|
defer for (state.custom_binds.items) |*i| {
|
||||||
i.lbl.deinit();
|
i.lbl.deinit();
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!state.config.hide_key_hints) {
|
if (!state.config.hide_key_hints) {
|
||||||
@@ -1907,11 +1907,11 @@ fn positionWidgets(ptr: *anyopaque) !void {
|
|||||||
}
|
}
|
||||||
for (state.custom_info.items, 0..) |*item, i| {
|
for (state.custom_info.items, 0..) |*item, i| {
|
||||||
item.lbl.positionXY(state.edge_margin
|
item.lbl.positionXY(state.edge_margin
|
||||||
.addY(@intCast(i))
|
|
||||||
.invertX(state.buffer.width)
|
.invertX(state.buffer.width)
|
||||||
.removeX(item.lbl.text.len)
|
.removeX(item.lbl.text.len)
|
||||||
.invertY(state.buffer.height)
|
.invertY(state.buffer.height)
|
||||||
.removeY(1));
|
.removeY(state.custom_info.items.len)
|
||||||
|
.addY(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
state.battery_label.positionXY(state.edge_margin
|
state.battery_label.positionXY(state.edge_margin
|
||||||
|
|||||||
Reference in New Issue
Block a user