Skip to content

Add possibility to update texts #230

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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 @@ -78,6 +78,10 @@ _swaylock()
--text-color
--text-ver-color
--text-wrong-color
--text-clear
--text-caps-lock
--text-ver
--text-wrong
--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 @@ -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."
4 changes: 4 additions & 0 deletions completions/zsh/_swaylock
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
8 changes: 8 additions & 0 deletions include/swaylock.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,16 @@ struct swaylock_colors {
struct swaylock_colorset text;
};

struct swaylock_texts {
char *clear;
char *caps_lock;
char *verifying;
char *wrong;
};

struct swaylock_args {
struct swaylock_colors colors;
struct swaylock_texts texts;
enum background_mode mode;
char *font;
uint32_t font_size;
Expand Down
44 changes: 44 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,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,
Expand Down Expand Up @@ -592,6 +599,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[] = {
Expand Down Expand Up @@ -648,6 +659,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}
};

Expand Down Expand Up @@ -768,6 +783,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 <color> "
"Sets the color of the text when invalid.\n"
" --text-clear <text> "
"Sets the text when cleared.\n"
" --text-caps-lock <text> "
"Sets the text when Caps Lock is active.\n"
" --text-ver <text> "
"Sets the text when verifying.\n"
" --text-wrong <text> "
"Sets the text when invalid.\n"
"\n"
"All <color> options are of the form <rrggbb[aa]>.\n";

Expand Down Expand Up @@ -1044,6 +1067,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;
Expand Down Expand Up @@ -1177,6 +1220,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);
Expand Down
8 changes: 4 additions & 4 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "wrong";
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) {
Expand Down