Skip to content

Commit c957ca7

Browse files
committed
WM (Linux): query Hyprland version from hyprland dev header
1 parent 5dfd267 commit c957ca7

File tree

1 file changed

+61
-14
lines changed

1 file changed

+61
-14
lines changed

src/detection/wm/wm_linux.c

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,90 @@
66
#include "util/binary.h"
77
#include "util/path.h"
88
#include "util/stringUtils.h"
9+
#include "util/debug.h"
910

1011
const char* ffDetectWMPlugin(FF_MAYBE_UNUSED FFstrbuf* pluginName)
1112
{
1213
return "Not supported on this platform";
1314
}
1415

15-
static bool extractHyprlandVersion(const char* line, FF_MAYBE_UNUSED uint32_t len, void *userdata)
16+
static bool extractHyprlandVersion(const char* line, uint32_t len, void *userdata)
1617
{
18+
if (line[0] != 'v') return true;
19+
++line; --len;
1720
int count = 0;
18-
sscanf(line, " version: bump to v%*d.%*d.%*d%n", &count);
21+
sscanf(line, "%*d.%*d.%*d%n", &count);
1922
if (count == 0) return true;
2023

21-
// SUPER hacky and doesn't work for development versions
22-
uint32_t prefixLen = (uint32_t) strlen(" version: bump to v"); // version bump commit message
23-
ffStrbufSetNS((FFstrbuf*) userdata, len - prefixLen, line + prefixLen);
24+
ffStrbufSetNS((FFstrbuf*) userdata, len, line);
2425
return false;
2526
}
2627

2728
static const char* getHyprland(FFstrbuf* result)
2829
{
29-
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
30-
const char* error = ffFindExecutableInPath("Hyprland", &path);
31-
if (error) return "Failed to find Hyprland executable path";
30+
FF_DEBUG("Detecting Hyprland version");
31+
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
32+
33+
FF_DEBUG("Checking for " FASTFETCH_TARGET_DIR_USR "/include/hyprland/src/version.h" " file");
34+
if (ffReadFileBuffer(FASTFETCH_TARGET_DIR_USR "/include/hyprland/src/version.h", &buffer))
35+
{
36+
FF_DEBUG("Found version.h file, extracting version");
37+
if (ffStrbufSubstrAfterFirstS(&buffer, "\n#define GIT_TAG "))
38+
{
39+
ffStrbufSubstrAfterFirstC(&buffer, '"');
40+
ffStrbufSubstrBeforeFirstC(&buffer, '"');
41+
FF_DEBUG("Extracted version from version.h: %s", buffer.chars);
42+
return NULL;
43+
}
44+
FF_DEBUG("Failed to extract version from version.h");
45+
ffStrbufClear(&buffer);
46+
}
47+
else
48+
{
49+
FF_DEBUG("version.h file not found, trying Hyprland executable");
50+
}
3251

33-
ffBinaryExtractStrings(path.chars, extractHyprlandVersion, result, (uint32_t) strlen(" version: bump to v0.0.0"));
34-
if (result->length > 0) return NULL;
52+
const char* error = ffFindExecutableInPath("Hyprland", &buffer);
53+
if (error) {
54+
FF_DEBUG("Error finding Hyprland executable: %s", error);
55+
return "Failed to find Hyprland executable path";
56+
}
57+
FF_DEBUG("Found Hyprland executable at: %s", buffer.chars);
58+
59+
ffBinaryExtractStrings(buffer.chars, extractHyprlandVersion, result, (uint32_t) strlen("v0.0.0"));
60+
if (result->length > 0) {
61+
FF_DEBUG("Extracted version from binary strings: %s", result->chars);
62+
return NULL;
63+
}
64+
FF_DEBUG("Failed to extract version from binary strings, trying --version option");
3565

3666
if (ffProcessAppendStdOut(result, (char* const[]){
37-
path.chars,
67+
buffer.chars,
3868
"--version",
3969
NULL
4070
}) == NULL)
41-
{ // Hyprland 0.46.2 built from branch v0.46.2-b at... long and multi line
42-
ffStrbufSubstrAfterFirstC(result, ' ');
43-
ffStrbufSubstrBeforeFirstC(result, ' ');
71+
{
72+
// Hyprland 0.48.1 built from branch at commit 29e2e59...
73+
// Date: ...
74+
// Tag: v0.48.1, commits: 5937
75+
// ...
76+
77+
FF_DEBUG("Raw version output: %s", result->chars);
78+
// Use tag if available
79+
if (ffStrbufSubstrAfterFirstS(result, "\nTag: v"))
80+
{
81+
ffStrbufSubstrBeforeFirstC(result, ',');
82+
FF_DEBUG("Extracted version from Tag: %s", result->chars);
83+
}
84+
else
85+
{
86+
ffStrbufSubstrAfterFirstC(result, ' ');
87+
ffStrbufSubstrBeforeFirstC(result, ' ');
88+
FF_DEBUG("Extracted version from output: %s", result->chars);
89+
}
4490
return NULL;
4591
}
92+
FF_DEBUG("Failed to run Hyprland --version command");
4693

4794
return "Failed to run command `Hyprland --version`";
4895
}

0 commit comments

Comments
 (0)