diff --git a/CMakeLists.txt b/CMakeLists.txt index 57a9833..fb2209c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ execute_process( # include_directories(.) -add_compile_options(-std=c++20 -DWLR_USE_UNSTABLE ) +add_compile_options(-std=c++23 -DWLR_USE_UNSTABLE ) add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-value -Wno-missing-field-initializers -Wno-narrowing) find_package(Threads REQUIRED) diff --git a/src/Hyprpaper.cpp b/src/Hyprpaper.cpp index bd73dda..768eaeb 100644 --- a/src/Hyprpaper.cpp +++ b/src/Hyprpaper.cpp @@ -3,6 +3,9 @@ CHyprpaper::CHyprpaper() { } void CHyprpaper::init() { + + removeOldHyprpaperImages(); + g_pConfigManager = std::make_unique(); g_pIPCSocket = std::make_unique(); @@ -108,6 +111,30 @@ void CHyprpaper::recheckMonitor(SMonitor* pMonitor) { } } +void CHyprpaper::removeOldHyprpaperImages() { + int cleaned = 0; + uint64_t memoryFreed = 0; + + for (const auto& entry : std::filesystem::directory_iterator(std::string(getenv("XDG_RUNTIME_DIR")))) { + if (entry.is_directory()) + continue; + + const auto FILENAME = entry.path().filename().string(); + + if (FILENAME.contains(".hyprpaper_")) { + // unlink it + + memoryFreed += entry.file_size(); + std::filesystem::remove(FILENAME); + cleaned++; + } + } + + if (cleaned != 0) { + Debug::log(LOG, "Cleaned old hyprpaper preloads (%i), removing %.1fMB", cleaned, ((float)memoryFreed) / 1000000.f); + } +} + SMonitor* CHyprpaper::getMonitorFromName(const std::string& monname) { for (auto& m : m_vMonitors) { if (m->name == monname) diff --git a/src/Hyprpaper.hpp b/src/Hyprpaper.hpp index 6c458ed..04d71f2 100644 --- a/src/Hyprpaper.hpp +++ b/src/Hyprpaper.hpp @@ -28,6 +28,7 @@ public: std::vector> m_vBuffers; std::vector> m_vMonitors; + void removeOldHyprpaperImages(); void preloadAllWallpapersFromConfig(); void recheckAllMonitors(); void ensureMonitorHasActiveWallpaper(SMonitor*); diff --git a/src/includes.hpp b/src/includes.hpp index 8bcf789..9d6fb60 100644 --- a/src/includes.hpp +++ b/src/includes.hpp @@ -41,4 +41,4 @@ extern "C" { #include #include #include -#include \ No newline at end of file +#include