From 87e7c6507655e57e64b38f7fc80b38e3c005f318 Mon Sep 17 00:00:00 2001 From: JCallicoat Date: Sun, 20 Mar 2022 02:43:34 -0500 Subject: [PATCH] Add backandforth attribute to Desktops tag This commit adds a backandforth attribute to the Desktops tag. The accepted values are "on and "off" (the default). When this attribute is set to "on" trying to change desktops to the currently active desktop with the desktop# action will change to the previously active desktop instead. When it is set to "off" (or not set) the previous behavior of doing nothing is retained. --- jwm.1.in | 9 +++++++++ src/client.c | 1 + src/desktop.c | 1 + src/event.c | 8 +++++++- src/main.c | 1 + src/main.h | 1 + src/parse.c | 11 ++++++++++- src/settings.c | 1 + src/settings.h | 6 ++++++ 9 files changed, 37 insertions(+), 2 deletions(-) diff --git a/jwm.1.in b/jwm.1.in index a762161f..75ef227b 100644 --- a/jwm.1.in +++ b/jwm.1.in @@ -1870,6 +1870,15 @@ The number of virtual desktops in the vertical direction. The default is 1. .RE .P +\fBbackandforth\fP \fIstring\fP +.RS +Controls whether changing the desktop to the currently active desktop using +the \fBdesktop#\fP action should instead switch to the previously active +desktop. +Default is "off" to do nothing when switching to the currently active desktop. +Possible values are "on" and "off". +.RE +.P Within the \fBDesktops\fP tag the following tags are supported: .P .B Background diff --git a/src/client.c b/src/client.c index a62d7e29..a6004896 100644 --- a/src/client.c +++ b/src/client.c @@ -49,6 +49,7 @@ void StartupClients(void) clientCount = 0; activeClient = NULL; currentDesktop = 0; + previousDesktop = 0; /* Clear out the client lists. */ for(x = 0; x < LAYER_COUNT; x++) { diff --git a/src/desktop.c b/src/desktop.c index e8b46237..409a593f 100644 --- a/src/desktop.c +++ b/src/desktop.c @@ -192,6 +192,7 @@ void ChangeDesktop(unsigned int desktop) } } + previousDesktop = currentDesktop; currentDesktop = desktop; SetCardinalAtom(rootWindow, ATOM_NET_CURRENT_DESKTOP, currentDesktop); diff --git a/src/event.c b/src/event.c index 517201b7..bafeb4b8 100644 --- a/src/event.c +++ b/src/event.c @@ -480,12 +480,18 @@ void ProcessBinding(MouseContextType context, ClientNode *np, { const ActionType key = GetKey(context, state, code); const char keyAction = context == MC_NONE; + unsigned int desktop; switch(key.action) { case ACTION_EXEC: RunKeyCommand(context, state, code); break; case ACTION_DESKTOP: - ChangeDesktop(key.extra); + desktop = key.extra; + if(currentDesktop == desktop && + settings.desktopBackAndForth) { + desktop = previousDesktop; + } + ChangeDesktop(desktop); break; case ACTION_RDESKTOP: RightDesktop(); diff --git a/src/main.c b/src/main.c index de1e5ddc..41fc47e5 100644 --- a/src/main.c +++ b/src/main.c @@ -63,6 +63,7 @@ char initializing = 0; char shouldReload = 0; unsigned int currentDesktop = 0; +unsigned int previousDesktop = 0; char *exitCommand = NULL; diff --git a/src/main.h b/src/main.h index dc80d1db..517d0d1f 100644 --- a/src/main.h +++ b/src/main.h @@ -25,6 +25,7 @@ extern Atom managerSelection; extern char *exitCommand; extern unsigned int currentDesktop; +extern unsigned int previousDesktop; extern char shouldExit; extern char shouldRestart; diff --git a/src/parse.c b/src/parse.c index 800a9c77..5f08b0ae 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1097,14 +1097,23 @@ void ParseInclude(const TokenNode *tp, int depth) /** Parse desktop configuration. */ void ParseDesktops(const TokenNode *tp) { - + + static const StringMappingType mapping[] = { + { "off", DBACKANDFORTH_OFF }, + { "on", DBACKANDFORTH_ON } + }; TokenNode *np; const char *width; const char *height; int desktop; + DesktopBackAndForthType backandforth; Assert(tp); + backandforth = ParseAttribute(mapping, ARRAY_LENGTH(mapping), tp, + "backandforth", DBACKANDFORTH_OFF); + settings.desktopBackAndForth = backandforth; + width = FindAttribute(tp->attributes, WIDTH_ATTRIBUTE); if(width != NULL) { settings.desktopWidth = ParseUnsigned(tp, width); diff --git a/src/settings.c b/src/settings.c index 1a5d7c35..b057519c 100644 --- a/src/settings.c +++ b/src/settings.c @@ -51,6 +51,7 @@ void InitializeSettings(void) settings.titleTextAlignment = ALIGN_LEFT; settings.desktopWidth = 4; settings.desktopHeight = 1; + settings.desktopBackAndForth = DBACKANDFORTH_OFF; settings.menuOpacity = UINT_MAX; settings.windowDecorations = DECO_FLAT; settings.trayDecorations = DECO_FLAT; diff --git a/src/settings.h b/src/settings.h index 6df8b49f..cb7733b2 100644 --- a/src/settings.h +++ b/src/settings.h @@ -79,6 +79,11 @@ typedef unsigned char MouseContextType; #define MC_BORDER_E 0x40 /**< East border. */ #define MC_BORDER_W 0x80 /**< West border. */ +/** Enumeration of desktop back and forth values. */ +typedef unsigned char DesktopBackAndForthType; +#define DBACKANDFORTH_OFF 0 /**< No back and forth */ +#define DBACKANDFORTH_ON 1 /**< Enable back and forth */ + /** Maximimum number of title bar components * For now, we allow each component to be used twice. */ #define TBC_COUNT 9 @@ -117,6 +122,7 @@ typedef struct { MouseContextType titleBarLayout[TBC_COUNT + 1]; char groupTasks; char listAllTasks; + DesktopBackAndForthType desktopBackAndForth; } Settings; extern Settings settings;