Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added toggleswallow dispatcher #5548

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/desktop/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ class CWindow {
CAnimatedVariable<float> m_fDimPercent;

// swallowing
CWindow* m_pSwallowed = nullptr;
CWindow* m_pSwallowed = nullptr;
CWindow* m_pPreviouslySwallowed = nullptr;
CWindow* m_pSwallowedBy = nullptr;

// focus stuff
bool m_bStayFocused = false;
Expand Down
13 changes: 10 additions & 3 deletions src/events/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,8 @@ void Events::listener_mapWindow(void* owner, void* data) {
// check if it's the window we want & not exempt from getting swallowed
if (valid) {
// swallow
PWINDOW->m_pSwallowed = finalFound;
PWINDOW->m_pSwallowed = finalFound;
finalFound->m_pSwallowedBy = PWINDOW;

g_pLayoutManager->getCurrentLayout()->onWindowRemoved(finalFound);

Expand Down Expand Up @@ -687,10 +688,16 @@ void Events::listener_unmapWindow(void* owner, void* data) {
g_pHyprOpenGL->makeWindowSnapshot(PWINDOW);

// swallowing
if (PWINDOW->m_pSwallowed && g_pCompositor->windowExists(PWINDOW->m_pSwallowed)) {
if (PWINDOW->m_pSwallowed) {
Copy link
Member

@vaxerski vaxerski Apr 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about previouslySwallowed? Also reset this :P

Generally I see no point in the "previously" member as the "swallowed" member shouldnt change anything. Just hide and unhide I'd say

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with a bool. Is there a better method to handle the hide and unhide in C++ ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not check isHidden()? If swallowed != null and swallowed->ishidden(), it's swallowed, if it's not hidden, it's not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this, but it could be hidden for other reasons, like if another window is fullscreen, no ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grouped windows are hidden

PWINDOW->m_pSwallowed->setHidden(false);
g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW->m_pSwallowed);
PWINDOW->m_pSwallowed = nullptr;
PWINDOW->m_pSwallowed->m_pSwallowedBy = nullptr;
PWINDOW->m_pSwallowed = nullptr;
}
// swallowed
if (PWINDOW->m_pSwallowedBy) {
PWINDOW->m_pSwallowedBy->m_pSwallowed = nullptr;
PWINDOW->m_pSwallowedBy = nullptr;
}

bool wasLastWindow = false;
Expand Down
25 changes: 25 additions & 0 deletions src/managers/KeybindManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ CKeybindManager::CKeybindManager() {
m_mDispatchers["cyclenext"] = circleNext;
m_mDispatchers["focuswindowbyclass"] = focusWindow;
m_mDispatchers["focuswindow"] = focusWindow;
m_mDispatchers["toggleswallow"] = toggleSwallow;
m_mDispatchers["submap"] = setSubmap;
m_mDispatchers["pass"] = pass;
m_mDispatchers["layoutmsg"] = layoutmsg;
Expand Down Expand Up @@ -1820,6 +1821,30 @@ void CKeybindManager::focusWindow(std::string regexp) {
g_pCompositor->warpCursorTo(PWINDOW->middle());
}

void CKeybindManager::toggleSwallow(std::string args) {
CWindow* pWindow = g_pCompositor->m_pLastWindow;
if (pWindow->m_pSwallowed) {
pWindow->m_pPreviouslySwallowed = pWindow->m_pSwallowed;

pWindow->m_pSwallowed->setHidden(false);

g_pLayoutManager->getCurrentLayout()->onWindowCreated(pWindow->m_pSwallowed);

pWindow->m_pSwallowed->m_pSwallowedBy = nullptr;
pWindow->m_pSwallowed = nullptr;

} else if (pWindow->m_pPreviouslySwallowed) {
pWindow->m_pSwallowed = pWindow->m_pPreviouslySwallowed;
pWindow->m_pSwallowed->m_pSwallowedBy = pWindow;

g_pLayoutManager->getCurrentLayout()->onWindowRemoved(pWindow->m_pPreviouslySwallowed);

pWindow->m_pPreviouslySwallowed->setHidden(true);

g_pLayoutManager->getCurrentLayout()->recalculateMonitor(pWindow->m_iMonitorID);
}
}

void 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 @@ -151,6 +151,7 @@ class CKeybindManager {
static void forceRendererReload(std::string);
static void resizeActive(std::string);
static void moveActive(std::string);
static void toggleSwallow(std::string);
static void moveWindow(std::string);
static void resizeWindow(std::string);
static void circleNext(std::string);
Expand Down
Loading