2020-06-11 10:42:27 +00:00
|
|
|
#define _GNU_SOURCE 1
|
2020-01-02 07:23:39 +00:00
|
|
|
|
2019-11-21 05:16:53 +00:00
|
|
|
#include <assert.h>
|
2019-12-16 20:13:32 +00:00
|
|
|
#include <signal.h>
|
2019-11-21 05:16:53 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2019-12-31 01:50:22 +00:00
|
|
|
#include <pthread.h>
|
2020-01-02 07:23:39 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2019-12-31 06:50:49 +00:00
|
|
|
#include <sys/epoll.h>
|
2019-11-21 05:16:53 +00:00
|
|
|
|
2021-02-18 13:59:13 +00:00
|
|
|
#include <map>
|
|
|
|
|
2020-01-17 09:57:39 +00:00
|
|
|
#include <linux/input-event-codes.h>
|
|
|
|
|
2020-01-19 04:37:11 +00:00
|
|
|
#include <X11/extensions/XTest.h>
|
2020-01-17 09:57:39 +00:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
|
|
|
|
2019-11-21 05:16:53 +00:00
|
|
|
#include <wayland-server-core.h>
|
2020-06-11 10:42:27 +00:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#define static
|
|
|
|
#define class class_
|
2019-11-21 05:16:53 +00:00
|
|
|
#include <wlr/backend.h>
|
|
|
|
#include <wlr/backend/headless.h>
|
|
|
|
#include <wlr/backend/multi.h>
|
|
|
|
#include <wlr/backend/libinput.h>
|
2021-02-01 09:24:39 +00:00
|
|
|
#include <wlr/backend/noop.h>
|
2019-11-21 05:16:53 +00:00
|
|
|
#include <wlr/render/wlr_renderer.h>
|
2020-12-16 10:47:32 +00:00
|
|
|
#include <wlr/types/wlr_keyboard.h>
|
|
|
|
#include <wlr/types/wlr_pointer.h>
|
|
|
|
#include <wlr/types/wlr_touch.h>
|
2020-06-11 10:42:27 +00:00
|
|
|
#include <wlr/xwayland.h>
|
2019-11-21 05:16:53 +00:00
|
|
|
#include <wlr/util/log.h>
|
2020-06-11 10:42:27 +00:00
|
|
|
#undef static
|
|
|
|
#undef class
|
|
|
|
}
|
2019-11-21 07:41:54 +00:00
|
|
|
|
2021-02-18 13:59:13 +00:00
|
|
|
#include "gamescope-xwayland-protocol.h"
|
|
|
|
|
2020-06-11 10:42:27 +00:00
|
|
|
#include "wlserver.hpp"
|
2020-01-17 09:57:39 +00:00
|
|
|
#include "drm.hpp"
|
2019-11-21 07:41:54 +00:00
|
|
|
#include "main.hpp"
|
2020-07-03 00:40:31 +00:00
|
|
|
#include "steamcompmgr.hpp"
|
2019-11-21 05:16:53 +00:00
|
|
|
|
2020-01-14 02:45:53 +00:00
|
|
|
#include "gpuvis_trace_utils.h"
|
|
|
|
|
2019-11-21 05:16:53 +00:00
|
|
|
struct wlserver_t wlserver;
|
|
|
|
|
2019-11-23 07:42:02 +00:00
|
|
|
Display *g_XWLDpy;
|
|
|
|
|
2020-01-23 06:15:22 +00:00
|
|
|
bool run = true;
|
2020-01-01 23:00:34 +00:00
|
|
|
|
2021-02-18 13:59:13 +00:00
|
|
|
struct wlserver_content_override {
|
|
|
|
struct wlr_surface *surface;
|
|
|
|
uint32_t x11_window;
|
|
|
|
struct wl_listener surface_destroy_listener;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::map<uint32_t, struct wlserver_content_override *> content_overrides;
|
|
|
|
|
2021-06-18 08:44:13 +00:00
|
|
|
enum wlserver_touch_click_mode g_nTouchClickMode = WLSERVER_TOUCH_CLICK_LEFT;
|
2020-04-02 02:13:58 +00:00
|
|
|
|
2021-04-01 21:58:33 +00:00
|
|
|
static struct wl_list pending_surfaces = {0};
|
|
|
|
|
|
|
|
static void wlserver_surface_set_wlr( struct wlserver_surface *surf, struct wlr_surface *wlr_surf );
|
|
|
|
|
2019-12-16 20:13:32 +00:00
|
|
|
void sig_handler(int signal)
|
|
|
|
{
|
2020-08-30 02:14:38 +00:00
|
|
|
if ( signal == SIGUSR2 )
|
|
|
|
{
|
|
|
|
g_bTakeScreenshot = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-16 20:13:32 +00:00
|
|
|
wlr_log(WLR_DEBUG, "Received kill signal. Terminating!");
|
2020-01-01 23:00:34 +00:00
|
|
|
run = false;
|
2019-12-16 20:13:32 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 10:42:27 +00:00
|
|
|
extern const struct wlr_surface_role xwayland_surface_role;
|
2020-01-23 05:50:01 +00:00
|
|
|
|
2020-01-17 00:43:21 +00:00
|
|
|
void xwayland_surface_role_commit(struct wlr_surface *wlr_surface) {
|
2019-11-23 06:58:07 +00:00
|
|
|
assert(wlr_surface->role == &xwayland_surface_role);
|
2020-01-17 00:43:21 +00:00
|
|
|
|
2020-05-15 13:59:01 +00:00
|
|
|
if ( wlr_surface->buffer == NULL )
|
2020-01-17 00:43:21 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2020-05-15 13:59:01 +00:00
|
|
|
|
|
|
|
struct wlr_buffer *buf = wlr_buffer_lock( &wlr_surface->buffer->base );
|
|
|
|
|
2021-03-11 10:24:44 +00:00
|
|
|
gpuvis_trace_printf( "xwayland_surface_role_commit wlr_surface %p", wlr_surface );
|
2020-05-15 12:51:41 +00:00
|
|
|
|
2020-05-15 13:59:01 +00:00
|
|
|
wayland_commit( wlr_surface, buf );
|
2019-11-23 06:58:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void xwayland_surface_role_precommit(struct wlr_surface *wlr_surface) {
|
|
|
|
assert(wlr_surface->role == &xwayland_surface_role);
|
2020-06-11 10:42:27 +00:00
|
|
|
struct wlr_xwayland_surface *surface = (struct wlr_xwayland_surface *) wlr_surface->role_data;
|
2019-11-23 06:58:07 +00:00
|
|
|
if (surface == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct wlr_surface_role xwayland_surface_role = {
|
|
|
|
.name = "wlr_xwayland_surface",
|
|
|
|
.commit = xwayland_surface_role_commit,
|
|
|
|
.precommit = xwayland_surface_role_precommit,
|
|
|
|
};
|
|
|
|
|
2019-12-31 09:52:32 +00:00
|
|
|
static void xwayland_ready(struct wl_listener *listener, void *data)
|
|
|
|
{
|
2020-05-19 15:25:43 +00:00
|
|
|
setenv("DISPLAY", wlserver.wlr.xwayland_server->display_name, true);
|
2021-06-16 07:17:45 +00:00
|
|
|
|
|
|
|
g_XWLDpy = XOpenDisplay( wlserver.wlr.xwayland_server->display_name );
|
|
|
|
if ( g_XWLDpy == nullptr )
|
|
|
|
{
|
|
|
|
wlr_log( WLR_ERROR, "wlserver: failed to connect to X11 server\n" );
|
|
|
|
exit ( 1 );
|
|
|
|
}
|
2020-01-27 01:51:27 +00:00
|
|
|
|
2019-12-31 09:52:32 +00:00
|
|
|
startSteamCompMgr();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wl_listener xwayland_ready_listener = { .notify = xwayland_ready };
|
|
|
|
|
2020-01-17 09:57:39 +00:00
|
|
|
static void wlserver_handle_modifiers(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct wlserver_keyboard *keyboard = wl_container_of( listener, keyboard, modifiers );
|
|
|
|
|
|
|
|
wlr_seat_set_keyboard( wlserver.wlr.seat, keyboard->device );
|
|
|
|
wlr_seat_keyboard_notify_modifiers( wlserver.wlr.seat, &keyboard->device->keyboard->modifiers );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wlserver_handle_key(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct wlserver_keyboard *keyboard = wl_container_of( listener, keyboard, key );
|
2020-06-11 10:42:27 +00:00
|
|
|
struct wlr_event_keyboard_key *event = (struct wlr_event_keyboard_key *) data;
|
2020-05-12 09:13:20 +00:00
|
|
|
|
|
|
|
xkb_keycode_t keycode = event->keycode + 8;
|
|
|
|
xkb_keysym_t keysym = xkb_state_key_get_one_sym(keyboard->device->keyboard->xkb_state, keycode);
|
|
|
|
|
2020-12-16 10:47:32 +00:00
|
|
|
if (wlserver.wlr.session && event->state == WL_KEYBOARD_KEY_STATE_PRESSED && keysym >= XKB_KEY_XF86Switch_VT_1 && keysym <= XKB_KEY_XF86Switch_VT_12) {
|
2020-05-12 09:13:20 +00:00
|
|
|
unsigned vt = keysym - XKB_KEY_XF86Switch_VT_1 + 1;
|
|
|
|
wlr_session_change_vt(wlserver.wlr.session, vt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-17 09:57:39 +00:00
|
|
|
wlr_seat_set_keyboard( wlserver.wlr.seat, keyboard->device);
|
|
|
|
wlr_seat_keyboard_notify_key( wlserver.wlr.seat, event->time_msec, event->keycode, event->state );
|
|
|
|
}
|
|
|
|
|
2020-04-01 20:42:09 +00:00
|
|
|
static void wlserver_movecursor( int x, int y )
|
2020-01-19 04:37:11 +00:00
|
|
|
{
|
|
|
|
wlserver.mouse_surface_cursorx += x;
|
|
|
|
|
|
|
|
if ( wlserver.mouse_surface_cursorx > wlserver.mouse_focus_surface->current.width - 1 )
|
|
|
|
{
|
|
|
|
wlserver.mouse_surface_cursorx = wlserver.mouse_focus_surface->current.width - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( wlserver.mouse_surface_cursorx < 0 )
|
|
|
|
{
|
|
|
|
wlserver.mouse_surface_cursorx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
wlserver.mouse_surface_cursory += y;
|
|
|
|
|
|
|
|
if ( wlserver.mouse_surface_cursory > wlserver.mouse_focus_surface->current.height - 1 )
|
|
|
|
{
|
|
|
|
wlserver.mouse_surface_cursory = wlserver.mouse_focus_surface->current.height - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( wlserver.mouse_surface_cursory < 0 )
|
|
|
|
{
|
|
|
|
wlserver.mouse_surface_cursory = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-17 09:57:39 +00:00
|
|
|
static void wlserver_handle_pointer_motion(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct wlserver_pointer *pointer = wl_container_of( listener, pointer, motion );
|
2020-06-11 10:42:27 +00:00
|
|
|
struct wlr_event_pointer_motion *event = (struct wlr_event_pointer_motion *) data;
|
2020-01-17 09:57:39 +00:00
|
|
|
|
2020-01-19 04:37:11 +00:00
|
|
|
if ( wlserver.mouse_focus_surface != NULL )
|
|
|
|
{
|
2020-04-01 20:42:09 +00:00
|
|
|
wlserver_movecursor( event->unaccel_dx, event->unaccel_dy );
|
2020-01-17 09:57:39 +00:00
|
|
|
|
2020-01-19 04:37:11 +00:00
|
|
|
wlr_seat_pointer_notify_motion( wlserver.wlr.seat, event->time_msec, wlserver.mouse_surface_cursorx, wlserver.mouse_surface_cursory );
|
|
|
|
wlr_seat_pointer_notify_frame( wlserver.wlr.seat );
|
|
|
|
}
|
2020-01-17 09:57:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wlserver_handle_pointer_button(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct wlserver_pointer *pointer = wl_container_of( listener, pointer, button );
|
2020-06-11 10:42:27 +00:00
|
|
|
struct wlr_event_pointer_button *event = (struct wlr_event_pointer_button *) data;
|
2020-01-17 09:57:39 +00:00
|
|
|
|
|
|
|
wlr_seat_pointer_notify_button( wlserver.wlr.seat, event->time_msec, event->button, event->state );
|
|
|
|
wlr_seat_pointer_notify_frame( wlserver.wlr.seat );
|
|
|
|
}
|
|
|
|
|
2020-04-02 02:13:58 +00:00
|
|
|
static inline uint32_t steamcompmgr_button_to_wlserver_button( int button )
|
|
|
|
{
|
|
|
|
switch ( button )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
case 1:
|
|
|
|
return BTN_LEFT;
|
|
|
|
case 2:
|
|
|
|
return BTN_RIGHT;
|
|
|
|
case 3:
|
|
|
|
return BTN_MIDDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-17 09:57:39 +00:00
|
|
|
static void wlserver_handle_touch_down(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct wlserver_touch *touch = wl_container_of( listener, touch, down );
|
2020-06-11 10:42:27 +00:00
|
|
|
struct wlr_event_touch_down *event = (struct wlr_event_touch_down *) data;
|
2020-01-17 09:57:39 +00:00
|
|
|
|
|
|
|
if ( wlserver.mouse_focus_surface != NULL )
|
|
|
|
{
|
|
|
|
double x = g_bRotated ? event->y : event->x;
|
|
|
|
double y = g_bRotated ? 1.0 - event->x : event->y;
|
2020-04-01 20:42:15 +00:00
|
|
|
|
2020-07-03 00:40:31 +00:00
|
|
|
x *= g_nOutputWidth;
|
|
|
|
y *= g_nOutputHeight;
|
|
|
|
|
|
|
|
x += focusedWindowOffsetX;
|
|
|
|
y += focusedWindowOffsetY;
|
|
|
|
|
|
|
|
x *= focusedWindowScaleX;
|
|
|
|
y *= focusedWindowScaleY;
|
|
|
|
|
|
|
|
if ( x < 0.0f ) x = 0.0f;
|
|
|
|
if ( y < 0.0f ) y = 0.0f;
|
|
|
|
|
|
|
|
if ( x > wlserver.mouse_focus_surface->current.width ) x = wlserver.mouse_focus_surface->current.width;
|
|
|
|
if ( y > wlserver.mouse_focus_surface->current.height ) y = wlserver.mouse_focus_surface->current.height;
|
|
|
|
|
|
|
|
wlserver.mouse_surface_cursorx = x;
|
|
|
|
wlserver.mouse_surface_cursory = y;
|
2020-09-18 21:59:26 +00:00
|
|
|
|
2021-06-18 08:44:13 +00:00
|
|
|
if ( g_nTouchClickMode == WLSERVER_TOUCH_CLICK_PASSTHROUGH )
|
2020-09-18 21:59:26 +00:00
|
|
|
{
|
|
|
|
if ( event->touch_id >= 0 && event->touch_id < WLSERVER_TOUCH_COUNT )
|
|
|
|
{
|
|
|
|
wlr_seat_touch_notify_down( wlserver.wlr.seat, wlserver.mouse_focus_surface, event->time_msec, event->touch_id,
|
|
|
|
wlserver.mouse_surface_cursorx, wlserver.mouse_surface_cursory );
|
|
|
|
|
|
|
|
wlserver.touch_down[ event->touch_id ] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2020-04-02 02:13:58 +00:00
|
|
|
{
|
2020-09-18 21:59:26 +00:00
|
|
|
wlr_seat_pointer_notify_motion( wlserver.wlr.seat, event->time_msec, wlserver.mouse_surface_cursorx, wlserver.mouse_surface_cursory );
|
2020-04-02 02:13:58 +00:00
|
|
|
wlr_seat_pointer_notify_frame( wlserver.wlr.seat );
|
2020-09-18 21:59:26 +00:00
|
|
|
|
2020-09-23 22:22:42 +00:00
|
|
|
uint32_t button = steamcompmgr_button_to_wlserver_button( g_nTouchClickMode );
|
|
|
|
|
2020-09-18 21:59:26 +00:00
|
|
|
if ( button != 0 && g_nTouchClickMode < WLSERVER_BUTTON_COUNT )
|
|
|
|
{
|
|
|
|
wlr_seat_pointer_notify_button( wlserver.wlr.seat, event->time_msec, button, WLR_BUTTON_PRESSED );
|
|
|
|
wlr_seat_pointer_notify_frame( wlserver.wlr.seat );
|
|
|
|
|
|
|
|
wlserver.button_held[ g_nTouchClickMode ] = true;
|
|
|
|
}
|
2020-04-02 02:13:58 +00:00
|
|
|
}
|
2020-01-17 09:57:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wlserver_handle_touch_up(struct wl_listener *listener, void *data)
|
|
|
|
{
|
2020-05-04 07:42:24 +00:00
|
|
|
struct wlserver_touch *touch = wl_container_of( listener, touch, up );
|
2020-06-11 10:42:27 +00:00
|
|
|
struct wlr_event_touch_up *event = (struct wlr_event_touch_up *) data;
|
2020-05-04 07:42:24 +00:00
|
|
|
|
2020-01-17 09:57:39 +00:00
|
|
|
if ( wlserver.mouse_focus_surface != NULL )
|
|
|
|
{
|
2020-04-02 02:13:58 +00:00
|
|
|
bool bReleasedAny = false;
|
|
|
|
for ( int i = 0; i < WLSERVER_BUTTON_COUNT; i++ )
|
2020-01-17 09:57:39 +00:00
|
|
|
{
|
2020-04-02 02:13:58 +00:00
|
|
|
if ( wlserver.button_held[ i ] == true )
|
|
|
|
{
|
2020-09-23 22:22:42 +00:00
|
|
|
uint32_t button = steamcompmgr_button_to_wlserver_button( i );
|
|
|
|
|
|
|
|
if ( button != 0 )
|
|
|
|
{
|
|
|
|
wlr_seat_pointer_notify_button( wlserver.wlr.seat, event->time_msec, button, WLR_BUTTON_RELEASED );
|
|
|
|
bReleasedAny = true;
|
|
|
|
}
|
2020-09-18 21:59:26 +00:00
|
|
|
|
2020-04-02 02:13:58 +00:00
|
|
|
wlserver.button_held[ i ] = false;
|
|
|
|
}
|
2020-01-17 09:57:39 +00:00
|
|
|
}
|
2020-09-18 21:59:26 +00:00
|
|
|
|
2020-04-02 02:13:58 +00:00
|
|
|
if ( bReleasedAny == true )
|
2020-01-17 11:27:55 +00:00
|
|
|
{
|
|
|
|
wlr_seat_pointer_notify_frame( wlserver.wlr.seat );
|
|
|
|
}
|
2020-09-18 21:59:26 +00:00
|
|
|
|
|
|
|
if ( event->touch_id >= 0 && event->touch_id < WLSERVER_TOUCH_COUNT && wlserver.touch_down[ event->touch_id ] == true )
|
|
|
|
{
|
|
|
|
wlr_seat_touch_notify_up( wlserver.wlr.seat, event->time_msec, event->touch_id );
|
|
|
|
wlserver.touch_down[ event->touch_id ] = false;
|
|
|
|
}
|
2020-01-17 09:57:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wlserver_handle_touch_motion(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct wlserver_touch *touch = wl_container_of( listener, touch, motion );
|
2020-06-11 10:42:27 +00:00
|
|
|
struct wlr_event_touch_motion *event = (struct wlr_event_touch_motion *) data;
|
2020-01-17 09:57:39 +00:00
|
|
|
|
|
|
|
if ( wlserver.mouse_focus_surface != NULL )
|
|
|
|
{
|
|
|
|
double x = g_bRotated ? event->y : event->x;
|
|
|
|
double y = g_bRotated ? 1.0 - event->x : event->y;
|
2020-07-03 00:40:31 +00:00
|
|
|
|
|
|
|
x *= g_nOutputWidth;
|
|
|
|
y *= g_nOutputHeight;
|
|
|
|
|
|
|
|
x += focusedWindowOffsetX;
|
|
|
|
y += focusedWindowOffsetY;
|
|
|
|
|
|
|
|
x *= focusedWindowScaleX;
|
|
|
|
y *= focusedWindowScaleY;
|
|
|
|
|
|
|
|
if ( x < 0.0f ) x = 0.0f;
|
|
|
|
if ( y < 0.0f ) y = 0.0f;
|
|
|
|
|
|
|
|
if ( x > wlserver.mouse_focus_surface->current.width ) x = wlserver.mouse_focus_surface->current.width;
|
|
|
|
if ( y > wlserver.mouse_focus_surface->current.height ) y = wlserver.mouse_focus_surface->current.height;
|
|
|
|
|
|
|
|
wlserver.mouse_surface_cursorx = x;
|
|
|
|
wlserver.mouse_surface_cursory = y;
|
2020-01-17 11:27:55 +00:00
|
|
|
|
2021-06-18 08:44:13 +00:00
|
|
|
if ( g_nTouchClickMode == WLSERVER_TOUCH_CLICK_PASSTHROUGH )
|
2020-09-18 21:59:26 +00:00
|
|
|
{
|
|
|
|
wlr_seat_touch_notify_motion( wlserver.wlr.seat, event->time_msec, event->touch_id, wlserver.mouse_surface_cursorx, wlserver.mouse_surface_cursory );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wlr_seat_pointer_notify_motion( wlserver.wlr.seat, event->time_msec, wlserver.mouse_surface_cursorx, wlserver.mouse_surface_cursory );
|
|
|
|
wlr_seat_pointer_notify_frame( wlserver.wlr.seat );
|
|
|
|
}
|
2020-01-17 09:57:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wlserver_new_input(struct wl_listener *listener, void *data)
|
|
|
|
{
|
2020-06-11 10:42:27 +00:00
|
|
|
struct wlr_input_device *device = (struct wlr_input_device *) data;
|
2020-01-17 09:57:39 +00:00
|
|
|
|
|
|
|
switch ( device->type )
|
|
|
|
{
|
|
|
|
case WLR_INPUT_DEVICE_KEYBOARD:
|
|
|
|
{
|
2020-06-11 10:42:27 +00:00
|
|
|
struct wlserver_keyboard *pKB = (struct wlserver_keyboard *) calloc( 1, sizeof( struct wlserver_keyboard ) );
|
2020-01-17 09:57:39 +00:00
|
|
|
|
|
|
|
pKB->device = device;
|
|
|
|
|
|
|
|
struct xkb_rule_names rules = { 0 };
|
|
|
|
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
|
|
|
struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules,
|
|
|
|
XKB_KEYMAP_COMPILE_NO_FLAGS);
|
|
|
|
|
|
|
|
wlr_keyboard_set_keymap(device->keyboard, keymap);
|
|
|
|
xkb_keymap_unref(keymap);
|
|
|
|
xkb_context_unref(context);
|
|
|
|
wlr_keyboard_set_repeat_info(device->keyboard, 25, 600);
|
|
|
|
|
|
|
|
pKB->modifiers.notify = wlserver_handle_modifiers;
|
|
|
|
wl_signal_add( &device->keyboard->events.modifiers, &pKB->modifiers );
|
|
|
|
|
|
|
|
pKB->key.notify = wlserver_handle_key;
|
|
|
|
wl_signal_add( &device->keyboard->events.key, &pKB->key );
|
|
|
|
|
|
|
|
wlr_seat_set_keyboard( wlserver.wlr.seat, device );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_POINTER:
|
|
|
|
{
|
2020-06-11 10:42:27 +00:00
|
|
|
struct wlserver_pointer *pointer = (struct wlserver_pointer *) calloc( 1, sizeof( struct wlserver_pointer ) );
|
2020-01-17 09:57:39 +00:00
|
|
|
|
|
|
|
pointer->device = device;
|
|
|
|
|
|
|
|
pointer->motion.notify = wlserver_handle_pointer_motion;
|
|
|
|
wl_signal_add( &device->pointer->events.motion, &pointer->motion );
|
|
|
|
pointer->button.notify = wlserver_handle_pointer_button;
|
|
|
|
wl_signal_add( &device->pointer->events.button, &pointer->button );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_TOUCH:
|
|
|
|
{
|
2020-06-11 10:42:27 +00:00
|
|
|
struct wlserver_touch *touch = (struct wlserver_touch *) calloc( 1, sizeof( struct wlserver_touch ) );
|
2020-01-17 09:57:39 +00:00
|
|
|
|
|
|
|
touch->device = device;
|
|
|
|
|
|
|
|
touch->down.notify = wlserver_handle_touch_down;
|
|
|
|
wl_signal_add( &device->touch->events.down, &touch->down );
|
|
|
|
touch->up.notify = wlserver_handle_touch_up;
|
|
|
|
wl_signal_add( &device->touch->events.up, &touch->up );
|
|
|
|
touch->motion.notify = wlserver_handle_touch_motion;
|
|
|
|
wl_signal_add( &device->touch->events.motion, &touch->motion );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wl_listener new_input_listener = { .notify = wlserver_new_input };
|
|
|
|
|
2021-04-01 21:58:33 +00:00
|
|
|
static void wlserver_new_surface(struct wl_listener *l, void *data)
|
2020-07-03 01:45:00 +00:00
|
|
|
{
|
2021-04-01 21:58:33 +00:00
|
|
|
struct wlr_surface *wlr_surf = (struct wlr_surface *)data;
|
|
|
|
uint32_t id = wl_resource_get_id(wlr_surf->resource);
|
2020-07-03 01:45:00 +00:00
|
|
|
|
2021-04-01 21:58:33 +00:00
|
|
|
struct wlserver_surface *s, *tmp;
|
|
|
|
wl_list_for_each_safe(s, tmp, &pending_surfaces, pending_link)
|
|
|
|
{
|
2021-02-18 13:59:13 +00:00
|
|
|
if (s->wl_id == id && s->wlr == nullptr)
|
2021-04-01 21:58:33 +00:00
|
|
|
{
|
|
|
|
wlserver_surface_set_wlr( s, wlr_surf );
|
|
|
|
}
|
|
|
|
}
|
2020-07-03 01:45:00 +00:00
|
|
|
}
|
|
|
|
|
2021-04-01 21:58:33 +00:00
|
|
|
struct wl_listener new_surface_listener = { .notify = wlserver_new_surface };
|
|
|
|
|
2021-02-18 13:59:13 +00:00
|
|
|
static void destroy_content_override( struct wlserver_content_override *co )
|
|
|
|
{
|
|
|
|
wl_list_remove( &co->surface_destroy_listener.link );
|
|
|
|
content_overrides.erase( co->x11_window );
|
|
|
|
free( co );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void content_override_handle_surface_destroy( struct wl_listener *listener, void *data )
|
|
|
|
{
|
|
|
|
struct wlserver_content_override *co = wl_container_of( listener, co, surface_destroy_listener );
|
|
|
|
destroy_content_override( co );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gamescope_xwayland_handle_override_window_content( struct wl_client *client, struct wl_resource *resource, struct wl_resource *surface_resource, uint32_t x11_window )
|
|
|
|
{
|
|
|
|
struct wlr_surface *surface = wlr_surface_from_resource( surface_resource );
|
|
|
|
|
|
|
|
if ( content_overrides.count( x11_window ) ) {
|
|
|
|
destroy_content_override( content_overrides[ x11_window ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlserver_content_override *co = (struct wlserver_content_override *)calloc(1, sizeof(*co));
|
|
|
|
co->surface = surface;
|
|
|
|
co->x11_window = x11_window;
|
|
|
|
co->surface_destroy_listener.notify = content_override_handle_surface_destroy;
|
|
|
|
wl_signal_add( &surface->events.destroy, &co->surface_destroy_listener );
|
|
|
|
content_overrides[ x11_window ] = co;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gamescope_xwayland_handle_destroy( struct wl_client *client, struct wl_resource *resource )
|
|
|
|
{
|
|
|
|
wl_resource_destroy( resource );
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct gamescope_xwayland_interface gamescope_xwayland_impl = {
|
|
|
|
.destroy = gamescope_xwayland_handle_destroy,
|
|
|
|
.override_window_content = gamescope_xwayland_handle_override_window_content,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void gamescope_xwayland_bind( struct wl_client *client, void *data, uint32_t version, uint32_t id )
|
|
|
|
{
|
|
|
|
struct wl_resource *resource = wl_resource_create( client, &gamescope_xwayland_interface, version, id );
|
|
|
|
wl_resource_set_implementation( resource, &gamescope_xwayland_impl, NULL, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void create_gamescope_xwayland( void )
|
|
|
|
{
|
|
|
|
uint32_t version = 1;
|
|
|
|
wl_global_create( wlserver.wl_display, &gamescope_xwayland_interface, version, NULL, gamescope_xwayland_bind );
|
|
|
|
}
|
|
|
|
|
2020-01-02 07:23:39 +00:00
|
|
|
int wlserver_init(int argc, char **argv, bool bIsNested) {
|
|
|
|
bool bIsDRM = bIsNested == false;
|
2020-07-23 11:52:07 +00:00
|
|
|
|
2021-04-01 21:58:33 +00:00
|
|
|
wl_list_init(&pending_surfaces);
|
|
|
|
|
2019-11-21 05:16:53 +00:00
|
|
|
wlr_log_init(WLR_DEBUG, NULL);
|
|
|
|
wlserver.wl_display = wl_display_create();
|
2019-12-16 20:13:32 +00:00
|
|
|
|
|
|
|
signal(SIGTERM, sig_handler);
|
|
|
|
signal(SIGINT, sig_handler);
|
2020-08-30 02:14:38 +00:00
|
|
|
signal(SIGUSR2, sig_handler);
|
2020-07-23 11:52:07 +00:00
|
|
|
|
2019-11-21 05:16:53 +00:00
|
|
|
wlserver.wlr.session = ( bIsDRM == True ) ? wlr_session_create(wlserver.wl_display) : NULL;
|
2020-07-23 11:52:07 +00:00
|
|
|
|
2019-12-31 06:50:49 +00:00
|
|
|
wlserver.wl_event_loop = wl_display_get_event_loop(wlserver.wl_display);
|
|
|
|
wlserver.wl_event_loop_fd = wl_event_loop_get_fd( wlserver.wl_event_loop );
|
2020-07-23 11:52:07 +00:00
|
|
|
|
2020-01-17 09:57:39 +00:00
|
|
|
wlserver.wlr.multi_backend = wlr_multi_backend_create(wlserver.wl_display);
|
2020-07-23 11:52:07 +00:00
|
|
|
|
2020-01-17 09:57:39 +00:00
|
|
|
assert( wlserver.wl_display && wlserver.wl_event_loop && wlserver.wlr.multi_backend );
|
2019-11-21 05:16:53 +00:00
|
|
|
assert( !bIsDRM || wlserver.wlr.session );
|
|
|
|
|
2020-07-23 11:52:07 +00:00
|
|
|
wl_signal_add( &wlserver.wlr.multi_backend->events.new_input, &new_input_listener );
|
|
|
|
|
2021-01-07 11:07:28 +00:00
|
|
|
wlserver.wlr.headless_backend = wlr_headless_backend_create( wlserver.wl_display );
|
2020-01-17 09:57:39 +00:00
|
|
|
if ( wlserver.wlr.headless_backend == NULL )
|
|
|
|
{
|
2019-11-21 05:16:53 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2020-01-17 09:57:39 +00:00
|
|
|
wlr_multi_backend_add( wlserver.wlr.multi_backend, wlserver.wlr.headless_backend );
|
2020-07-23 11:52:07 +00:00
|
|
|
|
2021-02-01 09:24:39 +00:00
|
|
|
wlserver.wlr.noop_backend = wlr_noop_backend_create( wlserver.wl_display );
|
|
|
|
wlr_multi_backend_add( wlserver.wlr.multi_backend, wlserver.wlr.noop_backend );
|
2020-07-23 11:52:07 +00:00
|
|
|
|
2021-02-01 09:24:39 +00:00
|
|
|
wlserver.wlr.output = wlr_noop_add_output( wlserver.wlr.noop_backend );
|
2020-07-23 11:52:07 +00:00
|
|
|
|
2019-11-21 05:16:53 +00:00
|
|
|
if ( bIsDRM == True )
|
|
|
|
{
|
2020-01-17 09:57:39 +00:00
|
|
|
wlserver.wlr.libinput_backend = wlr_libinput_backend_create( wlserver.wl_display, wlserver.wlr.session );
|
|
|
|
if ( wlserver.wlr.libinput_backend == NULL)
|
|
|
|
{
|
2019-11-21 05:16:53 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2020-01-17 09:57:39 +00:00
|
|
|
wlr_multi_backend_add( wlserver.wlr.multi_backend, wlserver.wlr.libinput_backend );
|
2019-11-21 05:16:53 +00:00
|
|
|
}
|
2020-07-23 11:52:07 +00:00
|
|
|
else if ( wlr_backend_is_headless(wlserver.wlr.headless_backend) )
|
2020-01-18 23:10:14 +00:00
|
|
|
{
|
|
|
|
wlr_headless_add_input_device( wlserver.wlr.headless_backend, WLR_INPUT_DEVICE_KEYBOARD );
|
|
|
|
}
|
2020-07-23 11:52:07 +00:00
|
|
|
|
2021-03-05 14:42:35 +00:00
|
|
|
struct wlr_renderer *headless_renderer = wlr_backend_get_renderer( wlserver.wlr.multi_backend );
|
|
|
|
assert( headless_renderer );
|
|
|
|
wlserver.wlr.renderer = vulkan_renderer_create( headless_renderer );
|
2019-11-21 05:16:53 +00:00
|
|
|
|
|
|
|
wlr_renderer_init_wl_display(wlserver.wlr.renderer, wlserver.wl_display);
|
|
|
|
|
|
|
|
wlserver.wlr.compositor = wlr_compositor_create(wlserver.wl_display, wlserver.wlr.renderer);
|
2021-04-01 21:58:33 +00:00
|
|
|
|
|
|
|
wl_signal_add( &wlserver.wlr.compositor->events.new_surface, &new_surface_listener );
|
2021-02-18 13:59:13 +00:00
|
|
|
|
|
|
|
create_gamescope_xwayland();
|
2019-11-21 05:16:53 +00:00
|
|
|
|
2020-05-19 15:25:43 +00:00
|
|
|
struct wlr_xwayland_server_options xwayland_options = {
|
|
|
|
.lazy = false,
|
|
|
|
.enable_wm = false,
|
|
|
|
};
|
|
|
|
wlserver.wlr.xwayland_server = wlr_xwayland_server_create(wlserver.wl_display, &xwayland_options);
|
|
|
|
wl_signal_add(&wlserver.wlr.xwayland_server->events.ready, &xwayland_ready_listener);
|
2021-04-28 04:17:36 +00:00
|
|
|
|
2020-09-01 18:52:55 +00:00
|
|
|
int result = -1;
|
|
|
|
int display_slot = 0;
|
|
|
|
|
|
|
|
while ( result != 0 && display_slot < 128 )
|
|
|
|
{
|
2021-04-28 04:17:36 +00:00
|
|
|
sprintf( wlserver.wl_display_name, "gamescope-%d", display_slot );
|
|
|
|
result = wl_display_add_socket( wlserver.wl_display, wlserver.wl_display_name );
|
2020-09-01 18:52:55 +00:00
|
|
|
display_slot++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( result != 0 )
|
2020-01-17 09:57:39 +00:00
|
|
|
{
|
2019-11-21 05:16:53 +00:00
|
|
|
wlr_log_errno(WLR_ERROR, "Unable to open wayland socket");
|
2020-01-17 09:57:39 +00:00
|
|
|
wlr_backend_destroy( wlserver.wlr.multi_backend );
|
2019-11-21 05:16:53 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2020-05-12 13:55:01 +00:00
|
|
|
|
2020-01-17 09:57:39 +00:00
|
|
|
wlserver.wlr.seat = wlr_seat_create(wlserver.wl_display, "seat0");
|
2020-09-18 21:59:26 +00:00
|
|
|
wlr_seat_set_capabilities( wlserver.wlr.seat, WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_KEYBOARD | WL_SEAT_CAPABILITY_TOUCH );
|
2019-11-21 05:16:53 +00:00
|
|
|
|
2021-04-28 04:17:36 +00:00
|
|
|
wlr_log(WLR_INFO, "Running compositor on wayland display '%s'", wlserver.wl_display_name);
|
2019-11-21 05:16:53 +00:00
|
|
|
|
2021-04-28 04:17:36 +00:00
|
|
|
setenv("GAMESCOPE_WAYLAND_DISPLAY", wlserver.wl_display_name, 1);
|
2021-02-18 13:59:50 +00:00
|
|
|
|
2020-01-17 09:57:39 +00:00
|
|
|
if (!wlr_backend_start( wlserver.wlr.multi_backend ))
|
|
|
|
{
|
2019-11-21 05:16:53 +00:00
|
|
|
wlr_log(WLR_ERROR, "Failed to start backend");
|
2020-01-17 09:57:39 +00:00
|
|
|
wlr_backend_destroy( wlserver.wlr.multi_backend );
|
2019-11-21 05:16:53 +00:00
|
|
|
wl_display_destroy(wlserver.wl_display);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-02-01 09:24:39 +00:00
|
|
|
wlr_output_enable( wlserver.wlr.output, true );
|
|
|
|
wlr_output_set_custom_mode( wlserver.wlr.output, g_nNestedWidth, g_nNestedHeight, g_nOutputRefresh * 1000 );
|
|
|
|
wlr_output_commit( wlserver.wlr.output );
|
|
|
|
|
|
|
|
wlr_output_create_global( wlserver.wlr.output );
|
|
|
|
|
2019-11-21 05:16:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-31 01:50:22 +00:00
|
|
|
pthread_mutex_t waylock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
|
|
void wlserver_lock(void)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&waylock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlserver_unlock(void)
|
|
|
|
{
|
2020-01-01 04:54:32 +00:00
|
|
|
wl_display_flush_clients(wlserver.wl_display);
|
2019-12-31 01:50:22 +00:00
|
|
|
pthread_mutex_unlock(&waylock);
|
|
|
|
}
|
|
|
|
|
2019-11-23 06:58:07 +00:00
|
|
|
int wlserver_run(void)
|
2019-11-21 05:16:53 +00:00
|
|
|
{
|
2019-12-31 06:50:49 +00:00
|
|
|
int epoll_fd = epoll_create( 1 );
|
|
|
|
struct epoll_event ev;
|
|
|
|
struct epoll_event events[128];
|
|
|
|
int n;
|
|
|
|
|
|
|
|
ev.events = EPOLLIN;
|
|
|
|
|
|
|
|
if ( epoll_fd == -1 ||
|
|
|
|
epoll_ctl( epoll_fd, EPOLL_CTL_ADD, wlserver.wl_event_loop_fd, &ev ) == -1 )
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-01-01 23:00:34 +00:00
|
|
|
while ( run )
|
2019-12-31 01:50:22 +00:00
|
|
|
{
|
2019-12-31 06:50:49 +00:00
|
|
|
n = epoll_wait( epoll_fd, events, 128, -1 );
|
|
|
|
if ( n == -1 )
|
|
|
|
{
|
2020-01-16 01:48:20 +00:00
|
|
|
if ( errno == EINTR )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2019-12-31 01:50:22 +00:00
|
|
|
}
|
2020-01-16 01:48:20 +00:00
|
|
|
|
2019-12-31 06:50:49 +00:00
|
|
|
// We have wayland stuff to do, do it while locked
|
|
|
|
wlserver_lock();
|
|
|
|
|
|
|
|
for ( int i = 0; i < n; i++ )
|
|
|
|
{
|
|
|
|
wl_display_flush_clients(wlserver.wl_display);
|
|
|
|
int ret = wl_event_loop_dispatch(wlserver.wl_event_loop, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wlserver_unlock();
|
2019-12-31 01:50:22 +00:00
|
|
|
}
|
|
|
|
|
2019-11-21 05:16:53 +00:00
|
|
|
// We need to shutdown Xwayland before disconnecting all clients, otherwise
|
|
|
|
// wlroots will restart it automatically.
|
2020-05-19 15:25:43 +00:00
|
|
|
wlr_xwayland_server_destroy(wlserver.wlr.xwayland_server);
|
2019-11-21 05:16:53 +00:00
|
|
|
wl_display_destroy_clients(wlserver.wl_display);
|
|
|
|
wl_display_destroy(wlserver.wl_display);
|
|
|
|
return 0;
|
|
|
|
}
|
2020-01-02 07:23:39 +00:00
|
|
|
|
2020-01-17 09:57:39 +00:00
|
|
|
void wlserver_keyboardfocus( struct wlr_surface *surface )
|
|
|
|
{
|
|
|
|
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard( wlserver.wlr.seat );
|
|
|
|
if ( keyboard != NULL )
|
|
|
|
{
|
|
|
|
wlr_seat_keyboard_notify_enter( wlserver.wlr.seat, surface, keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 23:10:14 +00:00
|
|
|
void wlserver_key( uint32_t key, bool press, uint32_t time )
|
|
|
|
{
|
|
|
|
wlr_seat_keyboard_notify_key( wlserver.wlr.seat, time, key, press );
|
|
|
|
}
|
|
|
|
|
2020-01-02 07:23:39 +00:00
|
|
|
void wlserver_mousefocus( struct wlr_surface *wlrsurface )
|
|
|
|
{
|
2020-01-17 09:57:39 +00:00
|
|
|
wlserver.mouse_focus_surface = wlrsurface;
|
|
|
|
wlserver.mouse_surface_cursorx = wlrsurface->current.width / 2.0;
|
|
|
|
wlserver.mouse_surface_cursory = wlrsurface->current.height / 2.0;
|
|
|
|
wlr_seat_pointer_notify_enter( wlserver.wlr.seat, wlrsurface, wlserver.mouse_surface_cursorx, wlserver.mouse_surface_cursory );
|
2020-01-02 07:23:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 20:41:58 +00:00
|
|
|
void wlserver_mousemotion( int x, int y, uint32_t time )
|
2020-01-02 07:23:39 +00:00
|
|
|
{
|
2020-04-01 20:41:58 +00:00
|
|
|
if ( g_XWLDpy != NULL )
|
|
|
|
{
|
|
|
|
XTestFakeRelativeMotionEvent( g_XWLDpy, x, y, CurrentTime );
|
|
|
|
XFlush( g_XWLDpy );
|
2020-01-19 04:37:11 +00:00
|
|
|
}
|
2020-01-02 07:23:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlserver_mousebutton( int button, bool press, uint32_t time )
|
|
|
|
{
|
|
|
|
wlr_seat_pointer_notify_button( wlserver.wlr.seat, time, button, press ? WLR_BUTTON_PRESSED : WLR_BUTTON_RELEASED );
|
|
|
|
wlr_seat_pointer_notify_frame( wlserver.wlr.seat );
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlserver_mousewheel( int x, int y, uint32_t time )
|
|
|
|
{
|
|
|
|
if ( x != 0 )
|
|
|
|
{
|
|
|
|
wlr_seat_pointer_notify_axis( wlserver.wlr.seat, time, WLR_AXIS_ORIENTATION_HORIZONTAL, x, x, WLR_AXIS_SOURCE_WHEEL );
|
|
|
|
}
|
|
|
|
if ( y != 0 )
|
|
|
|
{
|
|
|
|
wlr_seat_pointer_notify_axis( wlserver.wlr.seat, time, WLR_AXIS_ORIENTATION_VERTICAL, y, y, WLR_AXIS_SOURCE_WHEEL );
|
|
|
|
}
|
|
|
|
wlr_seat_pointer_notify_frame( wlserver.wlr.seat );
|
|
|
|
}
|
2020-01-23 05:50:01 +00:00
|
|
|
|
|
|
|
void wlserver_send_frame_done( struct wlr_surface *surf, const struct timespec *when )
|
|
|
|
{
|
|
|
|
wlr_surface_send_frame_done( surf, when );
|
|
|
|
}
|
|
|
|
|
2021-04-28 04:17:36 +00:00
|
|
|
const char *wlserver_get_nested_display_name( void )
|
2020-01-23 05:50:01 +00:00
|
|
|
{
|
2021-04-01 21:58:33 +00:00
|
|
|
return wlserver.wlr.xwayland_server->display_name;
|
|
|
|
}
|
2020-01-23 05:50:01 +00:00
|
|
|
|
2021-04-28 04:17:36 +00:00
|
|
|
const char *wlserver_get_wl_display_name( void )
|
|
|
|
{
|
|
|
|
return wlserver.wl_display_name;
|
|
|
|
}
|
|
|
|
|
2021-04-01 21:58:33 +00:00
|
|
|
static void handle_surface_destroy( struct wl_listener *l, void *data )
|
|
|
|
{
|
|
|
|
struct wlserver_surface *surf = wl_container_of( l, surf, destroy );
|
|
|
|
wlserver_surface_finish( surf );
|
2021-02-18 13:59:13 +00:00
|
|
|
wlserver_surface_init( surf, surf->x11_id );
|
2021-04-01 21:58:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wlserver_surface_set_wlr( struct wlserver_surface *surf, struct wlr_surface *wlr_surf )
|
|
|
|
{
|
2021-04-16 13:16:14 +00:00
|
|
|
assert( surf->wlr == nullptr );
|
2021-04-01 21:58:33 +00:00
|
|
|
|
|
|
|
wl_list_remove( &surf->pending_link );
|
|
|
|
wl_list_init( &surf->pending_link );
|
|
|
|
|
|
|
|
surf->destroy.notify = handle_surface_destroy;
|
|
|
|
wl_signal_add( &wlr_surf->events.destroy, &surf->destroy );
|
|
|
|
|
|
|
|
surf->wlr = wlr_surf;
|
|
|
|
|
|
|
|
if ( !wlr_surface_set_role(wlr_surf, &xwayland_surface_role, NULL, NULL, 0 ) )
|
2020-01-23 05:50:01 +00:00
|
|
|
{
|
2020-04-01 20:41:50 +00:00
|
|
|
fprintf (stderr, "Failed to set xwayland surface role");
|
2020-01-23 05:50:01 +00:00
|
|
|
}
|
2021-04-01 21:58:33 +00:00
|
|
|
}
|
|
|
|
|
2021-02-18 13:59:13 +00:00
|
|
|
void wlserver_surface_init( struct wlserver_surface *surf, long x11_id )
|
2021-04-01 21:58:33 +00:00
|
|
|
{
|
2021-04-16 12:39:38 +00:00
|
|
|
surf->wl_id = 0;
|
2021-02-18 13:59:13 +00:00
|
|
|
surf->x11_id = x11_id;
|
2021-04-01 21:58:33 +00:00
|
|
|
surf->wlr = nullptr;
|
|
|
|
wl_list_init( &surf->pending_link );
|
|
|
|
wl_list_init( &surf->destroy.link );
|
|
|
|
}
|
2020-07-03 01:45:00 +00:00
|
|
|
|
2021-04-16 12:39:38 +00:00
|
|
|
void wlserver_surface_set_wl_id( struct wlserver_surface *surf, long id )
|
2021-04-01 21:58:33 +00:00
|
|
|
{
|
2021-05-01 01:45:00 +00:00
|
|
|
if ( surf->wl_id != 0 )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "surf->wl_id already set, was %lu, set %lu\n", surf->wl_id, id );
|
2021-05-20 15:40:20 +00:00
|
|
|
return;
|
2021-05-01 01:45:00 +00:00
|
|
|
}
|
2020-07-03 01:45:00 +00:00
|
|
|
|
2021-04-16 12:39:38 +00:00
|
|
|
surf->wl_id = id;
|
2021-04-01 21:58:33 +00:00
|
|
|
surf->wlr = nullptr;
|
|
|
|
|
|
|
|
wl_list_insert( &pending_surfaces, &surf->pending_link );
|
|
|
|
wl_list_init( &surf->destroy.link );
|
|
|
|
|
2021-02-18 13:59:13 +00:00
|
|
|
struct wlr_surface *wlr_surf = nullptr;
|
|
|
|
if ( content_overrides.count( surf->x11_id ) )
|
|
|
|
{
|
|
|
|
wlr_surf = content_overrides[ surf->x11_id ]->surface;
|
|
|
|
}
|
|
|
|
else
|
2021-04-01 21:58:33 +00:00
|
|
|
{
|
2021-02-18 13:59:13 +00:00
|
|
|
struct wl_resource *resource = wl_client_get_object( wlserver.wlr.xwayland_server->client, id );
|
|
|
|
if ( resource != nullptr )
|
|
|
|
wlr_surf = wlr_surface_from_resource( resource );
|
2021-04-01 21:58:33 +00:00
|
|
|
}
|
2021-02-18 13:59:13 +00:00
|
|
|
|
|
|
|
if ( wlr_surf != nullptr )
|
|
|
|
wlserver_surface_set_wlr( surf, wlr_surf );
|
2020-01-23 05:50:01 +00:00
|
|
|
}
|
|
|
|
|
2021-04-01 21:58:33 +00:00
|
|
|
void wlserver_surface_finish( struct wlserver_surface *surf )
|
2020-01-23 05:50:01 +00:00
|
|
|
{
|
2021-05-05 23:37:51 +00:00
|
|
|
if ( surf->wlr == wlserver.mouse_focus_surface )
|
|
|
|
{
|
|
|
|
wlserver.mouse_focus_surface = nullptr;
|
|
|
|
}
|
|
|
|
|
2021-04-16 12:39:38 +00:00
|
|
|
surf->wl_id = 0;
|
2021-04-01 21:58:33 +00:00
|
|
|
surf->wlr = nullptr;
|
|
|
|
wl_list_remove( &surf->pending_link );
|
|
|
|
wl_list_remove( &surf->destroy.link );
|
2020-01-23 05:50:01 +00:00
|
|
|
}
|