From 60711d89511548a6cb9f52efdddd095478df64fe Mon Sep 17 00:00:00 2001 From: Hydroxycarbamide Date: Wed, 16 Aug 2023 18:11:59 +0200 Subject: [PATCH] Disable icons + replace usage of title by address for the filename + replace sed operation by json operations --- eww/hyprmsn/scripts/move_to_window.sh | 8 +-- eww/hyprmsn/scripts/windows.sh | 75 +++++++++++++-------------- scripts/daemon.sh | 24 +++------ 3 files changed, 49 insertions(+), 58 deletions(-) diff --git a/eww/hyprmsn/scripts/move_to_window.sh b/eww/hyprmsn/scripts/move_to_window.sh index 3fcd16c..cce12f1 100755 --- a/eww/hyprmsn/scripts/move_to_window.sh +++ b/eww/hyprmsn/scripts/move_to_window.sh @@ -1,3 +1,5 @@ -window_id=$(hyprctl clients | rg 'Window ([A-Fa-f0-9]+)' | grep -F "$*" | sed -E 's/Window (.*) \->.*/\1/g') -hyprctl dispatch focuswindow address:0x$window_id > /dev/null -eww --config $HOME/.config/eww/hyprmsn close hyprmsn \ No newline at end of file +#!/bin/bash + +window_id=$1 +hyprctl dispatch focuswindow address:"$window_id" > /dev/null +eww --config "$HOME"/.config/eww/hyprmsn close hyprmsn \ No newline at end of file diff --git a/eww/hyprmsn/scripts/windows.sh b/eww/hyprmsn/scripts/windows.sh index 4478c50..ec68d67 100755 --- a/eww/hyprmsn/scripts/windows.sh +++ b/eww/hyprmsn/scripts/windows.sh @@ -1,66 +1,65 @@ -#! /bin/bash +#!/bin/bash +word_per_line=3 trun() { window=$1 OLD_IFS="$IFS" IFS=$' ' for word in $window; do - if [[ $count == $word_per_line ]]; then + if [[ $count == "$word_per_line" ]]; then str="$str$word\n" count=0 else str="$str$word " - count=$(($count + 1)) + count=$((count + 1)) fi done IFS=$OLD_IFS - echo $str + echo "$str" } -img() { - window=$1 - windows_images_dir=$HOME/.config/hyprmsn/windows - window_no_slash=$(echo $window | sed 's|/|⁄|g') - window_img="$windows_images_dir/$(ls $windows_images_dir | grep -F $window_no_slash | tail -1)" - if [[ $window_img == "$windows_images_dir/" ]]; then - window_img="$windows_images_dir/default.png" - fi - echo "$window_img" -} - -word_per_line=3 echo "(box" OLD_IFS="$IFS" IFS=$'\n' -windows=$(hyprctl clients | rg 'Window ([A-Fa-f0-9]+)' | sed -E 's/.*\-> (.*):/\1/g') -classes=$(hyprctl clients | rg 'class: ' | sed "s/.*class: //g") source $HOME/.config/hyprmsn/scripts/load_config.sh -i=1 -for window in $windows; do - window_class=$(echo $classes | tr ' ' '\n' | head -$i | tail -1) - window_str=$(trun $window) - window_img=$(img $window) - - if [ $use_icons == true ]; then - find_icon=$(find /usr/share/icons/$icon_pack -iname "$window_class*" | head -4 | tail -1) - if [[ $find_icon == "/usr/share/icons/$icon_pack" ]]; then - window_img=$(img $window) - fi - window_img=$find_icon - else - window_img=$(img $window) +current_workspace=$(hyprctl -j activeworkspace | jq -r '.id') +windows_images_dir=$HOME/.config/hyprmsn/windows +hyprctl -j clients | jq -c '.[]' | while read -r window; do + workspace=$(echo "$window" | jq -r '.workspace.id') + + if [ "$workspace" -lt 0 ]; then + continue fi - #echo $window_img - eww="(box :orientation \"v\" :class \"window-box\" (image :path \"$window_img\" :image-width 192 :image-height 108) (button :onclick \"$HOME/.config/eww/hyprmsn/scripts/move_to_window.sh \'$window\'\" :class \"window-button\" (box :orientation \"v\" " - for string in $(echo -e $window_str); do + address=$(echo "$window" | jq -r '.address') + window_img="$windows_images_dir/$address.jpeg" + if [ "$workspace" -eq "$current_workspace" ]; then + at=$(echo "$window" | jq -r '.at' | jq -r 'join(",")') + size=$(echo "$window" | jq -r '.size' | jq -r 'join("x")') + grim -g "$at $size" -t jpeg -q 50 "$window_img" + fi + + # TODO: Implement icons + # find_icon=$(find /usr/share/icons/$icon_pack -iname "$window_class*" | head -4 | tail -1) + # if [[ $find_icon == "/usr/share/icons/$icon_pack" ]]; then + # window_img=$(img $window) + # fi + # window_img=$find_icon + + if [ ! -e "$window_img" ]; then + window_img="$windows_images_dir/default.png" + fi + + window_str=$(echo "$window" | jq -r '.title') + eww="(box :orientation \"v\" :class \"window-box\" (image :path \"$window_img\" :image-width 192 :image-height 108) (button :onclick \"$HOME/.config/eww/hyprmsn/scripts/move_to_window.sh \'$address\'\" :class \"window-button\" (box :orientation \"v\" " + for string in $(echo -e "$window_str"); do eww="$eww $(echo -e "(label :text \"$string\")")" done eww="$eww)))" - echo $eww - - i=$(( $i + 1 )) + echo "$eww" done + + IFS=$OLD_IFS echo ")" diff --git a/scripts/daemon.sh b/scripts/daemon.sh index 6039f09..fb29e87 100755 --- a/scripts/daemon.sh +++ b/scripts/daemon.sh @@ -1,24 +1,14 @@ #! /bin/bash hyprmsn=$HOME/.config/hyprmsn -mkdir $hyprmsn/windows 2> /dev/null -window=$(hyprctl activewindow -j | jq --raw-output .title) -rm -rf $hyprmsn/windows/*.jpeg 2> /dev/null +mkdir "$hyprmsn"/windows 2> /dev/null +rm -rf "$hyprmsn"/windows/*.jpeg 2> /dev/null while true; do - new_window=$(hyprctl activewindow -j | jq --raw-output .title) - - if [[ "$window" == "$new_window" ]]; then - continue - fi - window=$new_window - - window_str=$(echo $window | sed -e 's/[]\/$*.^[]/\\&/g') #| sed 's/\[\([^]]*\)\]/\\[\1\\]/g') #add \ to [] - window_no_slash=$(echo $window | sed 's|/|⁄|g') - - at_size=$(hyprctl clients | sed -n "/$window_str/,/^\$/p" | grep -Ew 'at|size' | tr -d '[a-z]|:|\t| ') - at=$(echo $at_size | tr ' ' '\n' | head -1 | tail -1) - size=$(echo $at_size | tr ' ' '\n' | head -2 | tail -1 | tr ',' 'x') + window=$(hyprctl activewindow -j | jq -r) + address=$(echo "$window" | jq -r '.address') + at=$(echo "$window" | jq -r '.at' | jq -r 'join(",")') + size=$(echo "$window" | jq -r '.size' | jq -r 'join("x")') + grim -g "$at $size" -t jpeg -q 50 "$hyprmsn/windows/$address.jpeg" sleep 0.4 - grim -g "$at $size" -t jpeg -q 50 "$hyprmsn/windows/$window_no_slash.jpeg" done