From 83d69cb233288a95d79bc5ae97c14e405e414c3a Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 4 Apr 2022 21:40:10 +0200 Subject: [PATCH] Added pinning windows --- src/KeybindManager.cpp | 11 +++++++++++ src/KeybindManager.hpp | 1 + src/config/ConfigManager.cpp | 1 + src/window.cpp | 2 +- src/window.hpp | 3 +++ src/windowManager.cpp | 6 +++--- 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/KeybindManager.cpp b/src/KeybindManager.cpp index 0b53adf..18c35b4 100644 --- a/src/KeybindManager.cpp +++ b/src/KeybindManager.cpp @@ -182,6 +182,7 @@ void KeybindManager::toggleActiveWindowFloating(std::string arg) { if (const auto PWINDOW = g_pWindowManager->getWindowFromDrawable(g_pWindowManager->LastWindow); PWINDOW) { PWINDOW->setIsFloating(!PWINDOW->getIsFloating()); PWINDOW->setDirty(true); + PWINDOW->setPinned(false); // Fix window as if it's closed if we just made it floating if (PWINDOW->getIsFloating()) { @@ -276,4 +277,14 @@ void KeybindManager::lastWorkspace(std::string args) { return; g_pWindowManager->changeWorkspaceByID(g_pWindowManager->activeWorkspaces[PMONITOR->ID] < 2 ? 1 : g_pWindowManager->activeWorkspaces[PMONITOR->ID] - 1); +} + +void KeybindManager::pinActive(std::string agrs) { + const auto PWINDOW = g_pWindowManager->getWindowFromDrawable(g_pWindowManager->LastWindow); + + if (!PWINDOW) + return; + + if (PWINDOW->getIsFloating()) + PWINDOW->setPinned(!PWINDOW->getPinned()); } \ No newline at end of file diff --git a/src/KeybindManager.hpp b/src/KeybindManager.hpp index 00a346d..ef55009 100644 --- a/src/KeybindManager.hpp +++ b/src/KeybindManager.hpp @@ -32,4 +32,5 @@ namespace KeybindManager { void toggleScratchpad(std::string args); void nextWorkspace(std::string args); void lastWorkspace(std::string args); + void pinActive(std::string args); }; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index cb1302b..1ee88f5 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -130,6 +130,7 @@ void handleBind(const std::string& command, const std::string& value) { if (HANDLER == "scratchpad") dispatcher = KeybindManager::toggleScratchpad; if (HANDLER == "nextworkspace") dispatcher = KeybindManager::nextWorkspace; if (HANDLER == "lastworkspace") dispatcher = KeybindManager::lastWorkspace; + if (HANDLER == "pin") dispatcher = KeybindManager::pinActive; if (dispatcher && KEY != 0) KeybindManager::keybinds.push_back(Keybind(KeybindManager::modToMask(MOD), KEY, COMMAND, dispatcher)); diff --git a/src/window.cpp b/src/window.cpp index 06d132d..94dd934 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1,7 +1,7 @@ #include "window.hpp" #include "windowManager.hpp" -CWindow::CWindow() { this->setDraggingTiled(false); this->setIsPseudotiled(false); this->setSplitRatio(1); this->setDockHidden(false); this->setRealBorderColor(0); this->setEffectiveBorderColor(0); this->setFirstOpen(true); this->setConstructed(false); this->setTransient(false); this->setLastUpdatePosition(Vector2D(0,0)); this->setLastUpdateSize(Vector2D(0,0)); this->setDock(false); this->setUnderFullscreen(false); this->setIsSleeping(true); this->setFirstAnimFrame(true); this->setIsAnimated(false); this->setDead(false); this->setMasterChildIndex(0); this->setMaster(false); this->setCanKill(false); this->setImmovable(false); this->setNoInterventions(false); this->setDirty(true); this->setFullscreen(false); this->setIsFloating(false); this->setParentNodeID(0); this->setChildNodeAID(0); this->setChildNodeBID(0); this->setName(""); } +CWindow::CWindow() { this->setPinned(false); this->setDraggingTiled(false); this->setIsPseudotiled(false); this->setSplitRatio(1); this->setDockHidden(false); this->setRealBorderColor(0); this->setEffectiveBorderColor(0); this->setFirstOpen(true); this->setConstructed(false); this->setTransient(false); this->setLastUpdatePosition(Vector2D(0,0)); this->setLastUpdateSize(Vector2D(0,0)); this->setDock(false); this->setUnderFullscreen(false); this->setIsSleeping(true); this->setFirstAnimFrame(true); this->setIsAnimated(false); this->setDead(false); this->setMasterChildIndex(0); this->setMaster(false); this->setCanKill(false); this->setImmovable(false); this->setNoInterventions(false); this->setDirty(true); this->setFullscreen(false); this->setIsFloating(false); this->setParentNodeID(0); this->setChildNodeAID(0); this->setChildNodeBID(0); this->setName(""); } CWindow::~CWindow() { } void CWindow::generateNodeID() { diff --git a/src/window.hpp b/src/window.hpp index 5e9c41f..cbc74b4 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -115,6 +115,9 @@ public: // For dragging tiled windows EXPOSED_MEMBER(DraggingTiled, bool, b); + // For pinning floating + EXPOSED_MEMBER(Pinned, bool, b); + private: }; \ No newline at end of file diff --git a/src/windowManager.cpp b/src/windowManager.cpp index 0cad85b..b21c8a8 100644 --- a/src/windowManager.cpp +++ b/src/windowManager.cpp @@ -406,7 +406,7 @@ void CWindowManager::refreshDirtyWindows() { if (window.getChildNodeAID() != 0 || window.getNoInterventions() || window.getDock()) continue; - setEffectiveSizePosUsingConfig(&window); + setEffectiveSizePosUsingConrgifig(&window); const auto PWORKSPACE = getWorkspaceByID(window.getWorkspaceID()); @@ -416,7 +416,7 @@ void CWindowManager::refreshDirtyWindows() { // first and foremost, let's check if the window isn't on a hidden workspace // or an animated workspace if (PWORKSPACE && (!isWorkspaceVisible(window.getWorkspaceID()) - || PWORKSPACE->getAnimationInProgress())) { + || PWORKSPACE->getAnimationInProgress()) && !window.getPinned()) { const auto MONITOR = getMonitorFromWindow(&window); @@ -447,7 +447,7 @@ void CWindowManager::refreshDirtyWindows() { } // or that it is not a non-fullscreen window in a fullscreen workspace thats under - if (bHasFullscreenWindow && !window.getFullscreen() && (window.getUnderFullscreen() || !window.getIsFloating())) { + if (bHasFullscreenWindow && !window.getFullscreen() && (window.getUnderFullscreen() || !window.getIsFloating()) && !window.getPinned()) { Values[0] = 150000; Values[1] = 150000; if (VECTORDELTANONZERO(window.getLastUpdatePosition(), Vector2D(Values[0], Values[1]))) {