From 12a109d3036a64305a06e220c2d13ba760b6956b Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 4 Dec 2022 20:44:05 +0100 Subject: [PATCH] Use XDG decoration protocol. --- profiler/src/BackendWayland.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/profiler/src/BackendWayland.cpp b/profiler/src/BackendWayland.cpp index ac91a961..ae674df7 100644 --- a/profiler/src/BackendWayland.cpp +++ b/profiler/src/BackendWayland.cpp @@ -16,6 +16,7 @@ #include #include "wayland/xdg-activation.h" +#include "wayland/xdg-decoration.h" #include "wayland/xdg-shell.h" #include "Backend.hpp" @@ -42,6 +43,8 @@ static struct wl_surface* s_cursorSurf; static int32_t s_cursorX, s_cursorY; static struct xdg_activation_v1* s_activation; static struct xdg_activation_token_v1* s_actToken; +static struct zxdg_decoration_manager_v1* s_decoration; +static struct zxdg_toplevel_decoration_v1* s_tldec; struct Output { @@ -200,6 +203,15 @@ constexpr struct wl_output_listener outputListener = { }; +static void DecorationConfigure( void*, struct zxdg_toplevel_decoration_v1* tldec, uint32_t mode ) +{ +} + +constexpr struct zxdg_toplevel_decoration_v1_listener decorationListener = { + .configure = DecorationConfigure +}; + + static void RegistryGlobal( void*, struct wl_registry* reg, uint32_t name, const char* interface, uint32_t version ) { if( strcmp( interface, wl_compositor_interface.name ) == 0 ) @@ -231,6 +243,16 @@ static void RegistryGlobal( void*, struct wl_registry* reg, uint32_t name, const wl_output_add_listener( output, &outputListener, ptr.get() ); s_output.emplace( name, std::move( ptr ) ); } + else if( strcmp( interface, zxdg_decoration_manager_v1_interface.name ) == 0 ) + { + s_decoration = (zxdg_decoration_manager_v1*)wl_registry_bind( reg, name, &zxdg_decoration_manager_v1_interface, 1 ); + } + else if( strcmp( interface, zxdg_toplevel_decoration_v1_interface.name ) == 0 ) + { + s_tldec = (zxdg_toplevel_decoration_v1*)wl_registry_bind( reg, name, &zxdg_toplevel_decoration_v1_interface, 1 ); + zxdg_toplevel_decoration_v1_add_listener( s_tldec, &decorationListener, nullptr ); + zxdg_toplevel_decoration_v1_set_mode( s_tldec, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE ); + } } static void RegistryGlobalRemove( void*, struct wl_registry* reg, uint32_t name ) @@ -358,6 +380,12 @@ Backend::Backend( const char* title, std::function redraw, RunQueue* mai xdg_toplevel_set_title( s_toplevel, title ); xdg_toplevel_set_app_id( s_toplevel, "tracy" ); + if( s_decoration ) + { + zxdg_decoration_manager_v1_get_toplevel_decoration( s_decoration, s_toplevel ); + wl_display_roundtrip( s_dpy ); + } + ImGuiIO& io = ImGui::GetIO(); io.BackendPlatformName = "wayland (tracy profiler)"; s_time = std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch() ).count(); @@ -365,6 +393,8 @@ Backend::Backend( const char* title, std::function redraw, RunQueue* mai Backend::~Backend() { + if( s_tldec ) zxdg_toplevel_decoration_v1_destroy( s_tldec ); + if( s_decoration ) zxdg_decoration_manager_v1_destroy( s_decoration ); if( s_actToken ) xdg_activation_token_v1_destroy( s_actToken ); if( s_activation ) xdg_activation_v1_destroy( s_activation ); if( s_pointer ) wl_pointer_destroy( s_pointer );