diff --git a/sunshine/platform/linux/misc.cpp b/sunshine/platform/linux/misc.cpp index 24c8ceb6..ad5afc5a 100644 --- a/sunshine/platform/linux/misc.cpp +++ b/sunshine/platform/linux/misc.cpp @@ -23,6 +23,8 @@ using namespace std::literals; namespace fs = std::filesystem; +window_system_e window_system; + namespace dyn { void *handle(const std::vector &libs) { void *handle; @@ -156,7 +158,7 @@ std::vector wl_display_names(); std::shared_ptr wl_display(mem_type_e hwdevice_type, const std::string &display_name, int framerate); bool verify_wl() { - return !wl_display_names().empty(); + return window_system == window_system_e::WAYLAND && !wl_display_names().empty(); } #endif @@ -174,7 +176,7 @@ std::vector x11_display_names(); std::shared_ptr x11_display(mem_type_e hwdevice_type, const std::string &display_name, int framerate); bool verify_x11() { - return !x11_display_names().empty(); + return window_system == window_system_e::X11 && !x11_display_names().empty(); } #endif @@ -220,6 +222,22 @@ std::unique_ptr init() { // These are allowed to fail. gbm::init(); va::init(); + + window_system = window_system_e::NONE; +#ifdef SUNSHINE_BUILD_WAYLAND + if(std::getenv("WAYLAND_DISPLAY")) { + window_system = window_system_e::WAYLAND; + } +#endif +#ifdef SUNSHINE_BUILD_X11 + if(std::getenv("DISPLAY") && window_system != window_system_e::WAYLAND) { + if(std::getenv("WAYLAND_DISPLAY")) { + BOOST_LOG(warning) << "Wayland detected, yet sunshine will use X11 for screencasting, screencasting will only work on XWayland applications"sv; + } + + window_system = window_system_e::X11; + } +#endif #ifdef SUNSHINE_BUILD_WAYLAND if(verify_wl()) { BOOST_LOG(info) << "Using Wayland for screencasting"sv; @@ -229,6 +247,12 @@ std::unique_ptr init() { #endif #ifdef SUNSHINE_BUILD_DRM if(verify_kms()) { + if(window_system == window_system_e::WAYLAND) { + // On Wayland, using KMS, the cursor is unreliable. + // Hide it by default + display_cursor = false; + } + BOOST_LOG(info) << "Using KMS for screencasting"sv; source = source_e::KMS; goto found_source; diff --git a/sunshine/platform/linux/misc.h b/sunshine/platform/linux/misc.h index cdefff64..432aa9ed 100644 --- a/sunshine/platform/linux/misc.h +++ b/sunshine/platform/linux/misc.h @@ -12,6 +12,14 @@ KITTY_USING_MOVE_T(file_t, int, -1, { } }); +enum class window_system_e { + NONE, + X11, + WAYLAND, +}; + +extern window_system_e window_system; + namespace dyn { typedef void (*apiproc)(void); diff --git a/sunshine/platform/linux/x11grab.cpp b/sunshine/platform/linux/x11grab.cpp index de12f62b..33797f24 100644 --- a/sunshine/platform/linux/x11grab.cpp +++ b/sunshine/platform/linux/x11grab.cpp @@ -756,7 +756,9 @@ int load_xcb() { int load_x11() { // This will be called once only - static int x11_status = x11::init() || x11::rr::init() || x11::fix::init(); + static int x11_status = + window_system == window_system_e::NONE || + x11::init() || x11::rr::init() || x11::fix::init(); return x11_status; }