mirror of
https://github.com/fairyglade/ly.git
synced 2025-12-21 03:34:54 +00:00
Compare commits
12 Commits
JAicewizar
...
peterc-s/m
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6d8bea236 | ||
|
|
7e69260511 | ||
|
|
1ddccf2683 | ||
|
|
798d9d934c | ||
|
|
c54ca6761d | ||
|
|
5e05d29e0c | ||
|
|
020f27b203 | ||
|
|
e125d8f1aa | ||
|
|
e885a5e776 | ||
|
|
aea95b7724 | ||
|
|
215ca5edc7 | ||
|
|
022d146f76 |
@@ -25,7 +25,7 @@ Ly is a lightweight TUI (ncurses-like) display manager for Linux and BSD.
|
||||
It is recommended to add a rule for Ly as it currently does not ship one.
|
||||
|
||||
```
|
||||
# dnf install kernel-devel pam-devel libxcb-devel
|
||||
# dnf install kernel-devel pam-devel libxcb-devel zig
|
||||
```
|
||||
|
||||
## Support
|
||||
@@ -40,6 +40,7 @@ The following desktop environments were tested with success:
|
||||
- dwm
|
||||
- enlightenment
|
||||
- gnome
|
||||
- hyprland
|
||||
- i3
|
||||
- kde
|
||||
- labwc
|
||||
|
||||
@@ -35,6 +35,14 @@
|
||||
# matrix -> CMatrix
|
||||
animation = none
|
||||
|
||||
# The minimum time between animation frames
|
||||
# 32 -> ~30fps
|
||||
# 16 -> ~60fps
|
||||
# 8 -> ~120fps
|
||||
# 6 -> ~144fps
|
||||
# 4 -> ~240fps
|
||||
animation_refresh_ms = 16
|
||||
|
||||
# Stop the animation after some time
|
||||
# 0 -> Run forever
|
||||
# 1..2e12 -> Stop the animation after this many seconds
|
||||
|
||||
@@ -1,45 +1,60 @@
|
||||
authenticating = autenticant...
|
||||
brightness_down = abaixar brillantor
|
||||
brightness_up = apujar brillantor
|
||||
capslock = Bloq Majús
|
||||
err_alloc = falla d'assignació de memòria
|
||||
err_bounds = índex fora de límit
|
||||
err_chdir = error al obrir carpeta home
|
||||
err_console_dev = error al accedir a la consola
|
||||
err_alloc = assignació de memòria fallida
|
||||
err_bounds = índex fora de límits
|
||||
err_brightness_change = error en canviar la brillantor
|
||||
err_chdir = error en obrir la carpeta home
|
||||
err_console_dev = error en accedir a la consola
|
||||
err_dgn_oob = missatge de registre
|
||||
err_domain = domini invàlid
|
||||
err_hostname = error al obtenir el nom del host
|
||||
err_mlock = error al bloquejar la clau de memòria
|
||||
err_envlist = error en obtenir l'envlist
|
||||
err_hostname = error en obtenir el nom de l'amfitrió
|
||||
err_mlock = error en bloquejar la memòria de clau
|
||||
err_null = punter nul
|
||||
err_numlock = error en establir el Bloq num
|
||||
err_pam = error en la transacció pam
|
||||
err_pam_abort = transacció pam avortada
|
||||
err_pam_acct_expired = compte expirat
|
||||
err_pam_auth = error d'autenticació
|
||||
err_pam_authinfo_unavail = error al obtenir informació de l'usuari
|
||||
err_pam_authinfo_unavail = error en obtenir la informació de l'usuari
|
||||
err_pam_authok_reqd = token expirat
|
||||
err_pam_buf = error de la memòria intermitja
|
||||
err_pam_cred_err = error al establir les credencials
|
||||
err_pam_buf = error en la memòria intermèdia
|
||||
err_pam_cred_err = error en establir les credencials
|
||||
err_pam_cred_expired = credencials expirades
|
||||
err_pam_cred_insufficient = credencials insuficients
|
||||
err_pam_cred_unavail = error al obtenir credencials
|
||||
err_pam_maxtries = s'ha assolit al màxim nombre d'intents
|
||||
err_pam_cred_unavail = error en obtenir credencials
|
||||
err_pam_maxtries = s'ha assolit al nombre màxim d'intents
|
||||
err_pam_perm_denied = permís denegat
|
||||
err_pam_session = error de sessió
|
||||
err_pam_sys = error de sistema
|
||||
err_pam_user_unknown = usuari desconegut
|
||||
err_path = error al establir la ruta
|
||||
err_perm_dir = error al canviar de directori actual
|
||||
err_perm_group = error al degradar els permisos de grup
|
||||
err_perm_user = error al degradar els permisos de l'usuari
|
||||
err_pwnam = error al obtenir la informació de l'usuari
|
||||
err_user_gid = error al establir el GID de l'usuari
|
||||
err_user_init = error al inicialitzar usuari
|
||||
err_user_uid = error al establir el UID de l'usuari
|
||||
err_xsessions_dir = error al cercar la carpeta de sessions
|
||||
err_xsessions_open = error al obrir la carpeta de sessions
|
||||
err_path = error en establir la ruta
|
||||
err_perm_dir = error en canviar el directori actual
|
||||
err_perm_group = error en degradar els permisos de grup
|
||||
err_perm_user = error en degradar els permisos de l'usuari
|
||||
err_pwnam = error en obtenir la informació de l'usuari
|
||||
err_unknown = ha ocorregut un error desconegut
|
||||
err_user_gid = error en establir el GID de l'usuari
|
||||
err_user_init = error en inicialitzar usuari
|
||||
err_user_uid = error en establir l'UID de l'usuari
|
||||
err_xauth = error en la comanda xauth
|
||||
err_xcb_conn = error en la connexió xcb
|
||||
err_xsessions_dir = error en trobar la carpeta de sessions
|
||||
err_xsessions_open = error en obrir la carpeta de sessions
|
||||
insert = inserir
|
||||
login = iniciar sessió
|
||||
logout = tancar sessió
|
||||
logout = sessió tancada
|
||||
no_x11_support = x11 support disabled at compile-time
|
||||
no_x11_support = el suport per x11 ha estat desactivat en la compilació
|
||||
normal = normal
|
||||
numlock = Bloq Num
|
||||
password = Clau
|
||||
restart = reiniciar
|
||||
shell = shell
|
||||
shutdown = aturar
|
||||
sleep = suspendre
|
||||
wayland = wayland
|
||||
x11 = x11
|
||||
xinitrc = xinitrc
|
||||
|
||||
@@ -35,6 +35,7 @@ err_perm_dir = failed to change current directory
|
||||
err_perm_group = failed to downgrade group permissions
|
||||
err_perm_user = failed to downgrade user permissions
|
||||
err_pwnam = failed to get user info
|
||||
err_sleep = failed to execute sleep command
|
||||
err_unknown = an unknown error occurred
|
||||
err_user_gid = failed to set user GID
|
||||
err_user_init = failed to initialize user
|
||||
|
||||
@@ -50,35 +50,57 @@ pub fn realloc(self: *Doom) !void {
|
||||
self.buffer = buffer;
|
||||
}
|
||||
|
||||
pub fn draw(self: Doom) void {
|
||||
pub fn drawWithUpdate(self: Doom) void {
|
||||
for (0..self.terminal_buffer.width) |x| {
|
||||
for (1..self.terminal_buffer.height) |y| {
|
||||
// get source index
|
||||
const source = y * self.terminal_buffer.width + x;
|
||||
|
||||
// random number between 0 and 3 inclusive
|
||||
const random = (self.terminal_buffer.random.int(u16) % 7) & 3;
|
||||
|
||||
// adjust destination index based on random value
|
||||
var dest = (source - @min(source, random)) + 1;
|
||||
if (self.terminal_buffer.width > dest) dest = 0 else dest -= self.terminal_buffer.width;
|
||||
|
||||
// get source intensity and destination offset
|
||||
const buffer_source = self.buffer[source];
|
||||
const buffer_dest_offset = random & 1;
|
||||
|
||||
if (buffer_source < buffer_dest_offset) continue;
|
||||
|
||||
// calculate the destination intensity
|
||||
var buffer_dest = buffer_source - buffer_dest_offset;
|
||||
if (buffer_dest > 12) buffer_dest = 0;
|
||||
self.buffer[dest] = @intCast(buffer_dest);
|
||||
|
||||
// update terminal
|
||||
self.terminal_buffer.buffer[dest] = toTermboxCell(FIRE[buffer_dest]);
|
||||
self.terminal_buffer.buffer[source] = toTermboxCell(FIRE[buffer_source]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn initBuffer(buffer: []u8, width: usize) void {
|
||||
const length = buffer.len - width;
|
||||
const slice_start = buffer[0..length];
|
||||
const slice_end = buffer[length..];
|
||||
pub fn draw(self: Doom) void {
|
||||
for (0..self.terminal_buffer.width) |x| {
|
||||
for (1..self.terminal_buffer.height) |y| {
|
||||
// get source index
|
||||
const source = y * self.terminal_buffer.width + x;
|
||||
|
||||
// get intensity from buffer
|
||||
const buffer_source = self.buffer[source];
|
||||
|
||||
// set cell to correct fire char
|
||||
self.terminal_buffer.buffer[source] = toTermboxCell(FIRE[buffer_source]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn initBuffer(buffer: []u8, width: usize) void {
|
||||
const slice_start = buffer[0..buffer.len];
|
||||
const slice_end = buffer[buffer.len - width .. buffer.len];
|
||||
|
||||
// set cell initial values to 0, set bottom row to be fire sources
|
||||
@memset(slice_start, 0);
|
||||
@memset(slice_end, STEPS - 1);
|
||||
}
|
||||
|
||||
@@ -68,14 +68,12 @@ pub fn realloc(self: *Matrix) !void {
|
||||
self.lines = lines;
|
||||
}
|
||||
|
||||
pub fn draw(self: *Matrix) void {
|
||||
pub fn drawWithUpdate(self: *Matrix) void {
|
||||
const buf_height = self.terminal_buffer.height;
|
||||
const buf_width = self.terminal_buffer.width;
|
||||
self.count += 1;
|
||||
if (self.count > FRAME_DELAY) {
|
||||
|
||||
self.frame += 1;
|
||||
if (self.frame > 4) self.frame = 1;
|
||||
self.count = 0;
|
||||
|
||||
var x: usize = 0;
|
||||
while (x < self.terminal_buffer.width) : (x += 2) {
|
||||
@@ -140,7 +138,12 @@ pub fn draw(self: *Matrix) void {
|
||||
first_col = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.draw();
|
||||
}
|
||||
|
||||
pub fn draw(self: *Matrix) void {
|
||||
const buf_width = self.terminal_buffer.width;
|
||||
|
||||
var x: usize = 0;
|
||||
while (x < buf_width) : (x += 2) {
|
||||
|
||||
@@ -8,6 +8,7 @@ const Bigclock = enums.Bigclock;
|
||||
|
||||
animation: Animation = .none,
|
||||
animation_timeout_sec: u12 = 0,
|
||||
animation_refresh_ms: u16 = 16,
|
||||
asterisk: ?u8 = '*',
|
||||
auth_fails: u64 = 10,
|
||||
bg: u16 = 0,
|
||||
|
||||
@@ -36,6 +36,7 @@ err_perm_dir: []const u8 = "failed to change current directory",
|
||||
err_perm_group: []const u8 = "failed to downgrade group permissions",
|
||||
err_perm_user: []const u8 = "failed to downgrade user permissions",
|
||||
err_pwnam: []const u8 = "failed to get user info",
|
||||
err_sleep: []const u8 = "failed to execute sleep command",
|
||||
err_unknown: []const u8 = "an unknown error occurred",
|
||||
err_user_gid: []const u8 = "failed to set user GID",
|
||||
err_user_init: []const u8 = "failed to initialize user",
|
||||
|
||||
63
src/main.zig
63
src/main.zig
@@ -317,6 +317,11 @@ pub fn main() !void {
|
||||
}
|
||||
}
|
||||
|
||||
var animation_timer = switch (config.animation) {
|
||||
.none => undefined,
|
||||
else => try std.time.Timer.start(),
|
||||
};
|
||||
|
||||
const animate = config.animation != .none;
|
||||
const shutdown_key = try std.fmt.parseInt(u8, config.shutdown_key[1..], 10);
|
||||
const shutdown_len = try utils.strWidth(lang.shutdown);
|
||||
@@ -380,8 +385,22 @@ pub fn main() !void {
|
||||
if (!animation_timed_out) {
|
||||
switch (config.animation) {
|
||||
.none => {},
|
||||
.doom => doom.draw(),
|
||||
.matrix => matrix.draw(),
|
||||
.doom => {
|
||||
if (animation_timer.read() / std.time.ns_per_ms > config.animation_refresh_ms) {
|
||||
animation_timer.reset();
|
||||
doom.drawWithUpdate();
|
||||
} else {
|
||||
doom.draw();
|
||||
}
|
||||
},
|
||||
.matrix => {
|
||||
if (animation_timer.read() / std.time.ns_per_ms > config.animation_refresh_ms) {
|
||||
animation_timer.reset();
|
||||
matrix.drawWithUpdate();
|
||||
} else {
|
||||
matrix.draw();
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -580,14 +599,33 @@ pub fn main() !void {
|
||||
} else if (pressed_key == sleep_key) {
|
||||
if (config.sleep_cmd) |sleep_cmd| {
|
||||
var sleep = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", sleep_cmd }, allocator);
|
||||
_ = sleep.spawnAndWait() catch .{};
|
||||
sleep.stdout_behavior = .Ignore;
|
||||
sleep.stderr_behavior = .Ignore;
|
||||
|
||||
handle_sleep_cmd: {
|
||||
const process_result = sleep.spawnAndWait() catch {
|
||||
break :handle_sleep_cmd;
|
||||
};
|
||||
if (process_result.Exited != 0) {
|
||||
try info_line.addMessage(lang.err_sleep, config.error_bg, config.error_fg);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (pressed_key == brightness_down_key or pressed_key == brightness_up_key) {
|
||||
const cmd = if (pressed_key == brightness_down_key) config.brightness_down_cmd else config.brightness_up_cmd;
|
||||
|
||||
var brightness = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", cmd }, allocator);
|
||||
brightness.stdout_behavior = .Ignore;
|
||||
brightness.stderr_behavior = .Ignore;
|
||||
|
||||
handle_brightness_cmd: {
|
||||
const process_result = brightness.spawnAndWait() catch {
|
||||
break :handle_brightness_cmd;
|
||||
};
|
||||
if (process_result.Exited != 0) {
|
||||
try info_line.addMessage(lang.err_brightness_change, config.error_bg, config.error_fg);
|
||||
}
|
||||
}
|
||||
} else if (pressed_key == brightness_down_key) {
|
||||
var brightness = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", config.brightness_down_cmd }, allocator);
|
||||
_ = brightness.spawnAndWait() catch .{};
|
||||
} else if (pressed_key == brightness_up_key) {
|
||||
var brightness = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", config.brightness_up_cmd }, allocator);
|
||||
_ = brightness.spawnAndWait() catch .{};
|
||||
}
|
||||
},
|
||||
termbox.TB_KEY_CTRL_C => run = false,
|
||||
@@ -666,7 +704,7 @@ pub fn main() !void {
|
||||
const password_text = try allocator.dupeZ(u8, password.text.items);
|
||||
defer allocator.free(password_text);
|
||||
|
||||
// Give up control on the TTY
|
||||
// Give up TTY
|
||||
_ = termbox.tb_shutdown();
|
||||
|
||||
session_pid = try std.posix.fork();
|
||||
@@ -683,10 +721,13 @@ pub fn main() !void {
|
||||
session_pid = -1;
|
||||
}
|
||||
|
||||
// Take back control of the TTY
|
||||
// Take back TTY
|
||||
_ = termbox.tb_init();
|
||||
_ = termbox.tb_set_output_mode(termbox.TB_OUTPUT_NORMAL);
|
||||
|
||||
// Reinitialise buffer to avoid use after free
|
||||
buffer = TerminalBuffer.init(config, labels_max_length, random);
|
||||
|
||||
const auth_err = shared_err.readError();
|
||||
if (auth_err) |err| {
|
||||
auth_fails += 1;
|
||||
|
||||
Reference in New Issue
Block a user