Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to change state texts (Verifying, Wrong, Cleared, Caps Lock) #52

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions completions/bash/swaylock
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ _swaylock()
--separator-color
--show-failed-attempts
--show-keyboard-layout
--text-caps-lock
--text-caps-lock-color
--text-clear
--text-clear-color
--text-color
--text-ver
--text-ver-color
--text-wrong
--text-wrong-color
--tiling
--version
Expand Down
4 changes: 4 additions & 0 deletions completions/fish/swaylock.fish
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ complete -c swaylock -l scaling -s s --description "Image scaling
complete -c swaylock -l separator-color --description "Sets the color of the lines that separate highlight segments."
complete -c swaylock -l show-failed-attempts -s F --description "Show current count of failed authentication attempts."
complete -c swaylock -l show-keyboard-layout -s k --description "Display the current xkb layout while typing."
complete -c swaylock -l text-caps-lock --description "Sets the string displayed when Caps Lock is active."
complete -c swaylock -l text-caps-lock-color --description "Sets the color of the text when Caps Lock is active."
complete -c swaylock -l text-clear --description "Sets the string displayed when the password is cleared."
complete -c swaylock -l text-clear-color --description "Sets the color of the text when cleared."
complete -c swaylock -l text-color --description "Sets the color of the text."
complete -c swaylock -l text-ver --description "Sets the string displayed when the password is being verified."
complete -c swaylock -l text-ver-color --description "Sets the color of the text when verifying."
complete -c swaylock -l text-wrong --description "Sets the string displayed when the password is wrong."
complete -c swaylock -l text-wrong-color --description "Sets the color of the text when invalid."
complete -c swaylock -l tiling -s t --description "Same as --scaling=tile."
complete -c swaylock -l version -s v --description "Show the version number and quit."
4 changes: 4 additions & 0 deletions completions/zsh/_swaylock
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ _arguments -s \
'(--separator-color)'--separator-color'[Sets the color of the lines that separate highlight segments]:color:' \
'(--show-failed-attempts -F)'{--show-failed-attempts,-F}'[Show current count of failed authentication attempts]' \
'(--show-keyboard-layout -k)'{--show-keyboard-layout,-k}'[Display the current xkb layout while typing]' \
'(--text-caps-lock)'--text-caps-lock'[Sets the string displayed when Caps Lock is active]' \
'(--text-caps-lock-color)'--text-caps-lock-color'[Sets the color of the text when Caps Lock is active]:color:' \
'(--text-clear)'--text-clear'[Sets the string displayed when the password is cleared]' \
'(--text-clear-color)'--text-clear-color'[Sets the color of the text when cleared]:color:' \
'(--text-color)'--text-color'[Sets the color of the text]:color:' \
'(--text-ver)'--text-ver'[Sets the string displayed when the password is being verified]' \
'(--text-ver-color)'--text-ver-color'[Sets the color of the text when verifying]:color:' \
'(--text-wrong)'--text-wrong'[Sets the string displayed when the password is wrong]' \
'(--text-wrong-color)'--text-wrong-color'[Sets the color of the text when invalid]:color:' \
'(--tiling -T)'{--tiling,-T}'[Same as --scaling=tile]' \
'(--version -v)'{--version,-v}'[Show the version number and quit]'
5 changes: 5 additions & 0 deletions include/swaylock.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ struct swaylock_args {
uint32_t password_grace_period;
bool password_grace_no_mouse;
bool password_grace_no_touch;

char *text_cleared;
char *text_caps_lock;
char *text_verifying;
char *text_wrong;
};

struct swaylock_password {
Expand Down
37 changes: 37 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,9 +957,13 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
LO_RING_WRONG_COLOR,
LO_SEP_COLOR,
LO_TEXT_COLOR,
LO_TEXT_CLEAR,
LO_TEXT_CLEAR_COLOR,
LO_TEXT_CAPS_LOCK,
LO_TEXT_CAPS_LOCK_COLOR,
LO_TEXT_VER,
LO_TEXT_VER_COLOR,
LO_TEXT_WRONG,
LO_TEXT_WRONG_COLOR,
LO_EFFECT_BLUR,
LO_EFFECT_PIXELATE,
Expand Down Expand Up @@ -1033,9 +1037,13 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
{"ring-wrong-color", required_argument, NULL, LO_RING_WRONG_COLOR},
{"separator-color", required_argument, NULL, LO_SEP_COLOR},
{"text-color", required_argument, NULL, LO_TEXT_COLOR},
{"text-clear", required_argument, NULL, LO_TEXT_CLEAR},
{"text-clear-color", required_argument, NULL, LO_TEXT_CLEAR_COLOR},
{"text-caps-lock", required_argument, NULL, LO_TEXT_CAPS_LOCK},
{"text-caps-lock-color", required_argument, NULL, LO_TEXT_CAPS_LOCK_COLOR},
{"text-ver", required_argument, NULL, LO_TEXT_VER},
{"text-ver-color", required_argument, NULL, LO_TEXT_VER_COLOR},
{"text-wrong", required_argument, NULL, LO_TEXT_WRONG},
{"text-wrong-color", required_argument, NULL, LO_TEXT_WRONG_COLOR},
{"effect-blur", required_argument, NULL, LO_EFFECT_BLUR},
{"effect-pixelate", required_argument, NULL, LO_EFFECT_PIXELATE},
Expand Down Expand Up @@ -1481,21 +1489,45 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
state->args.colors.text.input = parse_color(optarg);
}
break;
case LO_TEXT_CLEAR:
if (state) {
free(state->args.text_cleared);
state->args.text_cleared = strdup(optarg);
}
break;
case LO_TEXT_CLEAR_COLOR:
if (state) {
state->args.colors.text.cleared = parse_color(optarg);
}
break;
case LO_TEXT_CAPS_LOCK:
if (state) {
free(state->args.text_caps_lock);
state->args.text_caps_lock = strdup(optarg);
}
break;
case LO_TEXT_CAPS_LOCK_COLOR:
if (state) {
state->args.colors.text.caps_lock = parse_color(optarg);
}
break;
case LO_TEXT_VER:
if (state) {
free(state->args.text_verifying);
state->args.text_verifying = strdup(optarg);
}
break;
case LO_TEXT_VER_COLOR:
if (state) {
state->args.colors.text.verifying = parse_color(optarg);
}
break;
case LO_TEXT_WRONG:
if (state) {
free(state->args.text_wrong);
state->args.text_wrong = strdup(optarg);
}
break;
case LO_TEXT_WRONG_COLOR:
if (state) {
state->args.colors.text.wrong = parse_color(optarg);
Expand Down Expand Up @@ -1815,6 +1847,11 @@ int main(int argc, char **argv) {
.datestr = strdup("%a, %x"),
.allow_fade = true,
.password_grace_period = 0,

.text_cleared = strdup("Cleared"),
.text_caps_lock = strdup("Caps Lock"),
.text_verifying = strdup("Verifying"),
.text_wrong = strdup("Wrong"),
};
wl_list_init(&state.images);
set_default_colors(&state.args.colors);
Expand Down
8 changes: 4 additions & 4 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,20 @@ void render_frame(struct swaylock_surface *surface) {
cairo_set_font_size(cairo, font_size);
switch (state->auth_state) {
case AUTH_STATE_VALIDATING:
text = "Verifying";
text = state->args.text_verifying;
break;
case AUTH_STATE_INVALID:
text = "Wrong";
text = state->args.text_wrong;
break;
case AUTH_STATE_CLEAR:
text = "Cleared";
text = state->args.text_cleared;
break;
case AUTH_STATE_INPUT:
case AUTH_STATE_INPUT_NOP:
case AUTH_STATE_BACKSPACE:
// Caps Lock has higher priority
if (state->xkb.caps_lock && state->args.show_caps_lock_text) {
text = "Caps Lock";
text = state->args.text_caps_lock;
} else if (state->args.show_failed_attempts &&
state->failed_attempts > 0) {
if (state->failed_attempts > 999) {
Expand Down
12 changes: 12 additions & 0 deletions swaylock.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,27 @@ Locks your Wayland session.
*--text-color* <rrggbb[aa]>
Sets the color of the text.

*--text-clear* <string>
Sets the string displayed when the password is cleared.

*--text-clear-color* <rrggbb[aa]>
Sets the color of the text when cleared.

*--text-caps-lock* <string>
Sets the string displayed when Caps Lock is active.

*--text-caps-lock-color* <rrggbb[aa]>
Sets the color of the text when Caps Lock is active.

*--text-ver* <string>
Sets the string displayed when the password is being verified.

*--text-ver-color* <rrggbb[aa]>
Sets the color of the text when verifying.

*--text-wrong* <string>
Sets the string displayed when the password is wrong.

*--text-wrong-color* <rrggbb[aa]>
Sets the color of the text when invalid.

Expand Down