implemented specialWorkspaceMap

This commit is contained in:
willifan 2024-04-09 18:12:55 +02:00
parent 93598400a3
commit 0166b32872
5 changed files with 69 additions and 130 deletions

View file

@ -21,11 +21,11 @@ json workspacesOutput;
std::map<std::string, std::string> iconMap;
std::map<int, std::string> monitorMap;
const std::map<std::string, int> specialWorkspaceMap = {
{"special:super", 0},
{"special:ctrl", 1},
{"special:alt", 2},
{"special:gr", 3}
std::map<std::string, int> specialWorkspaceMap = {
{"special:ctrl", 0},
{"special:alt", 1},
{"special:altgr", 2},
{"special:strg", 3}
};
@ -155,7 +155,7 @@ void getAllWorkspaces()
{
json workspacesInput = json::parse(command("hyprctl workspaces -j"));
int specialIndex = 0;
int specialIndex = 4; //next index after specialWorkspaceMap
for(const auto& workspace : workspacesInput)
{
@ -168,10 +168,21 @@ void getAllWorkspaces()
}
else if (std::string(workspace["name"]).find("special:") == 0)
{
workspacesOutput[specialIndex]["special"].clear();
workspacesOutput[specialIndex]["special"] = getWorkspace(workspace);
std::string name = workspace["name"];
specialIndex++;
int currentIndex;
if (specialWorkspaceMap.contains(name))
{
currentIndex = specialWorkspaceMap[name];
}
else
{
currentIndex = specialIndex;
specialIndex++;
}
workspacesOutput[currentIndex]["special"].clear();
workspacesOutput[currentIndex]["special"] = getWorkspace(workspace);
}
}
@ -237,47 +248,47 @@ int main(int argc, char const *argv[])
// Create a socket
int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
if (sockfd == -1) {
std::cerr << "Error: Failed to create socket\n";
return 1;
}
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;
// Define the address of the IPC socket
struct sockaddr_un addr;
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, socketPath.c_str(), 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) {
std::cerr << "Error: Failed to connect to IPC socket\n";
close(sockfd);
return 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) {
// 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::string message = std::string(buffer, bytes_received);
std::istringstream iss(message);
std::string messageLine;
std::istringstream iss(message);
std::string messageLine;
while(std::getline(iss, messageLine)){
handle(messageLine);
}
while(std::getline(iss, messageLine)){
handle(messageLine);
}
}
if (bytes_received == -1) {
std::cerr << "Error: Failed to receive message\n";
}
}
if (bytes_received == -1) {
std::cerr << "Error: Failed to receive message\n";
}
// Close the socket
close(sockfd);
// Close the socket
close(sockfd);
return 0;
return 0;
}