summaryrefslogtreecommitdiffstats
path: root/swaylock/render.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-07-10 21:29:15 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-07-10 21:29:15 -0400
commit936a920a8e95c001c86b9186d36fa652f874287d (patch)
treec56b4475f38f6ad5b783434dc609f0cfabeeec8a /swaylock/render.c
parentMerge pull request #2233 from emersion/remove-clipboard (diff)
downloadsway-936a920a8e95c001c86b9186d36fa652f874287d.tar.gz
sway-936a920a8e95c001c86b9186d36fa652f874287d.tar.zst
sway-936a920a8e95c001c86b9186d36fa652f874287d.zip
Implement swaylock customization flags
Diffstat (limited to 'swaylock/render.c')
-rw-r--r--swaylock/render.c74
1 files changed, 31 insertions, 43 deletions
diff --git a/swaylock/render.c b/swaylock/render.c
index ea23d0d8..66c55965 100644
--- a/swaylock/render.c
+++ b/swaylock/render.c
@@ -7,11 +7,22 @@
7#include "swaylock/swaylock.h" 7#include "swaylock/swaylock.h"
8 8
9#define M_PI 3.14159265358979323846 9#define M_PI 3.14159265358979323846
10const int ARC_RADIUS = 50;
11const int ARC_THICKNESS = 10;
12const float TYPE_INDICATOR_RANGE = M_PI / 3.0f; 10const float TYPE_INDICATOR_RANGE = M_PI / 3.0f;
13const float TYPE_INDICATOR_BORDER_THICKNESS = M_PI / 128.0f; 11const float TYPE_INDICATOR_BORDER_THICKNESS = M_PI / 128.0f;
14 12
13static void set_color_for_state(cairo_t *cairo, struct swaylock_state *state,
14 struct swaylock_colorset *colorset) {
15 if (state->auth_state == AUTH_STATE_VALIDATING) {
16 cairo_set_source_u32(cairo, colorset->verifying);
17 } else if (state->auth_state == AUTH_STATE_INVALID) {
18 cairo_set_source_u32(cairo, colorset->wrong);
19 } else if (state->auth_state == AUTH_STATE_CLEAR) {
20 cairo_set_source_u32(cairo, colorset->cleared);
21 } else {
22 cairo_set_source_u32(cairo, colorset->input);
23 }
24}
25
15void render_frame(struct swaylock_surface *surface) { 26void render_frame(struct swaylock_surface *surface) {
16 struct swaylock_state *state = surface->state; 27 struct swaylock_state *state = surface->state;
17 28
@@ -33,7 +44,7 @@ void render_frame(struct swaylock_surface *surface) {
33 cairo_save(cairo); 44 cairo_save(cairo);
34 cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); 45 cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
35 if (state->args.mode == BACKGROUND_MODE_SOLID_COLOR || !surface->image) { 46 if (state->args.mode == BACKGROUND_MODE_SOLID_COLOR || !surface->image) {
36 cairo_set_source_u32(cairo, state->args.color); 47 cairo_set_source_u32(cairo, state->args.colors.background);
37 cairo_paint(cairo); 48 cairo_paint(cairo);
38 } else { 49 } else {
39 render_background_image(cairo, surface->image, 50 render_background_image(cairo, surface->image,
@@ -42,49 +53,25 @@ void render_frame(struct swaylock_surface *surface) {
42 cairo_restore(cairo); 53 cairo_restore(cairo);
43 cairo_identity_matrix(cairo); 54 cairo_identity_matrix(cairo);
44 55
45 int arc_radius = ARC_RADIUS * surface->scale; 56 int arc_radius = state->args.radius * surface->scale;
46 int arc_thickness = ARC_THICKNESS * surface->scale; 57 int arc_thickness = state->args.thickness * surface->scale;
47 float type_indicator_border_thickness = 58 float type_indicator_border_thickness =
48 TYPE_INDICATOR_BORDER_THICKNESS * surface->scale; 59 TYPE_INDICATOR_BORDER_THICKNESS * surface->scale;
49 60
50 if (state->args.show_indicator && state->auth_state != AUTH_STATE_IDLE) { 61 if (state->args.show_indicator && state->auth_state != AUTH_STATE_IDLE) {
51 // Draw circle 62 // Draw circle
52 cairo_set_line_width(cairo, arc_thickness); 63 cairo_set_line_width(cairo, arc_thickness);
53 cairo_arc(cairo, buffer_width / 2, buffer_height / 2, arc_radius, 0, 2 * M_PI); 64 cairo_arc(cairo, buffer_width / 2, buffer_height / 2, arc_radius,
54 switch (state->auth_state) { 65 0, 2 * M_PI);
55 case AUTH_STATE_INPUT: 66 set_color_for_state(cairo, state, &state->args.colors.inside);
56 case AUTH_STATE_INPUT_NOP: 67 cairo_fill_preserve(cairo);
57 case AUTH_STATE_BACKSPACE: { 68 set_color_for_state(cairo, state, &state->args.colors.ring);
58 cairo_set_source_rgba(cairo, 0, 0, 0, 0.75); 69 cairo_stroke(cairo);
59 cairo_fill_preserve(cairo);
60 cairo_set_source_rgb(cairo, 51.0 / 255, 125.0 / 255, 0);
61 cairo_stroke(cairo);
62 } break;
63 case AUTH_STATE_VALIDATING: {
64 cairo_set_source_rgba(cairo, 0, 114.0 / 255, 255.0 / 255, 0.75);
65 cairo_fill_preserve(cairo);
66 cairo_set_source_rgb(cairo, 51.0 / 255, 0, 250.0 / 255);
67 cairo_stroke(cairo);
68 } break;
69 case AUTH_STATE_INVALID: {
70 cairo_set_source_rgba(cairo, 250.0 / 255, 0, 0, 0.75);
71 cairo_fill_preserve(cairo);
72 cairo_set_source_rgb(cairo, 125.0 / 255, 51.0 / 255, 0);
73 cairo_stroke(cairo);
74 } break;
75 case AUTH_STATE_CLEAR: {
76 cairo_set_source_rgba(cairo, 229.0/255, 164.0/255, 69.0/255, 0.75);
77 cairo_fill_preserve(cairo);
78 cairo_set_source_rgb(cairo, 229.0/255, 164.0/255, 69.0/255);
79 cairo_stroke(cairo);
80 } break;
81 default: break;
82 }
83 70
84 // Draw a message 71 // Draw a message
85 char *text = NULL; 72 char *text = NULL;
86 cairo_set_source_rgb(cairo, 0, 0, 0); 73 set_color_for_state(cairo, state, &state->args.colors.text);
87 cairo_select_font_face(cairo, "sans-serif", 74 cairo_select_font_face(cairo, state->args.font,
88 CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); 75 CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
89 cairo_set_font_size(cairo, arc_radius / 3.0f); 76 cairo_set_font_size(cairo, arc_radius / 3.0f);
90 switch (state->auth_state) { 77 switch (state->auth_state) {
@@ -101,9 +88,10 @@ void render_frame(struct swaylock_surface *surface) {
101 case AUTH_STATE_INPUT_NOP: 88 case AUTH_STATE_INPUT_NOP:
102 if (state->xkb.caps_lock) { 89 if (state->xkb.caps_lock) {
103 text = "Caps Lock"; 90 text = "Caps Lock";
104 cairo_set_source_rgb(cairo, 229.0/255, 164.0/255, 69.0/255);
105 } 91 }
106 default: break; 92 break;
93 default:
94 break;
107 } 95 }
108 96
109 if (text) { 97 if (text) {
@@ -131,14 +119,14 @@ void render_frame(struct swaylock_surface *surface) {
131 arc_radius, highlight_start, 119 arc_radius, highlight_start,
132 highlight_start + TYPE_INDICATOR_RANGE); 120 highlight_start + TYPE_INDICATOR_RANGE);
133 if (state->auth_state == AUTH_STATE_INPUT) { 121 if (state->auth_state == AUTH_STATE_INPUT) {
134 cairo_set_source_rgb(cairo, 51.0 / 255, 219.0 / 255, 0); 122 cairo_set_source_u32(cairo, state->args.colors.key_highlight);
135 } else { 123 } else {
136 cairo_set_source_rgb(cairo, 219.0 / 255, 51.0 / 255, 0); 124 cairo_set_source_u32(cairo, state->args.colors.bs_highlight);
137 } 125 }
138 cairo_stroke(cairo); 126 cairo_stroke(cairo);
139 127
140 // Draw borders 128 // Draw borders
141 cairo_set_source_rgb(cairo, 0, 0, 0); 129 cairo_set_source_u32(cairo, state->args.colors.separator);
142 cairo_arc(cairo, buffer_width / 2, buffer_height / 2, 130 cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
143 arc_radius, highlight_start, 131 arc_radius, highlight_start,
144 highlight_start + type_indicator_border_thickness); 132 highlight_start + type_indicator_border_thickness);
@@ -152,7 +140,7 @@ void render_frame(struct swaylock_surface *surface) {
152 } 140 }
153 141
154 // Draw inner + outer border of the circle 142 // Draw inner + outer border of the circle
155 cairo_set_source_rgb(cairo, 0, 0, 0); 143 set_color_for_state(cairo, state, &state->args.colors.line);
156 cairo_set_line_width(cairo, 2.0 * surface->scale); 144 cairo_set_line_width(cairo, 2.0 * surface->scale);
157 cairo_arc(cairo, buffer_width / 2, buffer_height / 2, 145 cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
158 arc_radius - arc_thickness / 2, 0, 2 * M_PI); 146 arc_radius - arc_thickness / 2, 0, 2 * M_PI);