Skip to content

Commit

Permalink
Get current monitor based on focused window, not mouse cursor position
Browse files Browse the repository at this point in the history
  • Loading branch information
zjeffer committed Jun 2, 2024
1 parent df17c6f commit 1d5c1e1
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 1d5c1e1

Please sign in to comment.