68 lines
1.5 KiB
C
68 lines
1.5 KiB
C
/* DESKTOP - desktop environment / window manager / compositor module for modfetch
|
|
*
|
|
* author: jacekpoz
|
|
* 09 Feb 2024
|
|
*/
|
|
|
|
#include "../mod.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#ifdef MF_DESKTOP_X11
|
|
#include <X11/Xlib.h>
|
|
#endif
|
|
|
|
static const semver api_ver = {
|
|
.major = 0,
|
|
.minor = 1,
|
|
.patch = 0,
|
|
};
|
|
|
|
static const semver _version = {
|
|
.major = 0,
|
|
.minor = 1,
|
|
.patch = 0,
|
|
};
|
|
|
|
semver version(void) { return _version; }
|
|
const char *name(void) { return "desktop"; }
|
|
|
|
uint8_t init(char **config) {
|
|
if (!sveq(api_ver, API_VERSION)) {
|
|
return MFERR_APIVER;
|
|
}
|
|
|
|
(void)config;
|
|
|
|
return 0;
|
|
}
|
|
|
|
const char *get(void) {
|
|
char *ret;
|
|
|
|
char *current_desktop = getenv("XDG_CURRENT_DESKTOP");
|
|
|
|
if (current_desktop == NULL) {
|
|
#ifdef MF_DESKTOP_X11
|
|
Display *disp = XOpenDisplay(NULL);
|
|
Window root = XDefaultRootWindow(disp);
|
|
Atom atom = XInternAtom(disp, "_NET_WM_NAME", 0);
|
|
Atom type;
|
|
int fmt;
|
|
unsigned long num_items;
|
|
unsigned long bytes_after;
|
|
unsigned char *prop;
|
|
XGetWindowProperty(disp, root, atom, 0, 4096 / sizeof(int32_t), 0, AnyPropertyType,
|
|
&type, &fmt, &num_items, &bytes_after, &prop);
|
|
current_desktop = prop;
|
|
#else
|
|
current_desktop = "Unknown";
|
|
#endif
|
|
}
|
|
|
|
if (asprintf(&ret, "Desktop: %s", current_desktop) < 0) {
|
|
fprintf(stderr, "error: failed formatting (this shouldn't happen)");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
return ret;
|
|
}
|