Merge pull request #1294 from 4e554c4c/swaylock_size

Allow swaylock indicator size to be configurable
master
Drew DeVault 7 years ago committed by GitHub
commit f59fb6bc76

@ -56,6 +56,9 @@ struct lock_config {
struct lock_colors validating; struct lock_colors validating;
struct lock_colors invalid; struct lock_colors invalid;
} colors; } colors;
int radius;
int thickness;
}; };
void render(struct render_data* render_data, struct lock_config *config); void render(struct render_data* render_data, struct lock_config *config);

@ -81,6 +81,9 @@ struct lock_config *init_config() {
config->colors.invalid.inner_ring = 0xFA0000BF; config->colors.invalid.inner_ring = 0xFA0000BF;
config->colors.invalid.outer_ring = 0x7D3300FF; config->colors.invalid.outer_ring = 0x7D3300FF;
config->radius = 50;
config->thickness = 10;
return config; return config;
} }
@ -383,6 +386,8 @@ int main(int argc, char **argv) {
{"separatorcolor", required_argument, NULL, 0}, {"separatorcolor", required_argument, NULL, 0},
{"keyhlcolor", required_argument, NULL, 0}, {"keyhlcolor", required_argument, NULL, 0},
{"bshlcolor", 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} {0, 0, 0, 0}
}; };
@ -509,6 +514,10 @@ int main(int argc, char **argv) {
config->colors.input_cursor = parse_color(optarg); config->colors.input_cursor = parse_color(optarg);
} else if (strcmp(long_options[option_index].name, "bshlcolor") == 0) { } else if (strcmp(long_options[option_index].name, "bshlcolor") == 0) {
config->colors.backspace_cursor = parse_color(optarg); 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; break;
default: default:
@ -678,16 +687,14 @@ void render(struct render_data *render_data, struct lock_config *config) {
cairo_identity_matrix(window->cairo); cairo_identity_matrix(window->cairo);
// Draw specific values (copied from i3) // 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_RANGE = M_PI / 3.0f;
const float TYPE_INDICATOR_BORDER_THICKNESS = M_PI / 128.0f; const float TYPE_INDICATOR_BORDER_THICKNESS = M_PI / 128.0f;
// Add visual indicator // Add visual indicator
if (show_indicator && render_data->auth_state != AUTH_STATE_IDLE) { if (show_indicator && render_data->auth_state != AUTH_STATE_IDLE) {
// Draw circle // Draw circle
cairo_set_line_width(window->cairo, ARC_THICKNESS); cairo_set_line_width(window->cairo, config->thickness);
cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS, 0, 2 * M_PI); cairo_arc(window->cairo, wwidth/2, wheight/2, config->radius, 0, 2 * M_PI);
switch (render_data->auth_state) { switch (render_data->auth_state) {
case AUTH_STATE_INPUT: case AUTH_STATE_INPUT:
case AUTH_STATE_BACKSPACE: { case AUTH_STATE_BACKSPACE: {
@ -715,7 +722,7 @@ void render(struct render_data *render_data, struct lock_config *config) {
char *text = NULL; char *text = NULL;
cairo_set_source_u32(window->cairo, config->colors.text); 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_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) { switch (render_data->auth_state) {
case AUTH_STATE_VALIDATING: case AUTH_STATE_VALIDATING:
text = "verifying"; text = "verifying";
@ -744,7 +751,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) { if (render_data->auth_state == AUTH_STATE_INPUT || render_data->auth_state == AUTH_STATE_BACKSPACE) {
static double highlight_start = 0; static double highlight_start = 0;
highlight_start += (rand() % (int)(M_PI * 100)) / 100.0 + M_PI * 0.5; 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) { if (render_data->auth_state == AUTH_STATE_INPUT) {
cairo_set_source_u32(window->cairo, config->colors.input_cursor); cairo_set_source_u32(window->cairo, config->colors.input_cursor);
} else { } else {
@ -754,10 +761,10 @@ void render(struct render_data *render_data, struct lock_config *config) {
// Draw borders // Draw borders
cairo_set_source_u32(window->cairo, config->colors.separator); 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_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); cairo_stroke(window->cairo);
} }
@ -793,9 +800,9 @@ void render(struct render_data *render_data, struct lock_config *config) {
} }
// Draw inner + outer border of the circle // Draw inner + outer border of the circle
cairo_set_line_width(window->cairo, 2.0); 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_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); cairo_stroke(window->cairo);
} }
window_render(window); window_render(window);

@ -95,6 +95,14 @@ Appearance
*--textcolor* <rrggbb[aa]>:: *--textcolor* <rrggbb[aa]>::
Sets the color of the text inside the indicator. Sets the color of the text inside the indicator.
*--indicator-radius* <radius>::
Sets the radius of the indicator to _radius_ pixels. The default value is
50.
*--indicator-thickness* <thickness>::
Sets the thickness of the indicator to _thickness_ pixels. The default value
is 10.
Authors Authors
------- -------

Loading…
Cancel
Save