gamescope/src/wlserver.hpp

245 lines
6.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>
#include <set>
#include <optional>
#include <vulkan/vulkan_core.h>
2019-11-21 05:16:53 +00:00
2022-12-18 10:22:01 +00:00
#include "drm.hpp"
#define WLSERVER_BUTTON_COUNT 4
struct _XDisplay;
struct xwayland_ctx_t;
struct wlserver_vk_swapchain_feedback
{
2022-12-18 10:22:01 +00:00
~wlserver_vk_swapchain_feedback()
{
drm_destroy_hdr_metadata_blob( &g_DRM, hdr_metadata_blob );
}
uint32_t image_count;
VkFormat vk_format;
VkColorSpaceKHR vk_colorspace;
VkCompositeAlphaFlagBitsKHR vk_composite_alpha;
VkSurfaceTransformFlagBitsKHR vk_pre_transform;
VkPresentModeKHR vk_present_mode;
VkBool32 vk_clipped;
2022-12-18 10:22:01 +00:00
uint32_t hdr_metadata_blob;
};
struct ResListEntry_t {
struct wlr_surface *surf;
struct wlr_buffer *buf;
bool async;
std::shared_ptr<wlserver_vk_swapchain_feedback> feedback;
};
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_x11_surface_info *surf, uint32_t 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);
struct wl_client *get_client();
struct wlr_output *get_output();
void update_output_info();
private:
struct wlr_xwayland_server *xwayland_server = NULL;
struct wl_listener xwayland_ready_listener = { .notify = xwayland_ready_callback };
struct wlr_output *output;
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;
2019-11-21 05:16:53 +00:00
struct wlr_seat *seat;
// Used to simulate key events and set the keymap
struct wlr_keyboard *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;
struct wlr_surface *kb_focus_surface;
double mouse_surface_cursorx;
double mouse_surface_cursory;
bool button_held[ WLSERVER_BUTTON_COUNT ];
std::set <uint32_t> touch_down_ids;
struct {
char *name;
char *description;
int phys_width, phys_height; // millimeters
} output_info;
struct wl_listener session_active;
struct wl_listener new_input_method;
};
struct wlserver_keyboard {
struct wlr_keyboard *wlr;
struct wl_listener modifiers;
struct wl_listener key;
};
struct wlserver_pointer {
struct wlr_pointer *wlr;
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_touch *wlr;
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,
WLSERVER_TOUCH_CLICK_DISABLED = 5,
};
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_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 );
2022-10-21 23:12:25 +00:00
void wlserver_mousewarp( 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 );
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 );
bool wlserver_surface_is_async( struct wlr_surface *surf );
const std::shared_ptr<wlserver_vk_swapchain_feedback>& wlserver_surface_swapchain_feedback( 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 );
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_x11_surface_info
2021-04-01 21:58:33 +00:00
{
std::atomic<struct wlr_surface *> override_surface;
std::atomic<struct wlr_surface *> main_surface;
struct wlr_surface *current_surface()
{
if ( override_surface )
return override_surface;
return main_surface;
}
2021-04-01 21:58:33 +00:00
// owned by wlserver
uint32_t wl_id, x11_id;
2021-04-01 21:58:33 +00:00
struct wl_list pending_link;
gamescope_xwayland_server_t *xwayland_server;
2021-04-01 21:58:33 +00:00
};
struct wlserver_wl_surface_info
{
wlserver_x11_surface_info *x11_surface = nullptr;
struct wlr_surface *wlr = nullptr;
struct wl_listener commit;
struct wl_listener destroy;
2022-08-31 11:50:41 +00:00
uint32_t presentation_hint = 0;
std::shared_ptr<wlserver_vk_swapchain_feedback> swapchain_feedback = {};
};
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 );
void wlserver_set_xwayland_server_mode( size_t idx, int w, int h, int refresh );
extern std::atomic<bool> g_bPendingTouchMovement;