diff options
author | emersion <contact@emersion.fr> | 2018-04-03 16:47:06 -0400 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-04-03 16:47:06 -0400 |
commit | 9b4f8637a93258157245700a4fd4f7e0eefc86a3 (patch) | |
tree | c2d3525c5487f66e1883443f65f4805cce0ea7d7 /swaybg/main.c | |
parent | Fix #1709 (diff) | |
download | sway-9b4f8637a93258157245700a4fd4f7e0eefc86a3.tar.gz sway-9b4f8637a93258157245700a4fd4f7e0eefc86a3.tar.zst sway-9b4f8637a93258157245700a4fd4f7e0eefc86a3.zip |
swaybg: add HiDPI support
Diffstat (limited to 'swaybg/main.c')
-rw-r--r-- | swaybg/main.c | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/swaybg/main.c b/swaybg/main.c index 203082f6..053225bd 100644 --- a/swaybg/main.c +++ b/swaybg/main.c | |||
@@ -47,6 +47,7 @@ struct swaybg_state { | |||
47 | 47 | ||
48 | bool run_display; | 48 | bool run_display; |
49 | uint32_t width, height; | 49 | uint32_t width, height; |
50 | int32_t scale; | ||
50 | struct pool_buffer buffers[2]; | 51 | struct pool_buffer buffers[2]; |
51 | struct pool_buffer *current_buffer; | 52 | struct pool_buffer *current_buffer; |
52 | }; | 53 | }; |
@@ -74,8 +75,8 @@ static void render_image(struct swaybg_state *state) { | |||
74 | cairo_surface_t *image = state->context.image; | 75 | cairo_surface_t *image = state->context.image; |
75 | double width = cairo_image_surface_get_width(image); | 76 | double width = cairo_image_surface_get_width(image); |
76 | double height = cairo_image_surface_get_height(image); | 77 | double height = cairo_image_surface_get_height(image); |
77 | int wwidth = state->width; | 78 | int wwidth = state->width * state->scale; |
78 | int wheight = state->height; | 79 | int wheight = state->height * state->scale; |
79 | 80 | ||
80 | switch (state->args->mode) { | 81 | switch (state->args->mode) { |
81 | case BACKGROUND_MODE_STRETCH: | 82 | case BACKGROUND_MODE_STRETCH: |
@@ -135,8 +136,8 @@ static void render_image(struct swaybg_state *state) { | |||
135 | } | 136 | } |
136 | 137 | ||
137 | static void render_frame(struct swaybg_state *state) { | 138 | static void render_frame(struct swaybg_state *state) { |
138 | state->current_buffer = get_next_buffer(state->shm, | 139 | state->current_buffer = get_next_buffer(state->shm, state->buffers, |
139 | state->buffers, state->width, state->height); | 140 | state->width * state->scale, state->height * state->scale); |
140 | cairo_t *cairo = state->current_buffer->cairo; | 141 | cairo_t *cairo = state->current_buffer->cairo; |
141 | 142 | ||
142 | switch (state->args->mode) { | 143 | switch (state->args->mode) { |
@@ -149,6 +150,7 @@ static void render_frame(struct swaybg_state *state) { | |||
149 | break; | 150 | break; |
150 | } | 151 | } |
151 | 152 | ||
153 | wl_surface_set_buffer_scale(state->surface, state->scale); | ||
152 | wl_surface_attach(state->surface, state->current_buffer->buffer, 0, 0); | 154 | wl_surface_attach(state->surface, state->current_buffer->buffer, 0, 0); |
153 | wl_surface_damage(state->surface, 0, 0, state->width, state->height); | 155 | wl_surface_damage(state->surface, 0, 0, state->width, state->height); |
154 | wl_surface_commit(state->surface); | 156 | wl_surface_commit(state->surface); |
@@ -212,12 +214,42 @@ struct zwlr_layer_surface_v1_listener layer_surface_listener = { | |||
212 | .closed = layer_surface_closed, | 214 | .closed = layer_surface_closed, |
213 | }; | 215 | }; |
214 | 216 | ||
217 | static void output_geometry(void *data, struct wl_output *output, int32_t x, | ||
218 | int32_t y, int32_t width_mm, int32_t height_mm, int32_t subpixel, | ||
219 | const char *make, const char *model, int32_t transform) { | ||
220 | // Who cares | ||
221 | } | ||
222 | |||
223 | static void output_mode(void *data, struct wl_output *output, uint32_t flags, | ||
224 | int32_t width, int32_t height, int32_t refresh) { | ||
225 | // Who cares | ||
226 | } | ||
227 | |||
228 | static void output_done(void *data, struct wl_output *output) { | ||
229 | // Who cares | ||
230 | } | ||
231 | |||
232 | static void output_scale(void *data, struct wl_output *output, int32_t factor) { | ||
233 | struct swaybg_state *state = data; | ||
234 | state->scale = factor; | ||
235 | if (state->run_display) { | ||
236 | render_frame(state); | ||
237 | } | ||
238 | } | ||
239 | |||
240 | struct wl_output_listener output_listener = { | ||
241 | .geometry = output_geometry, | ||
242 | .mode = output_mode, | ||
243 | .done = output_done, | ||
244 | .scale = output_scale, | ||
245 | }; | ||
246 | |||
215 | static void handle_global(void *data, struct wl_registry *registry, | 247 | static void handle_global(void *data, struct wl_registry *registry, |
216 | uint32_t name, const char *interface, uint32_t version) { | 248 | uint32_t name, const char *interface, uint32_t version) { |
217 | struct swaybg_state *state = data; | 249 | struct swaybg_state *state = data; |
218 | if (strcmp(interface, wl_compositor_interface.name) == 0) { | 250 | if (strcmp(interface, wl_compositor_interface.name) == 0) { |
219 | state->compositor = wl_registry_bind(registry, name, | 251 | state->compositor = wl_registry_bind(registry, name, |
220 | &wl_compositor_interface, 1); | 252 | &wl_compositor_interface, 3); |
221 | } else if (strcmp(interface, wl_shm_interface.name) == 0) { | 253 | } else if (strcmp(interface, wl_shm_interface.name) == 0) { |
222 | state->shm = wl_registry_bind(registry, name, | 254 | state->shm = wl_registry_bind(registry, name, |
223 | &wl_shm_interface, 1); | 255 | &wl_shm_interface, 1); |
@@ -225,7 +257,8 @@ static void handle_global(void *data, struct wl_registry *registry, | |||
225 | static int output_idx = 0; | 257 | static int output_idx = 0; |
226 | if (output_idx == state->args->output_idx) { | 258 | if (output_idx == state->args->output_idx) { |
227 | state->output = wl_registry_bind(registry, name, | 259 | state->output = wl_registry_bind(registry, name, |
228 | &wl_output_interface, 1); | 260 | &wl_output_interface, 3); |
261 | wl_output_add_listener(state->output, &output_listener, state); | ||
229 | } | 262 | } |
230 | output_idx++; | 263 | output_idx++; |
231 | } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { | 264 | } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { |
@@ -287,6 +320,9 @@ int main(int argc, const char **argv) { | |||
287 | wl_display_roundtrip(state.display); | 320 | wl_display_roundtrip(state.display); |
288 | assert(state.compositor && state.layer_shell && state.output && state.shm); | 321 | assert(state.compositor && state.layer_shell && state.output && state.shm); |
289 | 322 | ||
323 | // Second roundtrip to get output properties | ||
324 | wl_display_roundtrip(state.display); | ||
325 | |||
290 | assert(state.surface = wl_compositor_create_surface(state.compositor)); | 326 | assert(state.surface = wl_compositor_create_surface(state.compositor)); |
291 | 327 | ||
292 | state.layer_surface = zwlr_layer_shell_v1_get_layer_surface( | 328 | state.layer_surface = zwlr_layer_shell_v1_get_layer_surface( |