From ec7fc42a00db8c230ca1a050f0a1f7badc697fa5 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 8 Dec 2017 07:22:26 -0500 Subject: [PATCH] sway cursor --- include/sway/cursor.h | 26 +++++++++ include/sway/seat.h | 1 + sway/input/cursor.c | 128 ++++++++++++++++++++++++++++++++++++++++++ sway/input/seat.c | 52 +++++++++++++++++ sway/meson.build | 1 + 5 files changed, 208 insertions(+) create mode 100644 include/sway/cursor.h create mode 100644 sway/input/cursor.c diff --git a/include/sway/cursor.h b/include/sway/cursor.h new file mode 100644 index 00000000..647bc8f1 --- /dev/null +++ b/include/sway/cursor.h @@ -0,0 +1,26 @@ +#ifndef _SWAY_CURSOR_H +#define _SWAY_CURSOR_H + +#include "sway/seat.h" + +struct sway_cursor { + struct wlr_cursor *cursor; + + struct wl_listener motion; + struct wl_listener motion_absolute; + struct wl_listener button; + struct wl_listener axis; + + struct wl_listener touch_down; + struct wl_listener touch_up; + struct wl_listener touch_motion; + + struct wl_listener tool_axis; + struct wl_listener tool_tip; + + struct wl_listener request_set_cursor; +}; + +struct sway_cursor *sway_cursor_create(struct sway_seat *seat); + +#endif diff --git a/include/sway/seat.h b/include/sway/seat.h index a2b8fe51..2f8ca72e 100644 --- a/include/sway/seat.h +++ b/include/sway/seat.h @@ -6,6 +6,7 @@ struct sway_seat { struct wlr_seat *seat; + struct sway_cursor *cursor; }; struct sway_seat *sway_seat_create(struct wl_display *display, diff --git a/sway/input/cursor.c b/sway/input/cursor.c new file mode 100644 index 00000000..819007d5 --- /dev/null +++ b/sway/input/cursor.c @@ -0,0 +1,128 @@ +#define _XOPEN_SOURCE 700 +#include +#include "sway/cursor.h" +#include "log.h" + +static void handle_cursor_motion(struct wl_listener *listener, void *data) { + struct sway_cursor *cursor = + wl_container_of(listener, cursor, motion); + struct wlr_event_pointer_motion *event = data; + sway_log(L_DEBUG, "TODO: handle event: %p", event); +} + +static void handle_cursor_motion_absolute(struct wl_listener *listener, + void *data) { + struct sway_cursor *cursor = + wl_container_of(listener, cursor, motion_absolute); + struct wlr_event_pointer_motion_absolute *event = data; + sway_log(L_DEBUG, "TODO: handle event: %p", event); +} + +static void handle_cursor_button(struct wl_listener *listener, void *data) { + struct sway_cursor *cursor = + wl_container_of(listener, cursor, button); + struct wlr_event_pointer_button *event = data; + sway_log(L_DEBUG, "TODO: handle event: %p", event); +} + +static void handle_cursor_axis(struct wl_listener *listener, void *data) { + struct sway_cursor *cursor = + wl_container_of(listener, cursor, axis); + struct wlr_event_pointer_axis *event = data; + sway_log(L_DEBUG, "TODO: handle event: %p", event); +} + +static void handle_touch_down(struct wl_listener *listener, void *data) { + struct sway_cursor *cursor = + wl_container_of(listener, cursor, touch_down); + struct wlr_event_touch_down *event = data; + sway_log(L_DEBUG, "TODO: handle event: %p", event); +} + +static void handle_touch_up(struct wl_listener *listener, void *data) { + struct sway_cursor *cursor = + wl_container_of(listener, cursor, touch_up); + struct wlr_event_touch_up *event = data; + sway_log(L_DEBUG, "TODO: handle event: %p", event); +} + +static void handle_touch_motion(struct wl_listener *listener, void *data) { + struct sway_cursor *cursor = + wl_container_of(listener, cursor, touch_motion); + struct wlr_event_touch_motion *event = data; + sway_log(L_DEBUG, "TODO: handle event: %p", event); +} + +static void handle_tool_axis(struct wl_listener *listener, void *data) { + struct sway_cursor *cursor = + wl_container_of(listener, cursor, tool_axis); + struct wlr_event_tablet_tool_axis *event = data; + sway_log(L_DEBUG, "TODO: handle event: %p", event); +} + +static void handle_tool_tip(struct wl_listener *listener, void *data) { + struct sway_cursor *cursor = + wl_container_of(listener, cursor, tool_tip); + struct wlr_event_tablet_tool_tip *event = data; + sway_log(L_DEBUG, "TODO: handle event: %p", event); +} + +static void handle_request_set_cursor(struct wl_listener *listener, + void *data) { + struct sway_cursor *cursor = + wl_container_of(listener, cursor, request_set_cursor); + struct wlr_seat_pointer_request_set_cursor_event *event = data; + sway_log(L_DEBUG, "TODO: handle event: %p", event); +} + +struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { + struct sway_cursor *cursor = calloc(1, sizeof(struct sway_cursor)); + if (!sway_assert(cursor, "could not allocate sway cursor")) { + return NULL; + } + + struct wlr_cursor *wlr_cursor = wlr_cursor_create(); + if (!sway_assert(wlr_cursor, "could not allocate wlr cursor")) { + free(cursor); + return NULL; + } + + // input events + wl_signal_add(&wlr_cursor->events.motion, &cursor->motion); + cursor->motion.notify = handle_cursor_motion; + + wl_signal_add(&wlr_cursor->events.motion_absolute, + &cursor->motion_absolute); + cursor->motion_absolute.notify = handle_cursor_motion_absolute; + + wl_signal_add(&wlr_cursor->events.button, &cursor->button); + cursor->button.notify = handle_cursor_button; + + wl_signal_add(&wlr_cursor->events.axis, &cursor->axis); + cursor->axis.notify = handle_cursor_axis; + + wl_signal_add(&wlr_cursor->events.touch_down, &cursor->touch_down); + cursor->touch_down.notify = handle_touch_down; + + wl_signal_add(&wlr_cursor->events.touch_up, &cursor->touch_up); + cursor->touch_up.notify = handle_touch_up; + + wl_signal_add(&wlr_cursor->events.touch_motion, + &cursor->touch_motion); + cursor->touch_motion.notify = handle_touch_motion; + + wl_signal_add(&wlr_cursor->events.tablet_tool_axis, + &cursor->tool_axis); + cursor->tool_axis.notify = handle_tool_axis; + + wl_signal_add(&wlr_cursor->events.tablet_tool_tip, &cursor->tool_tip); + cursor->tool_tip.notify = handle_tool_tip; + + wl_signal_add(&seat->seat->events.request_set_cursor, + &cursor->request_set_cursor); + cursor->request_set_cursor.notify = handle_request_set_cursor; + + cursor->cursor = wlr_cursor; + + return cursor; +} diff --git a/sway/input/seat.c b/sway/input/seat.c index f41b6dba..459b2ee2 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -1,5 +1,7 @@ #define _XOPEN_SOURCE 700 +#include #include "sway/seat.h" +#include "sway/cursor.h" #include "sway/input-manager.h" #include "log.h" @@ -9,16 +11,66 @@ struct sway_seat *sway_seat_create(struct wl_display *display, if (!seat) { return NULL; } + seat->seat = wlr_seat_create(display, seat_name); + if (!sway_assert(seat->seat, "could not allocate seat")) { + return NULL; + } + + seat->cursor = sway_cursor_create(seat); + if (!seat->cursor) { + wlr_seat_destroy(seat->seat); + free(seat); + return NULL; + } + + wlr_seat_set_capabilities(seat->seat, + WL_SEAT_CAPABILITY_KEYBOARD | + WL_SEAT_CAPABILITY_POINTER | + WL_SEAT_CAPABILITY_TOUCH); + return seat; } +static void seat_add_pointer(struct sway_seat *seat, + struct wlr_input_device *device) { + // TODO pointer configuration + wlr_cursor_attach_input_device(seat->cursor->cursor, device); +} + void sway_seat_add_device(struct sway_seat *seat, struct wlr_input_device *device) { sway_log(L_DEBUG, "input add: %s", device->name); + switch (device->type) { + case WLR_INPUT_DEVICE_POINTER: + seat_add_pointer(seat, device); + break; + case WLR_INPUT_DEVICE_KEYBOARD: + case WLR_INPUT_DEVICE_TOUCH: + case WLR_INPUT_DEVICE_TABLET_PAD: + case WLR_INPUT_DEVICE_TABLET_TOOL: + sway_log(L_DEBUG, "TODO: add other devices"); + break; + } +} + +static void seat_remove_pointer(struct sway_seat *seat, + struct wlr_input_device *device) { + // TODO } void sway_seat_remove_device(struct sway_seat *seat, struct wlr_input_device *device) { sway_log(L_DEBUG, "input remove: %s", device->name); + switch (device->type) { + case WLR_INPUT_DEVICE_POINTER: + seat_remove_pointer(seat, device); + break; + case WLR_INPUT_DEVICE_KEYBOARD: + case WLR_INPUT_DEVICE_TOUCH: + case WLR_INPUT_DEVICE_TABLET_PAD: + case WLR_INPUT_DEVICE_TABLET_TOOL: + sway_log(L_DEBUG, "TODO: remove other devices"); + break; + } } diff --git a/sway/meson.build b/sway/meson.build index cea565d6..059204b2 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -4,6 +4,7 @@ sway_sources = files( 'commands.c', 'input/input-manager.c', 'input/seat.c', + 'input/cursor.c', 'commands/exit.c', 'commands/exec.c', 'commands/exec_always.c',