aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/rootston/seat.h2
-rw-r--r--include/wlr/types/wlr_seat.h2
-rw-r--r--include/wlr/xwayland.h5
-rw-r--r--include/wlr/xwm.h1
-rw-r--r--rootston/seat.c28
-rw-r--r--types/wlr_seat.c4
-rw-r--r--xwayland/selection.c23
-rw-r--r--xwayland/xwayland.c37
-rw-r--r--xwayland/xwm.c10
9 files changed, 97 insertions, 15 deletions
diff --git a/include/rootston/seat.h b/include/rootston/seat.h
index 7822bb70..cf5dd3b2 100644
--- a/include/rootston/seat.h
+++ b/include/rootston/seat.h
@@ -21,6 +21,8 @@ struct roots_seat {
struct wl_list pointers;
struct wl_list touch;
struct wl_list tablet_tools;
+
+ struct wl_listener seat_destroy;
};
struct roots_seat_view {
diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h
index f7dea52f..e049d4c7 100644
--- a/include/wlr/types/wlr_seat.h
+++ b/include/wlr/types/wlr_seat.h
@@ -207,6 +207,8 @@ struct wlr_seat {
struct wl_signal selection;
struct wl_signal primary_selection;
+
+ struct wl_signal destroy;
} events;
void *data;
diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h
index 8d71a7ab..b6671de1 100644
--- a/include/wlr/xwayland.h
+++ b/include/wlr/xwayland.h
@@ -22,7 +22,6 @@ struct wlr_xwayland {
struct wl_client *client;
struct wl_display *wl_display;
struct wlr_compositor *compositor;
- struct wlr_seat *seat;
time_t server_start;
struct wl_event_source *sigusr1_source;
@@ -31,6 +30,10 @@ struct wlr_xwayland {
struct wlr_xwm *xwm;
struct wlr_xwayland_cursor *cursor;
+ /* Anything above seat is reset on Xwayland restart, rest is conserved */
+ struct wlr_seat *seat;
+ struct wl_listener seat_destroy;
+
struct {
struct wl_signal ready;
struct wl_signal new_surface;
diff --git a/include/wlr/xwm.h b/include/wlr/xwm.h
index cbc2f132..35c43b18 100644
--- a/include/wlr/xwm.h
+++ b/include/wlr/xwm.h
@@ -108,6 +108,7 @@ void xwm_set_cursor(struct wlr_xwm *xwm, const uint8_t *pixels, uint32_t stride,
int xwm_handle_selection_event(struct wlr_xwm *xwm, xcb_generic_event_t *event);
void xwm_selection_init(struct wlr_xwm *xwm);
+void xwm_selection_finish(struct wlr_xwm *xwm);
void xwm_set_seat(struct wlr_xwm *xwm, struct wlr_seat *seat);
diff --git a/rootston/seat.c b/rootston/seat.c
index c2c7e3ea..2728ca96 100644
--- a/rootston/seat.c
+++ b/rootston/seat.c
@@ -220,6 +220,27 @@ static void roots_seat_init_cursor(struct roots_seat *seat) {
seat->cursor->request_set_cursor.notify = handle_request_set_cursor;
}
+static void seat_view_destroy(struct roots_seat_view *seat_view);
+
+static void roots_seat_handle_seat_destroy(struct wl_listener *listener,
+ void *data) {
+ struct roots_seat *seat =
+ wl_container_of(listener, seat, seat_destroy);
+
+ // TODO: probably more to be freed here
+ wl_list_remove(&seat->seat_destroy.link);
+
+ struct roots_seat_view *view, *nview;
+ wl_list_for_each_safe(view, nview, &seat->views, link) {
+ seat_view_destroy(view);
+ }
+}
+
+void roots_seat_destroy(struct roots_seat *seat) {
+ roots_seat_handle_seat_destroy(&seat->seat_destroy, seat->seat);
+ wlr_seat_destroy(seat->seat);
+}
+
struct roots_seat *roots_seat_create(struct roots_input *input, char *name) {
struct roots_seat *seat = calloc(1, sizeof(struct roots_seat));
if (!seat) {
@@ -254,11 +275,10 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) {
wl_list_insert(&input->seats, &seat->link);
- return seat;
-}
+ seat->seat_destroy.notify = roots_seat_handle_seat_destroy;
+ wl_signal_add(&seat->seat->events.destroy, &seat->seat_destroy);
-void roots_seat_destroy(struct roots_seat *seat) {
- // TODO
+ return seat;
}
static void seat_add_keyboard(struct roots_seat *seat,
diff --git a/types/wlr_seat.c b/types/wlr_seat.c
index 2a79f784..f9e2db5f 100644
--- a/types/wlr_seat.c
+++ b/types/wlr_seat.c
@@ -348,6 +348,8 @@ void wlr_seat_destroy(struct wlr_seat *wlr_seat) {
return;
}
+ wl_signal_emit(&wlr_seat->events.destroy, wlr_seat);
+
wl_list_remove(&wlr_seat->display_destroy.link);
struct wlr_seat_client *client, *tmp;
@@ -453,6 +455,8 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
wl_signal_init(&wlr_seat->events.touch_grab_begin);
wl_signal_init(&wlr_seat->events.touch_grab_end);
+ wl_signal_init(&wlr_seat->events.destroy);
+
wlr_seat->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &wlr_seat->display_destroy);
diff --git a/xwayland/selection.c b/xwayland/selection.c
index 00e45182..65599145 100644
--- a/xwayland/selection.c
+++ b/xwayland/selection.c
@@ -826,6 +826,29 @@ void xwm_selection_init(struct wlr_xwm *xwm) {
selection_init(xwm, &xwm->primary_selection, xwm->atoms[PRIMARY]);
}
+void xwm_selection_finish(struct wlr_xwm *xwm) {
+ if (!xwm) {
+ return;
+ }
+ if (xwm->selection_window) {
+ xcb_destroy_window(xwm->xcb_conn, xwm->selection_window);
+ }
+ if (xwm->seat) {
+ if (xwm->seat->selection_source &&
+ xwm->seat->selection_source->cancel == data_source_cancel) {
+ wlr_seat_set_selection(xwm->seat, NULL,
+ wl_display_next_serial(xwm->xwayland->wl_display));
+ }
+ if (xwm->seat->primary_selection_source &&
+ xwm->seat->primary_selection_source->cancel == primary_selection_source_cancel) {
+ wlr_seat_set_primary_selection(xwm->seat, NULL,
+ wl_display_next_serial(xwm->xwayland->wl_display));
+ }
+ wlr_xwayland_set_seat(xwm->xwayland, NULL);
+ }
+
+}
+
static void xwm_selection_set_owner(struct wlr_xwm_selection *selection,
bool set) {
if (set) {
diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c
index 6dc71689..6c700cc5 100644
--- a/xwayland/xwayland.c
+++ b/xwayland/xwayland.c
@@ -162,7 +162,7 @@ static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) {
*/
}
-static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland,
+static bool wlr_xwayland_start(struct wlr_xwayland *wlr_xwayland,
struct wl_display *wl_display, struct wlr_compositor *compositor);
static void handle_client_destroy(struct wl_listener *listener, void *data) {
@@ -177,7 +177,7 @@ static void handle_client_destroy(struct wl_listener *listener, void *data) {
if (time(NULL) - wlr_xwayland->server_start > 5) {
wlr_log(L_INFO, "Restarting Xwayland");
- wlr_xwayland_init(wlr_xwayland, wlr_xwayland->wl_display,
+ wlr_xwayland_start(wlr_xwayland, wlr_xwayland->wl_display,
wlr_xwayland->compositor);
}
}
@@ -238,20 +238,20 @@ static int xserver_handle_ready(int signal_number, void *data) {
setenv("DISPLAY", display_name, true);
wl_signal_emit(&wlr_xwayland->events.ready, wlr_xwayland);
+ /* ready is a one-shot signal, fire and forget */
+ wl_signal_init(&wlr_xwayland->events.ready);
return 1; /* wayland event loop dispatcher's count */
}
-static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland,
+static bool wlr_xwayland_start(struct wlr_xwayland *wlr_xwayland,
struct wl_display *wl_display, struct wlr_compositor *compositor) {
- memset(wlr_xwayland, 0, sizeof(struct wlr_xwayland));
+ memset(wlr_xwayland, 0, offsetof(struct wlr_xwayland, seat));
wlr_xwayland->wl_display = wl_display;
wlr_xwayland->compositor = compositor;
wlr_xwayland->x_fd[0] = wlr_xwayland->x_fd[1] = -1;
wlr_xwayland->wl_fd[0] = wlr_xwayland->wl_fd[1] = -1;
wlr_xwayland->wm_fd[0] = wlr_xwayland->wm_fd[1] = -1;
- wl_signal_init(&wlr_xwayland->events.new_surface);
- wl_signal_init(&wlr_xwayland->events.ready);
wlr_xwayland->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(wl_display, &wlr_xwayland->display_destroy);
@@ -336,6 +336,7 @@ static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland,
}
void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland) {
+ wlr_xwayland_set_seat(wlr_xwayland, NULL);
wlr_xwayland_finish(wlr_xwayland);
free(wlr_xwayland);
}
@@ -343,7 +344,10 @@ void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland) {
struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display,
struct wlr_compositor *compositor) {
struct wlr_xwayland *wlr_xwayland = calloc(1, sizeof(struct wlr_xwayland));
- if (wlr_xwayland_init(wlr_xwayland, wl_display, compositor)) {
+
+ wl_signal_init(&wlr_xwayland->events.new_surface);
+ wl_signal_init(&wlr_xwayland->events.ready);
+ if (wlr_xwayland_start(wlr_xwayland, wl_display, compositor)) {
return wlr_xwayland;
}
free(wlr_xwayland);
@@ -373,11 +377,30 @@ void wlr_xwayland_set_cursor(struct wlr_xwayland *wlr_xwayland,
wlr_xwayland->cursor->hotspot_y = hotspot_y;
}
+static void wlr_xwayland_handle_seat_destroy(struct wl_listener *listener,
+ void *data) {
+ struct wlr_xwayland *xwayland =
+ wl_container_of(listener, xwayland, seat_destroy);
+
+ wlr_xwayland_set_seat(xwayland, NULL);
+}
+
void wlr_xwayland_set_seat(struct wlr_xwayland *xwayland,
struct wlr_seat *seat) {
+ if (xwayland->seat) {
+ wl_list_remove(&xwayland->seat_destroy.link);
+ }
+
xwayland->seat = seat;
if (xwayland->xwm) {
xwm_set_seat(xwayland->xwm, seat);
}
+
+ if (seat == NULL) {
+ return;
+ }
+
+ xwayland->seat_destroy.notify = wlr_xwayland_handle_seat_destroy;
+ wl_signal_add(&seat->events.destroy, &xwayland->seat_destroy);
}
diff --git a/xwayland/xwm.c b/xwayland/xwm.c
index 849acff8..53aac6a4 100644
--- a/xwayland/xwm.c
+++ b/xwayland/xwm.c
@@ -1092,9 +1092,7 @@ void xwm_destroy(struct wlr_xwm *xwm) {
if (!xwm) {
return;
}
- if (xwm->selection_window) {
- xcb_destroy_window(xwm->xcb_conn, xwm->selection_window);
- }
+ xwm_selection_finish(xwm);
if (xwm->cursor) {
xcb_free_cursor(xwm->xcb_conn, xwm->cursor);
}
@@ -1256,6 +1254,10 @@ static void xwm_get_render_format(struct wlr_xwm *xwm) {
xcb_render_query_pict_formats(xwm->xcb_conn);
xcb_render_query_pict_formats_reply_t *reply =
xcb_render_query_pict_formats_reply(xwm->xcb_conn, cookie, NULL);
+ if (!reply) {
+ wlr_log(L_ERROR, "Did not get any reply from xcb_render_query_pict_formats");
+ return;
+ }
xcb_render_pictforminfo_iterator_t iter =
xcb_render_query_pict_formats_formats_iterator(reply);
xcb_render_pictforminfo_t *format = NULL;
@@ -1270,10 +1272,12 @@ static void xwm_get_render_format(struct wlr_xwm *xwm) {
if (format == NULL) {
wlr_log(L_DEBUG, "No 32 bit render format");
+ free(reply);
return;
}
xwm->render_format_id = format->id;
+ free(reply);
}
void xwm_set_cursor(struct wlr_xwm *xwm, const uint8_t *pixels, uint32_t stride,