Organized source tree

This commit is contained in:
2025-06-10 14:16:44 +02:00
parent b0d173873c
commit 96ce9c023a
8 changed files with 9 additions and 5 deletions

31
src/Client.cpp Normal file
View File

@@ -0,0 +1,31 @@
#include "../include/Client.h"
void from_json(const json& j, WorkspaceSignature& ws) {
j.at("id").get_to(ws.id);
j.at("name").get_to(ws.name);
}
void from_json(const json& j, Client& client) {
j.at("address").get_to(client.address);
j.at("mapped").get_to(client.mapped);
j.at("hidden").get_to(client.hidden);
j.at("size").get_to(client.size);
j.at("workspace").get_to(client.workspace);
j.at("floating").get_to(client.floating);
j.at("pseudo").get_to(client.pseudo);
j.at("monitor").get_to(client.monitor);
j.at("class").get_to(client.className); // Maps "class" JSON field to className
j.at("title").get_to(client.title);
j.at("initialClass").get_to(client.initialClass);
j.at("initialTitle").get_to(client.initialTitle);
j.at("pid").get_to(client.pid);
j.at("xwayland").get_to(client.xwayland);
j.at("pinned").get_to(client.pinned);
j.at("fullscreen").get_to(client.fullscreen);
j.at("fullscreenClient").get_to(client.fullscreenClient);
j.at("swallowing").get_to(client.swallowing);
j.at("focusHistoryID").get_to(client.focusHistory);
j.at("inhibitingIdle").get_to(client.inhibitingIdle);
j.at("xdgTag").get_to(client.xdgTag);
j.at("xdgDescription").get_to(client.xdgDescription);
}

34
src/HyprlandService.cpp Normal file
View File

@@ -0,0 +1,34 @@
#include "../include/HyprlandService.h"
using json = nlohmann::json;
std::string HyprlandService::exec(const std::string& command) {
char buffer[128];
std::string result = "";
FILE* pipe = popen(command.c_str(), "r");
if (!pipe) {
return "popen failed";
}
while (fgets(buffer, sizeof(buffer), pipe) != NULL) {
result += buffer;
}
int status = pclose(pipe);
if (status == -1) {
return "Error closing pipe";
}
return result;
};
Workspace HyprlandService::getCurrentWorkspace() {
json j = json::parse(exec("/usr/bin/hyprctl activeworkspace -j"));
return j.get<Workspace>();
};
std::list<Client> HyprlandService::getClients() {
json j = json::parse(exec("/usr/bin/hyprctl clients -j"));
return j.get<std::list<Client>>();
};

13
src/Workspace.cpp Normal file
View File

@@ -0,0 +1,13 @@
#include "../include/Workspace.h"
void from_json(const nlohmann::json &j, Workspace &w) {
j.at("id").get_to(w.id);
j.at("name").get_to(w.name);
j.at("monitor").get_to(w.monitor);
j.at("monitorID").get_to(w.monitorID);
j.at("windows").get_to(w.windows);
j.at("hasfullscreen").get_to(w.hasfullscreen);
j.at("lastwindow").get_to(w.lastwindow);
j.at("lastwindowtitle").get_to(w.lastwindowtitle);
j.at("ispersistent").get_to(w.ispersistent);
}

44
src/main.cpp Normal file
View File

@@ -0,0 +1,44 @@
#include <iostream>
#include "../include/HyprlandService.h"
int main(int, char**){
Workspace w = HyprlandService::getCurrentWorkspace();
std::cout << w.id << std::endl;
std::cout << w.name << std::endl;
std::cout << w.monitor << std::endl;
std::cout << w.monitorID << std::endl;
std::cout << w.windows << std::endl;
std::cout << w.hasfullscreen << std::endl;
std::cout << w.lastwindow << std::endl;
std::cout << w.lastwindowtitle << std::endl;
std::cout << w.ispersistent;
std::list<Client> clients = HyprlandService::getClients();
for (const auto& c : clients) {
std::cout << "Client:" << std::endl;
std::cout << " address: " << c.address << std::endl;
std::cout << " mapped: " << c.mapped << std::endl;
std::cout << " hidden: " << c.hidden << std::endl;
std::cout << " size: [" << c.size[0] << ", " << c.size[1] << "]" << std::endl;
std::cout << " workspace.id: " << c.workspace.id << std::endl;
std::cout << " workspace.name: " << c.workspace.name << std::endl;
std::cout << " floating: " << c.floating << std::endl;
std::cout << " pseudo: " << c.pseudo << std::endl;
std::cout << " monitor: " << c.monitor << std::endl;
std::cout << " className: " << c.className << std::endl;
std::cout << " title: " << c.title << std::endl;
std::cout << " initialClass: " << c.initialClass << std::endl;
std::cout << " initialTitle: " << c.initialTitle << std::endl;
std::cout << " pid: " << c.pid << std::endl;
std::cout << " xwayland: " << c.xwayland << std::endl;
std::cout << " pinned: " << c.pinned << std::endl;
std::cout << " fullscreen: " << c.fullscreen << std::endl;
std::cout << " fullscreenClient: " << c.fullscreenClient << std::endl;
std::cout << " swallowing: " << c.swallowing << std::endl;
std::cout << " focusHistory: " << c.focusHistory << std::endl;
std::cout << " inhibitingIdle: " << c.inhibitingIdle << std::endl;
std::cout << " xdgTag: " << c.xdgTag << std::endl;
std::cout << " xdgDescription: " << c.xdgDescription << std::endl;
std::cout << std::endl;
}
}