From eb5b9cc6daa39f6e1bcafae074f832f07b5d0a19 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sun, 20 Aug 2017 07:59:03 +0200 Subject: [PATCH] xwayland: move & split internal header file --- examples/compositor.c | 6 ++-- include/wlr/xwayland.h | 6 ++-- xwayland/sockets.c | 4 +-- xwayland/sockets.h | 7 +++++ xwayland/xwayland.c | 28 ++++++++++++++++--- xwayland/xwm.c | 4 +-- .../xwayland/internals.h => xwayland/xwm.h | 3 -- 7 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 xwayland/sockets.h rename include/xwayland/internals.h => xwayland/xwm.h (95%) diff --git a/examples/compositor.c b/examples/compositor.c index e143099c..e0bafe60 100644 --- a/examples/compositor.c +++ b/examples/compositor.c @@ -36,7 +36,7 @@ struct sample_state { struct wlr_data_device_manager *data_device_manager; struct wl_resource *focus; struct wl_listener keyboard_bound; - struct wlr_xwayland wlr_xwayland; + struct wlr_xwayland *wlr_xwayland; int keymap_fd; size_t keymap_size; uint32_t serial; @@ -178,13 +178,13 @@ int main() { free(keymap); break; } - wlr_xwayland_init(&state.wlr_xwayland, compositor.display, state.wlr_compositor); + state.wlr_xwayland = wlr_xwayland_create(compositor.display, state.wlr_compositor); compositor.keyboard_key_cb = handle_keyboard_key; wl_display_run(compositor.display); - wlr_xwayland_finish(&state.wlr_xwayland); + wlr_xwayland_destroy(state.wlr_xwayland); close(state.keymap_fd); wlr_seat_destroy(state.wl_seat); wlr_data_device_manager_destroy(state.data_device_manager); diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index bbb315e2..61386700 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -20,8 +20,8 @@ struct wlr_xwayland { struct wlr_xwm *xwm; }; -void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland); -bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, - struct wl_display *wl_display, struct wlr_compositor *compositor); +void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland); +struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display, + struct wlr_compositor *compositor); #endif diff --git a/xwayland/sockets.c b/xwayland/sockets.c index 714969fe..ca46ec9f 100644 --- a/xwayland/sockets.c +++ b/xwayland/sockets.c @@ -12,7 +12,7 @@ #include #include #include "wlr/util/log.h" -#include "xwayland/internals.h" +#include "sockets.h" static const char *lock_fmt = "/tmp/.X%d-lock"; static const char *socket_dir = "/tmp/.X11-unix"; @@ -78,7 +78,7 @@ static bool open_sockets(int socks[2], int display) { return true; } -void unlink_sockets(int display) { +void unlink_display_sockets(int display) { char sun_path[64]; snprintf(sun_path, sizeof(sun_path), socket_fmt, display); diff --git a/xwayland/sockets.h b/xwayland/sockets.h new file mode 100644 index 00000000..73eb36e0 --- /dev/null +++ b/xwayland/sockets.h @@ -0,0 +1,7 @@ +#ifndef XWAYLAND_SOCKETS_H +#define XWAYLAND_SOCKETS_H + +void unlink_display_sockets(int display); +int open_display_sockets(int socks[2]); + +#endif diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index a7047369..764c0135 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -11,7 +11,8 @@ #include #include "wlr/util/log.h" #include "wlr/xwayland.h" -#include "xwayland/internals.h" +#include "sockets.h" +#include "xwm.h" static void safe_close(int fd) { if (fd >= 0) { @@ -84,6 +85,10 @@ static void exec_xwayland(struct wlr_xwayland *wlr_xwayland) { execvpe("Xwayland", argv, envp); } +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 wl_client *client = data; struct wlr_xwayland *wlr_xwayland = wl_container_of(client, wlr_xwayland, client); @@ -102,7 +107,7 @@ static struct wl_listener xwayland_destroy_listener = { .notify = xwayland_destroy_event, }; -void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { +static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { if (wlr_xwayland->client) { wl_list_remove(&xwayland_destroy_listener.link); @@ -122,7 +127,7 @@ void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { safe_close(wlr_xwayland->wm_fd[0]); safe_close(wlr_xwayland->wm_fd[1]); - unlink_sockets(wlr_xwayland->display); + unlink_display_sockets(wlr_xwayland->display); unsetenv("DISPLAY"); /* kill Xwayland process? */ } @@ -148,7 +153,7 @@ static int xserver_handle_ready(int signal_number, void *data) { return 1; } -bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, +static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, struct wl_display *wl_display, struct wlr_compositor *compositor) { memset(wlr_xwayland, 0, sizeof(struct wlr_xwayland)); wlr_xwayland->wl_display = wl_display; @@ -204,3 +209,18 @@ bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, return true; } + +void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland) { + wlr_xwayland_finish(wlr_xwayland); + free(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)) { + return wlr_xwayland; + } + free(wlr_xwayland); + return NULL; +} diff --git a/xwayland/xwm.c b/xwayland/xwm.c index af21c78d..26d86fb3 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -4,9 +4,7 @@ #include "wlr/util/log.h" #include "wlr/types/wlr_surface.h" #include "wlr/xwayland.h" -#include "xwayland/internals.h" - - +#include "xwm.h" static int x11_event_handler(int fd, uint32_t mask, void *data) { diff --git a/include/xwayland/internals.h b/xwayland/xwm.h similarity index 95% rename from include/xwayland/internals.h rename to xwayland/xwm.h index 97c7e31a..cfdd95f5 100644 --- a/include/xwayland/internals.h +++ b/xwayland/xwm.h @@ -77,9 +77,6 @@ struct wlr_xwm { xcb_window_t window; }; -void unlink_sockets(int display); -int open_display_sockets(int socks[2]); - void xwm_destroy(struct wlr_xwm *xwm); struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland);