diff options
Diffstat (limited to 'swaynag/swaynag.c')
-rw-r--r-- | swaynag/swaynag.c | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c index 5620155d..50eea148 100644 --- a/swaynag/swaynag.c +++ b/swaynag/swaynag.c | |||
@@ -1,4 +1,3 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <stdlib.h> | 1 | #include <stdlib.h> |
3 | #include <assert.h> | 2 | #include <assert.h> |
4 | #include <sys/stat.h> | 3 | #include <sys/stat.h> |
@@ -153,8 +152,15 @@ static void update_cursor(struct swaynag_seat *seat) { | |||
153 | } | 152 | } |
154 | pointer->cursor_theme = wl_cursor_theme_load( | 153 | pointer->cursor_theme = wl_cursor_theme_load( |
155 | cursor_theme, cursor_size * swaynag->scale, swaynag->shm); | 154 | cursor_theme, cursor_size * swaynag->scale, swaynag->shm); |
156 | struct wl_cursor *cursor = | 155 | if (!pointer->cursor_theme) { |
157 | wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr"); | 156 | sway_log(SWAY_ERROR, "Failed to load cursor theme"); |
157 | return; | ||
158 | } | ||
159 | struct wl_cursor *cursor = wl_cursor_theme_get_cursor(pointer->cursor_theme, "default"); | ||
160 | if (!cursor) { | ||
161 | sway_log(SWAY_ERROR, "Failed to get default cursor from theme"); | ||
162 | return; | ||
163 | } | ||
158 | pointer->cursor_image = cursor->images[0]; | 164 | pointer->cursor_image = cursor->images[0]; |
159 | wl_surface_set_buffer_scale(pointer->cursor_surface, | 165 | wl_surface_set_buffer_scale(pointer->cursor_surface, |
160 | swaynag->scale); | 166 | swaynag->scale); |
@@ -182,11 +188,22 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, | |||
182 | uint32_t serial, struct wl_surface *surface, | 188 | uint32_t serial, struct wl_surface *surface, |
183 | wl_fixed_t surface_x, wl_fixed_t surface_y) { | 189 | wl_fixed_t surface_x, wl_fixed_t surface_y) { |
184 | struct swaynag_seat *seat = data; | 190 | struct swaynag_seat *seat = data; |
191 | |||
185 | struct swaynag_pointer *pointer = &seat->pointer; | 192 | struct swaynag_pointer *pointer = &seat->pointer; |
186 | pointer->x = wl_fixed_to_int(surface_x); | 193 | pointer->x = wl_fixed_to_int(surface_x); |
187 | pointer->y = wl_fixed_to_int(surface_y); | 194 | pointer->y = wl_fixed_to_int(surface_y); |
188 | pointer->serial = serial; | 195 | |
189 | update_cursor(seat); | 196 | if (seat->swaynag->cursor_shape_manager) { |
197 | struct wp_cursor_shape_device_v1 *device = | ||
198 | wp_cursor_shape_manager_v1_get_pointer( | ||
199 | seat->swaynag->cursor_shape_manager, wl_pointer); | ||
200 | wp_cursor_shape_device_v1_set_shape(device, serial, | ||
201 | WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT); | ||
202 | wp_cursor_shape_device_v1_destroy(device); | ||
203 | } else { | ||
204 | pointer->serial = serial; | ||
205 | update_cursor(seat); | ||
206 | } | ||
190 | } | 207 | } |
191 | 208 | ||
192 | static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, | 209 | static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, |
@@ -378,6 +395,9 @@ static void handle_global(void *data, struct wl_registry *registry, | |||
378 | } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { | 395 | } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { |
379 | swaynag->layer_shell = wl_registry_bind( | 396 | swaynag->layer_shell = wl_registry_bind( |
380 | registry, name, &zwlr_layer_shell_v1_interface, 1); | 397 | registry, name, &zwlr_layer_shell_v1_interface, 1); |
398 | } else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) { | ||
399 | swaynag->cursor_shape_manager = wl_registry_bind( | ||
400 | registry, name, &wp_cursor_shape_manager_v1_interface, 1); | ||
381 | } | 401 | } |
382 | } | 402 | } |
383 | 403 | ||
@@ -456,7 +476,9 @@ void swaynag_setup(struct swaynag *swaynag) { | |||
456 | exit(EXIT_FAILURE); | 476 | exit(EXIT_FAILURE); |
457 | } | 477 | } |
458 | 478 | ||
459 | swaynag_setup_cursors(swaynag); | 479 | if (!swaynag->cursor_shape_manager) { |
480 | swaynag_setup_cursors(swaynag); | ||
481 | } | ||
460 | 482 | ||
461 | swaynag->surface = wl_compositor_create_surface(swaynag->compositor); | 483 | swaynag->surface = wl_compositor_create_surface(swaynag->compositor); |
462 | assert(swaynag->surface); | 484 | assert(swaynag->surface); |
@@ -483,10 +505,6 @@ void swaynag_run(struct swaynag *swaynag) { | |||
483 | && wl_display_dispatch(swaynag->display) != -1) { | 505 | && wl_display_dispatch(swaynag->display) != -1) { |
484 | // This is intentionally left blank | 506 | // This is intentionally left blank |
485 | } | 507 | } |
486 | |||
487 | if (swaynag->display) { | ||
488 | wl_display_disconnect(swaynag->display); | ||
489 | } | ||
490 | } | 508 | } |
491 | 509 | ||
492 | void swaynag_destroy(struct swaynag *swaynag) { | 510 | void swaynag_destroy(struct swaynag *swaynag) { |
@@ -501,6 +519,7 @@ void swaynag_destroy(struct swaynag *swaynag) { | |||
501 | } | 519 | } |
502 | list_free(swaynag->buttons); | 520 | list_free(swaynag->buttons); |
503 | free(swaynag->details.message); | 521 | free(swaynag->details.message); |
522 | free(swaynag->details.details_text); | ||
504 | free(swaynag->details.button_up.text); | 523 | free(swaynag->details.button_up.text); |
505 | free(swaynag->details.button_down.text); | 524 | free(swaynag->details.button_down.text); |
506 | 525 | ||
@@ -541,4 +560,8 @@ void swaynag_destroy(struct swaynag *swaynag) { | |||
541 | if (swaynag->shm) { | 560 | if (swaynag->shm) { |
542 | wl_shm_destroy(swaynag->shm); | 561 | wl_shm_destroy(swaynag->shm); |
543 | } | 562 | } |
563 | |||
564 | if (swaynag->display) { | ||
565 | wl_display_disconnect(swaynag->display); | ||
566 | } | ||
544 | } | 567 | } |