aboutsummaryrefslogtreecommitdiffstats
path: root/swaylock
diff options
context:
space:
mode:
authorLibravatar Calvin Lee <cyrus296@gmail.com>2017-07-31 14:48:48 +0200
committerLibravatar Calvin Lee <cyrus296@gmail.com>2017-07-31 19:49:01 +0200
commit23f11d7c45b25ec8752ab08cc7065b8a3e8b4399 (patch)
tree6c37414aae964cd387ae68314a8ada0214d9d7a3 /swaylock
parentRemove test clipboard code (diff)
downloadsway-23f11d7c45b25ec8752ab08cc7065b8a3e8b4399.tar.gz
sway-23f11d7c45b25ec8752ab08cc7065b8a3e8b4399.tar.zst
sway-23f11d7c45b25ec8752ab08cc7065b8a3e8b4399.zip
Allow swaylock indicator size to be configurable
Diffstat (limited to 'swaylock')
-rw-r--r--swaylock/main.c27
-rw-r--r--swaylock/swaylock.1.txt8
2 files changed, 25 insertions, 10 deletions
diff --git a/swaylock/main.c b/swaylock/main.c
index 47592409..e624df46 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -81,6 +81,9 @@ struct lock_config *init_config() {
81 config->colors.invalid.inner_ring = 0xFA0000BF; 81 config->colors.invalid.inner_ring = 0xFA0000BF;
82 config->colors.invalid.outer_ring = 0x7D3300FF; 82 config->colors.invalid.outer_ring = 0x7D3300FF;
83 83
84 config->radius = 50;
85 config->thickness = 10;
86
84 return config; 87 return config;
85} 88}
86 89
@@ -383,6 +386,8 @@ int main(int argc, char **argv) {
383 {"separatorcolor", required_argument, NULL, 0}, 386 {"separatorcolor", required_argument, NULL, 0},
384 {"keyhlcolor", required_argument, NULL, 0}, 387 {"keyhlcolor", required_argument, NULL, 0},
385 {"bshlcolor", required_argument, NULL, 0}, 388 {"bshlcolor", required_argument, NULL, 0},
389 {"indicator-radius", required_argument, NULL, 0},
390 {"indicator-thickness", required_argument, NULL, 0},
386 {0, 0, 0, 0} 391 {0, 0, 0, 0}
387 }; 392 };
388 393
@@ -509,6 +514,10 @@ int main(int argc, char **argv) {
509 config->colors.input_cursor = parse_color(optarg); 514 config->colors.input_cursor = parse_color(optarg);
510 } else if (strcmp(long_options[option_index].name, "bshlcolor") == 0) { 515 } else if (strcmp(long_options[option_index].name, "bshlcolor") == 0) {
511 config->colors.backspace_cursor = parse_color(optarg); 516 config->colors.backspace_cursor = parse_color(optarg);
517 } else if (strcmp(long_options[option_index].name, "indicator-radius") == 0) {
518 config->radius = atoi(optarg);
519 } else if (strcmp(long_options[option_index].name, "indicator-thickness") == 0) {
520 config->thickness = atoi(optarg);
512 } 521 }
513 break; 522 break;
514 default: 523 default:
@@ -678,16 +687,14 @@ void render(struct render_data *render_data, struct lock_config *config) {
678 cairo_identity_matrix(window->cairo); 687 cairo_identity_matrix(window->cairo);
679 688
680 // Draw specific values (copied from i3) 689 // Draw specific values (copied from i3)
681 const int ARC_RADIUS = 50;
682 const int ARC_THICKNESS = 10;
683 const float TYPE_INDICATOR_RANGE = M_PI / 3.0f; 690 const float TYPE_INDICATOR_RANGE = M_PI / 3.0f;
684 const float TYPE_INDICATOR_BORDER_THICKNESS = M_PI / 128.0f; 691 const float TYPE_INDICATOR_BORDER_THICKNESS = M_PI / 128.0f;
685 692
686 // Add visual indicator 693 // Add visual indicator
687 if (show_indicator && render_data->auth_state != AUTH_STATE_IDLE) { 694 if (show_indicator && render_data->auth_state != AUTH_STATE_IDLE) {
688 // Draw circle 695 // Draw circle
689 cairo_set_line_width(window->cairo, ARC_THICKNESS); 696 cairo_set_line_width(window->cairo, config->thickness);
690 cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS, 0, 2 * M_PI); 697 cairo_arc(window->cairo, wwidth/2, wheight/2, config->radius, 0, 2 * M_PI);
691 switch (render_data->auth_state) { 698 switch (render_data->auth_state) {
692 case AUTH_STATE_INPUT: 699 case AUTH_STATE_INPUT:
693 case AUTH_STATE_BACKSPACE: { 700 case AUTH_STATE_BACKSPACE: {
@@ -715,7 +722,7 @@ void render(struct render_data *render_data, struct lock_config *config) {
715 char *text = NULL; 722 char *text = NULL;
716 cairo_set_source_u32(window->cairo, config->colors.text); 723 cairo_set_source_u32(window->cairo, config->colors.text);
717 cairo_select_font_face(window->cairo, config->font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); 724 cairo_select_font_face(window->cairo, config->font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
718 cairo_set_font_size(window->cairo, ARC_RADIUS/3.0f); 725 cairo_set_font_size(window->cairo, config->radius/3.0f);
719 switch (render_data->auth_state) { 726 switch (render_data->auth_state) {
720 case AUTH_STATE_VALIDATING: 727 case AUTH_STATE_VALIDATING:
721 text = "verifying"; 728 text = "verifying";
@@ -744,7 +751,7 @@ void render(struct render_data *render_data, struct lock_config *config) {
744 if (render_data->auth_state == AUTH_STATE_INPUT || render_data->auth_state == AUTH_STATE_BACKSPACE) { 751 if (render_data->auth_state == AUTH_STATE_INPUT || render_data->auth_state == AUTH_STATE_BACKSPACE) {
745 static double highlight_start = 0; 752 static double highlight_start = 0;
746 highlight_start += (rand() % (int)(M_PI * 100)) / 100.0 + M_PI * 0.5; 753 highlight_start += (rand() % (int)(M_PI * 100)) / 100.0 + M_PI * 0.5;
747 cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS, highlight_start, highlight_start + TYPE_INDICATOR_RANGE); 754 cairo_arc(window->cairo, wwidth/2, wheight/2, config->radius, highlight_start, highlight_start + TYPE_INDICATOR_RANGE);
748 if (render_data->auth_state == AUTH_STATE_INPUT) { 755 if (render_data->auth_state == AUTH_STATE_INPUT) {
749 cairo_set_source_u32(window->cairo, config->colors.input_cursor); 756 cairo_set_source_u32(window->cairo, config->colors.input_cursor);
750 } else { 757 } else {
@@ -754,10 +761,10 @@ void render(struct render_data *render_data, struct lock_config *config) {
754 761
755 // Draw borders 762 // Draw borders
756 cairo_set_source_u32(window->cairo, config->colors.separator); 763 cairo_set_source_u32(window->cairo, config->colors.separator);
757 cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS, highlight_start, highlight_start + TYPE_INDICATOR_BORDER_THICKNESS); 764 cairo_arc(window->cairo, wwidth/2, wheight/2, config->radius, highlight_start, highlight_start + TYPE_INDICATOR_BORDER_THICKNESS);
758 cairo_stroke(window->cairo); 765 cairo_stroke(window->cairo);
759 766
760 cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS, highlight_start + TYPE_INDICATOR_RANGE, (highlight_start + TYPE_INDICATOR_RANGE) + TYPE_INDICATOR_BORDER_THICKNESS); 767 cairo_arc(window->cairo, wwidth/2, wheight/2, config->radius, highlight_start + TYPE_INDICATOR_RANGE, (highlight_start + TYPE_INDICATOR_RANGE) + TYPE_INDICATOR_BORDER_THICKNESS);
761 cairo_stroke(window->cairo); 768 cairo_stroke(window->cairo);
762 } 769 }
763 770
@@ -793,9 +800,9 @@ void render(struct render_data *render_data, struct lock_config *config) {
793 } 800 }
794 // Draw inner + outer border of the circle 801 // Draw inner + outer border of the circle
795 cairo_set_line_width(window->cairo, 2.0); 802 cairo_set_line_width(window->cairo, 2.0);
796 cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS - ARC_THICKNESS/2, 0, 2*M_PI); 803 cairo_arc(window->cairo, wwidth/2, wheight/2, config->radius - config->thickness/2, 0, 2*M_PI);
797 cairo_stroke(window->cairo); 804 cairo_stroke(window->cairo);
798 cairo_arc(window->cairo, wwidth/2, wheight/2, ARC_RADIUS + ARC_THICKNESS/2, 0, 2*M_PI); 805 cairo_arc(window->cairo, wwidth/2, wheight/2, config->radius + config->thickness/2, 0, 2*M_PI);
799 cairo_stroke(window->cairo); 806 cairo_stroke(window->cairo);
800 } 807 }
801 window_render(window); 808 window_render(window);
diff --git a/swaylock/swaylock.1.txt b/swaylock/swaylock.1.txt
index 0e503f29..4c462794 100644
--- a/swaylock/swaylock.1.txt
+++ b/swaylock/swaylock.1.txt
@@ -95,6 +95,14 @@ Appearance
95*--textcolor* <rrggbb[aa]>:: 95*--textcolor* <rrggbb[aa]>::
96 Sets the color of the text inside the indicator. 96 Sets the color of the text inside the indicator.
97 97
98*--indicator-radius* <radius>::
99 Sets the radius of the indicator to _radius_ pixels. The default value is
100 50.
101
102*--indicator-thickness* <thickness>::
103 Sets the thickness of the indicator to _thickness_ pixels. The default value
104 is 10.
105
98Authors 106Authors
99------- 107-------
100 108