Add back -c option to send uicb func throught xprops

This commit is contained in:
Martin Duquesnoy 2012-01-28 02:27:34 +01:00
parent fd27ce371e
commit e8941ae7b8
2 changed files with 66 additions and 5 deletions

View File

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

View File

@ -3,6 +3,7 @@
* For license, see COPYING.
*/
#include <string.h>
#include <getopt.h>
#include <X11/keysym.h>
#include <X11/cursorfont.h>
@ -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 <file>]\n"
" -h Show this page\n"
" -v Show WMFS version\n"
" -C <file> Launch WMFS with a specified configuration file\n", argv[0]);
printf("usage: %s [-hv] [-c <func> <cmd] [-C <file>]\n"
" -h Show this page\n"
" -v Show WMFS version\n"
" -c <func> <cmd> Execute a specified UICB function\n"
" -C <file> 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;