aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/input/seat.h9
-rw-r--r--sway/input/seat.c30
2 files changed, 37 insertions, 2 deletions
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h
index a0c6ab07..5455601e 100644
--- a/include/sway/input/seat.h
+++ b/include/sway/input/seat.h
@@ -10,11 +10,18 @@ struct sway_seat {
10 struct sway_input_manager *input; 10 struct sway_input_manager *input;
11 swayc_t *focus; 11 swayc_t *focus;
12 12
13 struct wl_list keyboards; 13 struct wl_list keyboards; // sway_keyboard::link
14 struct wl_list pointers; // sway_pointer::link
14 15
15 struct wl_listener focus_destroy; 16 struct wl_listener focus_destroy;
16}; 17};
17 18
19struct sway_pointer {
20 struct sway_seat *seat;
21 struct wlr_input_device *device;
22 struct wl_list link;
23};
24
18struct sway_seat *sway_seat_create(struct sway_input_manager *input, 25struct sway_seat *sway_seat_create(struct sway_input_manager *input,
19 const char *seat_name); 26 const char *seat_name);
20 27
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 7c827374..9c17250d 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -42,6 +42,18 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input,
42 return seat; 42 return seat;
43} 43}
44 44
45static struct sway_pointer *seat_pointer_from_device(struct sway_seat *seat,
46 struct wlr_input_device *device) {
47 struct sway_pointer *pointer = NULL;
48 wl_list_for_each(pointer, &seat->pointers, link) {
49 if (pointer->device == device) {
50 return pointer;
51 }
52 }
53
54 return pointer;
55}
56
45static struct sway_keyboard *seat_keyboard_from_device(struct sway_seat *seat, 57static struct sway_keyboard *seat_keyboard_from_device(struct sway_seat *seat,
46 struct wlr_input_device *device) { 58 struct wlr_input_device *device) {
47 struct sway_keyboard *keyboard = NULL; 59 struct sway_keyboard *keyboard = NULL;
@@ -57,6 +69,16 @@ static struct sway_keyboard *seat_keyboard_from_device(struct sway_seat *seat,
57static void seat_add_pointer(struct sway_seat *seat, 69static void seat_add_pointer(struct sway_seat *seat,
58 struct wlr_input_device *device) { 70 struct wlr_input_device *device) {
59 // TODO pointer configuration 71 // TODO pointer configuration
72 if (seat_pointer_from_device(seat, device)) {
73 // already added
74 return;
75 }
76
77 struct sway_pointer *pointer = calloc(1, sizeof(struct sway_pointer));
78 pointer->seat = seat;
79 pointer->device = device;
80 wl_list_insert(&seat->pointers, &pointer->link);
81
60 wlr_cursor_attach_input_device(seat->cursor->cursor, device); 82 wlr_cursor_attach_input_device(seat->cursor->cursor, device);
61} 83}
62 84
@@ -100,7 +122,13 @@ static void seat_remove_keyboard(struct sway_seat *seat,
100 122
101static void seat_remove_pointer(struct sway_seat *seat, 123static void seat_remove_pointer(struct sway_seat *seat,
102 struct wlr_input_device *device) { 124 struct wlr_input_device *device) {
103 wlr_cursor_detach_input_device(seat->cursor->cursor, device); 125 struct sway_pointer *pointer = seat_pointer_from_device(seat, device);
126
127 if (pointer) {
128 wl_list_remove(&pointer->link);
129 free(pointer);
130 wlr_cursor_detach_input_device(seat->cursor->cursor, device);
131 }
104} 132}
105 133
106void sway_seat_remove_device(struct sway_seat *seat, 134void sway_seat_remove_device(struct sway_seat *seat,