diff --git a/include/HyprlandService.h b/include/HyprlandService.h index fd7c1b9..8d62753 100644 --- a/include/HyprlandService.h +++ b/include/HyprlandService.h @@ -11,6 +11,10 @@ class HyprlandService { public: static Workspace getCurrentWorkspace(); static std::list getClients(); + static std::list getClientsOnActiveWorkspace(); + static void setClientFloating(Client&); + static void setClientTiled(Client&); + static void toggleClientFloating(Client&); static std::string exec(const std::string& command); }; #endif diff --git a/src/HyprlandService.cpp b/src/HyprlandService.cpp index 9a501af..2e3312a 100644 --- a/src/HyprlandService.cpp +++ b/src/HyprlandService.cpp @@ -32,3 +32,30 @@ std::list HyprlandService::getClients() { json j = json::parse(exec("/usr/bin/hyprctl clients -j")); return j.get>(); }; + +std::list HyprlandService::getClientsOnActiveWorkspace() { + std::list clients = HyprlandService::getClients(); + int activeWorkspaceID = HyprlandService::getCurrentWorkspace().id; + + for (auto it = clients.begin(); it != clients.end(); ) { + if (it->workspace.id != activeWorkspaceID) { + it = clients.erase(it); + } else { + ++it; + } + } + + return clients; +}; + +void HyprlandService::setClientFloating(Client& c) { + exec("/usr/bin/hyprctl dispatch setfloating address:" + c.address); +}; + +void HyprlandService::setClientTiled(Client& c) { + exec("/usr/bin/hyprctl dispatch settiled address:" + c.address); +} + +void HyprlandService::toggleClientFloating(Client& c) { + exec("/usr/bin/hyprctl dispatch togglefloating address:" + c.address); +}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 08efa77..e07601d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include #include "../include/HyprlandService.h" +#include int main(int, char**){ Workspace w = HyprlandService::getCurrentWorkspace(); @@ -15,6 +16,8 @@ int main(int, char**){ std::cout << " ispersistent: " << w.ispersistent << std::endl; std::cout << std::endl; + std::cout << "---------------------------------------------" << std::endl << std::endl; + std::list clients = HyprlandService::getClients(); for (const auto& c : clients) { std::cout << "Client:" << std::endl; @@ -43,4 +46,33 @@ int main(int, char**){ std::cout << " xdgDescription: " << c.xdgDescription << std::endl; std::cout << std::endl; } + + std::cout << "---------------------------------------------" << std::endl << std::endl; + + std::list activeClients = HyprlandService::getClientsOnActiveWorkspace(); + for (const auto& c : activeClients) { + std::cout << "Active client:" << std::endl; + std::cout << " workspace.id: " << c.workspace.id << std::endl; + std::cout << " workspace.name: " << c.workspace.name << std::endl; + std::cout << " className: " << c.className << std::endl; + std::cout << " title: " << c.title << std::endl; + std::cout << std::endl; + } + + + std::cout << "Setting " << activeClients.front().className << " into floating mode..." << std::endl; + sleep(2); + HyprlandService::setClientFloating(activeClients.front()); + + std::cout << "Setting " << activeClients.front().className << " into tiled mode..." << std::endl; + sleep(2); + HyprlandService::setClientTiled(activeClients.front()); + + std::cout << "Toggling floating mode for " << activeClients.front().className << " ..." << std::endl; + sleep(2); + HyprlandService::toggleClientFloating(activeClients.front()); + + std::cout << "Toggling floating mode for " << activeClients.front().className << " once more..." << std::endl; + sleep(2); + HyprlandService::toggleClientFloating(activeClients.front()); }