Controlling tiled/floating mode works

This commit is contained in:
2025-06-10 14:55:42 +02:00
parent b24c9bac2d
commit 9a4619b1ba
3 changed files with 63 additions and 0 deletions

View File

@@ -32,3 +32,30 @@ std::list<Client> HyprlandService::getClients() {
json j = json::parse(exec("/usr/bin/hyprctl clients -j"));
return j.get<std::list<Client>>();
};
std::list<Client> HyprlandService::getClientsOnActiveWorkspace() {
std::list<Client> 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);
};

View File

@@ -1,5 +1,6 @@
#include <iostream>
#include "../include/HyprlandService.h"
#include <unistd.h>
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<Client> 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<Client> 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());
}