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

@@ -112,6 +112,7 @@ static char *keyOptions[] = {
"WindowShortcut8Key", "WindowShortcut8Key",
"WindowShortcut9Key", "WindowShortcut9Key",
"WindowShortcut10Key", "WindowShortcut10Key",
"WindowRelaunchKey",
"ScreenSwitchKey", "ScreenSwitchKey",
"DockRaiseLowerKey", "DockRaiseLowerKey",
#ifndef XKB_MODELOCK #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 8"));
WMAddListItem(panel->actLs, _("Shortcut for window 9")); WMAddListItem(panel->actLs, _("Shortcut for window 9"));
WMAddListItem(panel->actLs, _("Shortcut for window 10")); 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, _("Switch to Next Screen/Monitor"));
WMAddListItem(panel->actLs, _("Raise/Lower Dock")); WMAddListItem(panel->actLs, _("Raise/Lower Dock"));
WMAddListItem(panel->actLs, _("Raise/Lower Clip")); WMAddListItem(panel->actLs, _("Raise/Lower Clip"));

View File

@@ -639,6 +639,8 @@ WDefaultEntry optionList[] = {
NULL, getKeybind, setKeyGrab, NULL, NULL}, NULL, getKeybind, setKeyGrab, NULL, NULL},
{"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10, {"WindowShortcut10Key", "None", (void *)WKBD_WINDOW10,
NULL, getKeybind, setKeyGrab, NULL, NULL}, NULL, getKeybind, setKeyGrab, NULL, NULL},
{"WindowRelaunchKey", "None", (void *)WKBD_RELAUNCH,
NULL, getKeybind, setKeyGrab, NULL, NULL},
{"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN, {"ScreenSwitchKey", "None", (void *)WKBD_SWITCH_SCREEN,
NULL, getKeybind, setKeyGrab, NULL, NULL}, NULL, getKeybind, setKeyGrab, NULL, NULL},

View File

@@ -1651,6 +1651,12 @@ static void handleKeyPress(XEvent * event)
break; break;
case WKBD_RELAUNCH:
if (ISMAPPED(wwin) && ISFOCUSED(wwin))
(void) RelaunchWindow(wwin);
break;
case WKBD_SWITCH_SCREEN: case WKBD_SWITCH_SCREEN:
if (wScreenCount > 1) { if (wScreenCount > 1) {
WScreen *scr2; WScreen *scr2;

View File

@@ -98,6 +98,8 @@ char *ExpandOptions(WScreen *scr, char *cmdline);
void ExecuteShellCommand(WScreen *scr, char *command); void ExecuteShellCommand(WScreen *scr, char *command);
Bool RelaunchWindow(WWindow *wwin);
Bool IsDoubleClick(WScreen *scr, XEvent *event); Bool IsDoubleClick(WScreen *scr, XEvent *event);
WWindow *NextToFocusAfter(WWindow *wwin); WWindow *NextToFocusAfter(WWindow *wwin);

View File

@@ -86,6 +86,9 @@ enum {
WKBD_WINDOW9, WKBD_WINDOW9,
WKBD_WINDOW10, WKBD_WINDOW10,
/* launch a new instance of the active window */
WKBD_RELAUNCH,
/* screen */ /* screen */
WKBD_SWITCH_SCREEN, WKBD_SWITCH_SCREEN,

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-- * wAbort--