diff options
Diffstat (limited to 'swaynag/swaynag.c')
-rw-r--r-- | swaynag/swaynag.c | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c index 22511529..3966277d 100644 --- a/swaynag/swaynag.c +++ b/swaynag/swaynag.c | |||
@@ -106,21 +106,33 @@ static struct wl_surface_listener surface_listener = { | |||
106 | .leave = nop, | 106 | .leave = nop, |
107 | }; | 107 | }; |
108 | 108 | ||
109 | static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, | 109 | static void update_cursor(struct swaynag *swaynag) { |
110 | uint32_t serial, struct wl_surface *surface, | ||
111 | wl_fixed_t surface_x, wl_fixed_t surface_y) { | ||
112 | struct swaynag *swaynag = data; | ||
113 | struct swaynag_pointer *pointer = &swaynag->pointer; | 110 | struct swaynag_pointer *pointer = &swaynag->pointer; |
111 | pointer->cursor_theme = wl_cursor_theme_load(NULL, 24 * swaynag->scale, | ||
112 | swaynag->shm); | ||
113 | struct wl_cursor *cursor = | ||
114 | wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr"); | ||
115 | pointer->cursor_image = cursor->images[0]; | ||
114 | wl_surface_set_buffer_scale(pointer->cursor_surface, | 116 | wl_surface_set_buffer_scale(pointer->cursor_surface, |
115 | swaynag->scale); | 117 | swaynag->scale); |
116 | wl_surface_attach(pointer->cursor_surface, | 118 | wl_surface_attach(pointer->cursor_surface, |
117 | wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0); | 119 | wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0); |
118 | wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface, | 120 | wl_pointer_set_cursor(pointer->pointer, pointer->serial, |
121 | pointer->cursor_surface, | ||
119 | pointer->cursor_image->hotspot_x / swaynag->scale, | 122 | pointer->cursor_image->hotspot_x / swaynag->scale, |
120 | pointer->cursor_image->hotspot_y / swaynag->scale); | 123 | pointer->cursor_image->hotspot_y / swaynag->scale); |
121 | wl_surface_commit(pointer->cursor_surface); | 124 | wl_surface_commit(pointer->cursor_surface); |
122 | } | 125 | } |
123 | 126 | ||
127 | static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, | ||
128 | uint32_t serial, struct wl_surface *surface, | ||
129 | wl_fixed_t surface_x, wl_fixed_t surface_y) { | ||
130 | struct swaynag *swaynag = data; | ||
131 | struct swaynag_pointer *pointer = &swaynag->pointer; | ||
132 | pointer->serial = serial; | ||
133 | update_cursor(swaynag); | ||
134 | } | ||
135 | |||
124 | static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, | 136 | static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, |
125 | uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { | 137 | uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { |
126 | struct swaynag *swaynag = data; | 138 | struct swaynag *swaynag = data; |
@@ -233,6 +245,7 @@ static void output_scale(void *data, struct wl_output *output, | |||
233 | swaynag_output->scale = factor; | 245 | swaynag_output->scale = factor; |
234 | if (swaynag_output->swaynag->output == swaynag_output) { | 246 | if (swaynag_output->swaynag->output == swaynag_output) { |
235 | swaynag_output->swaynag->scale = swaynag_output->scale; | 247 | swaynag_output->swaynag->scale = swaynag_output->scale; |
248 | update_cursor(swaynag_output->swaynag); | ||
236 | render_frame(swaynag_output->swaynag); | 249 | render_frame(swaynag_output->swaynag); |
237 | } | 250 | } |
238 | } | 251 | } |
@@ -345,14 +358,6 @@ void swaynag_setup(struct swaynag *swaynag) { | |||
345 | } | 358 | } |
346 | 359 | ||
347 | struct swaynag_pointer *pointer = &swaynag->pointer; | 360 | struct swaynag_pointer *pointer = &swaynag->pointer; |
348 | int scale = swaynag->output ? swaynag->scale : 1; | ||
349 | pointer->cursor_theme = wl_cursor_theme_load(NULL, 24 * scale, | ||
350 | swaynag->shm); | ||
351 | assert(pointer->cursor_theme); | ||
352 | struct wl_cursor *cursor = | ||
353 | wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr"); | ||
354 | assert(cursor); | ||
355 | pointer->cursor_image = cursor->images[0]; | ||
356 | pointer->cursor_surface = wl_compositor_create_surface(swaynag->compositor); | 361 | pointer->cursor_surface = wl_compositor_create_surface(swaynag->compositor); |
357 | assert(pointer->cursor_surface); | 362 | assert(pointer->cursor_surface); |
358 | 363 | ||
@@ -410,6 +415,10 @@ void swaynag_destroy(struct swaynag *swaynag) { | |||
410 | wl_surface_destroy(swaynag->surface); | 415 | wl_surface_destroy(swaynag->surface); |
411 | } | 416 | } |
412 | 417 | ||
418 | if (swaynag->pointer.cursor_theme) { | ||
419 | wl_cursor_theme_destroy(swaynag->pointer.cursor_theme); | ||
420 | } | ||
421 | |||
413 | if (&swaynag->buffers[0]) { | 422 | if (&swaynag->buffers[0]) { |
414 | destroy_buffer(&swaynag->buffers[0]); | 423 | destroy_buffer(&swaynag->buffers[0]); |
415 | } | 424 | } |
@@ -418,13 +427,15 @@ void swaynag_destroy(struct swaynag *swaynag) { | |||
418 | destroy_buffer(&swaynag->buffers[1]); | 427 | destroy_buffer(&swaynag->buffers[1]); |
419 | } | 428 | } |
420 | 429 | ||
421 | struct swaynag_output *output, *temp; | 430 | if (swaynag->outputs.prev || swaynag->outputs.next) { |
422 | wl_list_for_each_safe(output, temp, &swaynag->outputs, link) { | 431 | struct swaynag_output *output, *temp; |
423 | wl_output_destroy(output->wl_output); | 432 | wl_list_for_each_safe(output, temp, &swaynag->outputs, link) { |
424 | free(output->name); | 433 | wl_output_destroy(output->wl_output); |
425 | wl_list_remove(&output->link); | 434 | free(output->name); |
426 | free(output); | 435 | wl_list_remove(&output->link); |
427 | }; | 436 | free(output); |
437 | }; | ||
438 | } | ||
428 | 439 | ||
429 | if (swaynag->compositor) { | 440 | if (swaynag->compositor) { |
430 | wl_compositor_destroy(swaynag->compositor); | 441 | wl_compositor_destroy(swaynag->compositor); |