aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-04-03 19:15:14 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-04-04 18:47:48 -0400
commit46b388995d7d50a39d13fce9417e2ad0d2cf749f (patch)
treeb675d26dbb554c9aef25839cf3f09cf82f6f9b92
parentImplement input-inhibit in sway, swaylock (diff)
downloadsway-46b388995d7d50a39d13fce9417e2ad0d2cf749f.tar.gz
sway-46b388995d7d50a39d13fce9417e2ad0d2cf749f.tar.zst
sway-46b388995d7d50a39d13fce9417e2ad0d2cf749f.zip
Add hidpi support to swaylock
-rw-r--r--include/swaylock/swaylock.h1
-rw-r--r--swaylock/main.c35
-rw-r--r--swaylock/render.c41
3 files changed, 57 insertions, 20 deletions
diff --git a/include/swaylock/swaylock.h b/include/swaylock/swaylock.h
index 06c94ead..173e8b12 100644
--- a/include/swaylock/swaylock.h
+++ b/include/swaylock/swaylock.h
@@ -52,6 +52,7 @@ struct swaylock_surface {
52 struct pool_buffer buffers[2]; 52 struct pool_buffer buffers[2];
53 struct pool_buffer *current_buffer; 53 struct pool_buffer *current_buffer;
54 uint32_t width, height; 54 uint32_t width, height;
55 int32_t scale;
55 struct wl_list link; 56 struct wl_list link;
56}; 57};
57 58
diff --git a/swaylock/main.c b/swaylock/main.c
index 6cd4e41d..1eda3afc 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -56,12 +56,42 @@ static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
56 .closed = layer_surface_closed, 56 .closed = layer_surface_closed,
57}; 57};
58 58
59static void output_geometry(void *data, struct wl_output *output, int32_t x,
60 int32_t y, int32_t width_mm, int32_t height_mm, int32_t subpixel,
61 const char *make, const char *model, int32_t transform) {
62 // Who cares
63}
64
65static void output_mode(void *data, struct wl_output *output, uint32_t flags,
66 int32_t width, int32_t height, int32_t refresh) {
67 // Who cares
68}
69
70static void output_done(void *data, struct wl_output *output) {
71 // Who cares
72}
73
74static void output_scale(void *data, struct wl_output *output, int32_t factor) {
75 struct swaylock_surface *surface = data;
76 surface->scale = factor;
77 if (surface->state->run_display) {
78 render_frames(surface->state);
79 }
80}
81
82struct wl_output_listener output_listener = {
83 .geometry = output_geometry,
84 .mode = output_mode,
85 .done = output_done,
86 .scale = output_scale,
87};
88
59static void handle_global(void *data, struct wl_registry *registry, 89static void handle_global(void *data, struct wl_registry *registry,
60 uint32_t name, const char *interface, uint32_t version) { 90 uint32_t name, const char *interface, uint32_t version) {
61 struct swaylock_state *state = data; 91 struct swaylock_state *state = data;
62 if (strcmp(interface, wl_compositor_interface.name) == 0) { 92 if (strcmp(interface, wl_compositor_interface.name) == 0) {
63 state->compositor = wl_registry_bind(registry, name, 93 state->compositor = wl_registry_bind(registry, name,
64 &wl_compositor_interface, 1); 94 &wl_compositor_interface, 3);
65 } else if (strcmp(interface, wl_shm_interface.name) == 0) { 95 } else if (strcmp(interface, wl_shm_interface.name) == 0) {
66 state->shm = wl_registry_bind(registry, name, 96 state->shm = wl_registry_bind(registry, name,
67 &wl_shm_interface, 1); 97 &wl_shm_interface, 1);
@@ -80,7 +110,8 @@ static void handle_global(void *data, struct wl_registry *registry,
80 calloc(1, sizeof(struct swaylock_surface)); 110 calloc(1, sizeof(struct swaylock_surface));
81 surface->state = state; 111 surface->state = state;
82 surface->output = wl_registry_bind(registry, name, 112 surface->output = wl_registry_bind(registry, name,
83 &wl_output_interface, 1); 113 &wl_output_interface, 3);
114 wl_output_add_listener(surface->output, &output_listener, surface);
84 wl_list_insert(&state->surfaces, &surface->link); 115 wl_list_insert(&state->surfaces, &surface->link);
85 } 116 }
86} 117}
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}