aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/wayland/backend.c28
-rw-r--r--backend/wayland/output.c7
-rw-r--r--backend/wayland/seat.c84
3 files changed, 76 insertions, 43 deletions
diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c
index a09126ce..2059b726 100644
--- a/backend/wayland/backend.c
+++ b/backend/wayland/backend.c
@@ -103,9 +103,9 @@ static void registry_global(void *data, struct wl_registry *registry,
wl->compositor = wl_registry_bind(registry, name,
&wl_compositor_interface, 4);
} else if (strcmp(iface, wl_seat_interface.name) == 0) {
- wl->seat = wl_registry_bind(registry, name,
+ struct wl_seat *wl_seat = wl_registry_bind(registry, name,
&wl_seat_interface, 5);
- wl_seat_add_listener(wl->seat, &seat_listener, wl);
+ create_wl_seat(wl_seat, wl);
} else if (strcmp(iface, xdg_wm_base_interface.name) == 0) {
wl->xdg_wm_base = wl_registry_bind(registry, name,
&xdg_wm_base_interface, 1);
@@ -155,13 +155,16 @@ static bool backend_start(struct wlr_backend *backend) {
wl->started = true;
- if (wl->keyboard) {
- create_wl_keyboard(wl->keyboard, wl);
- }
+ struct wlr_wl_seat *seat = wl->seat;
+ if (seat != NULL) {
+ if (seat->keyboard) {
+ create_wl_keyboard(seat->keyboard, wl);
+ }
- if (wl->tablet_manager && wl->seat) {
- wl_add_tablet_seat(wl->tablet_manager,
- wl->seat, wl);
+ if (wl->tablet_manager) {
+ wl_add_tablet_seat(wl->tablet_manager,
+ seat->wl_seat, wl);
+ }
}
for (size_t i = 0; i < wl->requested_outputs; ++i) {
@@ -192,8 +195,6 @@ static void backend_destroy(struct wlr_backend *backend) {
wl_list_remove(&wl->local_display_destroy.link);
- free(wl->seat_name);
-
wl_event_source_remove(wl->remote_display_src);
wlr_renderer_destroy(wl->renderer);
@@ -201,12 +202,7 @@ static void backend_destroy(struct wlr_backend *backend) {
wlr_drm_format_set_finish(&wl->linux_dmabuf_v1_formats);
- if (wl->pointer) {
- wl_pointer_destroy(wl->pointer);
- }
- if (wl->seat) {
- wl_seat_destroy(wl->seat);
- }
+ destroy_wl_seats(wl);
if (wl->zxdg_decoration_manager_v1) {
zxdg_decoration_manager_v1_destroy(wl->zxdg_decoration_manager_v1);
}
diff --git a/backend/wayland/output.c b/backend/wayland/output.c
index b234c6a0..568d90db 100644
--- a/backend/wayland/output.c
+++ b/backend/wayland/output.c
@@ -586,8 +586,11 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *wlr_backend) {
wlr_signal_emit_safe(&backend->backend.events.new_output, wlr_output);
- if (backend->pointer != NULL) {
- create_wl_pointer(backend->pointer, output);
+ struct wlr_wl_seat *seat = backend->seat;
+ if (seat != NULL) {
+ if (seat->pointer) {
+ create_wl_pointer(seat->pointer, output);
+ }
}
return wlr_output;
diff --git a/backend/wayland/seat.c b/backend/wayland/seat.c
index cce5c0dc..f20619d5 100644
--- a/backend/wayland/seat.c
+++ b/backend/wayland/seat.c
@@ -372,12 +372,49 @@ static struct wlr_wl_input_device *get_wl_input_device_from_input_device(
return (struct wlr_wl_input_device *)wlr_dev;
}
+void create_wl_seat(struct wl_seat *wl_seat, struct wlr_wl_backend *wl) {
+ assert(!wl->seat); // only one seat supported at the moment
+ struct wlr_wl_seat *seat = calloc(1, sizeof(struct wlr_wl_seat));
+ seat->wl_seat = wl_seat;
+ wl->seat = seat;
+ wl_seat_add_listener(wl_seat, &seat_listener, wl);
+}
+
+void destroy_wl_seats(struct wlr_wl_backend *wl) {
+ struct wlr_wl_seat *seat = wl->seat;
+ if (!seat) {
+ return;
+ }
+
+ if (seat->pointer) {
+ wl_pointer_destroy(seat->pointer);
+ }
+ free(seat->name);
+ if (seat->wl_seat) {
+ wl_seat_destroy(seat->wl_seat);
+ }
+ free(seat);
+}
+
+static struct wlr_wl_seat *backend_get_seat(struct wlr_wl_backend *backend, struct wl_seat *wl_seat) {
+ assert(backend->seat && backend->seat->wl_seat == wl_seat);
+ return backend->seat;
+}
+
+static struct wlr_wl_seat *input_device_get_seat(struct wlr_input_device *wlr_dev) {
+ struct wlr_wl_input_device *dev =
+ get_wl_input_device_from_input_device(wlr_dev);
+ assert(dev->backend->seat);
+ return dev->backend->seat;
+}
+
static void input_device_destroy(struct wlr_input_device *wlr_dev) {
struct wlr_wl_input_device *dev =
get_wl_input_device_from_input_device(wlr_dev);
if (dev->wlr_input_device.type == WLR_INPUT_DEVICE_KEYBOARD) {
- wl_keyboard_release(dev->backend->keyboard);
- dev->backend->keyboard = NULL;
+ struct wlr_wl_seat *seat = input_device_get_seat(wlr_dev);
+ wl_keyboard_release(seat->keyboard);
+ seat->keyboard = NULL;
}
wl_list_remove(&dev->wlr_input_device.link);
free(dev);
@@ -678,20 +715,20 @@ void create_wl_touch(struct wl_touch *wl_touch, struct wlr_wl_backend *wl) {
static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
enum wl_seat_capability caps) {
struct wlr_wl_backend *backend = data;
- assert(backend->seat == wl_seat);
+ struct wlr_wl_seat *seat = backend_get_seat(backend, wl_seat);
- if ((caps & WL_SEAT_CAPABILITY_POINTER) && backend->pointer == NULL) {
+ if ((caps & WL_SEAT_CAPABILITY_POINTER) && seat->pointer == NULL) {
wlr_log(WLR_DEBUG, "seat %p offered pointer", (void *)wl_seat);
struct wl_pointer *wl_pointer = wl_seat_get_pointer(wl_seat);
- backend->pointer = wl_pointer;
+ seat->pointer = wl_pointer;
struct wlr_wl_output *output;
wl_list_for_each(output, &backend->outputs, link) {
create_wl_pointer(wl_pointer, output);
}
}
- if (!(caps & WL_SEAT_CAPABILITY_POINTER) && backend->pointer != NULL) {
+ if (!(caps & WL_SEAT_CAPABILITY_POINTER) && seat->pointer != NULL) {
wlr_log(WLR_DEBUG, "seat %p dropped pointer", (void *)wl_seat);
struct wlr_input_device *device, *tmp;
@@ -701,21 +738,21 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
}
}
- wl_pointer_release(backend->pointer);
- backend->pointer = NULL;
+ wl_pointer_release(seat->pointer);
+ seat->pointer = NULL;
}
- if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && backend->keyboard == NULL) {
+ if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && seat->keyboard == NULL) {
wlr_log(WLR_DEBUG, "seat %p offered keyboard", (void *)wl_seat);
struct wl_keyboard *wl_keyboard = wl_seat_get_keyboard(wl_seat);
- backend->keyboard = wl_keyboard;
+ seat->keyboard = wl_keyboard;
if (backend->started) {
create_wl_keyboard(wl_keyboard, backend);
}
}
- if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && backend->keyboard != NULL) {
+ if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && seat->keyboard != NULL) {
wlr_log(WLR_DEBUG, "seat %p dropped keyboard", (void *)wl_seat);
struct wlr_input_device *device, *tmp;
@@ -724,18 +761,18 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
wlr_input_device_destroy(device);
}
}
- assert(backend->keyboard == NULL); // free'ed by input_device_destroy
+ assert(seat->keyboard == NULL); // free'ed by input_device_destroy
}
- if ((caps & WL_SEAT_CAPABILITY_TOUCH) && backend->touch == NULL) {
+ if ((caps & WL_SEAT_CAPABILITY_TOUCH) && seat->touch == NULL) {
wlr_log(WLR_DEBUG, "seat %p offered touch", (void *)wl_seat);
- backend->touch = wl_seat_get_touch(wl_seat);
+ seat->touch = wl_seat_get_touch(wl_seat);
if (backend->started) {
- create_wl_touch(backend->touch, backend);
+ create_wl_touch(seat->touch, backend);
}
}
- if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && backend->touch != NULL) {
+ if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && seat->touch != NULL) {
wlr_log(WLR_DEBUG, "seat %p dropped touch", (void *)wl_seat);
struct wlr_input_device *device, *tmp;
@@ -745,18 +782,17 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
}
}
- wl_touch_release(backend->touch);
- backend->touch = NULL;
+ wl_touch_release(seat->touch);
+ seat->touch = NULL;
}
}
static void seat_handle_name(void *data, struct wl_seat *wl_seat,
const char *name) {
struct wlr_wl_backend *backend = data;
- assert(backend->seat == wl_seat);
- // Do we need to check if seatName was previously set for name change?
- free(backend->seat_name);
- backend->seat_name = strdup(name);
+ struct wlr_wl_seat *seat = backend_get_seat(backend, wl_seat);
+ free(seat->name);
+ seat->name = strdup(name);
}
const struct wl_seat_listener seat_listener = {
@@ -765,7 +801,5 @@ const struct wl_seat_listener seat_listener = {
};
struct wl_seat *wlr_wl_input_device_get_seat(struct wlr_input_device *wlr_dev) {
- struct wlr_wl_input_device *dev =
- get_wl_input_device_from_input_device(wlr_dev);
- return dev->backend->seat;
+ return input_device_get_seat(wlr_dev)->wl_seat;
}