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

@@ -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)