mirror of
https://github.com/hyprwm/hyprpaper.git
synced 2024-11-16 22:25:59 +01:00
added contain:
This commit is contained in:
parent
5eb087d338
commit
036bf93bf4
3 changed files with 41 additions and 7 deletions
|
@ -250,8 +250,6 @@ void CHyprpaper::clearWallpaperFromMonitor(const std::string& monname) {
|
|||
PMONITOR->wantsReload = false;
|
||||
PMONITOR->initialized = false;
|
||||
PMONITOR->readyForLS = true;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -386,6 +384,7 @@ SPoolBuffer* CHyprpaper::getPoolBuffer(SMonitor* pMonitor, CWallpaperTarget* pWa
|
|||
|
||||
void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) {
|
||||
const auto PWALLPAPERTARGET = m_mMonitorActiveWallpaperTargets[pMonitor];
|
||||
const auto CONTAIN = m_mMonitorWallpaperRenderData[pMonitor->name].contain;
|
||||
|
||||
if (!PWALLPAPERTARGET) {
|
||||
Debug::log(CRIT, "wallpaper target null in render??");
|
||||
|
@ -412,19 +411,41 @@ void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) {
|
|||
cairo_paint(PCAIRO);
|
||||
cairo_restore(PCAIRO);
|
||||
|
||||
if (CONTAIN) {
|
||||
cairo_set_source_rgb(PCAIRO, 0, 0, 0);
|
||||
cairo_rectangle(PCAIRO, 0, 0, pMonitor->size.x * pMonitor->scale, pMonitor->size.y * pMonitor->scale);
|
||||
|
||||
cairo_fill(PCAIRO);
|
||||
|
||||
cairo_surface_flush(PBUFFER->surface);
|
||||
}
|
||||
|
||||
// get scale
|
||||
// we always do cover
|
||||
float scale;
|
||||
Vector2D origin;
|
||||
if (pMonitor->size.x / pMonitor->size.y > PWALLPAPERTARGET->m_vSize.x / PWALLPAPERTARGET->m_vSize.y) {
|
||||
scale = pMonitor->size.x * pMonitor->scale / PWALLPAPERTARGET->m_vSize.x;
|
||||
|
||||
origin.y = - (PWALLPAPERTARGET->m_vSize.y * scale - pMonitor->size.y * pMonitor->scale) / 2.f / scale;
|
||||
if (!CONTAIN) {
|
||||
if (pMonitor->size.x / pMonitor->size.y > PWALLPAPERTARGET->m_vSize.x / PWALLPAPERTARGET->m_vSize.y) {
|
||||
scale = pMonitor->size.x * pMonitor->scale / PWALLPAPERTARGET->m_vSize.x;
|
||||
|
||||
origin.y = -(PWALLPAPERTARGET->m_vSize.y * scale - pMonitor->size.y * pMonitor->scale) / 2.f / scale;
|
||||
|
||||
} else {
|
||||
scale = pMonitor->size.y * pMonitor->scale / PWALLPAPERTARGET->m_vSize.y;
|
||||
|
||||
origin.x = -(PWALLPAPERTARGET->m_vSize.x * scale - pMonitor->size.x * pMonitor->scale) / 2.f / scale;
|
||||
}
|
||||
} else {
|
||||
scale = pMonitor->size.y * pMonitor->scale / PWALLPAPERTARGET->m_vSize.y;
|
||||
if (pMonitor->size.x / pMonitor->size.y > PWALLPAPERTARGET->m_vSize.x / PWALLPAPERTARGET->m_vSize.y) {
|
||||
scale = (pMonitor->size.y * pMonitor->scale) / PWALLPAPERTARGET->m_vSize.y;
|
||||
|
||||
origin.x = - (PWALLPAPERTARGET->m_vSize.x * scale - pMonitor->size.x * pMonitor->scale) / 2.f / scale;
|
||||
origin.x = (pMonitor->size.x * pMonitor->scale - PWALLPAPERTARGET->m_vSize.x * scale);
|
||||
} else {
|
||||
scale = (pMonitor->size.x * pMonitor->scale) / PWALLPAPERTARGET->m_vSize.x;
|
||||
|
||||
origin.y = (pMonitor->size.y * pMonitor->scale - PWALLPAPERTARGET->m_vSize.y * scale);
|
||||
}
|
||||
}
|
||||
|
||||
Debug::log(LOG, "Image data for %s: %s at [%.2f, %.2f], scale: %.2f (original image size: [%i, %i])", pMonitor->name.c_str(), PWALLPAPERTARGET->m_szPath.c_str(), origin.x, origin.y, scale, (int)PWALLPAPERTARGET->m_vSize.x, (int)PWALLPAPERTARGET->m_vSize.y);
|
||||
|
|
|
@ -9,6 +9,10 @@
|
|||
#include "ipc/Socket.hpp"
|
||||
#include <mutex>
|
||||
|
||||
struct SWallpaperRenderData {
|
||||
bool contain = false;
|
||||
};
|
||||
|
||||
class CHyprpaper {
|
||||
public:
|
||||
// important
|
||||
|
@ -24,6 +28,7 @@ public:
|
|||
|
||||
std::unordered_map<std::string, CWallpaperTarget> m_mWallpaperTargets;
|
||||
std::unordered_map<std::string, std::string> m_mMonitorActiveWallpapers;
|
||||
std::unordered_map<std::string, SWallpaperRenderData> m_mMonitorWallpaperRenderData;
|
||||
std::unordered_map<SMonitor*, CWallpaperTarget*> m_mMonitorActiveWallpaperTargets;
|
||||
std::vector<std::unique_ptr<SPoolBuffer>> m_vBuffers;
|
||||
std::vector<std::unique_ptr<SMonitor>> m_vMonitors;
|
||||
|
|
|
@ -110,11 +110,18 @@ void CConfigManager::handleWallpaper(const std::string& COMMAND, const std::stri
|
|||
auto MONITOR = VALUE.substr(0, VALUE.find_first_of(','));
|
||||
auto WALLPAPER = VALUE.substr(VALUE.find_first_of(',') + 1);
|
||||
|
||||
bool contain = false;
|
||||
|
||||
if (WALLPAPER[0] == '~') {
|
||||
static const char* const ENVHOME = getenv("HOME");
|
||||
WALLPAPER = std::string(ENVHOME) + WALLPAPER.substr(1);
|
||||
}
|
||||
|
||||
if (WALLPAPER.find("contain:") == 0) {
|
||||
WALLPAPER = WALLPAPER.substr(8);
|
||||
contain = true;
|
||||
}
|
||||
|
||||
if (!std::filesystem::exists(WALLPAPER)) {
|
||||
parseError = "wallpaper failed (no such file)";
|
||||
return;
|
||||
|
@ -127,6 +134,7 @@ void CConfigManager::handleWallpaper(const std::string& COMMAND, const std::stri
|
|||
|
||||
g_pHyprpaper->clearWallpaperFromMonitor(MONITOR);
|
||||
g_pHyprpaper->m_mMonitorActiveWallpapers[MONITOR] = WALLPAPER;
|
||||
g_pHyprpaper->m_mMonitorWallpaperRenderData[MONITOR].contain = contain;
|
||||
}
|
||||
|
||||
void CConfigManager::handlePreload(const std::string& COMMAND, const std::string& VALUE) {
|
||||
|
|
Loading…
Reference in a new issue