First working version
This commit is contained in:
parent
c8ac4b08ea
commit
d507864ec1
8 changed files with 194 additions and 135 deletions
13
Struktur.md
Normal file
13
Struktur.md
Normal 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)
|
17
eww.yuck
17
eww.yuck
|
@ -13,8 +13,10 @@
|
|||
`scripts/network.sh &`)
|
||||
|
||||
(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":""}]'
|
||||
`scripts/clients.sh`)
|
||||
:initial ''
|
||||
`scripts/clients/build/clients`)
|
||||
|
||||
|
||||
|
||||
(defpoll bluetooth
|
||||
:initial '{"name":"","battery":"0"}'
|
||||
|
@ -259,12 +261,13 @@
|
|||
(space)
|
||||
(workspaces)))
|
||||
|
||||
(defwidget center []
|
||||
(defwidget center [monitor]
|
||||
(box
|
||||
:orientation "h"
|
||||
:space-evenly false
|
||||
:halign "center"
|
||||
(workspaces)
|
||||
(workspaces
|
||||
:monitor "${monitor}")
|
||||
))
|
||||
|
||||
(defwidget end []
|
||||
|
@ -291,11 +294,7 @@
|
|||
|
||||
(space)))
|
||||
|
||||
(defwidget bar []
|
||||
(centerbox :orientation "h"
|
||||
(start)
|
||||
(center)
|
||||
(end)))
|
||||
|
||||
|
||||
|
||||
;; Window definition
|
||||
|
|
42
newbar.yuck
42
newbar.yuck
|
@ -5,27 +5,28 @@
|
|||
|
||||
|
||||
(defwindow bar [monitor width height]
|
||||
:monitor "${monitor}"
|
||||
:class "bar"
|
||||
:geometry (geometry
|
||||
:x "0%"
|
||||
:y "5px"
|
||||
:width "${width}px"
|
||||
:height "${height}px"
|
||||
:anchor "top center")
|
||||
:stacking "fg"
|
||||
:exclusive true
|
||||
(bar))
|
||||
:monitor "${monitor}"
|
||||
:class "bar"
|
||||
:geometry (geometry
|
||||
:x "0%"
|
||||
:y "5px"
|
||||
:width "${width}px"
|
||||
:height "${height}px"
|
||||
:anchor "top center")
|
||||
:stacking "fg"
|
||||
:exclusive true
|
||||
(bar
|
||||
:monitor "${monitor}"))
|
||||
|
||||
|
||||
(defwidget workspaces []
|
||||
(defwidget workspaces [monitor]
|
||||
(box
|
||||
:space-evenly false
|
||||
:spacing 3
|
||||
(for workspace in workspaces
|
||||
(eventbox
|
||||
:onclick `/home/willifan/.config/scripts/workspaces.sh ${workspace.ID}`
|
||||
:class {workspace.activeID == "0" ? "activeWorkspace" : "smallBox"}
|
||||
:onclick `/home/willifan/.config/scripts/workspaces.sh ${workspace.normal.ID}`
|
||||
:class {workspace.normal.monitorID == "${monitor}" ? "activeWorkspace" : "smallBox"}
|
||||
:valign "center"
|
||||
:halign "center"
|
||||
:height 20
|
||||
|
@ -35,12 +36,12 @@
|
|||
:space-evenly false
|
||||
(smallSpacer)
|
||||
(label
|
||||
:class {workspace.occupied == true ? "" : "unoccupiedWorkspace"}
|
||||
:class {workspace.normal.occupied == true ? "" : "unoccupiedWorkspace"}
|
||||
:width 16
|
||||
:text "${workspace.ID}")
|
||||
:text "${workspace.normal.ID}")
|
||||
(imageDPI
|
||||
:visible "${workspace.occupied}"
|
||||
:image "${workspace.clients[0].icon}"
|
||||
:visible "${workspace.normal.occupied > 0 ? true : false}"
|
||||
:image "${workspace.normal.icon}"
|
||||
:size "16")
|
||||
(smallSpacer))))))
|
||||
|
||||
|
@ -52,9 +53,10 @@
|
|||
(space)
|
||||
(time)))
|
||||
|
||||
(defwidget bar []
|
||||
(defwidget bar [monitor]
|
||||
(centerbox :orientation "h"
|
||||
(start)
|
||||
(center)
|
||||
(center
|
||||
:monitor "${monitor}")
|
||||
(end)))
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -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";
|
||||
|
|
|
@ -1,64 +1,26 @@
|
|||
#!/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
|
||||
done < <(hyprctl clients -j | jq -r '.[]|"\(.pid) \(.workspace.id) \(.size[0]) \(.size[1]) \(.initialClass)"')
|
||||
|
||||
for ((i=0; i<${#clientOnWorkspace[@]}; i++)); do
|
||||
clientInfos[i]='{"onWorkspace":"'${clientOnWorkspace[$i]}'","pid":"'${pid[$i]}'","class":"'${classes[$i]}'","mainOn":"''","icon":"'${images[$i]}'"}'
|
||||
echo ${clientInfos[$i]}
|
||||
done
|
||||
|
||||
|
||||
#for window in ${!windows[@]}; do
|
||||
# echo -n "${window} "
|
||||
# echo $(ps -p ${windows[$window]} -o comm=)
|
||||
#done
|
||||
|
||||
#test=$(ps -p ${windows[2]} -o comm=)
|
||||
#$(feh /usr/share/icons/Papirus-Dark/128x128/apps/${test}.svg)
|
||||
if [ -z "$desktop" ]; then
|
||||
desktop=$(ls /usr/share/applications | grep -l /usr/share/applications/${1}.desktop)
|
||||
fi
|
||||
fi
|
||||
if [ $2 ]; then
|
||||
if [ -z "$desktop" ]; then
|
||||
process=$(ps -p ${2} -o comm=)
|
||||
desktop=$(grep -Pl "$process" /usr/share/applications/*.desktop)
|
||||
fi
|
||||
fi
|
||||
if [ $1 ]; then
|
||||
if [ -z "$desktop" ]; then
|
||||
desktop=$(grep -Pli "$1" /usr/share/applications/*.desktop)
|
||||
fi
|
||||
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
|
Loading…
Add table
Reference in a new issue