aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/container.h4
-rw-r--r--include/sway/input/input-manager.h3
-rw-r--r--include/sway/input/seat.h8
-rw-r--r--sway/input/cursor.c15
-rw-r--r--sway/input/input-manager.c14
-rw-r--r--sway/input/seat.c44
-rw-r--r--sway/tree/container.c6
7 files changed, 90 insertions, 4 deletions
diff --git a/include/sway/container.h b/include/sway/container.h
index 0e1cc8a3..f13745ee 100644
--- a/include/sway/container.h
+++ b/include/sway/container.h
@@ -124,6 +124,10 @@ struct sway_container {
124 * Marks applied to the container, list_t of char*. 124 * Marks applied to the container, list_t of char*.
125 */ 125 */
126 list_t *marks; 126 list_t *marks;
127
128 struct {
129 struct wl_signal destroy;
130 } events;
127}; 131};
128 132
129void swayc_descendants_of_type(swayc_t *root, enum swayc_types type, 133void swayc_descendants_of_type(swayc_t *root, enum swayc_types type,
diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h
index 5dc75ba7..9548c170 100644
--- a/include/sway/input/input-manager.h
+++ b/include/sway/input/input-manager.h
@@ -19,4 +19,7 @@ char* libinput_dev_unique_id(struct libinput_device *dev);
19struct sway_input_manager *sway_input_manager_create( 19struct sway_input_manager *sway_input_manager_create(
20 struct sway_server *server); 20 struct sway_server *server);
21 21
22bool sway_input_manager_swayc_has_focus(struct sway_input_manager *input,
23 swayc_t *container);
24
22#endif 25#endif
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h
index f7f8a1bb..964c0f7b 100644
--- a/include/sway/input/seat.h
+++ b/include/sway/input/seat.h
@@ -7,9 +7,13 @@
7struct sway_seat { 7struct sway_seat {
8 struct wlr_seat *seat; 8 struct wlr_seat *seat;
9 struct sway_cursor *cursor; 9 struct sway_cursor *cursor;
10 struct sway_input_manager *input;
11 swayc_t *focus;
12
13 struct wl_listener focus_destroy;
10}; 14};
11 15
12struct sway_seat *sway_seat_create(struct wl_display *display, 16struct sway_seat *sway_seat_create(struct sway_input_manager *input,
13 const char *seat_name); 17 const char *seat_name);
14 18
15void sway_seat_add_device(struct sway_seat *seat, 19void sway_seat_add_device(struct sway_seat *seat,
@@ -20,4 +24,6 @@ void sway_seat_remove_device(struct sway_seat *seat,
20 24
21void sway_seat_configure_xcursor(struct sway_seat *seat); 25void sway_seat_configure_xcursor(struct sway_seat *seat);
22 26
27void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container);
28
23#endif 29#endif
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 @@
1#define _XOPEN_SOURCE 700 1#define _XOPEN_SOURCE 700
2#ifdef __linux__
3#include <linux/input-event-codes.h>
4#elif __FreeBSD__
5#include <dev/evdev/input-event-codes.h>
6#endif
2#include <wlr/types/wlr_cursor.h> 7#include <wlr/types/wlr_cursor.h>
3#include <wlr/types/wlr_xcursor_manager.h> 8#include <wlr/types/wlr_xcursor_manager.h>
4#include "sway/input/cursor.h" 9#include "sway/input/cursor.h"
@@ -57,6 +62,16 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
57 struct sway_cursor *cursor = 62 struct sway_cursor *cursor =
58 wl_container_of(listener, cursor, button); 63 wl_container_of(listener, cursor, button);
59 struct wlr_event_pointer_button *event = data; 64 struct wlr_event_pointer_button *event = data;
65
66 if (event->button == BTN_LEFT) {
67 struct wlr_surface *surface = NULL;
68 double sx, sy;
69 swayc_t *swayc =
70 swayc_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy);
71
72 sway_seat_set_focus(cursor->seat, swayc);
73 }
74
60 wlr_seat_pointer_notify_button(cursor->seat->seat, event->time_msec, 75 wlr_seat_pointer_notify_button(cursor->seat->seat, event->time_msec,
61 event->button, event->state); 76 event->button, event->state);
62} 77}
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(
27 } 27 }
28 } 28 }
29 29
30 seat = sway_seat_create(input->server->wl_display, seat_name); 30 seat = sway_seat_create(input, seat_name);
31 list_add(input->seats, seat); 31 list_add(input->seats, seat);
32 32
33 return seat; 33 return seat;
@@ -131,3 +131,15 @@ char *libinput_dev_unique_id(struct libinput_device *device) {
131 free(name); 131 free(name);
132 return identifier; 132 return identifier;
133} 133}
134
135bool sway_input_manager_swayc_has_focus(struct sway_input_manager *input,
136 swayc_t *container) {
137 for (int i = 0; i < input->seats->length; ++i) {
138 struct sway_seat *seat = input->seats->items[i];
139 if (seat->focus == container) {
140 return true;
141 }
142 }
143
144 return false;
145}
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
10struct sway_seat *sway_seat_create(struct wl_display *display, 11struct 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
117static 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
125void 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}
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) {
40 if (type != C_VIEW) { 40 if (type != C_VIEW) {
41 c->children = create_list(); 41 c->children = create_list();
42 } 42 }
43
44 wl_signal_init(&c->events.destroy);
45
43 return c; 46 return c;
44} 47}
45 48
@@ -119,6 +122,9 @@ static void free_swayc(swayc_t *cont) {
119 if (!sway_assert(cont, "free_swayc passed NULL")) { 122 if (!sway_assert(cont, "free_swayc passed NULL")) {
120 return; 123 return;
121 } 124 }
125
126 wl_signal_emit(&cont->events.destroy, cont);
127
122 if (cont->children) { 128 if (cont->children) {
123 // remove children until there are no more, free_swayc calls 129 // remove children until there are no more, free_swayc calls
124 // remove_child, which removes child from this container 130 // remove_child, which removes child from this container