mirror of https://github.com/fairyglade/ly.git
Rewrite INPUTS enum in Zig
This commit is contained in:
parent
70770ab16b
commit
d1cf1ebd80
|
@ -66,7 +66,7 @@ max_password_len = 255
|
||||||
|
|
||||||
|
|
||||||
# Input box active by default on startup
|
# Input box active by default on startup
|
||||||
default_input = 2
|
default_input = login
|
||||||
|
|
||||||
# Load the saved desktop and username
|
# Load the saved desktop and username
|
||||||
load = true
|
load = true
|
||||||
|
|
|
@ -4,12 +4,6 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
enum INPUTS {
|
|
||||||
SESSION_SWITCH,
|
|
||||||
LOGIN_INPUT,
|
|
||||||
PASSWORD_INPUT,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct lang
|
struct lang
|
||||||
{
|
{
|
||||||
char* capslock;
|
char* capslock;
|
||||||
|
|
|
@ -6,6 +6,12 @@ const interop = @import("interop.zig");
|
||||||
const INI_CONFIG_PATH: []const u8 = "/etc/ly/";
|
const INI_CONFIG_PATH: []const u8 = "/etc/ly/";
|
||||||
const INI_CONFIG_MAX_SIZE: usize = 16 * 1024;
|
const INI_CONFIG_MAX_SIZE: usize = 16 * 1024;
|
||||||
|
|
||||||
|
pub const Inputs = enum {
|
||||||
|
session,
|
||||||
|
login,
|
||||||
|
password,
|
||||||
|
};
|
||||||
|
|
||||||
pub const LyConfig = struct {
|
pub const LyConfig = struct {
|
||||||
ly: struct {
|
ly: struct {
|
||||||
animate: bool,
|
animate: bool,
|
||||||
|
@ -17,7 +23,7 @@ pub const LyConfig = struct {
|
||||||
blank_password: bool,
|
blank_password: bool,
|
||||||
clock: []const u8,
|
clock: []const u8,
|
||||||
console_dev: []const u8,
|
console_dev: []const u8,
|
||||||
default_input: u8,
|
default_input: Inputs,
|
||||||
fg: u8,
|
fg: u8,
|
||||||
hide_borders: bool,
|
hide_borders: bool,
|
||||||
hide_f1_commands: bool,
|
hide_f1_commands: bool,
|
||||||
|
@ -207,7 +213,7 @@ pub fn config_load(cfg_path: []const u8) !void {
|
||||||
main.c_config.blank_password = ly_config.ly.blank_password;
|
main.c_config.blank_password = ly_config.ly.blank_password;
|
||||||
main.c_config.clock = config_clock.ptr;
|
main.c_config.clock = config_clock.ptr;
|
||||||
main.c_config.console_dev = config_console_dev.ptr;
|
main.c_config.console_dev = config_console_dev.ptr;
|
||||||
main.c_config.default_input = ly_config.ly.default_input;
|
main.c_config.default_input = @intFromEnum(ly_config.ly.default_input);
|
||||||
main.c_config.fg = ly_config.ly.fg;
|
main.c_config.fg = ly_config.ly.fg;
|
||||||
main.c_config.hide_borders = ly_config.ly.hide_borders;
|
main.c_config.hide_borders = ly_config.ly.hide_borders;
|
||||||
main.c_config.hide_f1_commands = ly_config.ly.hide_f1_commands;
|
main.c_config.hide_f1_commands = ly_config.ly.hide_f1_commands;
|
||||||
|
|
60
src/main.zig
60
src/main.zig
|
@ -119,9 +119,9 @@ pub fn main() !void {
|
||||||
|
|
||||||
// Place the cursor on the login field if there is no saved username
|
// Place the cursor on the login field if there is no saved username
|
||||||
// If there is, place the curser on the password field
|
// If there is, place the curser on the password field
|
||||||
var active_input: u8 = 0;
|
var active_input: config.Inputs = undefined;
|
||||||
if (config.ly_config.ly.default_input == c.LOGIN_INPUT and username.text != username.end) {
|
if (config.ly_config.ly.default_input == .login and username.text != username.end) {
|
||||||
active_input = c.PASSWORD_INPUT;
|
active_input = .password;
|
||||||
} else {
|
} else {
|
||||||
active_input = config.ly_config.ly.default_input;
|
active_input = config.ly_config.ly.default_input;
|
||||||
}
|
}
|
||||||
|
@ -135,16 +135,15 @@ pub fn main() !void {
|
||||||
c.position_input(buffer, desktop, username, password);
|
c.position_input(buffer, desktop, username, password);
|
||||||
|
|
||||||
switch (active_input) {
|
switch (active_input) {
|
||||||
c.SESSION_SWITCH => {
|
.session => {
|
||||||
c.handle_desktop(desktop, event);
|
c.handle_desktop(desktop, event);
|
||||||
},
|
},
|
||||||
c.LOGIN_INPUT => {
|
.login => {
|
||||||
c.handle_text(username, event);
|
c.handle_text(username, event);
|
||||||
},
|
},
|
||||||
c.PASSWORD_INPUT => {
|
.password => {
|
||||||
c.handle_text(password, event);
|
c.handle_text(password, event);
|
||||||
},
|
},
|
||||||
else => unreachable,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.ly_config.ly.animate) {
|
if (config.ly_config.ly.animate) {
|
||||||
|
@ -171,16 +170,15 @@ pub fn main() !void {
|
||||||
if (update) {
|
if (update) {
|
||||||
if (auth_fails < MAX_AUTH_FAILS) {
|
if (auth_fails < MAX_AUTH_FAILS) {
|
||||||
switch (active_input) {
|
switch (active_input) {
|
||||||
c.SESSION_SWITCH => {
|
.session => {
|
||||||
c.handle_desktop(desktop, event);
|
c.handle_desktop(desktop, event);
|
||||||
},
|
},
|
||||||
c.LOGIN_INPUT => {
|
.login => {
|
||||||
c.handle_text(username, event);
|
c.handle_text(username, event);
|
||||||
},
|
},
|
||||||
c.PASSWORD_INPUT => {
|
.password => {
|
||||||
c.handle_text(password, event);
|
c.handle_text(password, event);
|
||||||
},
|
},
|
||||||
else => unreachable,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.tb_clear();
|
c.tb_clear();
|
||||||
|
@ -218,9 +216,9 @@ pub fn main() !void {
|
||||||
_ = std.os.linux.gettimeofday(time, undefined);
|
_ = std.os.linux.gettimeofday(time, undefined);
|
||||||
|
|
||||||
if (config.ly_config.ly.bigclock) {
|
if (config.ly_config.ly.bigclock) {
|
||||||
timeout = @intCast(c_int, (60 - @mod(time.tv_sec, 60)) * 1000 - @divTrunc(time.tv_usec, 1000) + 1);
|
timeout = @intCast((60 - @mod(time.tv_sec, 60)) * 1000 - @divTrunc(time.tv_usec, 1000) + 1);
|
||||||
} else if (config.ly_config.ly.clock.len > 0) {
|
} else if (config.ly_config.ly.clock.len > 0) {
|
||||||
timeout = @intCast(c_int, 1000 - @divTrunc(time.tv_usec, 1000) + 1);
|
timeout = @intCast(1000 - @divTrunc(time.tv_usec, 1000) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,12 +246,12 @@ pub fn main() !void {
|
||||||
run = false;
|
run = false;
|
||||||
},
|
},
|
||||||
c.TB_KEY_CTRL_U => {
|
c.TB_KEY_CTRL_U => {
|
||||||
if (active_input > c.SESSION_SWITCH) {
|
if (active_input != .session) {
|
||||||
switch (active_input) {
|
switch (active_input) {
|
||||||
c.LOGIN_INPUT => {
|
.login => {
|
||||||
c.input_text_clear(username);
|
c.input_text_clear(username);
|
||||||
},
|
},
|
||||||
c.PASSWORD_INPUT => {
|
.password => {
|
||||||
c.input_text_clear(password);
|
c.input_text_clear(password);
|
||||||
},
|
},
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
|
@ -263,23 +261,33 @@ pub fn main() !void {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
c.TB_KEY_CTRL_K, c.TB_KEY_ARROW_UP => {
|
c.TB_KEY_CTRL_K, c.TB_KEY_ARROW_UP => {
|
||||||
if (active_input > c.SESSION_SWITCH) {
|
if (active_input != .session) {
|
||||||
active_input -= 1;
|
active_input = switch (active_input) {
|
||||||
|
.login => .session,
|
||||||
|
.password => .login,
|
||||||
|
else => unreachable,
|
||||||
|
};
|
||||||
|
|
||||||
update = true;
|
update = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
c.TB_KEY_CTRL_J, c.TB_KEY_ARROW_DOWN => {
|
c.TB_KEY_CTRL_J, c.TB_KEY_ARROW_DOWN => {
|
||||||
if (active_input < c.PASSWORD_INPUT) {
|
if (active_input != .password) {
|
||||||
active_input += 1;
|
active_input = switch (active_input) {
|
||||||
|
.session => .login,
|
||||||
|
.login => .password,
|
||||||
|
else => unreachable,
|
||||||
|
};
|
||||||
|
|
||||||
update = true;
|
update = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
c.TB_KEY_TAB => {
|
c.TB_KEY_TAB => {
|
||||||
active_input += 1;
|
active_input = switch (active_input) {
|
||||||
|
.session => .login,
|
||||||
if (active_input > c.PASSWORD_INPUT) {
|
.login => .password,
|
||||||
active_input = c.SESSION_SWITCH;
|
.password => .session,
|
||||||
}
|
};
|
||||||
|
|
||||||
update = true;
|
update = true;
|
||||||
},
|
},
|
||||||
|
@ -291,7 +299,7 @@ pub fn main() !void {
|
||||||
auth_fails += 1;
|
auth_fails += 1;
|
||||||
|
|
||||||
// Move focus back to password input
|
// Move focus back to password input
|
||||||
active_input = c.PASSWORD_INPUT;
|
active_input = .password;
|
||||||
|
|
||||||
if (c.dgn_output_code() != c.DGN_PAM) {
|
if (c.dgn_output_code() != c.DGN_PAM) {
|
||||||
buffer.info_line = c.dgn_output_log();
|
buffer.info_line = c.dgn_output_log();
|
||||||
|
|
Loading…
Reference in New Issue