First working version
This commit is contained in:
parent
c8ac4b08ea
commit
d507864ec1
8 changed files with 194 additions and 135 deletions
|
@ -1,50 +1,150 @@
|
|||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include <sstream>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
|
||||
//test
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
json workspaces, clients;
|
||||
json workspacesInput, workspacesOutput;
|
||||
|
||||
std::string command(const char* command);
|
||||
/*json workspacesOutput = json::parse(R"(
|
||||
{
|
||||
"normal": [
|
||||
{
|
||||
"occupied": bool,
|
||||
"monitorID": int,
|
||||
"active": bool,
|
||||
"icon": str
|
||||
}
|
||||
],
|
||||
"special": [
|
||||
{
|
||||
"ID": int,
|
||||
"name": str,
|
||||
"occupied": bool,
|
||||
"monitorID": int,
|
||||
"active": bool,
|
||||
"icon": str
|
||||
}
|
||||
]
|
||||
}
|
||||
)");*/
|
||||
|
||||
json generate()
|
||||
std::map<int, std::string> test;
|
||||
|
||||
std::string command(std::string command);
|
||||
std::string getIcon(std::string windowAddress);
|
||||
|
||||
|
||||
|
||||
|
||||
std::string getIcon(std::string windowAddress)
|
||||
{
|
||||
return "";
|
||||
|
||||
json clients = json::parse(command("hyprctl clients -j"));
|
||||
|
||||
for (json& client : clients)
|
||||
{
|
||||
|
||||
if (windowAddress == client["address"])
|
||||
{
|
||||
std::string initClass = client["initialClass"];
|
||||
if (initClass == "")
|
||||
{
|
||||
initClass = "aguiienagi";
|
||||
}
|
||||
int pid = client["pid"];
|
||||
std::string cmd ="cd /home/willifan/.config/eww/scripts/ && ./test.sh ";
|
||||
cmd.append(initClass);
|
||||
cmd.append(" ");
|
||||
cmd.append(std::to_string(pid));
|
||||
return command(cmd);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return "placeholder";
|
||||
|
||||
}
|
||||
|
||||
|
||||
json getWorkspaces()
|
||||
void getWorkspaces()
|
||||
{
|
||||
|
||||
workspaces = json::parse(command("hyprctl workspaces -j"));
|
||||
return "";
|
||||
workspacesInput = json::parse(command("hyprctl workspaces -j"));
|
||||
|
||||
workspacesOutput.clear();
|
||||
|
||||
int specialIndex = 0;
|
||||
|
||||
for(auto& workspace : workspacesInput)
|
||||
{
|
||||
if(workspace["id"] >= 1 && workspace["id"] <= 9)
|
||||
{
|
||||
int index = workspace["id"].get<int>() - 1;
|
||||
|
||||
workspacesOutput[index]["normal"]["ID"] = index + 1;
|
||||
|
||||
workspacesOutput[index]["normal"]["occupied"] = workspace["windows"];
|
||||
|
||||
workspacesOutput[index]["normal"]["monitorID"] = workspace["monitorID"];
|
||||
|
||||
if (!(workspace["lastwindow"] == "0x0"))
|
||||
{
|
||||
|
||||
workspacesOutput[index]["normal"]["icon"] = getIcon(workspace["lastwindow"]);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
workspacesOutput[index]["normal"]["icon"] = "";
|
||||
}
|
||||
|
||||
}
|
||||
else if (std::string(workspace["name"]).find("special:") == 0)
|
||||
{
|
||||
|
||||
workspacesOutput[specialIndex]["special"]["ID"] = specialIndex;
|
||||
|
||||
workspacesOutput[specialIndex]["special"]["name"] = workspace["name"];
|
||||
|
||||
workspacesOutput[specialIndex]["special"]["occupied"] = workspace["windows"];
|
||||
|
||||
workspacesOutput[specialIndex]["special"]["monitorID"] = workspace["monitorID"];
|
||||
|
||||
if (!(workspace["lastwindow"] == "0x0"))
|
||||
{
|
||||
|
||||
workspacesOutput[specialIndex]["special"]["icon"] = getIcon(workspace["lastwindow"]);
|
||||
|
||||
}
|
||||
|
||||
specialIndex++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::cout << workspacesOutput << std::endl;
|
||||
}
|
||||
|
||||
|
||||
json getClients()
|
||||
{
|
||||
clients = json::parse(command("hyprctl clients -j"));
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
std::string command(const char* command)
|
||||
std::string command(std::string inputCommand)
|
||||
{
|
||||
const char* command = inputCommand.c_str();
|
||||
char buffer[128];
|
||||
std::string result;
|
||||
FILE* pipe = popen(command, "r");
|
||||
|
@ -73,35 +173,27 @@ void handle(std::string message)
|
|||
|
||||
if (message.find("workspace") == 0)
|
||||
{
|
||||
std::cout << "1" << std::endl;
|
||||
workspaces = getWorkspaces();
|
||||
}
|
||||
else if (message.find("createworkspace") == 0)
|
||||
{
|
||||
std::cout << "2" << std::endl;
|
||||
workspaces = getWorkspaces();
|
||||
}
|
||||
else if (message.find("destroyworkspace") == 0)
|
||||
{
|
||||
std::cout << "3" << std::endl;
|
||||
workspaces = getWorkspaces();
|
||||
getWorkspaces();
|
||||
}
|
||||
else if (message.find("moveworkspace") == 0)
|
||||
{
|
||||
std::cout << "4" << std::endl;
|
||||
workspaces = getWorkspaces();
|
||||
getWorkspaces();
|
||||
}
|
||||
else if (message.find("openwindow") == 0)
|
||||
{
|
||||
std::cout << "5" << std::endl;
|
||||
getWorkspaces();
|
||||
}
|
||||
else if (message.find("closewindow") == 0)
|
||||
{
|
||||
std::cout << "6" << std::endl;
|
||||
getWorkspaces();
|
||||
}
|
||||
else if (message.find("movewindow") == 0)
|
||||
{
|
||||
std::cout << "7" << std::endl;
|
||||
getWorkspaces();
|
||||
}
|
||||
else if (message.find("activewindow") == 0)
|
||||
{
|
||||
getWorkspaces();
|
||||
}
|
||||
|
||||
|
||||
|
@ -111,14 +203,7 @@ int main(int argc, char const *argv[])
|
|||
{
|
||||
|
||||
std::string socketPath = "/tmp/hypr/" + std::string(std::getenv("HYPRLAND_INSTANCE_SIGNATURE")) + "/.socket2.sock";
|
||||
std::ifstream socketStream(socketPath);
|
||||
while(socketStream)
|
||||
{
|
||||
std::string line;
|
||||
socketStream >> line;
|
||||
std::cout << line << std::endl;
|
||||
}
|
||||
const char* socketPathPtr = socketPath.c_str();
|
||||
|
||||
|
||||
// Create a socket
|
||||
int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
|
@ -132,7 +217,7 @@ int main(int argc, char const *argv[])
|
|||
// Define the address of the IPC socket
|
||||
struct sockaddr_un addr;
|
||||
addr.sun_family = AF_UNIX;
|
||||
strncpy(addr.sun_path, socketPathPtr, sizeof(addr.sun_path) - 1);
|
||||
strncpy(addr.sun_path, socketPath.c_str(), sizeof(addr.sun_path) - 1);
|
||||
|
||||
// Connect to the IPC socket
|
||||
if (connect(sockfd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
|
||||
|
@ -152,11 +237,9 @@ int main(int argc, char const *argv[])
|
|||
std::string messageLine;
|
||||
|
||||
while(std::getline(iss, messageLine)){
|
||||
std::cout << messageLine << std::endl;
|
||||
handle(messageLine);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (bytes_received == -1) {
|
||||
std::cerr << "Error: Failed to receive message\n";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue