swaynag: Implement wp_cursor_shape_v1

master
Alexander Orzechowski 1 year ago committed by Simon Ser
parent f436de9200
commit df8aad9c5a

@ -4,6 +4,8 @@
#include <strings.h> #include <strings.h>
#include "list.h" #include "list.h"
#include "pool-buffer.h" #include "pool-buffer.h"
#include "cursor-shape-v1-client-protocol.h"
#include "swaynag/types.h" #include "swaynag/types.h"
#define SWAYNAG_MAX_HEIGHT 500 #define SWAYNAG_MAX_HEIGHT 500
@ -85,6 +87,7 @@ struct swaynag {
struct swaynag_output *output; struct swaynag_output *output;
struct zwlr_layer_shell_v1 *layer_shell; struct zwlr_layer_shell_v1 *layer_shell;
struct zwlr_layer_surface_v1 *layer_surface; struct zwlr_layer_surface_v1 *layer_surface;
struct wp_cursor_shape_manager_v1 *cursor_shape_manager;
struct wl_surface *surface; struct wl_surface *surface;
uint32_t width; uint32_t width;

@ -157,8 +157,7 @@ static void update_cursor(struct swaynag_seat *seat) {
sway_log(SWAY_ERROR, "Failed to load cursor theme"); sway_log(SWAY_ERROR, "Failed to load cursor theme");
return; return;
} }
struct wl_cursor *cursor = struct wl_cursor *cursor = wl_cursor_theme_get_cursor(pointer->cursor_theme, "default");
wl_cursor_theme_get_cursor(pointer->cursor_theme, "default");
if (!cursor) { if (!cursor) {
sway_log(SWAY_ERROR, "Failed to get default cursor from theme"); sway_log(SWAY_ERROR, "Failed to get default cursor from theme");
return; return;
@ -190,12 +189,23 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, struct wl_surface *surface, uint32_t serial, struct wl_surface *surface,
wl_fixed_t surface_x, wl_fixed_t surface_y) { wl_fixed_t surface_x, wl_fixed_t surface_y) {
struct swaynag_seat *seat = data; struct swaynag_seat *seat = data;
struct swaynag_pointer *pointer = &seat->pointer; struct swaynag_pointer *pointer = &seat->pointer;
pointer->x = wl_fixed_to_int(surface_x); pointer->x = wl_fixed_to_int(surface_x);
pointer->y = wl_fixed_to_int(surface_y); pointer->y = wl_fixed_to_int(surface_y);
if (seat->swaynag->cursor_shape_manager) {
struct wp_cursor_shape_device_v1 *device =
wp_cursor_shape_manager_v1_get_pointer(
seat->swaynag->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; pointer->serial = serial;
update_cursor(seat); update_cursor(seat);
} }
}
static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
@ -386,6 +396,9 @@ static void handle_global(void *data, struct wl_registry *registry,
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
swaynag->layer_shell = wl_registry_bind( swaynag->layer_shell = wl_registry_bind(
registry, name, &zwlr_layer_shell_v1_interface, 1); registry, name, &zwlr_layer_shell_v1_interface, 1);
} else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) {
swaynag->cursor_shape_manager = wl_registry_bind(
registry, name, &wp_cursor_shape_manager_v1_interface, 1);
} }
} }
@ -464,7 +477,9 @@ void swaynag_setup(struct swaynag *swaynag) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!swaynag->cursor_shape_manager) {
swaynag_setup_cursors(swaynag); swaynag_setup_cursors(swaynag);
}
swaynag->surface = wl_compositor_create_surface(swaynag->compositor); swaynag->surface = wl_compositor_create_surface(swaynag->compositor);
assert(swaynag->surface); assert(swaynag->surface);

Loading…
Cancel
Save