diff options
author | emersion <contact@emersion.fr> | 2018-04-03 23:00:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-03 23:00:46 -0400 |
commit | 3ea7d2d10ed0d6d68e5bf3dd4efac765eb2b0212 (patch) | |
tree | b7a2db86f6f547db827c29633e88c40a5ef9d9fc /swaybar/bar.c | |
parent | Merge pull request #1721 from emersion/fix-output-container-coords (diff) | |
parent | Address review feedback (diff) | |
download | sway-3ea7d2d10ed0d6d68e5bf3dd4efac765eb2b0212.tar.gz sway-3ea7d2d10ed0d6d68e5bf3dd4efac765eb2b0212.tar.zst sway-3ea7d2d10ed0d6d68e5bf3dd4efac765eb2b0212.zip |
Merge pull request #1722 from swaywm/swaybar-hidpi
Add hidpi support to swaybar
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r-- | swaybar/bar.c | 89 |
1 files changed, 72 insertions, 17 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index fb417095..ea0141cc 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); |
@@ -256,24 +299,36 @@ void bar_setup(struct swaybar *bar, | |||
256 | bar->status = status_line_init(bar->config->status_command); | 299 | bar->status = status_line_init(bar->config->status_command); |
257 | } | 300 | } |
258 | 301 | ||
259 | assert(bar->display = wl_display_connect(NULL)); | 302 | bar->display = wl_display_connect(NULL); |
303 | assert(bar->display); | ||
260 | 304 | ||
261 | struct wl_registry *registry = wl_display_get_registry(bar->display); | 305 | struct wl_registry *registry = wl_display_get_registry(bar->display); |
262 | wl_registry_add_listener(registry, ®istry_listener, bar); | 306 | wl_registry_add_listener(registry, ®istry_listener, bar); |
263 | wl_display_roundtrip(bar->display); | 307 | wl_display_roundtrip(bar->display); |
264 | assert(bar->compositor && bar->layer_shell && bar->shm); | 308 | assert(bar->compositor && bar->layer_shell && bar->shm); |
309 | wl_display_roundtrip(bar->display); | ||
310 | |||
265 | struct swaybar_pointer *pointer = &bar->pointer; | 311 | struct swaybar_pointer *pointer = &bar->pointer; |
266 | 312 | ||
267 | assert(pointer->cursor_theme = wl_cursor_theme_load(NULL, 16, bar->shm)); | 313 | int max_scale = 1; |
314 | struct swaybar_output *output; | ||
315 | wl_list_for_each(output, &bar->outputs, link) { | ||
316 | if (output->scale > max_scale) { | ||
317 | max_scale = output->scale; | ||
318 | } | ||
319 | } | ||
320 | |||
321 | pointer->cursor_theme = wl_cursor_theme_load( | ||
322 | NULL, 24 * max_scale, bar->shm); | ||
323 | assert(pointer->cursor_theme); | ||
268 | struct wl_cursor *cursor; | 324 | struct wl_cursor *cursor; |
269 | assert(cursor = wl_cursor_theme_get_cursor( | 325 | cursor = wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr"); |
270 | pointer->cursor_theme, "left_ptr")); | 326 | assert(cursor); |
271 | pointer->cursor_image = cursor->images[0]; | 327 | pointer->cursor_image = cursor->images[0]; |
272 | assert(pointer->cursor_surface = | 328 | pointer->cursor_surface = wl_compositor_create_surface(bar->compositor); |
273 | wl_compositor_create_surface(bar->compositor)); | 329 | assert(pointer->cursor_surface); |
274 | 330 | ||
275 | // TODO: we might not necessarily be meant to do all of the outputs | 331 | // 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) { | 332 | wl_list_for_each(output, &bar->outputs, link) { |
278 | struct config_output *coutput; | 333 | struct config_output *coutput; |
279 | wl_list_for_each(coutput, &bar->config->outputs, link) { | 334 | wl_list_for_each(coutput, &bar->config->outputs, link) { |
@@ -281,8 +336,8 @@ void bar_setup(struct swaybar *bar, | |||
281 | continue; | 336 | continue; |
282 | } | 337 | } |
283 | output->name = strdup(coutput->name); | 338 | output->name = strdup(coutput->name); |
284 | assert(output->surface = wl_compositor_create_surface( | 339 | output->surface = wl_compositor_create_surface(bar->compositor); |
285 | bar->compositor)); | 340 | assert(output->surface); |
286 | output->layer_surface = zwlr_layer_shell_v1_get_layer_surface( | 341 | output->layer_surface = zwlr_layer_shell_v1_get_layer_surface( |
287 | bar->layer_shell, output->surface, output->output, | 342 | bar->layer_shell, output->surface, output->output, |
288 | ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel"); | 343 | ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel"); |