diff options
author | 2018-07-23 20:27:56 -0400 | |
---|---|---|
committer | 2018-07-23 20:31:11 -0400 | |
commit | f4b882475eee7a81c206c7825616cc4656b2f60b (patch) | |
tree | 38e6ebf81b235424f105dcbcbb194e5e9eac70c0 /swaylock/render.c | |
parent | Implement pid->workspace tracking (diff) | |
parent | Merge pull request #2342 from RyanDwyer/update-cursor (diff) | |
download | sway-f4b882475eee7a81c206c7825616cc4656b2f60b.tar.gz sway-f4b882475eee7a81c206c7825616cc4656b2f60b.tar.zst sway-f4b882475eee7a81c206c7825616cc4656b2f60b.zip |
Merge branch 'master' into pid-workspaces
Diffstat (limited to 'swaylock/render.c')
-rw-r--r-- | swaylock/render.c | 77 |
1 files changed, 34 insertions, 43 deletions
diff --git a/swaylock/render.c b/swaylock/render.c index 2032ddcf..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 |
10 | const int ARC_RADIUS = 50; | ||
11 | const int ARC_THICKNESS = 10; | ||
12 | const float TYPE_INDICATOR_RANGE = M_PI / 3.0f; | 10 | const float TYPE_INDICATOR_RANGE = M_PI / 3.0f; |
13 | const float TYPE_INDICATOR_BORDER_THICKNESS = M_PI / 128.0f; | 11 | const float TYPE_INDICATOR_BORDER_THICKNESS = M_PI / 128.0f; |
14 | 12 | ||
13 | static 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 | |||
15 | void render_frame(struct swaylock_surface *surface) { | 26 | void render_frame(struct swaylock_surface *surface) { |
16 | struct swaylock_state *state = surface->state; | 27 | struct swaylock_state *state = surface->state; |
17 | 28 | ||
@@ -30,58 +41,37 @@ void render_frame(struct swaylock_surface *surface) { | |||
30 | cairo_t *cairo = surface->current_buffer->cairo; | 41 | cairo_t *cairo = surface->current_buffer->cairo; |
31 | cairo_identity_matrix(cairo); | 42 | cairo_identity_matrix(cairo); |
32 | 43 | ||
44 | cairo_save(cairo); | ||
45 | cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); | ||
33 | if (state->args.mode == BACKGROUND_MODE_SOLID_COLOR || !surface->image) { | 46 | if (state->args.mode == BACKGROUND_MODE_SOLID_COLOR || !surface->image) { |
34 | cairo_set_source_u32(cairo, state->args.color); | 47 | cairo_set_source_u32(cairo, state->args.colors.background); |
35 | cairo_paint(cairo); | 48 | cairo_paint(cairo); |
36 | } else { | 49 | } else { |
37 | render_background_image(cairo, surface->image, | 50 | render_background_image(cairo, surface->image, |
38 | state->args.mode, buffer_width, buffer_height); | 51 | state->args.mode, buffer_width, buffer_height); |
39 | } | 52 | } |
53 | cairo_restore(cairo); | ||
40 | cairo_identity_matrix(cairo); | 54 | cairo_identity_matrix(cairo); |
41 | 55 | ||
42 | int arc_radius = ARC_RADIUS * surface->scale; | 56 | int arc_radius = state->args.radius * surface->scale; |
43 | int arc_thickness = ARC_THICKNESS * surface->scale; | 57 | int arc_thickness = state->args.thickness * surface->scale; |
44 | float type_indicator_border_thickness = | 58 | float type_indicator_border_thickness = |
45 | TYPE_INDICATOR_BORDER_THICKNESS * surface->scale; | 59 | TYPE_INDICATOR_BORDER_THICKNESS * surface->scale; |
46 | 60 | ||
47 | if (state->args.show_indicator && state->auth_state != AUTH_STATE_IDLE) { | 61 | if (state->args.show_indicator && state->auth_state != AUTH_STATE_IDLE) { |
48 | // Draw circle | 62 | // Draw circle |
49 | cairo_set_line_width(cairo, arc_thickness); | 63 | cairo_set_line_width(cairo, arc_thickness); |
50 | 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, |
51 | switch (state->auth_state) { | 65 | 0, 2 * M_PI); |
52 | case AUTH_STATE_INPUT: | 66 | set_color_for_state(cairo, state, &state->args.colors.inside); |
53 | case AUTH_STATE_INPUT_NOP: | 67 | cairo_fill_preserve(cairo); |
54 | case AUTH_STATE_BACKSPACE: { | 68 | set_color_for_state(cairo, state, &state->args.colors.ring); |
55 | cairo_set_source_rgba(cairo, 0, 0, 0, 0.75); | 69 | cairo_stroke(cairo); |
56 | cairo_fill_preserve(cairo); | ||
57 | cairo_set_source_rgb(cairo, 51.0 / 255, 125.0 / 255, 0); | ||
58 | cairo_stroke(cairo); | ||
59 | } break; | ||
60 | case AUTH_STATE_VALIDATING: { | ||
61 | cairo_set_source_rgba(cairo, 0, 114.0 / 255, 255.0 / 255, 0.75); | ||
62 | cairo_fill_preserve(cairo); | ||
63 | cairo_set_source_rgb(cairo, 51.0 / 255, 0, 250.0 / 255); | ||
64 | cairo_stroke(cairo); | ||
65 | } break; | ||
66 | case AUTH_STATE_INVALID: { | ||
67 | cairo_set_source_rgba(cairo, 250.0 / 255, 0, 0, 0.75); | ||
68 | cairo_fill_preserve(cairo); | ||
69 | cairo_set_source_rgb(cairo, 125.0 / 255, 51.0 / 255, 0); | ||
70 | cairo_stroke(cairo); | ||
71 | } break; | ||
72 | case AUTH_STATE_CLEAR: { | ||
73 | cairo_set_source_rgba(cairo, 229.0/255, 164.0/255, 69.0/255, 0.75); | ||
74 | cairo_fill_preserve(cairo); | ||
75 | cairo_set_source_rgb(cairo, 229.0/255, 164.0/255, 69.0/255); | ||
76 | cairo_stroke(cairo); | ||
77 | } break; | ||
78 | default: break; | ||
79 | } | ||
80 | 70 | ||
81 | // Draw a message | 71 | // Draw a message |
82 | char *text = NULL; | 72 | char *text = NULL; |
83 | cairo_set_source_rgb(cairo, 0, 0, 0); | 73 | set_color_for_state(cairo, state, &state->args.colors.text); |
84 | cairo_select_font_face(cairo, "sans-serif", | 74 | cairo_select_font_face(cairo, state->args.font, |
85 | CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); | 75 | CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); |
86 | cairo_set_font_size(cairo, arc_radius / 3.0f); | 76 | cairo_set_font_size(cairo, arc_radius / 3.0f); |
87 | switch (state->auth_state) { | 77 | switch (state->auth_state) { |
@@ -98,9 +88,10 @@ void render_frame(struct swaylock_surface *surface) { | |||
98 | case AUTH_STATE_INPUT_NOP: | 88 | case AUTH_STATE_INPUT_NOP: |
99 | if (state->xkb.caps_lock) { | 89 | if (state->xkb.caps_lock) { |
100 | text = "Caps Lock"; | 90 | text = "Caps Lock"; |
101 | cairo_set_source_rgb(cairo, 229.0/255, 164.0/255, 69.0/255); | ||
102 | } | 91 | } |
103 | default: break; | 92 | break; |
93 | default: | ||
94 | break; | ||
104 | } | 95 | } |
105 | 96 | ||
106 | if (text) { | 97 | if (text) { |
@@ -128,14 +119,14 @@ void render_frame(struct swaylock_surface *surface) { | |||
128 | arc_radius, highlight_start, | 119 | arc_radius, highlight_start, |
129 | highlight_start + TYPE_INDICATOR_RANGE); | 120 | highlight_start + TYPE_INDICATOR_RANGE); |
130 | if (state->auth_state == AUTH_STATE_INPUT) { | 121 | if (state->auth_state == AUTH_STATE_INPUT) { |
131 | cairo_set_source_rgb(cairo, 51.0 / 255, 219.0 / 255, 0); | 122 | cairo_set_source_u32(cairo, state->args.colors.key_highlight); |
132 | } else { | 123 | } else { |
133 | cairo_set_source_rgb(cairo, 219.0 / 255, 51.0 / 255, 0); | 124 | cairo_set_source_u32(cairo, state->args.colors.bs_highlight); |
134 | } | 125 | } |
135 | cairo_stroke(cairo); | 126 | cairo_stroke(cairo); |
136 | 127 | ||
137 | // Draw borders | 128 | // Draw borders |
138 | cairo_set_source_rgb(cairo, 0, 0, 0); | 129 | cairo_set_source_u32(cairo, state->args.colors.separator); |
139 | cairo_arc(cairo, buffer_width / 2, buffer_height / 2, | 130 | cairo_arc(cairo, buffer_width / 2, buffer_height / 2, |
140 | arc_radius, highlight_start, | 131 | arc_radius, highlight_start, |
141 | highlight_start + type_indicator_border_thickness); | 132 | highlight_start + type_indicator_border_thickness); |
@@ -149,7 +140,7 @@ void render_frame(struct swaylock_surface *surface) { | |||
149 | } | 140 | } |
150 | 141 | ||
151 | // Draw inner + outer border of the circle | 142 | // Draw inner + outer border of the circle |
152 | cairo_set_source_rgb(cairo, 0, 0, 0); | 143 | set_color_for_state(cairo, state, &state->args.colors.line); |
153 | cairo_set_line_width(cairo, 2.0 * surface->scale); | 144 | cairo_set_line_width(cairo, 2.0 * surface->scale); |
154 | cairo_arc(cairo, buffer_width / 2, buffer_height / 2, | 145 | cairo_arc(cairo, buffer_width / 2, buffer_height / 2, |
155 | arc_radius - arc_thickness / 2, 0, 2 * M_PI); | 146 | arc_radius - arc_thickness / 2, 0, 2 * M_PI); |