aboutsummaryrefslogtreecommitdiff
path: root/swt.c
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2023-04-07 23:05:42 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2023-04-07 23:05:42 +0200
commitfe84e69990a9f156a818eb1547384812bc9db41c (patch)
treefd088810599fff47e26026150fa708bc5621d0dd /swt.c
parent77d32cb5e492d68f871516c171d192d755e7c4c6 (diff)
add pointer support
Diffstat (limited to 'swt.c')
-rw-r--r--swt.c63
1 files changed, 60 insertions, 3 deletions
diff --git a/swt.c b/swt.c
index dbd06b8..befcfd1 100644
--- a/swt.c
+++ b/swt.c
@@ -51,6 +51,11 @@ static void keyboard_key(void *data, struct wl_keyboard *keyboard, uint32_t seri
static void keyboard_modifiers(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group);
static void keyboard_repeat_info(void *data, struct wl_keyboard *keyboard, int32_t rate, int32_t delay);
static void handle_keyboard_event();
+static void pointer_enter(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y);
+static void pointer_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface);
+static void pointer_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t x, wl_fixed_t y);
+static void pointer_button(void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state);
+static void pointer_axis(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t value);
static void dummy() {}
@@ -79,6 +84,11 @@ static const struct xdg_wm_base_listener wm_base_listener = {
.ping = wm_base_ping,
};
+static const struct wl_seat_listener seat_listener = {
+ .capabilities = seat_capabilities,
+ .name = dummy
+};
+
static const struct wl_keyboard_listener keyboard_listener = {
.keymap = keyboard_keymap,
.key = keyboard_key,
@@ -88,11 +98,20 @@ static const struct wl_keyboard_listener keyboard_listener = {
.leave = dummy,
};
-static const struct wl_seat_listener seat_listener = {
- .capabilities = seat_capabilities,
- .name = dummy
+const struct wl_pointer_listener pointer_listener = {
+ .enter = pointer_enter,
+ .leave = pointer_leave,
+ .motion = pointer_motion,
+ .button = pointer_button,
+ .axis = pointer_axis,
+ .axis_discrete = dummy,
+ .axis_source = dummy,
+ .axis_stop = dummy,
+ .axis_value120 = dummy,
+ .frame = dummy,
};
+
Client client = { 0 };
Window win = { 0 };
int running = 1;
@@ -296,6 +315,41 @@ handle_keyboard_event()
void
+pointer_enter(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
+{
+ fprintf(stderr, "pointer enter: (%i, %i)\n", x, y);
+}
+
+
+void
+pointer_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface)
+{
+ fprintf(stderr, "pointer leave\n");
+}
+
+
+void
+pointer_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t x, wl_fixed_t y)
+{
+ fprintf(stderr, "pointer motion: (%i, %i)\n", x, y);
+}
+
+
+void
+pointer_button(void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
+{
+ fprintf(stderr, "pointer button: (b: %i, s: %i)\n", button, state);
+}
+
+
+void
+pointer_axis(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t value)
+{
+ fprintf(stderr, "pointer axis: (a: %i, v: %i)\n", axis, value);
+}
+
+
+void
setup()
{
client.kb.repeat.timer = timerfd_create(CLOCK_MONOTONIC, 0);
@@ -308,6 +362,9 @@ setup()
xdg_wm_base_add_listener(client.wm_base, &wm_base_listener, &client);
wl_display_roundtrip(client.display);
+ client.pointer.pointer = wl_seat_get_pointer(client.seat);
+ wl_pointer_add_listener(client.pointer.pointer, &pointer_listener, &client);
+
win.surface.wl = wl_compositor_create_surface(client.compositor);
win.surface.xdg = xdg_wm_base_get_xdg_surface(client.wm_base, win.surface.wl);
xdg_surface_add_listener(win.surface.xdg, &surface_listener, &win);