2024-02-29 14:26:02 +00:00
|
|
|
#include "Popup.hpp"
|
2024-04-03 10:09:42 +01:00
|
|
|
#include "../config/ConfigValue.hpp"
|
2024-03-01 14:07:36 -06:00
|
|
|
#include "../Compositor.hpp"
|
2024-05-09 21:47:21 +01:00
|
|
|
#include "../protocols/LayerShell.hpp"
|
2024-05-10 23:28:33 +01:00
|
|
|
#include "../protocols/XDGShell.hpp"
|
2024-06-08 10:07:59 +02:00
|
|
|
#include "../protocols/core/Compositor.hpp"
|
2024-11-09 02:26:24 +00:00
|
|
|
#include "../managers/SeatManager.hpp"
|
|
|
|
|
#include "../managers/eventLoop/EventLoopManager.hpp"
|
2025-01-17 15:21:35 +00:00
|
|
|
#include "../desktop/LayerSurface.hpp"
|
|
|
|
|
#include "../managers/input/InputManager.hpp"
|
|
|
|
|
#include "../render/Renderer.hpp"
|
|
|
|
|
#include "../render/OpenGL.hpp"
|
2024-05-09 21:47:21 +01:00
|
|
|
#include <ranges>
|
2024-02-29 14:26:02 +00:00
|
|
|
|
2025-02-01 19:10:19 +00:00
|
|
|
UP<CPopup> CPopup::create(PHLWINDOW pOwner) {
|
2025-04-24 20:49:49 +02:00
|
|
|
auto popup = UP<CPopup>(new CPopup());
|
|
|
|
|
popup->m_windowOwner = pOwner;
|
|
|
|
|
popup->m_self = popup;
|
2025-02-01 15:08:30 +00:00
|
|
|
popup->initAllSignals();
|
|
|
|
|
return popup;
|
2024-02-29 14:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-01 19:10:19 +00:00
|
|
|
UP<CPopup> CPopup::create(PHLLS pOwner) {
|
2025-04-24 20:49:49 +02:00
|
|
|
auto popup = UP<CPopup>(new CPopup());
|
|
|
|
|
popup->m_layerOwner = pOwner;
|
|
|
|
|
popup->m_self = popup;
|
2025-02-01 15:08:30 +00:00
|
|
|
popup->initAllSignals();
|
|
|
|
|
return popup;
|
2024-02-29 14:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-01 19:10:19 +00:00
|
|
|
UP<CPopup> CPopup::create(SP<CXDGPopupResource> resource, WP<CPopup> pOwner) {
|
2025-04-24 20:49:49 +02:00
|
|
|
auto popup = UP<CPopup>(new CPopup());
|
|
|
|
|
popup->m_resource = resource;
|
|
|
|
|
popup->m_windowOwner = pOwner->m_windowOwner;
|
|
|
|
|
popup->m_layerOwner = pOwner->m_layerOwner;
|
|
|
|
|
popup->m_parent = pOwner;
|
|
|
|
|
popup->m_self = popup;
|
|
|
|
|
popup->m_wlSurface = CWLSurface::create();
|
|
|
|
|
popup->m_wlSurface->assign(resource->surface->surface.lock(), popup.get());
|
|
|
|
|
|
|
|
|
|
popup->m_lastSize = resource->surface->current.geometry.size();
|
2025-02-01 15:08:30 +00:00
|
|
|
popup->reposition();
|
|
|
|
|
|
|
|
|
|
popup->initAllSignals();
|
|
|
|
|
return popup;
|
2024-02-29 14:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CPopup::~CPopup() {
|
2025-04-24 20:49:49 +02:00
|
|
|
if (m_wlSurface)
|
|
|
|
|
m_wlSurface->unassign();
|
2024-02-29 14:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CPopup::initAllSignals() {
|
|
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!m_resource) {
|
|
|
|
|
if (!m_windowOwner.expired())
|
2025-04-28 22:25:22 +02:00
|
|
|
m_listeners.newPopup = m_windowOwner->m_xdgSurface->events.newPopup.registerListener([this](std::any d) { this->onNewPopup(std::any_cast<SP<CXDGPopupResource>>(d)); });
|
2025-04-24 20:49:49 +02:00
|
|
|
else if (!m_layerOwner.expired())
|
|
|
|
|
m_listeners.newPopup =
|
2025-05-04 00:13:29 +02:00
|
|
|
m_layerOwner->m_layerSurface->m_events.newPopup.registerListener([this](std::any d) { this->onNewPopup(std::any_cast<SP<CXDGPopupResource>>(d)); });
|
2024-02-29 14:26:02 +00:00
|
|
|
else
|
|
|
|
|
ASSERT(false);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
m_listeners.reposition = m_resource->events.reposition.registerListener([this](std::any d) { this->onReposition(); });
|
|
|
|
|
m_listeners.map = m_resource->surface->events.map.registerListener([this](std::any d) { this->onMap(); });
|
|
|
|
|
m_listeners.unmap = m_resource->surface->events.unmap.registerListener([this](std::any d) { this->onUnmap(); });
|
|
|
|
|
m_listeners.dismissed = m_resource->events.dismissed.registerListener([this](std::any d) { this->onUnmap(); });
|
|
|
|
|
m_listeners.destroy = m_resource->surface->events.destroy.registerListener([this](std::any d) { this->onDestroy(); });
|
|
|
|
|
m_listeners.commit = m_resource->surface->events.commit.registerListener([this](std::any d) { this->onCommit(); });
|
|
|
|
|
m_listeners.newPopup = m_resource->surface->events.newPopup.registerListener([this](std::any d) { this->onNewPopup(std::any_cast<SP<CXDGPopupResource>>(d)); });
|
2024-02-29 14:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
2024-05-10 23:28:33 +01:00
|
|
|
void CPopup::onNewPopup(SP<CXDGPopupResource> popup) {
|
2025-04-24 20:49:49 +02:00
|
|
|
const auto& POPUP = m_children.emplace_back(CPopup::create(popup, m_self));
|
|
|
|
|
POPUP->m_self = POPUP;
|
2024-05-10 23:28:33 +01:00
|
|
|
Debug::log(LOG, "New popup at {:x}", (uintptr_t)POPUP);
|
2024-02-29 14:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CPopup::onDestroy() {
|
2025-04-24 20:49:49 +02:00
|
|
|
m_inert = true;
|
2024-02-29 14:26:02 +00:00
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!m_parent)
|
2024-02-29 14:26:02 +00:00
|
|
|
return; // head node
|
|
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
std::erase_if(m_parent->m_children, [this](const auto& other) { return other.get() == this; });
|
2024-02-29 14:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CPopup::onMap() {
|
2025-04-24 20:49:49 +02:00
|
|
|
if (m_mapped)
|
2024-06-05 16:53:06 +02:00
|
|
|
return;
|
|
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
m_mapped = true;
|
2025-05-03 16:02:49 +02:00
|
|
|
m_lastSize = m_resource->surface->surface->m_current.size;
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2024-05-11 01:02:57 +01:00
|
|
|
const auto COORDS = coordsGlobal();
|
|
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromVector(COORDS);
|
2024-02-29 14:26:02 +00:00
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
CBox box = m_wlSurface->resource()->extends();
|
2024-06-08 10:07:59 +02:00
|
|
|
box.translate(COORDS).expand(4);
|
2025-01-26 15:05:34 +00:00
|
|
|
g_pHyprRenderer->damageBox(box);
|
2024-02-29 14:26:02 +00:00
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
m_lastPos = coordsRelativeToParent();
|
2024-02-29 14:26:02 +00:00
|
|
|
|
|
|
|
|
g_pInputManager->simulateMouseMovement();
|
|
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
m_subsurfaceHead = CSubsurface::create(m_self);
|
2024-02-29 14:26:02 +00:00
|
|
|
|
2024-05-11 01:02:57 +01:00
|
|
|
//unconstrain();
|
2024-03-05 20:42:22 +00:00
|
|
|
sendScale();
|
2025-04-30 23:45:20 +02:00
|
|
|
m_resource->surface->surface->enter(PMONITOR->m_self.lock());
|
2024-03-25 16:08:55 +00:00
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!m_layerOwner.expired() && m_layerOwner->m_layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP)
|
|
|
|
|
g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_layerOwner->m_layer));
|
2024-02-29 14:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CPopup::onUnmap() {
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!m_mapped)
|
2024-06-05 16:53:06 +02:00
|
|
|
return;
|
|
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!m_resource || !m_resource->surface) {
|
2024-06-05 16:53:06 +02:00
|
|
|
Debug::log(ERR, "CPopup: orphaned (no surface/resource) and unmaps??");
|
|
|
|
|
onDestroy();
|
2024-05-10 23:28:33 +01:00
|
|
|
return;
|
2024-06-05 16:53:06 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
m_mapped = false;
|
2024-11-09 02:26:24 +00:00
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
m_lastSize = m_resource->surface->surface->m_current.size;
|
2024-06-08 10:07:59 +02:00
|
|
|
|
2024-02-29 14:26:02 +00:00
|
|
|
const auto COORDS = coordsGlobal();
|
|
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
CBox box = m_wlSurface->resource()->extends();
|
2024-06-08 10:07:59 +02:00
|
|
|
box.translate(COORDS).expand(4);
|
2025-01-26 15:05:34 +00:00
|
|
|
g_pHyprRenderer->damageBox(box);
|
2024-02-29 14:26:02 +00:00
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
m_subsurfaceHead.reset();
|
2024-02-29 14:26:02 +00:00
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!m_layerOwner.expired() && m_layerOwner->m_layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP)
|
|
|
|
|
g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_layerOwner->m_layer));
|
2024-05-10 23:28:33 +01:00
|
|
|
|
|
|
|
|
// damage all children
|
|
|
|
|
breadthfirst(
|
2025-01-26 12:54:32 +00:00
|
|
|
[](WP<CPopup> p, void* data) {
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!p->m_resource)
|
2024-05-10 23:28:33 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
auto box = CBox{p->coordsGlobal(), p->size()};
|
2025-01-26 15:05:34 +00:00
|
|
|
g_pHyprRenderer->damageBox(box);
|
2024-05-10 23:28:33 +01:00
|
|
|
},
|
|
|
|
|
nullptr);
|
2024-11-09 02:26:24 +00:00
|
|
|
|
2025-01-29 23:05:54 +00:00
|
|
|
// TODO: probably refocus, but without a motion event?
|
|
|
|
|
// const bool WASLASTFOCUS = g_pSeatManager->state.keyboardFocus == m_pWLSurface->resource() || g_pSeatManager->state.pointerFocus == m_pWLSurface->resource();
|
2024-11-09 02:26:24 +00:00
|
|
|
|
2025-01-29 23:05:54 +00:00
|
|
|
// if (WASLASTFOCUS)
|
|
|
|
|
// g_pInputManager->simulateMouseMovement();
|
2024-02-29 14:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
2024-03-15 15:55:24 +00:00
|
|
|
void CPopup::onCommit(bool ignoreSiblings) {
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!m_resource || !m_resource->surface) {
|
2024-06-05 16:53:06 +02:00
|
|
|
Debug::log(ERR, "CPopup: orphaned (no surface/resource) and commits??");
|
|
|
|
|
onDestroy();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-06-06 20:27:09 +02:00
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
if (m_resource->surface->initialCommit) {
|
|
|
|
|
m_resource->surface->scheduleConfigure();
|
2024-02-29 14:26:02 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-28 22:25:22 +02:00
|
|
|
if (!m_windowOwner.expired() && (!m_windowOwner->m_isMapped || !m_windowOwner->m_workspace->m_visible)) {
|
2025-05-03 16:02:49 +02:00
|
|
|
m_lastSize = m_resource->surface->surface->m_current.size;
|
2024-04-03 10:09:42 +01:00
|
|
|
|
|
|
|
|
static auto PLOGDAMAGE = CConfigValue<Hyprlang::INT>("debug:log_damage");
|
|
|
|
|
if (*PLOGDAMAGE)
|
2025-04-24 20:49:49 +02:00
|
|
|
Debug::log(LOG, "Refusing to commit damage from a subsurface of {} because it's invisible.", m_windowOwner.lock());
|
2024-04-03 10:09:42 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!m_resource->surface->mapped)
|
2024-04-04 16:42:24 +01:00
|
|
|
return;
|
|
|
|
|
|
2024-02-29 14:26:02 +00:00
|
|
|
const auto COORDS = coordsGlobal();
|
|
|
|
|
const auto COORDSLOCAL = coordsRelativeToParent();
|
|
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
if (m_lastSize != m_resource->surface->surface->m_current.size || m_requestedReposition || m_lastPos != COORDSLOCAL) {
|
2025-04-24 20:49:49 +02:00
|
|
|
CBox box = {localToGlobal(m_lastPos), m_lastSize};
|
2025-01-26 15:05:34 +00:00
|
|
|
g_pHyprRenderer->damageBox(box);
|
2025-05-03 16:02:49 +02:00
|
|
|
m_lastSize = m_resource->surface->surface->m_current.size;
|
2025-04-24 20:49:49 +02:00
|
|
|
box = {COORDS, m_lastSize};
|
2025-01-26 15:05:34 +00:00
|
|
|
g_pHyprRenderer->damageBox(box);
|
2024-02-29 14:26:02 +00:00
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
m_lastPos = COORDSLOCAL;
|
2024-02-29 14:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!ignoreSiblings && m_subsurfaceHead)
|
|
|
|
|
m_subsurfaceHead->recheckDamageForSubsurfaces();
|
2024-02-29 14:26:02 +00:00
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
g_pHyprRenderer->damageSurface(m_wlSurface->resource(), COORDS.x, COORDS.y);
|
2024-02-29 14:26:02 +00:00
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
m_requestedReposition = false;
|
2024-03-25 16:08:55 +00:00
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!m_layerOwner.expired() && m_layerOwner->m_layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP)
|
|
|
|
|
g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_layerOwner->m_layer));
|
2024-02-29 14:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CPopup::onReposition() {
|
|
|
|
|
Debug::log(LOG, "Popup {:x} requests reposition", (uintptr_t)this);
|
|
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
m_requestedReposition = true;
|
2024-02-29 14:26:02 +00:00
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
m_lastPos = coordsRelativeToParent();
|
2024-02-29 14:26:02 +00:00
|
|
|
|
2024-07-27 13:43:01 -07:00
|
|
|
reposition();
|
2024-02-29 14:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-27 13:43:01 -07:00
|
|
|
void CPopup::reposition() {
|
2024-02-29 14:26:02 +00:00
|
|
|
const auto COORDS = t1ParentCoords();
|
|
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromVector(COORDS);
|
|
|
|
|
|
|
|
|
|
if (!PMONITOR)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-04-30 23:45:20 +02:00
|
|
|
CBox box = {PMONITOR->m_position.x, PMONITOR->m_position.y, PMONITOR->m_size.x, PMONITOR->m_size.y};
|
2025-04-24 20:49:49 +02:00
|
|
|
m_resource->applyPositioning(box, COORDS);
|
2024-02-29 14:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
2024-09-06 17:06:55 -07:00
|
|
|
SP<CWLSurface> CPopup::getT1Owner() {
|
2025-04-24 20:49:49 +02:00
|
|
|
if (m_windowOwner)
|
2025-04-28 22:25:22 +02:00
|
|
|
return m_windowOwner->m_wlSurface;
|
2024-09-06 17:06:55 -07:00
|
|
|
else
|
2025-04-24 20:49:49 +02:00
|
|
|
return m_layerOwner->m_surface;
|
2024-09-06 17:06:55 -07:00
|
|
|
}
|
|
|
|
|
|
2024-02-29 14:26:02 +00:00
|
|
|
Vector2D CPopup::coordsRelativeToParent() {
|
|
|
|
|
Vector2D offset;
|
|
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!m_resource)
|
2024-05-10 23:28:33 +01:00
|
|
|
return {};
|
|
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
WP<CPopup> current = m_self;
|
|
|
|
|
offset -= current->m_resource->surface->current.geometry.pos();
|
2024-02-29 14:26:02 +00:00
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
while (current->m_parent && current->m_resource) {
|
2024-02-29 14:26:02 +00:00
|
|
|
|
2025-05-03 16:02:49 +02:00
|
|
|
offset += current->m_wlSurface->resource()->m_current.offset;
|
2025-04-24 20:49:49 +02:00
|
|
|
offset += current->m_resource->geometry.pos();
|
2024-02-29 14:26:02 +00:00
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
current = current->m_parent;
|
2024-02-29 14:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector2D CPopup::coordsGlobal() {
|
|
|
|
|
return localToGlobal(coordsRelativeToParent());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector2D CPopup::localToGlobal(const Vector2D& rel) {
|
|
|
|
|
return t1ParentCoords() + rel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector2D CPopup::t1ParentCoords() {
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!m_windowOwner.expired())
|
2025-04-28 22:25:22 +02:00
|
|
|
return m_windowOwner->m_realPosition->value();
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!m_layerOwner.expired())
|
|
|
|
|
return m_layerOwner->m_realPosition->value();
|
2024-02-29 14:26:02 +00:00
|
|
|
|
|
|
|
|
ASSERT(false);
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CPopup::recheckTree() {
|
2025-04-24 20:49:49 +02:00
|
|
|
WP<CPopup> curr = m_self;
|
|
|
|
|
while (curr->m_parent) {
|
|
|
|
|
curr = curr->m_parent;
|
2024-02-29 14:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curr->recheckChildrenRecursive();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CPopup::recheckChildrenRecursive() {
|
2025-04-24 20:49:49 +02:00
|
|
|
if (m_inert || !m_wlSurface)
|
2025-02-17 13:02:32 -05:00
|
|
|
return;
|
|
|
|
|
|
2025-02-01 19:10:19 +00:00
|
|
|
std::vector<WP<CPopup>> cpy;
|
2025-04-24 20:49:49 +02:00
|
|
|
std::ranges::for_each(m_children, [&cpy](const auto& el) { cpy.emplace_back(el); });
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& c : cpy) {
|
2024-03-15 15:55:24 +00:00
|
|
|
c->onCommit(true);
|
2024-02-29 14:26:02 +00:00
|
|
|
c->recheckChildrenRecursive();
|
|
|
|
|
}
|
2024-02-29 15:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector2D CPopup::size() {
|
2025-04-24 20:49:49 +02:00
|
|
|
return m_lastSize;
|
2024-03-01 14:07:36 -06:00
|
|
|
}
|
2024-03-05 20:42:22 +00:00
|
|
|
|
|
|
|
|
void CPopup::sendScale() {
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!m_windowOwner.expired())
|
2025-04-28 22:25:22 +02:00
|
|
|
g_pCompositor->setPreferredScaleForSurface(m_wlSurface->resource(), m_windowOwner->m_wlSurface->m_lastScaleFloat);
|
2025-04-24 20:49:49 +02:00
|
|
|
else if (!m_layerOwner.expired())
|
2025-04-25 02:37:12 +02:00
|
|
|
g_pCompositor->setPreferredScaleForSurface(m_wlSurface->resource(), m_layerOwner->m_surface->m_lastScaleFloat);
|
2024-03-05 20:42:22 +00:00
|
|
|
else
|
|
|
|
|
UNREACHABLE();
|
|
|
|
|
}
|
2024-05-04 23:46:10 +01:00
|
|
|
|
|
|
|
|
bool CPopup::visible() {
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!m_windowOwner.expired())
|
|
|
|
|
return g_pHyprRenderer->shouldRenderWindow(m_windowOwner.lock());
|
|
|
|
|
if (!m_layerOwner.expired())
|
2024-05-04 23:46:10 +01:00
|
|
|
return true;
|
2025-04-24 20:49:49 +02:00
|
|
|
if (m_parent)
|
|
|
|
|
return m_parent->visible();
|
2024-05-04 23:46:10 +01:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-05-09 21:47:21 +01:00
|
|
|
|
2025-01-26 12:54:32 +00:00
|
|
|
void CPopup::bfHelper(std::vector<WP<CPopup>> const& nodes, std::function<void(WP<CPopup>, void*)> fn, void* data) {
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& n : nodes) {
|
2024-05-09 21:47:21 +01:00
|
|
|
fn(n, data);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-26 12:54:32 +00:00
|
|
|
std::vector<WP<CPopup>> nodes2;
|
2024-10-28 19:02:52 +01:00
|
|
|
nodes2.reserve(nodes.size() * 2);
|
2024-05-09 21:47:21 +01:00
|
|
|
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& n : nodes) {
|
2025-04-24 20:49:49 +02:00
|
|
|
for (auto const& c : n->m_children) {
|
|
|
|
|
nodes2.push_back(c->m_self);
|
2024-05-09 21:47:21 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-10 02:28:21 +01:00
|
|
|
if (!nodes2.empty())
|
|
|
|
|
bfHelper(nodes2, fn, data);
|
2024-05-09 21:47:21 +01:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 12:54:32 +00:00
|
|
|
void CPopup::breadthfirst(std::function<void(WP<CPopup>, void*)> fn, void* data) {
|
|
|
|
|
std::vector<WP<CPopup>> popups;
|
2025-04-24 20:49:49 +02:00
|
|
|
popups.push_back(m_self);
|
2024-05-10 02:36:56 +01:00
|
|
|
bfHelper(popups, fn, data);
|
2024-05-09 21:47:21 +01:00
|
|
|
}
|
|
|
|
|
|
2025-01-26 12:54:32 +00:00
|
|
|
WP<CPopup> CPopup::at(const Vector2D& globalCoords, bool allowsInput) {
|
|
|
|
|
std::vector<WP<CPopup>> popups;
|
2025-02-01 15:49:10 +00:00
|
|
|
breadthfirst([&popups](WP<CPopup> popup, void* data) { popups.push_back(popup); }, &popups);
|
2024-05-09 21:47:21 +01:00
|
|
|
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& p : popups | std::views::reverse) {
|
2025-04-24 20:49:49 +02:00
|
|
|
if (!p->m_resource || !p->m_mapped)
|
2024-05-09 21:47:21 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!allowsInput) {
|
2025-04-24 20:49:49 +02:00
|
|
|
const bool HASSURFACE = p->m_resource && p->m_resource->surface;
|
2024-05-11 01:02:57 +01:00
|
|
|
|
2025-04-24 20:49:49 +02:00
|
|
|
Vector2D offset = HASSURFACE ? p->m_resource->surface->current.geometry.pos() : Vector2D{};
|
|
|
|
|
Vector2D size = HASSURFACE ? p->m_resource->surface->current.geometry.size() : p->size();
|
2025-02-06 12:13:35 +00:00
|
|
|
|
|
|
|
|
if (size == Vector2D{})
|
|
|
|
|
size = p->size();
|
|
|
|
|
|
|
|
|
|
const auto BOX = CBox{p->coordsGlobal() + offset, size};
|
2024-05-09 21:47:21 +01:00
|
|
|
if (BOX.containsPoint(globalCoords))
|
|
|
|
|
return p;
|
|
|
|
|
} else {
|
2025-05-03 16:02:49 +02:00
|
|
|
const auto REGION = CRegion{p->m_wlSurface->resource()->m_current.input}.intersect(CBox{{}, p->m_wlSurface->resource()->m_current.size}).translate(p->coordsGlobal());
|
2024-05-09 21:47:21 +01:00
|
|
|
if (REGION.containsPoint(globalCoords))
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-26 12:54:32 +00:00
|
|
|
return {};
|
2024-05-09 21:47:21 +01:00
|
|
|
}
|
2025-02-17 13:02:32 -05:00
|
|
|
|
|
|
|
|
bool CPopup::inert() const {
|
2025-04-24 20:49:49 +02:00
|
|
|
return m_inert;
|
2025-02-17 13:02:32 -05:00
|
|
|
}
|