summaryrefslogtreecommitdiffstats
path: root/swaylock/render.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaylock/render.c')
-rw-r--r--swaylock/render.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/swaylock/render.c b/swaylock/render.c
index cb3ed276..cd387be5 100644
--- a/swaylock/render.c
+++ b/swaylock/render.c
@@ -7,18 +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;
13const float TYPE_INDICATOR_BORDER_THICKNESS = M_PI / 128.0f;
10 14
11void render_frame(struct swaylock_surface *surface) { 15void render_frame(struct swaylock_surface *surface) {
12 struct swaylock_state *state = surface->state; 16 struct swaylock_state *state = surface->state;
17
18 int buffer_width = surface->width * surface->scale;
19 int buffer_height = surface->height * surface->scale;
20
13 surface->current_buffer = get_next_buffer(state->shm, 21 surface->current_buffer = get_next_buffer(state->shm,
14 surface->buffers, 22 surface->buffers, buffer_width, buffer_height);
15 surface->width * surface->scale,
16 surface->height * surface->scale);
17 cairo_t *cairo = surface->current_buffer->cairo; 23 cairo_t *cairo = surface->current_buffer->cairo;
18 cairo_identity_matrix(cairo); 24 cairo_identity_matrix(cairo);
19 25
20 int buffer_width = surface->width * surface->scale;
21 int buffer_height = surface->height * surface->scale;
22 if (state->args.mode == BACKGROUND_MODE_SOLID_COLOR) { 26 if (state->args.mode == BACKGROUND_MODE_SOLID_COLOR) {
23 cairo_set_source_u32(cairo, state->args.color); 27 cairo_set_source_u32(cairo, state->args.color);
24 cairo_paint(cairo); 28 cairo_paint(cairo);
@@ -28,15 +32,15 @@ void render_frame(struct swaylock_surface *surface) {
28 } 32 }
29 cairo_identity_matrix(cairo); 33 cairo_identity_matrix(cairo);
30 34
31 int ARC_RADIUS = 50 * surface->scale; 35 int arc_radius = ARC_RADIUS * surface->scale;
32 int ARC_THICKNESS = 10 * surface->scale; 36 int arc_thickness = ARC_THICKNESS * surface->scale;
33 float TYPE_INDICATOR_RANGE = M_PI / 3.0f; 37 float type_indicator_border_thickness =
34 float TYPE_INDICATOR_BORDER_THICKNESS = M_PI / 128.0f * surface->scale; 38 TYPE_INDICATOR_BORDER_THICKNESS * surface->scale;
35 39
36 if (state->args.show_indicator && state->auth_state != AUTH_STATE_IDLE) { 40 if (state->args.show_indicator && state->auth_state != AUTH_STATE_IDLE) {
37 // Draw circle 41 // Draw circle
38 cairo_set_line_width(cairo, ARC_THICKNESS); 42 cairo_set_line_width(cairo, arc_thickness);
39 cairo_arc(cairo, buffer_width / 2, buffer_height / 2, ARC_RADIUS, 0, 2 * M_PI); 43 cairo_arc(cairo, buffer_width / 2, buffer_height / 2, arc_radius, 0, 2 * M_PI);
40 switch (state->auth_state) { 44 switch (state->auth_state) {
41 case AUTH_STATE_INPUT: 45 case AUTH_STATE_INPUT:
42 case AUTH_STATE_BACKSPACE: { 46 case AUTH_STATE_BACKSPACE: {
@@ -65,7 +69,7 @@ void render_frame(struct swaylock_surface *surface) {
65 cairo_set_source_rgb(cairo, 0, 0, 0); 69 cairo_set_source_rgb(cairo, 0, 0, 0);
66 cairo_select_font_face(cairo, "sans-serif", 70 cairo_select_font_face(cairo, "sans-serif",
67 CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); 71 CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
68 cairo_set_font_size(cairo, ARC_RADIUS / 3.0f); 72 cairo_set_font_size(cairo, arc_radius / 3.0f);
69 switch (state->auth_state) { 73 switch (state->auth_state) {
70 case AUTH_STATE_VALIDATING: 74 case AUTH_STATE_VALIDATING:
71 text = "verifying"; 75 text = "verifying";
@@ -98,7 +102,7 @@ void render_frame(struct swaylock_surface *surface) {
98 highlight_start += 102 highlight_start +=
99 (rand() % (int)(M_PI * 100)) / 100.0 + M_PI * 0.5; 103 (rand() % (int)(M_PI * 100)) / 100.0 + M_PI * 0.5;
100 cairo_arc(cairo, buffer_width / 2, buffer_height / 2, 104 cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
101 ARC_RADIUS, highlight_start, 105 arc_radius, highlight_start,
102 highlight_start + TYPE_INDICATOR_RANGE); 106 highlight_start + TYPE_INDICATOR_RANGE);
103 if (state->auth_state == AUTH_STATE_INPUT) { 107 if (state->auth_state == AUTH_STATE_INPUT) {
104 cairo_set_source_rgb(cairo, 51.0 / 255, 219.0 / 255, 0); 108 cairo_set_source_rgb(cairo, 51.0 / 255, 219.0 / 255, 0);
@@ -110,14 +114,14 @@ void render_frame(struct swaylock_surface *surface) {
110 // Draw borders 114 // Draw borders
111 cairo_set_source_rgb(cairo, 0, 0, 0); 115 cairo_set_source_rgb(cairo, 0, 0, 0);
112 cairo_arc(cairo, buffer_width / 2, buffer_height / 2, 116 cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
113 ARC_RADIUS, highlight_start, 117 arc_radius, highlight_start,
114 highlight_start + TYPE_INDICATOR_BORDER_THICKNESS); 118 highlight_start + type_indicator_border_thickness);
115 cairo_stroke(cairo); 119 cairo_stroke(cairo);
116 120
117 cairo_arc(cairo, buffer_width / 2, buffer_height / 2, 121 cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
118 ARC_RADIUS, highlight_start + TYPE_INDICATOR_RANGE, 122 arc_radius, highlight_start + TYPE_INDICATOR_RANGE,
119 highlight_start + TYPE_INDICATOR_RANGE + 123 highlight_start + TYPE_INDICATOR_RANGE +
120 TYPE_INDICATOR_BORDER_THICKNESS); 124 type_indicator_border_thickness);
121 cairo_stroke(cairo); 125 cairo_stroke(cairo);
122 } 126 }
123 127
@@ -125,16 +129,16 @@ void render_frame(struct swaylock_surface *surface) {
125 cairo_set_source_rgb(cairo, 0, 0, 0); 129 cairo_set_source_rgb(cairo, 0, 0, 0);
126 cairo_set_line_width(cairo, 2.0 * surface->scale); 130 cairo_set_line_width(cairo, 2.0 * surface->scale);
127 cairo_arc(cairo, buffer_width / 2, buffer_height / 2, 131 cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
128 ARC_RADIUS - ARC_THICKNESS / 2, 0, 2 * M_PI); 132 arc_radius - arc_thickness / 2, 0, 2 * M_PI);
129 cairo_stroke(cairo); 133 cairo_stroke(cairo);
130 cairo_arc(cairo, buffer_width / 2, buffer_height / 2, 134 cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
131 ARC_RADIUS + ARC_THICKNESS / 2, 0, 2 * M_PI); 135 arc_radius + arc_thickness / 2, 0, 2 * M_PI);
132 cairo_stroke(cairo); 136 cairo_stroke(cairo);
133 } 137 }
134 138
135 wl_surface_set_buffer_scale(surface->surface, surface->scale); 139 wl_surface_set_buffer_scale(surface->surface, surface->scale);
136 wl_surface_attach(surface->surface, surface->current_buffer->buffer, 0, 0); 140 wl_surface_attach(surface->surface, surface->current_buffer->buffer, 0, 0);
137 wl_surface_damage(surface->surface, 0, 0, buffer_width, buffer_height); 141 wl_surface_damage(surface->surface, 0, 0, surface->width, surface->height);
138 wl_surface_commit(surface->surface); 142 wl_surface_commit(surface->surface);
139} 143}
140 144