summaryrefslogtreecommitdiffstats
path: root/swaylock/render.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaylock/render.c')
-rw-r--r--swaylock/render.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/swaylock/render.c b/swaylock/render.c
index 90db71e3..2469e60b 100644
--- a/swaylock/render.c
+++ b/swaylock/render.c
@@ -9,28 +9,32 @@
9void render_frame(struct swaylock_surface *surface) { 9void render_frame(struct swaylock_surface *surface) {
10 struct swaylock_state *state = surface->state; 10 struct swaylock_state *state = surface->state;
11 surface->current_buffer = get_next_buffer(state->shm, 11 surface->current_buffer = get_next_buffer(state->shm,
12 surface->buffers, surface->width, surface->height); 12 surface->buffers,
13 surface->width * surface->scale,
14 surface->height * surface->scale);
13 cairo_t *cairo = surface->current_buffer->cairo; 15 cairo_t *cairo = surface->current_buffer->cairo;
14 cairo_identity_matrix(cairo); 16 cairo_identity_matrix(cairo);
17
18 int buffer_width = surface->width * surface->scale;
19 int buffer_height = surface->height * surface->scale;
15 if (state->args.mode == BACKGROUND_MODE_SOLID_COLOR) { 20 if (state->args.mode == BACKGROUND_MODE_SOLID_COLOR) {
16 cairo_set_source_u32(cairo, state->args.color); 21 cairo_set_source_u32(cairo, state->args.color);
17 cairo_paint(cairo); 22 cairo_paint(cairo);
18 } else { 23 } else {
19 // TODO: hidpi
20 render_background_image(cairo, surface->image, 24 render_background_image(cairo, surface->image,
21 state->args.mode, surface->width, surface->height, 1); 25 state->args.mode, buffer_width, buffer_height);
22 } 26 }
23 cairo_identity_matrix(cairo); 27 cairo_identity_matrix(cairo);
24 28
25 const int ARC_RADIUS = 50; 29 int ARC_RADIUS = 50 * surface->scale;
26 const int ARC_THICKNESS = 10; 30 int ARC_THICKNESS = 10 * surface->scale;
27 const float TYPE_INDICATOR_RANGE = M_PI / 3.0f; 31 float TYPE_INDICATOR_RANGE = M_PI / 3.0f;
28 const float TYPE_INDICATOR_BORDER_THICKNESS = M_PI / 128.0f; 32 float TYPE_INDICATOR_BORDER_THICKNESS = M_PI / 128.0f * surface->scale;
33
29 if (state->args.show_indicator && state->auth_state != AUTH_STATE_IDLE) { 34 if (state->args.show_indicator && state->auth_state != AUTH_STATE_IDLE) {
30 // Draw circle 35 // Draw circle
31 cairo_set_line_width(cairo, ARC_THICKNESS); 36 cairo_set_line_width(cairo, ARC_THICKNESS);
32 cairo_arc(cairo, surface->width / 2, surface->height / 2, 37 cairo_arc(cairo, buffer_width / 2, buffer_height / 2, ARC_RADIUS, 0, 2 * M_PI);
33 ARC_RADIUS, 0, 2 * M_PI);
34 switch (state->auth_state) { 38 switch (state->auth_state) {
35 case AUTH_STATE_INPUT: 39 case AUTH_STATE_INPUT:
36 case AUTH_STATE_BACKSPACE: { 40 case AUTH_STATE_BACKSPACE: {
@@ -74,9 +78,9 @@ void render_frame(struct swaylock_surface *surface) {
74 cairo_text_extents_t extents; 78 cairo_text_extents_t extents;
75 double x, y; 79 double x, y;
76 cairo_text_extents(cairo, text, &extents); 80 cairo_text_extents(cairo, text, &extents);
77 x = (surface->width / 2) - 81 x = (buffer_width / 2) -
78 (extents.width / 2 + extents.x_bearing); 82 (extents.width / 2 + extents.x_bearing);
79 y = (surface->height / 2) - 83 y = (buffer_height / 2) -
80 (extents.height / 2 + extents.y_bearing); 84 (extents.height / 2 + extents.y_bearing);
81 85
82 cairo_move_to(cairo, x, y); 86 cairo_move_to(cairo, x, y);
@@ -91,7 +95,7 @@ void render_frame(struct swaylock_surface *surface) {
91 static double highlight_start = 0; 95 static double highlight_start = 0;
92 highlight_start += 96 highlight_start +=
93 (rand() % (int)(M_PI * 100)) / 100.0 + M_PI * 0.5; 97 (rand() % (int)(M_PI * 100)) / 100.0 + M_PI * 0.5;
94 cairo_arc(cairo, surface->width / 2, surface->height / 2, 98 cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
95 ARC_RADIUS, highlight_start, 99 ARC_RADIUS, highlight_start,
96 highlight_start + TYPE_INDICATOR_RANGE); 100 highlight_start + TYPE_INDICATOR_RANGE);
97 if (state->auth_state == AUTH_STATE_INPUT) { 101 if (state->auth_state == AUTH_STATE_INPUT) {
@@ -103,12 +107,12 @@ void render_frame(struct swaylock_surface *surface) {
103 107
104 // Draw borders 108 // Draw borders
105 cairo_set_source_rgb(cairo, 0, 0, 0); 109 cairo_set_source_rgb(cairo, 0, 0, 0);
106 cairo_arc(cairo, surface->width / 2, surface->height / 2, 110 cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
107 ARC_RADIUS, highlight_start, 111 ARC_RADIUS, highlight_start,
108 highlight_start + TYPE_INDICATOR_BORDER_THICKNESS); 112 highlight_start + TYPE_INDICATOR_BORDER_THICKNESS);
109 cairo_stroke(cairo); 113 cairo_stroke(cairo);
110 114
111 cairo_arc(cairo, surface->width / 2, surface->height / 2, 115 cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
112 ARC_RADIUS, highlight_start + TYPE_INDICATOR_RANGE, 116 ARC_RADIUS, highlight_start + TYPE_INDICATOR_RANGE,
113 highlight_start + TYPE_INDICATOR_RANGE + 117 highlight_start + TYPE_INDICATOR_RANGE +
114 TYPE_INDICATOR_BORDER_THICKNESS); 118 TYPE_INDICATOR_BORDER_THICKNESS);
@@ -117,17 +121,18 @@ void render_frame(struct swaylock_surface *surface) {
117 121
118 // Draw inner + outer border of the circle 122 // Draw inner + outer border of the circle
119 cairo_set_source_rgb(cairo, 0, 0, 0); 123 cairo_set_source_rgb(cairo, 0, 0, 0);
120 cairo_set_line_width(cairo, 2.0); 124 cairo_set_line_width(cairo, 2.0 * surface->scale);
121 cairo_arc(cairo, surface->width / 2, surface->height / 2, 125 cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
122 ARC_RADIUS - ARC_THICKNESS / 2, 0, 2 * M_PI); 126 ARC_RADIUS - ARC_THICKNESS / 2, 0, 2 * M_PI);
123 cairo_stroke(cairo); 127 cairo_stroke(cairo);
124 cairo_arc(cairo, surface->width / 2, surface->height / 2, 128 cairo_arc(cairo, buffer_width / 2, buffer_height / 2,
125 ARC_RADIUS + ARC_THICKNESS / 2, 0, 2 * M_PI); 129 ARC_RADIUS + ARC_THICKNESS / 2, 0, 2 * M_PI);
126 cairo_stroke(cairo); 130 cairo_stroke(cairo);
127 } 131 }
128 132
133 wl_surface_set_buffer_scale(surface->surface, surface->scale);
129 wl_surface_attach(surface->surface, surface->current_buffer->buffer, 0, 0); 134 wl_surface_attach(surface->surface, surface->current_buffer->buffer, 0, 0);
130 wl_surface_damage(surface->surface, 0, 0, surface->width, surface->height); 135 wl_surface_damage(surface->surface, 0, 0, buffer_width, buffer_height);
131 wl_surface_commit(surface->surface); 136 wl_surface_commit(surface->surface);
132 wl_display_roundtrip(state->display); 137 wl_display_roundtrip(state->display);
133} 138}