aboutsummaryrefslogtreecommitdiff
path: root/sway/input/seat.c
diff options
context:
space:
mode:
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 @@
#include "sway/view.h"
#include "log.h"
+static void seat_device_destroy(struct sway_seat_device *seat_device) {
+ if (!seat_device) {
+ return;
+ }
+
+ sway_keyboard_destroy(seat_device->keyboard);
+ wlr_cursor_detach_input_device(seat_device->sway_seat->cursor->cursor,
+ seat_device->input_device->wlr_device);
+ wl_list_remove(&seat_device->link);
+ free(seat_device);
+}
+
struct sway_seat *sway_seat_create(struct sway_input_manager *input,
const char *seat_name) {
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,
return NULL;
}
- seat->seat = wlr_seat_create(input->server->wl_display, seat_name);
- if (!sway_assert(seat->seat, "could not allocate seat")) {
+ seat->wlr_seat = wlr_seat_create(input->server->wl_display, seat_name);
+ if (!sway_assert(seat->wlr_seat, "could not allocate seat")) {
return NULL;
}
seat->cursor = sway_cursor_create(seat);
if (!seat->cursor) {
- wlr_seat_destroy(seat->seat);
+ wlr_seat_destroy(seat->wlr_seat);
free(seat);
return NULL;
}
seat->input = input;
- seat->devices = create_list();
+ wl_list_init(&seat->devices);
- wlr_seat_set_capabilities(seat->seat,
+ wlr_seat_set_capabilities(seat->wlr_seat,
WL_SEAT_CAPABILITY_KEYBOARD |
WL_SEAT_CAPABILITY_POINTER |
WL_SEAT_CAPABILITY_TOUCH);
@@ -43,88 +55,94 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input,
return seat;
}
-static void seat_add_pointer(struct sway_seat *seat,
- struct sway_input_device *sway_device) {
+static void seat_configure_pointer(struct sway_seat *seat,
+ struct sway_seat_device *sway_device) {
// TODO pointer configuration
wlr_cursor_attach_input_device(seat->cursor->cursor,
- sway_device->wlr_device);
+ sway_device->input_device->wlr_device);
}
-static void seat_add_keyboard(struct sway_seat *seat,
- struct sway_input_device *device) {
- // TODO keyboard configuration
- sway_keyboard_create(seat, device);
- wlr_seat_set_keyboard(seat->seat, device->wlr_device);
+static void seat_configure_keyboard(struct sway_seat *seat,
+ struct sway_seat_device *seat_device) {
+ if (!seat_device->keyboard) {
+ sway_keyboard_create(seat, seat_device);
+ }
+ sway_keyboard_configure(seat_device->keyboard);
}
-bool sway_seat_has_device(struct sway_seat *seat,
- struct sway_input_device *device) {
- return false;
+static struct sway_seat_device *sway_seat_get_device(struct sway_seat *seat,
+ struct sway_input_device *input_device) {
+ struct sway_seat_device *seat_device = NULL;
+ wl_list_for_each(seat_device, &seat->devices, link) {
+ if (seat_device->input_device == input_device) {
+ return seat_device;
+ }
+ }
+
+ return NULL;
}
-void sway_seat_add_device(struct sway_seat *seat,
- struct sway_input_device *device) {
- if (sway_seat_has_device(seat, device)) {
+void sway_seat_configure_device(struct sway_seat *seat,
+ struct sway_input_device *input_device) {
+ struct sway_seat_device *seat_device =
+ sway_seat_get_device(seat, input_device);
+ if (!seat_device) {
return;
}
- sway_log(L_DEBUG, "input add: %s", device->identifier);
- switch (device->wlr_device->type) {
+ if (seat->config) {
+ seat_device->attachment_config =
+ seat_config_get_attachment(seat->config, input_device->identifier);
+ }
+
+ switch (input_device->wlr_device->type) {
case WLR_INPUT_DEVICE_POINTER:
- seat_add_pointer(seat, device);
+ seat_configure_pointer(seat, seat_device);
break;
case WLR_INPUT_DEVICE_KEYBOARD:
- seat_add_keyboard(seat, device);
+ seat_configure_keyboard(seat, seat_device);
+ wlr_seat_set_keyboard(seat->wlr_seat,
+ seat_device->input_device->wlr_device);
break;
case WLR_INPUT_DEVICE_TOUCH:
case WLR_INPUT_DEVICE_TABLET_PAD:
case WLR_INPUT_DEVICE_TABLET_TOOL:
- sway_log(L_DEBUG, "TODO: add other devices");
+ sway_log(L_DEBUG, "TODO: configure other devices");
break;
}
-
- list_add(seat->devices, device);
}
-static void seat_remove_keyboard(struct sway_seat *seat,
- struct sway_input_device *device) {
- if (device && device->keyboard) {
- sway_keyboard_destroy(device->keyboard);
+void sway_seat_add_device(struct sway_seat *seat,
+ struct sway_input_device *input_device) {
+ if (sway_seat_get_device(seat, input_device)) {
+ return;
}
-}
-static void seat_remove_pointer(struct sway_seat *seat,
- struct sway_input_device *device) {
- wlr_cursor_detach_input_device(seat->cursor->cursor, device->wlr_device);
+ struct sway_seat_device *seat_device =
+ calloc(1, sizeof(struct sway_seat_device));
+ if (!seat_device) {
+ sway_log(L_DEBUG, "could not allocate seat device");
+ return;
+ }
+
+ seat_device->sway_seat = seat;
+ seat_device->input_device = input_device;
+ wl_list_insert(&seat->devices, &seat_device->link);
+
+ sway_seat_configure_device(seat, input_device);
}
void sway_seat_remove_device(struct sway_seat *seat,
- struct sway_input_device *device) {
- sway_log(L_DEBUG, "input remove: %s", device->identifier);
- if (!sway_seat_has_device(seat, device)) {
- return;
- }
+ struct sway_input_device *input_device) {
+ sway_log(L_DEBUG, "input remove: %s", input_device->identifier);
+ struct sway_seat_device *seat_device =
+ sway_seat_get_device(seat, input_device);
- switch (device->wlr_device->type) {
- case WLR_INPUT_DEVICE_POINTER:
- seat_remove_pointer(seat, device);
- break;
- case WLR_INPUT_DEVICE_KEYBOARD:
- seat_remove_keyboard(seat, device);
- break;
- case WLR_INPUT_DEVICE_TOUCH:
- case WLR_INPUT_DEVICE_TABLET_PAD:
- case WLR_INPUT_DEVICE_TABLET_TOOL:
- sway_log(L_DEBUG, "TODO: remove other devices");
- break;
+ if (!seat_device) {
+ return;
}
- for (int i = 0; i < seat->devices->length; ++i) {
- if (seat->devices->items[i] == device) {
- list_del(seat->devices, i);
- break;
- }
- }
+ seat_device_destroy(seat_device);
}
void sway_seat_configure_xcursor(struct sway_seat *seat) {
@@ -135,7 +153,8 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) {
seat->cursor->xcursor_manager =
wlr_xcursor_manager_create("default", 24);
if (sway_assert(seat->cursor->xcursor_manager,
- "Cannot create XCursor manager for theme %s", cursor_theme)) {
+ "Cannot create XCursor manager for theme %s",
+ cursor_theme)) {
return;
}
}
@@ -183,7 +202,7 @@ void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) {
view->iface.set_activated(view, true);
wl_signal_add(&container->events.destroy, &seat->focus_destroy);
seat->focus_destroy.notify = handle_focus_destroy;
- wlr_seat_keyboard_notify_enter(seat->seat, view->surface);
+ wlr_seat_keyboard_notify_enter(seat->wlr_seat, view->surface);
}
seat->focus = container;
@@ -195,3 +214,29 @@ void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) {
}
}
+
+void sway_seat_set_config(struct sway_seat *seat,
+ struct seat_config *seat_config) {
+ // clear configs
+ seat->config = NULL;
+
+ struct sway_seat_device *seat_device = NULL;
+ wl_list_for_each(seat_device, &seat->devices, link) {
+ seat_device->attachment_config = NULL;
+ }
+
+ if (!seat_config) {
+ return;
+ }
+
+ // add configs
+ seat->config = seat_config;
+
+ wl_list_for_each(seat_device, &seat->devices, link) {
+ seat_device->attachment_config =
+ seat_config_get_attachment(seat_config,
+ seat_device->input_device->identifier);
+ sway_seat_configure_device(seat, seat_device->input_device);
+ }
+
+}