Hyprland/src/events/Popups.cpp

139 lines
4.7 KiB
C++
Raw Normal View History

2022-03-21 15:17:04 +01:00
#include "Events.hpp"
#include "../Compositor.hpp"
#include "../helpers/WLClasses.hpp"
#include "../managers/InputManager.hpp"
#include "../render/Renderer.hpp"
// --------------------------------------------- //
// _____ ____ _____ _ _ _____ _____ //
// | __ \ / __ \| __ \| | | | __ \ / ____| //
// | |__) | | | | |__) | | | | |__) | (___ //
// | ___/| | | | ___/| | | | ___/ \___ \ //
// | | | |__| | | | |__| | | ____) | //
// |_| \____/|_| \____/|_| |_____/ //
// //
// --------------------------------------------- //
2022-03-27 17:25:20 +02:00
void addPopupGlobalCoords(void* pPopup, int* x, int* y) {
SXDGPopup *const PPOPUP = (SXDGPopup*)pPopup;
int px = 0;
int py = 0;
auto curPopup = PPOPUP;
while (true) {
px += curPopup->popup->geometry.x;
py += curPopup->popup->geometry.y;
if (curPopup->parentPopup) {
curPopup = curPopup->parentPopup;
} else {
break;
}
}
px += *PPOPUP->lx;
py += *PPOPUP->ly;
2022-03-21 15:17:04 +01:00
2022-03-27 17:25:20 +02:00
*x += px;
*y += py;
}
2022-03-21 15:17:04 +01:00
2022-03-27 17:25:20 +02:00
void createNewPopup(wlr_xdg_popup* popup, SXDGPopup* pHyprPopup) {
pHyprPopup->popup = popup;
2022-03-21 15:17:04 +01:00
2022-03-28 22:31:39 +02:00
pHyprPopup->hyprListener_destroyPopupXDG.initCallback(&popup->base->surface->events.destroy, &Events::listener_destroyPopupXDG, pHyprPopup, "HyprPopup");
pHyprPopup->hyprListener_mapPopupXDG.initCallback(&popup->base->events.map, &Events::listener_mapPopupXDG, pHyprPopup, "HyprPopup");
pHyprPopup->hyprListener_unmapPopupXDG.initCallback(&popup->base->events.unmap, &Events::listener_unmapPopupXDG, pHyprPopup, "HyprPopup");
pHyprPopup->hyprListener_newPopupFromPopupXDG.initCallback(&popup->base->events.new_popup, &Events::listener_newPopupFromPopupXDG, pHyprPopup, "HyprPopup");
2022-03-21 15:17:04 +01:00
2022-03-27 17:25:20 +02:00
const auto PMONITOR = g_pCompositor->m_pLastMonitor;
2022-03-21 15:17:04 +01:00
wlr_box box = {.x = PMONITOR->vecPosition.x, .y = PMONITOR->vecPosition.y, .width = PMONITOR->vecSize.x, .height = PMONITOR->vecSize.y};
2022-03-27 17:25:20 +02:00
wlr_xdg_popup_unconstrain_from_box(popup, &box);
2022-03-21 15:17:04 +01:00
}
2022-03-28 22:31:39 +02:00
void Events::listener_newPopup(void* owner, void* data) {
SLayerSurface* layersurface = (SLayerSurface*)owner;
2022-03-21 15:17:04 +01:00
2022-03-24 21:34:24 +01:00
Debug::log(LOG, "New layer popup created from surface %x", layersurface);
2022-03-21 15:17:04 +01:00
const auto WLRPOPUP = (wlr_xdg_popup*)data;
g_pCompositor->m_lXDGPopups.push_back(SXDGPopup());
const auto PNEWPOPUP = &g_pCompositor->m_lXDGPopups.back();
2022-03-27 17:25:20 +02:00
PNEWPOPUP->popup = WLRPOPUP;
PNEWPOPUP->lx = &layersurface->position.x;
PNEWPOPUP->ly = &layersurface->position.y;
createNewPopup(WLRPOPUP, PNEWPOPUP);
2022-03-21 15:17:04 +01:00
}
2022-03-28 22:31:39 +02:00
void Events::listener_newPopupXDG(void* owner, void* data) {
CWindow* PWINDOW = (CWindow*)owner;
2022-03-21 15:17:04 +01:00
2022-03-24 21:34:24 +01:00
Debug::log(LOG, "New layer popup created from XDG window %x -> %s", PWINDOW, PWINDOW->m_szTitle.c_str());
2022-03-21 15:17:04 +01:00
const auto WLRPOPUP = (wlr_xdg_popup*)data;
2022-03-27 17:25:20 +02:00
g_pCompositor->m_lXDGPopups.push_back(SXDGPopup());
const auto PNEWPOPUP = &g_pCompositor->m_lXDGPopups.back();
PNEWPOPUP->popup = WLRPOPUP;
PNEWPOPUP->lx = &PWINDOW->m_vEffectivePosition.x;
PNEWPOPUP->ly = &PWINDOW->m_vEffectivePosition.y;
2022-03-31 21:55:21 +02:00
PNEWPOPUP->parentWindow = PWINDOW;
2022-03-27 17:25:20 +02:00
createNewPopup(WLRPOPUP, PNEWPOPUP);
2022-03-21 15:17:04 +01:00
}
2022-03-28 22:31:39 +02:00
void Events::listener_newPopupFromPopupXDG(void* owner, void* data) {
SXDGPopup* PPOPUP = (SXDGPopup*)owner;
2022-03-21 15:17:04 +01:00
2022-03-24 21:34:24 +01:00
Debug::log(LOG, "New layer popup created from XDG popup %x -> %s", PPOPUP, PPOPUP->parentWindow->m_szTitle.c_str());
2022-03-21 15:17:04 +01:00
const auto WLRPOPUP = (wlr_xdg_popup*)data;
2022-03-27 17:25:20 +02:00
g_pCompositor->m_lXDGPopups.push_back(SXDGPopup());
const auto PNEWPOPUP = &g_pCompositor->m_lXDGPopups.back();
PNEWPOPUP->popup = WLRPOPUP;
PNEWPOPUP->parentPopup = PPOPUP;
PNEWPOPUP->lx = PPOPUP->lx;
PNEWPOPUP->ly = PPOPUP->ly;
createNewPopup(WLRPOPUP, PNEWPOPUP);
2022-03-21 15:17:04 +01:00
}
2022-03-28 22:31:39 +02:00
void Events::listener_mapPopupXDG(void* owner, void* data) {
SXDGPopup* PPOPUP = (SXDGPopup*)owner;
2022-03-27 17:25:20 +02:00
2022-03-24 21:34:24 +01:00
Debug::log(LOG, "New XDG Popup mapped");
2022-03-27 17:25:20 +02:00
PPOPUP->pSurfaceTree = SubsurfaceTree::createTreeRoot(PPOPUP->popup->base->surface, addPopupGlobalCoords, PPOPUP);
2022-03-28 21:16:23 +02:00
Debug::log(LOG, "XDG Popup got assigned a surfaceTreeNode %x", PPOPUP->pSurfaceTree);
2022-03-21 15:17:04 +01:00
}
2022-03-28 22:31:39 +02:00
void Events::listener_unmapPopupXDG(void* owner, void* data) {
SXDGPopup* PPOPUP = (SXDGPopup*)owner;
2022-03-24 21:34:24 +01:00
Debug::log(LOG, "XDG Popup unmapped");
2022-03-27 17:25:20 +02:00
SubsurfaceTree::destroySurfaceTree(PPOPUP->pSurfaceTree);
PPOPUP->pSurfaceTree = nullptr;
2022-03-21 15:17:04 +01:00
}
2022-03-28 22:31:39 +02:00
void Events::listener_destroyPopupXDG(void* owner, void* data) {
SXDGPopup* PPOPUP = (SXDGPopup*)owner;
2022-03-21 15:17:04 +01:00
2022-03-24 21:34:24 +01:00
Debug::log(LOG, "Destroyed popup XDG %x", PPOPUP);
2022-03-27 17:25:20 +02:00
if (PPOPUP->pSurfaceTree) {
SubsurfaceTree::destroySurfaceTree(PPOPUP->pSurfaceTree);
PPOPUP->pSurfaceTree = nullptr;
}
2022-03-21 15:17:04 +01:00
g_pCompositor->m_lXDGPopups.remove(*PPOPUP);
}