From 35368ac32021c6c65ecac82357c91bfbb69d6776 Mon Sep 17 00:00:00 2001 From: Campbell Jones Date: Sun, 7 Jul 2024 13:28:56 -0400 Subject: [PATCH] Allow layer surfaces and subsurface to request activation --- src/server.cpp | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index 804f7b0b3..9787f7168 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -34,6 +34,21 @@ #include #include "wlr-wrap-end.hpp" +static wlr_layer_surface_v1* find_subsurface_parent_layer(const wlr_subsurface* subsurface) { + wlr_surface* parent = subsurface->parent; + wlr_subsurface* parent_as_subsurface = wlr_subsurface_try_from_wlr_surface(parent); + wlr_layer_surface_v1* parent_as_layer_surface = wlr_layer_surface_v1_try_from_wlr_surface(parent); + + // traverse up the tree to find the root parent surface + while (parent_as_subsurface != nullptr) { + parent = parent_as_subsurface->parent; + parent_as_subsurface = wlr_subsurface_try_from_wlr_surface(parent); + parent_as_layer_surface = wlr_layer_surface_v1_try_from_wlr_surface(parent); + } + + return parent_as_layer_surface; +} + void Server::focus_view(std::shared_ptr&& view) { auto layer = this->focused_layer.lock(); if (layer != nullptr) { @@ -261,13 +276,32 @@ static void request_activation_notify(wl_listener* listener, void* data) { const auto* event = static_cast(data); const auto* xdg_surface = wlr_xdg_surface_try_from_wlr_surface(event->surface); - if (xdg_surface == nullptr) { + if (xdg_surface != nullptr) { + auto* view = dynamic_cast(static_cast(xdg_surface->surface->data)); + if (view != nullptr && xdg_surface->surface->mapped) { + server.focus_view(std::dynamic_pointer_cast(view->shared_from_this())); + } return; } - auto* view = dynamic_cast(static_cast(xdg_surface->surface->data)); - if (view != nullptr && xdg_surface->surface->mapped) { - server.focus_view(std::dynamic_pointer_cast(view->shared_from_this())); + const auto* layer_surface = wlr_layer_surface_v1_try_from_wlr_surface(event->surface); + if (layer_surface != nullptr) { + auto* layer = dynamic_cast(static_cast(layer_surface->surface->data)); + if (layer != nullptr && layer_surface->surface->mapped) { + server.focus_layer(std::dynamic_pointer_cast(layer->shared_from_this())); + } + return; + } + + const auto* subsurface = wlr_subsurface_try_from_wlr_surface(event->surface); + if (subsurface != nullptr) { + wlr_layer_surface_v1* parent_as_layer_surface = find_subsurface_parent_layer(subsurface); + if (parent_as_layer_surface != nullptr) { + auto* layer = dynamic_cast(static_cast(layer_surface->surface->data)); + if (layer != nullptr && parent_as_layer_surface->surface->mapped) { + server.focus_layer(std::dynamic_pointer_cast(layer->shared_from_this())); + } + } } }