1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 20:38:08 +01:00

Allow relaunch with shortcut key.

Use the WindowRelaunchKey shortcut to examine the WM_COMMAND property of
the active application's main window and launch a new instance of the
application using the retrieved command line.
This commit is contained in:
Iain Patterson
2012-03-30 17:35:57 +01:00
committed by Carlos R. Mafra
parent 528d97b597
commit 8352c9ef60
6 changed files with 77 additions and 0 deletions

View File

@@ -398,6 +398,68 @@ void ExecuteShellCommand(WScreen * scr, char *command)
}
}
/*
*---------------------------------------------------------------------
* RelaunchWindow--
* Launch a new instance of the active window
*
*----------------------------------------------------------------------
*/
Bool RelaunchWindow(WWindow *wwin)
{
if (! wwin || ! wwin->client_win) {
werror("no window to relaunch");
return False;
}
char **argv;
int argc;
if (! XGetCommand(dpy, wwin->client_win, &argv, &argc) || argc == 0 || argv == NULL) {
werror("cannot relaunch the application because no WM_COMMAND property is set");
return False;
}
pid_t pid = fork();
if (pid == 0) {
SetupEnvironment(wwin->screen_ptr);
#ifdef HAVE_SETSID
setsid();
#endif
/* argv is not null-terminated */
char **a = (char **) malloc(argc + 1);
if (! a) {
werror("out of memory trying to relaunch the application");
Exit(-1);
}
int i;
for (i = 0; i < argc; i++) a[i] = argv[i];
a[i] = NULL;
execvp(a[0], a);
Exit(-1);
} else if (pid < 0) {
werror("cannot fork a new process");
XFreeStringList(argv);
return False;
} else {
_tuple *data = wmalloc(sizeof(_tuple));
data->scr = wwin->screen_ptr;
data->command = wtokenjoin(argv, argc);
/* not actually a shell command */
wAddDeathHandler(pid, (WDeathHandler *) shellCommandHandler, data);
XFreeStringList(argv);
return True;
}
}
/*
*---------------------------------------------------------------------
* wAbort--