Added options to move the box

This commit is contained in:
MartorSkull 2026-04-18 21:04:01 +02:00
commit 84486c4e18
3 changed files with 36 additions and 10 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

@ -1965,22 +1965,38 @@ fn positionWidgets(ptr: *anyopaque) !void {
.childrenPosition()
.removeX(TerminalBuffer.strWidth(state.lang.numlock) + TerminalBuffer.strWidth(state.lang.capslock) + 1));
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));
var bb_height = state.box.height;
var bb_width = state.box.width;
const clock_text_len = TerminalBuffer.strWidth(state.bigclock_label.text) * (BigLabel.CHAR_WIDTH + 1);
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;
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));
bb_height += BigLabel.CHAR_HEIGHT + 2;
bb_width = @max(bb_width, clock_text_len);
}
const max_v_position: f32 = @floatFromInt(state.buffer.height - bb_height - 1);
const max_h_position: f32 = @floatFromInt(state.buffer.width - bb_width - 1);
bb_height = @min(bb_height, state.buffer.height - 2);
bb_width = @min(bb_width, state.buffer.width - 2);
const v_space: f32 = @floatFromInt(state.buffer.height - bb_height);
const v_position: usize = @intFromFloat(
@min(@max(1.0, v_space * state.config.box_v_position), max_v_position));
const h_space: f32 = @floatFromInt(state.buffer.width - bb_width);
const h_position: usize = @intFromFloat(
@min(@max(1.0, h_space * state.config.box_h_position), max_h_position));
if (state.config.bigclock != .none) {
state.bigclock_label.positionXY(TerminalBuffer.START_POSITION
.addX(h_position + (bb_width - clock_text_len) / 2)
.addY(v_position));
}
state.box.positionXY(TerminalBuffer.START_POSITION
.addX(h_position + (bb_width - state.box.width) / 2)
.addY(v_position + (bb_height - state.box.height)));
state.info_line.label.positionY(state.box
.childrenPosition());