Skip to content

Commit

Permalink
internal: move to libhyprlang for config handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Dec 31, 2023
1 parent ef0e051 commit 39ad021
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 210 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ target_link_libraries(hyprpaper
GLESv2
pthread
magic
hyprlang
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_SOURCE_DIR}/wlr-layer-shell-unstable-v1-protocol.o
${CMAKE_SOURCE_DIR}/xdg-shell-protocol.o
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@ The development files of these packages need to be installed on the system for `
- libglvnd-core
- libjpeg-turbo
- libwebp
- hyprlang

Also `gcc-c++` and `ninja` needs to installed.
Please note hyprpaper > 0.5.0 depends on [hyprlang](https://github.com/hyprwm/hyprlang) which is new
and might not be packaged for your distro yet. If that's the case, build and install it from source.

To install all of these in Fedora, run this command:
```
sudo dnf install wayland-devel wayland-protocols-devel pango-devel cairo-devel file-devel libglvnd-devel libglvnd-core-devel libjpeg-turbo-devel libwebp-devel gcc-c++
```

On Arch:
```
sudo pacman -S ninja gcc wayland-protocols libjpeg-turbo libwebp pango cairo pkgconf cmake libglvnd wayland
```

On OpenSUSE:
```
sudo zypper install ninja gcc-c++ wayland-protocols-devel Mesa-libGLESv3-devel file-devel
Expand Down
15 changes: 9 additions & 6 deletions src/Hyprpaper.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "Hyprpaper.hpp"
#include <filesystem>
#include <fstream>
#include <sys/types.h>
#include <signal.h>
#include <sys/types.h>

CHyprpaper::CHyprpaper() = default;

Expand All @@ -18,6 +18,8 @@ void CHyprpaper::init() {
g_pConfigManager = std::make_unique<CConfigManager>();
g_pIPCSocket = std::make_unique<CIPCSocket>();

g_pConfigManager->parse();

m_sDisplay = (wl_display*)wl_display_connect(nullptr);

if (!m_sDisplay) {
Expand All @@ -27,7 +29,7 @@ void CHyprpaper::init() {

preloadAllWallpapersFromConfig();

if (m_bIPCEnabled)
if (std::any_cast<int64_t>(g_pConfigManager->config->getConfigValue("ipc")))
g_pIPCSocket->initialize();

// run
Expand Down Expand Up @@ -129,7 +131,6 @@ void CHyprpaper::preloadAllWallpapersFromConfig() {
} else {
m_mWallpaperTargets[wp].create(wp);
}

}

g_pConfigManager->m_dRequestedPreloads.clear();
Expand Down Expand Up @@ -450,6 +451,8 @@ SPoolBuffer* CHyprpaper::getPoolBuffer(SMonitor* pMonitor, CWallpaperTarget* pWa
}

void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) {
static auto* const PRENDERSPLASH = reinterpret_cast<int64_t*>(g_pConfigManager->config->getConfigValuePtr("splash"));
static auto* const PSPLASHOFFSET = reinterpret_cast<float*>(g_pConfigManager->config->getConfigValuePtr("splash_offset"));
const auto PWALLPAPERTARGET = m_mMonitorActiveWallpaperTargets[pMonitor];
const auto CONTAIN = m_mMonitorWallpaperRenderData[pMonitor->name].contain;

Expand Down Expand Up @@ -508,7 +511,7 @@ void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) {

cairo_paint(PCAIRO);

if (g_pHyprpaper->m_bRenderSplash && getenv("HYPRLAND_INSTANCE_SIGNATURE")) {
if (*PRENDERSPLASH && getenv("HYPRLAND_INSTANCE_SIGNATURE")) {
auto SPLASH = execAndGet("hyprctl splash");
SPLASH.pop_back();

Expand All @@ -524,9 +527,9 @@ void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) {
cairo_text_extents_t textExtents;
cairo_text_extents(PCAIRO, SPLASH.c_str(), &textExtents);

cairo_move_to(PCAIRO, ((DIMENSIONS.x - textExtents.width * scale) / 2.0) / scale, ((DIMENSIONS.y * (100 - m_fSplashOffset)) / 100 - textExtents.height * scale) / scale);
cairo_move_to(PCAIRO, ((DIMENSIONS.x - textExtents.width * scale) / 2.0) / scale, ((DIMENSIONS.y * (100 - *PSPLASHOFFSET)) / 100 - textExtents.height * scale) / scale);

Debug::log(LOG, "Splash font size: %d, pos: %.2f, %.2f", FONTSIZE, (DIMENSIONS.x - textExtents.width) / 2.0 / scale, ((DIMENSIONS.y * (100 - m_fSplashOffset)) / 100 - textExtents.height * scale) / scale);
Debug::log(LOG, "Splash font size: %d, pos: %.2f, %.2f", FONTSIZE, (DIMENSIONS.x - textExtents.width) / 2.0 / scale, ((DIMENSIONS.y * (100 - *PSPLASHOFFSET)) / 100 - textExtents.height * scale) / scale);

cairo_show_text(PCAIRO, SPLASH.c_str());

Expand Down
73 changes: 35 additions & 38 deletions src/Hyprpaper.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#pragma once

#include "defines.hpp"
#include "config/ConfigManager.hpp"
#include "render/WallpaperTarget.hpp"
#include "helpers/Monitor.hpp"
#include "defines.hpp"
#include "events/Events.hpp"
#include "helpers/PoolBuffer.hpp"
#include "helpers/MiscFunctions.hpp"
#include "helpers/Monitor.hpp"
#include "helpers/PoolBuffer.hpp"
#include "ipc/Socket.hpp"
#include "render/WallpaperTarget.hpp"
#include <mutex>

struct SWallpaperRenderData {
Expand All @@ -17,17 +17,17 @@ struct SWallpaperRenderData {
class CHyprpaper {
public:
// important
wl_display* m_sDisplay; // assured
wl_compositor* m_sCompositor; // assured
wl_shm* m_sSHM; // assured
zwlr_layer_shell_v1* m_sLayerShell = nullptr; // expected
wl_display* m_sDisplay; // assured
wl_compositor* m_sCompositor; // assured
wl_shm* m_sSHM; // assured
zwlr_layer_shell_v1* m_sLayerShell = nullptr; // expected
wp_fractional_scale_manager_v1* m_sFractionalScale = nullptr; // will remain null if not bound
wp_viewporter* m_sViewporter = nullptr; // expected
wp_viewporter* m_sViewporter = nullptr; // expected

// init the utility
CHyprpaper();
void init();
void tick(bool force);
void init();
void tick(bool force);

std::unordered_map<std::string, CWallpaperTarget> m_mWallpaperTargets;
std::unordered_map<std::string, std::string> m_mMonitorActiveWallpapers;
Expand All @@ -36,39 +36,36 @@ class CHyprpaper {
std::vector<std::unique_ptr<SPoolBuffer>> m_vBuffers;
std::vector<std::unique_ptr<SMonitor>> m_vMonitors;

bool m_bIPCEnabled = true;
bool m_bRenderSplash = false;
float m_fSplashOffset = 2;
std::string m_szExplicitConfigPath;
bool m_bNoFractionalScale = false;
bool m_bNoFractionalScale = false;

void removeOldHyprpaperImages();
void preloadAllWallpapersFromConfig();
void recheckAllMonitors();
void ensureMonitorHasActiveWallpaper(SMonitor*);
void createLSForMonitor(SMonitor*);
void renderWallpaperForMonitor(SMonitor*);
void createBuffer(SPoolBuffer*, int32_t, int32_t, uint32_t);
void destroyBuffer(SPoolBuffer*);
int createPoolFile(size_t, std::string&);
bool setCloexec(const int&);
void clearWallpaperFromMonitor(const std::string&);
SMonitor* getMonitorFromName(const std::string&);
bool isPreloaded(const std::string&);
void recheckMonitor(SMonitor*);
void ensurePoolBuffersPresent();
void removeOldHyprpaperImages();
void preloadAllWallpapersFromConfig();
void recheckAllMonitors();
void ensureMonitorHasActiveWallpaper(SMonitor*);
void createLSForMonitor(SMonitor*);
void renderWallpaperForMonitor(SMonitor*);
void createBuffer(SPoolBuffer*, int32_t, int32_t, uint32_t);
void destroyBuffer(SPoolBuffer*);
int createPoolFile(size_t, std::string&);
bool setCloexec(const int&);
void clearWallpaperFromMonitor(const std::string&);
SMonitor* getMonitorFromName(const std::string&);
bool isPreloaded(const std::string&);
void recheckMonitor(SMonitor*);
void ensurePoolBuffersPresent();
SPoolBuffer* getPoolBuffer(SMonitor*, CWallpaperTarget*);
void unloadWallpaper(const std::string&);
void createSeat(wl_seat*);
bool lockSingleInstance(); // fails on multi-instance
void unlockSingleInstance();
void unloadWallpaper(const std::string&);
void createSeat(wl_seat*);
bool lockSingleInstance(); // fails on multi-instance
void unlockSingleInstance();

std::mutex m_mtTickMutex;

std::mutex m_mtTickMutex;
SMonitor* m_pLastMonitor = nullptr;

SMonitor* m_pLastMonitor = nullptr;
private:

bool m_bShouldExit = false;
bool m_bShouldExit = false;
};

inline std::unique_ptr<CHyprpaper> g_pHyprpaper;
Loading

0 comments on commit 39ad021

Please sign in to comment.