1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-18 20:10:29 +01:00

Allow exit panel to be bound to a key shortcut

While debugging the save/restore workspace state, I found quite
useful to be able to exit windowmaker using a key shortcut.
This commit is contained in:
David Maciejak
2023-02-19 12:10:08 +08:00
committed by Carlos R. Mafra
parent 630e9292c2
commit fabd4252ab
8 changed files with 59 additions and 37 deletions

View File

@@ -156,6 +156,7 @@ static const struct {
{ "WindowRelaunchKey", N_("Launch new instance of application") },
{ "ScreenSwitchKey", N_("Switch to Next Screen/Monitor") },
{ "RunKey", N_("Run application") },
{ "ExitKey", N_("Exit Window Maker") },
{ "DockRaiseLowerKey", N_("Raise/Lower Dock") },
{ "ClipRaiseLowerKey", N_("Raise/Lower Clip") }
#ifdef XKB_MODELOCK

View File

@@ -232,6 +232,7 @@
WindowRelaunchKey = None;
ScreenSwitchKey = None;
RunKey = None;
ExitKey = None;
NormalCursor = (builtin, left_ptr);
ArrowCursor = (builtin, top_left_arrow);
MoveCursor = (builtin, fleur);

View File

@@ -788,6 +788,8 @@ WDefaultEntry optionList[] = {
NULL, getKeybind, setKeyGrab, NULL, NULL},
{"RunKey", "None", (void *)WKBD_RUN,
NULL, getKeybind, setKeyGrab, NULL, NULL},
{"ExitKey", "None", (void *)WKBD_EXIT,
NULL, getKeybind, setKeyGrab, NULL, NULL},
#ifdef KEEP_XKB_LOCK_STATUS
{"ToggleKbdModeKey", "None", (void *)WKBD_TOGGLE,

View File

@@ -1856,6 +1856,13 @@ static void handleKeyPress(XEvent * event)
break;
}
case WKBD_EXIT:
{
/* quick mode is not allowed to prevent inadvertently call */
ExecuteExitCommand(scr, 0);
break;
}
case WKBD_NEXTWSLAYER:
case WKBD_PREVWSLAYER:
{

View File

@@ -145,6 +145,9 @@ enum {
/* open "run" dialog */
WKBD_RUN,
/* open "exit" dialog */
WKBD_EXIT,
#ifdef KEEP_XKB_LOCK_STATUS
WKBD_TOGGLE,
#endif

View File

@@ -53,6 +53,7 @@
#include "xmodifier.h"
#include "main.h"
#include "event.h"
#include "shutdown.h"
#define ICON_SIZE wPreferences.icon_size
@@ -679,6 +680,46 @@ char *ExpandOptions(WScreen *scr, const char *cmdline)
return NULL;
}
void ExecuteExitCommand(WScreen *scr, long quickmode)
{
static int inside = 0;
int result;
/* prevent reentrant calls */
if (inside)
return;
inside = 1;
#define R_CANCEL 0
#define R_EXIT 1
result = R_CANCEL;
if (quickmode == M_QUICK) {
result = R_EXIT;
} else {
int r, oldSaveSessionFlag;
oldSaveSessionFlag = wPreferences.save_session_on_exit;
r = wExitDialog(scr, _("Exit"),
_("Are you sure you want to quit Window Maker?"), _("Exit"), _("Cancel"), NULL);
if (r == WAPRDefault) {
result = R_EXIT;
} else if (r == WAPRAlternate) {
/* Don't modify the "save session on exit" flag if the
* user canceled the operation. */
wPreferences.save_session_on_exit = oldSaveSessionFlag;
}
}
if (result == R_EXIT)
Shutdown(WSExitMode);
#undef R_EXIT
#undef R_CANCEL
inside = 0;
}
void ExecuteInputCommand(WScreen *scr, const char *cmdline)
{
char *cmd;

View File

@@ -25,6 +25,8 @@
#include "keybind.h"
#include "appicon.h"
#define M_QUICK 1
Bool wFetchName(Display *dpy, Window win, char **winname);
Bool wGetIconName(Display *dpy, Window win, char **iconname);
Bool UpdateDomainFile(WDDomain * domain);
@@ -46,6 +48,7 @@ char *ShrinkString(WMFont *font, const char *string, int width);
char *FindImage(const char *paths, const char *file);
char *ExpandOptions(WScreen * scr, const char *cmdline);
void ExecuteInputCommand(WScreen *scr, const char *cmdline);
void ExecuteExitCommand(WScreen *scr, long quickmode);
char *GetShortcutString(const char *text);
char *GetShortcutKey(WShortKey key);
char *EscapeWM_CLASS(const char *name, const char *class);

View File

@@ -142,8 +142,6 @@ static Shortcut *shortcutList = NULL;
*
*/
#define M_QUICK 1
/* menu commands */
static void execCommand(WMenu * menu, WMenuEntry * entry)
@@ -153,42 +151,8 @@ static void execCommand(WMenu * menu, WMenuEntry * entry)
static void exitCommand(WMenu * menu, WMenuEntry * entry)
{
static int inside = 0;
int result;
ExecuteExitCommand(menu->frame->screen_ptr, (long)entry->clientdata);
/* prevent reentrant calls */
if (inside)
return;
inside = 1;
#define R_CANCEL 0
#define R_EXIT 1
result = R_CANCEL;
if ((long)entry->clientdata == M_QUICK) {
result = R_EXIT;
} else {
int r, oldSaveSessionFlag;
oldSaveSessionFlag = wPreferences.save_session_on_exit;
r = wExitDialog(menu->frame->screen_ptr, _("Exit"),
_("Are you sure you want to quit Window Maker?"), _("Exit"), _("Cancel"), NULL);
if (r == WAPRDefault) {
result = R_EXIT;
} else if (r == WAPRAlternate) {
/* Don't modify the "save session on exit" flag if the
* user canceled the operation. */
wPreferences.save_session_on_exit = oldSaveSessionFlag;
}
}
if (result == R_EXIT)
Shutdown(WSExitMode);
#undef R_EXIT
#undef R_CANCEL
inside = 0;
}
static void shutdownCommand(WMenu * menu, WMenuEntry * entry)