From cc84ab2289381038f483f06963374aa0247f6724 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 2 Sep 2025 20:56:37 +0200 Subject: ... --- accounts/gkleen@sif/default.nix | 2 +- accounts/gkleen@sif/shell/default.nix | 69 ++++++++++++++- .../shell/quickshell-plugins/CMakeLists.txt | 1 + .../gkleen@sif/shell/quickshell-plugins/Chrono.hpp | 3 +- .../shell/quickshell-plugins/FileSelector.cpp | 99 ++++++++++++++++++++++ .../shell/quickshell-plugins/FileSelector.hpp | 52 ++++++++++++ .../quickshell/Services/WallpaperSelector.qml | 8 ++ .../shell/quickshell/WallpaperBackground.qml | 85 +++++++++++++++++++ accounts/gkleen@sif/shell/quickshell/shell.qml | 23 ++++- 9 files changed, 337 insertions(+), 5 deletions(-) create mode 100644 accounts/gkleen@sif/shell/quickshell-plugins/FileSelector.cpp create mode 100644 accounts/gkleen@sif/shell/quickshell-plugins/FileSelector.hpp create mode 100644 accounts/gkleen@sif/shell/quickshell/Services/WallpaperSelector.qml create mode 100644 accounts/gkleen@sif/shell/quickshell/WallpaperBackground.qml diff --git a/accounts/gkleen@sif/default.nix b/accounts/gkleen@sif/default.nix index f2978b6e..190a5016 100644 --- a/accounts/gkleen@sif/default.nix +++ b/accounts/gkleen@sif/default.nix @@ -374,7 +374,7 @@ in { services = { wpaperd = { - enable = true; + enable = false; settings.default = { path = "~/.wallpapers"; duration = "15m"; diff --git a/accounts/gkleen@sif/shell/default.nix b/accounts/gkleen@sif/shell/default.nix index 26c8bd98..84140072 100644 --- a/accounts/gkleen@sif/shell/default.nix +++ b/accounts/gkleen@sif/shell/default.nix @@ -7,8 +7,75 @@ config = { src = ./quickshell; replacements = { - coreutils = toString pkgs.coreutils; ignore_workspaces = builtins.toJSON (map ({ name, ... }: name) config.programs.niri.scratchspaces); + wallpapers = builtins.toJSON (pkgs.stdenvNoCC.mkDerivation { + name = "wallpapers"; + srcs = [ + (pkgs.fetchurl { + url = "https://esawebb.org/media/archives/images/publicationtiff10k/carinanebula3.tif"; + hash = "sha256-YxZEweDKJfvfrdxb/QFmgJhcZDEJYxotoHrG+RRn1tw="; + }) + (pkgs.fetchurl { + url = "https://esawebb.org/media/archives/images/original/pillarsofcreation_composite.tif"; + hash = "sha256-qRiODxR0lZWdxgYXna0fNRFFDErpBJDwOJuQl6sNjRc="; + }) + (pkgs.fetchurl { + url = "https://esawebb.org/media/archives/images/publicationtiff10k/weic2212a.tif"; + hash = "sha256-l2fqE/z//C1a0xkvZwsnwPbTSb+WuA11h+SUl3E1dhw="; + }) + (pkgs.fetchurl { + url = "https://esawebb.org/media/archives/images/publicationtiff10k/weic2415a.tif"; + hash = "sha256-onBy7cPoUpDuzQStbY2E+qmlGgSLXPwFCLX53ukAb4c="; + }) + (pkgs.fetchurl { + url = "https://esawebb.org/media/archives/images/publicationtiff10k/weic2330a.tif"; + hash = "sha256-nn0ZtjZIrPcpj3YcLTsrL7XiXvyh3QYgCSmdDMD+3OM="; + }) + (pkgs.fetchurl { + url = "https://esawebb.org/media/archives/images/original/weic2426a.tif"; + hash = "sha256-EDnfPn3GE9jt6XPqiGInP7E2F3Az7d25NqATSWltDv0="; + }) + (pkgs.fetchurl { + url = "https://esawebb.org/media/archives/images/original/weic2503a.tif"; + hash = "sha256-3/RX6RQp8naELcgReHPd5/zhJkoCjnA10w5BEnNo+qI="; + }) + (pkgs.fetchurl { + url = "https://esawebb.org/media/archives/images/original/weic2506a.tif"; + hash = "sha256-aDld0aoY1owRxDVf7Jcyw71TH42M1foYotxn2thyFYw="; + }) + (pkgs.fetchurl { + url = "https://esawebb.org/media/archives/images/original/weic2514a.tif"; + hash = "sha256-jTi1G1Ofo5xsF6ggrbtYJHxqLaCQ7edM5B3uORiVQtg="; + }) + (pkgs.fetchurl { + url = "https://esawebb.org/media/archives/images/original/weic2425c.tif"; + hash = "sha256-oaEOexSJHEGj090dJF3ct5HAoR+Y5gRiPrUlxdvnTRo="; + }) + ]; + + dontUnpack = true; + + buildInputs = [ pkgs.imagemagick ]; + buildPhase = '' + runHook preBuild + + typeset sources=($srcs) + + mkdir -p $out + magick ''${sources[0]} -crop 10000x5625+0+79 +repage -define jpeg:extent=10MB $out/carinanebula3.jpeg + magick ''${sources[1]} -crop 6716x3778+329+80 +repage -define jpeg:extent=10MB $out/pillarsofcreation_composite.jpeg + magick ''${sources[2]} -crop 10000x5625+0+79 +repage -define jpeg:extent=10MB $out/weic2212a.jpeg + magick ''${sources[3]} -crop 7650x4302+1166+389 +repage -define jpeg:extent=10MB $out/weic2415a.jpeg + magick ''${sources[4]} -crop 8732x4912+0+434 +repage -define jpeg:extent=10MB $out/weic2330a.jpeg + magick ''${sources[5]} -crop 5302x2982+636+0 +repage -define jpeg:extent=10MB $out/weic2426a.jpeg + magick ''${sources[6]} -crop 4328x2434+0+906 +repage -define jpeg:extent=10MB $out/weic2503a.jpeg + magick ''${sources[7]} -crop 4152x2335+0+666 +repage -define jpeg:extent=10MB $out/weic2506a.jpeg + magick ''${sources[8]} -crop 4320x2430+0+0 +repage -define jpeg:extent=10MB $out/weic2514a.jpeg + magick ''${sources[9]} -crop 5863x3298+0+477 +repage -define jpeg:extent=10MB $out/weic2425c.jpeg + + runHook postBuild + ''; + }); }; }; }; diff --git a/accounts/gkleen@sif/shell/quickshell-plugins/CMakeLists.txt b/accounts/gkleen@sif/shell/quickshell-plugins/CMakeLists.txt index aa363c4c..2123ed35 100644 --- a/accounts/gkleen@sif/shell/quickshell-plugins/CMakeLists.txt +++ b/accounts/gkleen@sif/shell/quickshell-plugins/CMakeLists.txt @@ -104,6 +104,7 @@ qt6_add_qml_module(customplugin target_sources(customplugin PRIVATE Chrono.cpp Chrono.hpp + FileSelector.cpp FileSelector.hpp ) target_compile_features(customplugin PUBLIC cxx_std_26) diff --git a/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp b/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp index 4d06007d..04080187 100644 --- a/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp +++ b/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp @@ -1,11 +1,12 @@ #pragma once +#include + #include #include #include #include -#include class Chrono : public QObject { Q_OBJECT; diff --git a/accounts/gkleen@sif/shell/quickshell-plugins/FileSelector.cpp b/accounts/gkleen@sif/shell/quickshell-plugins/FileSelector.cpp new file mode 100644 index 00000000..3a0537b6 --- /dev/null +++ b/accounts/gkleen@sif/shell/quickshell-plugins/FileSelector.cpp @@ -0,0 +1,99 @@ +#include "FileSelector.hpp" + +#include +#include +#include +#include + +#include +#include + +namespace fs = std::filesystem; + +FileSelector::FileSelector(QObject* parent): QObject(parent) { + QObject::connect(&this->timer, &QTimer::timeout, this, &FileSelector::onTimeout); +} + +QString FileSelector::directory() const { + return QString::fromStdString(this->mDirectory->string()); +} +void FileSelector::setDirectory(QString directory) { + this->mDirectory = directory.toStdString(); + if (this->mDirectory && this->mEpoch) + this->update(); + emit this->directoryChanged(); +} + +unsigned int FileSelector::epoch() const { + return std::chrono::duration_cast(*this->mEpoch).count(); +} +void FileSelector::setEpoch(unsigned int epoch) { + this->mEpoch = std::chrono::milliseconds{epoch}; + if (this->mDirectory && this->mEpoch) + this->update(); + emit this->epochChanged(); +} + +QString FileSelector::seed() const { + return this->mSeed; +} +void FileSelector::setSeed(QString seed) { + this->mSeed = seed; + emit this->seedChanged(); +} + +QString FileSelector::selected() const { + if (!this->mDirectory || !this->mEpoch) + return QString(); + + std::vector shuffled(this->mFiles.begin(), this->mFiles.end()); + std::sort(shuffled.begin(), shuffled.end()); + + auto currentTime = std::chrono::system_clock::now(); + uint64_t currentEpoch = currentTime.time_since_epoch() / *this->mEpoch; + std::chrono::milliseconds timeInEpoch = std::chrono::duration_cast(currentTime.time_since_epoch()) % *this->mEpoch; + + std::ostringstream seed; + seed << this->mSeed.size() << ";" << this->mSeed.toStdString() << ";"; + seed << *this->mEpoch << ";"; + seed << currentEpoch << ";"; + seed << this->mDirectory->string().size() << ";" << *this->mDirectory << ";"; + seed << this->mFiles.size() << ";"; + for (const fs::path& p: this->mFiles) + seed << p.string().size() << ";" << p << ";"; + + std::vector v; + v.reserve(seed.str().size()); + for (const char& c: seed.str()) + v.push_back(c); + + std::seed_seq engine_seed(v.begin(), v.end()); + std::mt19937 g(engine_seed); + std::shuffle(shuffled.begin(), shuffled.end(), g); + + std::vector::size_type ix = shuffled.size() * timeInEpoch / *this->mEpoch; + return QString::fromStdString((*this->mDirectory / shuffled[ix]).string()); +} + +void FileSelector::onTimeout() { + if (!this->mFiles.size()) + return; + + auto currentTime = std::chrono::system_clock::now(); + uint64_t currentMinorEpoch = currentTime.time_since_epoch() / (*this->mEpoch / this->mFiles.size()); + auto nextTime = std::chrono::time_point((2 * currentMinorEpoch + 3) * (*this->mEpoch / (this->mFiles.size() * 2))); + this->timer.start(std::chrono::duration_cast(nextTime - currentTime).count()); + + emit this->selectedChanged(); +} + +void FileSelector::update() { + this->mFiles = std::set{}; + for (const fs::directory_entry& entry: + fs::recursive_directory_iterator(*this->mDirectory, fs::directory_options::follow_directory_symlink)) + { + this->mFiles.insert(fs::relative(entry, *this->mDirectory)); + } + + this->onTimeout(); +} diff --git a/accounts/gkleen@sif/shell/quickshell-plugins/FileSelector.hpp b/accounts/gkleen@sif/shell/quickshell-plugins/FileSelector.hpp new file mode 100644 index 00000000..72c4f2a7 --- /dev/null +++ b/accounts/gkleen@sif/shell/quickshell-plugins/FileSelector.hpp @@ -0,0 +1,52 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include + +#include + +class FileSelector : public QObject { + Q_OBJECT; + Q_PROPERTY(QString directory READ directory WRITE setDirectory NOTIFY directoryChanged REQUIRED); + Q_PROPERTY(unsigned int epoch READ epoch WRITE setEpoch NOTIFY epochChanged REQUIRED); + Q_PROPERTY(QString seed READ seed WRITE setSeed NOTIFY seedChanged); + Q_PROPERTY(QString selected READ selected NOTIFY selectedChanged); + QML_ELEMENT; + +public: + explicit FileSelector(QObject* parent = nullptr); + + QString directory() const; + void setDirectory(QString directory); + + unsigned int epoch() const; + void setEpoch(unsigned int epoch); + + QString seed() const; + void setSeed(QString seed); + + QString selected() const; + +signals: + void directoryChanged(); + void epochChanged(); + void seedChanged(); + void selectedChanged(); + +private slots: + void onTimeout(); + +private: + std::optional mDirectory; + std::optional mEpoch; + std::set mFiles; + QString mSeed; + QTimer timer; + + void update(); +}; diff --git a/accounts/gkleen@sif/shell/quickshell/Services/WallpaperSelector.qml b/accounts/gkleen@sif/shell/quickshell/Services/WallpaperSelector.qml new file mode 100644 index 00000000..3c524955 --- /dev/null +++ b/accounts/gkleen@sif/shell/quickshell/Services/WallpaperSelector.qml @@ -0,0 +1,8 @@ +import Custom as Custom + +Custom.FileSelector { + id: root + + directory: @wallpapers@ + epoch: 72000000 +} diff --git a/accounts/gkleen@sif/shell/quickshell/WallpaperBackground.qml b/accounts/gkleen@sif/shell/quickshell/WallpaperBackground.qml new file mode 100644 index 00000000..de31915f --- /dev/null +++ b/accounts/gkleen@sif/shell/quickshell/WallpaperBackground.qml @@ -0,0 +1,85 @@ +import QtQuick +import Quickshell +import qs.Services + +Item { + id: root + + anchors.fill: parent + + required property string screen + + property Img current: one + property string source: selector.selected + + WallpaperSelector { + id: selector + seed: screen + } + + onSourceChanged: { + if (!source) + current = null; + else if (current === one) + two.update() + else + one.update() + } + + Img { id: one } + Img { id: two } + + component Img: Image { + id: img + + function update() { + source = root.source || "" + } + + anchors.fill: parent + fillMode: Image.PreserveAspectCrop + smooth: true + asynchronous: true + cache: false + + opacity: 0 + + onStatusChanged: { + if (status === Image.Ready) { + root.current = this + } + } + + states: State { + name: "visible" + when: root.current === img + + PropertyChanges { + img.opacity: 1 + } + StateChangeScript { + name: "unloadOther" + script: { + if (img === one) + two.source = "" + if (img === two) + one.source = "" + } + } + } + + transitions: Transition { + SequentialAnimation { + NumberAnimation { + target: img + properties: "opacity" + duration: 5000 + easing.type: Easing.OutCubic + } + ScriptAction { + scriptName: "unloadOther" + } + } + } + } +} diff --git a/accounts/gkleen@sif/shell/quickshell/shell.qml b/accounts/gkleen@sif/shell/quickshell/shell.qml index 4934cd4d..2ddecad9 100644 --- a/accounts/gkleen@sif/shell/quickshell/shell.qml +++ b/accounts/gkleen@sif/shell/quickshell/shell.qml @@ -1,6 +1,7 @@ //@ pragma UseQApplication import Quickshell +import Quickshell.Wayland ShellRoot { settings.watchFiles: false @@ -13,9 +14,27 @@ ShellRoot { required property var modelData - Bar { - id: bar + PanelWindow { + id: bgWindow + + screen: screenScope.modelData + + WlrLayershell.layer: WlrLayer.Background + WlrLayershell.exclusionMode: ExclusionMode.Ignore + + anchors.top: true + anchors.bottom: true + anchors.left: true + anchors.right: true + color: "black" + + WallpaperBackground { + screen: bgWindow.screen.name + } + } + + Bar { screen: screenScope.modelData } } -- cgit v1.2.3