aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/libinput/keyboard.c1
-rw-r--r--backend/wayland/wl_seat.c12
-rw-r--r--backend/x11/backend.c1
-rw-r--r--include/rootston/config.h1
-rw-r--r--include/rootston/input.h53
-rw-r--r--include/rootston/keyboard.h35
-rw-r--r--include/rootston/seat.h72
-rw-r--r--include/wlr/interfaces/wlr_keyboard.h3
-rw-r--r--include/wlr/types/wlr_keyboard.h11
-rw-r--r--rootston/config.c6
-rw-r--r--rootston/cursor.c2
-rw-r--r--rootston/input.c67
-rw-r--r--rootston/keyboard.c44
-rw-r--r--rootston/meson.build4
-rw-r--r--rootston/pointer.c23
-rw-r--r--rootston/seat.c293
-rw-r--r--rootston/tablet_tool.c24
-rw-r--r--rootston/touch.c26
-rw-r--r--types/wlr_keyboard.c11
19 files changed, 494 insertions, 195 deletions
diff --git a/backend/libinput/keyboard.c b/backend/libinput/keyboard.c
index 065d8ead..9a24c791 100644
--- a/backend/libinput/keyboard.c
+++ b/backend/libinput/keyboard.c
@@ -54,6 +54,7 @@ void handle_keyboard_key(struct libinput_event *event,
struct libinput_event_keyboard *kbevent =
libinput_event_get_keyboard_event(event);
struct wlr_event_keyboard_key wlr_event = { 0 };
+ wlr_event.device = wlr_dev;
wlr_event.time_msec =
usec_to_msec(libinput_event_keyboard_get_time_usec(kbevent));
wlr_event.keycode = libinput_event_keyboard_get_key(kbevent);
diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c
index a2da8df5..74eaf9bd 100644
--- a/backend/wayland/wl_seat.c
+++ b/backend/wayland/wl_seat.c
@@ -151,6 +151,7 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard,
assert(dev && dev->keyboard);
struct wlr_event_keyboard_key wlr_event;
+ wlr_event.device = dev;
wlr_event.keycode = key;
wlr_event.state = state;
wlr_event.time_msec = time;
@@ -162,8 +163,15 @@ static void keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboar
uint32_t mods_locked, uint32_t group) {
struct wlr_input_device *dev = data;
assert(dev && dev->keyboard);
- wlr_keyboard_notify_modifiers(dev->keyboard, mods_depressed, mods_latched,
- mods_locked, group);
+ struct wlr_event_keyboard_modifiers wlr_event;
+ wlr_event.device = dev;
+ wlr_event.keyboard = dev->keyboard;
+ wlr_event.mods_depressed = mods_depressed;
+ wlr_event.mods_latched = mods_latched;
+ wlr_event.mods_locked = mods_locked;
+ wlr_event.group = group;
+
+ wlr_keyboard_notify_modifiers(dev->keyboard, &wlr_event);
}
static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard,
diff --git a/backend/x11/backend.c b/backend/x11/backend.c
index 97b0dd8c..f76b314e 100644
--- a/backend/x11/backend.c
+++ b/backend/x11/backend.c
@@ -50,6 +50,7 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e
case XCB_KEY_RELEASE: {
xcb_key_press_event_t *ev = (xcb_key_press_event_t *)event;
struct wlr_event_keyboard_key key = {
+ .device = &x11->keyboard_dev,
.time_msec = ev->time,
.keycode = ev->detail - 8,
.state = event->response_type == XCB_KEY_PRESS ?
diff --git a/include/rootston/config.h b/include/rootston/config.h
index 75c04619..58fb1a1c 100644
--- a/include/rootston/config.h
+++ b/include/rootston/config.h
@@ -19,6 +19,7 @@ struct device_config {
char *name;
char *mapped_output;
struct wlr_box *mapped_box;
+ char *seat;
struct wl_list link;
};
diff --git a/include/rootston/input.h b/include/rootston/input.h
index 20b73c8a..7b1358f8 100644
--- a/include/rootston/input.h
+++ b/include/rootston/input.h
@@ -1,6 +1,5 @@
#ifndef _ROOTSTON_INPUT_H
#define _ROOTSTON_INPUT_H
-#include <xkbcommon/xkbcommon.h>
#include <wayland-server.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_cursor.h>
@@ -10,41 +9,6 @@
#include "rootston/view.h"
#include "rootston/server.h"
-#define ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP 32
-
-struct roots_keyboard {
- struct roots_input *input;
- struct wlr_input_device *device;
- struct wl_listener key;
- struct wl_listener modifiers;
- struct wl_list link;
-
- xkb_keysym_t pressed_keysyms[ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP];
-};
-
-struct roots_pointer {
- struct roots_input *input;
- struct wlr_input_device *device;
- struct wl_list link;
-};
-
-struct roots_touch {
- struct roots_input *input;
- struct wlr_input_device *device;
- struct wl_list link;
-};
-
-// TODO: tablet pad
-struct roots_tablet_tool {
- struct roots_input *input;
- struct wlr_input_device *device;
- struct wl_listener axis;
- struct wl_listener proximity;
- struct wl_listener tip;
- struct wl_listener button;
- struct wl_list link;
-};
-
enum roots_cursor_mode {
ROOTS_CURSOR_PASSTHROUGH = 0,
ROOTS_CURSOR_MOVE = 1,
@@ -77,13 +41,6 @@ struct roots_drag_icon {
struct wl_listener surface_commit;
};
-struct roots_touch_point {
- struct roots_touch *device;
- int32_t slot;
- double x, y;
- struct wl_list link;
-};
-
struct roots_input {
struct roots_config *config;
struct roots_server *server;
@@ -110,6 +67,7 @@ struct roots_input {
struct wl_list pointers;
struct wl_list touch;
struct wl_list tablet_tools;
+ struct wl_list seats;
struct wl_listener input_add;
struct wl_listener input_remove;
@@ -138,15 +96,6 @@ struct roots_input *input_create(struct roots_server *server,
struct roots_config *config);
void input_destroy(struct roots_input *input);
-void pointer_add(struct wlr_input_device *device, struct roots_input *input);
-void pointer_remove(struct wlr_input_device *device, struct roots_input *input);
-void keyboard_add(struct wlr_input_device *device, struct roots_input *input);
-void keyboard_remove(struct wlr_input_device *device, struct roots_input *input);
-void touch_add(struct wlr_input_device *device, struct roots_input *input);
-void touch_remove(struct wlr_input_device *device, struct roots_input *input);
-void tablet_tool_add(struct wlr_input_device *device, struct roots_input *input);
-void tablet_tool_remove(struct wlr_input_device *device, struct roots_input *input);
-
void cursor_initialize(struct roots_input *input);
void cursor_load_config(struct roots_config *config,
struct wlr_cursor *cursor,
diff --git a/include/rootston/keyboard.h b/include/rootston/keyboard.h
new file mode 100644
index 00000000..cb639ba1
--- /dev/null
+++ b/include/rootston/keyboard.h
@@ -0,0 +1,35 @@
+#ifndef _ROOTSTON_KEYBOARD_H
+#define _ROOTSTON_KEYBOARD_H
+
+#include <xkbcommon/xkbcommon.h>
+#include "rootston/input.h"
+
+#define ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP 32
+
+struct roots_keyboard {
+ struct roots_input *input;
+ struct roots_seat *seat;
+ struct wlr_input_device *device;
+ struct wl_list seat_link;
+ // XXX temporary
+ struct wl_list link;
+
+ struct wl_listener keyboard_key;
+ struct wl_listener keyboard_modifiers;
+
+ xkb_keysym_t pressed_keysyms[ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP];
+};
+
+struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device,
+ struct roots_input *input);
+
+void roots_keyboard_destroy(struct wlr_input_device *device,
+ struct roots_input *input);
+
+void roots_keyboard_handle_key(struct roots_keyboard *keyboard,
+ struct wlr_event_keyboard_key *event);
+
+void roots_keyboard_handle_modifiers(struct roots_keyboard *r_keyboard,
+ struct wlr_event_keyboard_modifiers *event);
+
+#endif
diff --git a/include/rootston/seat.h b/include/rootston/seat.h
new file mode 100644
index 00000000..e4130e5a
--- /dev/null
+++ b/include/rootston/seat.h
@@ -0,0 +1,72 @@
+#ifndef _ROOTSTON_SEAT_H
+#define _ROOTSTON_SEAT_H
+
+#include <wayland-server.h>
+
+#include "rootston/input.h"
+#include "rootston/keyboard.h"
+
+struct roots_seat {
+ struct roots_input *input;
+ struct wlr_seat *seat;
+ struct wlr_cursor *cursor;
+ struct wl_list link;
+
+ struct wl_list keyboards;
+ struct wl_list pointers;
+ struct wl_list touch;
+ struct wl_list tablet_tools;
+
+ struct wl_listener cursor_motion;
+ struct wl_listener cursor_motion_absolute;
+ struct wl_listener cursor_button;
+ struct wl_listener cursor_axis;
+
+ struct wl_listener cursor_touch_down;
+ struct wl_listener cursor_touch_up;
+ struct wl_listener cursor_touch_motion;
+
+ struct wl_listener cursor_tool_axis;
+ struct wl_listener cursor_tool_tip;
+};
+
+struct roots_pointer {
+ struct roots_seat *seat;
+ struct wlr_input_device *device;
+ struct wl_list link;
+};
+
+struct roots_touch {
+ struct roots_seat *seat;
+ struct wlr_input_device *device;
+ struct wl_list link;
+};
+
+struct roots_touch_point {
+ struct roots_touch *device;
+ int32_t slot;
+ double x, y;
+ struct wl_list link;
+};
+
+struct roots_tablet_tool {
+ struct roots_seat *seat;
+ struct wlr_input_device *device;
+ struct wl_listener axis;
+ struct wl_listener proximity;
+ struct wl_listener tip;
+ struct wl_listener button;
+ struct wl_list link;
+};
+
+struct roots_seat *roots_seat_create(struct roots_input *input, char *name);
+
+void roots_seat_destroy(struct roots_seat *seat);
+
+void roots_seat_add_device(struct roots_seat *seat,
+ struct wlr_input_device *device);
+
+void roots_seat_remove_device(struct roots_seat *seat,
+ struct wlr_input_device *device);
+
+#endif
diff --git a/include/wlr/interfaces/wlr_keyboard.h b/include/wlr/interfaces/wlr_keyboard.h
index 570f5721..5848416d 100644
--- a/include/wlr/interfaces/wlr_keyboard.h
+++ b/include/wlr/interfaces/wlr_keyboard.h
@@ -14,7 +14,6 @@ void wlr_keyboard_destroy(struct wlr_keyboard *keyboard);
void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard,
struct wlr_event_keyboard_key *event);
void wlr_keyboard_notify_modifiers(struct wlr_keyboard *keyboard,
- uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked,
- uint32_t group);
+ struct wlr_event_keyboard_modifiers *event);
#endif
diff --git a/include/wlr/types/wlr_keyboard.h b/include/wlr/types/wlr_keyboard.h
index af837ff5..c42cea9c 100644
--- a/include/wlr/types/wlr_keyboard.h
+++ b/include/wlr/types/wlr_keyboard.h
@@ -63,12 +63,23 @@ enum wlr_key_state {
};
struct wlr_event_keyboard_key {
+ struct wlr_input_device *device;
+ struct wlr_keyboard *keyboard;
uint32_t time_msec;
uint32_t keycode;
bool update_state;
enum wlr_key_state state;
};
+struct wlr_event_keyboard_modifiers {
+ struct wlr_input_device *device;
+ struct wlr_keyboard *keyboard;
+ uint32_t mods_depressed;
+ uint32_t mods_latched;
+ uint32_t mods_locked;
+ uint32_t group;
+};
+
void wlr_keyboard_set_keymap(struct wlr_keyboard *kb,
struct xkb_keymap *keymap);
void wlr_keyboard_led_update(struct wlr_keyboard *keyboard, uint32_t leds);
diff --git a/rootston/config.c b/rootston/config.c
index dc7a4b1d..815040bf 100644
--- a/rootston/config.c
+++ b/rootston/config.c
@@ -13,6 +13,7 @@
#include <wlr/types/wlr_box.h>
#include "rootston/config.h"
#include "rootston/input.h"
+#include "rootston/keyboard.h"
#include "rootston/ini.h"
static void usage(const char *name, int ret) {
@@ -288,6 +289,7 @@ static int config_ini_handler(void *user, const char *section, const char *name,
if (!found) {
dc = calloc(1, sizeof(struct device_config));
dc->name = strdup(device_name);
+ dc->seat = strdup("seat0");
wl_list_insert(&config->devices, &dc->link);
}
@@ -297,6 +299,9 @@ static int config_ini_handler(void *user, const char *section, const char *name,
} else if (strcmp(name, "geometry") == 0) {
free(dc->mapped_box);
dc->mapped_box = parse_geometry(value);
+ } else if (strcmp(name, "seat") == 0) {
+ free(dc->seat);
+ dc->seat = strdup(value);
} else {
wlr_log(L_ERROR, "got unknown device config: %s", name);
}
@@ -386,6 +391,7 @@ void roots_config_destroy(struct roots_config *config) {
struct device_config *dc, *dtmp = NULL;
wl_list_for_each_safe(dc, dtmp, &config->devices, link) {
free(dc->name);
+ free(dc->seat);
free(dc->mapped_output);
free(dc->mapped_box);
free(dc);
diff --git a/rootston/cursor.c b/rootston/cursor.c
index b153e8c8..64277464 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -18,6 +18,8 @@
#include "rootston/input.h"
#include "rootston/desktop.h"
#include "rootston/view.h"
+#include "rootston/keyboard.h"
+#include "rootston/seat.h"
const struct roots_input_event *get_input_event(struct roots_input *input,
uint32_t serial) {
diff --git a/rootston/input.c b/rootston/input.c
index 5d367a5e..4a567763 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);
+
+ 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", 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;
- }
+
+ 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_input *input = wl_container_of(listener, input, input_add);
+
+ struct roots_seat *seat;
+ wl_list_for_each(seat, &input->seats, link) {
+ roots_seat_remove_device(seat, device);
}
}
@@ -119,6 +121,7 @@ struct roots_input *input_create(struct roots_server *server,
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);
diff --git a/rootston/keyboard.c b/rootston/keyboard.c
index e174b731..0865f551 100644
--- a/rootston/keyboard.c
+++ b/rootston/keyboard.c
@@ -10,6 +10,8 @@
#include <wlr/util/log.h>
#include <xkbcommon/xkbcommon.h>
#include "rootston/input.h"
+#include "rootston/seat.h"
+#include "rootston/keyboard.h"
static ssize_t keyboard_pressed_keysym_index(struct roots_keyboard *keyboard,
xkb_keysym_t keysym) {
@@ -84,8 +86,8 @@ static bool keyboard_keysym_press(struct roots_keyboard *keyboard,
}
if (keysym == XKB_KEY_Escape) {
- wlr_seat_pointer_end_grab(keyboard->input->wl_seat);
- wlr_seat_keyboard_end_grab(keyboard->input->wl_seat);
+ wlr_seat_pointer_end_grab(keyboard->seat->seat);
+ wlr_seat_keyboard_end_grab(keyboard->seat->seat);
}
uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard);
@@ -122,10 +124,8 @@ static void keyboard_keysym_release(struct roots_keyboard *keyboard,
}
}
-static void keyboard_key_notify(struct wl_listener *listener, void *data) {
- struct wlr_event_keyboard_key *event = data;
- struct roots_keyboard *keyboard = wl_container_of(listener, keyboard, key);
-
+void roots_keyboard_handle_key(struct roots_keyboard *keyboard,
+ struct wlr_event_keyboard_key *event) {
uint32_t keycode = event->keycode + 8;
const xkb_keysym_t *syms;
int syms_len = xkb_state_key_get_syms(keyboard->device->keyboard->xkb_state,
@@ -142,16 +142,15 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) {
}
if (!handled) {
- wlr_seat_set_keyboard(keyboard->input->wl_seat, keyboard->device);
- wlr_seat_keyboard_notify_key(keyboard->input->wl_seat, event->time_msec,
+ wlr_seat_set_keyboard(keyboard->seat->seat, keyboard->device);
+ wlr_seat_keyboard_notify_key(keyboard->seat->seat, event->time_msec,
event->keycode, event->state);
}
}
-static void keyboard_modifiers_notify(struct wl_listener *listener, void *data) {
- struct roots_keyboard *r_keyboard =
- wl_container_of(listener, r_keyboard, modifiers);
- struct wlr_seat *seat = r_keyboard->input->wl_seat;
+void roots_keyboard_handle_modifiers(struct roots_keyboard *r_keyboard,
+ struct wlr_event_keyboard_modifiers *event) {
+ struct wlr_seat *seat = r_keyboard->seat->seat;
struct wlr_keyboard *keyboard = r_keyboard->device->keyboard;
wlr_seat_set_keyboard(seat, r_keyboard->device);
wlr_seat_keyboard_notify_modifiers(seat,
@@ -159,7 +158,6 @@ static void keyboard_modifiers_notify(struct wl_listener *listener, void *data)
keyboard->modifiers.latched,
keyboard->modifiers.locked,
keyboard->modifiers.group);
-
}
static void keyboard_config_merge(struct keyboard_config *config,
@@ -184,21 +182,17 @@ static void keyboard_config_merge(struct keyboard_config *config,
}
}
-void keyboard_add(struct wlr_input_device *device, struct roots_input *input) {
+struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device,
+ struct roots_input *input) {
struct roots_keyboard *keyboard = calloc(sizeof(struct roots_keyboard), 1);
if (keyboard == NULL) {
- return;
+ return NULL;
}
device->data = keyboard;
keyboard->device = device;
keyboard->input = input;
- keyboard->key.notify = keyboard_key_notify;
- wl_signal_add(&device->keyboard->events.key, &keyboard->key);
-
- keyboard->modifiers.notify = keyboard_modifiers_notify;
- wl_signal_add(&device->keyboard->events.modifiers, &keyboard->modifiers);
-
+ // XXX temporary
wl_list_insert(&input->keyboards, &keyboard->link);
struct keyboard_config config;
@@ -225,17 +219,17 @@ void keyboard_add(struct wlr_input_device *device, struct roots_input *input) {
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (context == NULL) {
wlr_log(L_ERROR, "Cannot create XKB context");
- return;
+ return NULL;
}
wlr_keyboard_set_keymap(device->keyboard, xkb_map_new_from_names(context,
&rules, XKB_KEYMAP_COMPILE_NO_FLAGS));
xkb_context_unref(context);
+
+ return keyboard;
}
-void keyboard_remove(struct wlr_input_device *device, struct roots_input *input) {
+void roots_keyboard_destroy(struct wlr_input_device *device, struct roots_input *input) {
struct roots_keyboard *keyboard = device->data;
- wl_list_remove(&keyboard->key.link);
- wl_list_remove(&keyboard->modifiers.link);
wl_list_remove(&keyboard->link);
free(keyboard);
}
diff --git a/rootston/meson.build b/rootston/meson.build
index d84422d8..9c543c4f 100644
--- a/rootston/meson.build
+++ b/rootston/meson.build
@@ -7,9 +7,7 @@ sources = [
'keyboard.c',
'main.c',
'output.c',
- 'pointer.c',
- 'tablet_tool.c',
- 'touch.c',
+ 'seat.c',
'xcursor.c',
'xdg_shell_v6.c',
'wl_shell.c',
diff --git a/rootston/pointer.c b/rootston/pointer.c
deleted file mode 100644
index 299ecdfc..00000000
--- a/rootston/pointer.c
+++ /dev/null
@@ -1,23 +0,0 @@
-#include <stdlib.h>
-#include <wayland-server.h>
-#include <wlr/types/wlr_input_device.h>
-#include <wlr/types/wlr_pointer.h>
-#include "rootston/input.h"
-
-void pointer_add(struct wlr_input_device *device, struct roots_input *input) {
- struct roots_pointer *pointer = calloc(sizeof(struct roots_pointer), 1);
- device->data = pointer;
- pointer->device = device;
- pointer->input = input;
- wl_list_insert(&input->pointers, &pointer->link);
- wlr_cursor_attach_input_device(input->cursor, device);
- cursor_load_config(input->server->config, input->cursor,
- input, input->server->desktop);
-}
-
-void pointer_remove(struct wlr_input_device *device, struct roots_input *input) {
- struct roots_pointer *pointer = device->data;
- wlr_cursor_detach_input_device(input->cursor, device);
- wl_list_remove(&pointer->link);
- free(pointer);
-}
diff --git a/rootston/seat.c b/rootston/seat.c
new file mode 100644
index 00000000..c8f689bc
--- /dev/null
+++ b/rootston/seat.c
@@ -0,0 +1,293 @@
+#include <wayland-server.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <wlr/util/log.h>
+
+#include "rootston/input.h"
+#include "rootston/seat.h"
+#include "rootston/keyboard.h"
+
+static void handle_keyboard_key(struct wl_listener *listener, void *data) {
+ struct roots_keyboard *keyboard =
+ wl_container_of(listener, keyboard, keyboard_key);
+ struct wlr_event_keyboard_key *event = data;
+ roots_keyboard_handle_key(keyboard, event);
+}
+
+static void handle_keyboard_modifiers(struct wl_listener *listener,
+ void *data) {
+ struct roots_keyboard *keyboard =
+ wl_container_of(listener, keyboard, keyboard_modifiers);
+ struct wlr_event_keyboard_modifiers *event = data;
+ roots_keyboard_handle_modifiers(keyboard, event);
+}
+
+static void handle_cursor_motion(struct wl_listener *listener, void *data) {
+ // TODO
+}
+
+static void handle_cursor_motion_absolute(struct wl_listener *listener, void *data) {
+ // TODO
+}
+
+static void handle_cursor_button(struct wl_listener *listener, void *data) {
+ // TODO
+}
+
+static void handle_cursor_axis(struct wl_listener *listener, void *data) {
+ // TODO
+}
+
+static void handle_touch_down(struct wl_listener *listener, void *data) {
+ // TODO
+}
+
+static void handle_touch_up(struct wl_listener *listener, void *data) {
+ // TODO
+}
+
+static void handle_touch_motion(struct wl_listener *listener, void *data) {
+ // TODO
+}
+
+static void handle_tool_axis(struct wl_listener *listener, void *data) {
+ // TODO
+}
+
+static void handle_tool_tip(struct wl_listener *listener, void *data) {
+ // TODO
+}
+
+static void seat_reset_device_mappings(struct roots_seat *seat, struct wlr_input_device *device) {
+ struct wlr_cursor *cursor = seat->cursor;
+ struct roots_config *config = seat->input->config;
+
+ wlr_cursor_map_input_to_output(cursor, device, NULL);
+ struct device_config *dconfig;
+ if ((dconfig = config_get_device(config, device))) {
+ wlr_cursor_map_input_to_region(cursor, device, dconfig->mapped_box);
+ }
+}
+
+static void seat_set_device_output_mappings(struct roots_seat *seat,
+ struct wlr_input_device *device, struct wlr_output *output) {
+ struct wlr_cursor *cursor = seat->cursor;
+ struct roots_config *config = seat->input->config;
+ struct device_config *dconfig;
+ dconfig = config_get_device(config, device);
+ if (dconfig && dconfig->mapped_output &&
+ strcmp(dconfig->mapped_output, output->name) == 0) {
+ wlr_cursor_map_input_to_output(cursor, device, output);
+ }
+}
+
+static void roots_seat_configure_cursor(struct roots_seat *seat) {
+ struct roots_config *config = seat->input->config;
+ struct roots_desktop *desktop = seat->input->server->desktop;
+ struct wlr_cursor *cursor = seat->cursor;
+
+ struct roots_pointer *pointer;
+ struct roots_touch *touch;
+ struct roots_tablet_tool *tablet_tool;
+ struct roots_output *output;
+
+ // reset mappings
+ wlr_cursor_map_to_output(cursor, NULL);
+ wl_list_for_each(pointer, &seat->pointers, link) {
+ seat_reset_device_mappings(seat, pointer->device);
+ }
+ wl_list_for_each(touch, &seat->touch, link) {
+ seat_reset_device_mappings(seat, touch->device);
+ }
+ wl_list_for_each(tablet_tool, &seat->tablet_tools, link) {
+ seat_reset_device_mappings(seat, tablet_tool->device);
+ }
+
+ // configure device to output mappings
+ const char *mapped_output = config->cursor.mapped_output;
+ wl_list_for_each(output, &desktop->outputs, link) {
+ if (mapped_output && strcmp(mapped_output, output->wlr_output->name) == 0) {
+ wlr_cursor_map_to_output(cursor, output->wlr_output);
+ }
+
+ wl_list_for_each(pointer, &seat->pointers, link) {
+ seat_set_device_output_mappings(seat, pointer->device, output->wlr_output);
+ }
+ wl_list_for_each(tablet_tool, &seat->tablet_tools, link) {
+ seat_set_device_output_mappings(seat, tablet_tool->device, output->wlr_output);
+ }
+ wl_list_for_each(touch, &seat->touch, link) {
+ seat_set_device_output_mappings(seat, touch->device, output->wlr_output);
+ }
+ }
+}
+
+static void roots_seat_init_cursor(struct roots_seat *seat) {
+ struct wlr_cursor *cursor = wlr_cursor_create();
+ if (!cursor) {
+ return;
+ }
+ seat->cursor = cursor;
+
+ // add output layout and configure
+ struct roots_desktop *desktop = seat->input->server->desktop;
+ wlr_cursor_attach_output_layout(cursor, desktop->layout);
+ roots_seat_configure_cursor(seat);
+ // TODO configure cursor by seat
+
+ // add input signals
+ wl_signal_add(&cursor->events.motion, &seat->cursor_motion);
+ seat->cursor_motion.notify = handle_cursor_motion;
+
+ wl_signal_add(&cursor->events.motion_absolute,
+ &seat->cursor_motion_absolute);
+ seat->cursor_motion_absolute.notify = handle_cursor_motion_absolute;
+
+ wl_signal_add(&cursor->events.button, &seat->cursor_button);
+ seat->cursor_button.notify = handle_cursor_button;
+
+ wl_signal_add(&cursor->events.axis, &seat->cursor_axis);
+ seat->cursor_axis.notify = handle_cursor_axis;
+
+ wl_signal_add(&cursor->events.touch_down, &seat->cursor_touch_down);
+ seat->cursor_touch_down.notify = handle_touch_down;
+
+ wl_signal_add(&cursor->events.touch_up, &seat->cursor_touch_up);
+ seat->cursor_touch_up.notify = handle_touch_up;
+
+ wl_signal_add(&cursor->events.touch_motion, &seat->cursor_touch_motion);
+ seat->cursor_touch_motion.notify = handle_touch_motion;
+
+ wl_signal_add(&cursor->events.tablet_tool_axis, &seat->cursor_tool_axis);
+ seat->cursor_tool_axis.notify = handle_tool_axis;
+
+ wl_signal_add(&cursor->events.tablet_tool_tip, &seat->cursor_tool_tip);
+ seat->cursor_tool_tip.notify = handle_tool_tip;
+}
+
+struct roots_seat *roots_seat_create(struct roots_input *input, char *name) {
+ struct roots_seat *seat = calloc(1, sizeof(struct roots_seat));
+ if (!seat) {
+ return NULL;
+ }
+
+ roots_seat_init_cursor(seat);
+ if (!seat->cursor) {
+ free(seat);
+ return NULL;
+ }
+
+ seat->seat = wlr_seat_create(input->server->wl_display, name);
+ if (!seat->seat) {
+ free(seat);
+ wlr_cursor_destroy(seat->cursor);
+ return NULL;
+ }
+
+ wlr_seat_set_capabilities(seat->seat,
+ WL_SEAT_CAPABILITY_KEYBOARD |
+ WL_SEAT_CAPABILITY_POINTER |
+ WL_SEAT_CAPABILITY_TOUCH);
+
+ seat->input = input;
+
+ wl_list_insert(&input->seats, &seat->link);
+ wl_list_init(&seat->keyboards);
+
+ return seat;
+}
+
+void roots_seat_destroy(struct roots_seat *seat) {
+ // TODO
+}
+
+static void seat_add_keyboard(struct roots_seat *seat, struct wlr_input_device *device) {
+ struct roots_keyboard *keyboard = roots_keyboard_create(device, seat->input);
+ keyboard->seat = seat;
+
+ wl_list_insert(&seat->keyboards, &keyboard->seat_link);
+
+ keyboard->keyboard_key.notify = handle_keyboard_key;
+ wl_signal_add(&keyboard->device->keyboard->events.key,
+ &keyboard->keyboard_key);
+
+ keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers;
+ wl_signal_add(&keyboard->device->keyboard->events.modifiers,
+ &keyboard->keyboard_modifiers);
+}
+
+static void seat_add_pointer(struct roots_seat *seat, struct wlr_input_device *device) {
+ struct roots_pointer *pointer = calloc(sizeof(struct roots_pointer), 1);
+ if (!pointer) {
+ wlr_log(L_ERROR, "could not allocate pointer for seat");
+ return;
+ }
+
+ device->data = pointer;
+ pointer->device = device;
+ pointer->seat = seat;
+ wl_list_insert(&seat->pointers, &pointer->link);
+ wlr_cursor_attach_input_device(seat->cursor, device);
+ roots_seat_configure_cursor(seat);
+}
+
+static void seat_add_touch(struct roots_seat *seat, struct wlr_input_device *device) {
+ struct roots_touch *touch = calloc(sizeof(struct roots_touch), 1);
+ if (!touch) {
+ wlr_log(L_ERROR, "could not allocate touch for seat");
+ return;
+ }
+
+ device->data = touch;
+ touch->device = device;
+ touch->seat = seat;
+ wl_list_insert(&seat->touch, &touch->link);
+ wlr_cursor_attach_input_device(seat->cursor, device);
+ roots_seat_configure_cursor(seat);
+}
+
+static void seat_add_tablet_pad(struct roots_seat *seat, struct wlr_input_device *device) {
+ // TODO
+}
+
+static void seat_add_tablet_tool(struct roots_seat *seat, struct wlr_input_device *device) {
+ struct roots_tablet_tool *tablet_tool = calloc(sizeof(struct roots_tablet_tool), 1);
+ if (!tablet_tool) {
+ wlr_log(L_ERROR, "could not allocate tablet_tool for seat");
+ return;
+ }
+
+ device->data = tablet_tool;
+ tablet_tool->device = device;
+ tablet_tool->seat = seat;
+ wl_list_insert(&seat->tablet_tools, &tablet_tool->link);
+ wlr_cursor_attach_input_device(seat->cursor, device);
+ roots_seat_configure_cursor(seat);
+}
+
+void roots_seat_add_device(struct roots_seat *seat,
+ struct wlr_input_device *device) {
+ switch (device->type) {
+ case WLR_INPUT_DEVICE_KEYBOARD:
+ seat_add_keyboard(seat, device);
+ break;
+ case WLR_INPUT_DEVICE_POINTER:
+ seat_add_pointer(seat, device);
+ break;
+ case WLR_INPUT_DEVICE_TOUCH:
+ seat_add_touch(seat, device);
+ break;
+ case WLR_INPUT_DEVICE_TABLET_PAD:
+ seat_add_tablet_pad(seat, device);
+ break;
+ case WLR_INPUT_DEVICE_TABLET_TOOL:
+ seat_add_tablet_tool(seat, device);
+ break;
+ }
+}
+
+void roots_seat_remove_device(struct roots_seat *seat,
+ struct wlr_input_device *device) {
+ // TODO
+}
diff --git a/rootston/tablet_tool.c b/rootston/tablet_tool.c
deleted file mode 100644
index a612e683..00000000
--- a/rootston/tablet_tool.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <stdlib.h>
-#include <wayland-server.h>
-#include <wlr/types/wlr_input_device.h>
-#include <wlr/types/wlr_pointer.h>
-#include <wlr/util/log.h>
-#include "rootston/input.h"
-
-void tablet_tool_add(struct wlr_input_device *device, struct roots_input *input) {
- struct roots_tablet_tool *tool = calloc(sizeof(struct roots_tablet_tool), 1);
- device->data = tool;
- tool->device = device;
- tool->input = input;
- wl_list_insert(&input->tablet_tools, &tool->link);
- wlr_cursor_attach_input_device(input->cursor, device);
- cursor_load_config(input->server->config, input->cursor,
- input, input->server->desktop);
-}
-
-void tablet_tool_remove(struct wlr_input_device *device, struct roots_input *input) {
- struct roots_tablet_tool *tablet_tool = device->data;
- wlr_cursor_detach_input_device(input->cursor, device);
- wl_list_remove(&tablet_tool->link);
- free(tablet_tool);
-}
diff --git a/rootston/touch.c b/rootston/touch.c
deleted file mode 100644
index f6d9b11a..00000000
--- a/rootston/touch.c
+++ /dev/null
@@ -1,26 +0,0 @@
-#include <stdlib.h>
-#include <wayland-server.h>
-#include <wlr/types/wlr_input_device.h>
-#include <wlr/types/wlr_pointer.h>
-#include "rootston/input.h"
-
-// TODO: we'll likely want touch events to both control the cursor *and* be
-// submitted directly to the seat.
-
-void touch_add(struct wlr_input_device *device, struct roots_input *input) {
- struct roots_touch *touch = calloc(sizeof(struct roots_touch), 1);
- device->data = touch;
- touch->device = device;
- touch->input = input;
- wl_list_insert(&input->touch, &touch->link);
- wlr_cursor_attach_input_device(input->cursor, device);
- cursor_load_config(input->server->config, input->cursor,
- input, input->server->desktop);
-}
-
-void touch_remove(struct wlr_input_device *device, struct roots_input *input) {
- struct roots_touch *touch = device->data;
- wlr_cursor_detach_input_device(input->cursor, device);
- wl_list_remove(&touch->link);
- free(touch);
-}
diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c
index c27264ef..c2fd9e0c 100644
--- a/types/wlr_keyboard.c
+++ b/types/wlr_keyboard.c
@@ -41,19 +41,18 @@ static void keyboard_modifier_update(struct wlr_keyboard *keyboard) {
keyboard->modifiers.latched = latched;
keyboard->modifiers.locked = locked;
keyboard->modifiers.group = group;
-
- wl_signal_emit(&keyboard->events.modifiers, keyboard);
}
void wlr_keyboard_notify_modifiers(struct wlr_keyboard *keyboard,
- uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked,
- uint32_t group) {
+ struct wlr_event_keyboard_modifiers *event) {
if (!keyboard->xkb_state) {
return;
}
- xkb_state_update_mask(keyboard->xkb_state, mods_depressed, mods_latched,
- mods_locked, 0, 0, group);
+ xkb_state_update_mask(keyboard->xkb_state, event->mods_depressed,
+ event->mods_latched, event->mods_locked, 0, 0, event->group);
keyboard_modifier_update(keyboard);
+
+ wl_signal_emit(&keyboard->events.modifiers, event);
}
void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard,