Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backandforth attribute to Desktops tag #558

Merged
merged 1 commit into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions jwm.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
1 change: 1 addition & 0 deletions src/desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ void ChangeDesktop(unsigned int desktop)
}
}

previousDesktop = currentDesktop;
currentDesktop = desktop;

SetCardinalAtom(rootWindow, ATOM_NET_CURRENT_DESKTOP, currentDesktop);
Expand Down
8 changes: 7 additions & 1 deletion src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ char initializing = 0;
char shouldReload = 0;

unsigned int currentDesktop = 0;
unsigned int previousDesktop = 0;

char *exitCommand = NULL;

Expand Down
1 change: 1 addition & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern Atom managerSelection;
extern char *exitCommand;

extern unsigned int currentDesktop;
extern unsigned int previousDesktop;

extern char shouldExit;
extern char shouldRestart;
Expand Down
11 changes: 10 additions & 1 deletion src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -117,6 +122,7 @@ typedef struct {
MouseContextType titleBarLayout[TBC_COUNT + 1];
char groupTasks;
char listAllTasks;
DesktopBackAndForthType desktopBackAndForth;
} Settings;

extern Settings settings;
Expand Down