From e8941ae7b820733ba8f61ecccff7afd4ddcd753f Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Sat, 28 Jan 2012 02:27:34 +0100 Subject: [PATCH] Add back -c option to send uicb func throught xprops --- src/event.c | 26 ++++++++++++++++++++++++++ src/wmfs.c | 45 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/event.c b/src/event.c index 4b5fad0..4a56169 100644 --- a/src/event.c +++ b/src/event.c @@ -5,6 +5,7 @@ #include "event.h" #include "ewmh.h" +#include "config.h" #include "util.h" #include "wmfs.h" #include "client.h" @@ -100,6 +101,31 @@ event_clientmessageevent(XEvent *e) } else if(ev->window == W->root) { + /* WMFS message */ + if(ev->data.l[4]) + { + /* Manage _WMFS_FUNCTION && _WMFS_CMD */ + if(type == wmfs_function || type == wmfs_cmd) + { + int d; + unsigned char *ret = NULL, *ret_cmd = NULL; + void (*func)(Uicb); + + XGetWindowProperty(EVDPY(e), W->root, W->net_atom[wmfs_function], 0, 4096, + False, W->net_atom[utf8_string], (Atom*)&d, &d, + (long unsigned int*)&d, (long unsigned int*)&d, &ret); + XGetWindowProperty(EVDPY(e), W->root, W->net_atom[wmfs_cmd], 0, 4096, + False, W->net_atom[utf8_string], (Atom*)&d, &d, + (long unsigned int*)&d, (long unsigned int*)&d, &ret_cmd); + + if((func = uicb_name_func((char*)ret))) + func((Uicb)ret_cmd); + + XFree(ret_cmd); + XFree(ret); + } + } + if(type == net_active_window) if((sy = systray_find(ev->data.l[0]))) XSetInputFocus(W->dpy, sy->win, RevertToNone, CurrentTime); diff --git a/src/wmfs.c b/src/wmfs.c index 4e64e11..568cbbc 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -3,6 +3,7 @@ * For license, see COPYING. */ +#include #include #include #include @@ -514,6 +515,21 @@ uicb_quit(Uicb cmd) W->flags &= ~WMFS_RUNNING; } +static void +exec_uicb_function(char *func, char *cmd) +{ + XChangeProperty(W->dpy, W->root, ATOM("_WMFS_FUNCTION"), ATOM("UTF8_STRING"), + 8, PropModeReplace, (unsigned char*)func, strlen(func)); + + if(!cmd) + cmd = ""; + + XChangeProperty(W->dpy, W->root, ATOM("_WMFS_CMD"), ATOM("UTF8_STRING"), + 8, PropModeReplace, (unsigned char*)cmd, strlen(cmd)); + + ewmh_send_message(W->root, W->root, "_WMFS_FUNCTION", 0, 0, 0, 0, True); +} + int main(int argc, char **argv) { @@ -527,23 +543,42 @@ main(int argc, char **argv) sprintf(W->confpath, "%s/"CONFIG_DEFAULT_PATH, getenv("HOME")); /* Opt */ - while((i = getopt(argc, argv, "hvC:")) != -1) + while((i = getopt(argc, argv, "hvC:c:")) != -1) { switch(i) { + default: case 'h': - printf("usage: %s [-hv] [-C ]\n" - " -h Show this page\n" - " -v Show WMFS version\n" - " -C Launch WMFS with a specified configuration file\n", argv[0]); + printf("usage: %s [-hv] [-c ]\n" + " -h Show this page\n" + " -v Show WMFS version\n" + " -c Execute a specified UICB function\n" + " -C Launch WMFS with a specified configuration file\n", argv[0]); free(W); exit(EXIT_SUCCESS); break; + case 'v': printf("wmfs("WMFS_VERSION") 2 beta\n"); free(W); exit(EXIT_SUCCESS); break; + + case 'c': + if(!(W->dpy = XOpenDisplay(NULL))) + { + fprintf(stderr, "%s: Can't open X server\n", argv[0]); + exit(EXIT_FAILURE); + } + W->root = DefaultRootWindow(W->dpy); + + exec_uicb_function(optarg, argv[optind]); + + XCloseDisplay(W->dpy); + free(W); + exit(EXIT_SUCCESS); + break; + case 'C': strncpy(W->confpath, optarg, sizeof(W->confpath)); break;