aboutsummaryrefslogtreecommitdiffstats
path: root/sway
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
parentinput config (diff)
downloadsway-163edc5a900fda58e006ed30e14ae10cc4aa13b3.tar.gz
sway-163edc5a900fda58e006ed30e14ae10cc4aa13b3.tar.zst
sway-163edc5a900fda58e006ed30e14ae10cc4aa13b3.zip
sway input device
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c23
-rw-r--r--sway/config.c29
-rw-r--r--sway/desktop/output.c5
-rw-r--r--sway/desktop/wl_shell.c5
-rw-r--r--sway/desktop/xdg_shell_v6.c5
-rw-r--r--sway/desktop/xwayland.c6
-rw-r--r--sway/input/input-manager.c185
-rw-r--r--sway/input/keyboard.c18
-rw-r--r--sway/input/seat.c104
-rw-r--r--sway/server.c2
10 files changed, 205 insertions, 177 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 7710c6ab..57f76ea9 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -71,28 +71,7 @@ void input_cmd_apply(struct input_config *input) {
71 } 71 }
72 72
73 current_input_config = input; 73 current_input_config = input;
74 74 sway_input_manager_apply_config(input_manager, input);
75 if (input->identifier) {
76 // Try to find the input device and apply configuration now. If
77 // this is during startup then there will be no container and config
78 // will be applied during normal "new input" event from wlc.
79 /* TODO WLR
80 struct libinput_device *device = NULL;
81 for (int i = 0; i < input_devices->length; ++i) {
82 device = input_devices->items[i];
83 char* dev_identifier = libinput_dev_unique_id(device);
84 if (!dev_identifier) {
85 break;
86 }
87 int match = dev_identifier && strcmp(dev_identifier, input->identifier) == 0;
88 free(dev_identifier);
89 if (match) {
90 apply_input_config(input, device);
91 break;
92 }
93 }
94 */
95 }
96} 75}
97 76
98/** 77/**
diff --git a/sway/config.c b/sway/config.c
index ec8e89b4..7ae3c2a4 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -226,6 +226,34 @@ static int qstrcmp(const void* a, const void* b) {
226 return strcmp(*((char**) a), *((char**) b)); 226 return strcmp(*((char**) a), *((char**) b));
227} 227}
228 228
229struct input_config *new_input_config(const char* identifier) {
230 struct input_config *input = calloc(1, sizeof(struct input_config));
231 if (!input) {
232 sway_log(L_DEBUG, "Unable to allocate input config");
233 return NULL;
234 }
235 sway_log(L_DEBUG, "new_input_config(%s)", identifier);
236 if (!(input->identifier = strdup(identifier))) {
237 free(input);
238 sway_log(L_DEBUG, "Unable to allocate input config");
239 return NULL;
240 }
241
242 input->tap = INT_MIN;
243 input->drag_lock = INT_MIN;
244 input->dwt = INT_MIN;
245 input->send_events = INT_MIN;
246 input->click_method = INT_MIN;
247 input->middle_emulation = INT_MIN;
248 input->natural_scroll = INT_MIN;
249 input->accel_profile = INT_MIN;
250 input->pointer_accel = FLT_MIN;
251 input->scroll_method = INT_MIN;
252 input->left_handed = INT_MIN;
253
254 return input;
255}
256
229void merge_input_config(struct input_config *dst, struct input_config *src) { 257void merge_input_config(struct input_config *dst, struct input_config *src) {
230 if (src->identifier) { 258 if (src->identifier) {
231 if (dst->identifier) { 259 if (dst->identifier) {
@@ -453,6 +481,7 @@ bool load_include_configs(const char *path, struct sway_config *config) {
453 return true; 481 return true;
454} 482}
455 483
484
456bool read_config(FILE *file, struct sway_config *config) { 485bool read_config(FILE *file, struct sway_config *config) {
457 bool success = true; 486 bool success = true;
458 enum cmd_status block = CMD_BLOCK_END; 487 enum cmd_status block = CMD_BLOCK_END;
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index 0e7f7060..af067326 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -136,10 +136,7 @@ void output_add_notify(struct wl_listener *listener, void *data) {
136 output->resolution.notify = output_resolution_notify; 136 output->resolution.notify = output_resolution_notify;
137 wl_signal_add(&wlr_output->events.resolution, &output->resolution); 137 wl_signal_add(&wlr_output->events.resolution, &output->resolution);
138 138
139 for (int i = 0; i < server->input->seats->length; ++i) { 139 sway_input_manager_configure_xcursor(input_manager);
140 struct sway_seat *seat = server->input->seats->items[i];
141 sway_seat_configure_xcursor(seat);
142 }
143 140
144 arrange_windows(output->swayc, -1, -1); 141 arrange_windows(output->swayc, -1, -1);
145} 142}
diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c
index 3d3b1c44..df81d5be 100644
--- a/sway/desktop/wl_shell.c
+++ b/sway/desktop/wl_shell.c
@@ -129,8 +129,5 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
129 129
130 arrange_windows(cont->parent, -1, -1); 130 arrange_windows(cont->parent, -1, -1);
131 131
132 for (int i = 0; i < server->input->seats->length; ++i) { 132 sway_input_manager_set_focus(input_manager, cont);
133 struct sway_seat *seat = server->input->seats->items[i];
134 sway_seat_set_focus(seat, cont);
135 }
136} 133}
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index 8ad6a5ec..82775e2f 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -135,8 +135,5 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
135 135
136 arrange_windows(cont->parent, -1, -1); 136 arrange_windows(cont->parent, -1, -1);
137 137
138 for (int i = 0; i < server->input->seats->length; ++i) { 138 sway_input_manager_set_focus(input_manager, cont);
139 struct sway_seat *seat = server->input->seats->items[i];
140 sway_seat_set_focus(seat, cont);
141 }
142} 139}
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index 724c8a82..a7e84aa1 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -173,9 +173,5 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
173 sway_view->swayc = cont; 173 sway_view->swayc = cont;
174 174
175 arrange_windows(cont->parent, -1, -1); 175 arrange_windows(cont->parent, -1, -1);
176 176 sway_input_manager_set_focus(input_manager, cont);
177 for (int i = 0; i < server->input->seats->length; ++i) {
178 struct sway_seat *seat = server->input->seats->items[i];
179 sway_seat_set_focus(seat, cont);
180 }
181} 177}
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c
index ca80f267..b7f5615c 100644
--- a/sway/input/input-manager.c
+++ b/sway/input/input-manager.c
@@ -14,23 +14,70 @@
14 14
15static const char *default_seat = "seat0"; 15static const char *default_seat = "seat0";
16 16
17// TODO make me not global
18struct sway_input_manager *input_manager;
19
17struct input_config *current_input_config = NULL; 20struct input_config *current_input_config = NULL;
18 21
19static struct sway_seat *input_manager_get_seat( 22static struct sway_seat *input_manager_get_seat(
20 struct sway_input_manager *input, const char *seat_name) { 23 struct sway_input_manager *input, const char *seat_name) {
21 struct sway_seat *seat = NULL; 24 struct sway_seat *seat = NULL;
22 25 wl_list_for_each(seat, &input->seats, link) {
23 for (int i = 0; i < input->seats->length; ++i) {
24 seat = input->seats->items[i];
25 if (strcmp(seat->seat->name, seat_name) == 0) { 26 if (strcmp(seat->seat->name, seat_name) == 0) {
26 return seat; 27 return seat;
27 } 28 }
28 } 29 }
29 30
30 seat = sway_seat_create(input, seat_name); 31 return sway_seat_create(input, seat_name);
31 list_add(input->seats, seat); 32}
33
34static char *get_device_identifier(struct wlr_input_device *device) {
35 int vendor = device->vendor;
36 int product = device->product;
37 char *name = strdup(device->name);
38
39 char *p = name;
40 for (; *p; ++p) {
41 if (*p == ' ') {
42 *p = '_';
43 }
44 }
45
46 sway_log(L_DEBUG, "rewritten name %s", name);
47
48 int len = strlen(name) + sizeof(char) * 6;
49 char *identifier = malloc(len);
50 if (!identifier) {
51 sway_log(L_ERROR, "Unable to allocate unique input device name");
52 return NULL;
53 }
54
55 const char *fmt = "%d:%d:%s";
56 snprintf(identifier, len, fmt, vendor, product, name);
57 free(name);
58 return identifier;
59}
32 60
33 return seat; 61static struct sway_input_device *input_sway_device_from_wlr(struct sway_input_manager *input,
62 struct wlr_input_device *device) {
63 struct sway_input_device *sway_device = NULL;
64 wl_list_for_each(sway_device, &input->devices, link) {
65 if (sway_device->wlr_device == device) {
66 return sway_device;
67 }
68 }
69 return NULL;
70}
71
72static struct sway_input_device *input_sway_device_from_config(struct sway_input_manager *input,
73 struct input_config *config) {
74 struct sway_input_device *sway_device = NULL;
75 wl_list_for_each(sway_device, &input->devices, link) {
76 if (strcmp(sway_device->identifier, config->identifier) == 0) {
77 return sway_device;
78 }
79 }
80 return NULL;
34} 81}
35 82
36static void input_add_notify(struct wl_listener *listener, void *data) { 83static void input_add_notify(struct wl_listener *listener, void *data) {
@@ -38,9 +85,27 @@ static void input_add_notify(struct wl_listener *listener, void *data) {
38 wl_container_of(listener, input, input_add); 85 wl_container_of(listener, input, input_add);
39 struct wlr_input_device *device = data; 86 struct wlr_input_device *device = data;
40 87
41 // TODO device configuration 88 struct sway_input_device *sway_device =
89 calloc(1, sizeof(struct sway_input_device));
90 if (!sway_assert(sway_device, "could not allocate input device")) {
91 return;
92 }
93
94 sway_device->wlr_device = device;
95 sway_device->identifier = get_device_identifier(device);
96 wl_list_insert(&input->devices, &sway_device->link);
97
98 // find config
99 for (int i = 0; i < config->input_configs->length; ++i) {
100 struct input_config *input_config = config->input_configs->items[i];
101 if (strcmp(input_config->identifier, sway_device->identifier) == 0) {
102 sway_device->config = input_config;
103 break;
104 }
105 }
106
42 struct sway_seat *seat = input_manager_get_seat(input, default_seat); 107 struct sway_seat *seat = input_manager_get_seat(input, default_seat);
43 sway_seat_add_device(seat, device); 108 sway_seat_add_device(seat, sway_device);
44} 109}
45 110
46static void input_remove_notify(struct wl_listener *listener, void *data) { 111static void input_remove_notify(struct wl_listener *listener, void *data) {
@@ -48,9 +113,21 @@ static void input_remove_notify(struct wl_listener *listener, void *data) {
48 wl_container_of(listener, input, input_remove); 113 wl_container_of(listener, input, input_remove);
49 struct wlr_input_device *device = data; 114 struct wlr_input_device *device = data;
50 115
51 // TODO device configuration 116 struct sway_input_device *sway_device =
52 struct sway_seat *seat = input_manager_get_seat(input, default_seat); 117 input_sway_device_from_wlr(input, device);
53 sway_seat_remove_device(seat, device); 118
119 if (!sway_assert(sway_device, "could not find sway device")) {
120 return;
121 }
122
123 struct sway_seat *seat = NULL;
124 wl_list_for_each(seat, &input->seats, link) {
125 sway_seat_remove_device(seat, sway_device);
126 }
127
128 wl_list_remove(&sway_device->link);
129 free(sway_device->identifier);
130 free(sway_device);
54} 131}
55 132
56struct sway_input_manager *sway_input_manager_create( 133struct sway_input_manager *sway_input_manager_create(
@@ -63,7 +140,8 @@ struct sway_input_manager *sway_input_manager_create(
63 // XXX probably don't need the full server 140 // XXX probably don't need the full server
64 input->server = server; 141 input->server = server;
65 142
66 input->seats = create_list(); 143 wl_list_init(&input->devices);
144 wl_list_init(&input->seats);
67 145
68 // create the default seat 146 // create the default seat
69 input_manager_get_seat(input, default_seat); 147 input_manager_get_seat(input, default_seat);
@@ -77,69 +155,46 @@ struct sway_input_manager *sway_input_manager_create(
77 return input; 155 return input;
78} 156}
79 157
80struct input_config *new_input_config(const char* identifier) { 158bool sway_input_manager_has_focus(struct sway_input_manager *input,
81 struct input_config *input = calloc(1, sizeof(struct input_config)); 159 swayc_t *container) {
82 if (!input) { 160 struct sway_seat *seat = NULL;
83 sway_log(L_DEBUG, "Unable to allocate input config"); 161 wl_list_for_each(seat, &input->seats, link) {
84 return NULL; 162 if (seat->focus == container) {
85 } 163 return true;
86 sway_log(L_DEBUG, "new_input_config(%s)", identifier); 164 }
87 if (!(input->identifier = strdup(identifier))) {
88 free(input);
89 sway_log(L_DEBUG, "Unable to allocate input config");
90 return NULL;
91 } 165 }
92 166
93 input->tap = INT_MIN; 167 return false;
94 input->drag_lock = INT_MIN;
95 input->dwt = INT_MIN;
96 input->send_events = INT_MIN;
97 input->click_method = INT_MIN;
98 input->middle_emulation = INT_MIN;
99 input->natural_scroll = INT_MIN;
100 input->accel_profile = INT_MIN;
101 input->pointer_accel = FLT_MIN;
102 input->scroll_method = INT_MIN;
103 input->left_handed = INT_MIN;
104
105 return input;
106} 168}
107 169
108char *libinput_dev_unique_id(struct libinput_device *device) { 170void sway_input_manager_set_focus(struct sway_input_manager *input,
109 int vendor = libinput_device_get_id_vendor(device); 171 swayc_t *container) {
110 int product = libinput_device_get_id_product(device); 172 struct sway_seat *seat ;
111 char *name = strdup(libinput_device_get_name(device)); 173 wl_list_for_each(seat, &input->seats, link) {
112 174 sway_seat_set_focus(seat, container);
113 char *p = name;
114 for (; *p; ++p) {
115 if (*p == ' ') {
116 *p = '_';
117 }
118 } 175 }
176}
119 177
120 sway_log(L_DEBUG, "rewritten name %s", name); 178void sway_input_manager_apply_config(struct sway_input_manager *input,
179 struct input_config *config) {
180 struct sway_input_device *sway_device =
181 input_sway_device_from_config(input, config);
182 if (!sway_device) {
183 return;
184 }
121 185
122 int len = strlen(name) + sizeof(char) * 6; 186 struct sway_seat *seat = NULL;
123 char *identifier = malloc(len); 187 wl_list_for_each(seat, &input->seats, link) {
124 if (!identifier) { 188 sway_seat_remove_device(seat, sway_device);
125 sway_log(L_ERROR, "Unable to allocate unique input device name");
126 return NULL;
127 } 189 }
128 190
129 const char *fmt = "%d:%d:%s"; 191 seat = input_manager_get_seat(input, default_seat);
130 snprintf(identifier, len, fmt, vendor, product, name); 192 sway_seat_add_device(seat, sway_device);
131 free(name);
132 return identifier;
133} 193}
134 194
135bool sway_input_manager_swayc_has_focus(struct sway_input_manager *input, 195void sway_input_manager_configure_xcursor(struct sway_input_manager *input) {
136 swayc_t *container) { 196 struct sway_seat *seat = NULL;
137 for (int i = 0; i < input->seats->length; ++i) { 197 wl_list_for_each(seat, &input->seats, link) {
138 struct sway_seat *seat = input->seats->items[i]; 198 sway_seat_configure_xcursor(seat);
139 if (seat->focus == container) {
140 return true;
141 }
142 } 199 }
143
144 return false;
145} 200}
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c
index 31d254df..6a792c65 100644
--- a/sway/input/keyboard.c
+++ b/sway/input/keyboard.c
@@ -6,7 +6,7 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) {
6 struct sway_keyboard *keyboard = 6 struct sway_keyboard *keyboard =
7 wl_container_of(listener, keyboard, keyboard_key); 7 wl_container_of(listener, keyboard, keyboard_key);
8 struct wlr_event_keyboard_key *event = data; 8 struct wlr_event_keyboard_key *event = data;
9 wlr_seat_set_keyboard(keyboard->seat->seat, keyboard->device); 9 wlr_seat_set_keyboard(keyboard->seat->seat, keyboard->device->wlr_device);
10 wlr_seat_keyboard_notify_key(keyboard->seat->seat, event->time_msec, 10 wlr_seat_keyboard_notify_key(keyboard->seat->seat, event->time_msec,
11 event->keycode, event->state); 11 event->keycode, event->state);
12} 12}
@@ -15,12 +15,12 @@ static void handle_keyboard_modifiers(struct wl_listener *listener,
15 void *data) { 15 void *data) {
16 struct sway_keyboard *keyboard = 16 struct sway_keyboard *keyboard =
17 wl_container_of(listener, keyboard, keyboard_modifiers); 17 wl_container_of(listener, keyboard, keyboard_modifiers);
18 wlr_seat_set_keyboard(keyboard->seat->seat, keyboard->device); 18 wlr_seat_set_keyboard(keyboard->seat->seat, keyboard->device->wlr_device);
19 wlr_seat_keyboard_notify_modifiers(keyboard->seat->seat); 19 wlr_seat_keyboard_notify_modifiers(keyboard->seat->seat);
20} 20}
21 21
22struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat, 22struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat,
23 struct wlr_input_device *device) { 23 struct sway_input_device *device) {
24 struct sway_keyboard *keyboard = 24 struct sway_keyboard *keyboard =
25 calloc(1, sizeof(struct sway_keyboard)); 25 calloc(1, sizeof(struct sway_keyboard));
26 if (!sway_assert(keyboard, "could not allocate sway keyboard")) { 26 if (!sway_assert(keyboard, "could not allocate sway keyboard")) {
@@ -43,18 +43,18 @@ struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat,
43 return NULL; 43 return NULL;
44 } 44 }
45 45
46 wlr_keyboard_set_keymap(device->keyboard, xkb_map_new_from_names(context, 46 wlr_keyboard_set_keymap(device->wlr_device->keyboard,
47 &rules, XKB_KEYMAP_COMPILE_NO_FLAGS)); 47 xkb_map_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS));
48 xkb_context_unref(context); 48 xkb_context_unref(context);
49 49
50 wl_signal_add(&device->keyboard->events.key, &keyboard->keyboard_key); 50 wl_signal_add(&device->wlr_device->keyboard->events.key,
51 &keyboard->keyboard_key);
51 keyboard->keyboard_key.notify = handle_keyboard_key; 52 keyboard->keyboard_key.notify = handle_keyboard_key;
52 53
53 wl_signal_add(&device->keyboard->events.modifiers, &keyboard->keyboard_modifiers); 54 wl_signal_add(&device->wlr_device->keyboard->events.modifiers,
55 &keyboard->keyboard_modifiers);
54 keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers; 56 keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers;
55 57
56 wl_list_insert(&seat->keyboards, &keyboard->link);
57
58 return keyboard; 58 return keyboard;
59} 59}
60 60
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
diff --git a/sway/server.c b/sway/server.c
index 7b9a5e8e..32c8f03c 100644
--- a/sway/server.c
+++ b/sway/server.c
@@ -60,7 +60,7 @@ bool server_init(struct sway_server *server) {
60 return false; 60 return false;
61 } 61 }
62 62
63 server->input = sway_input_manager_create(server); 63 input_manager = sway_input_manager_create(server);
64 64
65 return true; 65 return true;
66} 66}