From b66fbc494471fc540d8e9def65f36d78f8f8055a Mon Sep 17 00:00:00 2001 From: pagedmov Date: Sat, 26 Oct 2024 06:12:29 -0400 Subject: [PATCH] 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 --- modules/home/scripts/commands/chpaper.nix | 16 ++++ modules/home/scripts/commands/toolbelt.nix | 16 ++-- modules/home/scripts/default.nix | 2 + modules/home/scripts/nix/chscheme.nix | 39 +++++++--- .../home/scripts/wm-controls/moveonscreen.nix | 77 +++++++++++++++++++ 5 files changed, 133 insertions(+), 17 deletions(-) create mode 100644 modules/home/scripts/commands/chpaper.nix create mode 100644 modules/home/scripts/wm-controls/moveonscreen.nix diff --git a/modules/home/scripts/commands/chpaper.nix b/modules/home/scripts/commands/chpaper.nix new file mode 100644 index 0000000..224bfdd --- /dev/null +++ b/modules/home/scripts/commands/chpaper.nix @@ -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 +'' diff --git a/modules/home/scripts/commands/toolbelt.nix b/modules/home/scripts/commands/toolbelt.nix index def3c42..8954124 100644 --- a/modules/home/scripts/commands/toolbelt.nix +++ b/modules/home/scripts/commands/toolbelt.nix @@ -34,11 +34,13 @@ chpaper() { done } +running=true + declare -A commands=( ["Change Wallpaper"]="chpaper" - ["Change System Color Scheme"]="exec hyprctl dispatch exec '[float;size 50% 70%;move onscreen cursor -50% -50%] kitty chscheme'" - ["Open System Monitor"]="exec hyprctl dispatch exec '[float;size 50% 70%;move onscreen cursor -50% -50%] kitty btop'" - ["Open Volume Controls"]="exec hyprctl dispatch exec '[float;size 50% 70%;move onscreen cursor -50% -50%] pavucontrol'" + ["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"]="hyprctl dispatch resizeactive 50% 70% moveactive onscreen cursor -50% -50%; kitty btop'" + ["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'" ["Calculator"]="calc" ) @@ -56,6 +58,7 @@ declare -A descriptions=( export -A descriptions # Use fzf to select a command with preview +while $running; do selected_command=$(printf "%s\n" "''${!commands[@]}" | fzf --preview=" cleaned_key=\$(echo {} | tr -d \"'\"); \ echo \"Cleaned key: \$cleaned_key\"; \ @@ -77,7 +80,10 @@ fi" --prompt="> ") #Execute the selected command if selection is not empty -if [[ -n $selected_command ]]; then + if [[ -n $selected_command ]]; then eval "''${commands[$selected_command]}" -fi + else + running=false + fi +done '' diff --git a/modules/home/scripts/default.nix b/modules/home/scripts/default.nix index 2df1ea7..d56112b 100644 --- a/modules/home/scripts/default.nix +++ b/modules/home/scripts/default.nix @@ -86,6 +86,7 @@ self = self; pkgs = pkgs; }; + moveonscreen = import ./wm-controls/moveonscreen.nix { pkgs = pkgs; }; toolbelt = import ./commands/toolbelt.nix { pkgs = pkgs; }; viconf = import ./commands/viconf.nix { pkgs = pkgs; @@ -115,6 +116,7 @@ in { switchmon toggle_blur toggle_float + moveonscreen toggle_oppacity toggle_waybar toolbelt diff --git a/modules/home/scripts/nix/chscheme.nix b/modules/home/scripts/nix/chscheme.nix index 0601d2c..26fb22b 100644 --- a/modules/home/scripts/nix/chscheme.nix +++ b/modules/home/scripts/nix/chscheme.nix @@ -2,7 +2,7 @@ pkgs, }: pkgs.writeShellScriptBin "chscheme" '' -/usr/bin/env ls "$(nix-build '' -A base16-schemes)"/share/themes | \ +selected_scheme=$(/usr/bin/env ls "$(nix-build '' -A base16-schemes)"/share/themes | \ sed 's/\.yaml//g' | \ fzf --preview 'cat $(nix-build "" -A base16-schemes)/share/themes/{}.yaml | \ while IFS=": " read -r key value; do \ @@ -13,15 +13,30 @@ pkgs.writeShellScriptBin "chscheme" '' b=$((16#''${clean_value:4:2})); \ printf "\033[48;2;%d;%d;%dm %-20s %s \033[0m\n" $r $g $b $key $clean_value; \ fi; \ - done' | xargs -I {} sed -i '/base16scheme \=/s/\".*\"/\"{}\"/' "$FLAKEPATH"/flake.nix \ - [ $? -ne 0 ] && echo "Aborting color scheme change." && exit 0 - 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 + done') + +if [[ -z "$selected_scheme" ]]; then + echo "Aborting color scheme change." + exit 1 +fi + +echo "$selected_scheme" | xargs -I {} sed -i '/base16scheme\s*=\s*"/s/"[^"]*"/"{}"/' "$FLAKEPATH"/flake.nix +if [ $? -ne 0 ]; then + echo "Failed to change color scheme." + 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 '' diff --git a/modules/home/scripts/wm-controls/moveonscreen.nix b/modules/home/scripts/wm-controls/moveonscreen.nix new file mode 100644 index 0000000..ce5145c --- /dev/null +++ b/modules/home/scripts/wm-controls/moveonscreen.nix @@ -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" +''