Added Thumbnailing to wallpaper picker
This commit is contained in:
@@ -5,7 +5,6 @@ import Quickshell.Hyprland
|
|||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
import Qt.labs.folderlistmodel
|
import Qt.labs.folderlistmodel
|
||||||
|
|
||||||
|
|
||||||
PanelWindow {
|
PanelWindow {
|
||||||
id: picker
|
id: picker
|
||||||
implicitWidth: screen.width * 0.75
|
implicitWidth: screen.width * 0.75
|
||||||
@@ -41,7 +40,7 @@ PanelWindow {
|
|||||||
// get folder url
|
// get folder url
|
||||||
FolderListModel {
|
FolderListModel {
|
||||||
id: imagesModel
|
id: imagesModel
|
||||||
folder: "file://" + Quickshell.workingDirectory + "/Pictures/Wallpapers"
|
folder: "file://" + Quickshell.env("HOME") + "/.cache/wallpaper-thumbs"
|
||||||
nameFilters: ["*.png", "*.jpg", "*.jpeg"]
|
nameFilters: ["*.png", "*.jpg", "*.jpeg"]
|
||||||
showDirs: false
|
showDirs: false
|
||||||
}
|
}
|
||||||
@@ -103,7 +102,7 @@ PanelWindow {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
Process {
|
Process {
|
||||||
id: wallpaperProcess
|
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 {
|
stdout: StdioCollector {
|
||||||
onStreamFinished: console.log(`line read: ${this.text}`)
|
onStreamFinished: console.log(`line read: ${this.text}`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,22 @@ import QtQuick
|
|||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Hyprland
|
import Quickshell.Hyprland
|
||||||
|
|
||||||
|
import QtQuick.Controls
|
||||||
|
import Quickshell.Io
|
||||||
|
import Qt.labs.folderlistmodel
|
||||||
|
|
||||||
|
|
||||||
Item { // container, invisible
|
Item { // container, invisible
|
||||||
id: wLoader
|
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 {
|
Loader {
|
||||||
id: wallpaperLoader
|
id: wallpaperLoader
|
||||||
active: false
|
active: false
|
||||||
@@ -14,7 +27,9 @@ Item { // container, invisible
|
|||||||
GlobalShortcut {
|
GlobalShortcut {
|
||||||
name: "Wallpaper"
|
name: "Wallpaper"
|
||||||
description: "Open wallpaper picker"
|
description: "Open wallpaper picker"
|
||||||
|
|
||||||
onPressed: {
|
onPressed: {
|
||||||
|
generateThumbs.startDetached()
|
||||||
wallpaperLoader.active = !wallpaperLoader.active
|
wallpaperLoader.active = !wallpaperLoader.active
|
||||||
console.log("Pressed Meta+Shift+W (Hyprland global shortcut)")
|
console.log("Pressed Meta+Shift+W (Hyprland global shortcut)")
|
||||||
}
|
}
|
||||||
|
|||||||
Executable
+49
@@ -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()
|
||||||
+33
-12
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
# Path to the image is the first argument
|
# Path to the image is the first argument
|
||||||
IMAGE="$1"
|
IMAGE="$1"
|
||||||
|
image_name=$(basename "$IMAGE")
|
||||||
|
image="$HOME/Pictures/Wallpapers/$image_name"
|
||||||
|
|
||||||
|
echo "$image"
|
||||||
|
|
||||||
echo "start"
|
echo "start"
|
||||||
|
|
||||||
@@ -11,17 +15,34 @@ if [[ -z "$IMAGE" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
if [ -x "/usr/bin/swww-daemon" ]; then
|
||||||
sleep 0.2
|
echo "swww-daemon exists and is executable"
|
||||||
echo "daemon started"
|
|
||||||
|
# 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
|
fi
|
||||||
|
|
||||||
# Set the wallpaper
|
|
||||||
echo "running"
|
|
||||||
swww img "$IMAGE" -t grow --transition-duration 1
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user