add workspace clicks
This commit is contained in:
@@ -335,6 +335,54 @@ HyprlandService::Monitor *HyprlandService::getMonitorByIndex(std::size_t index)
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
void HyprlandService::switchToWorkspace(int monitorId, int slot)
|
||||
{
|
||||
auto it = m_monitors.find(monitorId);
|
||||
if (it == m_monitors.end())
|
||||
{
|
||||
std::cerr << "[Hyprland] switchToWorkspace: monitor " << monitorId << " not found\n";
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &monitor = it->second;
|
||||
auto wsIt = monitor.workspaceStates.find(slot);
|
||||
std::string cmd;
|
||||
|
||||
if (wsIt != monitor.workspaceStates.end() && wsIt->second.hyprId >= 0)
|
||||
{
|
||||
// Use the Hyprland workspace id if available
|
||||
cmd = "hyprctl dispatch workspace " + std::to_string(wsIt->second.hyprId);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback: ask Hyprland to switch/create a workspace on the monitor
|
||||
// by using the slot number and the monitor name. Syntax: "<slot>:<monitor>"
|
||||
// Example: hyprctl dispatch workspace 2:DP-1
|
||||
// This may vary by Hyprland version; if it doesn't work on your system
|
||||
// adjust the command accordingly.
|
||||
std::string monName = monitor.name;
|
||||
if (monName.empty())
|
||||
{
|
||||
// As a last resort, just try the slot number globally
|
||||
cmd = "hyprctl dispatch workspace " + std::to_string(slot);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Quote monitor name in case it contains spaces
|
||||
cmd = "hyprctl dispatch workspace " + std::to_string(slot) + ":\"" + monName + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
(void)SystemHelper::get_command_output(cmd.c_str());
|
||||
}
|
||||
catch (const std::exception &ex)
|
||||
{
|
||||
std::cerr << "[Hyprland] Failed to dispatch workspace command: " << ex.what() << " cmd=" << cmd << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
const HyprlandService::Monitor *HyprlandService::getMonitorByIndex(std::size_t index) const
|
||||
{
|
||||
if (index >= m_monitors.size())
|
||||
|
||||
Reference in New Issue
Block a user