keybinds: Added toggleswallow dispatcher ()

* Added `toggleswallow` dispatcher

* clang-format

* Removed brackets for 1-line if
This commit is contained in:
Tom Benham 2025-02-05 10:56:41 +01:00 committed by GitHub
parent 3b99e906df
commit 84c9baecc6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 38 additions and 7 deletions

View file

@ -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

View file

@ -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;

View file

@ -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();

View file

@ -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 = "";

View file

@ -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);