added maps for icons and monitors

This commit is contained in:
willifan 2024-03-19 00:10:43 +01:00
parent 618c02c14b
commit 7a315e3f38
7 changed files with 176 additions and 178 deletions

View file

@ -20,6 +20,11 @@ using json = nlohmann::json;
json workspacesInput, workspacesOutput;
std::map<std::string, std::string> iconMap;
std::map<int, std::string> monitorMap;
/*json workspacesOutput = json::parse(R"(
{
"normal": [
@ -43,81 +48,102 @@ json workspacesInput, workspacesOutput;
}
)");*/
std::map<int, std::string> test;
std::string command(std::string command);
std::string getIcon(std::string windowAddress);
std::string command(std::string inputCommand)
{
const char* command = inputCommand.c_str();
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;
}
std::string getIcon(std::string windowAddress)
void generateIconMap()
{
json clients = json::parse(command("hyprctl clients -j"));
for (json& client : clients)
{
if (windowAddress == client["address"])
{
std::string pid = std::to_string(static_cast<int>(client["pid"]));
if (pid == "-1")
{
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);
continue;
}
std::string initClass = client["initialClass"];
if (initClass == "")
{
initClass = "aguiienagi";
}
std::string cmd ="cd /home/willifan/.config/eww/scripts/ && ./test.sh ";
std::string test = std::string("cd /home/willifan/.config/eww/scripts/ && ./test.sh ") + initClass + " " + pid;
iconMap[client["address"]] = command(test);
}
return "placeholder";
return;
}
void generateMonitorMap()
{
json monitorsInput = json::parse(command("hyprctl monitors -j"));
monitorMap.clear();
for (json& monitor : monitorsInput)
{
monitorMap[monitor["activeWorkspace"]["id"]] = std::to_string(static_cast<int>(monitor["id"]));
}
}
json getWorkspace(json workspaceInput, char mode)
{
json workspaceOutput;
json monitorsInput = json::parse(command("hyprctl monitors -j"));
std::string keyValue;
if (mode == 'n')
{
keyValue = "id";
}
else if (mode == 's')
{
keyValue = "name";
}
workspaceOutput[keyValue] = workspaceInput[keyValue];
for (auto& monitor : monitorsInput)
{
if (monitor["activeWorkspace"][keyValue] == workspaceInput[keyValue])
{
workspaceOutput["activeOn"] = monitor[keyValue];
}
}
workspaceOutput["activeOn"] = monitorMap[workspaceInput["id"]];
workspaceOutput["occupied"] = workspaceInput["windows"];
if (!(workspaceInput["lastwindow"] == "0x0"))
{
workspaceOutput["icon"] = getIcon(workspaceInput["lastwindow"]);
}
workspaceOutput["icon"] = iconMap[workspaceInput["lastwindow"]];
else
{
workspaceOutput["icon"] = "";
}
return workspaceOutput;
@ -129,6 +155,9 @@ json getAllWorkspaces()
workspacesInput = json::parse(command("hyprctl workspaces -j"));
generateIconMap();
generateMonitorMap();
int specialIndex = 0;
for(auto& workspace : workspacesInput)
@ -155,30 +184,7 @@ json getAllWorkspaces()
}
std::string command(std::string inputCommand)
{
const char* command = inputCommand.c_str();
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)