diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-04-03 21:06:28 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2018-04-03 21:06:28 -0400 |
commit | 260595076977729bcaf9aadcfbbc8c5f269c6387 (patch) | |
tree | c102e0391d37aab306e7ac839b50906112491477 /swaybar/bar.c | |
parent | Merge pull request #1717 from emersion/fix-multiple-outputs (diff) | |
download | sway-260595076977729bcaf9aadcfbbc8c5f269c6387.tar.gz sway-260595076977729bcaf9aadcfbbc8c5f269c6387.tar.zst sway-260595076977729bcaf9aadcfbbc8c5f269c6387.zip |
Add hidpi support to swaybar
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r-- | swaybar/bar.c | 73 |
1 files changed, 63 insertions, 10 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index fb417095..cf812a60 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -69,11 +69,19 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, | |||
69 | break; | 69 | break; |
70 | } | 70 | } |
71 | } | 71 | } |
72 | int max_scale = 1; | ||
73 | struct swaybar_output *_output; | ||
74 | wl_list_for_each(_output, &bar->outputs, link) { | ||
75 | if (_output->scale > max_scale) { | ||
76 | max_scale = _output->scale; | ||
77 | } | ||
78 | } | ||
79 | wl_surface_set_buffer_scale(pointer->cursor_surface, max_scale); | ||
72 | wl_surface_attach(pointer->cursor_surface, | 80 | wl_surface_attach(pointer->cursor_surface, |
73 | wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0); | 81 | wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0); |
74 | wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface, | 82 | wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface, |
75 | pointer->cursor_image->hotspot_x, | 83 | pointer->cursor_image->hotspot_x / max_scale, |
76 | pointer->cursor_image->hotspot_y); | 84 | pointer->cursor_image->hotspot_y / max_scale); |
77 | wl_surface_commit(pointer->cursor_surface); | 85 | wl_surface_commit(pointer->cursor_surface); |
78 | } | 86 | } |
79 | 87 | ||
@@ -103,10 +111,12 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, | |||
103 | } | 111 | } |
104 | struct swaybar_hotspot *hotspot; | 112 | struct swaybar_hotspot *hotspot; |
105 | wl_list_for_each(hotspot, &output->hotspots, link) { | 113 | wl_list_for_each(hotspot, &output->hotspots, link) { |
106 | if (pointer->x >= hotspot->x | 114 | double x = pointer->x * output->scale; |
107 | && pointer->y >= hotspot->y | 115 | double y = pointer->y * output->scale; |
108 | && pointer->x < hotspot->x + hotspot->width | 116 | if (x >= hotspot->x |
109 | && pointer->y < hotspot->y + hotspot->height) { | 117 | && y >= hotspot->y |
118 | && x < hotspot->x + hotspot->width | ||
119 | && y < hotspot->y + hotspot->height) { | ||
110 | hotspot->callback(output, pointer->x, pointer->y, | 120 | hotspot->callback(output, pointer->x, pointer->y, |
111 | button, hotspot->data); | 121 | button, hotspot->data); |
112 | } | 122 | } |
@@ -197,12 +207,43 @@ const struct wl_seat_listener seat_listener = { | |||
197 | .name = seat_handle_name, | 207 | .name = seat_handle_name, |
198 | }; | 208 | }; |
199 | 209 | ||
210 | static void output_geometry(void *data, struct wl_output *output, int32_t x, | ||
211 | int32_t y, int32_t width_mm, int32_t height_mm, int32_t subpixel, | ||
212 | const char *make, const char *model, int32_t transform) { | ||
213 | // Who cares | ||
214 | } | ||
215 | |||
216 | static void output_mode(void *data, struct wl_output *output, uint32_t flags, | ||
217 | int32_t width, int32_t height, int32_t refresh) { | ||
218 | // Who cares | ||
219 | } | ||
220 | |||
221 | static void output_done(void *data, struct wl_output *output) { | ||
222 | // Who cares | ||
223 | } | ||
224 | |||
225 | static void output_scale(void *data, struct wl_output *wl_output, | ||
226 | int32_t factor) { | ||
227 | struct swaybar_output *output = data; | ||
228 | output->scale = factor; | ||
229 | if (output->surface) { | ||
230 | render_frame(output->bar, output); | ||
231 | } | ||
232 | } | ||
233 | |||
234 | struct wl_output_listener output_listener = { | ||
235 | .geometry = output_geometry, | ||
236 | .mode = output_mode, | ||
237 | .done = output_done, | ||
238 | .scale = output_scale, | ||
239 | }; | ||
240 | |||
200 | static void handle_global(void *data, struct wl_registry *registry, | 241 | static void handle_global(void *data, struct wl_registry *registry, |
201 | uint32_t name, const char *interface, uint32_t version) { | 242 | uint32_t name, const char *interface, uint32_t version) { |
202 | struct swaybar *bar = data; | 243 | struct swaybar *bar = data; |
203 | if (strcmp(interface, wl_compositor_interface.name) == 0) { | 244 | if (strcmp(interface, wl_compositor_interface.name) == 0) { |
204 | bar->compositor = wl_registry_bind(registry, name, | 245 | bar->compositor = wl_registry_bind(registry, name, |
205 | &wl_compositor_interface, 1); | 246 | &wl_compositor_interface, 3); |
206 | } else if (strcmp(interface, wl_seat_interface.name) == 0) { | 247 | } else if (strcmp(interface, wl_seat_interface.name) == 0) { |
207 | bar->seat = wl_registry_bind(registry, name, | 248 | bar->seat = wl_registry_bind(registry, name, |
208 | &wl_seat_interface, 1); | 249 | &wl_seat_interface, 1); |
@@ -216,7 +257,9 @@ static void handle_global(void *data, struct wl_registry *registry, | |||
216 | calloc(1, sizeof(struct swaybar_output)); | 257 | calloc(1, sizeof(struct swaybar_output)); |
217 | output->bar = bar; | 258 | output->bar = bar; |
218 | output->output = wl_registry_bind(registry, name, | 259 | output->output = wl_registry_bind(registry, name, |
219 | &wl_output_interface, 1); | 260 | &wl_output_interface, 3); |
261 | wl_output_add_listener(output->output, &output_listener, output); | ||
262 | output->scale = 1; | ||
220 | output->index = index++; | 263 | output->index = index++; |
221 | wl_list_init(&output->workspaces); | 264 | wl_list_init(&output->workspaces); |
222 | wl_list_init(&output->hotspots); | 265 | wl_list_init(&output->hotspots); |
@@ -262,9 +305,20 @@ void bar_setup(struct swaybar *bar, | |||
262 | wl_registry_add_listener(registry, ®istry_listener, bar); | 305 | wl_registry_add_listener(registry, ®istry_listener, bar); |
263 | wl_display_roundtrip(bar->display); | 306 | wl_display_roundtrip(bar->display); |
264 | assert(bar->compositor && bar->layer_shell && bar->shm); | 307 | assert(bar->compositor && bar->layer_shell && bar->shm); |
308 | wl_display_roundtrip(bar->display); | ||
309 | |||
265 | struct swaybar_pointer *pointer = &bar->pointer; | 310 | struct swaybar_pointer *pointer = &bar->pointer; |
266 | 311 | ||
267 | assert(pointer->cursor_theme = wl_cursor_theme_load(NULL, 16, bar->shm)); | 312 | int max_scale = 1; |
313 | struct swaybar_output *output; | ||
314 | wl_list_for_each(output, &bar->outputs, link) { | ||
315 | if (output->scale > max_scale) { | ||
316 | max_scale = output->scale; | ||
317 | } | ||
318 | } | ||
319 | |||
320 | assert(pointer->cursor_theme = wl_cursor_theme_load( | ||
321 | NULL, 16 * (max_scale * 2), bar->shm)); | ||
268 | struct wl_cursor *cursor; | 322 | struct wl_cursor *cursor; |
269 | assert(cursor = wl_cursor_theme_get_cursor( | 323 | assert(cursor = wl_cursor_theme_get_cursor( |
270 | pointer->cursor_theme, "left_ptr")); | 324 | pointer->cursor_theme, "left_ptr")); |
@@ -273,7 +327,6 @@ void bar_setup(struct swaybar *bar, | |||
273 | wl_compositor_create_surface(bar->compositor)); | 327 | wl_compositor_create_surface(bar->compositor)); |
274 | 328 | ||
275 | // TODO: we might not necessarily be meant to do all of the outputs | 329 | // TODO: we might not necessarily be meant to do all of the outputs |
276 | struct swaybar_output *output; | ||
277 | wl_list_for_each(output, &bar->outputs, link) { | 330 | wl_list_for_each(output, &bar->outputs, link) { |
278 | struct config_output *coutput; | 331 | struct config_output *coutput; |
279 | wl_list_for_each(coutput, &bar->config->outputs, link) { | 332 | wl_list_for_each(coutput, &bar->config->outputs, link) { |