diff options
Diffstat (limited to 'xwayland/xwayland.c')
-rw-r--r-- | xwayland/xwayland.c | 75 |
1 files changed, 51 insertions, 24 deletions
diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index c884dc63..6dc71689 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -125,38 +125,25 @@ static void exec_xwayland(struct wlr_xwayland *wlr_xwayland) { execvp("Xwayland", argv); } -static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, - struct wl_display *wl_display, struct wlr_compositor *compositor); -static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland); - -static void xwayland_destroy_event(struct wl_listener *listener, void *data) { - struct wlr_xwayland *wlr_xwayland = wl_container_of(listener, wlr_xwayland, destroy_listener); - - /* don't call client destroy */ - wlr_xwayland->client = NULL; - wl_list_remove(&wlr_xwayland->destroy_listener.link); - wlr_xwayland_finish(wlr_xwayland); - - if (time(NULL) - wlr_xwayland->server_start > 5) { - wlr_xwayland_init(wlr_xwayland, wlr_xwayland->wl_display, - wlr_xwayland->compositor); - } -} - static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { if (!wlr_xwayland || wlr_xwayland->display == -1) { return; } + + if (wlr_xwayland->cursor != NULL) { + free(wlr_xwayland->cursor); + } + + xwm_destroy(wlr_xwayland->xwm); + if (wlr_xwayland->client) { - wl_list_remove(&wlr_xwayland->destroy_listener.link); + wl_list_remove(&wlr_xwayland->client_destroy.link); wl_client_destroy(wlr_xwayland->client); } if (wlr_xwayland->sigusr1_source) { wl_event_source_remove(wlr_xwayland->sigusr1_source); } - xwm_destroy(wlr_xwayland->xwm); - safe_close(wlr_xwayland->x_fd[0]); safe_close(wlr_xwayland->x_fd[1]); safe_close(wlr_xwayland->wl_fd[0]); @@ -164,6 +151,8 @@ static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { safe_close(wlr_xwayland->wm_fd[0]); safe_close(wlr_xwayland->wm_fd[1]); + wl_list_remove(&wlr_xwayland->display_destroy.link); + unlink_display_sockets(wlr_xwayland->display); wlr_xwayland->display = -1; unsetenv("DISPLAY"); @@ -173,6 +162,39 @@ static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { */ } +static bool wlr_xwayland_init(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) { + struct wlr_xwayland *wlr_xwayland = + wl_container_of(listener, wlr_xwayland, client_destroy); + + // Don't call client destroy: it's being destroyed already + wlr_xwayland->client = NULL; + wl_list_remove(&wlr_xwayland->client_destroy.link); + + wlr_xwayland_finish(wlr_xwayland); + + 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->compositor); + } +} + +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_xwayland *wlr_xwayland = + wl_container_of(listener, wlr_xwayland, display_destroy); + + // Don't call client destroy: the display is being destroyed, it's too late + if (wlr_xwayland->client) { + wlr_xwayland->client = NULL; + wl_list_remove(&wlr_xwayland->client_destroy.link); + } + + wlr_xwayland_destroy(wlr_xwayland); +} + static int xserver_handle_ready(int signal_number, void *data) { struct wlr_xwayland *wlr_xwayland = data; @@ -231,6 +253,9 @@ static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, 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); + wlr_xwayland->display = open_display_sockets(wlr_xwayland->x_fd); if (wlr_xwayland->display < 0) { wlr_xwayland_finish(wlr_xwayland); @@ -256,11 +281,13 @@ static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, wlr_xwayland->wl_fd[0] = -1; /* not ours anymore */ - wlr_xwayland->destroy_listener.notify = xwayland_destroy_event; - wl_client_add_destroy_listener(wlr_xwayland->client, &wlr_xwayland->destroy_listener); + wlr_xwayland->client_destroy.notify = handle_client_destroy; + wl_client_add_destroy_listener(wlr_xwayland->client, + &wlr_xwayland->client_destroy); struct wl_event_loop *loop = wl_display_get_event_loop(wl_display); - wlr_xwayland->sigusr1_source = wl_event_loop_add_signal(loop, SIGUSR1, xserver_handle_ready, wlr_xwayland); + wlr_xwayland->sigusr1_source = wl_event_loop_add_signal(loop, SIGUSR1, + xserver_handle_ready, wlr_xwayland); if ((wlr_xwayland->pid = fork()) == 0) { /* Double-fork, but we need to forward SIGUSR1 once Xserver(1) |