mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 12:55:58 +01:00
xwm: fix minimal init, this gets us some events on window creations
This commit is contained in:
parent
6eb20fb8d2
commit
fa0e1015c6
5 changed files with 162 additions and 11 deletions
|
@ -4,13 +4,77 @@
|
|||
#include <wayland-server-core.h>
|
||||
#include <wlr/xwayland.h>
|
||||
|
||||
/* 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_connection_t *xcb_connection;
|
||||
xcb_screen_t *xcb_screen;
|
||||
xcb_atom_t atoms[ATOM_LAST];
|
||||
xcb_connection_t *xcb_conn;
|
||||
xcb_screen_t *screen;
|
||||
xcb_window_t window;
|
||||
};
|
||||
|
||||
void unlink_sockets(int display);
|
||||
|
|
|
@ -33,6 +33,7 @@ xkbcommon = dependency('xkbcommon')
|
|||
udev = dependency('libudev')
|
||||
pixman = dependency('pixman-1')
|
||||
xcb = dependency('xcb')
|
||||
xcb_composite = dependency('xcb-composite')
|
||||
libcap = dependency('libcap', required: false)
|
||||
systemd = dependency('libsystemd', required: false)
|
||||
math = cc.find_library('m', required: false)
|
||||
|
@ -67,6 +68,7 @@ wlr_deps = [
|
|||
udev,
|
||||
pixman,
|
||||
xcb,
|
||||
xcb_composite,
|
||||
libcap,
|
||||
systemd,
|
||||
math,
|
||||
|
|
|
@ -4,4 +4,4 @@ lib_wlr_xwayland = static_library('wlr_xwayland', files(
|
|||
'xwm.c',
|
||||
),
|
||||
include_directories: wlr_inc,
|
||||
dependencies: [wayland_server, xcb, pixman])
|
||||
dependencies: [wayland_server, xcb, xcb_composite, pixman])
|
||||
|
|
|
@ -138,6 +138,9 @@ static int xserver_handle_ready(int signal_number, void *data) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
wl_event_source_remove(wlr_xwayland->sigusr1_source);
|
||||
wlr_xwayland->sigusr1_source = NULL;
|
||||
|
||||
char display_name[16];
|
||||
snprintf(display_name, sizeof(display_name), ":%d", wlr_xwayland->display);
|
||||
setenv("DISPLAY", display_name, true);
|
||||
|
|
|
@ -1,20 +1,34 @@
|
|||
#include <stdlib.h>
|
||||
#include <xcb/xcb_event.h>
|
||||
#include <xcb/composite.h>
|
||||
#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);
|
||||
while ((event = xcb_poll_for_event(xwm->xcb_conn))) {
|
||||
count++;
|
||||
// TODO: actually do stuff!
|
||||
switch (event->response_type & XCB_EVENT_RESPONSE_TYPE_MASK) {
|
||||
case XCB_CREATE_NOTIFY:
|
||||
break;
|
||||
case XCB_CONFIGURE_REQUEST:
|
||||
break;
|
||||
case XCB_MAP_REQUEST:
|
||||
break;
|
||||
case XCB_DESTROY_NOTIFY:
|
||||
break;
|
||||
default:
|
||||
wlr_log(L_DEBUG, "X11 event: %d", event->response_type & XCB_EVENT_RESPONSE_TYPE_MASK);
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
@ -33,11 +47,76 @@ static void create_surface_handler(struct wl_listener *listener, void *data)
|
|||
// TODO: look for unpaired window, and assign
|
||||
}
|
||||
|
||||
static void xcb_get_resources(struct wlr_xwm *xwm) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ATOM_LAST; i++) {
|
||||
xcb_intern_atom_cookie_t cookie;
|
||||
xcb_intern_atom_reply_t *reply;
|
||||
xcb_generic_error_t *error;
|
||||
|
||||
cookie = xcb_intern_atom(xwm->xcb_conn, 0, strlen(atom_map[i]), atom_map[i]);
|
||||
reply = xcb_intern_atom_reply(xwm->xcb_conn, cookie, &error);
|
||||
|
||||
if (reply && !error) {
|
||||
xwm->atoms[i] = reply->atom;
|
||||
}
|
||||
if (reply) {
|
||||
free(reply);
|
||||
}
|
||||
if (error) {
|
||||
wlr_log(L_ERROR, "could not resolve atom %s, x11 error code %d",
|
||||
atom_map[i], error->error_code);
|
||||
free(error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool xcb_call(struct wlr_xwm *xwm, const char *func, uint32_t line, xcb_void_cookie_t cookie) {
|
||||
xcb_generic_error_t *error;
|
||||
if (!(error = xcb_request_check(xwm->xcb_conn, cookie))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
wlr_log(L_ERROR, "xcb call failed in %s:%u, x11 error code %d", func, line, error->error_code);
|
||||
free(error);
|
||||
return false;
|
||||
}
|
||||
#define XCB_CALL(xwm, x) xcb_call(xwm, __PRETTY_FUNCTION__, __LINE__, x)
|
||||
|
||||
static void xcb_init_wm(struct wlr_xwm *xwm) {
|
||||
xcb_screen_iterator_t screen_iterator;
|
||||
screen_iterator = xcb_setup_roots_iterator(xcb_get_setup(xwm->xcb_conn));
|
||||
xwm->screen = screen_iterator.data;
|
||||
|
||||
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 /* , xwm->cursor */ };
|
||||
XCB_CALL(xwm, xcb_change_window_attributes_checked(xwm->xcb_conn, xwm->screen->root,
|
||||
XCB_CW_EVENT_MASK /* | XCB_CW_CURSOR */, values));
|
||||
XCB_CALL(xwm, xcb_composite_redirect_subwindows_checked(xwm->xcb_conn, xwm->screen->root, XCB_COMPOSITE_REDIRECT_MANUAL));
|
||||
|
||||
XCB_CALL(xwm, xcb_create_window_checked(xwm->xcb_conn, XCB_COPY_FROM_PARENT, xwm->window, xwm->screen->root,
|
||||
0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, xwm->screen->root_visual,
|
||||
XCB_CW_EVENT_MASK, (uint32_t[]){XCB_EVENT_MASK_PROPERTY_CHANGE}));
|
||||
xcb_atom_t supported[] = {
|
||||
xwm->atoms[NET_WM_STATE],
|
||||
};
|
||||
XCB_CALL(xwm, xcb_change_property_checked(xwm->xcb_conn, XCB_PROP_MODE_REPLACE, xwm->screen->root, xwm->atoms[NET_SUPPORTED], XCB_ATOM_ATOM, 32, sizeof(supported)/sizeof(*supported), supported));
|
||||
|
||||
XCB_CALL(xwm, xcb_set_selection_owner_checked(xwm->xcb_conn, xwm->window, xwm->atoms[WM_S0], XCB_CURRENT_TIME));
|
||||
XCB_CALL(xwm, xcb_set_selection_owner_checked(xwm->xcb_conn, xwm->window, xwm->atoms[NET_WM_S0], XCB_CURRENT_TIME));
|
||||
xcb_flush(xwm->xcb_conn);
|
||||
}
|
||||
|
||||
void xwm_destroy(struct wlr_xwm *xwm) {
|
||||
if (xwm->event_source) {
|
||||
wl_event_source_remove(xwm->event_source);
|
||||
}
|
||||
|
||||
xcb_disconnect(xwm->xcb_conn);
|
||||
|
||||
free(xwm);
|
||||
}
|
||||
|
||||
|
@ -46,13 +125,12 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) {
|
|||
|
||||
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)) {
|
||||
xwm->xcb_conn = xcb_connect_to_fd(wlr_xwayland->wm_fd[0], NULL);
|
||||
if (xcb_connection_has_error(xwm->xcb_conn)) {
|
||||
free(xwm);
|
||||
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],
|
||||
|
@ -60,6 +138,10 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) {
|
|||
// probably not needed
|
||||
// wl_event_source_check(xwm->event_source);
|
||||
|
||||
// TODO more xcb init
|
||||
// xcb_prefetch_extension_data(xwm->xcb_conn, &xcb_composite_id);
|
||||
xcb_get_resources(xwm);
|
||||
xcb_init_wm(xwm);
|
||||
|
||||
xwm->surface_listener.notify = create_surface_handler;
|
||||
wl_signal_add(&wlr_xwayland->compositor->create_surface_signal,
|
||||
|
|
Loading…
Reference in a new issue