aboutsummaryrefslogtreecommitdiff
path: root/rootston/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'rootston/input.c')
-rw-r--r--rootston/input.c143
1 files changed, 60 insertions, 83 deletions
diff --git a/rootston/input.c b/rootston/input.c
index 5d367a5e..e96565e0 100644
--- a/rootston/input.c
+++ b/rootston/input.c
@@ -8,6 +8,8 @@
#include "rootston/server.h"
#include "rootston/config.h"
#include "rootston/input.h"
+#include "rootston/keyboard.h"
+#include "rootston/seat.h"
static const char *device_type(enum wlr_input_device_type type) {
switch (type) {
@@ -25,47 +27,47 @@ static const char *device_type(enum wlr_input_device_type type) {
return NULL;
}
+static struct roots_seat *input_get_seat(struct roots_input *input, char *name) {
+ struct roots_seat *seat = NULL;
+ wl_list_for_each(seat, &input->seats, link) {
+ if (strcmp(seat->seat->name, name) == 0) {
+ return seat;
+ }
+ }
+
+ seat = roots_seat_create(input, name);
+ return seat;
+}
+
static void input_add_notify(struct wl_listener *listener, void *data) {
struct wlr_input_device *device = data;
struct roots_input *input = wl_container_of(listener, input, input_add);
- wlr_log(L_DEBUG, "New input device: %s (%d:%d) %s", device->name,
- device->vendor, device->product, device_type(device->type));
- switch (device->type) {
- case WLR_INPUT_DEVICE_KEYBOARD:
- keyboard_add(device, input);
- break;
- case WLR_INPUT_DEVICE_POINTER:
- pointer_add(device, input);
- break;
- case WLR_INPUT_DEVICE_TOUCH:
- touch_add(device, input);
- break;
- case WLR_INPUT_DEVICE_TABLET_TOOL:
- tablet_tool_add(device, input);
- break;
- default:
- break;
+
+ char *seat_name = "seat0";
+ struct device_config *dc = config_get_device(input->config, device);
+ if (dc) {
+ seat_name = dc->seat;
+ }
+
+ struct roots_seat *seat = input_get_seat(input, seat_name);
+ if (!seat) {
+ wlr_log(L_ERROR, "could not create roots seat");
+ return;
}
+
+ wlr_log(L_DEBUG, "New input device: %s (%d:%d) %s seat:%s", device->name,
+ device->vendor, device->product, device_type(device->type), seat_name);
+
+ roots_seat_add_device(seat, device);
}
static void input_remove_notify(struct wl_listener *listener, void *data) {
struct wlr_input_device *device = data;
struct roots_input *input = wl_container_of(listener, input, input_remove);
- switch (device->type) {
- case WLR_INPUT_DEVICE_KEYBOARD:
- keyboard_remove(device, input);
- break;
- case WLR_INPUT_DEVICE_POINTER:
- pointer_remove(device, input);
- break;
- case WLR_INPUT_DEVICE_TOUCH:
- touch_remove(device, input);
- break;
- case WLR_INPUT_DEVICE_TABLET_TOOL:
- tablet_tool_remove(device, input);
- break;
- default:
- break;
+
+ struct roots_seat *seat;
+ wl_list_for_each(seat, &input->seats, link) {
+ roots_seat_remove_device(seat, device);
}
}
@@ -82,66 +84,41 @@ struct roots_input *input_create(struct roots_server *server,
input->config = config;
input->server = server;
- input->xcursor_theme = wlr_xcursor_theme_load("default", 16);
- if (input->xcursor_theme == NULL) {
- wlr_log(L_ERROR, "Cannot load xcursor theme");
- free(input);
- return NULL;
- }
-
- struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme);
- if (xcursor == NULL) {
- wlr_log(L_ERROR, "Cannot load xcursor from theme");
- wlr_xcursor_theme_destroy(input->xcursor_theme);
- free(input);
- return NULL;
- }
-
- if (server->desktop->xwayland != NULL) {
- struct wlr_xcursor_image *xcursor_image = xcursor->images[0];
- wlr_xwayland_set_cursor(server->desktop->xwayland,
- xcursor_image->buffer, xcursor_image->width, xcursor_image->width,
- xcursor_image->height, xcursor_image->hotspot_x,
- xcursor_image->hotspot_y);
- }
-
- input->wl_seat = wlr_seat_create(server->wl_display, "seat0");
- if (input->wl_seat == NULL) {
- wlr_log(L_ERROR, "Cannot create seat");
- wlr_xcursor_theme_destroy(input->xcursor_theme);
- free(input);
- return NULL;
- }
- wlr_seat_set_capabilities(input->wl_seat, WL_SEAT_CAPABILITY_KEYBOARD
- | WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH);
-
- wl_list_init(&input->keyboards);
- wl_list_init(&input->pointers);
- wl_list_init(&input->touch);
- wl_list_init(&input->tablet_tools);
+ wl_list_init(&input->seats);
input->input_add.notify = input_add_notify;
wl_signal_add(&server->backend->events.input_add, &input->input_add);
input->input_remove.notify = input_remove_notify;
wl_signal_add(&server->backend->events.input_remove, &input->input_remove);
- input->cursor = wlr_cursor_create();
- cursor_initialize(input);
-
- struct wlr_xcursor_image *image = xcursor->images[0];
- wlr_cursor_set_image(input->cursor, image->buffer, image->width,
- image->width, image->height, image->hotspot_x, image->hotspot_y);
-
- wlr_cursor_attach_output_layout(input->cursor, server->desktop->layout);
- wlr_cursor_map_to_region(input->cursor, config->cursor.mapped_box);
- cursor_load_config(config, input->cursor,
- input, server->desktop);
-
- wl_list_init(&input->drag_icons);
-
return input;
}
void input_destroy(struct roots_input *input) {
// TODO
}
+
+struct roots_seat *input_seat_from_wlr_seat(struct roots_input *input,
+ struct wlr_seat *wlr_seat) {
+ struct roots_seat *seat = NULL;
+ wl_list_for_each(seat, &input->seats, link) {
+ if (seat->seat == wlr_seat) {
+ return seat;
+ }
+ }
+ return seat;
+}
+
+bool input_view_has_focus(struct roots_input *input, struct roots_view *view) {
+ if (!view) {
+ return false;
+ }
+ struct roots_seat *seat;
+ wl_list_for_each(seat, &input->seats, link) {
+ if (seat->focus == view) {
+ return true;
+ }
+ }
+
+ return false;
+}