Adding files
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.cache/
|
||||
build/
|
||||
10
CMakeLists.txt
Normal file
10
CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.10.0)
|
||||
project(hyprland-toggle-tiling VERSION 0.1.0 LANGUAGES C CXX)
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.12.0/json.tar.xz)
|
||||
FetchContent_MakeAvailable(json)
|
||||
|
||||
add_executable(htt main.cpp HyprlandService.cpp Workspace.cpp Client.cpp)
|
||||
target_link_libraries(htt PRIVATE nlohmann_json::nlohmann_json)
|
||||
target_include_directories(htt PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
31
Client.cpp
Normal file
31
Client.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#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);
|
||||
}
|
||||
46
Client.h
Normal file
46
Client.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef CLIENT_H
|
||||
#define CLIENT_H
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
struct WorkspaceSignature {
|
||||
public:
|
||||
int id;
|
||||
std::string name;
|
||||
|
||||
friend void from_json(const json& j, WorkspaceSignature& ws);
|
||||
};
|
||||
|
||||
class Client {
|
||||
public:
|
||||
std::string address;
|
||||
bool mapped;
|
||||
bool hidden;
|
||||
std::array<int, 2> size;
|
||||
WorkspaceSignature workspace;
|
||||
bool floating;
|
||||
bool pseudo;
|
||||
int monitor;
|
||||
std::string className;
|
||||
std::string title;
|
||||
std::string initialClass;
|
||||
std::string initialTitle;
|
||||
int pid;
|
||||
bool xwayland;
|
||||
bool pinned;
|
||||
int fullscreen;
|
||||
int fullscreenClient;
|
||||
std::string swallowing;
|
||||
int focusHistory;
|
||||
bool inhibitingIdle;
|
||||
std::string xdgTag;
|
||||
std::string xdgDescription;
|
||||
|
||||
friend void from_json(const json& j, Client& client);
|
||||
};
|
||||
|
||||
#endif
|
||||
34
HyprlandService.cpp
Normal file
34
HyprlandService.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#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>>();
|
||||
};
|
||||
16
HyprlandService.h
Normal file
16
HyprlandService.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef HYPRLAND_SERVICE_H
|
||||
#define HYPRLAND_SERVICE_H
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include "Workspace.h"
|
||||
#include "Client.h"
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
class HyprlandService {
|
||||
public:
|
||||
static Workspace getCurrentWorkspace();
|
||||
static std::list<Client> getClients();
|
||||
static std::string exec(const std::string& command);
|
||||
};
|
||||
#endif
|
||||
13
Workspace.cpp
Normal file
13
Workspace.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#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);
|
||||
}
|
||||
23
Workspace.h
Normal file
23
Workspace.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef WORKSPACE_H
|
||||
#define WORKSPACE_H
|
||||
#include <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
class Workspace {
|
||||
public:
|
||||
int id;
|
||||
std::string name;
|
||||
std::string monitor;
|
||||
int monitorID;
|
||||
int windows;
|
||||
bool hasfullscreen;
|
||||
std::string lastwindow;
|
||||
std::string lastwindowtitle;
|
||||
bool ispersistent;
|
||||
|
||||
friend void from_json(const json& j, Workspace& workspace);
|
||||
};
|
||||
|
||||
#endif
|
||||
44
main.cpp
Normal file
44
main.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <iostream>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user