mirror of
https://github.com/hyprwm/hyprpaper.git
synced 2024-11-16 22:25:59 +01:00
added unload
This commit is contained in:
parent
59956ce32a
commit
8a7df4675a
8 changed files with 64 additions and 1 deletions
|
@ -65,6 +65,46 @@ bool CHyprpaper::isPreloaded(const std::string& path) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CHyprpaper::unloadWallpaper(const std::string& path) {
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
for (auto& [ewp, cls] : m_mWallpaperTargets) {
|
||||||
|
if (ewp == path) {
|
||||||
|
// found
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
Debug::log(LOG, "Cannot unload a target that was not loaded!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// clean buffers
|
||||||
|
for (auto it = m_vBuffers.begin(); it != m_vBuffers.end(); it++) {
|
||||||
|
|
||||||
|
if (it->get()->pTarget->m_szPath != path)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
|
||||||
|
const auto PRELOADPATH = it->get()->name;
|
||||||
|
|
||||||
|
Debug::log(LOG, "Unloading target %s, preload path %s", path.c_str(), PRELOADPATH.c_str());
|
||||||
|
|
||||||
|
std::filesystem::remove(PRELOADPATH);
|
||||||
|
|
||||||
|
destroyBuffer(it->get());
|
||||||
|
|
||||||
|
it = m_vBuffers.erase(it);
|
||||||
|
|
||||||
|
if (it == m_vBuffers.end())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_mWallpaperTargets.erase(path); // will free the cairo surface
|
||||||
|
}
|
||||||
|
|
||||||
void CHyprpaper::preloadAllWallpapersFromConfig() {
|
void CHyprpaper::preloadAllWallpapersFromConfig() {
|
||||||
if (g_pConfigManager->m_dRequestedPreloads.empty())
|
if (g_pConfigManager->m_dRequestedPreloads.empty())
|
||||||
return;
|
return;
|
||||||
|
@ -320,6 +360,7 @@ void CHyprpaper::createBuffer(SPoolBuffer* pBuffer, int32_t w, int32_t h, uint32
|
||||||
pBuffer->surface = cairo_image_surface_create_for_data((unsigned char*)DATA, CAIRO_FORMAT_ARGB32, w, h, STRIDE);
|
pBuffer->surface = cairo_image_surface_create_for_data((unsigned char*)DATA, CAIRO_FORMAT_ARGB32, w, h, STRIDE);
|
||||||
pBuffer->cairo = cairo_create(pBuffer->surface);
|
pBuffer->cairo = cairo_create(pBuffer->surface);
|
||||||
pBuffer->pixelSize = Vector2D(w, h);
|
pBuffer->pixelSize = Vector2D(w, h);
|
||||||
|
pBuffer->name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHyprpaper::destroyBuffer(SPoolBuffer* pBuffer) {
|
void CHyprpaper::destroyBuffer(SPoolBuffer* pBuffer) {
|
||||||
|
|
|
@ -44,6 +44,7 @@ public:
|
||||||
void recheckMonitor(SMonitor*);
|
void recheckMonitor(SMonitor*);
|
||||||
void ensurePoolBuffersPresent();
|
void ensurePoolBuffersPresent();
|
||||||
SPoolBuffer* getPoolBuffer(SMonitor*, CWallpaperTarget*);
|
SPoolBuffer* getPoolBuffer(SMonitor*, CWallpaperTarget*);
|
||||||
|
void unloadWallpaper(const std::string&);
|
||||||
|
|
||||||
std::mutex m_mtTickMutex;
|
std::mutex m_mtTickMutex;
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -93,6 +93,8 @@ void CConfigManager::parseKeyword(const std::string& COMMAND, const std::string&
|
||||||
handleWallpaper(COMMAND, VALUE);
|
handleWallpaper(COMMAND, VALUE);
|
||||||
else if (COMMAND == "preload")
|
else if (COMMAND == "preload")
|
||||||
handlePreload(COMMAND, VALUE);
|
handlePreload(COMMAND, VALUE);
|
||||||
|
else if (COMMAND == "unload")
|
||||||
|
handleUnload(COMMAND, VALUE);
|
||||||
else
|
else
|
||||||
parseError = "unknown keyword " + COMMAND;
|
parseError = "unknown keyword " + COMMAND;
|
||||||
}
|
}
|
||||||
|
@ -140,3 +142,14 @@ void CConfigManager::handlePreload(const std::string& COMMAND, const std::string
|
||||||
|
|
||||||
m_dRequestedPreloads.emplace_back(WALLPAPER);
|
m_dRequestedPreloads.emplace_back(WALLPAPER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CConfigManager::handleUnload(const std::string& COMMAND, const std::string& VALUE) {
|
||||||
|
auto WALLPAPER = VALUE;
|
||||||
|
|
||||||
|
if (WALLPAPER[0] == '~') {
|
||||||
|
static const char* const ENVHOME = getenv("HOME");
|
||||||
|
WALLPAPER = std::string(ENVHOME) + WALLPAPER.substr(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_pHyprpaper->unloadWallpaper(WALLPAPER);
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ private:
|
||||||
|
|
||||||
void handleWallpaper(const std::string&, const std::string&);
|
void handleWallpaper(const std::string&, const std::string&);
|
||||||
void handlePreload(const std::string&, const std::string&);
|
void handlePreload(const std::string&, const std::string&);
|
||||||
|
void handleUnload(const std::string&, const std::string&);
|
||||||
|
|
||||||
friend class CIPCSocket;
|
friend class CIPCSocket;
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,6 +10,7 @@ struct SPoolBuffer {
|
||||||
cairo_t* cairo = nullptr;
|
cairo_t* cairo = nullptr;
|
||||||
void* data = nullptr;
|
void* data = nullptr;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
std::string name = "";
|
||||||
|
|
||||||
CWallpaperTarget* pTarget = nullptr;
|
CWallpaperTarget* pTarget = nullptr;
|
||||||
Vector2D pixelSize;
|
Vector2D pixelSize;
|
||||||
|
|
|
@ -99,7 +99,7 @@ void CIPCSocket::mainThreadParseRequest() {
|
||||||
Debug::log(LOG, "Received a request: %s", copy.c_str());
|
Debug::log(LOG, "Received a request: %s", copy.c_str());
|
||||||
|
|
||||||
// parse
|
// parse
|
||||||
if (copy.find("wallpaper") == 0 || copy.find("preload") == 0) {
|
if (copy.find("wallpaper") == 0 || copy.find("preload") == 0 || copy.find("unload") == 0) {
|
||||||
g_pConfigManager->parseError = ""; // reset parse error
|
g_pConfigManager->parseError = ""; // reset parse error
|
||||||
|
|
||||||
g_pConfigManager->parseKeyword(copy.substr(0, copy.find_first_of(' ')), copy.substr(copy.find_first_of(' ') + 1));
|
g_pConfigManager->parseKeyword(copy.substr(0, copy.find_first_of(' ')), copy.substr(copy.find_first_of(' ') + 1));
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
#include "WallpaperTarget.hpp"
|
#include "WallpaperTarget.hpp"
|
||||||
|
|
||||||
|
CWallpaperTarget::~CWallpaperTarget() {
|
||||||
|
cairo_surface_destroy(m_pCairoSurface);
|
||||||
|
}
|
||||||
|
|
||||||
void CWallpaperTarget::create(const std::string& path) {
|
void CWallpaperTarget::create(const std::string& path) {
|
||||||
m_szPath = path;
|
m_szPath = path;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
class CWallpaperTarget {
|
class CWallpaperTarget {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
~CWallpaperTarget();
|
||||||
|
|
||||||
void create(const std::string& path);
|
void create(const std::string& path);
|
||||||
void render();
|
void render();
|
||||||
|
|
Loading…
Reference in a new issue