Add type_username option to config

This commit is contained in:
garopoulos 2026-03-05 12:49:23 +02:00
commit 0debd9dc46
3 changed files with 59 additions and 10 deletions

View file

@ -347,6 +347,9 @@ start_cmd = $CONFIG_DIRECTORY/ly/startup.sh
# Center the session name.
text_in_center = false
# Allow typing username manually
type_username = true
# Default vi mode
# normal -> normal mode
# insert -> insert mode

View file

@ -89,6 +89,7 @@ sleep_cmd: ?[]const u8 = null,
sleep_key: []const u8 = "F3",
start_cmd: ?[]const u8 = null,
text_in_center: bool = false,
type_username: bool = true,
vi_default_mode: ViMode = .normal,
vi_mode: bool = false,
waylandsessions: []const u8 = build_options.prefix_directory ++ "/share/wayland-sessions",

View file

@ -93,6 +93,8 @@ const UiState = struct {
session: Session,
saved_users: SavedUsers,
login: UserList,
login_text: *Text,
login_text_widget: Widget,
password: *Text,
password_widget: Widget,
insert_mode: bool,
@ -688,6 +690,21 @@ pub fn main() !void {
state.buffer.fg,
state.buffer.bg,
);
if (state.config.type_username) {
state.login_text = try Text.init(
state.allocator,
&state.buffer,
!state.config.vi_mode or state.config.vi_default_mode == .insert,
false,
null,
state.box.width - 2 * state.box.horizontal_margin - state.labels_max_length - 1,
state.buffer.fg,
state.buffer.bg,
);
state.login_text_widget = state.login_text.widget();
}
defer state.login.deinit();
try state.buffer.registerKeybind(&state.login.label.keybinds, "H", &viGoLeft, &state);
@ -1028,7 +1045,10 @@ pub fn main() !void {
const info_line_widget = state.info_line.widget();
const session_widget = state.session.widget();
const login_widget = state.login.widget();
const login_widget = if (state.config.type_username)
state.login_text_widget
else
state.login.widget();
var widgets: std.ArrayList([]Widget) = .empty;
defer widgets.deinit(state.allocator);
@ -1072,6 +1092,7 @@ pub fn main() !void {
if (!state.config.hide_keyboard_locks) {
try layer2.append(state.allocator, state.numlock_label.widget());
try layer2.append(state.allocator, state.capslock_label.widget());
try layer2.append(state.allocator, state.capslock_label.widget());
}
try layer2.append(state.allocator, state.box.widget());
try layer2.append(state.allocator, info_line_widget);
@ -1326,7 +1347,10 @@ fn authenticate(ptr: *anyopaque) !bool {
var file_writer = file.writer(&file_buffer);
var writer = &file_writer.interface;
try writer.print("{d}\n", .{state.login.label.current});
if (!state.config.type_username) {
try writer.print("{d}\n", .{state.login.label.current});
}
for (state.saved_users.user_list.items) |user| {
try writer.print("{s}:{d}\n", .{ user.username, user.session_index });
}
@ -1378,12 +1402,18 @@ fn authenticate(ptr: *anyopaque) !bool {
try state.log_file.reinit();
const username =
if (state.config.type_username)
state.login_text.text.items
else
state.login.getCurrentUsername();
auth.authenticate(
state.allocator,
&state.log_file,
auth_options,
current_environment,
state.login.getCurrentUsername(),
username,
password_text,
) catch |err| {
shared_err.writeError(err);
@ -1781,14 +1811,29 @@ fn positionWidgets(ptr: *anyopaque) !void {
.childrenPosition()
.resetXFrom(state.info_line.label.childrenPosition())
.addY(1));
state.login.label.positionY(state.login_label
.childrenPosition()
.addX(state.labels_max_length - TerminalBuffer.strWidth(state.login_label.text) + 1));
state.password_label.positionX(state.login.label
.childrenPosition()
.resetXFrom(state.info_line.label.childrenPosition())
.addY(1));
if (state.config.type_username) {
state.login_text.positionY(state.login_label
.childrenPosition()
.addX(state.labels_max_length - TerminalBuffer.strWidth(state.login_label.text) + 1));
} else {
state.login.label.positionY(state.login_label
.childrenPosition()
.addX(state.labels_max_length - TerminalBuffer.strWidth(state.login_label.text) + 1));
}
if (state.config.type_username) {
state.password_label.positionX(state.login_text
.childrenPosition()
.resetXFrom(state.info_line.label.childrenPosition())
.addY(1));
} else {
state.password_label.positionX(state.login.label
.childrenPosition()
.resetXFrom(state.info_line.label.childrenPosition())
.addY(1));
}
state.password.positionY(state.password_label
.childrenPosition()
.addX(state.labels_max_length - TerminalBuffer.strWidth(state.password_label.text) + 1));