From 5d2784ecb4df59c0c4ae4e88bd9eced436a671ee Mon Sep 17 00:00:00 2001 From: Hannes Date: Thu, 12 Feb 2026 21:09:56 +0100 Subject: [PATCH] Added Thumbnailing to wallpaper picker --- modules/wp/WallpaperPicker.qml | 5 +-- modules/wp/WallpaperPickerLoader.qml | 15 ++++++++ modules/wp/generate-wallpaper-thumbs.sh | 49 +++++++++++++++++++++++++ modules/wp/set-wallpaper.sh | 43 ++++++++++++++++------ 4 files changed, 98 insertions(+), 14 deletions(-) create mode 100755 modules/wp/generate-wallpaper-thumbs.sh diff --git a/modules/wp/WallpaperPicker.qml b/modules/wp/WallpaperPicker.qml index 0bd56e0..c452c52 100644 --- a/modules/wp/WallpaperPicker.qml +++ b/modules/wp/WallpaperPicker.qml @@ -5,7 +5,6 @@ import Quickshell.Hyprland import Quickshell.Io import Qt.labs.folderlistmodel - PanelWindow { id: picker implicitWidth: screen.width * 0.75 @@ -41,7 +40,7 @@ PanelWindow { // get folder url FolderListModel { id: imagesModel - folder: "file://" + Quickshell.workingDirectory + "/Pictures/Wallpapers" + folder: "file://" + Quickshell.env("HOME") + "/.cache/wallpaper-thumbs" nameFilters: ["*.png", "*.jpg", "*.jpeg"] showDirs: false } @@ -103,7 +102,7 @@ PanelWindow { anchors.fill: parent Process { id: wallpaperProcess - command: ["sh", "-c", Quickshell.workingDirectory + "/.config/quickshell/modules/wp/set-wallpaper.sh" + " " + model.filePath + " &"] + command: ["sh", "-c", Quickshell.env("HOME") + "/.config/quickshell/modules/wp/set-wallpaper.sh" + " " + model.filePath + " &"] stdout: StdioCollector { onStreamFinished: console.log(`line read: ${this.text}`) } diff --git a/modules/wp/WallpaperPickerLoader.qml b/modules/wp/WallpaperPickerLoader.qml index 70a9f6a..c1ede6d 100644 --- a/modules/wp/WallpaperPickerLoader.qml +++ b/modules/wp/WallpaperPickerLoader.qml @@ -2,9 +2,22 @@ import QtQuick import Quickshell import Quickshell.Hyprland +import QtQuick.Controls +import Quickshell.Io +import Qt.labs.folderlistmodel + + Item { // container, invisible id: wLoader + Process { + id: generateThumbs + command: ["sh", "-c", Quickshell.env("HOME") + "/.config/quickshell/modules/wp/generate-wallpaper-thumbs.sh"] + stdout: StdioCollector { + onStreamFinished: console.log(`line read: ${this.text}`) + } + } + Loader { id: wallpaperLoader active: false @@ -14,7 +27,9 @@ Item { // container, invisible GlobalShortcut { name: "Wallpaper" description: "Open wallpaper picker" + onPressed: { + generateThumbs.startDetached() wallpaperLoader.active = !wallpaperLoader.active console.log("Pressed Meta+Shift+W (Hyprland global shortcut)") } diff --git a/modules/wp/generate-wallpaper-thumbs.sh b/modules/wp/generate-wallpaper-thumbs.sh new file mode 100755 index 0000000..6fe3b83 --- /dev/null +++ b/modules/wp/generate-wallpaper-thumbs.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# Folder with full-size wallpapers +WALLPAPER_DIR="$HOME/Pictures/Wallpapers" + +# Folder to store thumbnails +THUMB_DIR="$HOME/.cache/wallpaper-thumbs" + +if [ ! -d $THUMB_DIR ]; then + mkdir -p $THUMB_DIR; +fi + + +# Make sure the thumb directory exists +mkdir -p "$THUMB_DIR" + +# Max width/height of the thumbnails +MAX_DIM=300 + +# Process each image +for img in "$WALLPAPER_DIR"/*.{jpg,jpeg,png}; do + # Skip if no files match + [ -e "$img" ] || continue + + # Get just the filename + fname=$(basename "$img") + + # Output path + thumb="$THUMB_DIR/$fname" + + # If thumbnail already exists and is newer than the original, skip + if [ -f "$thumb" ] && [ "$thumb" -nt "$img" ]; then + continue + fi + + # Generate thumbnail using ImageMagick + magick "$img" -resize "${MAX_DIM}x${MAX_DIM}" "$thumb" +done + +echo "Thumbnails generated in $THUMB_DIR" + +Process { + id: generateThumbs + command: ["sh", "-c", Quickshell.env("HOME") + "/.config/quickshell/modules/wp/generate-wallpaper-thumbs.sh" + " " + model.filePath + " &"] + stdout: StdioCollector { + onStreamFinished: console.log(`line read: ${this.text}`) + } +} +generateThumbs.startDetached() \ No newline at end of file diff --git a/modules/wp/set-wallpaper.sh b/modules/wp/set-wallpaper.sh index df1ac2f..938751f 100755 --- a/modules/wp/set-wallpaper.sh +++ b/modules/wp/set-wallpaper.sh @@ -2,6 +2,10 @@ # Path to the image is the first argument IMAGE="$1" +image_name=$(basename "$IMAGE") +image="$HOME/Pictures/Wallpapers/$image_name" + +echo "$image" echo "start" @@ -11,17 +15,34 @@ if [[ -z "$IMAGE" ]]; then exit 1 fi -# Check if swww daemon is running -if ! pgrep -x "swww-daemon" > /dev/null; then - echo "Starting swww daemon..." - swww-daemon & - # Give the daemon a moment to start - sleep 0.2 - echo "daemon started" -fi +if [ -x "/usr/bin/swww-daemon" ]; then + echo "swww-daemon exists and is executable" -# Set the wallpaper -echo "running" -swww img "$IMAGE" -t grow --transition-duration 1 + # Check if swww daemon is running + if ! pgrep -x "swww-daemon" > /dev/null; then + echo "Starting swww daemon..." + swww-daemon & + # Give the daemon a moment to start + sleep 0.2 + echo "daemon started" + fi + + # Set the wallpaper + echo "running" + swww img "$image" -t grow --transition-duration 1 + +elif [ -x "/usr/bin/hyprpaper" ]; then + echo "hyprpaper exists and is executable" + + if ! pgrep -x "hyprpaper" > /dev/null; then + echo "Starting hyprpaper daemon..." + hyprpaper & + + # Give the daemon a moment to start + sleep 0.2 + echo "daemon started" + fi + hyprctl hyprpaper wallpaper ", $image" +fi \ No newline at end of file