config: add show_tty option to display active TTY in top right corner (#956)

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 <jackson@stemn.com>
Reviewed-on: https://codeberg.org/fairyglade/ly/pulls/956
Reviewed-by: AnErrupTion <anerruption+codeberg@disroot.org>
Co-authored-by: Jackson Delahunt <sabrehagen@noreply.codeberg.org>
Co-committed-by: Jackson Delahunt <sabrehagen@noreply.codeberg.org>
This commit is contained in:
Jackson Delahunt
2026-04-01 18:51:37 +02:00
committed by AnErrupTion
parent 10a873acb9
commit b8048234d9
3 changed files with 33 additions and 1 deletions

View File

@@ -333,6 +333,11 @@ setup_cmd = $CONFIG_DIRECTORY/ly/setup.sh
# Specifies the key combination used for showing the password # Specifies the key combination used for showing the password
show_password_key = F7 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 # Command executed when pressing shutdown_key
shutdown_cmd = /sbin/shutdown $PLATFORM_SHUTDOWN_ARG now shutdown_cmd = /sbin/shutdown $PLATFORM_SHUTDOWN_ARG now

View File

@@ -84,6 +84,7 @@ service_name: [:0]const u8 = "ly",
session_log: ?[]const u8 = "ly-session.log", session_log: ?[]const u8 = "ly-session.log",
setup_cmd: []const u8 = build_options.config_directory ++ "/ly/setup.sh", setup_cmd: []const u8 = build_options.config_directory ++ "/ly/setup.sh",
show_password_key: []const u8 = "F7", show_password_key: []const u8 = "F7",
show_tty: bool = false,
shutdown_cmd: []const u8 = "/sbin/shutdown -a now", shutdown_cmd: []const u8 = "/sbin/shutdown -a now",
shutdown_key: []const u8 = "F1", shutdown_key: []const u8 = "F1",
sleep_cmd: ?[]const u8 = null, sleep_cmd: ?[]const u8 = null,

View File

@@ -94,6 +94,7 @@ const UiState = struct {
capslock_label: Label, capslock_label: Label,
battery_label: Label, battery_label: Label,
clock_label: Label, clock_label: Label,
tty_label: Label,
session_specifier_label: Label, session_specifier_label: Label,
login_label: Label, login_label: Label,
password_label: Label, password_label: Label,
@@ -118,6 +119,7 @@ const UiState = struct {
battery_buf: [16:0]u8, battery_buf: [16:0]u8,
bigclock_format_buf: [16:0]u8, bigclock_format_buf: [16:0]u8,
clock_buf: [64:0]u8, clock_buf: [64:0]u8,
tty_buf: [8:0]u8,
bigclock_buf: [32:0]u8, bigclock_buf: [32:0]u8,
custom_binds: std.ArrayList(CustomBindLabel), custom_binds: std.ArrayList(CustomBindLabel),
custom_info: std.ArrayList(CustomInfoLabel), custom_info: std.ArrayList(CustomInfoLabel),
@@ -541,6 +543,16 @@ pub fn main() !void {
); );
defer state.clock_label.deinit(); 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.bigclock_label = BigLabel.init(
&state.buffer, &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 // Initialize the animation, if any
var animation: ?*Widget = null; var animation: ?*Widget = null;
switch (state.config.animation) { switch (state.config.animation) {
@@ -1152,6 +1168,9 @@ pub fn main() !void {
if (state.config.clock != null) { if (state.config.clock != null) {
try layer2.append(state.allocator, state.clock_label.widget()); 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) { if (state.config.bigclock != .none) {
try layer2.append(state.allocator, state.bigclock_label.widget()); try layer2.append(state.allocator, state.bigclock_label.widget());
} }
@@ -1922,10 +1941,17 @@ fn positionWidgets(ptr: *anyopaque) !void {
.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)
.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_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 state.clock_label.positionXY(state.edge_margin
.add(TerminalBuffer.START_POSITION) .add(TerminalBuffer.START_POSITION)
.invertX(state.buffer.width) .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 state.numlock_label.positionX(state.edge_margin
.add(TerminalBuffer.START_POSITION) .add(TerminalBuffer.START_POSITION)