diff options
| author | Donald Williams <129223418+dwilliam62@users.noreply.github.com> | 2025-10-03 23:28:49 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-03 23:28:49 -0400 |
| commit | cd6730a58e7c5fb9fe2cb278152a5423bddea498 (patch) | |
| tree | 7e0fa9fc2b65a93544315e059eedc64a8ee7de26 /config/hypr/scripts | |
| parent | 3909e6850e669aee87404542bc6eb86f8a633ceb (diff) | |
| parent | cc437da9dd067a9a001c0a68cd6f1be57b333a78 (diff) | |
Merge pull request #822 from dwilliam62/development
Weather.py: switch to Open-Meteo; add caching, reverse geocoding
Diffstat (limited to 'config/hypr/scripts')
| -rwxr-xr-x | config/hypr/scripts/Dropterminal.sh | 141 | ||||
| -rwxr-xr-x | config/hypr/scripts/RefreshNoWaybar.sh | 5 | ||||
| -rwxr-xr-x | config/hypr/scripts/WallustSwww.sh | 75 | ||||
| -rwxr-xr-x | config/hypr/scripts/WaybarCava.sh | 51 |
4 files changed, 196 insertions, 76 deletions
diff --git a/config/hypr/scripts/Dropterminal.sh b/config/hypr/scripts/Dropterminal.sh index f1bfe0a5..4833545c 100755 --- a/config/hypr/scripts/Dropterminal.sh +++ b/config/hypr/scripts/Dropterminal.sh @@ -1,5 +1,8 @@ #!/bin/bash # /* ---- π« https://github.com/JaKooLit π« ---- */ ## +# +# Made and brought to by Kiran George +# /* -- β¨ https://github.com/SherLock707 β¨ -- */ ## # Dropdown Terminal # Usage: ./Dropdown.sh [-d] <terminal_command> # Example: ./Dropdown.sh foot @@ -14,8 +17,7 @@ ADDR_FILE="/tmp/dropdown_terminal_addr" # Dropdown size and position configuration (percentages) WIDTH_PERCENT=50 # Width as percentage of screen width HEIGHT_PERCENT=50 # Height as percentage of screen height -X_PERCENT=25 # X position as percentage from left (25% centers a 50% width window) -Y_PERCENT=5 # Y position as percentage from top +Y_PERCENT=5 # Y position as percentage from top (X is auto-centered) # Animation settings ANIMATION_DURATION=100 # milliseconds @@ -49,8 +51,8 @@ if [ -z "$TERMINAL_CMD" ]; then echo "Edit the script to modify size and position:" echo " WIDTH_PERCENT - Width as percentage of screen (default: 50)" echo " HEIGHT_PERCENT - Height as percentage of screen (default: 50)" - echo " X_PERCENT - X position from left as percentage (default: 25)" echo " Y_PERCENT - Y position from top as percentage (default: 5)" + echo " Note: X position is automatically centered" exit 1 fi @@ -117,26 +119,82 @@ animate_slide_up() { debug_echo "Slide up animation completed" } -# Function to get monitor info for centering +# Function to get monitor info including scale and name of focused monitor get_monitor_info() { - hyprctl monitors -j | jq -r '.[] | select(.focused == true) | "\(.x) \(.y) \(.width) \(.height)"' + local monitor_data=$(hyprctl monitors -j | jq -r '.[] | select(.focused == true) | "\(.x) \(.y) \(.width) \(.height) \(.scale) \(.name)"') + if [ -z "$monitor_data" ] || [[ "$monitor_data" =~ ^null ]]; then + debug_echo "Error: Could not get focused monitor information" + return 1 + fi + echo "$monitor_data" } -# Function to calculate dropdown position +# Function to calculate dropdown position with proper scaling and centering calculate_dropdown_position() { local monitor_info=$(get_monitor_info) + + if [ $? -ne 0 ] || [ -z "$monitor_info" ]; then + debug_echo "Error: Failed to get monitor info, using fallback values" + echo "100 100 800 600 fallback-monitor" + return 1 + fi + local mon_x=$(echo $monitor_info | cut -d' ' -f1) local mon_y=$(echo $monitor_info | cut -d' ' -f2) local mon_width=$(echo $monitor_info | cut -d' ' -f3) local mon_height=$(echo $monitor_info | cut -d' ' -f4) + local mon_scale=$(echo $monitor_info | cut -d' ' -f5) + local mon_name=$(echo $monitor_info | cut -d' ' -f6) + + debug_echo "Monitor info: x=$mon_x, y=$mon_y, width=$mon_width, height=$mon_height, scale=$mon_scale" + + # Validate scale value and provide fallback + if [ -z "$mon_scale" ] || [ "$mon_scale" = "null" ] || [ "$mon_scale" = "0" ]; then + debug_echo "Invalid scale value, using 1.0 as fallback" + mon_scale="1.0" + fi + + # Calculate logical dimensions by dividing physical dimensions by scale + local logical_width logical_height + if command -v bc >/dev/null 2>&1; then + # Use bc for precise floating point calculation + logical_width=$(echo "scale=0; $mon_width / $mon_scale" | bc | cut -d'.' -f1) + logical_height=$(echo "scale=0; $mon_height / $mon_scale" | bc | cut -d'.' -f1) + else + # Fallback to integer math (multiply by 100 for precision, then divide) + local scale_int=$(echo "$mon_scale" | sed 's/\.//' | sed 's/^0*//') + if [ -z "$scale_int" ]; then scale_int=100; fi + + logical_width=$(((mon_width * 100) / scale_int)) + logical_height=$(((mon_height * 100) / scale_int)) + fi + + # Ensure we have valid integer values + if ! [[ "$logical_width" =~ ^-?[0-9]+$ ]]; then logical_width=$mon_width; fi + if ! [[ "$logical_height" =~ ^-?[0-9]+$ ]]; then logical_height=$mon_height; fi + + debug_echo "Physical resolution: ${mon_width}x${mon_height}" + debug_echo "Logical resolution: ${logical_width}x${logical_height} (physical Γ· scale)" + + # Calculate window dimensions based on LOGICAL space percentages + local width=$((logical_width * WIDTH_PERCENT / 100)) + local height=$((logical_height * HEIGHT_PERCENT / 100)) - # Calculate position and size based on percentages - local width=$((mon_width * WIDTH_PERCENT / 100)) - local height=$((mon_height * HEIGHT_PERCENT / 100)) - local x=$((mon_x + (mon_width * X_PERCENT / 100))) - local y=$((mon_y + (mon_height * Y_PERCENT / 100))) + # Calculate Y position from top based on percentage of LOGICAL height + local y_offset=$((logical_height * Y_PERCENT / 100)) - echo "$x $y $width $height" + # Calculate centered X position in LOGICAL space + local x_offset=$(((logical_width - width) / 2)) + + # Apply monitor offset to get final positions in logical coordinates + local final_x=$((mon_x + x_offset)) + local final_y=$((mon_y + y_offset)) + + debug_echo "Window size: ${width}x${height} (logical pixels)" + debug_echo "Final position: x=$final_x, y=$final_y (logical coordinates)" + debug_echo "Hyprland will scale these to physical coordinates automatically" + + echo "$final_x $final_y $width $height $mon_name" } # Get the current workspace @@ -145,7 +203,14 @@ CURRENT_WS=$(hyprctl activeworkspace -j | jq -r '.id') # Function to get stored terminal address get_terminal_address() { if [ -f "$ADDR_FILE" ] && [ -s "$ADDR_FILE" ]; then - cat "$ADDR_FILE" + cut -d' ' -f1 "$ADDR_FILE" + fi +} + +# Function to get stored monitor name +get_terminal_monitor() { + if [ -f "$ADDR_FILE" ] && [ -s "$ADDR_FILE" ]; then + cut -d' ' -f2- "$ADDR_FILE" fi } @@ -174,17 +239,22 @@ spawn_terminal() { debug_echo "Creating new dropdown terminal with command: $TERMINAL_CMD" # Calculate dropdown position for later use - pos_info=$(calculate_dropdown_position) - target_x=$(echo $pos_info | cut -d' ' -f1) - target_y=$(echo $pos_info | cut -d' ' -f2) - width=$(echo $pos_info | cut -d' ' -f3) - height=$(echo $pos_info | cut -d' ' -f4) + local pos_info=$(calculate_dropdown_position) + if [ $? -ne 0 ]; then + debug_echo "Warning: Using fallback positioning" + fi - debug_echo "Target position: ${target_x}x${target_y}, size: ${width}x${height}" + local target_x=$(echo $pos_info | cut -d' ' -f1) + local target_y=$(echo $pos_info | cut -d' ' -f2) + local width=$(echo $pos_info | cut -d' ' -f3) + local height=$(echo $pos_info | cut -d' ' -f4) + local monitor_name=$(echo $pos_info | cut -d' ' -f5) + + debug_echo "Target position: ${target_x},${target_y}, size: ${width}x${height}" # Get window count before spawning - windows_before=$(hyprctl clients -j) - count_before=$(echo "$windows_before" | jq 'length') + local windows_before=$(hyprctl clients -j) + local count_before=$(echo "$windows_before" | jq 'length') # Launch terminal directly in special workspace to avoid visible spawn hyprctl dispatch exec "[float; size $width $height; workspace special:scratchpad silent] $TERMINAL_CMD" @@ -193,10 +263,10 @@ spawn_terminal() { sleep 0.1 # Get windows after spawning - windows_after=$(hyprctl clients -j) - count_after=$(echo "$windows_after" | jq 'length') + local windows_after=$(hyprctl clients -j) + local count_after=$(echo "$windows_after" | jq 'length') - new_addr="" + local new_addr="" if [ "$count_after" -gt "$count_before" ]; then # Find the new window by comparing before/after lists @@ -212,9 +282,9 @@ spawn_terminal() { fi if [ -n "$new_addr" ] && [ "$new_addr" != "null" ]; then - # Store the address - echo "$new_addr" > "$ADDR_FILE" - debug_echo "Terminal created with address: $new_addr in special workspace" + # Store the address and monitor name + echo "$new_addr $monitor_name" > "$ADDR_FILE" + debug_echo "Terminal created with address: $new_addr in special workspace on monitor $monitor_name" # Small delay to ensure it's properly in special workspace sleep 0.2 @@ -236,6 +306,23 @@ spawn_terminal() { if terminal_exists; then TERMINAL_ADDR=$(get_terminal_address) debug_echo "Found existing terminal: $TERMINAL_ADDR" + focused_monitor=$(get_monitor_info | awk '{print $6}') + dropdown_monitor=$(get_terminal_monitor) + if [ "$focused_monitor" != "$dropdown_monitor" ]; then + debug_echo "Monitor focus changed: moving dropdown to $focused_monitor" + # Calculate new position for focused monitor + pos_info=$(calculate_dropdown_position) + target_x=$(echo $pos_info | cut -d' ' -f1) + target_y=$(echo $pos_info | cut -d' ' -f2) + width=$(echo $pos_info | cut -d' ' -f3) + height=$(echo $pos_info | cut -d' ' -f4) + monitor_name=$(echo $pos_info | cut -d' ' -f5) + # Move and resize window + hyprctl dispatch movewindowpixel "exact $target_x $target_y,address:$TERMINAL_ADDR" + hyprctl dispatch resizewindowpixel "exact $width $height,address:$TERMINAL_ADDR" + # Update ADDR_FILE + echo "$TERMINAL_ADDR $monitor_name" > "$ADDR_FILE" + fi if terminal_in_special; then debug_echo "Bringing terminal from scratchpad with slide down animation" diff --git a/config/hypr/scripts/RefreshNoWaybar.sh b/config/hypr/scripts/RefreshNoWaybar.sh index f950db51..8454124e 100755 --- a/config/hypr/scripts/RefreshNoWaybar.sh +++ b/config/hypr/scripts/RefreshNoWaybar.sh @@ -31,8 +31,9 @@ done # quit quickshell & relaunch quickshell #pkill qs && qs & -# Wallust refresh -${SCRIPTSDIR}/WallustSwww.sh & +# Wallust refresh (synchronous to ensure colors are ready) +${SCRIPTSDIR}/WallustSwww.sh +sleep 0.2 # reload swaync swaync-client --reload-config diff --git a/config/hypr/scripts/WallustSwww.sh b/config/hypr/scripts/WallustSwww.sh index 62dde375..5a0bc491 100755 --- a/config/hypr/scripts/WallustSwww.sh +++ b/config/hypr/scripts/WallustSwww.sh @@ -1,39 +1,58 @@ #!/bin/bash # /* ---- π« https://github.com/JaKooLit π« ---- */ ## -# Wallust Colors for current wallpaper +# Wallust: derive colors from the current wallpaper and update templates +# Usage: WallustSwww.sh [absolute_path_to_wallpaper] -# Define the path to the swww cache directory +set -euo pipefail + +# Inputs and paths +passed_path="${1:-}" cache_dir="$HOME/.cache/swww/" +rofi_link="$HOME/.config/rofi/.current_wallpaper" +wallpaper_current="$HOME/.config/hypr/wallpaper_effects/.wallpaper_current" -# Get a list of monitor outputs -monitor_outputs=($(ls "$cache_dir")) +# Helper: get focused monitor name (prefer JSON) +get_focused_monitor() { + if command -v jq >/dev/null 2>&1; then + hyprctl monitors -j | jq -r '.[] | select(.focused) | .name' + else + hyprctl monitors | awk '/^Monitor/{name=$2} /focused: yes/{print name}' + fi +} -# Initialize a flag to determine if the ln command was executed -ln_success=false +# Determine wallpaper_path +wallpaper_path="" +if [[ -n "$passed_path" && -f "$passed_path" ]]; then + wallpaper_path="$passed_path" +else + # Try to read from swww cache for the focused monitor, with a short retry loop + current_monitor="$(get_focused_monitor)" + cache_file="$cache_dir$current_monitor" -# Get current focused monitor -current_monitor=$(hyprctl monitors | awk '/^Monitor/{name=$2} /focused: yes/{print name}') -echo $current_monitor -# Construct the full path to the cache file -cache_file="$cache_dir$current_monitor" -echo $cache_file -# Check if the cache file exists for the current monitor output -if [ -f "$cache_file" ]; then - # Get the wallpaper path from the cache file - wallpaper_path=$(grep -v 'Lanczos3' "$cache_file" | head -n 1) - echo $wallpaper_path - # symlink the wallpaper to the location Rofi can access - if ln -sf "$wallpaper_path" "$HOME/.config/rofi/.current_wallpaper"; then - ln_success=true # Set the flag to true upon successful execution + # Wait briefly for swww to write its cache after an image change + for i in {1..10}; do + if [[ -f "$cache_file" ]]; then + break fi - # copy the wallpaper for wallpaper effects - cp -r "$wallpaper_path" "$HOME/.config/hypr/wallpaper_effects/.wallpaper_current" + sleep 0.1 + done + + if [[ -f "$cache_file" ]]; then + # The first non-filter line is the original wallpaper path + wallpaper_path="$(grep -v 'Lanczos3' "$cache_file" | head -n 1)" + fi fi -# Check the flag before executing further commands -if [ "$ln_success" = true ]; then - # execute wallust - echo 'about to execute wallust' - # execute wallust skipping tty and terminal changes - wallust run "$wallpaper_path" -s & +if [[ -z "${wallpaper_path:-}" || ! -f "$wallpaper_path" ]]; then + # Nothing to do; avoid failing loudly so callers can continue + exit 0 fi + +# Update helpers that depend on the path +ln -sf "$wallpaper_path" "$rofi_link" || true +mkdir -p "$(dirname "$wallpaper_current")" +cp -f "$wallpaper_path" "$wallpaper_current" || true + +# Run wallust (silent) to regenerate templates defined in ~/.config/wallust/wallust.toml +# -s is used in this repo to keep things quiet and avoid extra prompts +wallust run -s "$wallpaper_path" || true diff --git a/config/hypr/scripts/WaybarCava.sh b/config/hypr/scripts/WaybarCava.sh index d31a05b5..6809e60e 100755 --- a/config/hypr/scripts/WaybarCava.sh +++ b/config/hypr/scripts/WaybarCava.sh @@ -1,26 +1,42 @@ -#!/bin/bash -# /* ---- π« https://github.com/JaKooLit π« ---- */ ## -# Not my own work. This was added through Github PR. Credit to original author +#!/usr/bin/env bash +# WaybarCava.sh β safer single-instance handling, cleanup, and robustness +# Original concept by JaKooLit; this variant focuses on lifecycle hardening. -#----- Optimized bars animation without much CPU usage increase -------- +set -euo pipefail + +# Ensure cava exists +if ! command -v cava >/dev/null 2>&1; then + echo "cava not found in PATH" >&2 + exit 1 +fi + +# 0..7 β βββββ
βββ bar="βββββ
βββ" dict="s/;//g" - -# Calculate the length of the bar outside the loop bar_length=${#bar} - -# Create dictionary to replace char with bar for ((i = 0; i < bar_length; i++)); do - dict+=";s/$i/${bar:$i:1}/g" + dict+=";s/$i/${bar:$i:1}/g" done -# Create cava config -config_file="/tmp/bar_cava_config" +# Single-instance guard (only kill our previous instance if itβs still alive) +RUNTIME_DIR="${XDG_RUNTIME_DIR:-/tmp}" +pidfile="$RUNTIME_DIR/waybar-cava.pid" +if [[ -f "$pidfile" ]]; then + oldpid="$(cat "$pidfile" || true)" + if [[ -n "$oldpid" ]] && kill -0 "$oldpid" 2>/dev/null; then + kill "$oldpid" 2>/dev/null || true + sleep 0.1 || true + fi +fi +printf '%d' $$ >"$pidfile" + +# Unique temp config + cleanup on exit +config_file="$(mktemp "$RUNTIME_DIR/waybar-cava.XXXXXX.conf")" +cleanup() { rm -f "$config_file" "$pidfile"; } +trap cleanup EXIT INT TERM + cat >"$config_file" <<EOF [general] -# Older systems show significant CPU use with default framerate -# Setting maximum framerate to 30 -# You can increase the value if you wish framerate = 30 bars = 10 @@ -35,8 +51,5 @@ data_format = ascii ascii_max_range = 7 EOF -# Kill cava if it's already running -pkill -f "cava -p $config_file" - -# Read stdout from cava and perform substitution in a single sed command -cava -p "$config_file" | sed -u "$dict" +# Stream cava output and translate digits 0..7 to bar glyphs +exec cava -p "$config_file" | sed -u "$dict" |
