Added monitor check
This commit is contained in:
parent
d507864ec1
commit
618c02c14b
6 changed files with 143 additions and 76 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,3 +1 @@
|
|||
scripts/clients/build/CMakeFiles/clients.dir/src/main.cpp.o.d
|
||||
scripts/clients/build/CMakeFiles/clients.dir/src/main.cpp.o
|
||||
scripts/clients/build/clients
|
||||
scripts/clients/build/*
|
53
Struktur.md
53
Struktur.md
|
@ -2,12 +2,57 @@
|
|||
- 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)
|
||||
- activeOn: int (ID of monitor workspace is on)
|
||||
- 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)
|
||||
- activeOn: int (ID of monitor workspace is on)
|
||||
- icon: string (path of icon of client)
|
||||
|
||||
|
||||
Events:
|
||||
|
||||
workspacev2>>WORKSPACEID,WORKSPACENAME
|
||||
|
||||
workspace changed, update activeOn
|
||||
|
||||
|
||||
createworkspacev2>>WORKSPACEID,WORKSPACENAME
|
||||
|
||||
workspace got created, update activeOn
|
||||
|
||||
|
||||
destroyworkspacev2>>WORKSPACEID,WORKSPACENAME
|
||||
|
||||
workspace got destroyed, update activeOn
|
||||
|
||||
|
||||
moveworkspacev2>>WORKSPACEID,WORKSPACENAME,MONNAME
|
||||
|
||||
workspace got moved to other monitor, update activeOn
|
||||
|
||||
|
||||
activespecial>>WORKSPACENAME,MONNAME
|
||||
|
||||
|
||||
|
||||
|
||||
activewindowv2>>WINDOWADDRESS
|
||||
|
||||
client focus changed, update icon
|
||||
|
||||
|
||||
openwindow>>WINDOWADDRESS,WORKSPACENAME,WINDOWCLASS,WINDOWTITLE
|
||||
|
||||
new client, update icon
|
||||
|
||||
|
||||
closewindow>>WINDOWADDRESS
|
||||
|
||||
closed client, update icon
|
||||
|
||||
|
||||
movewindowv2>>WINDOWADDRESS,WORKSPACENAME
|
||||
|
||||
client moved to other workspace, update icon
|
|
@ -25,8 +25,8 @@
|
|||
:spacing 3
|
||||
(for workspace in workspaces
|
||||
(eventbox
|
||||
:onclick `/home/willifan/.config/scripts/workspaces.sh ${workspace.normal.ID}`
|
||||
:class {workspace.normal.monitorID == "${monitor}" ? "activeWorkspace" : "smallBox"}
|
||||
:onclick `/home/willifan/.config/scripts/workspaces.sh ${workspace.normal.id}`
|
||||
:class {workspace.normal.activeOn == "${monitor}" ? "activeWorkspace" : "smallBox"}
|
||||
:valign "center"
|
||||
:halign "center"
|
||||
:height 20
|
||||
|
@ -36,9 +36,9 @@
|
|||
:space-evenly false
|
||||
(smallSpacer)
|
||||
(label
|
||||
:class {workspace.normal.occupied == true ? "" : "unoccupiedWorkspace"}
|
||||
:class {workspace.normal.occupied > 0 ? "" : "unoccupiedWorkspace"}
|
||||
:width 16
|
||||
:text "${workspace.normal.ID}")
|
||||
:text "${workspace.normal.id}")
|
||||
(imageDPI
|
||||
:visible "${workspace.normal.occupied > 0 ? true : false}"
|
||||
:image "${workspace.normal.icon}"
|
||||
|
|
|
@ -81,13 +81,54 @@ std::string getIcon(std::string windowAddress)
|
|||
}
|
||||
|
||||
|
||||
void getWorkspaces()
|
||||
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["occupied"] = workspaceInput["windows"];
|
||||
|
||||
if (!(workspaceInput["lastwindow"] == "0x0"))
|
||||
{
|
||||
workspaceOutput["icon"] = getIcon(workspaceInput["lastwindow"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
workspaceOutput["icon"] = "";
|
||||
}
|
||||
|
||||
return workspaceOutput;
|
||||
|
||||
}
|
||||
|
||||
|
||||
json getAllWorkspaces()
|
||||
{
|
||||
|
||||
workspacesInput = json::parse(command("hyprctl workspaces -j"));
|
||||
|
||||
workspacesOutput.clear();
|
||||
|
||||
int specialIndex = 0;
|
||||
|
||||
for(auto& workspace : workspacesInput)
|
||||
|
@ -96,49 +137,21 @@ void getWorkspaces()
|
|||
{
|
||||
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"] = "";
|
||||
}
|
||||
|
||||
workspacesOutput[index]["normal"].clear();
|
||||
workspacesOutput[index]["normal"] = getWorkspace(workspace, 'n');
|
||||
}
|
||||
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"]);
|
||||
|
||||
}
|
||||
workspacesOutput[specialIndex]["special"].clear();
|
||||
workspacesOutput[specialIndex]["special"] = getWorkspace(workspace, 's');
|
||||
|
||||
specialIndex++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::cout << workspacesOutput << std::endl;
|
||||
return workspacesOutput;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -173,27 +186,27 @@ void handle(std::string message)
|
|||
|
||||
if (message.find("workspace") == 0)
|
||||
{
|
||||
getWorkspaces();
|
||||
std::cout << getAllWorkspaces() << std::endl;
|
||||
}
|
||||
else if (message.find("moveworkspace") == 0)
|
||||
{
|
||||
getWorkspaces();
|
||||
std::cout << getAllWorkspaces() << std::endl;
|
||||
}
|
||||
else if (message.find("openwindow") == 0)
|
||||
{
|
||||
getWorkspaces();
|
||||
std::cout << getAllWorkspaces() << std::endl;
|
||||
}
|
||||
else if (message.find("closewindow") == 0)
|
||||
{
|
||||
getWorkspaces();
|
||||
std::cout << getAllWorkspaces() << std::endl;
|
||||
}
|
||||
else if (message.find("movewindow") == 0)
|
||||
{
|
||||
getWorkspaces();
|
||||
std::cout << getAllWorkspaces() << std::endl;
|
||||
}
|
||||
else if (message.find("activewindow") == 0)
|
||||
{
|
||||
getWorkspaces();
|
||||
std::cout << getAllWorkspaces() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
@ -202,6 +215,8 @@ void handle(std::string message)
|
|||
int main(int argc, char const *argv[])
|
||||
{
|
||||
|
||||
std::cout << getAllWorkspaces() << std::endl;
|
||||
|
||||
std::string socketPath = "/tmp/hypr/" + std::string(std::getenv("HYPRLAND_INSTANCE_SIGNATURE")) + "/.socket2.sock";
|
||||
|
||||
|
||||
|
|
|
@ -44,6 +44,8 @@ generate() {
|
|||
|
||||
eww close-all
|
||||
|
||||
sleep 2
|
||||
|
||||
for ((i = 0; i < ${#id[@]}; i++)); do
|
||||
scale_value=$(echo "${scale[$i]}" | bc -l)
|
||||
|
||||
|
@ -56,6 +58,7 @@ generate() {
|
|||
monitorID=$(xrandr --listactivemonitors | grep +${name[$i]} | awk '{sub(/.$/,"",$1); print $1}')
|
||||
|
||||
eww open bar --id bar${monitorID} --arg monitor=${monitorID} --arg width=${new_width} --arg height=25
|
||||
sleep 2
|
||||
|
||||
done
|
||||
|
||||
|
|
|
@ -1,26 +1,32 @@
|
|||
#!/bin/bash
|
||||
|
||||
getIcon() {
|
||||
local desktop=""
|
||||
|
||||
if [ $1 ]; then
|
||||
# Search for desktop files by WM class
|
||||
if [ -n "$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)
|
||||
[ -z "$desktop" ] && desktop=$(grep -Pl "Name\s*=\s*$1$" /usr/share/applications/*.desktop)
|
||||
[ -z "$desktop" ] && desktop=$(ls /usr/share/applications/${1}.desktop 2>/dev/null)
|
||||
fi
|
||||
if [ -z "$desktop" ]; then
|
||||
desktop=$(ls /usr/share/applications | grep -l /usr/share/applications/${1}.desktop)
|
||||
|
||||
# If not found by WM class, search by process name
|
||||
if [ -z "$desktop" ] && [ -n "$2" ]; then
|
||||
desktop=$(pgrep -fl "$2" | awk '{print $2}' | grep -m1 -o '[^/]*\.desktop' | head -n1)
|
||||
[ -n "$desktop" ] && desktop="/usr/share/applications/$desktop"
|
||||
fi
|
||||
|
||||
# If not found by WM class or process name, search by name or description
|
||||
if [ -z "$desktop" ] && [ -n "$1" ]; then
|
||||
desktop=$(grep -Pl "$1" /usr/share/applications/*.desktop)
|
||||
fi
|
||||
|
||||
echo "$desktop"
|
||||
}
|
||||
|
||||
desktop=$(getIcon "$1" "$2")
|
||||
if [ -n "$desktop" ]; then
|
||||
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"
|
||||
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