From 0d1af7a8c8e163250e940833d646a12852aa9e5b Mon Sep 17 00:00:00 2001 From: John Ankarstrom Date: Wed, 30 Jun 2021 20:01:38 +0200 Subject: Associate 'confirm' value with each individual Exit menu item Previously, the 'confirm' property would set a global value, controlling the behavior of all exits. --- src/event.c | 4 ++-- src/menu.c | 1 + src/menu.h | 1 + src/parse.c | 10 ++++------ src/root.c | 20 ++++++++++---------- src/root.h | 11 ++++------- 6 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/event.c b/src/event.c index 05218d8..e95aee8 100644 --- a/src/event.c +++ b/src/event.c @@ -440,7 +440,7 @@ void HandleKeyPress(const XKeyEvent *event) { Restart(); break; case KEY_EXIT: - Exit(); + Exit(1); break; default: break; @@ -773,7 +773,7 @@ void HandleClientMessage(const XClientMessageEvent *event) { if(event->message_type == atoms[ATOM_JWM_RESTART]) { Restart(); } else if(event->message_type == atoms[ATOM_JWM_EXIT]) { - Exit(); + Exit(1); } else if(event->message_type == atoms[ATOM_NET_CURRENT_DESKTOP]) { ChangeDesktop(event->data.l[0]); } else { diff --git a/src/menu.c b/src/menu.c index 9f6b80c..ecc5516 100644 --- a/src/menu.c +++ b/src/menu.c @@ -174,6 +174,7 @@ void DestroyMenu(Menu *menu) { } switch(menu->items->action.type) { case MA_EXECUTE: + case MA_EXIT_NOW: case MA_EXIT: if(menu->items->action.data.str) { Release(menu->items->action.data.str); diff --git a/src/menu.h b/src/menu.h index 5d4ad94..5813ebe 100644 --- a/src/menu.h +++ b/src/menu.h @@ -26,6 +26,7 @@ typedef enum { MA_KILL, MA_CLOSE, MA_EXIT, + MA_EXIT_NOW, MA_RESTART } MenuActionType; diff --git a/src/parse.c b/src/parse.c index 65e3197..45a0470 100644 --- a/src/parse.c +++ b/src/parse.c @@ -649,11 +649,10 @@ MenuItem *ParseMenuItem(const TokenNode *start, Menu *menu, } value = FindAttribute(start->attributes, CONFIRM_ATTRIBUTE); - if(value && !strcmp(value, FALSE_VALUE)) { - SetShowExitConfirmation(0); - } else { - SetShowExitConfirmation(1); - } + if(value && !strcmp(value, FALSE_VALUE)) + last->action.type = MA_EXIT_NOW; + else + last->action.type = MA_EXIT; value = FindAttribute(start->attributes, LABEL_ATTRIBUTE); if(!value) { @@ -664,7 +663,6 @@ MenuItem *ParseMenuItem(const TokenNode *start, Menu *menu, value = FindAttribute(start->attributes, ICON_ATTRIBUTE); last->iconName = CopyString(value); - last->action.type = MA_EXIT; last->action.data.str = CopyString(start->value); break; diff --git a/src/root.c b/src/root.c index b110018..13f85e6 100644 --- a/src/root.c +++ b/src/root.c @@ -18,7 +18,6 @@ #define ROOT_MENU_COUNT 10 static Menu *rootMenu[ROOT_MENU_COUNT]; -static int showExitConfirmation = 1; static void ExitHandler(ClientNode *np); static void PatchRootMenu(Menu *menu); @@ -129,12 +128,6 @@ void SetRootMenu(const char *indexes, Menu *m) { } -/*************************************************************************** - ***************************************************************************/ -void SetShowExitConfirmation(int v) { - showExitConfirmation = v; -} - /*************************************************************************** ***************************************************************************/ int IsRootMenuDefined(int index) { @@ -228,8 +221,8 @@ void Restart() { /*************************************************************************** ***************************************************************************/ -void Exit() { - if(showExitConfirmation) { +void Exit(int confirm) { + if(confirm) { ShowConfirmDialog(NULL, ExitHandler, "Exit JWM", "Are you sure?", @@ -251,12 +244,19 @@ void RunRootCommand(const MenuAction *action) { case MA_RESTART: Restart(); break; + case MA_EXIT_NOW: + if(exitCommand) { + Release(exitCommand); + } + exitCommand = CopyString(action->data.str); + Exit(0); + break; case MA_EXIT: if(exitCommand) { Release(exitCommand); } exitCommand = CopyString(action->data.str); - Exit(); + Exit(1); break; case MA_DESKTOP: ChangeDesktop(action->data.i); diff --git a/src/root.h b/src/root.h index b546156..ffb05e0 100644 --- a/src/root.h +++ b/src/root.h @@ -25,11 +25,6 @@ void DestroyRootMenu(); */ void SetRootMenu(const char *indexes, struct Menu *m); -/** Set whether a confirmation dialog is displayed on exit. - * @param v 1 to display confirmation, 0 to just exit. - */ -void SetShowExitConfirmation(int v); - /** Determine if a root menu is defined for the specified index. * @return 1 if it is defined, 0 if not. */ @@ -58,8 +53,10 @@ void RunCommand(const char *command); /** Restart the window manager. */ void Restart(); -/** Exit the window manager. */ -void Exit(); +/** Exit the window manager. + * @param confirm Whether to prompt for confirmation. + */ +void Exit(int confirm); #endif -- cgit v1.2.3