aboutsummaryrefslogtreecommitdiffstats
path: root/swaylock
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-04-04 18:52:44 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-04-04 18:52:44 -0400
commit5d444b34f6af17894e2808c9d25948db625dabde (patch)
tree4702abb406a59fb8588cbd2019741e99d40bcbfe /swaylock
parentexit() needs stdlib.h (diff)
downloadsway-5d444b34f6af17894e2808c9d25948db625dabde.tar.gz
sway-5d444b34f6af17894e2808c9d25948db625dabde.tar.zst
sway-5d444b34f6af17894e2808c9d25948db625dabde.zip
Address review feedback from @emersion
Diffstat (limited to 'swaylock')
-rw-r--r--swaylock/main.c7
-rw-r--r--swaylock/password.c3
-rw-r--r--swaylock/render.c44
3 files changed, 30 insertions, 24 deletions
diff --git a/swaylock/main.c b/swaylock/main.c
index 1eda3afc..1d522184 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -216,7 +216,8 @@ int main(int argc, char **argv) {
216 216
217 wl_list_init(&state.surfaces); 217 wl_list_init(&state.surfaces);
218 state.xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); 218 state.xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
219 assert(state.display = wl_display_connect(NULL)); 219 state.display = wl_display_connect(NULL);
220 assert(state.display);
220 221
221 struct wl_registry *registry = wl_display_get_registry(state.display); 222 struct wl_registry *registry = wl_display_get_registry(state.display);
222 wl_registry_add_listener(registry, &registry_listener, &state); 223 wl_registry_add_listener(registry, &registry_listener, &state);
@@ -236,8 +237,8 @@ int main(int argc, char **argv) {
236 wl_list_for_each(surface, &state.surfaces, link) { 237 wl_list_for_each(surface, &state.surfaces, link) {
237 surface->image = background_image; 238 surface->image = background_image;
238 239
239 assert(surface->surface = 240 surface->surface = wl_compositor_create_surface(state.compositor);
240 wl_compositor_create_surface(state.compositor)); 241 assert(surface->surface);
241 242
242 surface->layer_surface = zwlr_layer_shell_v1_get_layer_surface( 243 surface->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
243 state.layer_shell, surface->surface, surface->output, 244 state.layer_shell, surface->surface, surface->output,
diff --git a/swaylock/password.c b/swaylock/password.c
index 06c1180c..1839f991 100644
--- a/swaylock/password.c
+++ b/swaylock/password.c
@@ -103,7 +103,8 @@ void swaylock_handle_key(struct swaylock_state *state,
103 render_frames(state); 103 render_frames(state);
104 wl_display_roundtrip(state->display); 104 wl_display_roundtrip(state->display);
105 if (attempt_password(&state->password)) { 105 if (attempt_password(&state->password)) {
106 exit(0); 106 state->run_display = false;
107 break;
107 } 108 }
108 state->auth_state = AUTH_STATE_INVALID; 109 state->auth_state = AUTH_STATE_INVALID;
109 render_frames(state); 110 render_frames(state);
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