aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/seat.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-12 08:29:37 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-12 08:29:37 -0500
commit163edc5a900fda58e006ed30e14ae10cc4aa13b3 (patch)
treea43e355091da4545bf9f16c63accb7d853170195 /sway/input/seat.c
parentinput config (diff)
downloadsway-163edc5a900fda58e006ed30e14ae10cc4aa13b3.tar.gz
sway-163edc5a900fda58e006ed30e14ae10cc4aa13b3.tar.zst
sway-163edc5a900fda58e006ed30e14ae10cc4aa13b3.zip
sway input device
Diffstat (limited to 'sway/input/seat.c')
-rw-r--r--sway/input/seat.c104
1 files changed, 41 insertions, 63 deletions
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 9c17250d..80c6424f 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -29,6 +29,7 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input,
29 } 29 }
30 30
31 seat->input = input; 31 seat->input = input;
32 seat->devices = create_list();
32 33
33 wlr_seat_set_capabilities(seat->seat, 34 wlr_seat_set_capabilities(seat->seat,
34 WL_SEAT_CAPABILITY_KEYBOARD | 35 WL_SEAT_CAPABILITY_KEYBOARD |
@@ -37,67 +38,38 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input,
37 38
38 sway_seat_configure_xcursor(seat); 39 sway_seat_configure_xcursor(seat);
39 40
40 wl_list_init(&seat->keyboards); 41 wl_list_insert(&input->seats, &seat->link);
41 42
42 return seat; 43 return seat;
43} 44}
44 45
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
57static struct sway_keyboard *seat_keyboard_from_device(struct sway_seat *seat,
58 struct wlr_input_device *device) {
59 struct sway_keyboard *keyboard = NULL;
60 wl_list_for_each(keyboard, &seat->keyboards, link) {
61 if (keyboard->device == device) {
62 return keyboard;
63 }
64 }
65
66 return keyboard;
67}
68
69static void seat_add_pointer(struct sway_seat *seat, 46static void seat_add_pointer(struct sway_seat *seat,
70 struct wlr_input_device *device) { 47 struct sway_input_device *sway_device) {
71 // TODO pointer configuration 48 // TODO pointer configuration
72 if (seat_pointer_from_device(seat, device)) { 49 wlr_cursor_attach_input_device(seat->cursor->cursor,
73 // already added 50 sway_device->wlr_device);
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
82 wlr_cursor_attach_input_device(seat->cursor->cursor, device);
83} 51}
84 52
85static void seat_add_keyboard(struct sway_seat *seat, 53static void seat_add_keyboard(struct sway_seat *seat,
86 struct wlr_input_device *device) { 54 struct sway_input_device *device) {
87 // TODO keyboard configuration 55 // TODO keyboard configuration
88 if (seat_keyboard_from_device(seat, device)) {
89 // already added
90 return;
91 }
92
93 sway_keyboard_create(seat, device); 56 sway_keyboard_create(seat, device);
94 wlr_seat_set_keyboard(seat->seat, device); 57 wlr_seat_set_keyboard(seat->seat, device->wlr_device);
58}
59
60bool sway_seat_has_device(struct sway_seat *seat,
61 struct sway_input_device *device) {
62 return false;
95} 63}
96 64
97void sway_seat_add_device(struct sway_seat *seat, 65void sway_seat_add_device(struct sway_seat *seat,
98 struct wlr_input_device *device) { 66 struct sway_input_device *device) {
99 sway_log(L_DEBUG, "input add: %s", device->name); 67 if (sway_seat_has_device(seat, device)) {
100 switch (device->type) { 68 return;
69 }
70
71 sway_log(L_DEBUG, "input add: %s", device->identifier);
72 switch (device->wlr_device->type) {
101 case WLR_INPUT_DEVICE_POINTER: 73 case WLR_INPUT_DEVICE_POINTER:
102 seat_add_pointer(seat, device); 74 seat_add_pointer(seat, device);
103 break; 75 break;
@@ -110,31 +82,30 @@ void sway_seat_add_device(struct sway_seat *seat,
110 sway_log(L_DEBUG, "TODO: add other devices"); 82 sway_log(L_DEBUG, "TODO: add other devices");
111 break; 83 break;
112 } 84 }
85
86 list_add(seat->devices, device);
113} 87}
114 88
115static void seat_remove_keyboard(struct sway_seat *seat, 89static void seat_remove_keyboard(struct sway_seat *seat,
116 struct wlr_input_device *device) { 90 struct sway_input_device *device) {
117 struct sway_keyboard *keyboard = seat_keyboard_from_device(seat, device); 91 if (device && device->keyboard) {
118 if (keyboard) { 92 sway_keyboard_destroy(device->keyboard);
119 sway_keyboard_destroy(keyboard);
120 } 93 }
121} 94}
122 95
123static void seat_remove_pointer(struct sway_seat *seat, 96static void seat_remove_pointer(struct sway_seat *seat,
124 struct wlr_input_device *device) { 97 struct sway_input_device *device) {
125 struct sway_pointer *pointer = seat_pointer_from_device(seat, device); 98 wlr_cursor_detach_input_device(seat->cursor->cursor, device->wlr_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 }
132} 99}
133 100
134void sway_seat_remove_device(struct sway_seat *seat, 101void sway_seat_remove_device(struct sway_seat *seat,
135 struct wlr_input_device *device) { 102 struct sway_input_device *device) {
136 sway_log(L_DEBUG, "input remove: %s", device->name); 103 sway_log(L_DEBUG, "input remove: %s", device->identifier);
137 switch (device->type) { 104 if (!sway_seat_has_device(seat, device)) {
105 return;
106 }
107
108 switch (device->wlr_device->type) {
138 case WLR_INPUT_DEVICE_POINTER: 109 case WLR_INPUT_DEVICE_POINTER:
139 seat_remove_pointer(seat, device); 110 seat_remove_pointer(seat, device);
140 break; 111 break;
@@ -147,6 +118,13 @@ void sway_seat_remove_device(struct sway_seat *seat,
147 sway_log(L_DEBUG, "TODO: remove other devices"); 118 sway_log(L_DEBUG, "TODO: remove other devices");
148 break; 119 break;
149 } 120 }
121
122 for (int i = 0; i < seat->devices->length; ++i) {
123 if (seat->devices->items[i] == device) {
124 list_del(seat->devices, i);
125 break;
126 }
127 }
150} 128}
151 129
152void sway_seat_configure_xcursor(struct sway_seat *seat) { 130void sway_seat_configure_xcursor(struct sway_seat *seat) {
@@ -211,7 +189,7 @@ void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) {
211 seat->focus = container; 189 seat->focus = container;
212 190
213 if (last_focus && 191 if (last_focus &&
214 !sway_input_manager_swayc_has_focus(seat->input, last_focus)) { 192 !sway_input_manager_has_focus(seat->input, last_focus)) {
215 struct sway_view *view = last_focus->sway_view; 193 struct sway_view *view = last_focus->sway_view;
216 view->iface.set_activated(view, false); 194 view->iface.set_activated(view, false);
217 195