Skip to content

Commit

Permalink
Implement wp_cursor_shape_v1
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Ser <[email protected]>
  • Loading branch information
Nefsen402 and emersion committed Dec 26, 2023
1 parent 6d6b216 commit dc40411
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
2 changes: 2 additions & 0 deletions include/mako.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "config.h"
#include "event-loop.h"
#include "pool-buffer.h"
#include "cursor-shape-v1-client-protocol.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "xdg-activation-v1-client-protocol.h"

Expand Down Expand Up @@ -56,6 +57,7 @@ struct mako_state {
struct wl_shm *shm;
struct zwlr_layer_shell_v1 *layer_shell;
struct xdg_activation_v1 *xdg_activation;
struct wp_cursor_shape_manager_v1 *cursor_shape_manager;
struct wl_list outputs; // mako_output::link
struct wl_list seats; // mako_seat::link

Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ glib = dependency('glib-2.0')
gobject = dependency('gobject-2.0')
realtime = cc.find_library('rt')
wayland_client = dependency('wayland-client')
wayland_protos = dependency('wayland-protocols', version: '>=1.21')
wayland_protos = dependency('wayland-protocols', version: '>=1.32')
wayland_cursor = dependency('wayland-cursor')

epoll = dependency('', required: false)
Expand Down
2 changes: 2 additions & 0 deletions protocol/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ wayland_scanner_client = generator(

protocols = [
wl_protocol_dir / 'stable/xdg-shell/xdg-shell.xml',
wl_protocol_dir / 'staging/cursor-shape/cursor-shape-v1.xml',
wl_protocol_dir / 'staging/xdg-activation/xdg-activation-v1.xml',
wl_protocol_dir / 'unstable/tablet/tablet-unstable-v2.xml',
'wlr-layer-shell-unstable-v1.xml',
]

Expand Down
27 changes: 20 additions & 7 deletions wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static void touch_handle_up(void *data, struct wl_touch *wl_touch,
seat->touch.pts[id].surface = NULL;
}

static void load_cursor(struct mako_state *state, uint32_t scale) {
static void load_default_cursor(struct mako_state *state, uint32_t scale) {
const char *cursor_name = "left_ptr";

//don't reload the cursor if what we have already can be used
Expand Down Expand Up @@ -215,13 +215,20 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
}
}

// Change the mouse cursor to "left_ptr"
load_cursor(state, scale);
if (state->cursor_shape_manager != NULL) {
struct wp_cursor_shape_device_v1 *device =
wp_cursor_shape_manager_v1_get_pointer(state->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 {
load_default_cursor(state, scale);

if (state->cursor.theme != NULL) {
wl_pointer_set_cursor(wl_pointer, serial, state->cursor.surface,
state->cursor.image->hotspot_x / state->cursor.scale,
state->cursor.image->hotspot_y / state->cursor.scale);
if (state->cursor.theme != NULL) {
wl_pointer_set_cursor(wl_pointer, serial, state->cursor.surface,
state->cursor.image->hotspot_x / state->cursor.scale,
state->cursor.image->hotspot_y / state->cursor.scale);
}
}
}

Expand Down Expand Up @@ -430,6 +437,9 @@ static void handle_global(void *data, struct wl_registry *registry,
} else if (strcmp(interface, xdg_activation_v1_interface.name) == 0) {
state->xdg_activation = wl_registry_bind(registry, name,
&xdg_activation_v1_interface, 1);
} else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) {
state->cursor_shape_manager = wl_registry_bind(registry, name,
&wp_cursor_shape_manager_v1_interface, 1);
}
}

Expand Down Expand Up @@ -527,6 +537,9 @@ void finish_wayland(struct mako_state *state) {
if (state->xdg_activation != NULL) {
xdg_activation_v1_destroy(state->xdg_activation);
}
if (state->cursor_shape_manager != NULL) {
wp_cursor_shape_manager_v1_destroy(state->cursor_shape_manager);
}

if (state->cursor.theme != NULL) {
wl_cursor_theme_destroy(state->cursor.theme);
Expand Down

0 comments on commit dc40411

Please sign in to comment.