Add option show-failed-attempts
Keeps track of unsuccessful authentication attempts via an int counter in the state struct. Displays on the unlock indicator, but will be replaced by the Caps Lock text if enabled.
This commit is contained in:
parent
ecc8402c43
commit
40e9098a74
@ -50,6 +50,7 @@ struct swaylock_args {
|
|||||||
bool show_indicator;
|
bool show_indicator;
|
||||||
bool show_caps_lock_text;
|
bool show_caps_lock_text;
|
||||||
bool show_caps_lock_indicator;
|
bool show_caps_lock_indicator;
|
||||||
|
bool show_failed_attempts;
|
||||||
bool daemonize;
|
bool daemonize;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -73,6 +74,7 @@ struct swaylock_state {
|
|||||||
struct swaylock_password password;
|
struct swaylock_password password;
|
||||||
struct swaylock_xkb xkb;
|
struct swaylock_xkb xkb;
|
||||||
enum auth_state auth_state;
|
enum auth_state auth_state;
|
||||||
|
int failed_attempts;
|
||||||
bool run_display;
|
bool run_display;
|
||||||
struct zxdg_output_manager_v1 *zxdg_output_manager;
|
struct zxdg_output_manager_v1 *zxdg_output_manager;
|
||||||
};
|
};
|
||||||
|
15
main.c
15
main.c
@ -508,6 +508,7 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
|
|||||||
{"scaling", required_argument, NULL, 's'},
|
{"scaling", required_argument, NULL, 's'},
|
||||||
{"tiling", no_argument, NULL, 't'},
|
{"tiling", no_argument, NULL, 't'},
|
||||||
{"no-unlock-indicator", no_argument, NULL, 'u'},
|
{"no-unlock-indicator", no_argument, NULL, 'u'},
|
||||||
|
{"show-failed-attempts", no_argument, NULL, 'F'},
|
||||||
{"version", no_argument, NULL, 'v'},
|
{"version", no_argument, NULL, 'v'},
|
||||||
{"bs-hl-color", required_argument, NULL, LO_BS_HL_COLOR},
|
{"bs-hl-color", required_argument, NULL, LO_BS_HL_COLOR},
|
||||||
{"caps-lock-bs-hl-color", required_argument, NULL, LO_CAPS_LOCK_BS_HL_COLOR},
|
{"caps-lock-bs-hl-color", required_argument, NULL, LO_CAPS_LOCK_BS_HL_COLOR},
|
||||||
@ -567,6 +568,8 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
|
|||||||
"Same as --scaling=tile.\n"
|
"Same as --scaling=tile.\n"
|
||||||
" -u, --no-unlock-indicator "
|
" -u, --no-unlock-indicator "
|
||||||
"Disable the unlock indicator.\n"
|
"Disable the unlock indicator.\n"
|
||||||
|
" -F, --show-failed-attempts "
|
||||||
|
"Show current count of failed authentication attempts.\n"
|
||||||
" -v, --version "
|
" -v, --version "
|
||||||
"Show the version number and quit.\n"
|
"Show the version number and quit.\n"
|
||||||
" --bs-hl-color <color> "
|
" --bs-hl-color <color> "
|
||||||
@ -644,7 +647,7 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
|
|||||||
optind = 1;
|
optind = 1;
|
||||||
while (1) {
|
while (1) {
|
||||||
int opt_idx = 0;
|
int opt_idx = 0;
|
||||||
c = getopt_long(argc, argv, "c:defhi:Llnrs:tuvC:", long_options,
|
c = getopt_long(argc, argv, "c:deFfhi:Llnrs:tuvC:", long_options,
|
||||||
&opt_idx);
|
&opt_idx);
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
break;
|
break;
|
||||||
@ -716,6 +719,11 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
|
|||||||
state->args.show_indicator = false;
|
state->args.show_indicator = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'F':
|
||||||
|
if (state) {
|
||||||
|
state->args.show_failed_attempts = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
fprintf(stdout, "swaylock version " SWAYLOCK_VERSION "\n");
|
fprintf(stdout, "swaylock version " SWAYLOCK_VERSION "\n");
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
@ -961,6 +969,7 @@ static void comm_in(int fd, short mask, void *data) {
|
|||||||
} else {
|
} else {
|
||||||
state.auth_state = AUTH_STATE_INVALID;
|
state.auth_state = AUTH_STATE_INVALID;
|
||||||
schedule_indicator_clear(&state);
|
schedule_indicator_clear(&state);
|
||||||
|
++state.failed_attempts;
|
||||||
damage_state(&state);
|
damage_state(&state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -970,6 +979,7 @@ int main(int argc, char **argv) {
|
|||||||
initialize_pw_backend(argc, argv);
|
initialize_pw_backend(argc, argv);
|
||||||
|
|
||||||
enum line_mode line_mode = LM_LINE;
|
enum line_mode line_mode = LM_LINE;
|
||||||
|
state.failed_attempts = 0;
|
||||||
state.args = (struct swaylock_args){
|
state.args = (struct swaylock_args){
|
||||||
.mode = BACKGROUND_MODE_FILL,
|
.mode = BACKGROUND_MODE_FILL,
|
||||||
.font = strdup("sans-serif"),
|
.font = strdup("sans-serif"),
|
||||||
@ -978,7 +988,8 @@ int main(int argc, char **argv) {
|
|||||||
.ignore_empty = false,
|
.ignore_empty = false,
|
||||||
.show_indicator = true,
|
.show_indicator = true,
|
||||||
.show_caps_lock_indicator = false,
|
.show_caps_lock_indicator = false,
|
||||||
.show_caps_lock_text = true
|
.show_caps_lock_text = true,
|
||||||
|
.show_failed_attempts = false
|
||||||
};
|
};
|
||||||
wl_list_init(&state.images);
|
wl_list_init(&state.images);
|
||||||
set_default_colors(&state.args.colors);
|
set_default_colors(&state.args.colors);
|
||||||
|
10
render.c
10
render.c
@ -86,6 +86,7 @@ void render_frame(struct swaylock_surface *surface) {
|
|||||||
|
|
||||||
// Draw a message
|
// Draw a message
|
||||||
char *text = NULL;
|
char *text = NULL;
|
||||||
|
char attempts[4]; // like i3lock: count no more than 999
|
||||||
set_color_for_state(cairo, state, &state->args.colors.text);
|
set_color_for_state(cairo, state, &state->args.colors.text);
|
||||||
cairo_select_font_face(cairo, state->args.font,
|
cairo_select_font_face(cairo, state->args.font,
|
||||||
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
||||||
@ -103,8 +104,17 @@ void render_frame(struct swaylock_surface *surface) {
|
|||||||
case AUTH_STATE_INPUT:
|
case AUTH_STATE_INPUT:
|
||||||
case AUTH_STATE_INPUT_NOP:
|
case AUTH_STATE_INPUT_NOP:
|
||||||
case AUTH_STATE_BACKSPACE:
|
case AUTH_STATE_BACKSPACE:
|
||||||
|
// Caps Lock has higher priority
|
||||||
if (state->xkb.caps_lock && state->args.show_caps_lock_text) {
|
if (state->xkb.caps_lock && state->args.show_caps_lock_text) {
|
||||||
text = "Caps Lock";
|
text = "Caps Lock";
|
||||||
|
} else if (state->args.show_failed_attempts &&
|
||||||
|
state->failed_attempts > 0) {
|
||||||
|
if (state->failed_attempts > 999) {
|
||||||
|
text = "999+";
|
||||||
|
} else {
|
||||||
|
snprintf(attempts, sizeof(attempts), "%d", state->failed_attempts);
|
||||||
|
text = attempts;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -54,6 +54,9 @@ Locks your Wayland session.
|
|||||||
*-l, --indicator-caps-lock*
|
*-l, --indicator-caps-lock*
|
||||||
Show the current Caps Lock state also on the indicator.
|
Show the current Caps Lock state also on the indicator.
|
||||||
|
|
||||||
|
*-F, --show-failed-attempts*
|
||||||
|
Show the number of failed authentication attempts on the indicator.
|
||||||
|
|
||||||
*-s, --scaling*
|
*-s, --scaling*
|
||||||
Scaling mode for images: _stretch_, _fill_, _fit_, _center_, or _tile_. Use
|
Scaling mode for images: _stretch_, _fill_, _fit_, _center_, or _tile_. Use
|
||||||
the additional mode _solid\_color_ to display only the background color, even
|
the additional mode _solid\_color_ to display only the background color, even
|
||||||
|
Loading…
Reference in New Issue
Block a user