4 * Copyright (c) Tuomo Valkonen 1999-2006.
6 * Ion is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
17 #include <sys/types.h>
22 #include <libtu/util.h>
23 #include <libtu/optparser.h>
24 #include <libtu/errorlog.h>
25 #include <libextl/readconfig.h>
26 #include <libmainloop/exec.h>
28 #include <ioncore/common.h>
29 #include <ioncore/global.h>
30 #include <ioncore/ioncore.h>
31 #include <ioncore/exec.h>
32 #include <ioncore/event.h>
33 #include "../version.h"
36 /* Options. Getopt is not used because getopt_long is quite gnu-specific
37 * and they don't know of '-display foo' -style args anyway.
38 * Instead, I've reinvented the wheel in libtu :(.
40 static OptParserOpt pwm_opts[]={
41 {OPT_ID('d'), "display", OPT_ARG, "host:dpy.scr",
42 DUMMY_TR("X display to use")},
44 {'c', "conffile", OPT_ARG, "config_file",
45 DUMMY_TR("Configuration file")},
47 {'s', "searchdir", OPT_ARG, "dir",
48 DUMMY_TR("Add directory to search path")},
50 {OPT_ID('o'), "oneroot", 0, NULL,
51 DUMMY_TR("Manage default root window/non-Xinerama screen only")},
53 #if defined(CF_XINERAMA) || defined(CF_SUN_XINERAMA)
54 {OPT_ID('x'), "xinerama", OPT_ARG, "1|0",
55 DUMMY_TR("Use Xinerama screen information (default: 0/no)")},
57 {OPT_ID('x'), "xinerama", OPT_ARG, "?",
58 DUMMY_TR("Ignored: not compiled with Xinerama support")},
61 {OPT_ID('s'), "session", OPT_ARG, "session_name",
62 DUMMY_TR("Name of session (affects savefiles)")},
64 {OPT_ID('S'), "smclientid", OPT_ARG, "client_id",
65 DUMMY_TR("Session manager client ID")},
67 {OPT_ID('N'), "noerrorlog", 0, NULL,
68 DUMMY_TR("Do not create startup error log and display it "
71 {'h', "help", 0, NULL,
72 DUMMY_TR("Show this help")},
74 {'V', "version", 0, NULL,
75 DUMMY_TR("Show program version")},
77 {OPT_ID('a'), "about", 0, NULL,
78 DUMMY_TR("Show about text")},
87 printf(TR("Usage: %s [options]\n\n"), prog_execname());
88 for(i=0; pwm_opts[i].descr!=NULL; i++)
89 pwm_opts[i].descr=TR(pwm_opts[i].descr);
90 optparser_printhelp(OPTP_MIDLONG, pwm_opts);
95 int main(int argc, char*argv[])
97 const char *cfgfile="cfg_pwm";
98 const char *display=NULL;
100 int stflags=IONCORE_STARTUP_NOXINERAMA;
105 bool may_continue=FALSE;
106 bool noerrorlog=FALSE;
110 if(!ioncore_init("pwm3", argc, argv, LOCALEDIR))
113 extl_add_searchdir(EXTRABINDIR); /* ion-completefile */
114 extl_add_searchdir(MODULEDIR);
115 extl_add_searchdir(ETCDIR);
117 extl_add_searchdir(PWM_ETCDIR);
119 extl_add_searchdir(SHAREDIR);
120 extl_add_searchdir(LCDIR);
121 extl_set_userdirs("pwm3");
123 optparser_init(argc, argv, OPTP_MIDLONG, pwm_opts);
125 while((opt=optparser_get_opt())){
128 display=optparser_get_arg();
131 cfgfile=optparser_get_arg();
134 extl_add_searchdir(optparser_get_arg());
137 ioncore_g.sm_client_id=optparser_get_arg();
140 stflags|=IONCORE_STARTUP_ONEROOT;
144 const char *p=optparser_get_arg();
145 if(strcmp(p, "1")==0)
146 stflags&=~IONCORE_STARTUP_NOXINERAMA;
147 else if(strcmp(p, "0")==0)
148 stflags|=IONCORE_STARTUP_NOXINERAMA;
150 warn(TR("Invalid parameter to -xinerama."));
154 extl_set_sessiondir(optparser_get_arg());
163 printf("%s\n", ION_VERSION);
166 printf("%s\n", ioncore_aboutmsg());
169 warn(TR("Invalid command line."));
176 /* We may have to pass the file to xmessage so just using tmpfile()
179 libtu_asprintf(&efnam, "%s/pwm-%d-startup-errorlog", P_tmpdir,
184 ef=fopen(efnam, "wt");
190 cloexec_braindamage_fix(fileno(ef));
191 fprintf(ef, TR("PWM startup error log:\n"));
192 errorlog_begin_file(&el, ef);
197 if(ioncore_startup(display, cfgfile, stflags))
202 warn(TR("Refusing to start due to encountered errors."));
206 if(errorlog_end(&el) && ioncore_g.dpy!=NULL){
210 ioncore_setup_environ(DefaultScreen(ioncore_g.dpy));
212 XCloseDisplay(ioncore_g.dpy);
214 close(ioncore_g.conn);
215 libtu_asprintf(&cmd, CF_XMESSAGE " %s", efnam);
218 }else if(system(cmd)==-1){
224 if(!may_continue && pid>0)
225 waitpid(pid, NULL, 0);
239 /* The code should never return here */