xwayland: fix style issues
This commit is contained in:
parent
a39b091bd9
commit
3391e5b634
|
@ -10,7 +10,9 @@ struct wlr_compositor {
|
||||||
struct wl_list surfaces;
|
struct wl_list surfaces;
|
||||||
struct wl_listener destroy_surface_listener;
|
struct wl_listener destroy_surface_listener;
|
||||||
|
|
||||||
struct wl_signal create_surface_signal;
|
struct {
|
||||||
|
struct wl_signal create_surface;
|
||||||
|
} events;
|
||||||
};
|
};
|
||||||
|
|
||||||
void wlr_compositor_destroy(struct wlr_compositor *wlr_compositor);
|
void wlr_compositor_destroy(struct wlr_compositor *wlr_compositor);
|
||||||
|
|
|
@ -22,7 +22,7 @@ static void wl_compositor_create_surface(struct wl_client *client,
|
||||||
wl_resource_add_destroy_listener(surface_resource, &surface->compositor_listener);
|
wl_resource_add_destroy_listener(surface_resource, &surface->compositor_listener);
|
||||||
|
|
||||||
wl_list_insert(&compositor->surfaces, wl_resource_get_link(surface_resource));
|
wl_list_insert(&compositor->surfaces, wl_resource_get_link(surface_resource));
|
||||||
wl_signal_emit(&compositor->create_surface_signal, surface);
|
wl_signal_emit(&compositor->events.create_surface, surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wl_compositor_create_region(struct wl_client *client,
|
static void wl_compositor_create_region(struct wl_client *client,
|
||||||
|
@ -81,6 +81,6 @@ struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
|
||||||
compositor->renderer = renderer;
|
compositor->renderer = renderer;
|
||||||
wl_list_init(&compositor->wl_resources);
|
wl_list_init(&compositor->wl_resources);
|
||||||
wl_list_init(&compositor->surfaces);
|
wl_list_init(&compositor->surfaces);
|
||||||
wl_signal_init(&compositor->create_surface_signal);
|
wl_signal_init(&compositor->events.create_surface);
|
||||||
return compositor;
|
return compositor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#define _XOPEN_SOURCE 700
|
#define _XOPEN_SOURCE 700
|
||||||
#define _GNU_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
#include "wlr/util/log.h"
|
#include "wlr/util/log.h"
|
||||||
|
@ -28,6 +29,27 @@ static int unset_cloexec(int fd) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int fill_arg(char ***argv, const char *fmt, ...) {
|
||||||
|
int len;
|
||||||
|
char **cur_arg = *argv;
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, args) + 1;
|
||||||
|
va_end(args);
|
||||||
|
while (*cur_arg) {
|
||||||
|
cur_arg++;
|
||||||
|
}
|
||||||
|
*cur_arg = malloc(len);
|
||||||
|
if (!*cur_arg) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*argv = cur_arg;
|
||||||
|
va_start(args, fmt);
|
||||||
|
len = vsnprintf(*cur_arg, len, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
static void exec_xwayland(struct wlr_xwayland *wlr_xwayland) {
|
static void exec_xwayland(struct wlr_xwayland *wlr_xwayland) {
|
||||||
if (unset_cloexec(wlr_xwayland->x_fd[0]) ||
|
if (unset_cloexec(wlr_xwayland->x_fd[0]) ||
|
||||||
unset_cloexec(wlr_xwayland->x_fd[1]) ||
|
unset_cloexec(wlr_xwayland->x_fd[1]) ||
|
||||||
|
@ -39,27 +61,20 @@ static void exec_xwayland(struct wlr_xwayland *wlr_xwayland) {
|
||||||
/* Make Xwayland signal us when it's ready */
|
/* Make Xwayland signal us when it's ready */
|
||||||
signal(SIGUSR1, SIG_IGN);
|
signal(SIGUSR1, SIG_IGN);
|
||||||
|
|
||||||
char *argv[11] = { 0 };
|
char *argv[] = {
|
||||||
argv[0] = "Xwayland";
|
"Xwayland", NULL /* display, e.g. :1 */,
|
||||||
if (asprintf(&argv[1], ":%d", wlr_xwayland->display) < 0) {
|
"-rootless", "-terminate",
|
||||||
wlr_log_errno(L_ERROR, "asprintf failed");
|
"-listen", NULL /* x_fd[0] */,
|
||||||
exit(EXIT_FAILURE);
|
"-listen", NULL /* x_fd[1] */,
|
||||||
}
|
"-wm", NULL /* wm_fd[1] */,
|
||||||
argv[2] = "-rootless";
|
NULL };
|
||||||
argv[3] = "-terminate";
|
char **cur_arg = argv;
|
||||||
argv[4] = "-listen";
|
|
||||||
if (asprintf(&argv[5], "%d", wlr_xwayland->x_fd[0]) < 0) {
|
if (fill_arg(&cur_arg, ":%d", wlr_xwayland->display) < 0 ||
|
||||||
wlr_log_errno(L_ERROR, "asprintf failed");
|
fill_arg(&cur_arg, "%d", wlr_xwayland->x_fd[0]) < 0 ||
|
||||||
exit(EXIT_FAILURE);
|
fill_arg(&cur_arg, "%d", wlr_xwayland->x_fd[1]) < 0 ||
|
||||||
}
|
fill_arg(&cur_arg, "%d", wlr_xwayland->wm_fd[1]) < 0) {
|
||||||
argv[6] = "-listen";
|
wlr_log_errno(L_ERROR, "alloc/print failure");
|
||||||
if (asprintf(&argv[7], "%d", wlr_xwayland->x_fd[1]) < 0) {
|
|
||||||
wlr_log_errno(L_ERROR, "asprintf failed");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
argv[8] = "-wm";
|
|
||||||
if (asprintf(&argv[9], "%d", wlr_xwayland->wm_fd[1]) < 0) {
|
|
||||||
wlr_log_errno(L_ERROR, "asprintf failed");
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,12 +84,14 @@ static void exec_xwayland(struct wlr_xwayland *wlr_xwayland) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *envp[3] = { 0 };
|
if (clearenv()) {
|
||||||
if (asprintf(&envp[0], "XDG_RUNTIME_DIR=%s", xdg_runtime) < 0 ||
|
wlr_log_errno(L_ERROR, "clearenv failed");
|
||||||
asprintf(&envp[1], "WAYLAND_SOCKET=%d", wlr_xwayland->wl_fd[1]) < 0) {
|
|
||||||
wlr_log_errno(L_ERROR, "asprintf failed");
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
setenv("XDG_RUNTIME_DIR", xdg_runtime, true);
|
||||||
|
char wayland_socket_str[16];
|
||||||
|
snprintf(wayland_socket_str, sizeof(wayland_socket_str), "%d", wlr_xwayland->wl_fd[1]);
|
||||||
|
setenv("WAYLAND_SOCKET", wayland_socket_str, true);
|
||||||
|
|
||||||
wlr_log(L_INFO, "Xwayland :%d -rootless -terminate -listen %d -listen %d -wm %d",
|
wlr_log(L_INFO, "Xwayland :%d -rootless -terminate -listen %d -listen %d -wm %d",
|
||||||
wlr_xwayland->display, wlr_xwayland->x_fd[0], wlr_xwayland->x_fd[1],
|
wlr_xwayland->display, wlr_xwayland->x_fd[0], wlr_xwayland->x_fd[1],
|
||||||
|
@ -82,7 +99,7 @@ static void exec_xwayland(struct wlr_xwayland *wlr_xwayland) {
|
||||||
|
|
||||||
// TODO: close stdout/err depending on log level
|
// TODO: close stdout/err depending on log level
|
||||||
|
|
||||||
execvpe("Xwayland", argv, envp);
|
execvp("Xwayland", argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland,
|
static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland,
|
||||||
|
@ -108,7 +125,6 @@ static struct wl_listener xwayland_destroy_listener = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) {
|
static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) {
|
||||||
|
|
||||||
if (wlr_xwayland->client) {
|
if (wlr_xwayland->client) {
|
||||||
wl_list_remove(&xwayland_destroy_listener.link);
|
wl_list_remove(&xwayland_destroy_listener.link);
|
||||||
wl_client_destroy(wlr_xwayland->client);
|
wl_client_destroy(wlr_xwayland->client);
|
||||||
|
@ -118,6 +134,9 @@ static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) {
|
||||||
wl_event_source_remove(wlr_xwayland->sigusr1_source);
|
wl_event_source_remove(wlr_xwayland->sigusr1_source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: destroy all these windows, for now just cleanup
|
||||||
|
wl_list_init(&wlr_xwayland->displayable_windows);
|
||||||
|
|
||||||
xwm_destroy(wlr_xwayland->xwm);
|
xwm_destroy(wlr_xwayland->xwm);
|
||||||
|
|
||||||
safe_close(wlr_xwayland->x_fd[0]);
|
safe_close(wlr_xwayland->x_fd[0]);
|
||||||
|
@ -129,7 +148,9 @@ static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) {
|
||||||
|
|
||||||
unlink_display_sockets(wlr_xwayland->display);
|
unlink_display_sockets(wlr_xwayland->display);
|
||||||
unsetenv("DISPLAY");
|
unsetenv("DISPLAY");
|
||||||
/* kill Xwayland process? */
|
/* We do not kill the Xwayland process, it dies because of broken pipe
|
||||||
|
* after we close our side of the wm/wl fds. This is more reliable than
|
||||||
|
* trying to kill something that might no longer be Xwayland */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int xserver_handle_ready(int signal_number, void *data) {
|
static int xserver_handle_ready(int signal_number, void *data) {
|
||||||
|
@ -150,7 +171,7 @@ static int xserver_handle_ready(int signal_number, void *data) {
|
||||||
snprintf(display_name, sizeof(display_name), ":%d", wlr_xwayland->display);
|
snprintf(display_name, sizeof(display_name), ":%d", wlr_xwayland->display);
|
||||||
setenv("DISPLAY", display_name, true);
|
setenv("DISPLAY", display_name, true);
|
||||||
|
|
||||||
return 1;
|
return 1; /* wayland event loop dispatcher's count */
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland,
|
static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland,
|
||||||
|
|
|
@ -69,7 +69,6 @@ static bool xcb_call(struct wlr_xwm *xwm, const char *func, uint32_t line,
|
||||||
|
|
||||||
static void map_shell_surface(struct wlr_xwm *xwm, struct wlr_x11_window *window,
|
static void map_shell_surface(struct wlr_xwm *xwm, struct wlr_x11_window *window,
|
||||||
struct wlr_surface *surface) {
|
struct wlr_surface *surface) {
|
||||||
|
|
||||||
// get xcb geometry for depth = alpha channel
|
// get xcb geometry for depth = alpha channel
|
||||||
window->surface = surface->resource;
|
window->surface = surface->resource;
|
||||||
|
|
||||||
|
@ -207,6 +206,7 @@ static int x11_event_handler(int fd, uint32_t mask, void *data) {
|
||||||
default:
|
default:
|
||||||
wlr_log(L_DEBUG, "X11 event: %d",
|
wlr_log(L_DEBUG, "X11 event: %d",
|
||||||
event->response_type & XCB_EVENT_RESPONSE_TYPE_MASK);
|
event->response_type & XCB_EVENT_RESPONSE_TYPE_MASK);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,8 +214,7 @@ static int x11_event_handler(int fd, uint32_t mask, void *data) {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void create_surface_handler(struct wl_listener *listener, void *data)
|
static void create_surface_handler(struct wl_listener *listener, void *data) {
|
||||||
{
|
|
||||||
struct wlr_surface *surface = 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;
|
struct wlr_x11_window *window;
|
||||||
|
@ -272,8 +271,12 @@ static void xcb_init_wm(struct wlr_xwm *xwm) {
|
||||||
|
|
||||||
xwm->window = xcb_generate_id(xwm->xcb_conn);
|
xwm->window = xcb_generate_id(xwm->xcb_conn);
|
||||||
|
|
||||||
uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_PROPERTY_CHANGE,
|
uint32_t values[] = {
|
||||||
/* , xwm->cursor */ };
|
XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY |
|
||||||
|
XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
|
||||||
|
XCB_EVENT_MASK_PROPERTY_CHANGE,
|
||||||
|
/* xwm->cursor, */
|
||||||
|
};
|
||||||
XCB_CALL(xwm, xcb_change_window_attributes_checked(xwm->xcb_conn, xwm->screen->root,
|
XCB_CALL(xwm, xcb_change_window_attributes_checked(xwm->xcb_conn, xwm->screen->root,
|
||||||
XCB_CW_EVENT_MASK /* | XCB_CW_CURSOR */, values));
|
XCB_CW_EVENT_MASK /* | XCB_CW_CURSOR */, values));
|
||||||
XCB_CALL(xwm, xcb_composite_redirect_subwindows_checked(xwm->xcb_conn,
|
XCB_CALL(xwm, xcb_composite_redirect_subwindows_checked(xwm->xcb_conn,
|
||||||
|
@ -334,7 +337,7 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) {
|
||||||
xcb_init_wm(xwm);
|
xcb_init_wm(xwm);
|
||||||
|
|
||||||
xwm->surface_create_listener.notify = create_surface_handler;
|
xwm->surface_create_listener.notify = create_surface_handler;
|
||||||
wl_signal_add(&wlr_xwayland->compositor->create_surface_signal,
|
wl_signal_add(&wlr_xwayland->compositor->events.create_surface,
|
||||||
&xwm->surface_create_listener);
|
&xwm->surface_create_listener);
|
||||||
|
|
||||||
return xwm;
|
return xwm;
|
||||||
|
|
Loading…
Reference in New Issue