Skip to content

Commit

Permalink
keybinds: Added toggleswallow dispatcher (#5548)
Browse files Browse the repository at this point in the history
* Added `toggleswallow` dispatcher

* clang-format

* Removed brackets for 1-line if
  • Loading branch information
tomben13 authored Feb 5, 2025
1 parent 3b99e90 commit 84c9bae
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/desktop/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/desktop/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 9 additions & 4 deletions src/events/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
22 changes: 22 additions & 0 deletions src/managers/KeybindManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = "";
Expand Down
1 change: 1 addition & 0 deletions src/managers/KeybindManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 84c9bae

Please sign in to comment.