From 7cfca3f8c261cd6efc2d2f8000da2596b500a034 Mon Sep 17 00:00:00 2001 From: flightlessmango Date: Tue, 16 Jul 2024 13:02:53 +0200 Subject: [PATCH] param: display_server This option shows wether the app is native wayland, running under xwayland or regular X11 --- src/hud_elements.cpp | 19 ++++++++++++++++++- src/hud_elements.h | 11 +++++++++++ src/loaders/loader_x11.cpp | 9 +++++++++ src/loaders/loader_x11.h | 1 + src/overlay_params.h | 1 + src/shared_x11.cpp | 10 ++++++++++ src/vulkan.cpp | 1 + src/wayland_hook.cpp | 3 +++ 8 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/hud_elements.cpp b/src/hud_elements.cpp index 41e3f4e..5a4a665 100644 --- a/src/hud_elements.cpp +++ b/src/hud_elements.cpp @@ -1475,6 +1475,20 @@ void HudElements::network() { #endif } +void HudElements::_display_session() { + ImGui::PushFont(HUDElements.sw_stats->font1); + ImguiNextColumnFirstItem(); + HUDElements.TextColored(HUDElements.colors.engine, "%s", "display server"); + ImguiNextColumnOrNewRow(); + static std::map servers { + {WAYLAND, {"WAYLAND"}}, + {XWAYLAND, {"XWAYLAND"}}, + {XORG, {"XORG"}} + }; + right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%s", servers[HUDElements.display_server].c_str()); + ImGui::PopFont(); +} + void HudElements::sort_elements(const std::pair& option) { const auto& param = option.first; const auto& value = option.second; @@ -1522,7 +1536,8 @@ void HudElements::sort_elements(const std::pair& optio {"refresh_rate", {refresh_rate}}, {"winesync", {winesync}}, {"present_mode", {present_mode}}, - {"network", {network}} + {"network", {network}}, + {"display_session", {_display_session}} }; @@ -1650,6 +1665,8 @@ void HudElements::legacy_elements(){ ordered_functions.push_back({present_mode, "present_mode", value}); if (params->enabled[OVERLAY_PARAM_ENABLED_refresh_rate]) ordered_functions.push_back({refresh_rate, "refresh_rate", value}); + if (params->enabled[OVERLAY_PARAM_ENABLED_display_server]) + ordered_functions.push_back({_display_session, "display_session", value}); } void HudElements::update_exec(){ diff --git a/src/hud_elements.h b/src/hud_elements.h index 08c3b7e..8860c90 100644 --- a/src/hud_elements.h +++ b/src/hud_elements.h @@ -11,6 +11,7 @@ #include "net.h" #include "overlay_params.h" #include "shell.h" +#include "shared_x11.h" struct Function { std::function run; // Using std::function instead of a raw function pointer for more flexibility @@ -53,6 +54,15 @@ class HudElements{ int hdr_status = 0; int refresh = 0; unsigned int vsync = 10; + + enum display_servers { + UNKNOWN, + WAYLAND, + XWAYLAND, + XORG + }; + + display_servers display_server = UNKNOWN; std::unique_ptr winesync_ptr = nullptr; std::unique_ptr net = nullptr; #ifdef __linux__ @@ -104,6 +114,7 @@ class HudElements{ static void winesync(); static void present_mode(); static void network(); + static void _display_session(); void convert_colors(const struct overlay_params& params); void convert_colors(bool do_conv, const struct overlay_params& params); diff --git a/src/loaders/loader_x11.cpp b/src/loaders/loader_x11.cpp index dc59927..214fd50 100644 --- a/src/loaders/loader_x11.cpp +++ b/src/loaders/loader_x11.cpp @@ -77,6 +77,14 @@ bool libx11_loader::Load(const std::string& library_name) { return false; } + XQueryExtension = + reinterpret_castXQueryExtension)>( + dlsym(library_, "XQueryExtension")); + if (!XQueryExtension) { + CleanUp(true); + return false; + } + loaded_ = true; return true; } @@ -94,6 +102,7 @@ void libx11_loader::CleanUp(bool unload) { XKeysymToKeycode = NULL; XStringToKeysym = NULL; XGetGeometry = NULL; + XQueryExtension = NULL; } diff --git a/src/loaders/loader_x11.h b/src/loaders/loader_x11.h index 8861985..c6e2054 100644 --- a/src/loaders/loader_x11.h +++ b/src/loaders/loader_x11.h @@ -21,6 +21,7 @@ class libx11_loader { decltype(&::XKeysymToKeycode) XKeysymToKeycode; decltype(&::XStringToKeysym) XStringToKeysym; decltype(&::XGetGeometry) XGetGeometry; + decltype(&::XQueryExtension) XQueryExtension; private: diff --git a/src/overlay_params.h b/src/overlay_params.h index dbf2683..1ed33ed 100644 --- a/src/overlay_params.h +++ b/src/overlay_params.h @@ -114,6 +114,7 @@ typedef unsigned long KeySym; OVERLAY_PARAM_BOOL(winesync) \ OVERLAY_PARAM_BOOL(present_mode) \ OVERLAY_PARAM_BOOL(time_no_label) \ + OVERLAY_PARAM_BOOL(display_server) \ OVERLAY_PARAM_CUSTOM(fps_sampling_period) \ OVERLAY_PARAM_CUSTOM(output_folder) \ OVERLAY_PARAM_CUSTOM(output_file) \ diff --git a/src/shared_x11.cpp b/src/shared_x11.cpp index 2122310..4a22483 100644 --- a/src/shared_x11.cpp +++ b/src/shared_x11.cpp @@ -5,6 +5,7 @@ #include #include "shared_x11.h" #include "loaders/loader_x11.h" +#include "hud_elements.h" static std::unique_ptr> display; @@ -41,6 +42,15 @@ bool init_x11() { if (!displayid) SPDLOG_DEBUG("DISPLAY env is not set"); + if (display && HUDElements.display_server == HUDElements.display_servers::UNKNOWN) { + int opcode, event, error; + if (libx11->XQueryExtension(display.get(), "XWAYLAND", &opcode, &event, &error)) + HUDElements.display_server = HUDElements.display_servers::XWAYLAND; + else + HUDElements.display_server = HUDElements.display_servers::XORG; + + } + return !!display; } diff --git a/src/vulkan.cpp b/src/vulkan.cpp index f205b80..4dcc600 100644 --- a/src/vulkan.cpp +++ b/src/vulkan.cpp @@ -2045,6 +2045,7 @@ static VkResult overlay_CreateWaylandSurfaceKHR( if (!wl_handle) wl_handle = real_dlopen("libwayland-client.so", RTLD_LAZY); wl_display_ptr = pCreateInfo->display; + HUDElements.display_server = HUDElements.display_servers::WAYLAND; init_wayland_data(); return instance_data->vtable.CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); } diff --git a/src/wayland_hook.cpp b/src/wayland_hook.cpp index b6c05e9..98bbc2f 100644 --- a/src/wayland_hook.cpp +++ b/src/wayland_hook.cpp @@ -4,6 +4,7 @@ #include #include "real_dlsym.h" #include "wayland_hook.h" +#include "hud_elements.h" EXPORT_C_(struct wl_display*) wl_display_connect(const char *name); EXPORT_C_(struct wl_display*) wl_display_connect_to_fd(int fd); @@ -32,6 +33,7 @@ EXPORT_C_(struct wl_display*) wl_display_connect(const char *name) if (!wl_display_ptr) { wl_display_ptr = ret; + HUDElements.display_server = HUDElements.display_servers::WAYLAND; init_wayland_data(); } } @@ -55,6 +57,7 @@ EXPORT_C_(struct wl_display*) wl_display_connect_to_fd(int fd) if (!wl_display_ptr) { wl_display_ptr = ret; + HUDElements.display_server = HUDElements.display_servers::WAYLAND; init_wayland_data(); } }