clean old preloads

This commit is contained in:
vaxerski 2022-07-17 13:59:43 +02:00
parent 2c7927aa5a
commit 3de17d1636
4 changed files with 30 additions and 2 deletions

View file

@ -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)

View file

@ -3,6 +3,9 @@
CHyprpaper::CHyprpaper() { }
void CHyprpaper::init() {
removeOldHyprpaperImages();
g_pConfigManager = std::make_unique<CConfigManager>();
g_pIPCSocket = std::make_unique<CIPCSocket>();
@ -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)

View file

@ -28,6 +28,7 @@ public:
std::vector<std::unique_ptr<SPoolBuffer>> m_vBuffers;
std::vector<std::unique_ptr<SMonitor>> m_vMonitors;
void removeOldHyprpaperImages();
void preloadAllWallpapersFromConfig();
void recheckAllMonitors();
void ensureMonitorHasActiveWallpaper(SMonitor*);

View file

@ -41,4 +41,4 @@ extern "C" {
#include <algorithm>
#include <filesystem>
#include <thread>
#include <unordered_map>
#include <unordered_map>