summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Benham <38216488+tomben13@users.noreply.github.com>2025-02-05 10:56:41 +0100
committerGitHub <noreply@github.com>2025-02-05 09:56:41 +0000
commit84c9baecc6b73f6321b2739061e3c232710f73bf (patch)
tree30bf9787abd8c5c2b7ca069de390bb78576b3bb9 /src
parent3b99e906df8b439d65e740301940e57efc057012 (diff)
keybinds: Added `toggleswallow` dispatcher (#5548)
* Added `toggleswallow` dispatcher * clang-format * Removed brackets for 1-line if
Diffstat (limited to 'src')
-rw-r--r--src/desktop/Window.cpp6
-rw-r--r--src/desktop/Window.hpp3
-rw-r--r--src/events/Windows.cpp13
-rw-r--r--src/managers/KeybindManager.cpp22
-rw-r--r--src/managers/KeybindManager.hpp1
5 files changed, 38 insertions, 7 deletions
diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp
index 6a523eec..c71fe652 100644
--- a/src/desktop/Window.cpp
+++ b/src/desktop/Window.cpp
@@ -452,8 +452,10 @@ void CWindow::moveToWorkspace(PHLWORKSPACE pWorkspace) {
}
if (const auto SWALLOWED = m_pSwallowed.lock()) {
- SWALLOWED->moveToWorkspace(pWorkspace);
- SWALLOWED->m_pMonitor = m_pMonitor;
+ if (SWALLOWED->m_bCurrentlySwallowed) {
+ SWALLOWED->moveToWorkspace(pWorkspace);
+ SWALLOWED->m_pMonitor = m_pMonitor;
+ }
}
// update xwayland coords
diff --git a/src/desktop/Window.hpp b/src/desktop/Window.hpp
index 2d004855..8444a113 100644
--- a/src/desktop/Window.hpp
+++ b/src/desktop/Window.hpp
@@ -355,7 +355,8 @@ class CWindow {
// swallowing
PHLWINDOWREF m_pSwallowed;
- bool m_bGroupSwallowed = false;
+ bool m_bCurrentlySwallowed = false;
+ bool m_bGroupSwallowed = false;
// focus stuff
bool m_bStayFocused = false;
diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp
index a068ba07..d96bb332 100644
--- a/src/events/Windows.cpp
+++ b/src/events/Windows.cpp
@@ -392,6 +392,8 @@ void Events::listener_mapWindow(void* owner, void* data) {
// Verify window swallowing. Get the swallower before calling onWindowCreated(PWINDOW) because getSwallower() wouldn't get it after if PWINDOW gets auto grouped.
const auto SWALLOWER = PWINDOW->getSwallower();
PWINDOW->m_pSwallowed = SWALLOWER;
+ if (PWINDOW->m_pSwallowed)
+ PWINDOW->m_pSwallowed->m_bCurrentlySwallowed = true;
if (PWINDOW->m_bIsFloating) {
g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW);
@@ -731,12 +733,15 @@ void Events::listener_unmapWindow(void* owner, void* data) {
// swallowing
if (valid(PWINDOW->m_pSwallowed)) {
- PWINDOW->m_pSwallowed->setHidden(false);
+ if (PWINDOW->m_pSwallowed->m_bCurrentlySwallowed) {
+ PWINDOW->m_pSwallowed->m_bCurrentlySwallowed = false;
+ PWINDOW->m_pSwallowed->setHidden(false);
- if (PWINDOW->m_sGroupData.pNextWindow.lock())
- PWINDOW->m_pSwallowed->m_bGroupSwallowed = true; // flag for the swallowed window to be created into the group where it belongs when auto_group = false.
+ if (PWINDOW->m_sGroupData.pNextWindow.lock())
+ PWINDOW->m_pSwallowed->m_bGroupSwallowed = true; // flag for the swallowed window to be created into the group where it belongs when auto_group = false.
- g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW->m_pSwallowed.lock());
+ g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW->m_pSwallowed.lock());
+ }
PWINDOW->m_pSwallowed->m_bGroupSwallowed = false;
PWINDOW->m_pSwallowed.reset();
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp
index 47cc4f67..2d6b2cb8 100644
--- a/src/managers/KeybindManager.cpp
+++ b/src/managers/KeybindManager.cpp
@@ -113,6 +113,7 @@ CKeybindManager::CKeybindManager() {
m_mDispatchers["focuswindowbyclass"] = focusWindow;
m_mDispatchers["focuswindow"] = focusWindow;
m_mDispatchers["tagwindow"] = tagWindow;
+ m_mDispatchers["toggleswallow"] = toggleSwallow;
m_mDispatchers["submap"] = setSubmap;
m_mDispatchers["pass"] = pass;
m_mDispatchers["sendshortcut"] = sendshortcut;
@@ -2306,6 +2307,27 @@ SDispatchResult CKeybindManager::tagWindow(std::string args) {
return {};
}
+SDispatchResult CKeybindManager::toggleSwallow(std::string args) {
+ PHLWINDOWREF pWindow = g_pCompositor->m_pLastWindow;
+
+ if (!valid(pWindow) || !valid(pWindow->m_pSwallowed))
+ return {};
+
+ if (pWindow->m_pSwallowed->m_bCurrentlySwallowed) {
+ // Unswallow
+ pWindow->m_pSwallowed->m_bCurrentlySwallowed = false;
+ pWindow->m_pSwallowed->setHidden(false);
+ g_pLayoutManager->getCurrentLayout()->onWindowCreated(pWindow->m_pSwallowed.lock());
+ } else {
+ // Reswallow
+ pWindow->m_pSwallowed->m_bCurrentlySwallowed = true;
+ pWindow->m_pSwallowed->setHidden(true);
+ g_pLayoutManager->getCurrentLayout()->onWindowRemoved(pWindow->m_pSwallowed.lock());
+ }
+
+ return {};
+}
+
SDispatchResult CKeybindManager::setSubmap(std::string submap) {
if (submap == "reset" || submap == "") {
m_szCurrentSelectedSubmap = "";
diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp
index cea3e3cf..712fd58d 100644
--- a/src/managers/KeybindManager.hpp
+++ b/src/managers/KeybindManager.hpp
@@ -199,6 +199,7 @@ class CKeybindManager {
static SDispatchResult circleNext(std::string);
static SDispatchResult focusWindow(std::string);
static SDispatchResult tagWindow(std::string);
+ static SDispatchResult toggleSwallow(std::string);
static SDispatchResult setSubmap(std::string);
static SDispatchResult pass(std::string);
static SDispatchResult sendshortcut(std::string);