From c1a3cc79773d0f7dba6de12be0837405d51c09ac Mon Sep 17 00:00:00 2001 From: Chris Lee <@klee93> Date: Sat, 4 Dec 2021 10:49:03 +0100 Subject: [PATCH] add refresh-execp message --- src/main.c | 5 +++++ src/tint2-send/Makefile | 12 ----------- src/tint2-send/tint2-send.c | 40 +++++++++++++++++++++++++++++-------- src/util/server.c | 3 +++ src/util/server.h | 1 + 5 files changed, 41 insertions(+), 20 deletions(-) delete mode 100644 src/tint2-send/Makefile diff --git a/src/main.c b/src/main.c index 1d4ceb4..6f9b445 100644 --- a/src/main.c +++ b/src/main.c @@ -545,6 +545,11 @@ void handle_x_event(XEvent *e) handle_dnd_position(&e->xclient); } else if (e->xclient.message_type == server.atom.XdndDrop) { handle_dnd_drop(&e->xclient); + } else if (e->xclient.message_type == server.atom.TINT2_REFRESH_EXECP && + e->xclient.format == 8) { + char name[sizeof(e->xclient.data.b) + 1] = {}; + memcpy(name, e->xclient.data.b, sizeof(e->xclient.data.b)); + printf("TODO: refresh execp: %s\n", name); } break; } diff --git a/src/tint2-send/Makefile b/src/tint2-send/Makefile deleted file mode 100644 index 5fbbcdb..0000000 --- a/src/tint2-send/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -ifeq ($(PREFIX),) - PREFIX := /usr/local -endif - -tint2-send: tint2-send.c - $(CC) tint2-send.c -lX11 -o tint2-send - -install: tint2-send - install -m 755 tint2-send $(DESTDIR)/$(PREFIX)/bin/ - -clean: - rm -f tint2-send diff --git a/src/tint2-send/tint2-send.c b/src/tint2-send/tint2-send.c index c01bcda..5be118b 100644 --- a/src/tint2-send/tint2-send.c +++ b/src/tint2-send/tint2-send.c @@ -60,11 +60,10 @@ int is_tint2(Window window) return class_match; } -void handle_tint2_window(Window window, void *arg) +void handle_tint2_window(Window window, char *action, char **args) { if (!is_tint2(window)) return; - char *action = (char *)arg; if (strcmp(action, "show") == 0) { fprintf(stderr, "Showing tint2 window: %lx\n", window); XEvent event = {}; @@ -85,16 +84,40 @@ void handle_tint2_window(Window window, void *arg) event.xcrossing.same_screen = True; XSendEvent(display, window, False, 0, &event); XFlush(display); + } else if (strcmp(action, "refresh-execp") == 0) { + XEvent event = {}; + char *name = args[0]; + if (!name) { + fprintf(stderr, "Error: missing execp name\n"); + return; + } + if (!name[0]) { + fprintf(stderr, "Error: empty execp name\n"); + return; + } + if (strlen(name) > sizeof(event.xclient.data.b)) { + fprintf(stderr, "Error: execp name too long\n"); + return; + } + fprintf(stderr, "Refreshing execp '%s' for window: %lx\n", name, window); + event.xclient.type = ClientMessage; + event.xclient.window = window; + event.xclient.send_event = True; + event.xclient.message_type = XInternAtom(display, "_TINT2_REFRESH_EXECP", False); + event.xclient.format = 8; + strncpy(event.xclient.data.b, name, sizeof(event.xclient.data.b)); + XSendEvent(display, window, False, 0, &event); + XFlush(display); } else { fprintf(stderr, "Error: unknown action %s\n", action); } } -typedef void window_callback_t(Window window, void *arg); +typedef void window_callback_t(Window window, char *action, char **args); -void walk_windows(Window node, window_callback_t *callback, void *arg) +void walk_windows(Window node, window_callback_t *callback, char *action, char **args) { - callback(node, arg); + callback(node, action, args); Window root = 0; Window parent = 0; Window *children = 0; @@ -104,7 +127,7 @@ void walk_windows(Window node, window_callback_t *callback, void *arg) return; } for (unsigned int i = 0; i < nchildren; i++) { - walk_windows(children[i], callback, arg); + walk_windows(children[i], callback, action, args); } } @@ -118,11 +141,12 @@ int main(int argc, char **argv) argc--, argv++; if (!argc) { - fprintf(stderr, "Usage: tint2-show [show|hide]\n"); + fprintf(stderr, "Usage: tint2-show [show|hide|refresh-execp]\n"); exit(1); } char *action = argv[0]; - walk_windows(DefaultRootWindow(display), handle_tint2_window, action); + char **args = argv + 1; + walk_windows(DefaultRootWindow(display), handle_tint2_window, action, args); return 0; } diff --git a/src/util/server.c b/src/util/server.c index 41a7a2c..ea8ea98 100644 --- a/src/util/server.c +++ b/src/util/server.c @@ -122,6 +122,9 @@ void server_init_atoms() server.atom.XdndActionCopy = XInternAtom(server.display, "XdndActionCopy", False); server.atom.XdndFinished = XInternAtom(server.display, "XdndFinished", False); server.atom.TARGETS = XInternAtom(server.display, "TARGETS", False); + + // tint2 atoms + server.atom.TINT2_REFRESH_EXECP = XInternAtom(server.display, "_TINT2_REFRESH_EXECP", False); } const char *GetAtomName(Display *disp, Atom a) diff --git a/src/util/server.h b/src/util/server.h index 53db5aa..1259f1d 100644 --- a/src/util/server.h +++ b/src/util/server.h @@ -91,6 +91,7 @@ typedef struct Global_atom { Atom XdndActionCopy; Atom XdndFinished; Atom TARGETS; + Atom TINT2_REFRESH_EXECP; } Global_atom; typedef struct Property {