-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add directory wallpaper support (and subsequently shuffling) and deferred preloading #237
base: main
Are you sure you want to change the base?
Conversation
- Add support for selecting random wallpapers from directories - Add defer_preload option to reduce memory usage - Update README with new features - Improve path handling with tilde expansion
- Replace <random> with helpers/RandomGenerator.hpp for consistent random number generation - Improve buffer target handling by using path directly instead of dereferencing wallpaper target - Simplify lambda capture in ensurePoolBuffersPresent() by using reference capture
Introduces a new ImagePicker helper that consolidates duplicate wallpaper selection logic from Hyprpaper.cpp and ConfigManager.cpp into a single reusable function. - Add new ImagePicker.{hpp,cpp} with getRandomImageFromDirectory() helper - Function handles directory scanning, file extension validation, and random selection - Supports excluding current wallpaper to avoid duplicate selections - Updates both wallpaper loading code paths to use the new helper - Uses std::shuffle instead of random index for better randomization This change improves code maintainability by removing duplicate logic and centralizing image selection behavior in a single location.
src/helpers/ImagePicker.cpp
Outdated
std::string getRandomImageFromDirectory(const std::string &dirPath, const std::string &ignore) { | ||
std::vector<std::filesystem::path> images; | ||
for (const auto &entry : std::filesystem::directory_iterator(dirPath)) { | ||
if (entry.is_regular_file()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer guards
if (!entry.isregular())
continue;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙇
src/helpers/ImagePicker.cpp
Outdated
for (const auto &entry : std::filesystem::directory_iterator(dirPath)) { | ||
if (entry.is_regular_file()) { | ||
auto ext = entry.path().extension().string(); | ||
if ((ext == ".png" || ext == ".jpg" || ext == ".jpeg" || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a compromise... and a poor one imo. hyprgraphics uses libmagic to try to load images.
Maybe you want to add a fn to hyprgraphics that says if an image is loadable by it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this, candidly I implemented it due to me just wanting to get my fork working and it's been fine as-is, but I recognize that we need something more robust.
src/helpers/ImagePicker.cpp
Outdated
auto ext = entry.path().extension().string(); | ||
if ((ext == ".png" || ext == ".jpg" || ext == ".jpeg" || | ||
ext == ".webp" || ext == ".jxl")) { | ||
if (ignore.empty() || entry.path().string() != ignore) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no {}
return ""; | ||
} | ||
|
||
std::shuffle(images.begin(), images.end(), CRandomGenerator::get().getGenerator()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? Why not just images.at(randomInt)
} | ||
|
||
if (!g_pHyprpaper->isPreloaded(WALLPAPER)) { | ||
if (std::any_cast<Hyprlang::INT>(g_pConfigManager->config->getConfigValue("defer_preload"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 509 in f827dc3
static auto PRENDERSPLASH = Hyprlang::CSimpleConfigValue<Hyprlang::INT>(g_pConfigManager->config.get(), "splash"); |
Flattened nested conditionals into guard clauses for better readability.
A great addition would be the option to set the currently loaded wallpaper as "default wallpaper", so that the change is persistent even after restart. |
I'm happy to take a stab at that! Bear with me as I'm travelling etc. soon but I hope to pick up the requisite knowledge needed to get this through the door in that time.
On a personal level I'm fine with having more potential configurations, I'll leave it to the Hypr maintainers if they have opposing opinions 🫡 |
You're right, I'm sorry for hijacking this thread. I'll post a feature request. |
Hi all :)
This PR adds two new features:
defer_preload
config option to reduce memory usageAdditional improvements:
Feel free to leave feedback or lampoon as it's obviously not a small change, I saw #194 and wanted to do something about it. I'll make revisions as per feedback, candidly I'm unfamiliar with the Hypr suite on the dev end (but am a very grateful user!) 🙇