From 49a823d4c6b41723a9978c19d426e8ca4f5418d7 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 19 Aug 2017 17:59:31 +0200 Subject: Xwayland: first draft, just start server for now --- include/wlr/xwayland.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 include/wlr/xwayland.h (limited to 'include/wlr/xwayland.h') diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h new file mode 100644 index 00000000..ef9cc887 --- /dev/null +++ b/include/wlr/xwayland.h @@ -0,0 +1,17 @@ +#ifndef _WLR_XWAYLAND_H +#define _WLR_XWAYLAND_H + +struct wlr_xwayland { + pid_t pid; + int display; + int x_fd[2], wl_fd[2], wm_fd[2]; + struct wl_client *client; + struct wl_display *wl_display; + time_t server_start; +}; + +void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland); +bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, + struct wl_display *wl_display); + +#endif -- cgit v1.2.3 From b2bab1af5c34b785a9b08db04af1330e61dd210c Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 19 Aug 2017 21:25:26 +0200 Subject: xwayland: split xwm structure out, initial xwm.c --- examples/compositor.c | 2 +- include/wlr/xwayland.h | 11 ++++++- include/xwayland/internals.h | 16 ++++++++++ meson.build | 2 ++ xwayland/meson.build | 4 ++- xwayland/xwayland.c | 18 ++++++++++-- xwayland/xwm.c | 69 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 xwayland/xwm.c (limited to 'include/wlr/xwayland.h') diff --git a/examples/compositor.c b/examples/compositor.c index be9fc5ca..e143099c 100644 --- a/examples/compositor.c +++ b/examples/compositor.c @@ -178,7 +178,7 @@ int main() { free(keymap); break; } - wlr_xwayland_init(&state.wlr_xwayland, compositor.display); + wlr_xwayland_init(&state.wlr_xwayland, compositor.display, state.wlr_compositor); compositor.keyboard_key_cb = handle_keyboard_key; diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index ef9cc887..f61a90bd 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -1,5 +1,11 @@ #ifndef _WLR_XWAYLAND_H #define _WLR_XWAYLAND_H +#include +#include +#include +#include + +struct wlr_xwm; struct wlr_xwayland { pid_t pid; @@ -7,11 +13,14 @@ struct wlr_xwayland { int x_fd[2], wl_fd[2], wm_fd[2]; struct wl_client *client; struct wl_display *wl_display; + struct wlr_compositor *compositor; time_t server_start; + + 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 wl_display *wl_display, struct wlr_compositor *compositor); #endif diff --git a/include/xwayland/internals.h b/include/xwayland/internals.h index b91f7930..46158bd0 100644 --- a/include/xwayland/internals.h +++ b/include/xwayland/internals.h @@ -1,6 +1,22 @@ #ifndef XWAYLAND_INTERNALS_H #define XWAYLAND_INTERNALS_H +#include +#include +#include + +struct wlr_xwm { + struct wlr_xwayland *xwayland; + struct wl_event_source *event_source; + struct wl_listener surface_listener; + + xcb_connection_t *xcb_connection; + xcb_screen_t *xcb_screen; +}; 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); + #endif diff --git a/meson.build b/meson.build index b3706dbc..a7baacf9 100644 --- a/meson.build +++ b/meson.build @@ -32,6 +32,7 @@ libinput = dependency('libinput') xkbcommon = dependency('xkbcommon') udev = dependency('libudev') pixman = dependency('pixman-1') +xcb = dependency('xcb') libcap = dependency('libcap', required: false) systemd = dependency('libsystemd', required: false) math = cc.find_library('m', required: false) @@ -65,6 +66,7 @@ wlr_deps = [ xkbcommon, udev, pixman, + xcb, libcap, systemd, math, diff --git a/xwayland/meson.build b/xwayland/meson.build index d43ace9b..6f75e23a 100644 --- a/xwayland/meson.build +++ b/xwayland/meson.build @@ -1,5 +1,7 @@ lib_wlr_xwayland = static_library('wlr_xwayland', files( 'sockets.c', 'xwayland.c', + 'xwm.c', ), - include_directories: wlr_inc) + include_directories: wlr_inc, + dependencies: [wayland_server, xcb, pixman]) diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index 49173ace..e9bdfcc5 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -76,6 +76,8 @@ static void exec_xwayland(struct wlr_xwayland *wlr_xwayland) { wlr_xwayland->display, wlr_xwayland->x_fd[0], wlr_xwayland->x_fd[1], wlr_xwayland->wm_fd[1]); + // TODO: close stdout/err depending on log level + execvpe("Xwayland", argv, envp); } @@ -88,7 +90,8 @@ static void xwayland_destroy_event(struct wl_listener *listener, void *data) { wlr_xwayland_finish(wlr_xwayland); if (wlr_xwayland->server_start - time(NULL) > 5) { - wlr_xwayland_init(wlr_xwayland, wlr_xwayland->wl_display); + wlr_xwayland_init(wlr_xwayland, wlr_xwayland->wl_display, + wlr_xwayland->compositor); } } @@ -103,6 +106,8 @@ void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { wl_client_destroy(wlr_xwayland->client); } + 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]); @@ -116,8 +121,10 @@ void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { } bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, - struct wl_display *wl_display) { + struct wl_display *wl_display, struct wlr_compositor *compositor) { + memset(wlr_xwayland, 0, sizeof(struct wlr_xwayland)); 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; @@ -162,9 +169,16 @@ bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, if (!(wlr_xwayland->client = wl_client_create(wl_display, wlr_xwayland->wl_fd[0]))) { wlr_log_errno(L_ERROR, "wl_client_create failed"); wlr_xwayland_finish(wlr_xwayland); + return false; } wl_client_add_destroy_listener(wlr_xwayland->client, &xwayland_destroy_listener); + wlr_xwayland->xwm = xwm_create(wlr_xwayland); + if (!wlr_xwayland->xwm) { + wlr_xwayland_finish(wlr_xwayland); + return false; + } + return true; } diff --git a/xwayland/xwm.c b/xwayland/xwm.c new file mode 100644 index 00000000..d39527c5 --- /dev/null +++ b/xwayland/xwm.c @@ -0,0 +1,69 @@ +#include +#include "wlr/util/log.h" +#include "wlr/types/wlr_surface.h" +#include "wlr/xwayland.h" +#include "xwayland/internals.h" + +#define SEND_EVENT_MASK 0x80 +static int x11_event_handler(int fd, uint32_t mask, void *data) { + int count = 0; + xcb_generic_event_t *event; + struct wlr_xwayland *wlr_xwayland = data; + struct wlr_xwm *xwm = wlr_xwayland->xwm; + + while ((event = xcb_poll_for_event(xwm->xcb_connection))) { + wlr_log(L_DEBUG, "X11 event: %d", event->response_type & ~SEND_EVENT_MASK); + count++; + // TODO: actually do stuff! + } + return count; +} + +static void create_surface_handler(struct wl_listener *listener, void *data) +{ + struct wlr_surface *surface = data; + struct wlr_xwm *xwm = wl_container_of(listener, xwm, surface_listener); + + if (wl_resource_get_client(surface->resource) != xwm->xwayland->client) { + return; + } + + wlr_log(L_DEBUG, "new x11 surface: %p", surface); + + // TODO: look for unpaired window, and assign +} + +void xwm_destroy(struct wlr_xwm *xwm) { + if (xwm->event_source) { + wl_event_source_remove(xwm->event_source); + } + + free(xwm); +} + +struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { + struct wlr_xwm *xwm = calloc(1, sizeof(struct wlr_xwm)); + + xwm->xwayland = wlr_xwayland; + + xwm->xcb_connection = xcb_connect_to_fd(wlr_xwayland->wm_fd[0], NULL); + if (xcb_connection_has_error(xwm->xcb_connection)) { + return NULL; + } + + // TODO more xcb init + // xcb_prefetch_extension_data(xwm->xcb_connection, &xcb_composite_id); + + struct wl_event_loop *event_loop = wl_display_get_event_loop(wlr_xwayland->wl_display); + xwm->event_source = wl_event_loop_add_fd(event_loop, wlr_xwayland->wm_fd[0], + WL_EVENT_READABLE, x11_event_handler, wlr_xwayland); + // probably not needed + // wl_event_source_check(xwm->event_source); + + + xwm->surface_listener.notify = create_surface_handler; + //wl_signal_add(&wlr_xwayland->compositor->create_surface_signal, + // &xwm->surface_listener); + + return xwm; +} -- cgit v1.2.3 From 6eb20fb8d28749e0b710a54daa1b916080cf4ea1 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 19 Aug 2017 23:09:59 +0200 Subject: init xwm only once Xwayland server is ready --- include/wlr/xwayland.h | 1 + xwayland/sockets.c | 5 ++++- xwayland/xwayland.c | 35 +++++++++++++++++++++++++++-------- 3 files changed, 32 insertions(+), 9 deletions(-) (limited to 'include/wlr/xwayland.h') diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index f61a90bd..bbb315e2 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -16,6 +16,7 @@ struct wlr_xwayland { struct wlr_compositor *compositor; time_t server_start; + struct wl_event_source *sigusr1_source; struct wlr_xwm *xwm; }; diff --git a/xwayland/sockets.c b/xwayland/sockets.c index 868d6ada..714969fe 100644 --- a/xwayland/sockets.c +++ b/xwayland/sockets.c @@ -83,6 +83,9 @@ void unlink_sockets(int display) { snprintf(sun_path, sizeof(sun_path), socket_fmt, display); unlink(sun_path); + + snprintf(sun_path, sizeof(sun_path), lock_fmt, display); + unlink(sun_path); } int open_display_sockets(int socks[2]) { @@ -121,7 +124,7 @@ int open_display_sockets(int socks[2]) { } long int read_pid; read_pid = strtol(pid, &end_pid, 10); - if (read_pid < 0 || read_pid > INT32_MAX || end_pid != pid + sizeof(pid)) { + if (read_pid < 0 || read_pid > INT32_MAX || end_pid != pid + sizeof(pid) - 2) { continue; } errno = 0; diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index e9bdfcc5..e998db28 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -35,6 +35,9 @@ static void exec_xwayland(struct wlr_xwayland *wlr_xwayland) { exit(EXIT_FAILURE); } + /* Make Xwayland signal us when it's ready */ + signal(SIGUSR1, SIG_IGN); + char *argv[11] = { 0 }; argv[0] = "Xwayland"; if (asprintf(&argv[1], ":%d", wlr_xwayland->display) < 0) { @@ -106,6 +109,10 @@ void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { 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]); @@ -120,6 +127,24 @@ void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { /* kill Xwayland process? */ } +static int xserver_handle_ready(int signal_number, void *data) { + struct wlr_xwayland *wlr_xwayland = data; + + wlr_log(L_DEBUG, "Xserver is ready"); + + wlr_xwayland->xwm = xwm_create(wlr_xwayland); + if (!wlr_xwayland->xwm) { + wlr_xwayland_finish(wlr_xwayland); + return 1; + } + + char display_name[16]; + snprintf(display_name, sizeof(display_name), ":%d", wlr_xwayland->display); + setenv("DISPLAY", display_name, true); + + return 1; +} + 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)); @@ -161,9 +186,6 @@ bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, wlr_xwayland->x_fd[0] = wlr_xwayland->x_fd[1] = -1; wlr_xwayland->wl_fd[1] = wlr_xwayland->wm_fd[1] = -1; - char display_name[16]; - snprintf(display_name, sizeof(display_name), ":%d", wlr_xwayland->display); - setenv("DISPLAY", display_name, true); wlr_xwayland->server_start = time(NULL); if (!(wlr_xwayland->client = wl_client_create(wl_display, wlr_xwayland->wl_fd[0]))) { @@ -174,11 +196,8 @@ bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, wl_client_add_destroy_listener(wlr_xwayland->client, &xwayland_destroy_listener); - wlr_xwayland->xwm = xwm_create(wlr_xwayland); - if (!wlr_xwayland->xwm) { - wlr_xwayland_finish(wlr_xwayland); - return false; - } + 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); return true; } -- cgit v1.2.3 From eb5b9cc6daa39f6e1bcafae074f832f07b5d0a19 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sun, 20 Aug 2017 07:59:03 +0200 Subject: xwayland: move & split internal header file --- examples/compositor.c | 6 ++-- include/wlr/xwayland.h | 6 ++-- include/xwayland/internals.h | 86 -------------------------------------------- xwayland/sockets.c | 4 +-- xwayland/sockets.h | 7 ++++ xwayland/xwayland.c | 28 ++++++++++++--- xwayland/xwm.c | 4 +-- xwayland/xwm.h | 83 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 123 insertions(+), 101 deletions(-) delete mode 100644 include/xwayland/internals.h create mode 100644 xwayland/sockets.h create mode 100644 xwayland/xwm.h (limited to 'include/wlr/xwayland.h') 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/include/xwayland/internals.h b/include/xwayland/internals.h deleted file mode 100644 index 97c7e31a..00000000 --- a/include/xwayland/internals.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef XWAYLAND_INTERNALS_H -#define XWAYLAND_INTERNALS_H -#include -#include -#include - -/* wlc's atom list: - WL_SURFACE_ID, - WM_DELETE_WINDOW, - WM_TAKE_FOCUS, - WM_PROTOCOLS, - WM_NORMAL_HINTS, - MOTIF_WM_HINTS, - TEXT, - UTF8_STRING, - CLIPBOARD, - CLIPBOARD_MANAGER, - TARGETS, - PRIMARY, - WM_S0, - STRING, - WLC_SELECTION, - NET_WM_S0, - NET_WM_PID, - NET_WM_NAME, - NET_WM_STATE, - NET_WM_STATE_FULLSCREEN, - NET_WM_STATE_MODAL, - NET_WM_STATE_ABOVE, - NET_SUPPORTED, - NET_SUPPORTING_WM_CHECK, - NET_WM_WINDOW_TYPE, - NET_WM_WINDOW_TYPE_DESKTOP, - NET_WM_WINDOW_TYPE_DOCK, - NET_WM_WINDOW_TYPE_TOOLBAR, - NET_WM_WINDOW_TYPE_MENU, - NET_WM_WINDOW_TYPE_UTILITY, - NET_WM_WINDOW_TYPE_SPLASH, - NET_WM_WINDOW_TYPE_DIALOG, - NET_WM_WINDOW_TYPE_DROPDOWN_MENU, - NET_WM_WINDOW_TYPE_POPUP_MENU, - NET_WM_WINDOW_TYPE_TOOLTIP, - NET_WM_WINDOW_TYPE_NOTIFICATION, - NET_WM_WINDOW_TYPE_COMBO, - NET_WM_WINDOW_TYPE_DND, - NET_WM_WINDOW_TYPE_NORMAL, - */ - -enum atom_name { - WL_SURFACE_ID, - WM_PROTOCOLS, - WM_S0, - NET_SUPPORTED, - NET_WM_S0, - NET_WM_STATE, - ATOM_LAST -}; - -static const char * const atom_map[ATOM_LAST] = { - "WL_SURFACE_ID", - "WM_PROTOCOLS", - "WM_S0", - "_NET_SUPPORTED", - "_NET_WM_S0", - "_NET_WM_STATE", -}; - - -struct wlr_xwm { - struct wlr_xwayland *xwayland; - struct wl_event_source *event_source; - struct wl_listener surface_listener; - - xcb_atom_t atoms[ATOM_LAST]; - xcb_connection_t *xcb_conn; - xcb_screen_t *screen; - 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); - -#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/xwayland/xwm.h b/xwayland/xwm.h new file mode 100644 index 00000000..cfdd95f5 --- /dev/null +++ b/xwayland/xwm.h @@ -0,0 +1,83 @@ +#ifndef XWAYLAND_INTERNALS_H +#define XWAYLAND_INTERNALS_H +#include +#include +#include + +/* wlc's atom list: + WL_SURFACE_ID, + WM_DELETE_WINDOW, + WM_TAKE_FOCUS, + WM_PROTOCOLS, + WM_NORMAL_HINTS, + MOTIF_WM_HINTS, + TEXT, + UTF8_STRING, + CLIPBOARD, + CLIPBOARD_MANAGER, + TARGETS, + PRIMARY, + WM_S0, + STRING, + WLC_SELECTION, + NET_WM_S0, + NET_WM_PID, + NET_WM_NAME, + NET_WM_STATE, + NET_WM_STATE_FULLSCREEN, + NET_WM_STATE_MODAL, + NET_WM_STATE_ABOVE, + NET_SUPPORTED, + NET_SUPPORTING_WM_CHECK, + NET_WM_WINDOW_TYPE, + NET_WM_WINDOW_TYPE_DESKTOP, + NET_WM_WINDOW_TYPE_DOCK, + NET_WM_WINDOW_TYPE_TOOLBAR, + NET_WM_WINDOW_TYPE_MENU, + NET_WM_WINDOW_TYPE_UTILITY, + NET_WM_WINDOW_TYPE_SPLASH, + NET_WM_WINDOW_TYPE_DIALOG, + NET_WM_WINDOW_TYPE_DROPDOWN_MENU, + NET_WM_WINDOW_TYPE_POPUP_MENU, + NET_WM_WINDOW_TYPE_TOOLTIP, + NET_WM_WINDOW_TYPE_NOTIFICATION, + NET_WM_WINDOW_TYPE_COMBO, + NET_WM_WINDOW_TYPE_DND, + NET_WM_WINDOW_TYPE_NORMAL, + */ + +enum atom_name { + WL_SURFACE_ID, + WM_PROTOCOLS, + WM_S0, + NET_SUPPORTED, + NET_WM_S0, + NET_WM_STATE, + ATOM_LAST +}; + +static const char * const atom_map[ATOM_LAST] = { + "WL_SURFACE_ID", + "WM_PROTOCOLS", + "WM_S0", + "_NET_SUPPORTED", + "_NET_WM_S0", + "_NET_WM_STATE", +}; + + +struct wlr_xwm { + struct wlr_xwayland *xwayland; + struct wl_event_source *event_source; + struct wl_listener surface_listener; + + xcb_atom_t atoms[ATOM_LAST]; + xcb_connection_t *xcb_conn; + xcb_screen_t *screen; + xcb_window_t window; +}; + +void xwm_destroy(struct wlr_xwm *xwm); +struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland); + +#endif -- cgit v1.2.3 From 1458a95e65248fede646051d2607c4553e8dcb0c Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sun, 20 Aug 2017 14:18:29 +0200 Subject: example compositor: loop through xwayland surfaces --- examples/compositor.c | 10 +++++++--- include/wlr/xwayland.h | 22 ++++++++++++++++++---- xwayland/xwayland.c | 1 + xwayland/xwm.c | 13 ++++++------- xwayland/xwm.h | 14 -------------- 5 files changed, 32 insertions(+), 28 deletions(-) (limited to 'include/wlr/xwayland.h') diff --git a/examples/compositor.c b/examples/compositor.c index e0bafe60..024324cd 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 *xwayland; int keymap_fd; size_t keymap_size; uint32_t serial; @@ -85,6 +85,10 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wl_list_for_each(xdg_surface, &sample->xdg_shell->surfaces, link) { output_frame_handle_surface(sample, wlr_output, ts, xdg_surface->surface); } + struct wlr_x11_window *x11_window; + wl_list_for_each(x11_window, &sample->xwayland->displayable_windows, link) { + output_frame_handle_surface(sample, wlr_output, ts, x11_window->surface); + } wlr_renderer_end(sample->renderer); wlr_output_swap_buffers(wlr_output); @@ -178,13 +182,13 @@ int main() { free(keymap); break; } - state.wlr_xwayland = wlr_xwayland_create(compositor.display, state.wlr_compositor); + state.xwayland = wlr_xwayland_create(compositor.display, state.wlr_compositor); compositor.keyboard_key_cb = handle_keyboard_key; wl_display_run(compositor.display); - wlr_xwayland_destroy(state.wlr_xwayland); + wlr_xwayland_destroy(state.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 61386700..4d1a726d 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -4,20 +4,34 @@ #include #include #include +#include struct wlr_xwm; struct wlr_xwayland { - pid_t pid; - int display; - int x_fd[2], wl_fd[2], wm_fd[2]; - struct wl_client *client; + pid_t pid; + int display; + int x_fd[2], wl_fd[2], wm_fd[2]; + struct wl_client *client; struct wl_display *wl_display; struct wlr_compositor *compositor; time_t server_start; struct wl_event_source *sigusr1_source; struct wlr_xwm *xwm; + struct wl_list displayable_windows; +}; + +struct wlr_x11_window { + xcb_window_t window_id; + uint32_t surface_id; + struct wl_list link; + + struct wl_resource *surface; + struct wl_listener surface_destroy_listener; + int16_t x, y; + uint16_t width, height; + bool override_redirect; }; void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland); diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index 764c0135..aa1c3f96 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -161,6 +161,7 @@ static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, 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_list_init(&wlr_xwayland->displayable_windows); wlr_xwayland->display = open_display_sockets(wlr_xwayland->x_fd); if (wlr_xwayland->display < 0) { diff --git a/xwayland/xwm.c b/xwayland/xwm.c index b9653f14..bcc5ea05 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -19,7 +19,7 @@ static struct wlr_x11_window *lookup_window(struct wl_list *list, xcb_window_t w } static struct wlr_x11_window *lookup_window_any(struct wlr_xwm *xwm, xcb_window_t window_id) { struct wlr_x11_window *window; - if ((window = lookup_window(&xwm->paired_windows, window_id)) || + if ((window = lookup_window(&xwm->xwayland->displayable_windows, window_id)) || (window = lookup_window(&xwm->unpaired_windows, window_id)) || (window = lookup_window(&xwm->new_windows, window_id))) { return window; @@ -71,10 +71,10 @@ static void map_shell_surface(struct wlr_xwm *xwm, struct wlr_x11_window *window struct wlr_surface *surface) { // get xcb geometry for depth = alpha channel - // TODO link to compositor somehow + window->surface = surface->resource; wl_list_remove(&window->link); - wl_list_insert(&xwm->paired_windows, &window->link); + wl_list_insert(&xwm->xwayland->displayable_windows, &window->link); } /* xcb event handlers */ @@ -96,7 +96,7 @@ static void handle_destroy_notify(struct wlr_xwm *xwm, xcb_destroy_notify_event_ static void handle_configure_request(struct wlr_xwm *xwm, xcb_configure_request_event_t *ev) { struct wlr_x11_window *window; wlr_log(L_DEBUG, "XCB_CONFIGURE_REQUEST (%u) [%ux%u+%d,%d]", ev->window, - ev->width, ev->height, ev->x, ev->y); + ev->width, ev->height, ev->x, ev->y); if (!(window = lookup_window_any(xwm, ev->window))) { return; } @@ -211,7 +211,7 @@ static int x11_event_handler(int fd, uint32_t mask, void *data) { static void create_surface_handler(struct wl_listener *listener, void *data) { struct wlr_surface *surface = data; - struct wlr_xwm *xwm = wl_container_of(listener, xwm, surface_create_listener); + struct wlr_xwm *xwm = wl_container_of(listener, xwm, surface_create_listener); struct wlr_x11_window *window; uint32_t surface_id; @@ -308,7 +308,6 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { xwm->xwayland = wlr_xwayland; wl_list_init(&xwm->new_windows); wl_list_init(&xwm->unpaired_windows); - wl_list_init(&xwm->paired_windows); xwm->xcb_conn = xcb_connect_to_fd(wlr_xwayland->wm_fd[0], NULL); if ((rc = xcb_connection_has_error(xwm->xcb_conn))) { @@ -317,7 +316,7 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { return NULL; } - struct wl_event_loop *event_loop = wl_display_get_event_loop(wlr_xwayland->wl_display); + struct wl_event_loop *event_loop = wl_display_get_event_loop(wlr_xwayland->wl_display); xwm->event_source = wl_event_loop_add_fd(event_loop, wlr_xwayland->wm_fd[0], WL_EVENT_READABLE, x11_event_handler, xwm); // probably not needed diff --git a/xwayland/xwm.h b/xwayland/xwm.h index 51d60395..235145b9 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -1,6 +1,5 @@ #ifndef XWAYLAND_INTERNALS_H #define XWAYLAND_INTERNALS_H -#include #include #include @@ -65,18 +64,6 @@ static const char * const atom_map[ATOM_LAST] = { "_NET_WM_STATE", }; -struct wlr_x11_window { - xcb_window_t window_id; - uint32_t surface_id; - struct wl_list link; - - struct wl_resource *surface; - struct wl_listener surface_destroy_listener; - int16_t x, y; - uint16_t width, height; - bool override_redirect; -}; - struct wlr_xwm { struct wlr_xwayland *xwayland; struct wl_event_source *event_source; @@ -89,7 +76,6 @@ struct wlr_xwm { struct wl_list new_windows; struct wl_list unpaired_windows; - struct wl_list paired_windows; }; void xwm_destroy(struct wlr_xwm *xwm); -- cgit v1.2.3 From fd3ad3b9e42d9f2d1196a5c36b07763283729053 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 23 Aug 2017 23:11:44 +0200 Subject: xwayland: fix shutdown caused by Xwayland/client stop --- include/wlr/xwayland.h | 1 + xwayland/xwayland.c | 12 ++++-------- xwayland/xwm.c | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) (limited to 'include/wlr/xwayland.h') diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 4d1a726d..804e9962 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -18,6 +18,7 @@ struct wlr_xwayland { time_t server_start; struct wl_event_source *sigusr1_source; + struct wl_listener destroy_listener; struct wlr_xwm *xwm; struct wl_list displayable_windows; }; diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index a28073d8..9c0b1839 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -107,8 +107,7 @@ static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, 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); + struct wlr_xwayland *wlr_xwayland = wl_container_of(listener, wlr_xwayland, destroy_listener); /* don't call client destroy */ wlr_xwayland->client = NULL; @@ -120,13 +119,9 @@ static void xwayland_destroy_event(struct wl_listener *listener, void *data) { } } -static struct wl_listener xwayland_destroy_listener = { - .notify = xwayland_destroy_event, -}; - static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { if (wlr_xwayland->client) { - wl_list_remove(&xwayland_destroy_listener.link); + wl_list_remove(&wlr_xwayland->destroy_listener.link); wl_client_destroy(wlr_xwayland->client); } @@ -224,7 +219,8 @@ static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, return false; } - wl_client_add_destroy_listener(wlr_xwayland->client, &xwayland_destroy_listener); + wlr_xwayland->destroy_listener.notify = xwayland_destroy_event; + wl_client_add_destroy_listener(wlr_xwayland->client, &wlr_xwayland->destroy_listener); 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); diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 02794e72..0e161330 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -240,7 +240,7 @@ static void create_surface_handler(struct wl_listener *listener, void *data) { } static void xcb_get_resources(struct wlr_xwm *xwm) { - int i; + size_t i; xcb_intern_atom_cookie_t cookies[ATOM_LAST]; for (i = 0; i < ATOM_LAST; i++) { -- cgit v1.2.3