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/input/seat.c | |
parent | Merge branch 'wlroots' into feature/input (diff) | |
download | sway-21626e8153490bf155e812644454fe9610491ffd.tar.gz sway-21626e8153490bf155e812644454fe9610491ffd.tar.zst sway-21626e8153490bf155e812644454fe9610491ffd.zip |
seat focus on button press
Diffstat (limited to 'sway/input/seat.c')
-rw-r--r-- | sway/input/seat.c | 44 |
1 files changed, 42 insertions, 2 deletions
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 @@ | |||
5 | #include "sway/input/cursor.h" | 5 | #include "sway/input/cursor.h" |
6 | #include "sway/input/input-manager.h" | 6 | #include "sway/input/input-manager.h" |
7 | #include "sway/output.h" | 7 | #include "sway/output.h" |
8 | #include "sway/view.h" | ||
8 | #include "log.h" | 9 | #include "log.h" |
9 | 10 | ||
10 | struct sway_seat *sway_seat_create(struct wl_display *display, | 11 | struct sway_seat *sway_seat_create(struct sway_input_manager *input, |
11 | const char *seat_name) { | 12 | const char *seat_name) { |
12 | struct sway_seat *seat = calloc(1, sizeof(struct sway_seat)); | 13 | struct sway_seat *seat = calloc(1, sizeof(struct sway_seat)); |
13 | if (!seat) { | 14 | if (!seat) { |
14 | return NULL; | 15 | return NULL; |
15 | } | 16 | } |
16 | 17 | ||
17 | seat->seat = wlr_seat_create(display, seat_name); | 18 | seat->seat = wlr_seat_create(input->server->wl_display, seat_name); |
18 | if (!sway_assert(seat->seat, "could not allocate seat")) { | 19 | if (!sway_assert(seat->seat, "could not allocate seat")) { |
19 | return NULL; | 20 | return NULL; |
20 | } | 21 | } |
@@ -26,6 +27,8 @@ struct sway_seat *sway_seat_create(struct wl_display *display, | |||
26 | return NULL; | 27 | return NULL; |
27 | } | 28 | } |
28 | 29 | ||
30 | seat->input = input; | ||
31 | |||
29 | wlr_seat_set_capabilities(seat->seat, | 32 | wlr_seat_set_capabilities(seat->seat, |
30 | WL_SEAT_CAPABILITY_KEYBOARD | | 33 | WL_SEAT_CAPABILITY_KEYBOARD | |
31 | WL_SEAT_CAPABILITY_POINTER | | 34 | WL_SEAT_CAPABILITY_POINTER | |
@@ -110,3 +113,40 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) { | |||
110 | wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x, | 113 | wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x, |
111 | seat->cursor->cursor->y); | 114 | seat->cursor->cursor->y); |
112 | } | 115 | } |
116 | |||
117 | static void handle_focus_destroy(struct wl_listener *listener, void *data) { | ||
118 | struct sway_seat *seat = wl_container_of(listener, seat, focus_destroy); | ||
119 | //swayc_t *container = data; | ||
120 | |||
121 | // TODO set new focus based on the state of the tree | ||
122 | sway_seat_set_focus(seat, NULL); | ||
123 | } | ||
124 | |||
125 | void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) { | ||
126 | swayc_t *last_focus = seat->focus; | ||
127 | |||
128 | if (last_focus == container) { | ||
129 | return; | ||
130 | } | ||
131 | |||
132 | if (last_focus) { | ||
133 | wl_list_remove(&seat->focus_destroy.link); | ||
134 | } | ||
135 | |||
136 | if (container) { | ||
137 | struct sway_view *view = container->sway_view; | ||
138 | view->iface.set_activated(view, true); | ||
139 | wl_signal_add(&container->events.destroy, &seat->focus_destroy); | ||
140 | seat->focus_destroy.notify = handle_focus_destroy; | ||
141 | // TODO give keyboard focus | ||
142 | } | ||
143 | |||
144 | seat->focus = container; | ||
145 | |||
146 | if (last_focus && | ||
147 | !sway_input_manager_swayc_has_focus(seat->input, last_focus)) { | ||
148 | struct sway_view *view = last_focus->sway_view; | ||
149 | view->iface.set_activated(view, false); | ||
150 | |||
151 | } | ||
152 | } | ||