updated toolbelt to not create a new window for chscheme; it now resizes the same window and moves it so that the mouse is at the center of the window. If chscheme is closed, it reverts back to its original size and goes back to the previous menu

This commit is contained in:
pagedmov
2024-10-26 06:12:29 -04:00
parent 805c53ea2c
commit b66fbc4944
5 changed files with 133 additions and 17 deletions

View File

@@ -0,0 +1,16 @@
{ pkgs }:
pkgs.writeShellScriptBin "chpaper" ''
paper="$\{self}/assets/wallpapers/$(find "$FLAKEPATH"/assets/wallpapers -exec basename {} \; | rg "\.\w+$" | fzf --preview "chafa -s 30x40 $FLAKEPATH/assets/wallpapers/{}")"
[ "$paper" = "$\{self}/assets/wallpapers/" ] && echo "Cancelling wallpaper change" && exit 0
echo "$paper" | xargs -I {} sed -i '/wallpaper =/s|"[^"]*"|"{}"|' "$FLAKEPATH"/flake.nix
echo "Successfully changed wallpaper. Rebuild now?" && \
select choice in "Yes" "No"; do
case $choice in
"Yes")
rebuild;pkill -9 hyprpaper;exit 0;;
"No")
echo "Exiting...";exit 0;;
esac
done
''

View File

@@ -34,11 +34,13 @@ chpaper() {
done done
} }
running=true
declare -A commands=( declare -A commands=(
["Change Wallpaper"]="chpaper" ["Change Wallpaper"]="chpaper"
["Change System Color Scheme"]="exec hyprctl dispatch exec '[float;size 50% 70%;move onscreen cursor -50% -50%] kitty chscheme'" ["Change System Color Scheme"]="hyprctl dispatch resizeactive 10% 80% && moveonscreen --center && if chscheme; then running=false; else hyprctl dispatch resizeactive exact 40% 25% && moveonscreen; fi"
["Open System Monitor"]="exec hyprctl dispatch exec '[float;size 50% 70%;move onscreen cursor -50% -50%] kitty btop'" ["Open System Monitor"]="hyprctl dispatch resizeactive 50% 70% moveactive onscreen cursor -50% -50%; kitty btop'"
["Open Volume Controls"]="exec hyprctl dispatch exec '[float;size 50% 70%;move onscreen cursor -50% -50%] pavucontrol'" ["Open Volume Controls"]="hyprctl dispatch exec '[float;size 50% 70%;move onscreen cursor -50% -50%] pavucontrol'"
["Open Keyring"]="exec hyprctl dispatch exec '[float;size 25% 30%;move onscreen cursor 20 20] [ ! -f /tmp/keyringfile ] && kitty keyring'" ["Open Keyring"]="exec hyprctl dispatch exec '[float;size 25% 30%;move onscreen cursor 20 20] [ ! -f /tmp/keyringfile ] && kitty keyring'"
["Calculator"]="calc" ["Calculator"]="calc"
) )
@@ -56,6 +58,7 @@ declare -A descriptions=(
export -A descriptions export -A descriptions
# Use fzf to select a command with preview # Use fzf to select a command with preview
while $running; do
selected_command=$(printf "%s\n" "''${!commands[@]}" | fzf --preview=" selected_command=$(printf "%s\n" "''${!commands[@]}" | fzf --preview="
cleaned_key=\$(echo {} | tr -d \"'\"); \ cleaned_key=\$(echo {} | tr -d \"'\"); \
echo \"Cleaned key: \$cleaned_key\"; \ echo \"Cleaned key: \$cleaned_key\"; \
@@ -77,7 +80,10 @@ fi" --prompt="> ")
#Execute the selected command if selection is not empty #Execute the selected command if selection is not empty
if [[ -n $selected_command ]]; then if [[ -n $selected_command ]]; then
eval "''${commands[$selected_command]}" eval "''${commands[$selected_command]}"
fi else
running=false
fi
done
'' ''

View File

@@ -86,6 +86,7 @@
self = self; self = self;
pkgs = pkgs; pkgs = pkgs;
}; };
moveonscreen = import ./wm-controls/moveonscreen.nix { pkgs = pkgs; };
toolbelt = import ./commands/toolbelt.nix { pkgs = pkgs; }; toolbelt = import ./commands/toolbelt.nix { pkgs = pkgs; };
viconf = import ./commands/viconf.nix { viconf = import ./commands/viconf.nix {
pkgs = pkgs; pkgs = pkgs;
@@ -115,6 +116,7 @@ in {
switchmon switchmon
toggle_blur toggle_blur
toggle_float toggle_float
moveonscreen
toggle_oppacity toggle_oppacity
toggle_waybar toggle_waybar
toolbelt toolbelt

View File

@@ -2,7 +2,7 @@
pkgs, pkgs,
}: }:
pkgs.writeShellScriptBin "chscheme" '' pkgs.writeShellScriptBin "chscheme" ''
/usr/bin/env ls "$(nix-build '<nixpkgs>' -A base16-schemes)"/share/themes | \ selected_scheme=$(/usr/bin/env ls "$(nix-build '<nixpkgs>' -A base16-schemes)"/share/themes | \
sed 's/\.yaml//g' | \ sed 's/\.yaml//g' | \
fzf --preview 'cat $(nix-build "<nixpkgs>" -A base16-schemes)/share/themes/{}.yaml | \ fzf --preview 'cat $(nix-build "<nixpkgs>" -A base16-schemes)/share/themes/{}.yaml | \
while IFS=": " read -r key value; do \ while IFS=": " read -r key value; do \
@@ -13,15 +13,30 @@ pkgs.writeShellScriptBin "chscheme" ''
b=$((16#''${clean_value:4:2})); \ b=$((16#''${clean_value:4:2})); \
printf "\033[48;2;%d;%d;%dm %-20s %s \033[0m\n" $r $g $b $key $clean_value; \ printf "\033[48;2;%d;%d;%dm %-20s %s \033[0m\n" $r $g $b $key $clean_value; \
fi; \ fi; \
done' | xargs -I {} sed -i '/base16scheme \=/s/\".*\"/\"{}\"/' "$FLAKEPATH"/flake.nix \ done')
[ $? -ne 0 ] && echo "Aborting color scheme change." && exit 0
echo "Successfully changed system color scheme. Rebuild now?" && \ if [[ -z "$selected_scheme" ]]; then
select choice in "Yes" "No"; do echo "Aborting color scheme change."
case $choice in exit 1
"Yes") fi
rebuild;exit 0;;
"No") echo "$selected_scheme" | xargs -I {} sed -i '/base16scheme\s*=\s*"/s/"[^"]*"/"{}"/' "$FLAKEPATH"/flake.nix
echo "Exiting...";exit 0;; if [ $? -ne 0 ]; then
esac echo "Failed to change color scheme."
done exit 1
fi
echo "Successfully changed system color scheme. Rebuild now?"
select choice in "Yes" "No"; do
case $choice in
"Yes")
rebuild
exit 0
;;
"No")
echo "Exiting..."
exit 0
;;
esac
done
'' ''

View File

@@ -0,0 +1,77 @@
{ pkgs }:
pkgs.writeShellScriptBin "moveonscreen" ''
center_window=false
if [[ $1 == "--center" ]]; then
center_window=true
fi
cursor_pos=$(hyprctl cursorpos | sed 's/,//')
cursor_x=$(echo "$cursor_pos" | awk '{print $1}')
cursor_y=$(echo "$cursor_pos" | awk '{print $2}')
window_info=$(hyprctl activewindow -j)
window_width=$(echo "$window_info" | jq ".size[0]")
window_height=$(echo "$window_info" | jq ".size[1]")
if [ "$center_window" = true ]; then
cursor_x=$((cursor_x - window_width / 2))
cursor_y=$((cursor_y - window_height / 2))
if (( cursor_x < 10 )); then
cursor_x=10
fi
if (( cursor_y < 54 )); then
cursor_y=54
fi
fi
monitors=$(hyprctl monitors -j)
monitor_x_min=0
monitor_x_max=0
monitor_y_min=0
monitor_y_max=0
focused_monitor=-1
for ((i = 0; i < $(echo "$monitors" | jq 'length'); i++)); do
mon_x=$(echo "$monitors" | jq ".[$i].x")
mon_y=$(echo "$monitors" | jq ".[$i].y")
mon_width=$(echo "$monitors" | jq ".[$i].width")
mon_height=$(echo "$monitors" | jq ".[$i].height")
is_focused=$(echo "$monitors" | jq ".[$i].focused")
if [ "$is_focused" = true ]; then
monitor_x_min=$((mon_x + 10))
monitor_x_max=$((mon_x + mon_width - 10))
monitor_y_min=$((mon_y + 10))
monitor_y_max=$((mon_y + mon_height - 10))
focused_monitor=$i
break
fi
done
if [ "$focused_monitor" -eq -1 ]; then
exit 1
fi
if (( cursor_x < monitor_x_min )); then
adjusted_x=$monitor_x_min
elif (( cursor_x + window_width > monitor_x_max )); then
adjusted_x=$((monitor_x_max - window_width))
else
adjusted_x=$cursor_x
fi
if (( cursor_y < monitor_y_min )); then
adjusted_y=$monitor_y_min
elif (( cursor_y + window_height > monitor_y_max )); then
adjusted_y=$((monitor_y_max - window_height))
else
adjusted_y=$cursor_y
fi
hyprctl dispatch moveactive exact "$adjusted_x $adjusted_y"
''