mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 12:28:22 +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:
committed by
Carlos R. Mafra
parent
528d97b597
commit
8352c9ef60
@@ -112,6 +112,7 @@ static char *keyOptions[] = {
|
||||
"WindowShortcut8Key",
|
||||
"WindowShortcut9Key",
|
||||
"WindowShortcut10Key",
|
||||
"WindowRelaunchKey",
|
||||
"ScreenSwitchKey",
|
||||
"DockRaiseLowerKey",
|
||||
#ifndef XKB_MODELOCK
|
||||
@@ -499,6 +500,7 @@ static void createPanel(Panel * p)
|
||||
WMAddListItem(panel->actLs, _("Shortcut for window 8"));
|
||||
WMAddListItem(panel->actLs, _("Shortcut for window 9"));
|
||||
WMAddListItem(panel->actLs, _("Shortcut for window 10"));
|
||||
WMAddListItem(panel->actLs, _("Launch new instance of application"));
|
||||
WMAddListItem(panel->actLs, _("Switch to Next Screen/Monitor"));
|
||||
WMAddListItem(panel->actLs, _("Raise/Lower Dock"));
|
||||
WMAddListItem(panel->actLs, _("Raise/Lower Clip"));
|
||||
|
||||
@@ -639,6 +639,8 @@ WDefaultEntry optionList[] = {
|
||||
NULL, getKeybind, setKeyGrab, NULL, NULL},
|
||||
{"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
|
||||
NULL, getKeybind, setKeyGrab, NULL, NULL},
|
||||
{"WindowRelaunchKey", "None", (void *)WKBD_RELAUNCH,
|
||||
NULL, getKeybind, setKeyGrab, NULL, NULL},
|
||||
{"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
|
||||
NULL, getKeybind, setKeyGrab, NULL, NULL},
|
||||
|
||||
|
||||
@@ -1651,6 +1651,12 @@ static void handleKeyPress(XEvent * event)
|
||||
|
||||
break;
|
||||
|
||||
case WKBD_RELAUNCH:
|
||||
if (ISMAPPED(wwin) && ISFOCUSED(wwin))
|
||||
(void) RelaunchWindow(wwin);
|
||||
|
||||
break;
|
||||
|
||||
case WKBD_SWITCH_SCREEN:
|
||||
if (wScreenCount > 1) {
|
||||
WScreen *scr2;
|
||||
|
||||
@@ -98,6 +98,8 @@ char *ExpandOptions(WScreen *scr, char *cmdline);
|
||||
|
||||
void ExecuteShellCommand(WScreen *scr, char *command);
|
||||
|
||||
Bool RelaunchWindow(WWindow *wwin);
|
||||
|
||||
Bool IsDoubleClick(WScreen *scr, XEvent *event);
|
||||
|
||||
WWindow *NextToFocusAfter(WWindow *wwin);
|
||||
|
||||
@@ -86,6 +86,9 @@ enum {
|
||||
WKBD_WINDOW9,
|
||||
WKBD_WINDOW10,
|
||||
|
||||
/* launch a new instance of the active window */
|
||||
WKBD_RELAUNCH,
|
||||
|
||||
/* screen */
|
||||
WKBD_SWITCH_SCREEN,
|
||||
|
||||
|
||||
62
src/main.c
62
src/main.c
@@ -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--
|
||||
|
||||
Reference in New Issue
Block a user