summaryrefslogtreecommitdiff
path: root/src/wayland
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-12 10:17:33 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-12 10:17:33 +0300
commit881fb6cb1d64868132287bd9637f4ae1cbc3504c (patch)
tree5688d5f8be69805ccf290178675b522802155e6d /src/wayland
parent3b8af02be94a510e385f44d58c35c86bb89424a6 (diff)
cursor hidden and tablet support
Diffstat (limited to 'src/wayland')
-rw-r--r--src/wayland/internal.h1
-rw-r--r--src/wayland/pointer.c26
-rw-r--r--src/wayland/surface.c2
3 files changed, 19 insertions, 10 deletions
diff --git a/src/wayland/internal.h b/src/wayland/internal.h
index 249fc8d..04142f7 100644
--- a/src/wayland/internal.h
+++ b/src/wayland/internal.h
@@ -284,6 +284,7 @@ struct wayland_surface {
struct input_queue input;
/* 4-byte integers */
+ enum yasl_cursor cursor;
int ime_cursor_end;
int ime_shown_begin, ime_shown_end;
int floating_width, floating_height;
diff --git a/src/wayland/pointer.c b/src/wayland/pointer.c
index 3b3ad73..3341d35 100644
--- a/src/wayland/pointer.c
+++ b/src/wayland/pointer.c
@@ -164,7 +164,7 @@ static void set_cursor_theme_fallback(struct seat *s, struct wayland_surface *w,
{"ew-resize", "ew-resize"},
{"ns-resize", "ns-resize"},
};
- int idx = shape < YASL_CURSOR_NONE ? (int)shape : 0;
+ int idx = (unsigned)shape < YASL_CURSOR_HIDDEN ? (int)shape : 0;
struct wl_cursor *cursor = wl_cursor_theme_get_cursor(c->cursor_theme, names[idx][0]);
if (!cursor) cursor = wl_cursor_theme_get_cursor(c->cursor_theme, names[idx][1]);
if (!cursor || !cursor->image_count) return;
@@ -211,7 +211,7 @@ static void seat_set_cursor(struct seat *s, struct wayland_surface *w, enum yasl
if (!s->pointer || !s->pointer_serial || s->pointer_focus != w ||
s->cursor_shape == (int)shape)
return;
- if (shape == YASL_CURSOR_NONE)
+ if (shape == YASL_CURSOR_HIDDEN)
wl_pointer_set_cursor(s->pointer, s->pointer_serial, NULL, 0, 0);
else if (s->cursor_shape_dev)
wp_cursor_shape_device_v1_set_shape(s->cursor_shape_dev,
@@ -225,7 +225,7 @@ static void tool_set_cursor(struct tablet_tool *t, enum yasl_cursor shape)
{
if (!t->proximity_serial)
return;
- if (shape == YASL_CURSOR_NONE)
+ if (shape == YASL_CURSOR_HIDDEN)
zwp_tablet_tool_v2_set_cursor(t->proxy, t->proximity_serial, NULL, 0, 0);
else if (t->shape_dev)
wp_cursor_shape_device_v1_set_shape(t->shape_dev, t->proximity_serial,
@@ -234,7 +234,8 @@ static void tool_set_cursor(struct tablet_tool *t, enum yasl_cursor shape)
void wayland_surface_set_cursor(struct wayland_surface *w, enum yasl_cursor shape)
{
- if (!w || !w->conn) return;
+ if (!w || !w->conn || w->destroyed || (unsigned)shape > YASL_CURSOR_HIDDEN) return;
+ w->cursor = shape;
for (struct seat *s = w->conn->seats; s; s = s->next) {
seat_set_cursor(s, w, shape);
if (s->tool && s->tablet_focus == w)
@@ -325,7 +326,7 @@ static void pointer_enter(void *data, struct wl_pointer *pointer,
s->pointer_pos = device_from_fixed(w, surface_x, surface_y);
s->pointer_serial = serial;
s->cursor_shape = -1;
- seat_set_cursor(s, w, w->parent ? YASL_CURSOR_ARROW : YASL_CURSOR_TEXT);
+ seat_set_cursor(s, w, w->cursor);
s->motion_pending = true;
pointer_event_done(s);
}
@@ -741,7 +742,7 @@ static void tablet_tool_proximity_in(void *data,
if (s->conn->cursor_shape_mgr && !t->shape_dev)
t->shape_dev = wp_cursor_shape_manager_v1_get_tablet_tool_v2(
s->conn->cursor_shape_mgr, t->proxy);
- tool_set_cursor(t, w->parent ? YASL_CURSOR_ARROW : YASL_CURSOR_TEXT);
+ tool_set_cursor(t, w->cursor);
s->tool_motion = true;
}
@@ -753,6 +754,7 @@ static void tablet_tool_proximity_out(void *data, struct zwp_tablet_tool_v2 *too
struct wayland_surface *w = s->tablet_focus;
if (w) {
press_queue_flush(s, &s->tool_presses, NULL, &s->tool_buttons, tool_event(s));
+ s->pen.pressure = 0;
struct yasl_mouse_event ev = tool_event(s);
ev.pos = s->tool_pos;
ev.button = 3;
@@ -763,6 +765,8 @@ static void tablet_tool_proximity_out(void *data, struct zwp_tablet_tool_v2 *too
s->tablet_focus = NULL;
s->tool = NULL;
s->tool_motion = false;
+ s->tool_wheel = 0;
+ s->tool_buttons = 0;
t->proximity_serial = 0;
}
@@ -867,7 +871,11 @@ static void tool_frame(void *d, struct zwp_tablet_tool_v2 *t, uint32_t time)
}
press_queue_flush(s, &s->tool_presses, NULL, &s->tool_buttons, like);
if (s->tool_wheel) {
- report_wheel(s, w, s->tool_pos, s->tool_wheel > 0 ? 5 : 4, -s->tool_wheel, 0.0f);
+ struct yasl_mouse_event ev = like;
+ ev.pos = s->tool_pos;
+ ev.kind = YASL_PTR_SCROLL;
+ ev.scroll_lines = -s->tool_wheel;
+ push_mouse(s, w, ev);
s->tool_wheel = 0;
}
}
@@ -877,9 +885,7 @@ static void tablet_tool_removed(void *data, struct zwp_tablet_tool_v2 *tool)
struct tablet_tool *t = data;
struct seat *s = t->seat;
if (s->tool == t) {
- s->tool = NULL;
- s->tablet_focus = NULL;
- s->tool_presses.n = 0;
+ tablet_tool_proximity_out(t, tool);
}
struct tablet_tool **link = &s->tablet_tools;
while (*link && *link != t)
diff --git a/src/wayland/surface.c b/src/wayland/surface.c
index f291190..ce1764b 100644
--- a/src/wayland/surface.c
+++ b/src/wayland/surface.c
@@ -284,6 +284,7 @@ uint32_t wayland_display_caps(const struct wayland_display *c)
{
if (!c) return 0;
uint32_t caps = YASL_CAP_POPUPS | YASL_CAP_CSD | YASL_CAP_FRAME_PACING;
+ if (c->tablet_mgr) caps |= YASL_CAP_TABLET;
struct seat *s = conn_active_seat(c);
const struct wl_data_device *device = s ? clipboard_data_device(s->clipboard) : NULL;
if (device && wl_data_device_get_version((struct wl_data_device *)device) >= 3)
@@ -346,6 +347,7 @@ struct wayland_surface *wayland_surface_create_toplevel(struct wayland_display *
display_enter(c);
conn_link(c, w);
wayland_surface_set_callbacks(w, NULL, NULL);
+ w->cursor = YASL_CURSOR_TEXT;
w->req_width = width;
w->req_height = height;
w->logical_width = width;