Skip to content

Commit

Permalink
cli: add -input-alt-color
Browse files Browse the repository at this point in the history
  • Loading branch information
quite authored and ifreund committed Oct 3, 2024
1 parent 2444adb commit 5119631
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
9 changes: 7 additions & 2 deletions doc/waylock.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,20 @@ unlocked.
*-input-color* _0xRRGGBB_
Set the color used after input. (default: 0x6c71c4)

*-input-alt-color* _0xRRGGBB_
Set the alternate color used after input. (default is what
*-input-color* is set to)

*-fail-color* _0xRRGGBB_
Set the color used on authentication failure. (default: 0xdc322f)

# USAGE

Run the waylock executable to lock the session. All monitors will be blanked
with the *-init-color*. Typing causes the color to change to the
*-input-color*. Esc or Ctrl-U clears all current input, while backspace
deletes the last UTF-8 codepoint.
*-input-color*. If *-input-alt-color* is set, the typing color will alternate
between this and the former. Esc or Ctrl-U clears all current input, while
backspace deletes the last UTF-8 codepoint.

To unlock the session, type your password and press Enter. If the password
is correct, waylock will unlock the session and exit. Otherwise, the color
Expand Down
11 changes: 7 additions & 4 deletions src/Lock.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const gpa = std.heap.c_allocator;
pub const Color = enum {
init,
input,
input_alt,
fail,
};

Expand All @@ -34,12 +35,14 @@ pub const Options = struct {
ignore_empty_password: bool,
init_color: u24 = 0x002b36,
input_color: u24 = 0x6c71c4,
input_alt_color: u24 = 0x6c71c4,
fail_color: u24 = 0xdc322f,

fn rgb(options: Options, color: Color) u24 {
return switch (color) {
.init => options.init_color,
.input => options.input_color,
.input_alt => options.input_alt_color,
.fail => options.fail_color,
};
}
Expand Down Expand Up @@ -72,7 +75,7 @@ session_lock_manager: ?*ext.SessionLockManagerV1 = null,
session_lock: ?*ext.SessionLockV1 = null,
viewporter: ?*wp.Viewporter = null,
buffer_manager: ?*wp.SinglePixelBufferManagerV1 = null,
buffers: [3]*wl.Buffer,
buffers: [4]*wl.Buffer,

seats: std.SinglyLinkedList(Seat) = .{},
outputs: std.SinglyLinkedList(Output) = .{},
Expand Down Expand Up @@ -440,9 +443,9 @@ fn fatal_not_advertised(comptime Global: type) noreturn {
fn create_buffers(
buffer_manager: *wp.SinglePixelBufferManagerV1,
options: Options,
) error{OutOfMemory}![3]*wl.Buffer {
var buffers: [3]*wl.Buffer = undefined;
for ([_]Color{ .init, .input, .fail }) |color| {
) error{OutOfMemory}![4]*wl.Buffer {
var buffers: [4]*wl.Buffer = undefined;
for ([_]Color{ .init, .input, .input_alt, .fail }) |color| {
const rgb = options.rgb(color);
buffers[@intFromEnum(color)] = try buffer_manager.createU32RgbaBuffer(
@as(u32, (rgb >> 16) & 0xff) * (0xffff_ffff / 0xff),
Expand Down
5 changes: 4 additions & 1 deletion src/Seat.zig
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ fn keyboard_listener(_: *wl.Keyboard, event: wl.Keyboard.Event, seat: *Seat) voi
// If key was not handled, write to password buffer
const delta = xkb_state.keyGetUtf8(keycode, lock.password.unused_slice());
if (delta > 0) {
lock.set_color(.input);
switch (lock.color) {
.init, .input_alt, .fail => lock.set_color(.input),
.input => lock.set_color(.input_alt),
}
}
lock.password.grow(delta) catch log.err("password exceeds 1024 byte limit", .{});
},
Expand Down
26 changes: 16 additions & 10 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ const flags = @import("flags.zig");
const usage =
\\usage: waylock [options]
\\
\\ -h Print this help message and exit.
\\ -version Print the version number and exit.
\\ -log-level <level> Set the log level to error, warning, info, or debug.
\\ -h Print this help message and exit.
\\ -version Print the version number and exit.
\\ -log-level <level> Set the log level to error, warning, info, or debug.
\\
\\ -fork-on-lock Fork to the background after locking.
\\ -ready-fd <fd> Write a newline to fd after locking.
\\ -ignore-empty-password Do not validate an empty password.
\\ -fork-on-lock Fork to the background after locking.
\\ -ready-fd <fd> Write a newline to fd after locking.
\\ -ignore-empty-password Do not validate an empty password.
\\
\\ -init-color 0xRRGGBB Set the initial color.
\\ -input-color 0xRRGGBB Set the color used after input.
\\ -fail-color 0xRRGGBB Set the color used on authentication failure.
\\ -init-color 0xRRGGBB Set the initial color.
\\ -input-color 0xRRGGBB Set the color used after input.
\\ -input-alt-color 0xRRGGBB Set the alternate color used after input.
\\ -fail-color 0xRRGGBB Set the color used on authentication failure.
\\
;

Expand All @@ -38,6 +39,7 @@ pub fn main() void {
.{ .name = "ignore-empty-password", .kind = .boolean },
.{ .name = "init-color", .kind = .arg },
.{ .name = "input-color", .kind = .arg },
.{ .name = "input-alt-color", .kind = .arg },
.{ .name = "fail-color", .kind = .arg },
}).parse(std.os.argv[1..]) catch {
io.getStdErr().writeAll(usage) catch {};
Expand Down Expand Up @@ -83,7 +85,11 @@ pub fn main() void {
};
}
if (result.flags.@"init-color") |raw| options.init_color = parse_color(raw);
if (result.flags.@"input-color") |raw| options.input_color = parse_color(raw);
if (result.flags.@"input-color") |raw| {
options.input_color = parse_color(raw);
options.input_alt_color = parse_color(raw);
}
if (result.flags.@"input-alt-color") |raw| options.input_alt_color = parse_color(raw);
if (result.flags.@"fail-color") |raw| options.fail_color = parse_color(raw);

Lock.run(options);
Expand Down

0 comments on commit 5119631

Please sign in to comment.