Skip to content

Commit e527a66

Browse files
committed
modernize dep internals
1 parent a3ceb20 commit e527a66

10 files changed

+91
-105
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ pkg_check_modules(
6363
libjxl
6464
libjxl_cms
6565
libjxl_threads
66-
hyprlang>=0.2.0
67-
hyprutils>=0.2.0
66+
hyprlang>=0.6.0
67+
hyprutils>=0.2.4
6868
hyprgraphics)
6969

7070
file(GLOB_RECURSE SRCFILES "src/*.cpp")

src/Hyprpaper.cpp

+22-23
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static void handleGlobal(CCWlRegistry* registry, uint32_t name, const char* inte
3939
static void handleGlobalRemove(CCWlRegistry* registry, uint32_t name) {
4040
for (auto& m : g_pHyprpaper->m_vMonitors) {
4141
if (m->wayland_name == name) {
42-
Debug::log(LOG, "Destroying output %s", m->name.c_str());
42+
Debug::log(LOG, "Destroying output {}", m->name);
4343
g_pHyprpaper->clearWallpaperFromMonitor(m->name);
4444
std::erase_if(g_pHyprpaper->m_vMonitors, [&](const auto& other) { return other->wayland_name == name; });
4545
return;
@@ -139,7 +139,7 @@ void CHyprpaper::unloadWallpaper(const std::string& path) {
139139

140140
const auto PRELOADPATH = it->get()->name;
141141

142-
Debug::log(LOG, "Unloading target %s, preload path %s", path.c_str(), PRELOADPATH.c_str());
142+
Debug::log(LOG, "Unloading target {}, preload path {}", path, PRELOADPATH);
143143

144144
std::filesystem::remove(PRELOADPATH);
145145

@@ -161,7 +161,7 @@ void CHyprpaper::preloadAllWallpapersFromConfig() {
161161
bool exists = false;
162162
for (auto& [ewp, cls] : m_mWallpaperTargets) {
163163
if (ewp == wp) {
164-
Debug::log(LOG, "Ignoring request to preload %s as it already is preloaded!", ewp.c_str());
164+
Debug::log(LOG, "Ignoring request to preload {} as it already is preloaded!", ewp);
165165
exists = true;
166166
break;
167167
}
@@ -243,14 +243,13 @@ void CHyprpaper::removeOldHyprpaperImages() {
243243

244244
memoryFreed += entry.file_size();
245245
if (!std::filesystem::remove(entry.path()))
246-
Debug::log(LOG, "Couldn't remove %s", entry.path().string().c_str());
246+
Debug::log(LOG, "Couldn't remove {}", entry.path().string());
247247
cleaned++;
248248
}
249249
}
250250

251-
if (cleaned != 0) {
252-
Debug::log(LOG, "Cleaned old hyprpaper preloads (%i), removing %.1fMB", cleaned, ((float)memoryFreed) / 1000000.f);
253-
}
251+
if (cleaned != 0)
252+
Debug::log(LOG, "Cleaned old hyprpaper preloads ({}), removing {:.1f}MB", cleaned, ((float)memoryFreed) / 1000000.f);
254253
}
255254

256255
SMonitor* CHyprpaper::getMonitorFromName(const std::string& monname) {
@@ -294,7 +293,7 @@ void CHyprpaper::ensurePoolBuffersPresent() {
294293

295294
PBUFFER->target = wt.m_szPath;
296295

297-
Debug::log(LOG, "Buffer created for target %s, Shared Memory usage: %.1fMB", wt.m_szPath.c_str(), PBUFFER->size / 1000000.f);
296+
Debug::log(LOG, "Buffer created for target {}, Shared Memory usage: {:.1f}MB", wt.m_szPath, PBUFFER->size / 1000000.f);
298297

299298
anyNewBuffers = true;
300299
}
@@ -308,7 +307,7 @@ void CHyprpaper::ensurePoolBuffersPresent() {
308307
bytesUsed += bf->size;
309308
}
310309

311-
Debug::log(LOG, "Total SM usage for all buffers: %.1fMB", bytesUsed / 1000000.f);
310+
Debug::log(LOG, "Total SM usage for all buffers: {:.1f}MB", bytesUsed / 1000000.f);
312311
}
313312
}
314313

@@ -398,7 +397,7 @@ void CHyprpaper::ensureMonitorHasActiveWallpaper(SMonitor* pMonitor) {
398397

399398
if (!it->second) {
400399
pMonitor->hasATarget = false;
401-
Debug::log(WARN, "Monitor %s does not have a target! A wallpaper will not be created.", pMonitor->name.c_str());
400+
Debug::log(WARN, "Monitor {} does not have a target! A wallpaper will not be created.", pMonitor->name);
402401
return;
403402
}
404403

@@ -507,8 +506,8 @@ SPoolBuffer* CHyprpaper::getPoolBuffer(SMonitor* pMonitor, CWallpaperTarget* pWa
507506
}
508507

509508
void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) {
510-
static auto* const PRENDERSPLASH = reinterpret_cast<Hyprlang::INT* const*>(g_pConfigManager->config->getConfigValuePtr("splash")->getDataStaticPtr());
511-
static auto* const PSPLASHOFFSET = reinterpret_cast<Hyprlang::FLOAT* const*>(g_pConfigManager->config->getConfigValuePtr("splash_offset")->getDataStaticPtr());
509+
static auto PRENDERSPLASH = Hyprlang::CSimpleConfigValue<Hyprlang::INT>(g_pConfigManager->config.get(), "splash");
510+
static auto PSPLASHOFFSET = Hyprlang::CSimpleConfigValue<Hyprlang::FLOAT>(g_pConfigManager->config.get(), "splash_offset");
512511

513512
if (!m_mMonitorActiveWallpaperTargets[pMonitor])
514513
recheckMonitor(pMonitor);
@@ -565,8 +564,8 @@ void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) {
565564
origin.x = -(PWALLPAPERTARGET->m_vSize.x * scale - DIMENSIONS.x) / 2.0 / scale;
566565
}
567566

568-
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,
569-
origin.y, scale, (int)PWALLPAPERTARGET->m_vSize.x, (int)PWALLPAPERTARGET->m_vSize.y);
567+
Debug::log(LOG, "Image data for {}: {} at [{:.2f}, {:.2f}], scale: {:.2f} (original image size: [{}, {}])", pMonitor->name, PWALLPAPERTARGET->m_szPath, origin.x, origin.y,
568+
scale, (int)PWALLPAPERTARGET->m_vSize.x, (int)PWALLPAPERTARGET->m_vSize.y);
570569

571570
if (TILE) {
572571
cairo_pattern_t* pattern = cairo_pattern_create_for_surface(PWALLPAPERTARGET->m_pCairoSurface->cairo());
@@ -579,7 +578,7 @@ void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) {
579578

580579
cairo_paint(PCAIRO);
581580

582-
if (**PRENDERSPLASH && getenv("HYPRLAND_INSTANCE_SIGNATURE")) {
581+
if (*PRENDERSPLASH && getenv("HYPRLAND_INSTANCE_SIGNATURE")) {
583582
auto SPLASH = execAndGet("hyprctl splash");
584583
SPLASH.pop_back();
585584

@@ -590,20 +589,20 @@ void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) {
590589
const auto FONTSIZE = (int)(DIMENSIONS.y / 76.0 / scale);
591590
cairo_set_font_size(PCAIRO, FONTSIZE);
592591

593-
static auto* const PSPLASHCOLOR = reinterpret_cast<Hyprlang::INT* const*>(g_pConfigManager->config->getConfigValuePtr("splash_color")->getDataStaticPtr());
592+
static auto PSPLASHCOLOR = Hyprlang::CSimpleConfigValue<Hyprlang::INT>(g_pConfigManager->config.get(), "splash_color");
594593

595-
Debug::log(LOG, "Splash color: %x", **PSPLASHCOLOR);
594+
Debug::log(LOG, "Splash color: {:x}", *PSPLASHCOLOR);
596595

597-
cairo_set_source_rgba(PCAIRO, ((**PSPLASHCOLOR >> 16) & 0xFF) / 255.0, ((**PSPLASHCOLOR >> 8) & 0xFF) / 255.0, (**PSPLASHCOLOR & 0xFF) / 255.0,
598-
((**PSPLASHCOLOR >> 24) & 0xFF) / 255.0);
596+
cairo_set_source_rgba(PCAIRO, ((*PSPLASHCOLOR >> 16) & 0xFF) / 255.0, ((**PSPLASHCOLOR >> 8) & 0xFF) / 255.0, (*PSPLASHCOLOR & 0xFF) / 255.0,
597+
((*PSPLASHCOLOR >> 24) & 0xFF) / 255.0);
599598

600599
cairo_text_extents_t textExtents;
601600
cairo_text_extents(PCAIRO, SPLASH.c_str(), &textExtents);
602601

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

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

608607
cairo_show_text(PCAIRO, SPLASH.c_str());
609608

@@ -623,7 +622,7 @@ void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) {
623622
pMonitor->pCurrentLayerSurface->pSurface->sendSetOpaqueRegion(opaqueRegion.get());
624623

625624
if (pMonitor->pCurrentLayerSurface->pFractionalScaleInfo) {
626-
Debug::log(LOG, "Submitting viewport dest size %ix%i for %x", static_cast<int>(std::round(pMonitor->size.x)), static_cast<int>(std::round(pMonitor->size.y)),
625+
Debug::log(LOG, "Submitting viewport dest size {}x{} for {:x}", static_cast<int>(std::round(pMonitor->size.x)), static_cast<int>(std::round(pMonitor->size.y)),
627626
pMonitor->pCurrentLayerSurface);
628627
pMonitor->pCurrentLayerSurface->pViewport->sendSetDestination(static_cast<int>(std::round(pMonitor->size.x)), static_cast<int>(std::round(pMonitor->size.y)));
629628
}

src/Hyprpaper.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
struct SWallpaperRenderData {
2020
bool contain = false;
21-
bool tile = false;
21+
bool tile = false;
2222
};
2323

2424
class CHyprpaper {

src/debug/Log.cpp

-49
This file was deleted.

src/debug/Log.hpp

+48-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,57 @@
11
#pragma once
2+
#include <format>
3+
#include <iostream>
24
#include <string>
35

4-
#define LOGMESSAGESIZE 1024
5-
6-
enum LogLevel {
7-
NONE = -1,
8-
LOG = 0,
6+
enum eLogLevel {
7+
TRACE = 0,
8+
INFO,
9+
LOG,
910
WARN,
1011
ERR,
1112
CRIT,
12-
INFO
13+
NONE
1314
};
1415

16+
#define RASSERT(expr, reason, ...) \
17+
if (!(expr)) { \
18+
Debug::log(CRIT, "\n==========================================================================================\nASSERTION FAILED! \n\n{}\n\nat: line {} in {}", \
19+
std::format(reason, ##__VA_ARGS__), __LINE__, \
20+
([]() constexpr -> std::string { return std::string(__FILE__).substr(std::string(__FILE__).find_last_of('/') + 1); })().c_str()); \
21+
std::abort(); \
22+
}
23+
24+
#define ASSERT(expr) RASSERT(expr, "?")
25+
1526
namespace Debug {
16-
void log(LogLevel level, const char* fmt, ...);
17-
}
27+
inline bool quiet = false;
28+
inline bool verbose = false;
29+
30+
template <typename... Args>
31+
void log(eLogLevel level, const std::string& fmt, Args&&... args) {
32+
33+
if (!verbose && level == TRACE)
34+
return;
35+
36+
if (quiet)
37+
return;
38+
39+
if (level != NONE) {
40+
std::cout << '[';
41+
42+
switch (level) {
43+
case TRACE: std::cout << "TRACE"; break;
44+
case INFO: std::cout << "INFO"; break;
45+
case LOG: std::cout << "LOG"; break;
46+
case WARN: std::cout << "WARN"; break;
47+
case ERR: std::cout << "ERR"; break;
48+
case CRIT: std::cout << "CRITICAL"; break;
49+
default: break;
50+
}
51+
52+
std::cout << "] ";
53+
}
54+
55+
std::cout << std::vformat(fmt, std::make_format_args(args...)) << std::endl;
56+
}
57+
};

src/helpers/MiscFunctions.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#include "../debug/Log.hpp"
44
#include <memory>
55

6+
#include <hyprutils/os/Process.hpp>
7+
using namespace Hyprutils::OS;
8+
69
bool vectorDeltaLessThan(const Vector2D& a, const Vector2D& b, const float& delta) {
710
return std::abs(a.x - b.x) < delta && std::abs(a.y - b.y) < delta;
811
}
@@ -12,15 +15,8 @@ bool vectorDeltaLessThan(const Vector2D& a, const Vector2D& b, const Vector2D& d
1215
}
1316

1417
std::string execAndGet(const char* cmd) {
15-
std::array<char, 128> buffer;
16-
std::string result;
17-
const std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
18-
if (!pipe) {
19-
Debug::log(ERR, "execAndGet: failed in pipe");
18+
CProcess proc("/bin/bash", {cmd});
19+
if (!proc.runSync())
2020
return "";
21-
}
22-
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
23-
result += buffer.data();
24-
}
25-
return result;
21+
return proc.stdOut();
2622
}

src/ipc/Socket.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ void CIPCSocket::initialize() {
5050

5151
char readBuffer[1024] = {0};
5252

53-
Debug::log(LOG, "hyprpaper socket started at %s (fd: %i)", socketPath.c_str(), SOCKET);
53+
Debug::log(LOG, "hyprpaper socket started at {} (fd: {})", socketPath, SOCKET);
5454
while (1) {
5555
const auto ACCEPTEDCONNECTION = accept(SOCKET, (sockaddr*)&clientAddress, &clientSize);
5656
if (ACCEPTEDCONNECTION < 0) {
5757
Debug::log(ERR, "Couldn't listen on the hyprpaper Socket. (3) IPC will not work.");
5858
break;
5959
} else {
6060
do {
61-
Debug::log(LOG, "Accepted incoming socket connection request on fd %i", ACCEPTEDCONNECTION);
61+
Debug::log(LOG, "Accepted incoming socket connection request on fd {}", ACCEPTEDCONNECTION);
6262
std::lock_guard<std::mutex> lg(g_pHyprpaper->m_mtTickMutex);
6363

6464
auto messageSize = read(ACCEPTEDCONNECTION, readBuffer, 1024);
@@ -100,7 +100,7 @@ bool CIPCSocket::mainThreadParseRequest() {
100100

101101
// now we can work on the copy
102102

103-
Debug::log(LOG, "Received a request: %s", copy.c_str());
103+
Debug::log(LOG, "Received a request: {}", copy);
104104

105105
// set default reply
106106
m_szReply = "ok";
@@ -123,7 +123,7 @@ bool CIPCSocket::mainThreadParseRequest() {
123123
if (copy.find("listloaded") == 0) {
124124

125125
const auto numWallpapersLoaded = g_pHyprpaper->m_mWallpaperTargets.size();
126-
Debug::log(LOG, "numWallpapersLoaded: %d", numWallpapersLoaded);
126+
Debug::log(LOG, "numWallpapersLoaded: {}", numWallpapersLoaded);
127127

128128
if (numWallpapersLoaded == 0) {
129129
m_szReply = "no wallpapers loaded";
@@ -145,7 +145,7 @@ bool CIPCSocket::mainThreadParseRequest() {
145145
if (copy.find("listactive") == 0) {
146146

147147
const auto numWallpapersActive = g_pHyprpaper->m_mMonitorActiveWallpapers.size();
148-
Debug::log(LOG, "numWallpapersActive: %d", numWallpapersActive);
148+
Debug::log(LOG, "numWallpapersActive: {}", numWallpapersActive);
149149

150150
if (numWallpapersActive == 0) {
151151
m_szReply = "no wallpapers active";

src/main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
#include "Hyprpaper.hpp"
44

55
int main(int argc, char** argv, char** envp) {
6-
Debug::log(LOG, "Welcome to hyprpaper!\nbuilt from commit %s (%s)", GIT_COMMIT_HASH, GIT_COMMIT_MESSAGE);
6+
Debug::log(LOG, "Welcome to hyprpaper!\nbuilt from commit {} ({})", GIT_COMMIT_HASH, GIT_COMMIT_MESSAGE);
77

88
// parse some args
99
std::string configPath;
1010
bool noFractional = false;
1111
for (int i = 1; i < argc; ++i) {
1212
if ((!strcmp(argv[i], "-c") || !strcmp(argv[i], "--config")) && argc >= i + 2) {
1313
configPath = std::string(argv[++i]);
14-
Debug::log(LOG, "Using config location %s.", configPath.c_str());
14+
Debug::log(LOG, "Using config location {}.", configPath);
1515
} else if (!strcmp(argv[i], "--no-fractional") || !strcmp(argv[i], "-n")) {
1616
noFractional = true;
1717
Debug::log(LOG, "Disabling fractional scaling support!");

src/render/LayerSurface.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ CLayerSurface::CLayerSurface(SMonitor* pMonitor) {
6666
pFractionalScaleInfo->setPreferredScale([this](CCWpFractionalScaleV1* r, uint32_t sc120) {
6767
const double SCALE = sc120 / 120.0;
6868

69-
Debug::log(LOG, "handlePreferredScale: %.2lf for %lx", SCALE, this);
69+
Debug::log(LOG, "handlePreferredScale: {:.2f} for {:x}", SCALE, (uintptr_t)this);
7070

7171
if (fScale != SCALE) {
7272
fScale = SCALE;

0 commit comments

Comments
 (0)