diff options
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/cursor.c | 15 | ||||
-rw-r--r-- | sway/input/input-manager.c | 14 | ||||
-rw-r--r-- | sway/input/seat.c | 44 |
3 files changed, 70 insertions, 3 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 5f2d650e..217c2ddb 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -1,4 +1,9 @@ #define _XOPEN_SOURCE 700 +#ifdef __linux__ +#include <linux/input-event-codes.h> +#elif __FreeBSD__ +#include <dev/evdev/input-event-codes.h> +#endif #include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_xcursor_manager.h> #include "sway/input/cursor.h" @@ -57,6 +62,16 @@ 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; + + if (event->button == BTN_LEFT) { + struct wlr_surface *surface = NULL; + double sx, sy; + swayc_t *swayc = + swayc_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); + + sway_seat_set_focus(cursor->seat, swayc); + } + wlr_seat_pointer_notify_button(cursor->seat->seat, event->time_msec, event->button, event->state); } diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 4f52e59a..ca80f267 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -27,7 +27,7 @@ static struct sway_seat *input_manager_get_seat( } } - seat = sway_seat_create(input->server->wl_display, seat_name); + seat = sway_seat_create(input, seat_name); list_add(input->seats, seat); return seat; @@ -131,3 +131,15 @@ char *libinput_dev_unique_id(struct libinput_device *device) { free(name); return identifier; } + +bool sway_input_manager_swayc_has_focus(struct sway_input_manager *input, + swayc_t *container) { + for (int i = 0; i < input->seats->length; ++i) { + struct sway_seat *seat = input->seats->items[i]; + if (seat->focus == container) { + return true; + } + } + + return false; +} diff --git a/sway/input/seat.c b/sway/input/seat.c index 5aed1f68..94f547cc 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -5,16 +5,17 @@ #include "sway/input/cursor.h" #include "sway/input/input-manager.h" #include "sway/output.h" +#include "sway/view.h" #include "log.h" -struct sway_seat *sway_seat_create(struct wl_display *display, +struct sway_seat *sway_seat_create(struct sway_input_manager *input, const char *seat_name) { struct sway_seat *seat = calloc(1, sizeof(struct sway_seat)); if (!seat) { return NULL; } - seat->seat = wlr_seat_create(display, seat_name); + seat->seat = wlr_seat_create(input->server->wl_display, seat_name); if (!sway_assert(seat->seat, "could not allocate seat")) { return NULL; } @@ -26,6 +27,8 @@ struct sway_seat *sway_seat_create(struct wl_display *display, return NULL; } + seat->input = input; + wlr_seat_set_capabilities(seat->seat, WL_SEAT_CAPABILITY_KEYBOARD | WL_SEAT_CAPABILITY_POINTER | @@ -110,3 +113,40 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) { wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x, seat->cursor->cursor->y); } + +static void handle_focus_destroy(struct wl_listener *listener, void *data) { + struct sway_seat *seat = wl_container_of(listener, seat, focus_destroy); + //swayc_t *container = data; + + // TODO set new focus based on the state of the tree + sway_seat_set_focus(seat, NULL); +} + +void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) { + swayc_t *last_focus = seat->focus; + + if (last_focus == container) { + return; + } + + if (last_focus) { + wl_list_remove(&seat->focus_destroy.link); + } + + if (container) { + struct sway_view *view = container->sway_view; + view->iface.set_activated(view, true); + wl_signal_add(&container->events.destroy, &seat->focus_destroy); + seat->focus_destroy.notify = handle_focus_destroy; + // TODO give keyboard focus + } + + seat->focus = container; + + if (last_focus && + !sway_input_manager_swayc_has_focus(seat->input, last_focus)) { + struct sway_view *view = last_focus->sway_view; + view->iface.set_activated(view, false); + + } +} |