Added option to move the box relative to the screen size

This commit is contained in:
MartorSkull 2026-04-16 04:39:13 +02:00
parent eec83179b9
commit fcd105466e
3 changed files with 35 additions and 11 deletions

View File

@ -101,6 +101,14 @@ border_fg = 0x00FFFFFF
# If set to null, none will be shown
box_title = null
# Relative horizontal position from the end of the screen
# default: 0.5 (center)
box_h_position = 0.5
# Relative vertical position from the bottom of the screen
# default: 0.5 (center)
box_v_position = 0.5
# Brightness decrease command
brightness_down_cmd = $PREFIX_DIRECTORY/bin/brightnessctl -q -n s 10%-

View File

@ -24,6 +24,8 @@ bigclock_seconds: bool = false,
blank_box: bool = true,
border_fg: u32 = 0x00FFFFFF,
box_title: ?[]const u8 = null,
box_h_position: f32 = 0.5,
box_v_position: f32 = 0.5,
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 -n s +10%",

View File

@ -219,12 +219,17 @@ pub fn main() !void {
state.allocator.free(state.old_save_path);
};
const config_path = try std.fs.path.join(state.allocator, &[_][]const u8{ config_parent_path, "config.ini" });
const config_path = try std.fs.path.join(
state.allocator,
&[_][]const u8{ config_parent_path, "config.ini" });
defer state.allocator.free(config_path);
custom.binds = .init(state.allocator);
custom.labels = .init(state.allocator);
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 if (!shutdown or !restart) {
var iter = custom.binds.iterator();
@ -1965,20 +1970,29 @@ fn positionWidgets(ptr: *anyopaque) !void {
.childrenPosition()
.removeX(TerminalBuffer.strWidth(state.lang.numlock) + TerminalBuffer.strWidth(state.lang.capslock) + 1));
const v_center = @as(f32, @floatFromInt(state.buffer.height)) * state.config.box_v_position;
const v_position = @max(1, v_center - @as(f32, @floatFromInt(state.box.height)) * state.config.box_v_position);
const h_center = @as(f32, @floatFromInt(state.buffer.width)) * state.config.box_h_position;
const h_position = @max(1, h_center - @as(f32, @floatFromInt(state.box.width)) * state.config.box_h_position);
state.box.positionXY(TerminalBuffer.START_POSITION
.addX((state.buffer.width - @min(state.buffer.width - 2, state.box.width)) / 2)
.addY((state.buffer.height - @min(state.buffer.height - 2, state.box.height)) / 2));
.addX(@intFromFloat(h_position))
.addY(@intFromFloat(v_position)));
if (state.config.bigclock != .none) {
const half_width = state.buffer.width / 2;
const half_label_width = (TerminalBuffer.strWidth(state.bigclock_label.text) * (BigLabel.CHAR_WIDTH + 1)) / 2;
const half_height = (if (state.buffer.height > state.box.height) state.buffer.height - state.box.height else state.buffer.height) / 2;
const bc_v_position = v_position - BigLabel.CHAR_HEIGHT - 2;
const bc_h_offset: f32 = @floatFromInt(TerminalBuffer.strWidth(state.bigclock_label.text) * (BigLabel.CHAR_WIDTH + 1));
const bc_h_position = h_position + (@as(f32, @floatFromInt(state.box.width)) - bc_h_offset) / 2;
state.box.positionXY(state.box.left_pos
.removeXIf(@intFromFloat(bc_h_position - 2), bc_h_position < 0)
.removeYIf(@intFromFloat(bc_v_position - 2), bc_v_position < 0));
state.bigclock_label.positionXY(TerminalBuffer.START_POSITION
.addX(half_width)
.removeXIf(half_label_width, half_width > half_label_width)
.addY(half_height)
.removeYIf(BigLabel.CHAR_HEIGHT + 2, half_height > BigLabel.CHAR_HEIGHT + 2));
.addX(1)
.addXIf(@intFromFloat(bc_h_position - 1), bc_h_position >= 0)
.addY(1)
.addYIf(@intFromFloat(bc_v_position - 1), bc_v_position >= 0));
}
state.info_line.label.positionY(state.box