From b8048234d97fc48079d7a293fe811cd36c1840a4 Mon Sep 17 00:00:00 2001 From: Jackson Delahunt Date: Wed, 1 Apr 2026 18:51:37 +0200 Subject: [PATCH] config: add show_tty option to display active TTY in top right corner (#956) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When running multiple ly instances across different TTYs there is no way to tell which TTY a given login screen belongs to at a glance. This change adds a `show_tty` boolean config option (default `false`) that displays the active TTY number (e.g. `tty3`) in the top right corner. When the clock is also enabled the TTY label sits immediately to its right on the same row. When the clock is disabled it occupies the top right corner on its own. I'm open to advice from the maintainers on the placement of the TTY label — positioning it next to the clock is simply my personal preference and it doesn't need to stay there if a different position is more appropriate. Co-authored-by: Jackson Delahunt Reviewed-on: https://codeberg.org/fairyglade/ly/pulls/956 Reviewed-by: AnErrupTion Co-authored-by: Jackson Delahunt Co-committed-by: Jackson Delahunt --- res/config.ini | 5 +++++ src/config/Config.zig | 1 + src/main.zig | 28 +++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/res/config.ini b/res/config.ini index 52ed290..4970520 100644 --- a/res/config.ini +++ b/res/config.ini @@ -333,6 +333,11 @@ setup_cmd = $CONFIG_DIRECTORY/ly/setup.sh # Specifies the key combination used for showing the password show_password_key = F7 +# Display the active TTY number (e.g. tty3) to the right of the clock in the top right corner +# If the clock is disabled, the TTY label occupies the top right corner on its own +# If false, the TTY number will not be shown +show_tty = false + # Command executed when pressing shutdown_key shutdown_cmd = /sbin/shutdown $PLATFORM_SHUTDOWN_ARG now diff --git a/src/config/Config.zig b/src/config/Config.zig index 1bff3c0..c0a4350 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -84,6 +84,7 @@ service_name: [:0]const u8 = "ly", session_log: ?[]const u8 = "ly-session.log", setup_cmd: []const u8 = build_options.config_directory ++ "/ly/setup.sh", show_password_key: []const u8 = "F7", +show_tty: bool = false, shutdown_cmd: []const u8 = "/sbin/shutdown -a now", shutdown_key: []const u8 = "F1", sleep_cmd: ?[]const u8 = null, diff --git a/src/main.zig b/src/main.zig index 38da21f..08c5177 100644 --- a/src/main.zig +++ b/src/main.zig @@ -94,6 +94,7 @@ const UiState = struct { capslock_label: Label, battery_label: Label, clock_label: Label, + tty_label: Label, session_specifier_label: Label, login_label: Label, password_label: Label, @@ -118,6 +119,7 @@ const UiState = struct { battery_buf: [16:0]u8, bigclock_format_buf: [16:0]u8, clock_buf: [64:0]u8, + tty_buf: [8:0]u8, bigclock_buf: [32:0]u8, custom_binds: std.ArrayList(CustomBindLabel), custom_info: std.ArrayList(CustomInfoLabel), @@ -541,6 +543,16 @@ pub fn main() !void { ); defer state.clock_label.deinit(); + state.tty_label = Label.init( + "", + null, + state.buffer.fg, + state.buffer.bg, + null, + null, + ); + defer state.tty_label.deinit(); + state.bigclock_label = BigLabel.init( &state.buffer, "", @@ -945,6 +957,10 @@ pub fn main() !void { }; } + if (state.config.show_tty) { + try state.tty_label.setTextBuf(&state.tty_buf, "tty{d}", .{state.active_tty}); + } + // Initialize the animation, if any var animation: ?*Widget = null; switch (state.config.animation) { @@ -1152,6 +1168,9 @@ pub fn main() !void { if (state.config.clock != null) { try layer2.append(state.allocator, state.clock_label.widget()); } + if (state.config.show_tty) { + try layer2.append(state.allocator, state.tty_label.widget()); + } if (state.config.bigclock != .none) { try layer2.append(state.allocator, state.bigclock_label.widget()); } @@ -1922,10 +1941,17 @@ fn positionWidgets(ptr: *anyopaque) !void { .add(TerminalBuffer.START_POSITION) .addYFromIf(state.brightness_up_label.childrenPosition(), !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_gap = if (state.config.show_tty and state.config.clock != null) @as(usize, 1) else 0; + state.tty_label.positionXY(state.edge_margin + .add(TerminalBuffer.START_POSITION) + .invertX(state.buffer.width) + .removeXIf(tty_label_width, state.buffer.width > tty_label_width + state.edge_margin.x)); state.clock_label.positionXY(state.edge_margin .add(TerminalBuffer.START_POSITION) .invertX(state.buffer.width) - .removeXIf(TerminalBuffer.strWidth(state.clock_label.text), state.buffer.width > TerminalBuffer.strWidth(state.clock_label.text) + state.edge_margin.x)); + .removeXIf(TerminalBuffer.strWidth(state.clock_label.text) + tty_label_width + tty_label_gap, state.buffer.width > TerminalBuffer.strWidth(state.clock_label.text) + tty_label_width + tty_label_gap + state.edge_margin.x)); state.numlock_label.positionX(state.edge_margin .add(TerminalBuffer.START_POSITION)