From 6b8e1087bd27a9c213db81ed3c5840881565e5d8 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Sun, 11 Feb 2024 18:32:00 +0100 Subject: [PATCH 1/2] desktop: add x11 support (thanks krizej) --- modules/desktop.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/modules/desktop.c b/modules/desktop.c index 0098925..586fd9c 100644 --- a/modules/desktop.c +++ b/modules/desktop.c @@ -7,6 +7,9 @@ #include "../mod.h" #include #include +#ifdef MF_DESKTOP_X11 +#include +#endif static const semver api_ver = { .major = 0, @@ -36,7 +39,27 @@ uint8_t init(char **config) { const char *get(void) { char *ret; - if (asprintf(&ret, "Desktop: %s", getenv("XDG_CURRENT_DESKTOP")) < 0) { + 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); } From 49cf173286810cbeb192574ef2e0fc1fc285e9f8 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Sun, 11 Feb 2024 18:39:24 +0100 Subject: [PATCH 2/2] add OPTS for user defined options --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 83a59b4..6423bdc 100644 --- a/Makefile +++ b/Makefile @@ -30,10 +30,10 @@ $(NAME): $(OBJ) $(CC) -o $(BIN)/$(NAME) $(addprefix $(BIN)/, $^) $(LDFLAGS) %.so: modules/%.c $(LIB) - $(CC) -o $(BIN)/$@ $^ -shared -fPIC $(CFLAGS) $(LDFLAGS) + $(CC) -o $(BIN)/$@ $^ -shared -fPIC $(CFLAGS) $(OPTS) $(LDFLAGS) %.o: %.c - $(CC) -o $(BIN)/$@ -c $< $(CFLAGS) + $(CC) -o $(BIN)/$@ -c $< $(CFLAGS) $(OPTS) clean: clean_modules rm -rf $(addprefix $(BIN)/, $(OBJ))