Skip to content

Commit

Permalink
fix: focusWindow on hidden workspace triggers another focusWindow. (#…
Browse files Browse the repository at this point in the history
…3216)

This commit address an issue where focusing a window on a hidden
workspace inadvertently triggered a second `focusWindow` call due to
simulated mouse movement. This behaviour led to the incorrect focus on
the window under the cursor instead of target window of method
`focusWindow()`, disrupting `focusurgentorlast` and `focuscurrentorlast`
dispatchers. Introduced a flag to the `CMonitor::changeWorkspace()`
method to prevent simulated mouse movements. This flag is set to false
by default. Changed the `focusWindow()` method accordingly to set this
flag to true when the target window is in a hidden workspace.
  • Loading branch information
memchr committed Sep 8, 2023
1 parent 398e861 commit 6648274
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) {
const auto PWORKSPACE = getWorkspaceByID(pWindow->m_iWorkspaceID);
PWORKSPACE->m_pLastFocusedWindow = pWindow;
const auto PMONITOR = getMonitorFromID(PWORKSPACE->m_iMonitorID);
PMONITOR->changeWorkspace(PWORKSPACE);
PMONITOR->changeWorkspace(PWORKSPACE, false, true);
// changeworkspace already calls focusWindow
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/Monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ float CMonitor::getDefaultScale() {
return 1;
}

void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal) {
void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal, bool noMouseMove) {
if (!pWorkspace)
return;

Expand Down Expand Up @@ -543,8 +543,8 @@ void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal) {

g_pCompositor->focusWindow(pWindow);
}

g_pInputManager->simulateMouseMovement();
if (!noMouseMove)
g_pInputManager->simulateMouseMovement();

g_pLayoutManager->getCurrentLayout()->recalculateMonitor(ID);

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/Monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class CMonitor {
void setMirror(const std::string&);
bool isMirror();
float getDefaultScale();
void changeWorkspace(CWorkspace* const pWorkspace, bool internal = false);
void changeWorkspace(CWorkspace* const pWorkspace, bool internal = false, bool noMouseMove = false);
void changeWorkspace(const int& id, bool internal = false);
void setSpecialWorkspace(CWorkspace* const pWorkspace);
void setSpecialWorkspace(const int& id);
Expand Down

0 comments on commit 6648274

Please sign in to comment.