diff options
author | Tony Crisci <tony@dubstepdish.com> | 2017-12-10 11:11:47 -0500 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2017-12-10 11:11:47 -0500 |
commit | 21626e8153490bf155e812644454fe9610491ffd (patch) | |
tree | 5b881dcc23dfdae692f58aaf1a9677b5d1395f61 /sway | |
parent | 0fdecb4d3a36d4c73a906bcc0465620293b6e6d2 (diff) |
seat focus on button press
Diffstat (limited to 'sway')
-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 | ||||
-rw-r--r-- | sway/tree/container.c | 6 |
4 files changed, 76 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); + + } +} diff --git a/sway/tree/container.c b/sway/tree/container.c index 321ef8b1..78c8625f 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -40,6 +40,9 @@ static swayc_t *new_swayc(enum swayc_types type) { if (type != C_VIEW) { c->children = create_list(); } + + wl_signal_init(&c->events.destroy); + return c; } @@ -119,6 +122,9 @@ static void free_swayc(swayc_t *cont) { if (!sway_assert(cont, "free_swayc passed NULL")) { return; } + + wl_signal_emit(&cont->events.destroy, cont); + if (cont->children) { // remove children until there are no more, free_swayc calls // remove_child, which removes child from this container |