2020-06-11 10:42:27 +00:00
|
|
|
// Wayland stuff
|
2019-11-21 05:16:53 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <wayland-server-core.h>
|
2021-04-01 21:58:33 +00:00
|
|
|
#include <atomic>
|
2022-01-06 06:59:58 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
2022-01-07 04:49:21 +00:00
|
|
|
#include <mutex>
|
2022-01-08 15:32:54 +00:00
|
|
|
#include <map>
|
2022-11-25 19:03:55 +00:00
|
|
|
#include <set>
|
2019-11-21 05:16:53 +00:00
|
|
|
|
2020-04-02 02:13:58 +00:00
|
|
|
#define WLSERVER_BUTTON_COUNT 4
|
|
|
|
|
2022-01-06 07:18:22 +00:00
|
|
|
struct _XDisplay;
|
2022-01-06 09:02:21 +00:00
|
|
|
struct xwayland_ctx_t;
|
2022-01-06 07:18:22 +00:00
|
|
|
|
2022-01-07 04:49:21 +00:00
|
|
|
struct ResListEntry_t {
|
|
|
|
struct wlr_surface *surf;
|
|
|
|
struct wlr_buffer *buf;
|
|
|
|
};
|
|
|
|
|
2022-01-08 15:32:54 +00:00
|
|
|
struct wlserver_content_override;
|
|
|
|
|
2022-01-06 06:59:58 +00:00
|
|
|
class gamescope_xwayland_server_t
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
gamescope_xwayland_server_t(wl_display *display);
|
|
|
|
~gamescope_xwayland_server_t();
|
|
|
|
|
|
|
|
void on_xwayland_ready(void *data);
|
|
|
|
static void xwayland_ready_callback(struct wl_listener *listener, void *data);
|
|
|
|
|
|
|
|
bool is_xwayland_ready() const;
|
|
|
|
const char *get_nested_display_name() const;
|
|
|
|
|
2022-08-31 01:28:06 +00:00
|
|
|
void set_wl_id( struct wlserver_x11_surface_info *surf, uint32_t id );
|
2022-01-06 06:59:58 +00:00
|
|
|
|
2022-01-06 07:18:22 +00:00
|
|
|
_XDisplay *get_xdisplay();
|
|
|
|
|
2022-01-06 09:02:21 +00:00
|
|
|
std::unique_ptr<xwayland_ctx_t> ctx;
|
|
|
|
|
2022-01-07 04:49:21 +00:00
|
|
|
void wayland_commit(struct wlr_surface *surf, struct wlr_buffer *buf);
|
|
|
|
|
|
|
|
std::vector<ResListEntry_t> retrieve_commits();
|
|
|
|
|
2022-01-08 15:32:54 +00:00
|
|
|
void handle_override_window_content( struct wl_client *client, struct wl_resource *resource, struct wl_resource *surface_resource, uint32_t x11_window );
|
|
|
|
void destroy_content_override(struct wlserver_content_override *co);
|
|
|
|
|
2022-02-06 23:09:32 +00:00
|
|
|
struct wl_client *get_client();
|
2022-07-29 13:38:34 +00:00
|
|
|
struct wlr_output *get_output();
|
|
|
|
|
|
|
|
void update_output_info();
|
2022-02-06 23:09:32 +00:00
|
|
|
|
2022-01-06 06:59:58 +00:00
|
|
|
private:
|
|
|
|
struct wlr_xwayland_server *xwayland_server = NULL;
|
|
|
|
struct wl_listener xwayland_ready_listener = { .notify = xwayland_ready_callback };
|
|
|
|
|
2022-07-29 13:38:34 +00:00
|
|
|
struct wlr_output *output;
|
|
|
|
|
2022-01-08 15:32:54 +00:00
|
|
|
std::map<uint32_t, wlserver_content_override *> content_overrides;
|
|
|
|
|
2022-01-06 06:59:58 +00:00
|
|
|
bool xwayland_ready = false;
|
2022-01-06 07:18:22 +00:00
|
|
|
_XDisplay *dpy = NULL;
|
2022-01-07 04:49:21 +00:00
|
|
|
|
|
|
|
std::mutex wayland_commit_lock;
|
|
|
|
std::vector<ResListEntry_t> wayland_commit_queue;
|
2022-01-06 06:59:58 +00:00
|
|
|
};
|
|
|
|
|
2019-11-21 05:16:53 +00:00
|
|
|
struct wlserver_t {
|
2021-07-27 08:46:03 +00:00
|
|
|
struct wl_display *display;
|
|
|
|
struct wl_event_loop *event_loop;
|
2021-04-28 04:17:36 +00:00
|
|
|
char wl_display_name[32];
|
2019-11-21 05:16:53 +00:00
|
|
|
|
|
|
|
struct {
|
2020-01-17 09:57:39 +00:00
|
|
|
struct wlr_backend *multi_backend;
|
2021-12-20 09:22:17 +00:00
|
|
|
struct wlr_backend *headless_backend;
|
2020-01-17 09:57:39 +00:00
|
|
|
struct wlr_backend *libinput_backend;
|
|
|
|
|
2019-11-21 05:16:53 +00:00
|
|
|
struct wlr_renderer *renderer;
|
|
|
|
struct wlr_compositor *compositor;
|
2022-07-29 13:38:34 +00:00
|
|
|
struct wlr_session *session;
|
2019-11-21 05:16:53 +00:00
|
|
|
struct wlr_seat *seat;
|
2021-09-14 11:47:55 +00:00
|
|
|
|
2021-09-23 08:40:18 +00:00
|
|
|
// Used to simulate key events and set the keymap
|
2022-10-18 23:16:38 +00:00
|
|
|
struct wlr_keyboard *virtual_keyboard_device;
|
2022-01-06 06:59:58 +00:00
|
|
|
|
|
|
|
std::vector<std::unique_ptr<gamescope_xwayland_server_t>> xwayland_servers;
|
2019-11-21 05:16:53 +00:00
|
|
|
} wlr;
|
2020-01-17 09:57:39 +00:00
|
|
|
|
|
|
|
struct wlr_surface *mouse_focus_surface;
|
2022-01-31 20:37:25 +00:00
|
|
|
struct wlr_surface *kb_focus_surface;
|
2020-01-17 09:57:39 +00:00
|
|
|
double mouse_surface_cursorx;
|
|
|
|
double mouse_surface_cursory;
|
|
|
|
|
2020-04-02 02:13:58 +00:00
|
|
|
bool button_held[ WLSERVER_BUTTON_COUNT ];
|
2022-11-25 19:03:55 +00:00
|
|
|
std::set <uint32_t> touch_down_ids;
|
2021-07-27 12:09:04 +00:00
|
|
|
|
2022-07-29 13:38:34 +00:00
|
|
|
struct {
|
|
|
|
char *name;
|
|
|
|
char *description;
|
|
|
|
int phys_width, phys_height; // millimeters
|
|
|
|
} output_info;
|
|
|
|
|
2021-07-27 12:09:04 +00:00
|
|
|
struct wl_listener session_active;
|
2021-09-14 11:53:19 +00:00
|
|
|
struct wl_listener new_input_method;
|
2020-01-17 09:57:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct wlserver_keyboard {
|
2022-10-18 23:16:38 +00:00
|
|
|
struct wlr_keyboard *wlr;
|
2020-01-17 09:57:39 +00:00
|
|
|
|
|
|
|
struct wl_listener modifiers;
|
|
|
|
struct wl_listener key;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct wlserver_pointer {
|
2022-10-18 23:16:38 +00:00
|
|
|
struct wlr_pointer *wlr;
|
2020-01-17 09:57:39 +00:00
|
|
|
|
|
|
|
struct wl_listener motion;
|
|
|
|
struct wl_listener button;
|
2021-09-13 19:29:17 +00:00
|
|
|
struct wl_listener axis;
|
|
|
|
struct wl_listener frame;
|
2020-01-17 09:57:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct wlserver_touch {
|
2022-10-18 23:16:38 +00:00
|
|
|
struct wlr_touch *wlr;
|
2020-01-17 09:57:39 +00:00
|
|
|
|
|
|
|
struct wl_listener down;
|
|
|
|
struct wl_listener up;
|
|
|
|
struct wl_listener motion;
|
2019-11-21 05:16:53 +00:00
|
|
|
};
|
|
|
|
|
2021-06-18 08:44:13 +00:00
|
|
|
enum wlserver_touch_click_mode {
|
|
|
|
WLSERVER_TOUCH_CLICK_HOVER = 0,
|
|
|
|
WLSERVER_TOUCH_CLICK_LEFT = 1,
|
|
|
|
WLSERVER_TOUCH_CLICK_RIGHT = 2,
|
|
|
|
WLSERVER_TOUCH_CLICK_MIDDLE = 3,
|
|
|
|
WLSERVER_TOUCH_CLICK_PASSTHROUGH = 4,
|
2022-04-29 00:59:22 +00:00
|
|
|
WLSERVER_TOUCH_CLICK_DISABLED = 5,
|
2021-06-18 08:44:13 +00:00
|
|
|
};
|
|
|
|
|
2021-10-04 22:00:29 +00:00
|
|
|
extern enum wlserver_touch_click_mode g_nDefaultTouchClickMode;
|
2021-06-18 08:44:13 +00:00
|
|
|
extern enum wlserver_touch_click_mode g_nTouchClickMode;
|
2020-04-02 02:13:58 +00:00
|
|
|
|
2020-01-17 00:43:21 +00:00
|
|
|
void xwayland_surface_role_commit(struct wlr_surface *wlr_surface);
|
|
|
|
|
2021-09-14 14:59:46 +00:00
|
|
|
bool wlsession_init( void );
|
2021-07-27 09:24:04 +00:00
|
|
|
int wlsession_open_kms( const char *device_name );
|
|
|
|
|
2021-09-14 15:03:52 +00:00
|
|
|
bool wlserver_init( void );
|
2019-11-23 06:58:07 +00:00
|
|
|
|
2021-09-10 09:01:54 +00:00
|
|
|
void wlserver_run(void);
|
2019-11-23 07:42:02 +00:00
|
|
|
|
2019-12-31 01:50:22 +00:00
|
|
|
void wlserver_lock(void);
|
|
|
|
void wlserver_unlock(void);
|
|
|
|
|
2020-01-17 09:57:39 +00:00
|
|
|
void wlserver_keyboardfocus( struct wlr_surface *surface );
|
2020-01-18 23:10:14 +00:00
|
|
|
void wlserver_key( uint32_t key, bool press, uint32_t time );
|
2020-01-17 09:57:39 +00:00
|
|
|
|
2021-09-13 06:39:34 +00:00
|
|
|
void wlserver_mousefocus( struct wlr_surface *wlrsurface, int x = 0, int y = 0 );
|
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
|
|
|
void wlserver_mousebutton( int button, bool press, uint32_t time );
|
|
|
|
void wlserver_mousewheel( int x, int y, uint32_t time );
|
|
|
|
|
2022-06-17 23:42:22 +00:00
|
|
|
void wlserver_touchmotion( double x, double y, int touch_id, uint32_t time );
|
|
|
|
void wlserver_touchdown( double x, double y, int touch_id, uint32_t time );
|
|
|
|
void wlserver_touchup( int touch_id, uint32_t time );
|
|
|
|
|
2020-01-23 05:50:01 +00:00
|
|
|
void wlserver_send_frame_done( struct wlr_surface *surf, const struct timespec *when );
|
|
|
|
|
2022-08-31 11:53:11 +00:00
|
|
|
bool wlserver_surface_is_async( struct wlr_surface *surf );
|
|
|
|
|
2022-05-05 10:13:39 +00:00
|
|
|
struct wlserver_output_info {
|
|
|
|
const char *description;
|
|
|
|
int phys_width, phys_height; // millimeters
|
|
|
|
};
|
|
|
|
|
|
|
|
void wlserver_set_output_info( const wlserver_output_info *info );
|
|
|
|
|
2022-01-06 06:59:58 +00:00
|
|
|
gamescope_xwayland_server_t *wlserver_get_xwayland_server( size_t index );
|
2021-04-28 04:17:36 +00:00
|
|
|
const char *wlserver_get_wl_display_name( void );
|
2021-04-01 21:58:33 +00:00
|
|
|
|
2022-08-31 01:28:06 +00:00
|
|
|
struct wlserver_x11_surface_info
|
2021-04-01 21:58:33 +00:00
|
|
|
{
|
|
|
|
std::atomic<struct wlr_surface *> wlr;
|
|
|
|
|
|
|
|
// owned by wlserver
|
2022-07-14 20:44:19 +00:00
|
|
|
uint32_t wl_id, x11_id;
|
2021-02-18 13:59:13 +00:00
|
|
|
bool overridden;
|
2021-04-01 21:58:33 +00:00
|
|
|
struct wl_list pending_link;
|
|
|
|
struct wl_listener destroy;
|
2022-07-14 21:35:19 +00:00
|
|
|
|
|
|
|
gamescope_xwayland_server_t *xwayland_server;
|
2021-04-01 21:58:33 +00:00
|
|
|
};
|
|
|
|
|
2022-08-31 11:44:43 +00:00
|
|
|
struct wlserver_wl_surface_info
|
|
|
|
{
|
|
|
|
wlserver_x11_surface_info *x11_surface = nullptr;
|
|
|
|
struct wlr_surface *wlr = nullptr;
|
|
|
|
struct wl_listener destroy;
|
2022-08-31 11:50:41 +00:00
|
|
|
|
|
|
|
uint32_t presentation_hint = 0;
|
2022-08-31 11:44:43 +00:00
|
|
|
};
|
|
|
|
|
2022-08-31 01:28:06 +00:00
|
|
|
void wlserver_x11_surface_info_init( struct wlserver_x11_surface_info *surf, gamescope_xwayland_server_t *server, uint32_t x11_id );
|
|
|
|
void wlserver_x11_surface_info_finish( struct wlserver_x11_surface_info *surf );
|
2022-02-06 23:09:32 +00:00
|
|
|
|
|
|
|
void wlserver_set_xwayland_server_mode( size_t idx, int w, int h, int refresh );
|
2022-02-10 02:19:08 +00:00
|
|
|
|
|
|
|
extern std::atomic<bool> g_bPendingTouchMovement;
|