2022-06-30 12:09:05 +02:00
|
|
|
#include "IHyprLayout.hpp"
|
|
|
|
#include "../defines.hpp"
|
|
|
|
#include "../Compositor.hpp"
|
|
|
|
|
2023-09-13 12:13:29 +02:00
|
|
|
void IHyprLayout::onWindowCreated(CWindow* pWindow, eDirection direction) {
|
2022-06-30 12:09:05 +02:00
|
|
|
if (pWindow->m_bIsFloating) {
|
|
|
|
onWindowCreatedFloating(pWindow);
|
|
|
|
} else {
|
2022-08-05 17:52:14 +02:00
|
|
|
wlr_box desiredGeometry = {0};
|
|
|
|
g_pXWaylandManager->getGeometryForWindow(pWindow, &desiredGeometry);
|
|
|
|
|
|
|
|
if (desiredGeometry.width <= 5 || desiredGeometry.height <= 5) {
|
2022-12-16 18:17:31 +01:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
|
2022-08-05 17:52:14 +02:00
|
|
|
pWindow->m_vLastFloatingSize = PMONITOR->vecSize / 2.f;
|
|
|
|
} else {
|
|
|
|
pWindow->m_vLastFloatingSize = Vector2D(desiredGeometry.width, desiredGeometry.height);
|
|
|
|
}
|
|
|
|
|
2023-06-30 11:29:02 +02:00
|
|
|
pWindow->m_vPseudoSize = pWindow->m_vLastFloatingSize;
|
|
|
|
|
2023-09-13 12:13:29 +02:00
|
|
|
onWindowCreatedTiling(pWindow, direction);
|
2022-06-30 12:09:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IHyprLayout::onWindowRemoved(CWindow* pWindow) {
|
2022-12-07 19:55:56 +01:00
|
|
|
if (pWindow->m_bIsFullscreen)
|
|
|
|
g_pCompositor->setWindowFullscreen(pWindow, false, FULLSCREEN_FULL);
|
|
|
|
|
2023-02-19 22:07:32 +01:00
|
|
|
if (pWindow->m_sGroupData.pNextWindow) {
|
|
|
|
if (pWindow->m_sGroupData.pNextWindow == pWindow)
|
|
|
|
pWindow->m_sGroupData.pNextWindow = nullptr;
|
|
|
|
else {
|
|
|
|
// find last window and update
|
2023-09-04 15:13:39 +02:00
|
|
|
CWindow* PWINDOWPREV = pWindow->getGroupPrevious();
|
|
|
|
const auto WINDOWISVISIBLE = pWindow->getGroupCurrent() == pWindow;
|
2023-02-19 22:07:32 +01:00
|
|
|
|
2023-09-04 15:13:39 +02:00
|
|
|
if (WINDOWISVISIBLE)
|
|
|
|
PWINDOWPREV->setGroupCurrent(PWINDOWPREV);
|
2023-02-19 22:07:32 +01:00
|
|
|
|
2023-09-04 15:13:39 +02:00
|
|
|
PWINDOWPREV->m_sGroupData.pNextWindow = pWindow->m_sGroupData.pNextWindow;
|
2023-02-19 22:07:32 +01:00
|
|
|
|
|
|
|
pWindow->m_sGroupData.pNextWindow = nullptr;
|
|
|
|
|
|
|
|
if (pWindow->m_sGroupData.head) {
|
2023-09-04 15:13:39 +02:00
|
|
|
std::swap(PWINDOWPREV->m_sGroupData.head, pWindow->m_sGroupData.head);
|
|
|
|
std::swap(PWINDOWPREV->m_sGroupData.locked, pWindow->m_sGroupData.locked);
|
2023-02-19 22:07:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pWindow == m_pLastTiledWindow)
|
|
|
|
m_pLastTiledWindow = nullptr;
|
|
|
|
|
2023-02-20 00:26:36 +01:00
|
|
|
pWindow->setHidden(false);
|
|
|
|
|
2023-08-30 17:39:22 +02:00
|
|
|
pWindow->updateWindowDecos();
|
2023-09-04 15:13:39 +02:00
|
|
|
PWINDOWPREV->getGroupCurrent()->updateWindowDecos();
|
2023-08-30 17:39:22 +02:00
|
|
|
g_pCompositor->updateWindowAnimatedDecorationValues(pWindow);
|
|
|
|
|
2023-02-19 22:07:32 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-30 12:09:05 +02:00
|
|
|
if (pWindow->m_bIsFloating) {
|
|
|
|
onWindowRemovedFloating(pWindow);
|
|
|
|
} else {
|
|
|
|
onWindowRemovedTiling(pWindow);
|
|
|
|
}
|
2022-10-24 13:25:36 +02:00
|
|
|
|
|
|
|
if (pWindow == m_pLastTiledWindow)
|
|
|
|
m_pLastTiledWindow = nullptr;
|
2022-06-30 12:09:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void IHyprLayout::onWindowRemovedFloating(CWindow* pWindow) {
|
|
|
|
return; // no-op
|
|
|
|
}
|
|
|
|
|
|
|
|
void IHyprLayout::onWindowCreatedFloating(CWindow* pWindow) {
|
2023-08-17 10:13:19 +02:00
|
|
|
|
2022-06-30 12:09:05 +02:00
|
|
|
wlr_box desiredGeometry = {0};
|
|
|
|
g_pXWaylandManager->getGeometryForWindow(pWindow, &desiredGeometry);
|
2023-08-15 20:09:32 +02:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
|
|
|
|
|
|
|
|
if (pWindow->m_bIsX11) {
|
|
|
|
Vector2D xy = {desiredGeometry.x, desiredGeometry.y};
|
|
|
|
xy = g_pXWaylandManager->xwaylandToWaylandCoords(xy);
|
|
|
|
desiredGeometry.x = xy.x;
|
|
|
|
desiredGeometry.y = xy.y;
|
|
|
|
}
|
2023-06-22 21:43:31 +02:00
|
|
|
|
|
|
|
static auto* const PXWLFORCESCALEZERO = &g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling")->intValue;
|
2022-06-30 12:09:05 +02:00
|
|
|
|
|
|
|
if (!PMONITOR) {
|
2023-09-20 17:25:03 +02:00
|
|
|
Debug::log(ERR, "{:m} has an invalid monitor in onWindowCreatedFloating!!!", pWindow);
|
2022-06-30 12:09:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-18 13:14:31 +02:00
|
|
|
if (desiredGeometry.width <= 5 || desiredGeometry.height <= 5) {
|
2023-03-20 16:00:58 +01:00
|
|
|
const auto PWINDOWSURFACE = pWindow->m_pWLSurface.wlr();
|
2022-12-16 18:17:31 +01:00
|
|
|
pWindow->m_vRealSize = Vector2D(PWINDOWSURFACE->current.width, PWINDOWSURFACE->current.height);
|
2022-07-28 15:40:06 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
if ((desiredGeometry.width <= 1 || desiredGeometry.height <= 1) && pWindow->m_bIsX11 &&
|
|
|
|
pWindow->m_iX11Type == 2) { // XDG windows should be fine. TODO: check for weird atoms?
|
2022-10-14 21:46:32 +02:00
|
|
|
pWindow->setHidden(true);
|
2022-07-28 15:40:06 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2022-07-18 13:14:31 +02:00
|
|
|
// reject any windows with size <= 5x5
|
2023-07-01 16:28:17 +02:00
|
|
|
if (pWindow->m_vRealSize.goalv().x <= 5 || pWindow->m_vRealSize.goalv().y <= 5)
|
2022-07-18 13:14:31 +02:00
|
|
|
pWindow->m_vRealSize = PMONITOR->vecSize / 2.f;
|
2022-06-30 12:09:05 +02:00
|
|
|
|
2023-02-03 22:09:11 +01:00
|
|
|
if (pWindow->m_bIsX11 && pWindow->m_uSurface.xwayland->override_redirect) {
|
|
|
|
|
|
|
|
if (pWindow->m_uSurface.xwayland->x != 0 && pWindow->m_uSurface.xwayland->y != 0)
|
2023-08-15 20:09:32 +02:00
|
|
|
pWindow->m_vRealPosition = g_pXWaylandManager->xwaylandToWaylandCoords({pWindow->m_uSurface.xwayland->x, pWindow->m_uSurface.xwayland->y});
|
2023-02-03 22:09:11 +01:00
|
|
|
else
|
|
|
|
pWindow->m_vRealPosition = Vector2D(PMONITOR->vecPosition.x + (PMONITOR->vecSize.x - pWindow->m_vRealSize.goalv().x) / 2.f,
|
|
|
|
PMONITOR->vecPosition.y + (PMONITOR->vecSize.y - pWindow->m_vRealSize.goalv().y) / 2.f);
|
|
|
|
} else {
|
|
|
|
pWindow->m_vRealPosition = Vector2D(PMONITOR->vecPosition.x + (PMONITOR->vecSize.x - pWindow->m_vRealSize.goalv().x) / 2.f,
|
|
|
|
PMONITOR->vecPosition.y + (PMONITOR->vecSize.y - pWindow->m_vRealSize.goalv().y) / 2.f);
|
|
|
|
}
|
2022-06-30 12:09:05 +02:00
|
|
|
} else {
|
|
|
|
// we respect the size.
|
|
|
|
pWindow->m_vRealSize = Vector2D(desiredGeometry.width, desiredGeometry.height);
|
|
|
|
|
|
|
|
// check if it's on the correct monitor!
|
|
|
|
Vector2D middlePoint = Vector2D(desiredGeometry.x, desiredGeometry.y) + Vector2D(desiredGeometry.width, desiredGeometry.height) / 2.f;
|
|
|
|
|
2022-09-13 22:23:48 +02:00
|
|
|
// check if it's visible on any monitor (only for XDG)
|
|
|
|
bool visible = pWindow->m_bIsX11;
|
2022-09-13 12:29:56 +02:00
|
|
|
|
2023-08-25 18:10:12 +02:00
|
|
|
if (!visible) {
|
|
|
|
visible = g_pCompositor->isPointOnAnyMonitor(Vector2D(desiredGeometry.x, desiredGeometry.y)) &&
|
|
|
|
g_pCompositor->isPointOnAnyMonitor(Vector2D(desiredGeometry.x + desiredGeometry.width, desiredGeometry.y)) &&
|
|
|
|
g_pCompositor->isPointOnAnyMonitor(Vector2D(desiredGeometry.x, desiredGeometry.y + desiredGeometry.height)) &&
|
|
|
|
g_pCompositor->isPointOnAnyMonitor(Vector2D(desiredGeometry.x + desiredGeometry.width, desiredGeometry.y + desiredGeometry.height));
|
2022-09-13 12:29:56 +02:00
|
|
|
}
|
|
|
|
|
2022-06-30 12:09:05 +02:00
|
|
|
// TODO: detect a popup in a more consistent way.
|
2023-09-03 13:07:40 +02:00
|
|
|
if ((desiredGeometry.x == 0 && desiredGeometry.y == 0) || !visible || !pWindow->m_bIsX11) {
|
2022-06-30 12:09:05 +02:00
|
|
|
// if it's not, fall back to the center placement
|
|
|
|
pWindow->m_vRealPosition = PMONITOR->vecPosition + Vector2D((PMONITOR->vecSize.x - desiredGeometry.width) / 2.f, (PMONITOR->vecSize.y - desiredGeometry.height) / 2.f);
|
|
|
|
} else {
|
|
|
|
// if it is, we respect where it wants to put itself, but apply monitor offset if outside
|
|
|
|
// most of these are popups
|
|
|
|
|
2023-07-01 16:28:17 +02:00
|
|
|
if (const auto POPENMON = g_pCompositor->getMonitorFromVector(middlePoint); POPENMON->ID != PMONITOR->ID)
|
2022-06-30 12:09:05 +02:00
|
|
|
pWindow->m_vRealPosition = Vector2D(desiredGeometry.x, desiredGeometry.y) - POPENMON->vecPosition + PMONITOR->vecPosition;
|
2023-07-01 16:28:17 +02:00
|
|
|
else
|
2022-06-30 12:09:05 +02:00
|
|
|
pWindow->m_vRealPosition = Vector2D(desiredGeometry.x, desiredGeometry.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-15 20:09:32 +02:00
|
|
|
if (*PXWLFORCESCALEZERO && pWindow->m_bIsX11)
|
|
|
|
pWindow->m_vRealSize = pWindow->m_vRealSize.goalv() / PMONITOR->scale;
|
2023-06-22 21:43:31 +02:00
|
|
|
|
2023-02-03 22:09:11 +01:00
|
|
|
if (pWindow->m_bX11DoesntWantBorders || (pWindow->m_bIsX11 && pWindow->m_uSurface.xwayland->override_redirect)) {
|
2023-07-20 20:03:23 +02:00
|
|
|
pWindow->m_vRealPosition.warp();
|
|
|
|
pWindow->m_vRealSize.warp();
|
2022-06-30 12:09:05 +02:00
|
|
|
}
|
|
|
|
|
2022-07-08 11:24:07 +02:00
|
|
|
if (pWindow->m_iX11Type != 2) {
|
|
|
|
g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goalv());
|
2022-06-30 12:09:05 +02:00
|
|
|
|
2023-09-21 23:18:26 +02:00
|
|
|
g_pCompositor->changeWindowZOrder(pWindow, true);
|
2022-07-08 11:24:07 +02:00
|
|
|
}
|
2022-06-30 12:09:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void IHyprLayout::onBeginDragWindow() {
|
|
|
|
const auto DRAGGINGWINDOW = g_pInputManager->currentlyDraggedWindow;
|
|
|
|
|
|
|
|
m_vBeginDragSizeXY = Vector2D();
|
|
|
|
|
|
|
|
// Window will be floating. Let's check if it's valid. It should be, but I don't like crashing.
|
|
|
|
if (!g_pCompositor->windowValidMapped(DRAGGINGWINDOW)) {
|
|
|
|
Debug::log(ERR, "Dragging attempted on an invalid window!");
|
2023-01-20 16:30:30 +01:00
|
|
|
g_pInputManager->currentlyDraggedWindow = nullptr;
|
2022-06-30 12:09:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DRAGGINGWINDOW->m_bIsFullscreen) {
|
2023-08-28 22:54:23 +02:00
|
|
|
Debug::log(LOG, "Dragging a fullscreen window");
|
|
|
|
g_pCompositor->setWindowFullscreen(DRAGGINGWINDOW, false, FULLSCREEN_FULL);
|
2022-06-30 12:09:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(DRAGGINGWINDOW->m_iWorkspaceID);
|
|
|
|
|
2022-12-08 18:45:25 +01:00
|
|
|
if (PWORKSPACE->m_bHasFullscreenWindow && (!DRAGGINGWINDOW->m_bCreatedOverFullscreen || !DRAGGINGWINDOW->m_bIsFloating)) {
|
|
|
|
Debug::log(LOG, "Rejecting drag on a fullscreen workspace. (window under fullscreen)");
|
2023-01-20 16:30:30 +01:00
|
|
|
g_pInputManager->currentlyDraggedWindow = nullptr;
|
2022-06-30 12:09:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DRAGGINGWINDOW->m_bDraggingTiled = false;
|
|
|
|
|
2023-05-29 18:05:41 +02:00
|
|
|
m_vDraggingWindowOriginalFloatSize = DRAGGINGWINDOW->m_vLastFloatingSize;
|
|
|
|
|
2022-06-30 12:09:05 +02:00
|
|
|
if (!DRAGGINGWINDOW->m_bIsFloating) {
|
2022-09-19 20:04:48 +02:00
|
|
|
if (g_pInputManager->dragMode == MBIND_MOVE) {
|
2023-05-29 18:05:41 +02:00
|
|
|
DRAGGINGWINDOW->m_vLastFloatingSize = (DRAGGINGWINDOW->m_vRealSize.goalv() * 0.8489).clamp(Vector2D{5, 5}, Vector2D{}).floor();
|
2022-06-30 12:09:05 +02:00
|
|
|
changeWindowFloatingMode(DRAGGINGWINDOW);
|
2022-12-16 18:17:31 +01:00
|
|
|
DRAGGINGWINDOW->m_bIsFloating = true;
|
2022-06-30 12:09:05 +02:00
|
|
|
DRAGGINGWINDOW->m_bDraggingTiled = true;
|
2022-08-05 17:52:14 +02:00
|
|
|
|
|
|
|
DRAGGINGWINDOW->m_vRealPosition = g_pInputManager->getMouseCoordsInternal() - DRAGGINGWINDOW->m_vRealSize.goalv() / 2.f;
|
2022-06-30 12:09:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
m_vBeginDragXY = g_pInputManager->getMouseCoordsInternal();
|
2022-08-05 17:52:14 +02:00
|
|
|
m_vBeginDragPositionXY = DRAGGINGWINDOW->m_vRealPosition.goalv();
|
2022-12-16 18:17:31 +01:00
|
|
|
m_vBeginDragSizeXY = DRAGGINGWINDOW->m_vRealSize.goalv();
|
|
|
|
m_vLastDragXY = m_vBeginDragXY;
|
2022-06-30 12:09:05 +02:00
|
|
|
|
2022-10-03 23:41:05 +02:00
|
|
|
// get the grab corner
|
|
|
|
if (m_vBeginDragXY.x < m_vBeginDragPositionXY.x + m_vBeginDragSizeXY.x / 2.0) {
|
2023-02-26 02:56:23 +01:00
|
|
|
if (m_vBeginDragXY.y < m_vBeginDragPositionXY.y + m_vBeginDragSizeXY.y / 2.0) {
|
2023-02-12 23:24:47 +01:00
|
|
|
m_eGrabbedCorner = CORNER_TOPLEFT;
|
2023-02-26 02:56:23 +01:00
|
|
|
g_pInputManager->setCursorImageUntilUnset("nw-resize");
|
|
|
|
} else {
|
2023-02-12 23:24:47 +01:00
|
|
|
m_eGrabbedCorner = CORNER_BOTTOMLEFT;
|
2023-02-26 02:56:23 +01:00
|
|
|
g_pInputManager->setCursorImageUntilUnset("sw-resize");
|
|
|
|
}
|
2022-10-03 23:41:05 +02:00
|
|
|
} else {
|
2023-02-26 02:56:23 +01:00
|
|
|
if (m_vBeginDragXY.y < m_vBeginDragPositionXY.y + m_vBeginDragSizeXY.y / 2.0) {
|
2023-02-12 23:24:47 +01:00
|
|
|
m_eGrabbedCorner = CORNER_TOPRIGHT;
|
2023-02-26 02:56:23 +01:00
|
|
|
g_pInputManager->setCursorImageUntilUnset("ne-resize");
|
|
|
|
} else {
|
2023-02-12 23:24:47 +01:00
|
|
|
m_eGrabbedCorner = CORNER_BOTTOMRIGHT;
|
2023-02-26 02:56:23 +01:00
|
|
|
g_pInputManager->setCursorImageUntilUnset("se-resize");
|
|
|
|
}
|
2022-10-03 23:41:05 +02:00
|
|
|
}
|
|
|
|
|
2023-08-08 18:52:20 +02:00
|
|
|
if (g_pInputManager->dragMode != MBIND_RESIZE && g_pInputManager->dragMode != MBIND_RESIZE_FORCE_RATIO && g_pInputManager->dragMode != MBIND_RESIZE_BLOCK_RATIO)
|
2023-02-27 00:08:20 +01:00
|
|
|
g_pInputManager->setCursorImageUntilUnset("grab");
|
|
|
|
|
2022-06-30 12:09:05 +02:00
|
|
|
g_pHyprRenderer->damageWindow(DRAGGINGWINDOW);
|
2022-07-21 19:44:34 +02:00
|
|
|
|
|
|
|
g_pKeybindManager->shadowKeybinds();
|
2023-07-13 20:20:40 +02:00
|
|
|
|
|
|
|
g_pCompositor->focusWindow(DRAGGINGWINDOW);
|
2023-09-21 23:18:26 +02:00
|
|
|
g_pCompositor->changeWindowZOrder(DRAGGINGWINDOW, true);
|
2022-06-30 12:09:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void IHyprLayout::onEndDragWindow() {
|
|
|
|
const auto DRAGGINGWINDOW = g_pInputManager->currentlyDraggedWindow;
|
|
|
|
|
2023-02-18 23:35:31 +01:00
|
|
|
if (!g_pCompositor->windowValidMapped(DRAGGINGWINDOW)) {
|
|
|
|
if (DRAGGINGWINDOW) {
|
|
|
|
g_pInputManager->unsetCursorImage();
|
|
|
|
g_pInputManager->currentlyDraggedWindow = nullptr;
|
|
|
|
}
|
2022-06-30 12:09:05 +02:00
|
|
|
return;
|
2023-02-18 23:35:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
g_pInputManager->unsetCursorImage();
|
2022-06-30 12:09:05 +02:00
|
|
|
|
2023-01-02 12:06:06 +01:00
|
|
|
g_pInputManager->currentlyDraggedWindow = nullptr;
|
2023-10-29 21:14:47 +01:00
|
|
|
g_pInputManager->m_bWasDraggingWindow = true;
|
2023-01-02 12:06:06 +01:00
|
|
|
|
2022-06-30 12:09:05 +02:00
|
|
|
if (DRAGGINGWINDOW->m_bDraggingTiled) {
|
|
|
|
DRAGGINGWINDOW->m_bIsFloating = false;
|
2022-11-08 21:28:41 +01:00
|
|
|
g_pInputManager->refocus();
|
2022-06-30 12:09:05 +02:00
|
|
|
changeWindowFloatingMode(DRAGGINGWINDOW);
|
2023-05-29 18:05:41 +02:00
|
|
|
DRAGGINGWINDOW->m_vLastFloatingSize = m_vDraggingWindowOriginalFloatSize;
|
2022-06-30 12:09:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
g_pHyprRenderer->damageWindow(DRAGGINGWINDOW);
|
2023-08-05 20:53:13 +02:00
|
|
|
|
|
|
|
g_pCompositor->focusWindow(DRAGGINGWINDOW);
|
2023-10-29 21:14:47 +01:00
|
|
|
|
|
|
|
g_pInputManager->m_bWasDraggingWindow = false;
|
2022-06-30 12:09:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void IHyprLayout::onMouseMove(const Vector2D& mousePos) {
|
|
|
|
const auto DRAGGINGWINDOW = g_pInputManager->currentlyDraggedWindow;
|
|
|
|
|
|
|
|
// Window invalid or drag begin size 0,0 meaning we rejected it.
|
|
|
|
if (!g_pCompositor->windowValidMapped(DRAGGINGWINDOW) || m_vBeginDragSizeXY == Vector2D()) {
|
2022-12-12 15:32:23 +01:00
|
|
|
onEndDragWindow();
|
2022-06-30 12:09:05 +02:00
|
|
|
g_pInputManager->currentlyDraggedWindow = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-25 17:53:01 +02:00
|
|
|
static auto TIMER = std::chrono::high_resolution_clock::now();
|
2022-12-09 18:08:04 +01:00
|
|
|
|
2023-04-25 17:53:01 +02:00
|
|
|
const auto SPECIAL = g_pCompositor->isWorkspaceSpecial(DRAGGINGWINDOW->m_iWorkspaceID);
|
2022-06-30 12:09:05 +02:00
|
|
|
|
2023-04-25 17:53:01 +02:00
|
|
|
const auto DELTA = Vector2D(mousePos.x - m_vBeginDragXY.x, mousePos.y - m_vBeginDragXY.y);
|
|
|
|
const auto TICKDELTA = Vector2D(mousePos.x - m_vLastDragXY.x, mousePos.y - m_vLastDragXY.y);
|
2022-08-16 21:56:54 +02:00
|
|
|
|
2023-04-25 17:53:01 +02:00
|
|
|
static auto* const PANIMATEMOUSE = &g_pConfigManager->getConfigValuePtr("misc:animate_mouse_windowdragging")->intValue;
|
|
|
|
static auto* const PANIMATE = &g_pConfigManager->getConfigValuePtr("misc:animate_manual_resizes")->intValue;
|
2023-03-04 01:14:20 +01:00
|
|
|
|
|
|
|
if ((abs(TICKDELTA.x) < 1.f && abs(TICKDELTA.y) < 1.f) ||
|
|
|
|
(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - TIMER).count() <
|
2023-07-04 11:48:13 +02:00
|
|
|
1000.0 / g_pHyprRenderer->m_pMostHzMonitor->refreshRate &&
|
2023-08-16 10:56:48 +02:00
|
|
|
(*PANIMATEMOUSE || *PANIMATE)))
|
2022-06-30 12:09:05 +02:00
|
|
|
return;
|
|
|
|
|
2023-03-04 01:14:20 +01:00
|
|
|
TIMER = std::chrono::high_resolution_clock::now();
|
|
|
|
|
2022-06-30 12:09:05 +02:00
|
|
|
m_vLastDragXY = mousePos;
|
|
|
|
|
|
|
|
g_pHyprRenderer->damageWindow(DRAGGINGWINDOW);
|
|
|
|
|
2022-09-19 20:04:48 +02:00
|
|
|
if (g_pInputManager->dragMode == MBIND_MOVE) {
|
2022-10-19 22:17:49 +02:00
|
|
|
|
2023-02-28 21:50:10 +01:00
|
|
|
if (*PANIMATEMOUSE) {
|
2022-10-19 22:17:49 +02:00
|
|
|
DRAGGINGWINDOW->m_vRealPosition = m_vBeginDragPositionXY + DELTA;
|
|
|
|
} else {
|
|
|
|
DRAGGINGWINDOW->m_vRealPosition.setValueAndWarp(m_vBeginDragPositionXY + DELTA);
|
|
|
|
}
|
2022-06-30 12:09:05 +02:00
|
|
|
|
|
|
|
g_pXWaylandManager->setWindowSize(DRAGGINGWINDOW, DRAGGINGWINDOW->m_vRealSize.goalv());
|
2023-08-08 18:52:20 +02:00
|
|
|
} else if (g_pInputManager->dragMode == MBIND_RESIZE || g_pInputManager->dragMode == MBIND_RESIZE_FORCE_RATIO || g_pInputManager->dragMode == MBIND_RESIZE_BLOCK_RATIO) {
|
2022-06-30 12:09:05 +02:00
|
|
|
if (DRAGGINGWINDOW->m_bIsFloating) {
|
2022-08-05 17:58:08 +02:00
|
|
|
|
2023-08-08 18:52:20 +02:00
|
|
|
Vector2D MINSIZE = Vector2D(20, 20);
|
|
|
|
Vector2D MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(DRAGGINGWINDOW);
|
2022-10-03 23:41:05 +02:00
|
|
|
|
|
|
|
Vector2D newSize = m_vBeginDragSizeXY;
|
2022-12-16 18:17:31 +01:00
|
|
|
Vector2D newPos = m_vBeginDragPositionXY;
|
2022-10-03 23:41:05 +02:00
|
|
|
|
2023-08-08 18:52:20 +02:00
|
|
|
if (m_eGrabbedCorner == CORNER_BOTTOMRIGHT)
|
|
|
|
newSize = newSize + DELTA;
|
|
|
|
else if (m_eGrabbedCorner == CORNER_TOPLEFT)
|
|
|
|
newSize = newSize - DELTA;
|
|
|
|
else if (m_eGrabbedCorner == CORNER_TOPRIGHT)
|
|
|
|
newSize = newSize + Vector2D(DELTA.x, -DELTA.y);
|
|
|
|
else if (m_eGrabbedCorner == CORNER_BOTTOMLEFT)
|
|
|
|
newSize = newSize + Vector2D(-DELTA.x, DELTA.y);
|
|
|
|
|
|
|
|
if ((m_vBeginDragSizeXY.x >= 1 && m_vBeginDragSizeXY.y >= 1) &&
|
|
|
|
(g_pInputManager->dragMode == MBIND_RESIZE_FORCE_RATIO ||
|
|
|
|
(!(g_pInputManager->dragMode == MBIND_RESIZE_BLOCK_RATIO) && DRAGGINGWINDOW->m_sAdditionalConfigData.keepAspectRatio))) {
|
|
|
|
|
|
|
|
const float RATIO = m_vBeginDragSizeXY.y / m_vBeginDragSizeXY.x;
|
|
|
|
|
|
|
|
if (MINSIZE.x * RATIO > MINSIZE.y)
|
|
|
|
MINSIZE = Vector2D(MINSIZE.x, MINSIZE.x * RATIO);
|
|
|
|
else
|
|
|
|
MINSIZE = Vector2D(MINSIZE.y / RATIO, MINSIZE.y);
|
|
|
|
|
|
|
|
if (MAXSIZE.x * RATIO < MAXSIZE.y)
|
|
|
|
MAXSIZE = Vector2D(MAXSIZE.x, MAXSIZE.x * RATIO);
|
|
|
|
else
|
|
|
|
MAXSIZE = Vector2D(MAXSIZE.y / RATIO, MAXSIZE.y);
|
|
|
|
|
|
|
|
if (newSize.x * RATIO > newSize.y)
|
|
|
|
newSize = Vector2D(newSize.x, newSize.x * RATIO);
|
|
|
|
else
|
|
|
|
newSize = Vector2D(newSize.y / RATIO, newSize.y);
|
2022-10-03 23:41:05 +02:00
|
|
|
}
|
|
|
|
|
2023-08-08 18:52:20 +02:00
|
|
|
newSize = newSize.clamp(MINSIZE, MAXSIZE);
|
|
|
|
|
|
|
|
if (m_eGrabbedCorner == CORNER_TOPLEFT)
|
|
|
|
newPos = newPos - newSize + m_vBeginDragSizeXY;
|
|
|
|
else if (m_eGrabbedCorner == CORNER_TOPRIGHT)
|
|
|
|
newPos = newPos + Vector2D(0, (m_vBeginDragSizeXY - newSize).y);
|
|
|
|
else if (m_eGrabbedCorner == CORNER_BOTTOMLEFT)
|
|
|
|
newPos = newPos + Vector2D((m_vBeginDragSizeXY - newSize).x, 0);
|
|
|
|
|
2022-08-16 21:56:54 +02:00
|
|
|
if (*PANIMATE) {
|
2022-12-16 18:17:31 +01:00
|
|
|
DRAGGINGWINDOW->m_vRealSize = newSize;
|
2022-10-03 23:41:05 +02:00
|
|
|
DRAGGINGWINDOW->m_vRealPosition = newPos;
|
2022-08-16 21:56:54 +02:00
|
|
|
} else {
|
2022-10-03 23:41:05 +02:00
|
|
|
DRAGGINGWINDOW->m_vRealSize.setValueAndWarp(newSize);
|
|
|
|
DRAGGINGWINDOW->m_vRealPosition.setValueAndWarp(newPos);
|
2022-08-16 21:56:54 +02:00
|
|
|
}
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2022-06-30 12:09:05 +02:00
|
|
|
g_pXWaylandManager->setWindowSize(DRAGGINGWINDOW, DRAGGINGWINDOW->m_vRealSize.goalv());
|
|
|
|
} else {
|
2023-07-13 16:52:11 +02:00
|
|
|
resizeActiveWindow(TICKDELTA, m_eGrabbedCorner, DRAGGINGWINDOW);
|
2022-06-30 12:09:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get middle point
|
|
|
|
Vector2D middle = DRAGGINGWINDOW->m_vRealPosition.vec() + DRAGGINGWINDOW->m_vRealSize.vec() / 2.f;
|
|
|
|
|
|
|
|
// and check its monitor
|
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromVector(middle);
|
|
|
|
|
2022-12-09 18:08:04 +01:00
|
|
|
if (PMONITOR && !SPECIAL) {
|
2022-06-30 12:09:05 +02:00
|
|
|
DRAGGINGWINDOW->m_iMonitorID = PMONITOR->ID;
|
2022-08-21 17:01:26 +02:00
|
|
|
DRAGGINGWINDOW->moveToWorkspace(PMONITOR->activeWorkspace);
|
2023-03-18 17:30:29 +01:00
|
|
|
DRAGGINGWINDOW->updateGroupOutputs();
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2022-08-06 20:57:38 +02:00
|
|
|
DRAGGINGWINDOW->updateToplevel();
|
2022-06-30 12:09:05 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 19:23:53 +02:00
|
|
|
DRAGGINGWINDOW->updateWindowDecos();
|
|
|
|
|
2022-06-30 12:09:05 +02:00
|
|
|
g_pHyprRenderer->damageWindow(DRAGGINGWINDOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IHyprLayout::changeWindowFloatingMode(CWindow* pWindow) {
|
|
|
|
|
|
|
|
if (pWindow->m_bIsFullscreen) {
|
2023-08-28 22:55:52 +02:00
|
|
|
Debug::log(LOG, "changeWindowFloatingMode: fullscreen");
|
|
|
|
g_pCompositor->setWindowFullscreen(pWindow, false, FULLSCREEN_FULL);
|
2022-06-30 12:09:05 +02:00
|
|
|
}
|
|
|
|
|
2022-09-10 13:11:02 +02:00
|
|
|
pWindow->m_bPinned = false;
|
|
|
|
|
2022-06-30 12:09:05 +02:00
|
|
|
const auto TILED = isWindowTiled(pWindow);
|
|
|
|
|
2022-12-09 19:51:44 +01:00
|
|
|
// event
|
2023-09-20 09:26:20 +02:00
|
|
|
g_pEventManager->postEvent(SHyprIPCEvent{"changefloatingmode", std::format("{:x},{}", (uintptr_t)pWindow, (int)TILED)});
|
2023-02-19 21:54:53 +01:00
|
|
|
EMIT_HOOK_EVENT("changeFloatingMode", pWindow);
|
2022-12-09 19:51:44 +01:00
|
|
|
|
2022-06-30 12:09:05 +02:00
|
|
|
if (!TILED) {
|
2022-12-16 18:17:31 +01:00
|
|
|
const auto PNEWMON = g_pCompositor->getMonitorFromVector(pWindow->m_vRealPosition.vec() + pWindow->m_vRealSize.vec() / 2.f);
|
2022-06-30 12:09:05 +02:00
|
|
|
pWindow->m_iMonitorID = PNEWMON->ID;
|
2023-09-25 00:20:15 +02:00
|
|
|
pWindow->moveToWorkspace(PNEWMON->specialWorkspaceID != 0 ? PNEWMON->specialWorkspaceID : PNEWMON->activeWorkspace);
|
2023-03-18 17:30:29 +01:00
|
|
|
pWindow->updateGroupOutputs();
|
2022-06-30 12:09:05 +02:00
|
|
|
|
|
|
|
// save real pos cuz the func applies the default 5,5 mid
|
2022-12-16 18:17:31 +01:00
|
|
|
const auto PSAVEDPOS = pWindow->m_vRealPosition.goalv();
|
2022-11-09 23:01:53 +01:00
|
|
|
const auto PSAVEDSIZE = pWindow->m_vRealSize.goalv();
|
2022-06-30 12:09:05 +02:00
|
|
|
|
|
|
|
// if the window is pseudo, update its size
|
2022-11-09 23:01:53 +01:00
|
|
|
pWindow->m_vPseudoSize = pWindow->m_vRealSize.goalv();
|
2022-06-30 12:09:05 +02:00
|
|
|
|
2022-08-05 17:52:14 +02:00
|
|
|
pWindow->m_vLastFloatingSize = PSAVEDSIZE;
|
|
|
|
|
2022-10-19 22:32:30 +02:00
|
|
|
// move to narnia because we don't wanna find our own node. onWindowCreatedTiling should apply the coords back.
|
|
|
|
pWindow->m_vPosition = Vector2D(-999999, -999999);
|
|
|
|
|
2022-06-30 12:09:05 +02:00
|
|
|
onWindowCreatedTiling(pWindow);
|
|
|
|
|
|
|
|
pWindow->m_vRealPosition.setValue(PSAVEDPOS);
|
|
|
|
pWindow->m_vRealSize.setValue(PSAVEDSIZE);
|
|
|
|
|
|
|
|
// fix pseudo leaving artifacts
|
|
|
|
g_pHyprRenderer->damageMonitor(g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID));
|
2022-10-24 13:25:36 +02:00
|
|
|
|
|
|
|
if (pWindow == g_pCompositor->m_pLastWindow)
|
|
|
|
m_pLastTiledWindow = pWindow;
|
2022-06-30 12:09:05 +02:00
|
|
|
} else {
|
|
|
|
onWindowRemovedTiling(pWindow);
|
|
|
|
|
2023-09-21 23:18:26 +02:00
|
|
|
g_pCompositor->changeWindowZOrder(pWindow, true);
|
2022-07-08 21:52:52 +02:00
|
|
|
|
2023-04-06 20:45:59 +02:00
|
|
|
if (DELTALESSTHAN(pWindow->m_vRealSize.vec().x, pWindow->m_vLastFloatingSize.x, 10) && DELTALESSTHAN(pWindow->m_vRealSize.vec().y, pWindow->m_vLastFloatingSize.y, 10)) {
|
|
|
|
pWindow->m_vRealPosition = pWindow->m_vRealPosition.goalv() + (pWindow->m_vRealSize.goalv() - pWindow->m_vLastFloatingSize) / 2.f + Vector2D{10, 10};
|
|
|
|
pWindow->m_vRealSize = pWindow->m_vLastFloatingSize - Vector2D{20, 20};
|
|
|
|
}
|
|
|
|
|
2022-11-09 23:01:53 +01:00
|
|
|
pWindow->m_vRealPosition = pWindow->m_vRealPosition.goalv() + (pWindow->m_vRealSize.goalv() - pWindow->m_vLastFloatingSize) / 2.f;
|
2022-12-16 18:17:31 +01:00
|
|
|
pWindow->m_vRealSize = pWindow->m_vLastFloatingSize;
|
2022-07-08 21:52:52 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
pWindow->m_vSize = pWindow->m_vRealSize.goalv();
|
2022-11-09 23:01:53 +01:00
|
|
|
pWindow->m_vPosition = pWindow->m_vRealPosition.goalv();
|
|
|
|
|
2022-07-08 21:52:52 +02:00
|
|
|
g_pHyprRenderer->damageMonitor(g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID));
|
2022-08-05 18:08:23 +02:00
|
|
|
|
2023-08-17 10:13:19 +02:00
|
|
|
pWindow->updateSpecialRenderData();
|
2022-10-24 13:25:36 +02:00
|
|
|
|
|
|
|
if (pWindow == m_pLastTiledWindow)
|
|
|
|
m_pLastTiledWindow = nullptr;
|
2022-06-30 12:09:05 +02:00
|
|
|
}
|
2022-08-06 20:57:38 +02:00
|
|
|
|
2022-08-11 19:29:39 +02:00
|
|
|
g_pCompositor->updateWindowAnimatedDecorationValues(pWindow);
|
|
|
|
|
2022-08-06 20:57:38 +02:00
|
|
|
pWindow->updateToplevel();
|
2022-06-30 12:09:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void IHyprLayout::moveActiveWindow(const Vector2D& delta, CWindow* pWindow) {
|
|
|
|
const auto PWINDOW = pWindow ? pWindow : g_pCompositor->m_pLastWindow;
|
|
|
|
|
|
|
|
if (!g_pCompositor->windowValidMapped(PWINDOW))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!PWINDOW->m_bIsFloating) {
|
|
|
|
Debug::log(LOG, "Dwindle cannot move a tiled window in moveActiveWindow!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition.goalv() + delta;
|
|
|
|
|
|
|
|
g_pHyprRenderer->damageWindow(PWINDOW);
|
2022-09-25 20:07:48 +02:00
|
|
|
}
|
2022-10-24 13:25:36 +02:00
|
|
|
|
|
|
|
void IHyprLayout::onWindowFocusChange(CWindow* pNewFocus) {
|
|
|
|
m_pLastTiledWindow = pNewFocus && !pNewFocus->m_bIsFloating ? pNewFocus : m_pLastTiledWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
CWindow* IHyprLayout::getNextWindowCandidate(CWindow* pWindow) {
|
|
|
|
// although we don't expect nullptrs here, let's verify jic
|
|
|
|
if (!pWindow)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID);
|
|
|
|
|
|
|
|
// first of all, if this is a fullscreen workspace,
|
|
|
|
if (PWORKSPACE->m_bHasFullscreenWindow)
|
|
|
|
return g_pCompositor->getFullscreenWindowOnWorkspace(pWindow->m_iWorkspaceID);
|
|
|
|
|
|
|
|
if (pWindow->m_bIsFloating) {
|
|
|
|
|
2022-11-27 13:11:45 +01:00
|
|
|
// find whether there is a floating window below this one
|
|
|
|
for (auto& w : g_pCompositor->m_vWindows) {
|
2022-12-16 18:17:31 +01:00
|
|
|
if (w->m_bIsMapped && !w->isHidden() && w->m_bIsFloating && w->m_iX11Type != 2 && w->m_iWorkspaceID == pWindow->m_iWorkspaceID && !w->m_bX11ShouldntFocus &&
|
2022-12-16 21:07:44 +01:00
|
|
|
!w->m_bNoFocus && w.get() != pWindow) {
|
2022-12-16 18:17:31 +01:00
|
|
|
if (VECINRECT((pWindow->m_vSize / 2.f + pWindow->m_vPosition), w->m_vPosition.x, w->m_vPosition.y, w->m_vPosition.x + w->m_vSize.x,
|
|
|
|
w->m_vPosition.y + w->m_vSize.y)) {
|
2022-11-27 13:11:45 +01:00
|
|
|
return w.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// let's try the last tiled window.
|
2022-10-24 13:25:36 +02:00
|
|
|
if (m_pLastTiledWindow && m_pLastTiledWindow->m_iWorkspaceID == pWindow->m_iWorkspaceID)
|
|
|
|
return m_pLastTiledWindow;
|
|
|
|
|
|
|
|
// if we don't, let's try to find any window that is in the middle
|
2023-09-11 11:09:34 +02:00
|
|
|
if (const auto PWINDOWCANDIDATE = g_pCompositor->vectorToWindowIdeal(pWindow->middle()); PWINDOWCANDIDATE && PWINDOWCANDIDATE != pWindow)
|
2022-10-24 13:25:36 +02:00
|
|
|
return PWINDOWCANDIDATE;
|
|
|
|
|
|
|
|
// if not, floating window
|
|
|
|
for (auto& w : g_pCompositor->m_vWindows) {
|
2022-12-16 18:17:31 +01:00
|
|
|
if (w->m_bIsMapped && !w->isHidden() && w->m_bIsFloating && w->m_iX11Type != 2 && w->m_iWorkspaceID == pWindow->m_iWorkspaceID && !w->m_bX11ShouldntFocus &&
|
2022-12-16 21:07:44 +01:00
|
|
|
!w->m_bNoFocus && w.get() != pWindow)
|
2022-10-24 13:25:36 +02:00
|
|
|
return w.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there is no candidate, too bad
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if it was a tiled window, we first try to find the window that will replace it.
|
2023-09-11 11:09:34 +02:00
|
|
|
const auto PWINDOWCANDIDATE = g_pCompositor->vectorToWindowIdeal(pWindow->middle());
|
2022-10-24 13:25:36 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
if (!PWINDOWCANDIDATE || pWindow == PWINDOWCANDIDATE || !PWINDOWCANDIDATE->m_bIsMapped || PWINDOWCANDIDATE->isHidden() || PWINDOWCANDIDATE->m_bX11ShouldntFocus ||
|
|
|
|
PWINDOWCANDIDATE->m_iX11Type == 2 || PWINDOWCANDIDATE->m_iMonitorID != g_pCompositor->m_pLastMonitor->ID)
|
2022-10-24 13:25:36 +02:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return PWINDOWCANDIDATE;
|
|
|
|
}
|
2022-11-28 20:04:24 +01:00
|
|
|
|
2023-09-12 23:37:08 +02:00
|
|
|
bool IHyprLayout::isWindowReachable(CWindow* pWindow) {
|
|
|
|
return pWindow && (!pWindow->isHidden() || pWindow->m_sGroupData.pNextWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IHyprLayout::bringWindowToTop(CWindow* pWindow) {
|
|
|
|
if (pWindow == nullptr)
|
|
|
|
return;
|
|
|
|
|
2023-07-19 12:39:45 +02:00
|
|
|
if (pWindow->isHidden() && pWindow->m_sGroupData.pNextWindow) {
|
|
|
|
// grouped, change the current to this window
|
|
|
|
pWindow->setGroupCurrent(pWindow);
|
|
|
|
}
|
2023-09-12 23:37:08 +02:00
|
|
|
}
|
2023-07-19 12:39:45 +02:00
|
|
|
|
2023-09-12 23:37:08 +02:00
|
|
|
void IHyprLayout::requestFocusForWindow(CWindow* pWindow) {
|
|
|
|
bringWindowToTop(pWindow);
|
2023-07-19 12:39:45 +02:00
|
|
|
g_pCompositor->focusWindow(pWindow);
|
|
|
|
}
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
IHyprLayout::~IHyprLayout() {}
|