mirror of
https://github.com/levnikmyskin/hyprland-virtual-desktops.git
synced 2024-08-17 07:10:22 +03:00
Printdesks command (#42)
* feat: start of printdesks command * feat: update README, finish printdesks print * fix: support for new pointer wrapper for monitors * feat: easier printdesks implementation * feat: rename printdesks to printstate, only use active layout
This commit is contained in:
parent
b57c6c002f
commit
6bbcc08fe0
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ compile_flags.txt
|
|||||||
compile_commands.json
|
compile_commands.json
|
||||||
.cache
|
.cache
|
||||||
result/
|
result/
|
||||||
|
.idea
|
@ -116,6 +116,7 @@ Since version 2.2, this plugin exposes a couple of `hyprctl` commands. That is,
|
|||||||
| Command | description | args | example|
|
| Command | description | args | example|
|
||||||
|------------|-------------|------|--------|
|
|------------|-------------|------|--------|
|
||||||
| printdesk (vdesk)| Prints to Hyprland log the specified vdesk or the currently active vdesk* (if no argument is given) | optional vdesk, see [above](#hyprctl-dispatchers) | `hyprctl printdesk` or `hyprctl printdesk 2` or `hyprctl printdesk coding`|
|
| printdesk (vdesk)| Prints to Hyprland log the specified vdesk or the currently active vdesk* (if no argument is given) | optional vdesk, see [above](#hyprctl-dispatchers) | `hyprctl printdesk` or `hyprctl printdesk 2` or `hyprctl printdesk coding`|
|
||||||
|
| printstate | Prints state of all vdesks | `none` | `hyprctl printstate` |
|
||||||
| printlayout | print to Hyprland logs the current layout | `none` | `hyprctl printlayout` |
|
| printlayout | print to Hyprland logs the current layout | `none` | `hyprctl printlayout` |
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include <hyprland/src/helpers/memory/SharedPtr.hpp>
|
#include <hyprland/src/helpers/memory/SharedPtr.hpp>
|
||||||
|
|
||||||
typedef std::unordered_map<int, int> WorkspaceMap;
|
typedef std::unordered_map<int, int> WorkspaceMap;
|
||||||
|
// map with CMonitor* -> hyprland workspace id
|
||||||
typedef std::unordered_map<const CMonitor*, int> Layout;
|
typedef std::unordered_map<const CMonitor*, int> Layout;
|
||||||
typedef std::string MonitorName;
|
typedef std::string MonitorName;
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ const std::string BACKCYCLE_DISPATCH_STR = "backcyclevdesks";
|
|||||||
|
|
||||||
const std::string RESET_VDESK_DISPATCH_STR = "vdeskreset";
|
const std::string RESET_VDESK_DISPATCH_STR = "vdeskreset";
|
||||||
const std::string PRINTDESK_DISPATCH_STR = "printdesk";
|
const std::string PRINTDESK_DISPATCH_STR = "printdesk";
|
||||||
|
const std::string PRINTSTATE_DISPATCH_STR = "printstate";
|
||||||
const std::string PRINTLAYOUT_DISPATCH_STR = "printlayout";
|
const std::string PRINTLAYOUT_DISPATCH_STR = "printlayout";
|
||||||
|
|
||||||
const std::string REMEMBER_NONE = "none";
|
const std::string REMEMBER_NONE = "none";
|
||||||
|
64
src/main.cpp
64
src/main.cpp
@ -174,6 +174,60 @@ std::string printVDeskDispatch(eHyprCtlOutputFormat format, std::string arg) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string printStateDispatch(eHyprCtlOutputFormat format, std::string arg) {
|
||||||
|
std::string out;
|
||||||
|
if (format == eHyprCtlOutputFormat::FORMAT_NORMAL) {
|
||||||
|
out += "Virtual desks\n";
|
||||||
|
int index = 0;
|
||||||
|
for(auto const& [vdeskId, desk] : manager->vdesksMap) {
|
||||||
|
unsigned int windows = 0;
|
||||||
|
std::string workspaces;
|
||||||
|
bool first = true;
|
||||||
|
for(auto const& [monitor, workspaceId] : desk->activeLayout(manager->conf)) {
|
||||||
|
windows += g_pCompositor->getWindowsOnWorkspace(workspaceId);
|
||||||
|
if(!first) workspaces += ", ";
|
||||||
|
else first = false;
|
||||||
|
workspaces += std::format("{}", workspaceId);
|
||||||
|
}
|
||||||
|
out += std::format(
|
||||||
|
"- {}: {}\n Focused: {}\n Populated: {}\n Workspaces: {}\n Windows: {}\n",
|
||||||
|
desk->name,
|
||||||
|
desk->id,
|
||||||
|
manager->activeVdesk().get() == desk.get(),
|
||||||
|
windows > 0,
|
||||||
|
workspaces,
|
||||||
|
windows
|
||||||
|
);
|
||||||
|
if(index++ < manager->vdesksMap.size() - 1) out += "\n";
|
||||||
|
}
|
||||||
|
} else if(format == eHyprCtlOutputFormat::FORMAT_JSON) {
|
||||||
|
std::string vdesks;
|
||||||
|
int index = 0;
|
||||||
|
for(auto const& [vdeskId, desk] : manager->vdesksMap) {
|
||||||
|
unsigned int windows = 0;
|
||||||
|
std::string workspaces;
|
||||||
|
bool first = true;
|
||||||
|
for(auto const& [monitor, workspaceId] : desk->activeLayout(manager->conf)) {
|
||||||
|
windows += g_pCompositor->getWindowsOnWorkspace(workspaceId);
|
||||||
|
if(!first) workspaces += ", ";
|
||||||
|
else first = false;
|
||||||
|
workspaces += std::format("{}", workspaceId);
|
||||||
|
}
|
||||||
|
vdesks += std::format(R"#({{
|
||||||
|
"id": {},
|
||||||
|
"name": "{}",
|
||||||
|
"focused": {},
|
||||||
|
"populated": {},
|
||||||
|
"workspaces": [{}],
|
||||||
|
"windows": {}
|
||||||
|
}})#", vdeskId, desk->name, manager->activeVdesk().get() == desk.get(), windows > 0, workspaces, windows);
|
||||||
|
if(index++ < manager->vdesksMap.size() - 1) vdesks += ",";
|
||||||
|
}
|
||||||
|
out += std::format(R"#([{}])#", vdesks);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
std::string printLayoutDispatch(eHyprCtlOutputFormat format, std::string arg) {
|
std::string printLayoutDispatch(eHyprCtlOutputFormat format, std::string arg) {
|
||||||
auto activeDesk = manager->activeVdesk();
|
auto activeDesk = manager->activeVdesk();
|
||||||
auto layout = activeDesk->activeLayout(manager->conf);
|
auto layout = activeDesk->activeLayout(manager->conf);
|
||||||
@ -290,13 +344,21 @@ void registerHyprctlCommands() {
|
|||||||
if (!ptr)
|
if (!ptr)
|
||||||
printLog(std::format("Failed to register hyprctl command: {}", PRINTLAYOUT_DISPATCH_STR));
|
printLog(std::format("Failed to register hyprctl command: {}", PRINTLAYOUT_DISPATCH_STR));
|
||||||
|
|
||||||
|
// Register printstate
|
||||||
|
cmd.name = PRINTSTATE_DISPATCH_STR;
|
||||||
|
cmd.fn = printStateDispatch;
|
||||||
|
cmd.exact = true;
|
||||||
|
ptr = HyprlandAPI::registerHyprCtlCommand(PHANDLE, cmd);
|
||||||
|
if (!ptr)
|
||||||
|
printLog(std::format("Failed to register hyprctl command: {}", PRINTSTATE_DISPATCH_STR));
|
||||||
|
|
||||||
// Register printdesk
|
// Register printdesk
|
||||||
cmd.name = PRINTDESK_DISPATCH_STR;
|
cmd.name = PRINTDESK_DISPATCH_STR;
|
||||||
cmd.fn = printVDeskDispatch;
|
cmd.fn = printVDeskDispatch;
|
||||||
cmd.exact = false;
|
cmd.exact = false;
|
||||||
ptr = HyprlandAPI::registerHyprCtlCommand(PHANDLE, cmd);
|
ptr = HyprlandAPI::registerHyprCtlCommand(PHANDLE, cmd);
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
printLog(std::format("Failed to register hyprctl command: {}", VDESK_DISPATCH_STR));
|
printLog(std::format("Failed to register hyprctl command: {}", PRINTDESK_DISPATCH_STR));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do NOT change this function.
|
// Do NOT change this function.
|
||||||
|
Loading…
Reference in New Issue
Block a user