Skip to content

Commit

Permalink
Improvements to fixWorkspaceArrangement: focus correct workspace (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
zjeffer authored May 19, 2024
1 parent e3cc1a8 commit 0d15779
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,27 @@ void fixWorkspaceArrangement()
{
// for all monitors in the map, move the workspaces to the correct monitor
for (auto const& [monitorID, workspaces] : g_vMonitorWorkspaceMap) {
auto* const monitorPtr = g_pCompositor->getMonitorFromID(monitorID);
if (monitorPtr == nullptr) {
Debug::log(WARN, "[split-monitor-workspaces] fixWorkspaceArrangement: Monitor not found: {}", monitorID);
continue;
}

for (auto const& workspace : workspaces) {
PHLWORKSPACE workspacePtr = g_pCompositor->getWorkspaceByName(workspace);
if (workspacePtr != nullptr) {
auto* const monitorPtr = g_pCompositor->getMonitorFromID(monitorID);
if (monitorPtr == nullptr) {
Debug::log(WARN, "[split-monitor-workspaces] fixWorkspaceArrangement: Monitor not found: {}", monitorID);
continue;
}
g_pCompositor->moveWorkspaceToMonitor(workspacePtr, monitorPtr);
}
else {
Debug::log(WARN, "[split-monitor-workspaces] fixWorkspaceArrangement: Workspace not found: {}", workspace);
}
}
// check if currently focused workspace on this monitor actually belongs to this monitor, if not, switch to the first workspace
if (std::find(workspaces.begin(), workspaces.end(), monitorPtr->activeWorkspace->m_szName) == workspaces.end()) {
if (!workspaces.empty()) {
HyprlandAPI::invokeHyprctlCommand("dispatch", "workspace " + workspaces[0]);
}
}
}
}

Expand Down

0 comments on commit 0d15779

Please sign in to comment.