|
2 | 2 |
|
3 | 3 | #include "common/processing.h" |
4 | 4 | #include "detection/displayserver/displayserver.h" |
| 5 | +#include "util/binary.h" |
| 6 | +#include "util/path.h" |
| 7 | +#include "util/stringUtils.h" |
5 | 8 |
|
6 | 9 | const char* ffDetectWMPlugin(FF_MAYBE_UNUSED FFstrbuf* pluginName) |
7 | 10 | { |
8 | 11 | return "Not supported on this platform"; |
9 | 12 | } |
10 | 13 |
|
11 | | -static void getHyprland(FFstrbuf* result, FF_MAYBE_UNUSED FFWMOptions* options) |
| 14 | +static bool extractHyprlandVersion(const char* line, FF_MAYBE_UNUSED uint32_t len, void *userdata) |
12 | 15 | { |
| 16 | + if (line[0] != 'v') return true; |
| 17 | + int count = 0; |
| 18 | + sscanf(line + 1, "%*d.%*d.%*d%n", &count); |
| 19 | + if (count == 0) return true; |
| 20 | + |
| 21 | + ffStrbufSetNS((FFstrbuf*) userdata, len - 1, line + 1); |
| 22 | + return false; |
| 23 | +} |
| 24 | + |
| 25 | +static const char* getHyprland(FFstrbuf* result, FF_MAYBE_UNUSED FFWMOptions* options) |
| 26 | +{ |
| 27 | + FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); |
| 28 | + const char* error = ffFindExecutableInPath("Hyprland", &path); |
| 29 | + if (error) return "Failed to find Hyprland executable path"; |
| 30 | + |
| 31 | + if (ffBinaryExtractStrings(path.chars, extractHyprlandVersion, result, (uint32_t) strlen("v0.0.0")) == NULL) |
| 32 | + return NULL; |
| 33 | + |
13 | 34 | if (ffProcessAppendStdOut(result, (char* const[]){ |
14 | | - "Hyprland", |
| 35 | + path.chars, |
15 | 36 | "--version", |
16 | 37 | NULL |
17 | | - }) == NULL){ // Hyprland 0.46.2 built from branch v0.46.2-b at... long and multi line |
| 38 | + }) == NULL) |
| 39 | + { // Hyprland 0.46.2 built from branch v0.46.2-b at... long and multi line |
18 | 40 | ffStrbufSubstrAfterFirstC(result, ' '); |
19 | 41 | ffStrbufSubstrBeforeFirstC(result, ' '); |
| 42 | + return NULL; |
20 | 43 | } |
| 44 | + |
| 45 | + return "Failed to run command `Hyprland --version`"; |
| 46 | +} |
| 47 | + |
| 48 | +static bool extractSwayVersion(const char* line, FF_MAYBE_UNUSED uint32_t len, void *userdata) |
| 49 | +{ |
| 50 | + if (!ffStrStartsWith(line, "sway version ")) return true; |
| 51 | + |
| 52 | + ffStrbufSetNS((FFstrbuf*) userdata, len - (uint32_t) strlen("sway version "), line + strlen("sway version ")); |
| 53 | + return false; |
| 54 | +} |
| 55 | + |
| 56 | +static const char* getSway(FFstrbuf* result, FF_MAYBE_UNUSED FFWMOptions* options) |
| 57 | +{ |
| 58 | + FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); |
| 59 | + const char* error = ffFindExecutableInPath("sway", &path); |
| 60 | + if (error) return "Failed to find sway executable path"; |
| 61 | + |
| 62 | + if (ffBinaryExtractStrings(path.chars, extractSwayVersion, result, (uint32_t) strlen("v0.0.0")) == NULL) |
| 63 | + { |
| 64 | + ffStrbufTrimRightSpace(result); |
| 65 | + return NULL; |
| 66 | + } |
| 67 | + |
| 68 | + if (ffProcessAppendStdOut(result, (char* const[]){ |
| 69 | + path.chars, |
| 70 | + "--version", |
| 71 | + NULL |
| 72 | + }) == NULL) |
| 73 | + { // sway version 1.10 |
| 74 | + ffStrbufSubstrAfterLastC(result, ' '); |
| 75 | + ffStrbufTrimRightSpace(result); |
| 76 | + return NULL; |
| 77 | + } |
| 78 | + |
| 79 | + return "Failed to run command `sway --version`"; |
21 | 80 | } |
22 | 81 |
|
23 | 82 | const char* ffDetectWMVersion(const FFstrbuf* wmName, FFstrbuf* result, FFWMOptions* options) |
24 | 83 | { |
25 | 84 | if (!wmName) |
26 | 85 | return "No WM detected"; |
27 | 86 |
|
28 | | - if (ffStrbufEqualS(wmName, FF_WM_PRETTY_HYPRLAND)) |
29 | | - getHyprland(result, options); |
30 | | - else |
31 | | - return "Unsupported WM"; |
| 87 | + if (ffStrbufEqualS(wmName, "Hyprland")) |
| 88 | + return getHyprland(result, options); |
| 89 | + |
| 90 | + if (ffStrbufEqualS(wmName, "sway")) |
| 91 | + return getSway(result, options); |
32 | 92 |
|
33 | | - return NULL; |
| 93 | + return "Unsupported WM"; |
34 | 94 | } |
0 commit comments