First working version

This commit is contained in:
willifan 2024-03-17 15:44:15 +01:00
parent c8ac4b08ea
commit d507864ec1
8 changed files with 194 additions and 135 deletions

13
Struktur.md Normal file
View file

@ -0,0 +1,13 @@
- workspaces: array
- normal
- ID: int (ID of workspace)
- occupied: bool (if workspace is occupied)
- monitorID: int (ID of monitor workspace is on)
- active: bool (if workspace is open)
- icon: string (path of icon of client)
- special
- ID: int (ID of workspace)
- occupied: bool (if workspace is occupied)
- monitorID: int (ID of monitor workspace is on)
- active: bool (if workspace is open)
- icon: string (path of icon of client)

View file

@ -13,8 +13,10 @@
`scripts/network.sh &`) `scripts/network.sh &`)
(deflisten workspaces (deflisten workspaces
:initial '[{"ID":"1","occupied":"0","activeID":""},{"ID":"2","occupied":"0","activeID":""},{"ID":"3","occupied":"0","activeID":""},{"ID":"4","occupied":"0","activeID":""},{"ID":"5","occupied":"0","activeID":""},{"ID":"6","occupied":"0","activeID":""},{"ID":"7","occupied":"0","activeID":""},{"ID":"8","occupied":"0","activeID":""},{"ID":"9","occupied":"0","activeID":""},{"ID":"10","occupied":"0","activeID":""}]' :initial ''
`scripts/clients.sh`) `scripts/clients/build/clients`)
(defpoll bluetooth (defpoll bluetooth
:initial '{"name":"","battery":"0"}' :initial '{"name":"","battery":"0"}'
@ -259,12 +261,13 @@
(space) (space)
(workspaces))) (workspaces)))
(defwidget center [] (defwidget center [monitor]
(box (box
:orientation "h" :orientation "h"
:space-evenly false :space-evenly false
:halign "center" :halign "center"
(workspaces) (workspaces
:monitor "${monitor}")
)) ))
(defwidget end [] (defwidget end []
@ -291,11 +294,7 @@
(space))) (space)))
(defwidget bar []
(centerbox :orientation "h"
(start)
(center)
(end)))
;; Window definition ;; Window definition

View file

@ -5,27 +5,28 @@
(defwindow bar [monitor width height] (defwindow bar [monitor width height]
:monitor "${monitor}" :monitor "${monitor}"
:class "bar" :class "bar"
:geometry (geometry :geometry (geometry
:x "0%" :x "0%"
:y "5px" :y "5px"
:width "${width}px" :width "${width}px"
:height "${height}px" :height "${height}px"
:anchor "top center") :anchor "top center")
:stacking "fg" :stacking "fg"
:exclusive true :exclusive true
(bar)) (bar
:monitor "${monitor}"))
(defwidget workspaces [] (defwidget workspaces [monitor]
(box (box
:space-evenly false :space-evenly false
:spacing 3 :spacing 3
(for workspace in workspaces (for workspace in workspaces
(eventbox (eventbox
:onclick `/home/willifan/.config/scripts/workspaces.sh ${workspace.ID}` :onclick `/home/willifan/.config/scripts/workspaces.sh ${workspace.normal.ID}`
:class {workspace.activeID == "0" ? "activeWorkspace" : "smallBox"} :class {workspace.normal.monitorID == "${monitor}" ? "activeWorkspace" : "smallBox"}
:valign "center" :valign "center"
:halign "center" :halign "center"
:height 20 :height 20
@ -35,12 +36,12 @@
:space-evenly false :space-evenly false
(smallSpacer) (smallSpacer)
(label (label
:class {workspace.occupied == true ? "" : "unoccupiedWorkspace"} :class {workspace.normal.occupied == true ? "" : "unoccupiedWorkspace"}
:width 16 :width 16
:text "${workspace.ID}") :text "${workspace.normal.ID}")
(imageDPI (imageDPI
:visible "${workspace.occupied}" :visible "${workspace.normal.occupied > 0 ? true : false}"
:image "${workspace.clients[0].icon}" :image "${workspace.normal.icon}"
:size "16") :size "16")
(smallSpacer)))))) (smallSpacer))))))
@ -52,9 +53,10 @@
(space) (space)
(time))) (time)))
(defwidget bar [] (defwidget bar [monitor]
(centerbox :orientation "h" (centerbox :orientation "h"
(start) (start)
(center) (center
:monitor "${monitor}")
(end))) (end)))

Binary file not shown.

View file

@ -1,50 +1,150 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib> #include <cstdlib>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <sstream>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h> #include <sys/un.h>
#include <unistd.h> #include <unistd.h>
#include "nlohmann/json.hpp" #include "nlohmann/json.hpp"
#include <fstream> #include <map>
//test
using json = nlohmann::json; 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")); workspacesInput = json::parse(command("hyprctl workspaces -j"));
return "";
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() std::string command(std::string inputCommand)
{
clients = json::parse(command("hyprctl clients -j"));
return "";
}
std::string command(const char* command)
{ {
const char* command = inputCommand.c_str();
char buffer[128]; char buffer[128];
std::string result; std::string result;
FILE* pipe = popen(command, "r"); FILE* pipe = popen(command, "r");
@ -73,35 +173,27 @@ void handle(std::string message)
if (message.find("workspace") == 0) if (message.find("workspace") == 0)
{ {
std::cout << "1" << std::endl; getWorkspaces();
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) else if (message.find("moveworkspace") == 0)
{ {
std::cout << "4" << std::endl; getWorkspaces();
workspaces = getWorkspaces();
} }
else if (message.find("openwindow") == 0) else if (message.find("openwindow") == 0)
{ {
std::cout << "5" << std::endl; getWorkspaces();
} }
else if (message.find("closewindow") == 0) else if (message.find("closewindow") == 0)
{ {
std::cout << "6" << std::endl; getWorkspaces();
} }
else if (message.find("movewindow") == 0) 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::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 // Create a socket
int sockfd = socket(AF_UNIX, SOCK_STREAM, 0); 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 // Define the address of the IPC socket
struct sockaddr_un addr; struct sockaddr_un addr;
addr.sun_family = AF_UNIX; 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 // Connect to the IPC socket
if (connect(sockfd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { if (connect(sockfd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
@ -152,11 +237,9 @@ int main(int argc, char const *argv[])
std::string messageLine; std::string messageLine;
while(std::getline(iss, messageLine)){ while(std::getline(iss, messageLine)){
std::cout << messageLine << std::endl;
handle(messageLine); handle(messageLine);
} }
} }
if (bytes_received == -1) { if (bytes_received == -1) {
std::cerr << "Error: Failed to receive message\n"; std::cerr << "Error: Failed to receive message\n";

View file

@ -1,64 +1,26 @@
#!/bin/bash #!/bin/bash
pid=()
classes=()
clientOnWorkspace=()
images=()
numberOnWorkspace=()
area=()
i=0
while read -r p w x y c; do
if [[ $c ]]; then
pid[$i]="$p"
classes[$i]="$c"
clientOnWorkspace[$i]="$w"
((numberOnWorkspace[w]+=1))
area[$i]=$((x * y))
desktop=$(grep -l "StartupWMClass.*$c$" /usr/share/applications/*.desktop)
echo $c
if [ -z $desktop ]; then
desktop=$(grep -Pl "Name\s*=\s*$c$" /usr/share/applications/*.desktop)
fi
if [ -z $desktop ]; then
desktop=$(ls /usr/share/applications | grep -l /usr/share/applications/${c}.desktop)
fi
if [ -z $desktop ]; then
process=$(ps -p ${p} -o comm=)
desktop=$(grep -Pl "$process" /usr/share/applications/*.desktop)
fi
if [ -z $desktop ]; then
desktop=$(grep -Pli "$c" /usr/share/applications/*.desktop)
fi
if [ -z $desktop ]; then
continue
fi
images[$i]=$(awk -F'[[:space:]]*=[[:space:]]*' '/Icon[[:space:]]*=/{print $2}' $desktop)
ls /usr/share/icons/ePapirus-Dark/128x128/apps/${images[$i]}.svg
((i=$i+1))
if [ $1 ]; then
desktop=$(grep -l "StartupWMClass.*$1$" /usr/share/applications/*.desktop)
if [ -z "$desktop" ]; then
desktop=$(grep -Pl "Name\s*=\s*$1$" /usr/share/applications/*.desktop)
fi fi
done < <(hyprctl clients -j | jq -r '.[]|"\(.pid) \(.workspace.id) \(.size[0]) \(.size[1]) \(.initialClass)"') if [ -z "$desktop" ]; then
desktop=$(ls /usr/share/applications | grep -l /usr/share/applications/${1}.desktop)
for ((i=0; i<${#clientOnWorkspace[@]}; i++)); do fi
clientInfos[i]='{"onWorkspace":"'${clientOnWorkspace[$i]}'","pid":"'${pid[$i]}'","class":"'${classes[$i]}'","mainOn":"''","icon":"'${images[$i]}'"}' fi
echo ${clientInfos[$i]} if [ $2 ]; then
done if [ -z "$desktop" ]; then
process=$(ps -p ${2} -o comm=)
desktop=$(grep -Pl "$process" /usr/share/applications/*.desktop)
#for window in ${!windows[@]}; do fi
# echo -n "${window} " fi
# echo $(ps -p ${windows[$window]} -o comm=) if [ $1 ]; then
#done if [ -z "$desktop" ]; then
desktop=$(grep -Pli "$1" /usr/share/applications/*.desktop)
#test=$(ps -p ${windows[2]} -o comm=) fi
#$(feh /usr/share/icons/Papirus-Dark/128x128/apps/${test}.svg) fi
image=$(awk -F'[[:space:]]*=[[:space:]]*' '/Icon[[:space:]]*=/ && !seen[$2]++ {print $2; exit}' $desktop)
icon="/usr/share/icons/Papirus-Dark/128x128/apps/${image}.svg"
echo -n $icon