aboutsummaryrefslogtreecommitdiff
path: root/swaylock/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaylock/main.c')
-rw-r--r--swaylock/main.c135
1 files changed, 68 insertions, 67 deletions
diff --git a/swaylock/main.c b/swaylock/main.c
index 47592409..c2615951 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -81,6 +81,9 @@ struct lock_config *init_config() {
config->colors.invalid.inner_ring = 0xFA0000BF;
config->colors.invalid.outer_ring = 0x7D3300FF;
+ config->radius = 50;
+ config->thickness = 10;
+
return config;
}
@@ -149,10 +152,11 @@ bool verify_password() {
void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint) {
int redraw_screen = 0;
char *password_realloc;
+ int i;
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
switch (sym) {
- case XKB_KEY_KP_Enter: // fallthrough
+ case XKB_KEY_KP_Enter:
case XKB_KEY_Return:
render_data.auth_state = AUTH_STATE_VALIDATING;
@@ -163,6 +167,7 @@ void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t cod
if (verify_password()) {
exit(0);
}
+
render_data.auth_state = AUTH_STATE_INVALID;
redraw_screen = 1;
@@ -171,73 +176,65 @@ void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t cod
password[0] = '\0';
break;
case XKB_KEY_BackSpace:
- {
- int i = strlen(password);
- if (i > 0) {
- password[i - 1] = '\0';
- render_data.auth_state = AUTH_STATE_BACKSPACE;
- redraw_screen = 1;
- }
- break;
+ i = strlen(password);
+ if (i > 0) {
+ password[i - 1] = '\0';
+ render_data.auth_state = AUTH_STATE_BACKSPACE;
+ redraw_screen = 1;
}
- case XKB_KEY_Control_L: // fallthrough
- case XKB_KEY_Control_R: // fallthrough
- case XKB_KEY_Shift_L: // fallthrough
- case XKB_KEY_Shift_R: // fallthrough
- case XKB_KEY_Caps_Lock: // fallthrough
- case XKB_KEY_Shift_Lock: // fallthrough
- case XKB_KEY_Meta_L: // fallthrough
- case XKB_KEY_Meta_R: // fallthrough
- case XKB_KEY_Alt_L: // fallthrough
- case XKB_KEY_Alt_R: // fallthrough
- case XKB_KEY_Super_L: // fallthrough
- case XKB_KEY_Super_R: // fallthrough
- case XKB_KEY_Hyper_L: // fallthrough
+ break;
+ case XKB_KEY_Control_L:
+ case XKB_KEY_Control_R:
+ case XKB_KEY_Shift_L:
+ case XKB_KEY_Shift_R:
+ case XKB_KEY_Caps_Lock:
+ case XKB_KEY_Shift_Lock:
+ case XKB_KEY_Meta_L:
+ case XKB_KEY_Meta_R:
+ case XKB_KEY_Alt_L:
+ case XKB_KEY_Alt_R:
+ case XKB_KEY_Super_L:
+ case XKB_KEY_Super_R:
+ case XKB_KEY_Hyper_L:
case XKB_KEY_Hyper_R:
- {
- // don't draw screen on modifier keys
- break;
- }
- case XKB_KEY_Escape: // fallthrough
- case XKB_KEY_u: // fallthrough
+ break; // don't draw screen on modifier keys
+ case XKB_KEY_Escape:
+ case XKB_KEY_u:
case XKB_KEY_U:
- {
- // clear password buffer on ctrl-u (or escape for i3lock compatibility)
- if (sym == XKB_KEY_Escape || xkb_state_mod_name_is_active(registry->input->xkb.state,
- XKB_MOD_NAME_CTRL, XKB_STATE_MODS_EFFECTIVE) > 0) {
- render_data.auth_state = AUTH_STATE_BACKSPACE;
- redraw_screen = 1;
+ // clear password buffer on ctrl-u (or escape for i3lock compatibility)
+ if (sym == XKB_KEY_Escape || xkb_state_mod_name_is_active(registry->input->xkb.state,
+ XKB_MOD_NAME_CTRL, XKB_STATE_MODS_EFFECTIVE) > 0) {
+ render_data.auth_state = AUTH_STATE_BACKSPACE;
+ redraw_screen = 1;
+ password_size = 1024;
+ free(password);
+ password = malloc(password_size);
+ password[0] = '\0';
+ break;
+ }
+ /* fallthrough */
+ default:
+ render_data.auth_state = AUTH_STATE_INPUT;
+ redraw_screen = 1;
+ i = strlen(password);
+ if (i + 1 == password_size) {
+ password_size += 1024;
+ password_realloc = realloc(password, password_size);
+ // reset password if realloc fails.
+ if (password_realloc == NULL) {
password_size = 1024;
free(password);
password = malloc(password_size);
password[0] = '\0';
break;
+ } else {
+ password = password_realloc;
}
}
- default:
- {
- render_data.auth_state = AUTH_STATE_INPUT;
- redraw_screen = 1;
- int i = strlen(password);
- if (i + 1 == password_size) {
- password_size += 1024;
- password_realloc = realloc(password, password_size);
- // reset password if realloc fails.
- if (password_realloc == NULL) {
- password_size = 1024;
- free(password);
- password = malloc(password_size);
- password[0] = '\0';
- break;
- } else {
- password = password_realloc;
- }
- }
- password[i] = (char)codepoint;
- password[i + 1] = '\0';
- break;
- }
+ password[i] = (char)codepoint;
+ password[i + 1] = '\0';
+ break;
}
if (redraw_screen) {
render(&render_data, config);
@@ -383,6 +380,8 @@ int main(int argc, char **argv) {
{"separatorcolor", required_argument, NULL, 0},
{"keyhlcolor", required_argument, NULL, 0},
{"bshlcolor", required_argument, NULL, 0},
+ {"indicator-radius", required_argument, NULL, 0},
+ {"indicator-thickness", required_argument, NULL, 0},
{0, 0, 0, 0}
};
@@ -509,6 +508,10 @@ int main(int argc, char **argv) {
config->colors.input_cursor = parse_color(optarg);
} else if (strcmp(long_options[option_index].name, "bshlcolor") == 0) {
config->colors.backspace_cursor = parse_color(optarg);
+ } else if (strcmp(long_options[option_index].name, "indicator-radius") == 0) {
+ config->radius = atoi(optarg);
+ } else if (strcmp(long_options[option_index].name, "indicator-thickness") == 0) {
+ config->thickness = atoi(optarg);
}
break;
default:
@@ -678,16 +681,14 @@ void render(struct render_data *render_data, struct lock_config *config) {
cairo_identity_matrix(window->cairo);
// Draw specific values (copied from i3)
- const int ARC_RADIUS = 50;
- const int ARC_THICKNESS = 10;
const float TYPE_INDICATOR_RANGE = M_PI / 3.0f;
const float TYPE_INDICATOR_BORDER_THICKNESS = M_PI / 128.0f;
// Add visual indicator
if (show_indicator && render_data->auth_state != AUTH_STATE_IDLE) {
// Draw circle
- cairo_set_line_width(window->cairo, ARC_THICKNESS);
- cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS, 0, 2 * M_PI);
+ cairo_set_line_width(window->cairo, config->thickness);
+ cairo_arc(window->cairo, wwidth/2, wheight/2, config->radius, 0, 2 * M_PI);
switch (render_data->auth_state) {
case AUTH_STATE_INPUT:
case AUTH_STATE_BACKSPACE: {
@@ -715,7 +716,7 @@ void render(struct render_data *render_data, struct lock_config *config) {
char *text = NULL;
cairo_set_source_u32(window->cairo, config->colors.text);
cairo_select_font_face(window->cairo, config->font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
- cairo_set_font_size(window->cairo, ARC_RADIUS/3.0f);
+ cairo_set_font_size(window->cairo, config->radius/3.0f);
switch (render_data->auth_state) {
case AUTH_STATE_VALIDATING:
text = "verifying";
@@ -744,7 +745,7 @@ void render(struct render_data *render_data, struct lock_config *config) {
if (render_data->auth_state == AUTH_STATE_INPUT || render_data->auth_state == AUTH_STATE_BACKSPACE) {
static double highlight_start = 0;
highlight_start += (rand() % (int)(M_PI * 100)) / 100.0 + M_PI * 0.5;
- cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS, highlight_start, highlight_start + TYPE_INDICATOR_RANGE);
+ cairo_arc(window->cairo, wwidth/2, wheight/2, config->radius, highlight_start, highlight_start + TYPE_INDICATOR_RANGE);
if (render_data->auth_state == AUTH_STATE_INPUT) {
cairo_set_source_u32(window->cairo, config->colors.input_cursor);
} else {
@@ -754,10 +755,10 @@ void render(struct render_data *render_data, struct lock_config *config) {
// Draw borders
cairo_set_source_u32(window->cairo, config->colors.separator);
- cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS, highlight_start, highlight_start + TYPE_INDICATOR_BORDER_THICKNESS);
+ cairo_arc(window->cairo, wwidth/2, wheight/2, config->radius, highlight_start, highlight_start + TYPE_INDICATOR_BORDER_THICKNESS);
cairo_stroke(window->cairo);
- cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS, highlight_start + TYPE_INDICATOR_RANGE, (highlight_start + TYPE_INDICATOR_RANGE) + TYPE_INDICATOR_BORDER_THICKNESS);
+ cairo_arc(window->cairo, wwidth/2, wheight/2, config->radius, highlight_start + TYPE_INDICATOR_RANGE, (highlight_start + TYPE_INDICATOR_RANGE) + TYPE_INDICATOR_BORDER_THICKNESS);
cairo_stroke(window->cairo);
}
@@ -793,9 +794,9 @@ void render(struct render_data *render_data, struct lock_config *config) {
}
// Draw inner + outer border of the circle
cairo_set_line_width(window->cairo, 2.0);
- cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS - ARC_THICKNESS/2, 0, 2*M_PI);
+ cairo_arc(window->cairo, wwidth/2, wheight/2, config->radius - config->thickness/2, 0, 2*M_PI);
cairo_stroke(window->cairo);
- cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS + ARC_THICKNESS/2, 0, 2*M_PI);
+ cairo_arc(window->cairo, wwidth/2, wheight/2, config->radius + config->thickness/2, 0, 2*M_PI);
cairo_stroke(window->cairo);
}
window_render(window);