imported previous rust projects and cleaned up unused files

This commit is contained in:
willifan 2024-05-23 18:56:06 +02:00
parent 0166b32872
commit 10b8db251b
432 changed files with 874 additions and 1585 deletions

View file

@ -1,187 +0,0 @@
#!/bin/bash
ICON_THEME="ePapirus-Dark"
declare -A occupiedWorkspaces
declare -A workspaceActiveOn
declare -A workspaces
PIDs=()
workspaces=()
A=()
image=()
# get the monitors workspaces are active on and get workspaces that exist
workspace_event() {
unset workspaceActiveOn
unset occupiedWorkspaces
# store the monitor id in workspaceActiveOn with the index of the active workspace
while read -r m w; do
workspaceActiveOn[$w]=$m
done < <(hyprctl -j monitors | jq -r '.[]|"\(.id) \(.activeWorkspace.id)"')
# set occupiedWorkspaces with the workspace as its index true if the index exists
while read -r i; do
if (( $i > 0 )); then
occupiedWorkspaces[$i]=true
fi
done < <(hyprctl -j workspaces | jq -r '.[]|"\(.id)"')
}
client_event() {
unset clientOnWorkspace
unset PIDs
unset classes
unset icons
classes=()
clientOnWorkspace=()
images=()
numberOnWorkspace=()
area=()
i=0
while read -r p w x y c; do
if [[ $c ]]; then
# read PIDs of all clients in consecutive order
PIDs[$i]="$p"
# store class of process at index of its PID
classes[$p]="$c"
# store workspace process is on at index of its PID
clientOnWorkspace[$p]="$w"
# increment numberOnWorkspace by one to reflect amount of clients on it
((numberOnWorkspace[w]+=1))
# store area of the process at index of its PID
area[$p]=$((x * y))
# get icon in a hacky way
desktop=$(grep -l "StartupWMClass.*$c$" /usr/share/applications/*.desktop)
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
image=$(awk -F'[[:space:]]*=[[:space:]]*' '/Icon[[:space:]]*=/{print $2}' $desktop)
icons[$p]="/usr/share/icons/Papirus-Dark/128x128/apps/${image}.svg"
((i=$i+1))
fi
done < <(hyprctl clients -j | jq -r '.[]|"\(.pid) \(.workspace.id) \(.size[0]) \(.size[1]) \(.initialClass)"')
# store json string of all client information at the index of the clients pid
for ((i=0; i<${#PIDs[@]}; i++)); do
PID=${PIDs[$i]}
clientInfos[PID]='{"onWorkspace":"'${clientOnWorkspace[$PID]}'","pid":"'${PID}'","class":"'${classes[$PID]}'","mainOn":"''","icon":"'${icons[$PID]}'"}'
done
}
# generate the json for eww
generate() {
unset message
message='['
for i in {1..9}; do
message=$message''$([ $i -eq 1 ] || echo ,)'{"ID":"'$i'","occupied":"'${occupiedWorkspaces[$i]}'","activeID":"'${workspaceActiveOn[$i]}'","clients":['
firstClient=0
for ((j=0; j<${#PIDs[@]}; j++)); do
PID=${PIDs[j]}
if [[ $(echo ${clientInfos[$PID]} | jq '"\(.onWorkspace)"') == '"'${i}'"' ]]; then
message=$message''$([ $firstClient -eq 0 ] || echo ,)''${clientInfos[$PID]}''
firstClient=1
fi
done
message=$message']}'
done
message="${message}]"
echo $message
}
# setup
# generate initial widget
workspace_event
client_event
generate
socat -u UNIX-CONNECT:/tmp/hypr/"$HYPRLAND_INSTANCE_SIGNATURE"/.socket2.sock - | while read -r line; do
case ${line%>>*} in
"workspace")
workspace_event
generate
;;
# "createworkspace")
# workspace_event
# generate
# ;;
# "destroyworkspace")
# workspace_event
# generate
# ;;
# "moveworkspace")
# workspace_event
# generate
# ;;
"openwindow")
client_event
generate
;;
"closewindow")
client_event
generate
;;
"movewindow")
client_event
workspace_event
generate
;;
esac
done

Binary file not shown.

View file

@ -1,43 +0,0 @@
#include <filesystem>
#include <iostream>
#include <string>
#include <fstream>
namespace fs = std::filesystem;
const std::string dir = "/usr/share/applications";
int main(int argc, char const *argv[])
{
for (const auto& entry : fs::directory_iterator(dir))
{
if (entry.path().extension() == ".desktop")
{
std::ifstream file(entry.path());
if (!file.is_open())
{
std::cerr << "file not opened" << std::endl;
return 1;
}
std::string output;
std::string line;
while (std::getline(file, line))
{
output += line + "\n";
}
std::cout << output << std::endl;
file.close();
}
}
return 0;
}

View file

@ -1,65 +0,0 @@
#!/bin/bash
PIDs=()
classes=()
clientOnWorkspace=()
images=()
numberOnWorkspace=()
area=()
i=0
while read -r p w x y c; do
if [[ $c ]]; then
PIDs[$i]="$p"
classes[$p]="$c"
clientOnWorkspace[$p]="$w"
((numberOnWorkspace[w]+=1))
area[$p]=$((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[$p]=$(awk -F'[[:space:]]*=[[:space:]]*' '/Icon[[:space:]]*=/{print $2}' $desktop)
ls /usr/share/icons/ePapirus-Dark/128x128/apps/${images[$p]}.svg
((i=$i+1))
fi
done < <(hyprctl clients -j | jq -r '.[]|"\(.pid) \(.workspace.id) \(.size[0]) \(.size[1]) \(.initialClass)"')
for ((i=0; i<${#PIDs[@]}; i++)); do
PID=${PIDs[$i]}
clientInfos[PID]='{"onWorkspace":"'${clientOnWorkspace[$PID]}'","pid":"'${PID}'","class":"'${classes[$PID]}'","mainOn":"''","icon":"'${images[$PID]}'"}'
echo ${clientInfos[$PID]}
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)

View file

@ -1,102 +0,0 @@
#!/bin/bash
# get initial focused workspace
focusedws=$(hyprctl -j monitors | jq -r '.[] | select(.focused == true) | .activeWorkspace.id')
declare -A o=([1]=0 [2]=0 [3]=0 [4]=0 [5]=0 [6]=0 [7]=0 [8]=0 [9]=0 [10]=0)
declare -A monitormap
declare -A workspaces
# handle workspace create/destroy
workspace_event() {
if (( $1 <= 10 )); then
o[$1]=$2
while read -r k v; do workspaces[$k]="$v"; done < <(hyprctl -j workspaces | jq -r '.[]|"\(.id) \(.monitor)"')
fi
if [ "$2" == "0" ]; then
unset "workspaces[$1]"
fi
}
# handle monitor (dis)connects
monitor_event() {
while read -r k v; do monitormap["$k"]=$v; done < <(hyprctl -j monitors | jq -r '.[]|"\(.name) \(.id) "')
}
# generate the json for eww
generate() {
unset activeWorkspaces
while read -r i w; do
activeWorkspaces[$w]=$i
done < <(hyprctl -j monitors | jq -r '.[]|"\(.id) \(.activeWorkspace.id)"')
echo -n '['
for i in {1..10}; do
echo -n ''$([ $i -eq 1 ] || echo ,)'{"ID":"'$i'","occupied":"'${o[$i]}'","activeID":"'${activeWorkspaces[$i]}'"}'
done
echo ']'
}
# setup
# add monitors
monitor_event
# add workspaces
while read -r k v; do workspaces[$k]="$v"; done < <(hyprctl -j workspaces | jq -r '.[]|"\(.id) \(.monitor)"')
# get active workspace
activeWorkspace=$(hyprctl -j monitors | jq -r '.[] | select(.focused == true) | .activeWorkspace.id')
# check occupied workspaces
for num in "${!workspaces[@]}"; do
o[$num]=1
done
# generate initial widget
generate
socat -u UNIX-CONNECT:/tmp/hypr/"$HYPRLAND_INSTANCE_SIGNATURE"/.socket2.sock - | while read -r line; do
case ${line%>>*} in
"createworkspace")
o=([1]=0 [2]=0 [3]=0 [4]=0 [5]=0 [6]=0 [7]=0 [8]=0 [9]=0 [10]=0)
workspaces=()
# add workspaces
while read -r k v; do workspaces[$k]="$v"; done < <(hyprctl -j workspaces | jq -r '.[]|"\(.id) \(.monitor)"')
# check occupied workspaces
for num in "${!workspaces[@]}"; do
o[$num]=1
done
# focusedws=${line#*>>}
generate
;;
"movewindow")
generate
;;
"moveworkspace")
generate
;;
"destroyworkspace")
o=([1]=0 [2]=0 [3]=0 [4]=0 [5]=0 [6]=0 [7]=0 [8]=0 [9]=0 [10]=0)
workspaces=()
# add workspaces
while read -r k v; do workspaces[$k]="$v"; done < <(hyprctl -j workspaces | jq -r '.[]|"\(.id) \(.monitor)"')
# check occupied workspaces
for num in "${!workspaces[@]}"; do
o[$num]=1
done
generate
;;
"monitor"*)
monitor_event
generate
;;
"workspace")
generate
;;
esac
done