4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * See the included file LICENSE for details.
14 #include <libmainloop/select.h>
15 #include <libmainloop/exec.h>
28 void ioncore_setup_display(int xscr)
35 display=XDisplayName(ioncore_g.display);
37 /* %ui, UINT_MAX is used to ensure there is enough space for the screen
40 libtu_asprintf(&tmp, "DISPLAY=%s.0123456789a", display);
53 snprintf(tmp+strlen(tmp), 11, ".%u", (unsigned)xscr);
57 /* No need to free it, we'll execve soon */
64 void ioncore_setup_environ(const WExecP *p)
68 ioncore_setup_display(p->target!=NULL
69 ? region_rootwin_of(p->target)->xscr
72 /* Set up working directory */
81 WHook *ioncore_exec_environ_hook=NULL;
84 static void setup_exec(void *execp)
86 hook_call_p(ioncore_exec_environ_hook, execp, NULL);
97 int ioncore_do_exec_on(WRegion *reg, const char *cmd, const char *wd,
106 return mainloop_popen_bgread(cmd, setup_exec, (void*)&p,
107 extl_fn_none(), errh);
112 * Run \var{cmd} with the environment variable DISPLAY set to point to the
113 * X display the WM is running on. No specific screen is set unlike with
114 * \fnref{WRootWin.exec_on}. The PID of the (shell executing the) new
115 * process is returned.
119 int ioncore_exec(const char *cmd)
121 return ioncore_do_exec_on(NULL, cmd, NULL, extl_fn_none());
126 * Run \var{cmd} with a read pipe connected to its stdout.
127 * When data is received through the pipe, \var{handler} is called
132 int ioncore_popen_bgread(const char *cmd, ExtlFn h, ExtlFn errh)
140 return mainloop_popen_bgread(cmd, setup_exec, (void*)&p, h, errh);
148 /*{{{ Exit, restart, snapshot */
151 static void (*smhook)(int what);
153 bool ioncore_set_smhook(void (*fn)(int what))
160 void ioncore_do_exit()
167 bool ioncore_do_snapshot()
169 if(!ioncore_save_layout())
173 hook_call_v(ioncore_snapshot_hook);
174 extl_unprotect(NULL);
180 void ioncore_emergency_snapshot()
183 warn(TR("Not saving state: running under session manager."));
185 ioncore_do_snapshot();
190 static char *other=NULL;
192 static void set_other(const char *s)
196 other=(s==NULL ? NULL : scopy(s));
200 void ioncore_do_restart()
204 if(ioncore_g.display!=NULL)
205 ioncore_setup_display(-1);
206 mainloop_do_exec(other);
209 execvp(ioncore_g.argv[0], ioncore_g.argv);
210 die_err_obj(ioncore_g.argv[0]);
215 * Causes the window manager to simply exit without saving
219 void ioncore_resign()
222 smhook(IONCORE_SM_RESIGN);
230 * End session saving it first.
233 void ioncore_shutdown()
236 smhook(IONCORE_SM_SHUTDOWN);
238 ioncore_do_snapshot();
245 * Restart, saving session first.
248 void ioncore_restart()
253 smhook(IONCORE_SM_RESTART);
255 ioncore_do_snapshot();
256 ioncore_do_restart();
262 * Attempt to restart another window manager \var{cmd}.
265 void ioncore_restart_other(const char *cmd)
270 smhook(IONCORE_SM_RESTART_OTHER);
272 ioncore_do_snapshot();
273 ioncore_do_restart();
282 void ioncore_snapshot()
285 smhook(IONCORE_SM_SNAPSHOT);
287 ioncore_do_snapshot();