mirror of
https://github.com/hyprwm/Hyprland.git
synced 2024-12-01 18:55:02 +03:00
Add activeworkspace
hyprctl command (#2202)
* Add `activeworkspace` hyprctl command * fix format in hyprctl * Make stuff more shared in workspace hyprctl --------- Co-authored-by: vaxerski <43317083+vaxerski@users.noreply.github.com>
This commit is contained in:
parent
cde7f79af0
commit
ac3edec14b
@ -23,6 +23,7 @@ const std::string USAGE = R"#(usage: hyprctl [(opt)flags] [command] [(opt)args]
|
||||
commands:
|
||||
monitors
|
||||
workspaces
|
||||
activeworkspace
|
||||
clients
|
||||
activewindow
|
||||
layers
|
||||
@ -50,6 +51,8 @@ flags:
|
||||
--batch -> execute a batch of commands, separated by ';'
|
||||
)#";
|
||||
|
||||
#define PAD
|
||||
|
||||
void request(std::string arg, int minArgs = 0) {
|
||||
const auto SERVERSOCKET = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
|
||||
@ -327,6 +330,8 @@ int main(int argc, char** argv) {
|
||||
request(fullRequest);
|
||||
else if (fullRequest.contains("/workspaces"))
|
||||
request(fullRequest);
|
||||
else if (fullRequest.contains("/activeworkspace"))
|
||||
request(fullRequest);
|
||||
else if (fullRequest.contains("/activewindow"))
|
||||
request(fullRequest);
|
||||
else if (fullRequest.contains("/layers"))
|
||||
|
@ -188,17 +188,11 @@ std::string clientsRequest(HyprCtl::eHyprCtlOutputFormat format) {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string workspacesRequest(HyprCtl::eHyprCtlOutputFormat format) {
|
||||
std::string result = "";
|
||||
if (format == HyprCtl::FORMAT_JSON) {
|
||||
result += "[";
|
||||
|
||||
for (auto& w : g_pCompositor->m_vWorkspaces) {
|
||||
static std::string getWorkspaceData(CWorkspace* w, HyprCtl::eHyprCtlOutputFormat format) {
|
||||
const auto PLASTW = w->getLastFocusedWindow();
|
||||
const auto PMONITOR = g_pCompositor->getMonitorFromID(w->m_iMonitorID);
|
||||
|
||||
result += getFormat(
|
||||
R"#({
|
||||
if (format == HyprCtl::FORMAT_JSON) {
|
||||
return getFormat(R"#({
|
||||
"id": %i,
|
||||
"name": "%s",
|
||||
"monitor": "%s",
|
||||
@ -206,24 +200,41 @@ std::string workspacesRequest(HyprCtl::eHyprCtlOutputFormat format) {
|
||||
"hasfullscreen": %s,
|
||||
"lastwindow": "0x%lx",
|
||||
"lastwindowtitle": "%s"
|
||||
},)#",
|
||||
w->m_iID, escapeJSONStrings(w->m_szName).c_str(), escapeJSONStrings(PMONITOR ? PMONITOR->szName : "?").c_str(), g_pCompositor->getWindowsOnWorkspace(w->m_iID),
|
||||
((int)w->m_bHasFullscreenWindow == 1 ? "true" : "false"), PLASTW, PLASTW ? escapeJSONStrings(PLASTW->m_szTitle).c_str() : "");
|
||||
})#",
|
||||
w->m_iID, escapeJSONStrings(w->m_szName).c_str(), escapeJSONStrings(PMONITOR ? PMONITOR->szName : "?").c_str(),
|
||||
g_pCompositor->getWindowsOnWorkspace(w->m_iID), ((int)w->m_bHasFullscreenWindow == 1 ? "true" : "false"), PLASTW,
|
||||
PLASTW ? escapeJSONStrings(PLASTW->m_szTitle).c_str() : "");
|
||||
} else {
|
||||
return getFormat("workspace ID %i (%s) on monitor %s:\n\twindows: %i\n\thasfullscreen: %i\n\tlastwindow: 0x%lx\n\tlastwindowtitle: %s\n\n", w->m_iID, w->m_szName.c_str(),
|
||||
PMONITOR ? PMONITOR->szName.c_str() : "?", g_pCompositor->getWindowsOnWorkspace(w->m_iID), (int)w->m_bHasFullscreenWindow, PLASTW,
|
||||
PLASTW ? PLASTW->m_szTitle.c_str() : "");
|
||||
}
|
||||
}
|
||||
|
||||
std::string activeWorkspaceRequest(HyprCtl::eHyprCtlOutputFormat format) {
|
||||
std::string result = "";
|
||||
auto w = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace);
|
||||
return getWorkspaceData(w, format);
|
||||
}
|
||||
|
||||
std::string workspacesRequest(HyprCtl::eHyprCtlOutputFormat format) {
|
||||
std::string result = "";
|
||||
|
||||
if (format == HyprCtl::FORMAT_JSON) {
|
||||
result += "[";
|
||||
for (auto& w : g_pCompositor->m_vWorkspaces) {
|
||||
result += getWorkspaceData(w.get(), format);
|
||||
result += ",";
|
||||
}
|
||||
|
||||
// remove trailing comma
|
||||
result.pop_back();
|
||||
|
||||
result += "]";
|
||||
} else {
|
||||
for (auto& w : g_pCompositor->m_vWorkspaces) {
|
||||
const auto PLASTW = w->getLastFocusedWindow();
|
||||
const auto PMONITOR = g_pCompositor->getMonitorFromID(w->m_iMonitorID);
|
||||
result += getFormat("workspace ID %i (%s) on monitor %s:\n\twindows: %i\n\thasfullscreen: %i\n\tlastwindow: 0x%lx\n\tlastwindowtitle: %s\n\n", w->m_iID,
|
||||
w->m_szName.c_str(), PMONITOR ? PMONITOR->szName.c_str() : "?", g_pCompositor->getWindowsOnWorkspace(w->m_iID), (int)w->m_bHasFullscreenWindow,
|
||||
PLASTW, PLASTW ? PLASTW->m_szTitle.c_str() : "");
|
||||
result += getWorkspaceData(w.get(), format);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -815,9 +826,7 @@ std::string dispatchSetCursor(std::string request) {
|
||||
int size = 0;
|
||||
try {
|
||||
size = std::stoi(SIZESTR);
|
||||
} catch (...) {
|
||||
return "size not int";
|
||||
}
|
||||
} catch (...) { return "size not int"; }
|
||||
|
||||
if (size <= 0)
|
||||
return "size not positive";
|
||||
@ -1215,6 +1224,8 @@ std::string getReply(std::string request) {
|
||||
return monitorsRequest(format);
|
||||
else if (request == "workspaces")
|
||||
return workspacesRequest(format);
|
||||
else if (request == "activeworkspace")
|
||||
return activeWorkspaceRequest(format);
|
||||
else if (request == "clients")
|
||||
return clientsRequest(format);
|
||||
else if (request == "kill")
|
||||
|
Loading…
Reference in New Issue
Block a user