swaybar: Implement wp_cursor_shape_v1

This commit is contained in:
Alexander Orzechowski 2023-07-30 16:07:28 -04:00 committed by Simon Ser
parent 6bd11ad0df
commit f436de9200
3 changed files with 28 additions and 10 deletions

View file

@ -4,6 +4,7 @@
#include "config.h" #include "config.h"
#include "input.h" #include "input.h"
#include "pool-buffer.h" #include "pool-buffer.h"
#include "cursor-shape-v1-client-protocol.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h" #include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "xdg-output-unstable-v1-client-protocol.h" #include "xdg-output-unstable-v1-client-protocol.h"
@ -30,6 +31,7 @@ struct swaybar {
struct wl_compositor *compositor; struct wl_compositor *compositor;
struct zwlr_layer_shell_v1 *layer_shell; struct zwlr_layer_shell_v1 *layer_shell;
struct zxdg_output_manager_v1 *xdg_output_manager; struct zxdg_output_manager_v1 *xdg_output_manager;
struct wp_cursor_shape_manager_v1 *cursor_shape_manager;
struct wl_shm *shm; struct wl_shm *shm;
struct swaybar_config *config; struct swaybar_config *config;

View file

@ -362,6 +362,9 @@ static void handle_global(void *data, struct wl_registry *registry,
} else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0) { } else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0) {
bar->xdg_output_manager = wl_registry_bind(registry, name, bar->xdg_output_manager = wl_registry_bind(registry, name,
&zxdg_output_manager_v1_interface, 2); &zxdg_output_manager_v1_interface, 2);
} else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) {
bar->cursor_shape_manager = wl_registry_bind(registry, name,
&wp_cursor_shape_manager_v1_interface, 1);
} }
} }
@ -425,6 +428,7 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {
// Second roundtrip for xdg-output // Second roundtrip for xdg-output
wl_display_roundtrip(bar->display); wl_display_roundtrip(bar->display);
if (!bar->cursor_shape_manager) {
struct swaybar_seat *seat; struct swaybar_seat *seat;
wl_list_for_each(seat, &bar->seats, link) { wl_list_for_each(seat, &bar->seats, link) {
struct swaybar_pointer *pointer = &seat->pointer; struct swaybar_pointer *pointer = &seat->pointer;
@ -435,6 +439,7 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {
wl_compositor_create_surface(bar->compositor); wl_compositor_create_surface(bar->compositor);
assert(pointer->cursor_surface); assert(pointer->cursor_surface);
} }
}
if (bar->config->status_command) { if (bar->config->status_command) {
bar->status = status_line_init(bar->config->status_command); bar->status = status_line_init(bar->config->status_command);

View file

@ -111,7 +111,7 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
struct swaybar_pointer *pointer = &seat->pointer; struct swaybar_pointer *pointer = &seat->pointer;
seat->pointer.x = wl_fixed_to_double(surface_x); seat->pointer.x = wl_fixed_to_double(surface_x);
seat->pointer.y = wl_fixed_to_double(surface_y); seat->pointer.y = wl_fixed_to_double(surface_y);
pointer->serial = serial;
struct swaybar_output *output; struct swaybar_output *output;
wl_list_for_each(output, &seat->bar->outputs, link) { wl_list_for_each(output, &seat->bar->outputs, link) {
if (output->surface == surface) { if (output->surface == surface) {
@ -119,8 +119,19 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
break; break;
} }
} }
if (seat->bar->cursor_shape_manager) {
struct wp_cursor_shape_device_v1 *device =
wp_cursor_shape_manager_v1_get_pointer(
seat->bar->cursor_shape_manager, wl_pointer);
wp_cursor_shape_device_v1_set_shape(device, serial,
WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT);
wp_cursor_shape_device_v1_destroy(device);
} else {
pointer->serial = serial;
update_cursor(seat); update_cursor(seat);
} }
}
static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, struct wl_surface *surface) { uint32_t serial, struct wl_surface *surface) {