mirror of
https://github.com/hyprwm/hyprpaper.git
synced 2024-12-22 12:19:49 +01:00
parent
9e2a2670e1
commit
c022069390
4 changed files with 62 additions and 36 deletions
|
@ -15,11 +15,6 @@ void CHyprpaper::init() {
|
||||||
|
|
||||||
removeOldHyprpaperImages();
|
removeOldHyprpaperImages();
|
||||||
|
|
||||||
g_pConfigManager = std::make_unique<CConfigManager>();
|
|
||||||
g_pIPCSocket = std::make_unique<CIPCSocket>();
|
|
||||||
|
|
||||||
g_pConfigManager->parse();
|
|
||||||
|
|
||||||
m_sDisplay = (wl_display*)wl_display_connect(nullptr);
|
m_sDisplay = (wl_display*)wl_display_connect(nullptr);
|
||||||
|
|
||||||
if (!m_sDisplay) {
|
if (!m_sDisplay) {
|
||||||
|
@ -27,25 +22,36 @@ void CHyprpaper::init() {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// run
|
||||||
|
wl_registry* registry = wl_display_get_registry(m_sDisplay);
|
||||||
|
wl_registry_add_listener(registry, &Events::registryListener, nullptr);
|
||||||
|
|
||||||
|
wl_display_roundtrip(m_sDisplay);
|
||||||
|
|
||||||
|
while (m_vMonitors.size() < 1 || m_vMonitors[0]->name.empty()) {
|
||||||
|
wl_display_dispatch(m_sDisplay);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_pConfigManager = std::make_unique<CConfigManager>();
|
||||||
|
g_pIPCSocket = std::make_unique<CIPCSocket>();
|
||||||
|
|
||||||
|
g_pConfigManager->parse();
|
||||||
|
|
||||||
preloadAllWallpapersFromConfig();
|
preloadAllWallpapersFromConfig();
|
||||||
|
|
||||||
if (std::any_cast<Hyprlang::INT>(g_pConfigManager->config->getConfigValue("ipc")))
|
if (std::any_cast<Hyprlang::INT>(g_pConfigManager->config->getConfigValue("ipc")))
|
||||||
g_pIPCSocket->initialize();
|
g_pIPCSocket->initialize();
|
||||||
|
|
||||||
// run
|
do {
|
||||||
wl_registry* registry = wl_display_get_registry(m_sDisplay);
|
|
||||||
wl_registry_add_listener(registry, &Events::registryListener, nullptr);
|
|
||||||
|
|
||||||
while (wl_display_dispatch(m_sDisplay) != -1) {
|
|
||||||
std::lock_guard<std::mutex> lg(m_mtTickMutex);
|
std::lock_guard<std::mutex> lg(m_mtTickMutex);
|
||||||
tick(true);
|
tick(true);
|
||||||
}
|
} while (wl_display_dispatch(m_sDisplay) != -1);
|
||||||
|
|
||||||
unlockSingleInstance();
|
unlockSingleInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHyprpaper::tick(bool force) {
|
void CHyprpaper::tick(bool force) {
|
||||||
bool reload = g_pIPCSocket->mainThreadParseRequest();
|
bool reload = g_pIPCSocket && g_pIPCSocket->mainThreadParseRequest();
|
||||||
|
|
||||||
if (!reload && !force)
|
if (!reload && !force)
|
||||||
return;
|
return;
|
||||||
|
@ -453,6 +459,10 @@ SPoolBuffer* CHyprpaper::getPoolBuffer(SMonitor* pMonitor, CWallpaperTarget* pWa
|
||||||
void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) {
|
void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) {
|
||||||
static auto* const PRENDERSPLASH = reinterpret_cast<Hyprlang::INT* const*>(g_pConfigManager->config->getConfigValuePtr("splash")->getDataStaticPtr());
|
static auto* const PRENDERSPLASH = reinterpret_cast<Hyprlang::INT* const*>(g_pConfigManager->config->getConfigValuePtr("splash")->getDataStaticPtr());
|
||||||
static auto* const PSPLASHOFFSET = reinterpret_cast<Hyprlang::FLOAT* const*>(g_pConfigManager->config->getConfigValuePtr("splash_offset")->getDataStaticPtr());
|
static auto* const PSPLASHOFFSET = reinterpret_cast<Hyprlang::FLOAT* const*>(g_pConfigManager->config->getConfigValuePtr("splash_offset")->getDataStaticPtr());
|
||||||
|
|
||||||
|
if (!m_mMonitorActiveWallpaperTargets[pMonitor])
|
||||||
|
recheckMonitor(pMonitor);
|
||||||
|
|
||||||
const auto PWALLPAPERTARGET = m_mMonitorActiveWallpaperTargets[pMonitor];
|
const auto PWALLPAPERTARGET = m_mMonitorActiveWallpaperTargets[pMonitor];
|
||||||
const auto CONTAIN = m_mMonitorWallpaperRenderData[pMonitor->name].contain;
|
const auto CONTAIN = m_mMonitorWallpaperRenderData[pMonitor->name].contain;
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,20 @@ static Hyprlang::CParseResult handleWallpaper(const char* C, const char* V) {
|
||||||
g_pHyprpaper->m_mMonitorActiveWallpapers[MONITOR] = WALLPAPER;
|
g_pHyprpaper->m_mMonitorActiveWallpapers[MONITOR] = WALLPAPER;
|
||||||
g_pHyprpaper->m_mMonitorWallpaperRenderData[MONITOR].contain = contain;
|
g_pHyprpaper->m_mMonitorWallpaperRenderData[MONITOR].contain = contain;
|
||||||
|
|
||||||
|
if (MONITOR.empty()) {
|
||||||
|
for (auto& m : g_pHyprpaper->m_vMonitors) {
|
||||||
|
if (!m->hasATarget || m->wildcard) {
|
||||||
|
g_pHyprpaper->clearWallpaperFromMonitor(m->name);
|
||||||
|
g_pHyprpaper->m_mMonitorActiveWallpapers[m->name] = WALLPAPER;
|
||||||
|
g_pHyprpaper->m_mMonitorWallpaperRenderData[m->name].contain = contain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const auto PMON = g_pHyprpaper->getMonitorFromName(MONITOR);
|
||||||
|
if (PMON)
|
||||||
|
PMON->wildcard = false;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,72 +1,73 @@
|
||||||
#include "Events.hpp"
|
#include "Events.hpp"
|
||||||
#include "../Hyprpaper.hpp"
|
#include "../Hyprpaper.hpp"
|
||||||
|
|
||||||
void Events::geometry(void *data, wl_output *output, int32_t x, int32_t y, int32_t width_mm, int32_t height_mm, int32_t subpixel, const char *make, const char *model, int32_t transform) {
|
void Events::geometry(void* data, wl_output* output, int32_t x, int32_t y, int32_t width_mm, int32_t height_mm, int32_t subpixel, const char* make, const char* model, int32_t transform) {
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::mode(void *data, wl_output *output, uint32_t flags, int32_t width, int32_t height, int32_t refresh) {
|
void Events::mode(void* data, wl_output* output, uint32_t flags, int32_t width, int32_t height, int32_t refresh) {
|
||||||
const auto PMONITOR = (SMonitor*)data;
|
const auto PMONITOR = (SMonitor*)data;
|
||||||
|
|
||||||
PMONITOR->size = Vector2D(width, height);
|
PMONITOR->size = Vector2D(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::done(void *data, wl_output *wl_output) {
|
void Events::done(void* data, wl_output* wl_output) {
|
||||||
const auto PMONITOR = (SMonitor*)data;
|
const auto PMONITOR = (SMonitor*)data;
|
||||||
|
|
||||||
PMONITOR->readyForLS = true;
|
PMONITOR->readyForLS = true;
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lg(g_pHyprpaper->m_mtTickMutex);
|
std::lock_guard<std::mutex> lg(g_pHyprpaper->m_mtTickMutex);
|
||||||
g_pHyprpaper->tick(true);
|
if (g_pConfigManager) // don't tick if this is the first roundtrip
|
||||||
|
g_pHyprpaper->tick(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::scale(void *data, wl_output *wl_output, int32_t scale) {
|
void Events::scale(void* data, wl_output* wl_output, int32_t scale) {
|
||||||
const auto PMONITOR = (SMonitor*)data;
|
const auto PMONITOR = (SMonitor*)data;
|
||||||
|
|
||||||
PMONITOR->scale = scale;
|
PMONITOR->scale = scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::name(void *data, wl_output *wl_output, const char *name) {
|
void Events::name(void* data, wl_output* wl_output, const char* name) {
|
||||||
const auto PMONITOR = (SMonitor*)data;
|
const auto PMONITOR = (SMonitor*)data;
|
||||||
|
|
||||||
PMONITOR->name = name;
|
PMONITOR->name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::description(void *data, wl_output *wl_output, const char *description) {
|
void Events::description(void* data, wl_output* wl_output, const char* description) {
|
||||||
const auto PMONITOR = (SMonitor*)data;
|
const auto PMONITOR = (SMonitor*)data;
|
||||||
|
|
||||||
PMONITOR->description = description;
|
PMONITOR->description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::handleCapabilities(void *data, wl_seat *wl_seat, uint32_t capabilities) {
|
void Events::handleCapabilities(void* data, wl_seat* wl_seat, uint32_t capabilities) {
|
||||||
if (capabilities & WL_SEAT_CAPABILITY_POINTER) {
|
if (capabilities & WL_SEAT_CAPABILITY_POINTER) {
|
||||||
wl_pointer_add_listener(wl_seat_get_pointer(wl_seat), &pointerListener, wl_seat);
|
wl_pointer_add_listener(wl_seat_get_pointer(wl_seat), &pointerListener, wl_seat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::handlePointerLeave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface) {
|
void Events::handlePointerLeave(void* data, struct wl_pointer* wl_pointer, uint32_t serial, struct wl_surface* surface) {
|
||||||
// ignored
|
// ignored
|
||||||
wl_surface_commit(surface);
|
wl_surface_commit(surface);
|
||||||
|
|
||||||
g_pHyprpaper->m_pLastMonitor = nullptr;
|
g_pHyprpaper->m_pLastMonitor = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::handlePointerAxis(void *data, wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value) {
|
void Events::handlePointerAxis(void* data, wl_pointer* wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value) {
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::handlePointerMotion(void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
void Events::handlePointerMotion(void* data, struct wl_pointer* wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
||||||
// ignored
|
// ignored
|
||||||
if (g_pHyprpaper->m_pLastMonitor) {
|
if (g_pHyprpaper->m_pLastMonitor) {
|
||||||
wl_surface_commit(g_pHyprpaper->m_pLastMonitor->pCurrentLayerSurface->pSurface);
|
wl_surface_commit(g_pHyprpaper->m_pLastMonitor->pCurrentLayerSurface->pSurface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::handlePointerButton(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t button_state) {
|
void Events::handlePointerButton(void* data, struct wl_pointer* wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t button_state) {
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::handlePointerEnter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
void Events::handlePointerEnter(void* data, struct wl_pointer* wl_pointer, uint32_t serial, struct wl_surface* surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
||||||
for (auto& mon : g_pHyprpaper->m_vMonitors) {
|
for (auto& mon : g_pHyprpaper->m_vMonitors) {
|
||||||
if (mon->pCurrentLayerSurface->pSurface == surface) {
|
if (mon->pCurrentLayerSurface->pSurface == surface) {
|
||||||
g_pHyprpaper->m_pLastMonitor = mon.get();
|
g_pHyprpaper->m_pLastMonitor = mon.get();
|
||||||
|
@ -79,7 +80,7 @@ void Events::handlePointerEnter(void *data, struct wl_pointer *wl_pointer, uint3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::ls_configure(void *data, zwlr_layer_surface_v1 *surface, uint32_t serial, uint32_t width, uint32_t height) {
|
void Events::ls_configure(void* data, zwlr_layer_surface_v1* surface, uint32_t serial, uint32_t width, uint32_t height) {
|
||||||
const auto PLAYERSURFACE = (CLayerSurface*)data;
|
const auto PLAYERSURFACE = (CLayerSurface*)data;
|
||||||
|
|
||||||
PLAYERSURFACE->m_pMonitor->size = Vector2D(width, height);
|
PLAYERSURFACE->m_pMonitor->size = Vector2D(width, height);
|
||||||
|
@ -91,7 +92,7 @@ void Events::ls_configure(void *data, zwlr_layer_surface_v1 *surface, uint32_t s
|
||||||
Debug::log(LOG, "configure for %s", PLAYERSURFACE->m_pMonitor->name.c_str());
|
Debug::log(LOG, "configure for %s", PLAYERSURFACE->m_pMonitor->name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::handleLSClosed(void *data, zwlr_layer_surface_v1 *zwlr_layer_surface_v1) {
|
void Events::handleLSClosed(void* data, zwlr_layer_surface_v1* zwlr_layer_surface_v1) {
|
||||||
const auto PLAYERSURFACE = (CLayerSurface*)data;
|
const auto PLAYERSURFACE = (CLayerSurface*)data;
|
||||||
|
|
||||||
for (auto& m : g_pHyprpaper->m_vMonitors) {
|
for (auto& m : g_pHyprpaper->m_vMonitors) {
|
||||||
|
@ -107,18 +108,18 @@ void Events::handleLSClosed(void *data, zwlr_layer_surface_v1 *zwlr_layer_surfac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::handleGlobal(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) {
|
void Events::handleGlobal(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version) {
|
||||||
if (strcmp(interface, wl_compositor_interface.name) == 0) {
|
if (strcmp(interface, wl_compositor_interface.name) == 0) {
|
||||||
g_pHyprpaper->m_sCompositor = (wl_compositor *)wl_registry_bind(registry, name, &wl_compositor_interface, 4);
|
g_pHyprpaper->m_sCompositor = (wl_compositor*)wl_registry_bind(registry, name, &wl_compositor_interface, 4);
|
||||||
} else if (strcmp(interface, wl_shm_interface.name) == 0) {
|
} else if (strcmp(interface, wl_shm_interface.name) == 0) {
|
||||||
g_pHyprpaper->m_sSHM = (wl_shm *)wl_registry_bind(registry, name, &wl_shm_interface, 1);
|
g_pHyprpaper->m_sSHM = (wl_shm*)wl_registry_bind(registry, name, &wl_shm_interface, 1);
|
||||||
} else if (strcmp(interface, wl_output_interface.name) == 0) {
|
} else if (strcmp(interface, wl_output_interface.name) == 0) {
|
||||||
g_pHyprpaper->m_mtTickMutex.lock();
|
g_pHyprpaper->m_mtTickMutex.lock();
|
||||||
|
|
||||||
const auto PMONITOR = g_pHyprpaper->m_vMonitors.emplace_back(std::make_unique<SMonitor>()).get();
|
const auto PMONITOR = g_pHyprpaper->m_vMonitors.emplace_back(std::make_unique<SMonitor>()).get();
|
||||||
PMONITOR->wayland_name = name;
|
PMONITOR->wayland_name = name;
|
||||||
PMONITOR->name = "";
|
PMONITOR->name = "";
|
||||||
PMONITOR->output = (wl_output *)wl_registry_bind(registry, name, &wl_output_interface, 4);
|
PMONITOR->output = (wl_output*)wl_registry_bind(registry, name, &wl_output_interface, 4);
|
||||||
wl_output_add_listener(PMONITOR->output, &Events::outputListener, PMONITOR);
|
wl_output_add_listener(PMONITOR->output, &Events::outputListener, PMONITOR);
|
||||||
|
|
||||||
g_pHyprpaper->m_mtTickMutex.unlock();
|
g_pHyprpaper->m_mtTickMutex.unlock();
|
||||||
|
@ -133,7 +134,7 @@ void Events::handleGlobal(void *data, struct wl_registry *registry, uint32_t nam
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::handleGlobalRemove(void *data, struct wl_registry *registry, uint32_t name) {
|
void Events::handleGlobalRemove(void* data, struct wl_registry* registry, uint32_t name) {
|
||||||
for (auto& m : g_pHyprpaper->m_vMonitors) {
|
for (auto& m : g_pHyprpaper->m_vMonitors) {
|
||||||
if (m->wayland_name == name) {
|
if (m->wayland_name == name) {
|
||||||
Debug::log(LOG, "Destroying output %s", m->name.c_str());
|
Debug::log(LOG, "Destroying output %s", m->name.c_str());
|
||||||
|
@ -144,10 +145,10 @@ void Events::handleGlobalRemove(void *data, struct wl_registry *registry, uint32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::handlePreferredScale(void *data, wp_fractional_scale_v1* fractionalScaleInfo, uint32_t scale) {
|
void Events::handlePreferredScale(void* data, wp_fractional_scale_v1* fractionalScaleInfo, uint32_t scale) {
|
||||||
const double SCALE = scale / 120.0;
|
const double SCALE = scale / 120.0;
|
||||||
|
|
||||||
CLayerSurface *const pLS = (CLayerSurface*)data;
|
CLayerSurface* const pLS = (CLayerSurface*)data;
|
||||||
|
|
||||||
Debug::log(LOG, "handlePreferredScale: %.2lf for %lx", SCALE, pLS);
|
Debug::log(LOG, "handlePreferredScale: %.2lf for %lx", SCALE, pLS);
|
||||||
|
|
||||||
|
@ -157,4 +158,3 @@ void Events::handlePreferredScale(void *data, wp_fractional_scale_v1* fractional
|
||||||
g_pHyprpaper->tick(true);
|
g_pHyprpaper->tick(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../defines.hpp"
|
#include "../defines.hpp"
|
||||||
#include "PoolBuffer.hpp"
|
|
||||||
#include "../render/LayerSurface.hpp"
|
#include "../render/LayerSurface.hpp"
|
||||||
|
#include "PoolBuffer.hpp"
|
||||||
|
|
||||||
struct SMonitor {
|
struct SMonitor {
|
||||||
std::string name = "";
|
std::string name = "";
|
||||||
|
@ -15,6 +15,8 @@ struct SMonitor {
|
||||||
bool readyForLS = false;
|
bool readyForLS = false;
|
||||||
bool hasATarget = true;
|
bool hasATarget = true;
|
||||||
|
|
||||||
|
bool wildcard = true;
|
||||||
|
|
||||||
uint32_t configureSerial = 0;
|
uint32_t configureSerial = 0;
|
||||||
SPoolBuffer buffer;
|
SPoolBuffer buffer;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue