From 1d5c1e1a409f841dda7814c0fef10fbdebf5d429 Mon Sep 17 00:00:00 2001 From: zjeffer <4633209+zjeffer@users.noreply.github.com> Date: Sun, 2 Jun 2024 12:11:29 +0200 Subject: [PATCH] Get current monitor based on focused window, not mouse cursor position --- src/main.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7a62f22..be1076c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -88,30 +88,35 @@ const std::string& getWorkspaceFromMonitor(CMonitor* monitor, const std::string& return g_vMonitorWorkspaceMap[monitor->ID][workspaceIndex]; } -void splitWorkspace(const std::string& workspace) +CMonitor* getCurrentMonitor() { - CMonitor* monitor = g_pCompositor->getMonitorFromCursor(); + // get last focused monitor, because some people switch monitors with a keybind while the cursor is on a different monitor + if (CMonitor* monitor = g_pCompositor->m_pLastMonitor.lock().get()) { + return monitor; + } + Debug::log(WARN, "[split-monitor-workspaces] Last monitor does not exist, falling back to cursor's monitor"); + // fallback to the monitor the cursor is on + return g_pCompositor->getMonitorFromCursor(); +} - HyprlandAPI::invokeHyprctlCommand("dispatch", "workspace " + getWorkspaceFromMonitor(monitor, workspace)); +void splitWorkspace(const std::string& workspace) +{ + HyprlandAPI::invokeHyprctlCommand("dispatch", "workspace " + getWorkspaceFromMonitor(getCurrentMonitor(), workspace)); } void splitMoveToWorkspace(const std::string& workspace) { - CMonitor* monitor = g_pCompositor->getMonitorFromCursor(); - - HyprlandAPI::invokeHyprctlCommand("dispatch", "movetoworkspace " + getWorkspaceFromMonitor(monitor, workspace)); + HyprlandAPI::invokeHyprctlCommand("dispatch", "movetoworkspace " + getWorkspaceFromMonitor(getCurrentMonitor(), workspace)); } void splitMoveToWorkspaceSilent(const std::string& workspace) { - CMonitor* monitor = g_pCompositor->getMonitorFromCursor(); - - HyprlandAPI::invokeHyprctlCommand("dispatch", "movetoworkspacesilent " + getWorkspaceFromMonitor(monitor, workspace)); + HyprlandAPI::invokeHyprctlCommand("dispatch", "movetoworkspacesilent " + getWorkspaceFromMonitor(getCurrentMonitor(), workspace)); } void changeMonitor(bool quiet, const std::string& value) { - CMonitor* monitor = g_pCompositor->getMonitorFromCursor(); + CMonitor* monitor = getCurrentMonitor(); CMonitor* nextMonitor = nullptr;