gamescope/src/wlserver.hpp

169 lines
4.3 KiB
C++
Raw Normal View History

// 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>
#include <vector>
#include <memory>
#include <mutex>
#include <map>
2019-11-21 05:16:53 +00:00
#define WLSERVER_BUTTON_COUNT 4
#define WLSERVER_TOUCH_COUNT 11 // Ten fingers + nose ought to be enough for anyone
struct _XDisplay;
struct xwayland_ctx_t;
struct ResListEntry_t {
struct wlr_surface *surf;
struct wlr_buffer *buf;
};
struct wlserver_content_override;
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;
void set_wl_id( struct wlserver_surface *surf, long id );
_XDisplay *get_xdisplay();
std::unique_ptr<xwayland_ctx_t> ctx;
void wayland_commit(struct wlr_surface *surf, struct wlr_buffer *buf);
std::vector<ResListEntry_t> retrieve_commits();
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);
private:
struct wlr_xwayland_server *xwayland_server = NULL;
struct wl_listener xwayland_ready_listener = { .notify = xwayland_ready_callback };
std::map<uint32_t, wlserver_content_override *> content_overrides;
bool xwayland_ready = false;
_XDisplay *dpy = NULL;
std::mutex wayland_commit_lock;
std::vector<ResListEntry_t> wayland_commit_queue;
};
2019-11-21 05:16:53 +00:00
struct wlserver_t {
struct wl_display *display;
struct wl_event_loop *event_loop;
char wl_display_name[32];
2019-11-21 05:16:53 +00:00
struct {
struct wlr_backend *multi_backend;
2021-12-20 09:22:17 +00:00
struct wlr_backend *headless_backend;
struct wlr_backend *libinput_backend;
2019-11-21 05:16:53 +00:00
struct wlr_renderer *renderer;
struct wlr_compositor *compositor;
struct wlr_session *session;
struct wlr_seat *seat;
struct wlr_output *output;
// Used to simulate key events and set the keymap
struct wlr_input_device *virtual_keyboard_device;
std::vector<std::unique_ptr<gamescope_xwayland_server_t>> xwayland_servers;
2019-11-21 05:16:53 +00:00
} wlr;
struct wlr_surface *mouse_focus_surface;
double mouse_surface_cursorx;
double mouse_surface_cursory;
bool button_held[ WLSERVER_BUTTON_COUNT ];
bool touch_down[ WLSERVER_TOUCH_COUNT ];
struct wl_listener session_active;
struct wl_listener new_input_method;
};
struct wlserver_keyboard {
struct wlr_input_device *device;
struct wl_listener modifiers;
struct wl_listener key;
};
struct wlserver_pointer {
struct wlr_input_device *device;
struct wl_listener motion;
struct wl_listener button;
2021-09-13 19:29:17 +00:00
struct wl_listener axis;
struct wl_listener frame;
};
struct wlserver_touch {
struct wlr_input_device *device;
struct wl_listener down;
struct wl_listener up;
struct wl_listener motion;
2019-11-21 05:16:53 +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,
};
2021-10-04 22:00:29 +00:00
extern enum wlserver_touch_click_mode g_nDefaultTouchClickMode;
extern enum wlserver_touch_click_mode g_nTouchClickMode;
void xwayland_surface_role_commit(struct wlr_surface *wlr_surface);
bool wlsession_init( void );
int wlsession_open_kms( const char *device_name );
bool wlserver_init( void );
2019-11-23 06:58:07 +00:00
void wlserver_run(void);
void wlserver_lock(void);
void wlserver_unlock(void);
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 );
void wlserver_mousefocus( struct wlr_surface *wlrsurface, int x = 0, int y = 0 );
void wlserver_mousemotion( int x, int y, uint32_t time );
void wlserver_mousebutton( int button, bool press, uint32_t time );
void wlserver_mousewheel( int x, int y, uint32_t time );
2020-01-23 05:50:01 +00:00
void wlserver_send_frame_done( struct wlr_surface *surf, const struct timespec *when );
gamescope_xwayland_server_t *wlserver_get_xwayland_server( size_t index );
const char *wlserver_get_wl_display_name( void );
2021-04-01 21:58:33 +00:00
struct wlserver_surface
{
std::atomic<struct wlr_surface *> wlr;
// owned by wlserver
2021-02-18 13:59:13 +00:00
long wl_id, x11_id;
bool overridden;
2021-04-01 21:58:33 +00:00
struct wl_list pending_link;
struct wl_listener destroy;
};
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
void wlserver_surface_finish( struct wlserver_surface *surf );