Skip to content

Commit

Permalink
xwayland support, first ^working^ commit
Browse files Browse the repository at this point in the history
  • Loading branch information
danihek committed May 22, 2024
1 parent 01339db commit 30c68ec
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 101 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ LIBS=\
$(shell pkg-config --cflags --libs "wlroots >= 0.18.0-dev") \
$(shell pkg-config --cflags --libs wayland-server) \
$(shell pkg-config --cflags --libs xkbcommon) \
-llua
-llua \
-lxcb

wlr-layer-shell-unstable-v1-protocol.h:
$(WAYLAND_SCANNER) server-header \
Expand Down
26 changes: 5 additions & 21 deletions include/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@
#include "config.h"
#include "lua/luaUtil.h"


#ifdef XWAYLAND
#include <xcb/xproto.h>
#include <wlr/xwayland/shell.h>
#include <wlr/xwayland/xwayland.h>
#include "../include/xwayland.h"
#endif

#define HELLWM_INFO "INFO"
Expand Down Expand Up @@ -75,6 +78,7 @@ struct hellwm_server
struct wlr_scene *scene;
struct wl_list keyboards;
struct wl_list toplevels;
struct wl_list xtoplevels;
struct wlr_cursor *cursor;
struct wlr_box grab_geobox;
struct wlr_backend *backend;
Expand Down Expand Up @@ -105,29 +109,10 @@ struct hellwm_server
struct hellwm_config_pointers *config_pointer;
struct wlr_xdg_decoration_manager_v1 *xdg_decoration_manager;

#if XWAYLAND
xcb_atom_t atoms[ATOM_LAST];
struct wlr_xwayland *xwayland;
struct wl_listener xwayland_ready;
struct wl_listener new_xwayland_surface;
#endif
};

struct hellwm_xwayland_surface
{
struct wlr_xwayland_surface *xwayland_surface;

struct wl_listener destroy;
struct wl_listener request_configure;
struct wl_listener request_move;
struct wl_listener request_resize;
struct wl_listener request_maximize;
struct wl_listener request_fullscreen;
struct wl_listener map;
struct wl_listener unmap;
struct wl_listener set_title;
struct wl_listener set_class;

struct wl_listener surface_commit;
};

struct hellwm_tile_tree
Expand All @@ -154,7 +139,6 @@ struct hellwm_output

struct hellwm_toplevel
{
char *title;
struct wl_list link;
struct wl_listener map;
struct wl_listener unmap;
Expand Down
75 changes: 75 additions & 0 deletions include/xwayland.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#ifndef SWAY_XWAYLAND_H
#define SWAY_XWAYLAND_H

#include <linux/input-event-codes.h>
#include <assert.h>
#include <GLES2/gl2.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <wayland-client.h>
#include <wayland-cursor.h>
#include <wayland-egl.h>
#include <wayland-server-core.h>
#include <wayland-util.h>
#include <wlr/util/log.h>
#include <xcb/xcb_icccm.h>

#include <wlr/xwayland/shell.h>
#include <wlr/xwayland/xwayland.h>

#include "../include/server.h"

enum atom_name
{
NET_WM_WINDOW_TYPE_NORMAL,
NET_WM_WINDOW_TYPE_DIALOG,
NET_WM_WINDOW_TYPE_UTILITY,
NET_WM_WINDOW_TYPE_TOOLBAR,
NET_WM_WINDOW_TYPE_SPLASH,
NET_WM_WINDOW_TYPE_MENU,
NET_WM_WINDOW_TYPE_DROPDOWN_MENU,
NET_WM_WINDOW_TYPE_POPUP_MENU,
NET_WM_WINDOW_TYPE_TOOLTIP,
NET_WM_WINDOW_TYPE_NOTIFICATION,
NET_WM_STATE_MODAL,
ATOM_LAST,
};

struct hellwm_xwayland_toplevel
{
struct hellwm_server *server;
struct wlr_xwayland_surface *xwayland_surface;

struct wl_list link;
struct wl_listener map;
struct wl_listener unmap;
struct wl_listener commit;
struct wl_listener destroy;
struct wl_listener associate;
struct wl_listener request_role;
struct wl_listener request_move;
struct wl_listener request_title;
struct wl_listener request_app_id;
struct wl_listener request_resize;
struct wl_listener request_maximize;
struct wl_listener request_configure;
struct wl_listener request_fullscreen;
};

static void xhandle_map(struct wl_listener *listener, void *data);
static void xhandle_unmap(struct wl_listener *listener, void *data);
static void xhandle_destroy(struct wl_listener *listener, void *data);
static void xhandle_set_role(struct wl_listener *listener, void *data);
static void xhandle_associate(struct wl_listener *listener, void *data);
static void xhandle_set_title(struct wl_listener *listener, void *data);
static void xhandle_configure(struct wl_listener *listener, void *data);
static void xhandle_set_app_id(struct wl_listener *listener, void *data);
static void handle_surface_commit(struct wl_listener *listener ,void *data);
static void server_xwayland_ready(struct wl_listener *listener, void *data);
static void server_handle_xwayland_surface(struct wl_listener*listener,void*data);

#endif
33 changes: 16 additions & 17 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,15 +694,6 @@ static void output_destroy(struct wl_listener *listener, void *data) {
struct hellwm_output *output = wl_container_of(listener, output, destroy);
struct hellwm_server *server = output->server;

/*for (int i=0;i<server->outputs_list->count;i++)
{
if (server->outputs_list->outputs[i]->wlr_output->name == output->wlr_output->name)
{
free(server->outputs_list->outputs[i]);
server->outputs_list->count--;
}
}*/

wl_list_remove(&output->frame.link);
wl_list_remove(&output->request_state.link);
wl_list_remove(&output->destroy.link);
Expand Down Expand Up @@ -795,6 +786,7 @@ static void xdg_toplevel_destroy(struct wl_listener *listener, void *data) {
free(toplevel);

hellmw_tile_re_add(server);
focus_next(server);
}

static void begin_interactive(struct hellwm_toplevel *toplevel,
Expand Down Expand Up @@ -939,7 +931,7 @@ static void server_new_xdg_toplevel(struct wl_listener *listener, void *data)
static void xdg_toplevel_set_title(struct wl_listener *listener, void *data)
{
struct hellwm_toplevel *toplevel = wl_container_of(listener, toplevel, request_title);
const char *title = toplevel->xdg_toplevel->title;
const char *title = data;
hellwm_log(HELLWM_LOG, "xdg_toplevel_set_title() called on %s", title);
}

Expand Down Expand Up @@ -1121,16 +1113,23 @@ void hellwm_setup(struct hellwm_server *server)
//wl_signal_add(&server->xdg_decoration_manager->events.new_toplevel_decoration, &xdg_decoration_listener);

/* Set up xwayland */
#ifdef XWAYLAND
wl_list_init(&server->xtoplevels);
server->xwayland = wlr_xwayland_create(server->wl_display, server->compositor, true);
server->new_xwayland_surface.notify = server_handle_xwayland_surface;
wl_signal_add(&server->xwayland->events.new_surface, &server->new_xwayland_surface);
if (!server->xwayland)
{
hellwm_log(HELLWM_ERROR, "Failed to create xwayland");
unsetenv("DISPLAY");
}
else
{
server->new_xwayland_surface.notify = server_handle_xwayland_surface;
wl_signal_add(&server->xwayland->events.new_surface, &server->new_xwayland_surface);

server->xwayland_ready.notify = server_xwayland_ready;
wl_signal_add(&server->xwayland->events.new_surface, &server->xwayland_ready);
server->xwayland_ready.notify = server_xwayland_ready;
wl_signal_add(&server->xwayland->events.ready, &server->xwayland_ready);

setenv("DISPLAY", server->xwayland->server->display_name, true);
#endif
setenv("DISPLAY", server->xwayland->display_name, true);
}

server->cursor = wlr_cursor_create();
wlr_cursor_attach_output_layout(server->cursor, server->output_layout);
Expand Down
Loading

0 comments on commit 30c68ec

Please sign in to comment.