From fe7571c97492cdb71bb0f1624e9fbcd62e0e858b Mon Sep 17 00:00:00 2001 From: Paulobergine Date: Mon, 7 Mar 2022 23:15:29 -0500 Subject: [PATCH 1/4] test without user input --- main.c | 8 ++++++++ render.c | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 7f7bd6cb..30dc30c1 100644 --- a/main.c +++ b/main.c @@ -185,6 +185,7 @@ static void layer_surface_configure(void *data, surface->height = height; surface->indicator_width = 0; surface->indicator_height = 0; + surface->cleat_text = "test"; zwlr_layer_surface_v1_ack_configure(layer_surface, serial); render_frame_background(surface); render_frame(surface); @@ -648,6 +649,7 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, {"text-caps-lock-color", required_argument, NULL, LO_TEXT_CAPS_LOCK_COLOR}, {"text-ver-color", required_argument, NULL, LO_TEXT_VER_COLOR}, {"text-wrong-color", required_argument, NULL, LO_TEXT_WRONG_COLOR}, + //{"text-clear", required_argument, NULL, LO_TEXT_CLEAR}, {0, 0, 0, 0} }; @@ -1044,11 +1046,17 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, state->args.colors.text.wrong = parse_color(optarg); } break; + /*case LO_TEXT_CLEAR: + if( state) { + state->args.text.clear = optarg; + } + break;*/ default: fprintf(stderr, "%s", usage); return 1; } } + state->args.text.clear = "test"; return 0; } diff --git a/render.c b/render.c index 3dec7436..d19141a9 100644 --- a/render.c +++ b/render.c @@ -166,7 +166,7 @@ void render_frame(struct swaylock_surface *surface) { text = "verifying"; break; case AUTH_STATE_INVALID: - text = "wrong"; + text = state->args.text.clear; break; case AUTH_STATE_CLEAR: text = "cleared"; From 5bf9d7a18be6f110ecd5d9539af0cfc8bc6fdab8 Mon Sep 17 00:00:00 2001 From: Paulobergine Date: Mon, 7 Mar 2022 23:42:55 -0500 Subject: [PATCH 2/4] add new args struct --- include/swaylock.h | 8 ++++++++ main.c | 17 +++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/swaylock.h b/include/swaylock.h index 30f91176..d835613e 100644 --- a/include/swaylock.h +++ b/include/swaylock.h @@ -43,8 +43,16 @@ struct swaylock_colors { struct swaylock_colorset text; }; +struct swaylock_texts { + char clear[10]; + char caps_lock[10]; + char verifying[10]; + char wrong[10]; +}; + struct swaylock_args { struct swaylock_colors colors; + struct swaylock_texts texts; enum background_mode mode; char *font; uint32_t font_size; diff --git a/main.c b/main.c index 30dc30c1..b7a8e229 100644 --- a/main.c +++ b/main.c @@ -185,7 +185,7 @@ static void layer_surface_configure(void *data, surface->height = height; surface->indicator_width = 0; surface->indicator_height = 0; - surface->cleat_text = "test"; + //surface->clear_text = "test"; zwlr_layer_surface_v1_ack_configure(layer_surface, serial); render_frame_background(surface); render_frame(surface); @@ -549,6 +549,13 @@ static void set_default_colors(struct swaylock_colors *colors) { }; } +static void set_default_texts(struct swaylock_texts *texts) { + texts->clear = "Cleared"; + texts->caps_lock = "Caps lock"; + texts->verifying = "Verifying"; + texts->wrong = "Wrong"; +} + enum line_mode { LM_LINE, LM_INSIDE, @@ -649,7 +656,6 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, {"text-caps-lock-color", required_argument, NULL, LO_TEXT_CAPS_LOCK_COLOR}, {"text-ver-color", required_argument, NULL, LO_TEXT_VER_COLOR}, {"text-wrong-color", required_argument, NULL, LO_TEXT_WRONG_COLOR}, - //{"text-clear", required_argument, NULL, LO_TEXT_CLEAR}, {0, 0, 0, 0} }; @@ -1046,17 +1052,11 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, state->args.colors.text.wrong = parse_color(optarg); } break; - /*case LO_TEXT_CLEAR: - if( state) { - state->args.text.clear = optarg; - } - break;*/ default: fprintf(stderr, "%s", usage); return 1; } } - state->args.text.clear = "test"; return 0; } @@ -1185,6 +1185,7 @@ int main(int argc, char **argv) { }; wl_list_init(&state.images); set_default_colors(&state.args.colors); + set_default_texts(&state.args.texts); char *config_path = NULL; int result = parse_options(argc, argv, NULL, NULL, &config_path); From 6676f04be22b5270512b4900ea6eaefe380b81cb Mon Sep 17 00:00:00 2001 From: Paulobergine Date: Tue, 8 Mar 2022 09:54:33 -0500 Subject: [PATCH 3/4] Add args for text --- include/swaylock.h | 8 ++++---- main.c | 44 ++++++++++++++++++++++++++++++++++++-------- render.c | 8 ++++---- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/include/swaylock.h b/include/swaylock.h index d835613e..9bddbc6e 100644 --- a/include/swaylock.h +++ b/include/swaylock.h @@ -44,10 +44,10 @@ struct swaylock_colors { }; struct swaylock_texts { - char clear[10]; - char caps_lock[10]; - char verifying[10]; - char wrong[10]; + char *clear; + char *caps_lock; + char *verifying; + char *wrong; }; struct swaylock_args { diff --git a/main.c b/main.c index b7a8e229..d4d3a62f 100644 --- a/main.c +++ b/main.c @@ -185,7 +185,6 @@ static void layer_surface_configure(void *data, surface->height = height; surface->indicator_width = 0; surface->indicator_height = 0; - //surface->clear_text = "test"; zwlr_layer_surface_v1_ack_configure(layer_surface, serial); render_frame_background(surface); render_frame(surface); @@ -540,13 +539,6 @@ static void set_default_colors(struct swaylock_colors *colors) { .verifying = 0x3300FFFF, .wrong = 0x7D3300FF, }; - colors->text = (struct swaylock_colorset){ - .input = 0xE5A445FF, - .cleared = 0x000000FF, - .caps_lock = 0xE5A445FF, - .verifying = 0x000000FF, - .wrong = 0x000000FF, - }; } static void set_default_texts(struct swaylock_texts *texts) { @@ -600,6 +592,10 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, LO_TEXT_CAPS_LOCK_COLOR, LO_TEXT_VER_COLOR, LO_TEXT_WRONG_COLOR, + LO_TEXT_CLEAR, + LO_TEXT_CAPS_LOCK, + LO_TEXT_VER, + LO_TEXT_WRONG, }; static struct option long_options[] = { @@ -656,6 +652,10 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, {"text-caps-lock-color", required_argument, NULL, LO_TEXT_CAPS_LOCK_COLOR}, {"text-ver-color", required_argument, NULL, LO_TEXT_VER_COLOR}, {"text-wrong-color", required_argument, NULL, LO_TEXT_WRONG_COLOR}, + {"text-clear", required_argument, NULL, LO_TEXT_CLEAR}, + {"text-caps-lock", required_argument, NULL, LO_TEXT_CAPS_LOCK}, + {"text-ver", required_argument, NULL, LO_TEXT_VER}, + {"text-wrong", required_argument, NULL, LO_TEXT_WRONG}, {0, 0, 0, 0} }; @@ -776,6 +776,14 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, "Sets the color of the text when verifying.\n" " --text-wrong-color " "Sets the color of the text when invalid.\n" + " --text-clear " + "Sets the text when cleared.\n" + " --text-caps-lock " + "Sets the text when Caps Lock is active.\n" + " --text-ver " + "Sets the text when verifying.\n" + " --text-wrong " + "Sets the text when invalid.\n" "\n" "All options are of the form .\n"; @@ -1052,6 +1060,26 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, state->args.colors.text.wrong = parse_color(optarg); } break; + case LO_TEXT_CLEAR: + if (state) { + state->args.texts.clear = optarg; + } + break; + case LO_TEXT_CAPS_LOCK: + if (state) { + state->args.texts.caps_lock = optarg; + } + break; + case LO_TEXT_VER: + if (state) { + state->args.texts.verifying = optarg; + } + break; + case LO_TEXT_WRONG: + if (state) { + state->args.texts.wrong = optarg; + } + break; default: fprintf(stderr, "%s", usage); return 1; diff --git a/render.c b/render.c index d19141a9..6714a03a 100644 --- a/render.c +++ b/render.c @@ -163,20 +163,20 @@ void render_frame(struct swaylock_surface *surface) { } switch (state->auth_state) { case AUTH_STATE_VALIDATING: - text = "verifying"; + text = state->args.texts.verifying; break; case AUTH_STATE_INVALID: - text = state->args.text.clear; + text = state->args.texts.wrong; break; case AUTH_STATE_CLEAR: - text = "cleared"; + text = state->args.texts.clear; 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.texts.caps_lock; } else if (state->args.show_failed_attempts && state->failed_attempts > 0) { if (state->failed_attempts > 999) { From 6f7d2bc760b84379dcde1adf2fd1b9837dab9d93 Mon Sep 17 00:00:00 2001 From: Paulobergine Date: Tue, 8 Mar 2022 11:01:00 -0500 Subject: [PATCH 4/4] Add help messages --- completions/bash/swaylock | 4 ++++ completions/fish/swaylock.fish | 4 ++++ completions/zsh/_swaylock | 4 ++++ main.c | 7 +++++++ 4 files changed, 19 insertions(+) diff --git a/completions/bash/swaylock b/completions/bash/swaylock index 713fb4c0..4c661f94 100644 --- a/completions/bash/swaylock +++ b/completions/bash/swaylock @@ -78,6 +78,10 @@ _swaylock() --text-color --text-ver-color --text-wrong-color + --text-clear + --text-caps-lock + --text-ver + --text-wrong --tiling --version ) diff --git a/completions/fish/swaylock.fish b/completions/fish/swaylock.fish index 41416a39..82c16af9 100644 --- a/completions/fish/swaylock.fish +++ b/completions/fish/swaylock.fish @@ -51,5 +51,9 @@ complete -c swaylock -l text-clear-color --description "Sets the colo complete -c swaylock -l text-color --description "Sets the color of the text." complete -c swaylock -l text-ver-color --description "Sets the color of the text when verifying." complete -c swaylock -l text-wrong-color --description "Sets the color of the text when invalid." +complete -c swaylock -l text-clear --description "Sets the text when cleared." +complete -c swaylock -l text-caps-lock --description "Sets the text when Caps Lock is active." +complete -c swaylock -l text-ver --description "Sets the text when verifying." +complete -c swaylock -l text-wrong --description "Sets 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." diff --git a/completions/zsh/_swaylock b/completions/zsh/_swaylock index 9e9f7886..653bb0bb 100644 --- a/completions/zsh/_swaylock +++ b/completions/zsh/_swaylock @@ -55,5 +55,9 @@ _arguments -s \ '(--text-color)'--text-color'[Sets the color of the text]:color:' \ '(--text-ver-color)'--text-ver-color'[Sets the color of the text when verifying]:color:' \ '(--text-wrong-color)'--text-wrong-color'[Sets the color of the text when invalid]:color:' \ + '(--text-clear)'--text-clear'[Sets the text when cleared]:text:' \ + '(--text-caps-lock)'--text-caps-lock'[Sets the text when Caps Lock is active]:text:' \ + '(--text-ver)'--text-ver'[Sets the text when verifying]:text:' \ + '(--text-wrong)'--text-wrong'[Sets the text when invalid]:text:' \ '(--tiling -t)'{--tiling,-t}'[Same as --scaling=tile]' \ '(--version -v)'{--version,-v}'[Show the version number and quit]' diff --git a/main.c b/main.c index d4d3a62f..7357c562 100644 --- a/main.c +++ b/main.c @@ -539,6 +539,13 @@ static void set_default_colors(struct swaylock_colors *colors) { .verifying = 0x3300FFFF, .wrong = 0x7D3300FF, }; + colors->text = (struct swaylock_colorset){ + .input = 0xE5A445FF, + .cleared = 0x000000FF, + .caps_lock = 0xE5A445FF, + .verifying = 0x000000FF, + .wrong = 0x000000FF, + }; } static void set_default_texts(struct swaylock_texts *texts) {