From 099d5e8ba6ff0a9638cdc4718ce5a02e76b5a02c Mon Sep 17 00:00:00 2001 From: sudacode Date: Sun, 30 Nov 2025 12:25:38 -0800 Subject: [PATCH] update --- .config/rofi/scripts/rofi-wallpaper.sh | 4 ++-- .../go/change-wallpaper/change-wallpaper.go | 21 ++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.config/rofi/scripts/rofi-wallpaper.sh b/.config/rofi/scripts/rofi-wallpaper.sh index af33a79..be69b51 100755 --- a/.config/rofi/scripts/rofi-wallpaper.sh +++ b/.config/rofi/scripts/rofi-wallpaper.sh @@ -7,5 +7,5 @@ DIR="$HOME/Pictures/wallpapers/favorites" SELECTED_WALL=$(cd "$DIR" && for a in *.jpg *.png; do echo -en "$a\0icon\x1f$a\n"; done | rofi -dmenu -i -no-custom -theme "$THEME" -p "Select a wallpaper" -theme-str 'configuration {icon-size: 128; dpi: 96;} window {width: 45%; height: 45%;}') PTH="$(printf "%s" "$DIR/$SELECTED_WALL" | tr -s '/')" notify-send -a "rofi-wallpaper" "Wallpaper set to" -i "$PTH" "$PTH" -hyprctl hyprpaper reload , "$DIR/$SELECTED_WALL" -echo "$PTH" > "$HOME/.wallpaper" +echo "$PTH" >"$HOME/.wallpaper" +hyprctl hyprpaper reload , "$PTH" diff --git a/projects/go/change-wallpaper/change-wallpaper.go b/projects/go/change-wallpaper/change-wallpaper.go index 595a425..a01a6e4 100644 --- a/projects/go/change-wallpaper/change-wallpaper.go +++ b/projects/go/change-wallpaper/change-wallpaper.go @@ -272,11 +272,26 @@ func ensureSized(wallpaperPath string) (string, error) { return "", err } - if src.Bounds().Dx() == targetWidth && src.Bounds().Dy() == targetHeight { + srcWidth := float64(src.Bounds().Dx()) + srcHeight := float64(src.Bounds().Dy()) + targetW := float64(targetWidth) + targetH := float64(targetHeight) + + // Calculate scale factor to fit image within target while maintaining aspect ratio + scaleW := targetW / srcWidth + scaleH := targetH / srcHeight + scale := min(scaleW, scaleH) + + // If image already fits within target dimensions, no resize needed + if scale >= 1.0 { return wallpaperPath, nil } - dst := image.NewRGBA(image.Rect(0, 0, targetWidth, targetHeight)) + // Calculate new dimensions maintaining aspect ratio (best fit) + newWidth := int(srcWidth * scale) + newHeight := int(srcHeight * scale) + + dst := image.NewRGBA(image.Rect(0, 0, newWidth, newHeight)) draw.CatmullRom.Scale(dst, dst.Bounds(), src, src.Bounds(), draw.Over, nil) var ext string @@ -295,7 +310,7 @@ func ensureSized(wallpaperPath string) (string, error) { } base := strings.TrimSuffix(filepath.Base(wallpaperPath), filepath.Ext(wallpaperPath)) - resizedPath := filepath.Join(filepath.Dir(wallpaperPath), fmt.Sprintf("%s-%dx%d%s", base, targetWidth, targetHeight, ext)) + resizedPath := filepath.Join(filepath.Dir(wallpaperPath), fmt.Sprintf("%s-%dx%d%s", base, newWidth, newHeight, ext)) outFile, err := os.Create(resizedPath) if err != nil {