Skip to content

Commit f436de9

Browse files
Nefsen402emersion
authored andcommitted
swaybar: Implement wp_cursor_shape_v1
1 parent 6bd11ad commit f436de9

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

include/swaybar/bar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "config.h"
55
#include "input.h"
66
#include "pool-buffer.h"
7+
#include "cursor-shape-v1-client-protocol.h"
78
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
89
#include "xdg-output-unstable-v1-client-protocol.h"
910

@@ -30,6 +31,7 @@ struct swaybar {
3031
struct wl_compositor *compositor;
3132
struct zwlr_layer_shell_v1 *layer_shell;
3233
struct zxdg_output_manager_v1 *xdg_output_manager;
34+
struct wp_cursor_shape_manager_v1 *cursor_shape_manager;
3335
struct wl_shm *shm;
3436

3537
struct swaybar_config *config;

swaybar/bar.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ static void handle_global(void *data, struct wl_registry *registry,
362362
} else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0) {
363363
bar->xdg_output_manager = wl_registry_bind(registry, name,
364364
&zxdg_output_manager_v1_interface, 2);
365+
} else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) {
366+
bar->cursor_shape_manager = wl_registry_bind(registry, name,
367+
&wp_cursor_shape_manager_v1_interface, 1);
365368
}
366369
}
367370

@@ -425,15 +428,17 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {
425428
// Second roundtrip for xdg-output
426429
wl_display_roundtrip(bar->display);
427430

428-
struct swaybar_seat *seat;
429-
wl_list_for_each(seat, &bar->seats, link) {
430-
struct swaybar_pointer *pointer = &seat->pointer;
431-
if (!pointer) {
432-
continue;
431+
if (!bar->cursor_shape_manager) {
432+
struct swaybar_seat *seat;
433+
wl_list_for_each(seat, &bar->seats, link) {
434+
struct swaybar_pointer *pointer = &seat->pointer;
435+
if (!pointer) {
436+
continue;
437+
}
438+
pointer->cursor_surface =
439+
wl_compositor_create_surface(bar->compositor);
440+
assert(pointer->cursor_surface);
433441
}
434-
pointer->cursor_surface =
435-
wl_compositor_create_surface(bar->compositor);
436-
assert(pointer->cursor_surface);
437442
}
438443

439444
if (bar->config->status_command) {

swaybar/input.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,26 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
111111
struct swaybar_pointer *pointer = &seat->pointer;
112112
seat->pointer.x = wl_fixed_to_double(surface_x);
113113
seat->pointer.y = wl_fixed_to_double(surface_y);
114-
pointer->serial = serial;
114+
115115
struct swaybar_output *output;
116116
wl_list_for_each(output, &seat->bar->outputs, link) {
117117
if (output->surface == surface) {
118118
pointer->current = output;
119119
break;
120120
}
121121
}
122-
update_cursor(seat);
122+
123+
if (seat->bar->cursor_shape_manager) {
124+
struct wp_cursor_shape_device_v1 *device =
125+
wp_cursor_shape_manager_v1_get_pointer(
126+
seat->bar->cursor_shape_manager, wl_pointer);
127+
wp_cursor_shape_device_v1_set_shape(device, serial,
128+
WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT);
129+
wp_cursor_shape_device_v1_destroy(device);
130+
} else {
131+
pointer->serial = serial;
132+
update_cursor(seat);
133+
}
123134
}
124135

125136
static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,

0 commit comments

Comments
 (0)