summaryrefslogtreecommitdiffstats
path: root/swaybar/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar/input.c')
-rw-r--r--swaybar/input.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/swaybar/input.c b/swaybar/input.c
index 1f8491f6..7d219be3 100644
--- a/swaybar/input.c
+++ b/swaybar/input.c
@@ -55,11 +55,34 @@ static enum x11_button wl_axis_to_x11_button(uint32_t axis, wl_fixed_t value) {
55 } 55 }
56} 56}
57 57
58void update_cursor(struct swaybar *bar) {
59 struct swaybar_pointer *pointer = &bar->pointer;
60 if (pointer->cursor_theme) {
61 wl_cursor_theme_destroy(pointer->cursor_theme);
62 }
63 int scale = pointer->current ? pointer->current->scale : 1;
64 pointer->cursor_theme = wl_cursor_theme_load(NULL, 24 * scale, bar->shm);
65 struct wl_cursor *cursor;
66 cursor = wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr");
67 pointer->cursor_image = cursor->images[0];
68 wl_surface_set_buffer_scale(pointer->cursor_surface, scale);
69 wl_surface_attach(pointer->cursor_surface,
70 wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0);
71 wl_pointer_set_cursor(pointer->pointer, pointer->serial,
72 pointer->cursor_surface,
73 pointer->cursor_image->hotspot_x / scale,
74 pointer->cursor_image->hotspot_y / scale);
75 wl_surface_damage_buffer(pointer->cursor_surface, 0, 0,
76 INT32_MAX, INT32_MAX);
77 wl_surface_commit(pointer->cursor_surface);
78}
79
58static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, 80static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
59 uint32_t serial, struct wl_surface *surface, 81 uint32_t serial, struct wl_surface *surface,
60 wl_fixed_t surface_x, wl_fixed_t surface_y) { 82 wl_fixed_t surface_x, wl_fixed_t surface_y) {
61 struct swaybar *bar = data; 83 struct swaybar *bar = data;
62 struct swaybar_pointer *pointer = &bar->pointer; 84 struct swaybar_pointer *pointer = &bar->pointer;
85 pointer->serial = serial;
63 struct swaybar_output *output; 86 struct swaybar_output *output;
64 wl_list_for_each(output, &bar->outputs, link) { 87 wl_list_for_each(output, &bar->outputs, link) {
65 if (output->surface == surface) { 88 if (output->surface == surface) {
@@ -67,20 +90,7 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
67 break; 90 break;
68 } 91 }
69 } 92 }
70 int max_scale = 1; 93 update_cursor(bar);
71 struct swaybar_output *_output;
72 wl_list_for_each(_output, &bar->outputs, link) {
73 if (_output->scale > max_scale) {
74 max_scale = _output->scale;
75 }
76 }
77 wl_surface_set_buffer_scale(pointer->cursor_surface, max_scale);
78 wl_surface_attach(pointer->cursor_surface,
79 wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0);
80 wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface,
81 pointer->cursor_image->hotspot_x / max_scale,
82 pointer->cursor_image->hotspot_y / max_scale);
83 wl_surface_commit(pointer->cursor_surface);
84} 94}
85 95
86static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, 96static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,