Init display and W after option in main

This commit is contained in:
Martin Duquesnoy 2012-01-29 03:52:00 +01:00
parent 9048729876
commit 2bf2011cf1
2 changed files with 27 additions and 17 deletions

View File

@ -514,18 +514,28 @@ uicb_quit(Uicb cmd)
} }
static void static void
exec_uicb_function(char *func, char *cmd) exec_uicb_function(Display *dpy, Window root, char *func, char *cmd)
{ {
XChangeProperty(W->dpy, W->root, ATOM("_WMFS_FUNCTION"), ATOM("UTF8_STRING"), Atom utf8s = XInternAtom(dpy, "UTF8_STRING", false);
XClientMessageEvent e = {
.type = ClientMessage,
.message_type = XInternAtom(dpy, "_WMFS_FUNCTION", false),
.window = root,
.format = 32,
.data.l[4] = true
};
XChangeProperty(dpy,root, XInternAtom(dpy, "_WMFS_FUNCTION", false), utf8s,
8, PropModeReplace, (unsigned char*)func, strlen(func)); 8, PropModeReplace, (unsigned char*)func, strlen(func));
if(!cmd) if(!cmd)
cmd = ""; cmd = "";
XChangeProperty(W->dpy, W->root, ATOM("_WMFS_CMD"), ATOM("UTF8_STRING"), XChangeProperty(dpy, root, XInternAtom(dpy, "_WMFS_CMD", false), utf8s,
8, PropModeReplace, (unsigned char*)cmd, strlen(cmd)); 8, PropModeReplace, (unsigned char*)cmd, strlen(cmd));
ewmh_send_message(W->root, W->root, "_WMFS_FUNCTION", 0, 0, 0, 0, True); XSendEvent(dpy, root, false, StructureNotifyMask, (XEvent*)&e);
XSync(dpy, False);
} }
int int
@ -533,12 +543,11 @@ main(int argc, char **argv)
{ {
int i; int i;
bool r; bool r;
Display *dpy;
char path[MAX_PATH_LEN] = { 0 };
(void)argc; (void)argc;
W = (struct wmfs*)xcalloc(1, sizeof(struct wmfs)); sprintf(path, "%s/"CONFIG_DEFAULT_PATH, getenv("HOME"));
/* Default path ~/.config/wmfs/wmfsrc */
sprintf(W->confpath, "%s/"CONFIG_DEFAULT_PATH, getenv("HOME"));
/* Opt */ /* Opt */
while((i = getopt(argc, argv, "hvC:c:")) != -1) while((i = getopt(argc, argv, "hvC:c:")) != -1)
@ -552,37 +561,38 @@ main(int argc, char **argv)
" -v Show WMFS version\n" " -v Show WMFS version\n"
" -c <func> <cmd> Execute a specified UICB function\n" " -c <func> <cmd> Execute a specified UICB function\n"
" -C <file> Launch WMFS with a specified configuration file\n", argv[0]); " -C <file> Launch WMFS with a specified configuration file\n", argv[0]);
free(W);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
case 'v': case 'v':
printf("wmfs("WMFS_VERSION") 2 beta\n"); printf("wmfs("WMFS_VERSION") 2 beta\n");
free(W);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
case 'c': case 'c':
if(!(W->dpy = XOpenDisplay(NULL))) if(!(dpy = XOpenDisplay(NULL)))
{ {
fprintf(stderr, "%s: Can't open X server\n", argv[0]); fprintf(stderr, "%s: Can't open X server\n", argv[0]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
W->root = DefaultRootWindow(W->dpy);
exec_uicb_function(optarg, argv[optind]); exec_uicb_function(dpy, DefaultRootWindow(dpy), optarg, argv[optind]);
XCloseDisplay(W->dpy); XCloseDisplay(dpy);
free(W);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
case 'C': case 'C':
strncpy(W->confpath, optarg, sizeof(W->confpath)); strncpy(path, optarg, sizeof(W->confpath));
break; break;
} }
} }
W = (struct wmfs*)xcalloc(1, sizeof(struct wmfs));
/* Default path ~/.config/wmfs/wmfsrc */
W->confpath = path;
/* Get X display */ /* Get X display */
if(!(W->dpy = XOpenDisplay(NULL))) if(!(W->dpy = XOpenDisplay(NULL)))
{ {

View File

@ -320,7 +320,7 @@ struct wmfs
GC gc, rgc; GC gc, rgc;
Atom *net_atom; Atom *net_atom;
char **argv; char **argv;
char confpath[MAX_PATH_LEN]; char *confpath;
struct barwin *last_clicked_barwin; struct barwin *last_clicked_barwin;
/* FIFO stuffs */ /* FIFO stuffs */