From c37db71cacd3d55eb8333a7ffa8f54dc6ad67c0e Mon Sep 17 00:00:00 2001 From: Hannes Date: Mon, 8 Jun 2026 23:53:18 +0200 Subject: [PATCH] made wallpaper settable with xdg config --- install.sh | 16 ++++++++++++++++ modules/wlogout/WLogout.qml | 7 +++++-- modules/wlogout/WlogoutLoader.qml | 23 +++++++++++++++++++++-- modules/wp/WallpaperPicker.qml | 1 + modules/wp/generate-wallpaper-thumbs.sh | 13 ++++++++++--- modules/wp/set-wallpaper.sh | 20 +++++++++++++++----- scripts/wallpaper_dir.sh | 21 +++++++++++++++++++++ states/wallpaperdir/WallpaperState.qml | 7 +++++++ states/wallpaperdir/qmldir | 1 + 9 files changed, 97 insertions(+), 12 deletions(-) create mode 100755 scripts/wallpaper_dir.sh create mode 100644 states/wallpaperdir/WallpaperState.qml create mode 100644 states/wallpaperdir/qmldir diff --git a/install.sh b/install.sh index 28ecb6b..85de38e 100755 --- a/install.sh +++ b/install.sh @@ -103,5 +103,21 @@ download \ "$SCRIPT_DIR/colors/icons/correct.svg" \ "correct.svg" +# ---------------------------- +# Example Wallpaper +# ---------------------------- +echo +info "Preparing wallpaper..." + +WALLPAPER_DIR=$(scripts/wallpaper_dir.sh) + +# 5. Ensure it exists +mkdir -p "$WALLPAPER_DIR" + +info "Copying example Wallpaper..." + +# 6. Copy example wallpaper +cp $SCRIPT_DIR/colors/example_background.png "$WALLPAPER_DIR/japan_old_emperor_stream_with_bridge.png" + echo ok "All assets prepared successfully." \ No newline at end of file diff --git a/modules/wlogout/WLogout.qml b/modules/wlogout/WLogout.qml index b85c510..c3f7799 100644 --- a/modules/wlogout/WLogout.qml +++ b/modules/wlogout/WLogout.qml @@ -5,6 +5,7 @@ import Quickshell.Io import Quickshell.Wayland import "../../colors" +import "../../states/wallpaperdir" as Global Variants { id: root @@ -32,6 +33,7 @@ Variants { Keys.onPressed: event => { if (event.key == Qt.Key_Escape) { console.log("Pressed Escape, closing Wallpaper Picker") + console.log("Wallpaper Dir:", Global.WallpaperState.wallpaperDir) wlogoutLoader.active = false } else { for (let i = 0; i < buttons.length; i++) { @@ -51,16 +53,17 @@ Variants { Rectangle { anchors.fill: parent + Image { anchors.fill: parent - source: Quickshell.env("HOME") + "/Pictures/Wallpapers/Static/blurred.jpg" + source: Global.WallpaperState.wallpaperDir + "/Static/blurred.jpg" fillMode: Image.PreserveAspectCrop } MouseArea { anchors.fill: parent onClicked: { - console.log("Pressed Escape, closing Wallpaper Picker") + console.log("clicked ???, closing Wallpaper Picker") wlogoutLoader.active = false } GridLayout { diff --git a/modules/wlogout/WlogoutLoader.qml b/modules/wlogout/WlogoutLoader.qml index 14a0340..769054f 100644 --- a/modules/wlogout/WlogoutLoader.qml +++ b/modules/wlogout/WlogoutLoader.qml @@ -3,14 +3,32 @@ import Quickshell import Quickshell.Hyprland import Quickshell.Io +import "../../states/wallpaper" as Global + Item { // container, invisible id: wlLoader + Process { + id: getWallpaper + command: ["sh", "-c", Quickshell.env("HOME") + "/.config/quickshell/scripts/wallpaper_dir.sh"] + stdout: StdioCollector { + onStreamFinished: function() { + console.log("getWallpaper: " + this.text) + + Global.WallpaperState.wallpaperDir = this.text.trim() + + wlogoutLoader.active = true + } + } + } + Loader { id: wlogoutLoader active: false - sourceComponent: Wlogout { id: wLogout } + sourceComponent: Wlogout { + id: wLogout + } } GlobalShortcut { @@ -19,7 +37,8 @@ Item { // container, invisible onPressed: { console.log("Pressed Meta+Shift+W (Hyprland global shortcut)") - wlogoutLoader.active = !wlogoutLoader.active + getWallpaper.running = true + // wlogoutLoader.active = !wlogoutLoader.active } } diff --git a/modules/wp/WallpaperPicker.qml b/modules/wp/WallpaperPicker.qml index c01b199..432caa1 100644 --- a/modules/wp/WallpaperPicker.qml +++ b/modules/wp/WallpaperPicker.qml @@ -5,6 +5,7 @@ import Quickshell.Hyprland import Quickshell.Io import Qt.labs.folderlistmodel import "../../colors" +import "../../states/wallpaperdir" as Global PanelWindow { id: picker diff --git a/modules/wp/generate-wallpaper-thumbs.sh b/modules/wp/generate-wallpaper-thumbs.sh index 7322a3d..ab1154b 100755 --- a/modules/wp/generate-wallpaper-thumbs.sh +++ b/modules/wp/generate-wallpaper-thumbs.sh @@ -1,10 +1,15 @@ #!/usr/bin/env bash +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" + # Folder with full-size wallpapers -WALLPAPER_DIR="$HOME/Pictures/Wallpapers" +WALLPAPER_DIR=$("$SCRIPT_DIR/../../scripts/wallpaper_dir.sh") + +echo "$WALLPAPER_DIR" # Folder to store thumbnails THUMB_DIR="$HOME/.cache/wallpaper-thumbs" +echo "$THUMB_DIR" if [ ! -d $THUMB_DIR ]; then mkdir -p $THUMB_DIR; @@ -66,12 +71,14 @@ for img in "$WALLPAPER_DIR"/*.{jpg,jpeg,png}; do continue fi - num+=1 + ((num++)) # Generate thumbnail using ImageMagick if [ -x "/usr/bin/magick" ]; then magick "$img" -resize "${MAX_DIM}x${MAX_DIM}" "$thumb" - rm $temp_image_name + if [ -f "$temp_image_name" ]; then + rm "$temp_image_name" + fi else if [ -f "$temp_image_name" ] && [ "$temp_image_name" -nt "$img" ]; then continue diff --git a/modules/wp/set-wallpaper.sh b/modules/wp/set-wallpaper.sh index 69eeb6e..3d293a5 100755 --- a/modules/wp/set-wallpaper.sh +++ b/modules/wp/set-wallpaper.sh @@ -1,9 +1,18 @@ #!/bin/bash +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" + +# Folder with full-size wallpapers +WALLPAPER_DIR=$("$SCRIPT_DIR/../../scripts/wallpaper_dir.sh") +if [ -z "$WALLPAPER_DIR" ]; then + echo "Failed to determine wallpaper directory. Exiting." + exit 1 +fi + # Path to the image is the first argument IMAGE="$1" image_name=$(basename "$IMAGE") -image="$HOME/Pictures/Wallpapers/$image_name" +image="$WALLPAPER_DIR/$image_name" echo "start" @@ -45,6 +54,7 @@ elif [ -x "/usr/bin/hyprpaper" ]; then sed -i "3s|path = .*|path = ${image}|" ~/.config/hypr/hyprpaper.conf hyprctl monitors -j | jq -r 'sort_by(.id) | .[].name' | while IFS= read -r display; do + echo "hyprctl hyprpaper wallpaper $display, $image" hyprctl hyprpaper wallpaper "$display, $image" done fi @@ -74,9 +84,9 @@ if [ -x "/usr/bin/sddm" ]; then else cp $image $blurred_wp fi -if [ -x "/usr/bin/sddm" ] && [ -d "/usr/share/backgrounds" ]; then - sddm_background="/usr/share/backgrounds/background.jpg" - cp "$image" "$sddm_background" -fi +# if [ -x "/usr/bin/sddm" ] && [ -d "/usr/share/backgrounds" ]; then +# sddm_background="/usr/share/backgrounds/background.jpg" +# cp "$image" "$sddm_background" +# fi echo "test" diff --git a/scripts/wallpaper_dir.sh b/scripts/wallpaper_dir.sh new file mode 100755 index 0000000..da50adf --- /dev/null +++ b/scripts/wallpaper_dir.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# Setting wallpaper_dir + +WALLPAPER_DIR="${XDG_PICTURES_DIR:-}" + +# 2. If empty, use xdg-user-dir (most reliable) +if [ -z "$WALLPAPER_DIR" ]; then + if command -v xdg-user-dir >/dev/null 2>&1; then + WALLPAPER_DIR="$(xdg-user-dir PICTURES 2>/dev/null)" + fi +fi + +# 3. Final fallback (hardcoded default) +if [ -z "$WALLPAPER_DIR" ] || [ ! -d "$WALLPAPER_DIR" ]; then + WALLPAPER_DIR="$HOME/Pictures" +fi + +# 4. Your wallpaper subfolder +WALLPAPER_DIR="$WALLPAPER_DIR/Wallpapers" + +echo $WALLPAPER_DIR \ No newline at end of file diff --git a/states/wallpaperdir/WallpaperState.qml b/states/wallpaperdir/WallpaperState.qml new file mode 100644 index 0000000..5bdd39f --- /dev/null +++ b/states/wallpaperdir/WallpaperState.qml @@ -0,0 +1,7 @@ +pragma Singleton +import QtQuick +import Quickshell + +QtObject { + property string wallpaperDir: Quickshell.env("HOME") + "/Pictures/Wallpapers" +} \ No newline at end of file diff --git a/states/wallpaperdir/qmldir b/states/wallpaperdir/qmldir new file mode 100644 index 0000000..853b461 --- /dev/null +++ b/states/wallpaperdir/qmldir @@ -0,0 +1 @@ +singleton WallpaperState WallpaperState.qml \ No newline at end of file