xwayland: move & split internal header file

This commit is contained in:
Dominique Martinet 2017-08-20 07:59:03 +02:00
parent fa0e1015c6
commit eb5b9cc6da
7 changed files with 40 additions and 18 deletions

View File

@ -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);

View File

@ -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

View File

@ -12,7 +12,7 @@
#include <sys/un.h>
#include <errno.h>
#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);

7
xwayland/sockets.h Normal file
View File

@ -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

View File

@ -11,7 +11,8 @@
#include <wayland-server.h>
#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;
}

View File

@ -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) {

View File

@ -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);