aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/seat.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-14 11:11:56 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-14 11:11:56 -0500
commit92fef27eaa0b52c9d37bdabff14ae21cd6660f46 (patch)
tree7a923bbbc233079006597d82721117bae88b6ac6 /sway/input/seat.c
parentseat configuration (diff)
downloadsway-92fef27eaa0b52c9d37bdabff14ae21cd6660f46.tar.gz
sway-92fef27eaa0b52c9d37bdabff14ae21cd6660f46.tar.zst
sway-92fef27eaa0b52c9d37bdabff14ae21cd6660f46.zip
basic configuration
Diffstat (limited to 'sway/input/seat.c')
-rw-r--r--sway/input/seat.c163
1 files changed, 104 insertions, 59 deletions
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 80c6424f..1b25419b 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -9,6 +9,18 @@
9#include "sway/view.h" 9#include "sway/view.h"
10#include "log.h" 10#include "log.h"
11 11
12static void seat_device_destroy(struct sway_seat_device *seat_device) {
13 if (!seat_device) {
14 return;
15 }
16
17 sway_keyboard_destroy(seat_device->keyboard);
18 wlr_cursor_detach_input_device(seat_device->sway_seat->cursor->cursor,
19 seat_device->input_device->wlr_device);
20 wl_list_remove(&seat_device->link);
21 free(seat_device);
22}
23
12struct sway_seat *sway_seat_create(struct sway_input_manager *input, 24struct sway_seat *sway_seat_create(struct sway_input_manager *input,
13 const char *seat_name) { 25 const char *seat_name) {
14 struct sway_seat *seat = calloc(1, sizeof(struct sway_seat)); 26 struct sway_seat *seat = calloc(1, sizeof(struct sway_seat));
@@ -16,22 +28,22 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input,
16 return NULL; 28 return NULL;
17 } 29 }
18 30
19 seat->seat = wlr_seat_create(input->server->wl_display, seat_name); 31 seat->wlr_seat = wlr_seat_create(input->server->wl_display, seat_name);
20 if (!sway_assert(seat->seat, "could not allocate seat")) { 32 if (!sway_assert(seat->wlr_seat, "could not allocate seat")) {
21 return NULL; 33 return NULL;
22 } 34 }
23 35
24 seat->cursor = sway_cursor_create(seat); 36 seat->cursor = sway_cursor_create(seat);
25 if (!seat->cursor) { 37 if (!seat->cursor) {
26 wlr_seat_destroy(seat->seat); 38 wlr_seat_destroy(seat->wlr_seat);
27 free(seat); 39 free(seat);
28 return NULL; 40 return NULL;
29 } 41 }
30 42
31 seat->input = input; 43 seat->input = input;
32 seat->devices = create_list(); 44 wl_list_init(&seat->devices);
33 45
34 wlr_seat_set_capabilities(seat->seat, 46 wlr_seat_set_capabilities(seat->wlr_seat,
35 WL_SEAT_CAPABILITY_KEYBOARD | 47 WL_SEAT_CAPABILITY_KEYBOARD |
36 WL_SEAT_CAPABILITY_POINTER | 48 WL_SEAT_CAPABILITY_POINTER |
37 WL_SEAT_CAPABILITY_TOUCH); 49 WL_SEAT_CAPABILITY_TOUCH);
@@ -43,88 +55,94 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input,
43 return seat; 55 return seat;
44} 56}
45 57
46static void seat_add_pointer(struct sway_seat *seat, 58static void seat_configure_pointer(struct sway_seat *seat,
47 struct sway_input_device *sway_device) { 59 struct sway_seat_device *sway_device) {
48 // TODO pointer configuration 60 // TODO pointer configuration
49 wlr_cursor_attach_input_device(seat->cursor->cursor, 61 wlr_cursor_attach_input_device(seat->cursor->cursor,
50 sway_device->wlr_device); 62 sway_device->input_device->wlr_device);
51} 63}
52 64
53static void seat_add_keyboard(struct sway_seat *seat, 65static void seat_configure_keyboard(struct sway_seat *seat,
54 struct sway_input_device *device) { 66 struct sway_seat_device *seat_device) {
55 // TODO keyboard configuration 67 if (!seat_device->keyboard) {
56 sway_keyboard_create(seat, device); 68 sway_keyboard_create(seat, seat_device);
57 wlr_seat_set_keyboard(seat->seat, device->wlr_device); 69 }
70 sway_keyboard_configure(seat_device->keyboard);
58} 71}
59 72
60bool sway_seat_has_device(struct sway_seat *seat, 73static struct sway_seat_device *sway_seat_get_device(struct sway_seat *seat,
61 struct sway_input_device *device) { 74 struct sway_input_device *input_device) {
62 return false; 75 struct sway_seat_device *seat_device = NULL;
76 wl_list_for_each(seat_device, &seat->devices, link) {
77 if (seat_device->input_device == input_device) {
78 return seat_device;
79 }
80 }
81
82 return NULL;
63} 83}
64 84
65void sway_seat_add_device(struct sway_seat *seat, 85void sway_seat_configure_device(struct sway_seat *seat,
66 struct sway_input_device *device) { 86 struct sway_input_device *input_device) {
67 if (sway_seat_has_device(seat, device)) { 87 struct sway_seat_device *seat_device =
88 sway_seat_get_device(seat, input_device);
89 if (!seat_device) {
68 return; 90 return;
69 } 91 }
70 92
71 sway_log(L_DEBUG, "input add: %s", device->identifier); 93 if (seat->config) {
72 switch (device->wlr_device->type) { 94 seat_device->attachment_config =
95 seat_config_get_attachment(seat->config, input_device->identifier);
96 }
97
98 switch (input_device->wlr_device->type) {
73 case WLR_INPUT_DEVICE_POINTER: 99 case WLR_INPUT_DEVICE_POINTER:
74 seat_add_pointer(seat, device); 100 seat_configure_pointer(seat, seat_device);
75 break; 101 break;
76 case WLR_INPUT_DEVICE_KEYBOARD: 102 case WLR_INPUT_DEVICE_KEYBOARD:
77 seat_add_keyboard(seat, device); 103 seat_configure_keyboard(seat, seat_device);
104 wlr_seat_set_keyboard(seat->wlr_seat,
105 seat_device->input_device->wlr_device);
78 break; 106 break;
79 case WLR_INPUT_DEVICE_TOUCH: 107 case WLR_INPUT_DEVICE_TOUCH:
80 case WLR_INPUT_DEVICE_TABLET_PAD: 108 case WLR_INPUT_DEVICE_TABLET_PAD:
81 case WLR_INPUT_DEVICE_TABLET_TOOL: 109 case WLR_INPUT_DEVICE_TABLET_TOOL:
82 sway_log(L_DEBUG, "TODO: add other devices"); 110 sway_log(L_DEBUG, "TODO: configure other devices");
83 break; 111 break;
84 } 112 }
85
86 list_add(seat->devices, device);
87} 113}
88 114
89static void seat_remove_keyboard(struct sway_seat *seat, 115void sway_seat_add_device(struct sway_seat *seat,
90 struct sway_input_device *device) { 116 struct sway_input_device *input_device) {
91 if (device && device->keyboard) { 117 if (sway_seat_get_device(seat, input_device)) {
92 sway_keyboard_destroy(device->keyboard); 118 return;
93 } 119 }
94}
95 120
96static void seat_remove_pointer(struct sway_seat *seat, 121 struct sway_seat_device *seat_device =
97 struct sway_input_device *device) { 122 calloc(1, sizeof(struct sway_seat_device));
98 wlr_cursor_detach_input_device(seat->cursor->cursor, device->wlr_device); 123 if (!seat_device) {
124 sway_log(L_DEBUG, "could not allocate seat device");
125 return;
126 }
127
128 seat_device->sway_seat = seat;
129 seat_device->input_device = input_device;
130 wl_list_insert(&seat->devices, &seat_device->link);
131
132 sway_seat_configure_device(seat, input_device);
99} 133}
100 134
101void sway_seat_remove_device(struct sway_seat *seat, 135void sway_seat_remove_device(struct sway_seat *seat,
102 struct sway_input_device *device) { 136 struct sway_input_device *input_device) {
103 sway_log(L_DEBUG, "input remove: %s", device->identifier); 137 sway_log(L_DEBUG, "input remove: %s", input_device->identifier);
104 if (!sway_seat_has_device(seat, device)) { 138 struct sway_seat_device *seat_device =
105 return; 139 sway_seat_get_device(seat, input_device);
106 }
107 140
108 switch (device->wlr_device->type) { 141 if (!seat_device) {
109 case WLR_INPUT_DEVICE_POINTER: 142 return;
110 seat_remove_pointer(seat, device);
111 break;
112 case WLR_INPUT_DEVICE_KEYBOARD:
113 seat_remove_keyboard(seat, device);
114 break;
115 case WLR_INPUT_DEVICE_TOUCH:
116 case WLR_INPUT_DEVICE_TABLET_PAD:
117 case WLR_INPUT_DEVICE_TABLET_TOOL:
118 sway_log(L_DEBUG, "TODO: remove other devices");
119 break;
120 } 143 }
121 144
122 for (int i = 0; i < seat->devices->length; ++i) { 145 seat_device_destroy(seat_device);
123 if (seat->devices->items[i] == device) {
124 list_del(seat->devices, i);
125 break;
126 }
127 }
128} 146}
129 147
130void sway_seat_configure_xcursor(struct sway_seat *seat) { 148void sway_seat_configure_xcursor(struct sway_seat *seat) {
@@ -135,7 +153,8 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) {
135 seat->cursor->xcursor_manager = 153 seat->cursor->xcursor_manager =
136 wlr_xcursor_manager_create("default", 24); 154 wlr_xcursor_manager_create("default", 24);
137 if (sway_assert(seat->cursor->xcursor_manager, 155 if (sway_assert(seat->cursor->xcursor_manager,
138 "Cannot create XCursor manager for theme %s", cursor_theme)) { 156 "Cannot create XCursor manager for theme %s",
157 cursor_theme)) {
139 return; 158 return;
140 } 159 }
141 } 160 }
@@ -183,7 +202,7 @@ void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) {
183 view->iface.set_activated(view, true); 202 view->iface.set_activated(view, true);
184 wl_signal_add(&container->events.destroy, &seat->focus_destroy); 203 wl_signal_add(&container->events.destroy, &seat->focus_destroy);
185 seat->focus_destroy.notify = handle_focus_destroy; 204 seat->focus_destroy.notify = handle_focus_destroy;
186 wlr_seat_keyboard_notify_enter(seat->seat, view->surface); 205 wlr_seat_keyboard_notify_enter(seat->wlr_seat, view->surface);
187 } 206 }
188 207
189 seat->focus = container; 208 seat->focus = container;
@@ -195,3 +214,29 @@ void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) {
195 214
196 } 215 }
197} 216}
217
218void sway_seat_set_config(struct sway_seat *seat,
219 struct seat_config *seat_config) {
220 // clear configs
221 seat->config = NULL;
222
223 struct sway_seat_device *seat_device = NULL;
224 wl_list_for_each(seat_device, &seat->devices, link) {
225 seat_device->attachment_config = NULL;
226 }
227
228 if (!seat_config) {
229 return;
230 }
231
232 // add configs
233 seat->config = seat_config;
234
235 wl_list_for_each(seat_device, &seat->devices, link) {
236 seat_device->attachment_config =
237 seat_config_get_attachment(seat_config,
238 seat_device->input_device->identifier);
239 sway_seat_configure_device(seat, seat_device->input_device);
240 }
241
242}