add refresh-execp message

This commit is contained in:
Chris Lee 2021-12-04 10:49:03 +01:00
parent f8f9c18cef
commit c1a3cc7977
5 changed files with 41 additions and 20 deletions

View file

@ -545,6 +545,11 @@ void handle_x_event(XEvent *e)
handle_dnd_position(&e->xclient); handle_dnd_position(&e->xclient);
} else if (e->xclient.message_type == server.atom.XdndDrop) { } else if (e->xclient.message_type == server.atom.XdndDrop) {
handle_dnd_drop(&e->xclient); 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; break;
} }

View file

@ -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

View file

@ -60,11 +60,10 @@ int is_tint2(Window window)
return class_match; 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)) if (!is_tint2(window))
return; return;
char *action = (char *)arg;
if (strcmp(action, "show") == 0) { if (strcmp(action, "show") == 0) {
fprintf(stderr, "Showing tint2 window: %lx\n", window); fprintf(stderr, "Showing tint2 window: %lx\n", window);
XEvent event = {}; XEvent event = {};
@ -85,16 +84,40 @@ void handle_tint2_window(Window window, void *arg)
event.xcrossing.same_screen = True; event.xcrossing.same_screen = True;
XSendEvent(display, window, False, 0, &event); XSendEvent(display, window, False, 0, &event);
XFlush(display); 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 { } else {
fprintf(stderr, "Error: unknown action %s\n", action); 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 root = 0;
Window parent = 0; Window parent = 0;
Window *children = 0; Window *children = 0;
@ -104,7 +127,7 @@ void walk_windows(Window node, window_callback_t *callback, void *arg)
return; return;
} }
for (unsigned int i = 0; i < nchildren; i++) { 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++; argc--, argv++;
if (!argc) { if (!argc) {
fprintf(stderr, "Usage: tint2-show [show|hide]\n"); fprintf(stderr, "Usage: tint2-show [show|hide|refresh-execp]\n");
exit(1); exit(1);
} }
char *action = argv[0]; 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; return 0;
} }

View file

@ -122,6 +122,9 @@ void server_init_atoms()
server.atom.XdndActionCopy = XInternAtom(server.display, "XdndActionCopy", False); server.atom.XdndActionCopy = XInternAtom(server.display, "XdndActionCopy", False);
server.atom.XdndFinished = XInternAtom(server.display, "XdndFinished", False); server.atom.XdndFinished = XInternAtom(server.display, "XdndFinished", False);
server.atom.TARGETS = XInternAtom(server.display, "TARGETS", 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) const char *GetAtomName(Display *disp, Atom a)

View file

@ -91,6 +91,7 @@ typedef struct Global_atom {
Atom XdndActionCopy; Atom XdndActionCopy;
Atom XdndFinished; Atom XdndFinished;
Atom TARGETS; Atom TARGETS;
Atom TINT2_REFRESH_EXECP;
} Global_atom; } Global_atom;
typedef struct Property { typedef struct Property {