first Version

This commit is contained in:
willifan 2024-03-13 19:01:27 +01:00
commit 0c4bef47e8
149 changed files with 32273 additions and 0 deletions

View file

@ -0,0 +1,167 @@
#include <string>
#include <iostream>
#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>
using json = nlohmann::json;
json workspaces, clients;
std::string command(const char* command);
json generate()
{
return "";
}
json getWorkspaces()
{
workspaces = json::parse(command("hyprctl workspaces -j"));
return "";
}
json getClients()
{
clients = json::parse(command("hyprctl clients -j"));
return "";
}
std::string command(const char* command)
{
char buffer[128];
std::string result;
FILE* pipe = popen(command, "r");
if(!pipe)
{
std::cerr << "No pipe opened" << std::endl;
return "";
}
while(!feof(pipe))
{
if(fgets(buffer, 128, pipe) != NULL)
{
result += buffer;
}
}
pclose(pipe);
return result;
}
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();
}
else if (message.find("moveworkspace") == 0)
{
std::cout << "4" << std::endl;
workspaces = getWorkspaces();
}
else if (message.find("openwindow") == 0)
{
std::cout << "5" << std::endl;
}
else if (message.find("closewindow") == 0)
{
std::cout << "6" << std::endl;
}
else if (message.find("movewindow") == 0)
{
std::cout << "7" << std::endl;
}
}
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);
if (sockfd == -1) {
std::cerr << "Error: Failed to create socket\n";
return 1;
}
// 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);
// Connect to the IPC socket
if (connect(sockfd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
std::cerr << "Error: Failed to connect to IPC socket\n";
close(sockfd);
return 1;
}
// Receive and print messages from the IPC socket
char buffer[1024];
ssize_t bytes_received;
while ((bytes_received = recv(sockfd, buffer, sizeof(buffer), 0)) > 0) {
std::string message = std::string(buffer, bytes_received);
std::istringstream iss(message);
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";
}
// Close the socket
close(sockfd);
return 0;
}

BIN
scripts/clients/src/test Executable file

Binary file not shown.