From 295a0c4a6904b639ae406df2f106eb35d71899ae Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 21 Mar 2022 19:18:33 +0100 Subject: Added fullscreen --- src/layout/DwindleLayout.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++- src/layout/DwindleLayout.hpp | 1 + src/layout/IHyprLayout.hpp | 36 ++++++++++++++++++- 3 files changed, 117 insertions(+), 2 deletions(-) (limited to 'src/layout') diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index e496fbd9..5d598c24 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -228,6 +228,12 @@ void CHyprDwindleLayout::onWindowRemoved(CWindow* pWindow) { void CHyprDwindleLayout::recalculateMonitor(const int& monid) { const auto PMONITOR = g_pCompositor->getMonitorFromID(monid); + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); + + // Ignore any recalc events if we have a fullscreen window. + if (PWORKSPACE->hasFullscreenWindow) + return; + const auto TOPNODE = getMasterNodeOnWorkspace(PMONITOR->activeWorkspace); if (TOPNODE && PMONITOR) { @@ -238,6 +244,15 @@ void CHyprDwindleLayout::recalculateMonitor(const int& monid) { } void CHyprDwindleLayout::changeWindowFloatingMode(CWindow* pWindow) { + + if (pWindow->m_bIsFullscreen) { + Debug::log(LOG, "Rejecting a change float order because window is fullscreen."); + + // restore its' floating mode + pWindow->m_bIsFloating = !pWindow->m_bIsFloating; + return; + } + const auto PNODE = getNodeFromWindow(pWindow); if (!PNODE) { @@ -248,8 +263,16 @@ void CHyprDwindleLayout::changeWindowFloatingMode(CWindow* pWindow) { } void CHyprDwindleLayout::onBeginDragWindow() { + const auto DRAGGINGWINDOW = g_pInputManager->currentlyDraggedWindow; + m_vBeginDragSizeXY = Vector2D(); + + if (DRAGGINGWINDOW->m_bIsFullscreen) { + Debug::log(LOG, "Rejecting drag on a fullscreen window."); + return; + } + // 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!"); @@ -264,7 +287,8 @@ void CHyprDwindleLayout::onBeginDragWindow() { void CHyprDwindleLayout::onMouseMove(const Vector2D& mousePos) { const auto DRAGGINGWINDOW = g_pInputManager->currentlyDraggedWindow; - if (!g_pCompositor->windowValidMapped(DRAGGINGWINDOW)) + // Window invalid or drag begin size 0,0 meaning we rejected it. + if (!g_pCompositor->windowValidMapped(DRAGGINGWINDOW) || m_vBeginDragSizeXY == Vector2D()) return; const auto DELTA = Vector2D(mousePos.x - m_vBeginDragXY.x, mousePos.y - m_vBeginDragXY.y); @@ -317,4 +341,60 @@ void CHyprDwindleLayout::onWindowCreatedFloating(CWindow* pWindow) { pWindow->m_vRealPosition = Vector2D(desiredGeometry.x, desiredGeometry.y); } } +} + +void CHyprDwindleLayout::fullscreenRequestForWindow(CWindow* pWindow) { + if (!g_pCompositor->windowValidMapped(pWindow)) + return; + + const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + + if (PWORKSPACE->hasFullscreenWindow && !pWindow->m_bIsFullscreen) { + // if the window wants to be fullscreen but there already is one, + // ignore the request. + return; + } + + // otherwise, accept it. + pWindow->m_bIsFullscreen = !pWindow->m_bIsFullscreen; + PWORKSPACE->hasFullscreenWindow = !PWORKSPACE->hasFullscreenWindow; + + if (!pWindow->m_bIsFullscreen) { + // if it got its fullscreen disabled, set back its node if it had one + const auto PNODE = getNodeFromWindow(pWindow); + if (PNODE) + applyNodeDataToWindow(PNODE); + else { + // get back its' dimensions from position and size + pWindow->m_vEffectivePosition = pWindow->m_vPosition; + pWindow->m_vEffectiveSize = pWindow->m_vSize; + + // TEMP: Remove when anims added + pWindow->m_vRealPosition = pWindow->m_vEffectivePosition; + pWindow->m_vRealSize = pWindow->m_vEffectiveSize; + g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize); + } + } else { + // if it now got fullscreen, make it fullscreen + + // save position and size if floating + if (pWindow->m_bIsFloating) { + pWindow->m_vPosition = pWindow->m_vRealPosition; + pWindow->m_vSize = pWindow->m_vRealSize; + } + + // apply new pos and size being monitors' box + pWindow->m_vEffectivePosition = PMONITOR->vecPosition; + pWindow->m_vEffectiveSize = PMONITOR->vecSize; + + // TEMP: Remove when anims added + pWindow->m_vRealPosition = pWindow->m_vEffectivePosition; + pWindow->m_vRealSize = pWindow->m_vEffectiveSize; + g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize); + } + + // we need to fix XWayland windows by sending them to NARNIA + // because otherwise they'd still be recieving mouse events + g_pCompositor->fixXWaylandWindowsOnWorkspace(PMONITOR->activeWorkspace); } \ No newline at end of file diff --git a/src/layout/DwindleLayout.hpp b/src/layout/DwindleLayout.hpp index 7474f484..61b76be7 100644 --- a/src/layout/DwindleLayout.hpp +++ b/src/layout/DwindleLayout.hpp @@ -36,6 +36,7 @@ public: virtual void onBeginDragWindow(); virtual void onMouseMove(const Vector2D&); virtual void onWindowCreatedFloating(CWindow*); + virtual void fullscreenRequestForWindow(CWindow*); private: diff --git a/src/layout/IHyprLayout.hpp b/src/layout/IHyprLayout.hpp index c3fbd667..e437d703 100644 --- a/src/layout/IHyprLayout.hpp +++ b/src/layout/IHyprLayout.hpp @@ -6,14 +6,48 @@ interface IHyprLayout { public: + /* + Called when a window is created (mapped) + */ virtual void onWindowCreated(CWindow*) = 0; + /* + Called when a window is removed (unmapped) + */ virtual void onWindowRemoved(CWindow*) = 0; + /* + Called when a the monitor requires a layout recalculation + this usually means reserved area changes + */ virtual void recalculateMonitor(const int&) = 0; - // Floating windows + /* + Called when a window is requested to be floated + */ virtual void changeWindowFloatingMode(CWindow*) = 0; + /* + Called when a window is clicked on, beginning a drag + this might be a resize, move, whatever the layout defines it + as. + */ virtual void onBeginDragWindow() = 0; + /* + Called whenever the mouse moves, should the layout want to + do anything with it. + Useful for dragging. + */ virtual void onMouseMove(const Vector2D&) = 0; + /* + Called when a window is created, but is requesting to be floated. + Warning: this also includes stuff like popups, incorrect handling + of which can result in a crash! + */ virtual void onWindowCreatedFloating(CWindow*) = 0; + /* + Called when a window requests to toggle its' fullscreen state. + The layout sets all the fullscreen flags. + It can either accept or ignore. + */ + virtual void fullscreenRequestForWindow(CWindow*) = 0; + }; \ No newline at end of file -- cgit v1.2.3