This repository has been archived by the owner on Feb 28, 2024. It is now read-only.
/
main.cpp
56 lines (41 loc) · 2.04 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#define WLR_USE_UNSTABLE
#include <hyprland/src/helpers/Workspace.hpp>
#include <hyprland/src/plugins/PluginAPI.hpp>
#include <hyprland/src/config/ConfigManager.hpp>
#include "globals.hpp"
#include <hyprland/src/Compositor.hpp>
void grab_workspace(std::string args){
const auto workspace_to_change_to = g_pCompositor->getWorkspaceByString(args);
if (workspace_to_change_to == nullptr) {
// Make a new workspace
HyprlandAPI::invokeHyprctlCommand("dispatch", "workspace " + args);
return;
}
if (g_pConfigManager->getWorkspaceRuleFor(workspace_to_change_to).monitor != ""){
// We don't want to mess with workspaces with rules
HyprlandAPI::invokeHyprctlCommand("dispatch", "workspace " + args);
return;
}
const auto old_monitor = g_pCompositor->getMonitorFromID(workspace_to_change_to->m_iMonitorID);
const auto new_monitor = g_pCompositor->m_pLastMonitor;
if(
old_monitor->activeWorkspace == workspace_to_change_to->m_iID && // Moving from a workspace that is active on a screen
g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(new_monitor->activeWorkspace)).monitor == "" // We don't want to swap with a workspace that has a monitor rule
){
// Swap the workspaces
HyprlandAPI::invokeHyprctlCommand("dispatch", "swapactiveworkspaces " + old_monitor->szName + " " + new_monitor->szName);
} else {
// Grab the workspace
HyprlandAPI::invokeHyprctlCommand("dispatch", "moveworkspacetomonitor " + workspace_to_change_to->m_szName + " current");
HyprlandAPI::invokeHyprctlCommand("dispatch", "workspace " + workspace_to_change_to->m_szName);
}
}
// Do NOT change this function.
APICALL EXPORT std::string PLUGIN_API_VERSION() {
return HYPRLAND_API_VERSION;
}
APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
PHANDLE = handle;
HyprlandAPI::addDispatcher(PHANDLE, "grab-workspace", grab_workspace);
return {"grab-workspace", "Grabs a workspace", "CMurtagh-LGTM", "0.1.1"};
}