summaryrefslogtreecommitdiff
path: root/src/managers/KeybindManager.cpp
diff options
context:
space:
mode:
authorHilmar Wiegand <me@hwgnd.de>2023-04-10 21:07:49 +0200
committerGitHub <noreply@github.com>2023-04-10 20:07:49 +0100
commit7b43f9f056358667302c17d3da04c20af1e12888 (patch)
tree30f1416b0d3e46714aabe2e328188244eea471d4 /src/managers/KeybindManager.cpp
parentfa4aef4531d3ca138cc0c5a87768358fd5d7df7d (diff)
Implement window move (#2018)
Diffstat (limited to 'src/managers/KeybindManager.cpp')
-rw-r--r--src/managers/KeybindManager.cpp100
1 files changed, 53 insertions, 47 deletions
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp
index 20b9557a..6f12b8c6 100644
--- a/src/managers/KeybindManager.cpp
+++ b/src/managers/KeybindManager.cpp
@@ -28,6 +28,7 @@ CKeybindManager::CKeybindManager() {
m_mDispatchers["pseudo"] = toggleActivePseudo;
m_mDispatchers["movefocus"] = moveFocusTo;
m_mDispatchers["movewindow"] = moveActiveTo;
+ m_mDispatchers["swapwindow"] = swapActive;
m_mDispatchers["centerwindow"] = centerWindow;
m_mDispatchers["togglegroup"] = toggleGroup;
m_mDispatchers["changegroupactive"] = changeGroupActive;
@@ -174,18 +175,24 @@ bool CKeybindManager::ensureMouseBindState() {
return false;
}
-bool CKeybindManager::tryMoveFocusToMonitorInDirection(const char& dir) {
- const auto PNEWMONITOR = g_pCompositor->getMonitorInDirection(dir);
- if (!PNEWMONITOR)
+bool CKeybindManager::tryMoveFocusToMonitor(CMonitor* monitor) {
+ if (!monitor)
return false;
- Debug::log(LOG, "switching to monitor");
- const auto PNEWWORKSPACE = g_pCompositor->getWorkspaceByID(PNEWMONITOR->activeWorkspace);
- g_pCompositor->setActiveMonitor(PNEWMONITOR);
+ const auto LASTMONITOR = g_pCompositor->m_pLastMonitor;
+ if (LASTMONITOR == monitor) {
+ Debug::log(LOG, "Tried to move to active monitor");
+ return false;
+ }
+
+ const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace);
+ const auto PNEWWORKSPACE = g_pCompositor->getWorkspaceByID(monitor->activeWorkspace);
+
+ g_pCompositor->setActiveMonitor(monitor);
g_pCompositor->deactivateAllWLRWorkspaces(PNEWWORKSPACE->m_pWlrHandle);
PNEWWORKSPACE->setActive(true);
+ PNEWWORKSPACE->rememberPrevWorkspace(PWORKSPACE);
- // Focus window on new monitor
const auto PNEWWINDOW = PNEWWORKSPACE->getLastFocusedWindow();
if (PNEWWINDOW) {
g_pCompositor->focusWindow(PNEWWINDOW);
@@ -193,7 +200,7 @@ bool CKeybindManager::tryMoveFocusToMonitorInDirection(const char& dir) {
g_pCompositor->warpCursorTo(middle);
} else {
g_pCompositor->focusWindow(nullptr);
- Vector2D middle = PNEWMONITOR->vecPosition + PNEWMONITOR->vecSize / 2.f;
+ Vector2D middle = monitor->vecPosition + monitor->vecSize / 2.f;
g_pCompositor->warpCursorTo(middle);
}
@@ -1144,7 +1151,7 @@ void CKeybindManager::moveFocusTo(std::string args) {
const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
if (!PLASTWINDOW) {
- tryMoveFocusToMonitorInDirection(arg);
+ tryMoveFocusToMonitor(g_pCompositor->getMonitorInDirection(arg));
return;
}
@@ -1192,7 +1199,7 @@ void CKeybindManager::moveFocusTo(std::string args) {
Debug::log(LOG, "No window found in direction %c, looking for a monitor", arg);
- if (tryMoveFocusToMonitorInDirection(arg))
+ if (tryMoveFocusToMonitor(g_pCompositor->getMonitorInDirection(arg)))
return;
static auto* const PNOFALLBACK = &g_pConfigManager->getConfigValuePtr("general:no_focus_fallback")->intValue;
@@ -1277,28 +1284,36 @@ void CKeybindManager::focusCurrentOrLast(std::string args) {
switchToWindow(PWINDOWPREV);
}
-void CKeybindManager::moveActiveTo(std::string args) {
- char arg = args[0];
+void CKeybindManager::swapActive(std::string args) {
+ char arg = args[0];
- const auto LASTMONITOR = g_pCompositor->m_pLastMonitor;
+ if (!isDirection(args)) {
+ Debug::log(ERR, "Cannot move window in direction %c, unsupported direction. Supported: l,r,u/t,d/b", arg);
+ return;
+ }
- if (args.find("mon:") == 0) {
- // hack: save the active window
- const auto PACTIVE = g_pCompositor->m_pLastWindow;
+ Debug::log(LOG, "Swapping active window in direction %c", arg);
+ const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
+ if (!PLASTWINDOW || PLASTWINDOW->m_bIsFullscreen)
+ return;
- // monitor
- focusMonitor(args.substr(4));
+ const auto PWINDOWTOCHANGETO = g_pCompositor->getWindowInDirection(PLASTWINDOW, arg);
+ if (!PWINDOWTOCHANGETO)
+ return;
- if (LASTMONITOR == g_pCompositor->m_pLastMonitor) {
- Debug::log(ERR, "moveActiveTo: moving to an invalid mon");
- return;
- }
+ g_pLayoutManager->getCurrentLayout()->switchWindows(PLASTWINDOW, PWINDOWTOCHANGETO);
+ g_pCompositor->warpCursorTo(PLASTWINDOW->m_vRealPosition.vec() + PLASTWINDOW->m_vRealSize.vec() / 2.0);
+}
- // restore the active
- g_pCompositor->focusWindow(PACTIVE);
+void CKeybindManager::moveActiveTo(std::string args) {
+ char arg = args[0];
- moveActiveToWorkspace(std::to_string(g_pCompositor->m_pLastMonitor->activeWorkspace));
+ if (args.find("mon:") == 0) {
+ const auto PNEWMONITOR = g_pCompositor->getMonitorFromString(args.substr(4));
+ if (!PNEWMONITOR)
+ return;
+ moveActiveToWorkspace(std::to_string(PNEWMONITOR->activeWorkspace));
return;
}
@@ -1312,14 +1327,20 @@ void CKeybindManager::moveActiveTo(std::string args) {
if (!PLASTWINDOW || PLASTWINDOW->m_bIsFullscreen)
return;
+ // If the window to change to is on the same workspace, switch them
const auto PWINDOWTOCHANGETO = g_pCompositor->getWindowInDirection(PLASTWINDOW, arg);
-
- if (!PWINDOWTOCHANGETO)
+ if (PWINDOWTOCHANGETO && PWINDOWTOCHANGETO->m_iWorkspaceID == PLASTWINDOW->m_iWorkspaceID) {
+ g_pLayoutManager->getCurrentLayout()->switchWindows(PLASTWINDOW, PWINDOWTOCHANGETO);
+ g_pCompositor->warpCursorTo(PLASTWINDOW->m_vRealPosition.vec() + PLASTWINDOW->m_vRealSize.vec() / 2.0);
return;
+ }
- g_pLayoutManager->getCurrentLayout()->switchWindows(PLASTWINDOW, PWINDOWTOCHANGETO);
+ // Otherwise, we always want to move to the next monitor in that direction
+ const auto PMONITORTOCHANGETO = g_pCompositor->getMonitorInDirection(arg);
+ if (!PMONITORTOCHANGETO)
+ return;
- g_pCompositor->warpCursorTo(PLASTWINDOW->m_vRealPosition.vec() + PLASTWINDOW->m_vRealSize.vec() / 2.0);
+ moveActiveToWorkspace(std::to_string(PMONITORTOCHANGETO->activeWorkspace));
}
void CKeybindManager::toggleGroup(std::string args) {
@@ -1437,22 +1458,7 @@ void CKeybindManager::alterSplitRatio(std::string args) {
void CKeybindManager::focusMonitor(std::string arg) {
const auto PMONITOR = g_pCompositor->getMonitorFromString(arg);
-
- if (!PMONITOR || PMONITOR == g_pCompositor->m_pLastMonitor)
- return;
-
- const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace);
-
- changeworkspace("[internal]" + std::to_string(PMONITOR->activeWorkspace));
-
- // remember last workspace (internal calls don't preserve it)
-
- const auto PNEWWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace);
- if (PNEWWORKSPACE == PWORKSPACE)
- return;
-
- PNEWWORKSPACE->m_sPrevWorkspace.iID = PWORKSPACE->m_iID;
- PNEWWORKSPACE->m_sPrevWorkspace.name = PWORKSPACE->m_szName;
+ tryMoveFocusToMonitor(PMONITOR);
}
void CKeybindManager::moveCursorToCorner(std::string arg) {
@@ -1966,7 +1972,7 @@ void CKeybindManager::toggleOpaque(std::string unused) {
if (!PWINDOW)
return;
- PWINDOW->m_sAdditionalConfigData.forceOpaque = !PWINDOW->m_sAdditionalConfigData.forceOpaque;
+ PWINDOW->m_sAdditionalConfigData.forceOpaque = !PWINDOW->m_sAdditionalConfigData.forceOpaque;
PWINDOW->m_sAdditionalConfigData.forceOpaqueOverridden = true;
g_pHyprRenderer->damageWindow(PWINDOW);
@@ -2194,4 +2200,4 @@ void CKeybindManager::global(std::string args) {
return;
g_pProtocolManager->m_pGlobalShortcutsProtocolManager->sendGlobalShortcutEvent(APPID, NAME, g_pKeybindManager->m_iPassPressed);
-} \ No newline at end of file
+}