Two arrays of gaps are stored in pertag, switchable by toggle_gaps
With this commit, each tag has two gap values (indexes at `gaps_previous`, `gaps_current`) that can be interchanged via `toggle_gaps`. At initialisation, `gaps_previous` is set to `default_gaps` and `gaps_current` is set to all 0.
This commit is contained in:
22
config.h
22
config.h
@@ -8,8 +8,7 @@
|
|||||||
/* appearance */
|
/* appearance */
|
||||||
static const unsigned int borderpx = 0; /* border pixel of windows */
|
static const unsigned int borderpx = 0; /* border pixel of windows */
|
||||||
static const unsigned int snap = 32; /* snap pixel */
|
static const unsigned int snap = 32; /* snap pixel */
|
||||||
static const unsigned int optional_gaps = 20; /* optional gaps between windows */
|
static const int default_gaps = 20; /* default value of gaps_previous */
|
||||||
static const unsigned int default_gaps = 0; /* default gaps between windows */
|
|
||||||
static const int showbar = true; /* 0 means no bar */
|
static const int showbar = true; /* 0 means no bar */
|
||||||
static const int topbar = 0; /* 0 means bottom bar */
|
static const int topbar = 0; /* 0 means bottom bar */
|
||||||
static const char *fonts[] = { "Noto Sans Mono:size=13" };
|
static const char *fonts[] = { "Noto Sans Mono:size=13" };
|
||||||
@@ -173,14 +172,15 @@ static const Button buttons[] = {
|
|||||||
void
|
void
|
||||||
togglegaps(const Arg *arg)
|
togglegaps(const Arg *arg)
|
||||||
{
|
{
|
||||||
if (!selmon)
|
if (!selmon)
|
||||||
return;
|
return;
|
||||||
int *gap_size = &selmon->pertag->gaps[selmon->pertag->curtag];
|
int *gaps_current = selmon->pertag->gaps_current + selmon->pertag->curtag;
|
||||||
if (*gap_size == default_gaps)
|
int *gaps_previous = selmon->pertag->gaps_previous + selmon->pertag->curtag;
|
||||||
selmon->pertag->gaps[selmon->pertag->curtag] = optional_gaps;
|
// Swap the current gaps and the previous gaps
|
||||||
else
|
int temp = *gaps_current;
|
||||||
selmon->pertag->gaps[selmon->pertag->curtag] = default_gaps;
|
*gaps_current = *gaps_previous;
|
||||||
arrange(selmon);
|
*gaps_previous = temp;
|
||||||
|
arrange(selmon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -190,7 +190,7 @@ printgaps(const Arg *arg)
|
|||||||
return;
|
return;
|
||||||
char *cmd = malloc(sizeof(*cmd) * 38);
|
char *cmd = malloc(sizeof(*cmd) * 38);
|
||||||
sprintf(cmd, "notify-send -u low \"Gaps=%d\"",
|
sprintf(cmd, "notify-send -u low \"Gaps=%d\"",
|
||||||
selmon->pertag->gaps[selmon->pertag->curtag]);
|
selmon->pertag->gaps_current[selmon->pertag->curtag]);
|
||||||
system(cmd);
|
system(cmd);
|
||||||
free(cmd);
|
free(cmd);
|
||||||
}
|
}
|
||||||
|
|||||||
38
dwm.c
38
dwm.c
@@ -287,13 +287,14 @@ static Window root, wmcheckwin;
|
|||||||
// TODO: Figure out if there is a better way of doing this
|
// TODO: Figure out if there is a better way of doing this
|
||||||
#define TAG_SIZE 9
|
#define TAG_SIZE 9
|
||||||
struct Pertag {
|
struct Pertag {
|
||||||
unsigned int curtag, prevtag; /* current and previous tag */
|
unsigned int curtag, prevtag; /* current and previous tag */
|
||||||
int nmasters[TAG_SIZE + 1]; /* number of windows in master area */
|
int nmasters[TAG_SIZE + 1]; /* number of windows in master area */
|
||||||
float mfacts[TAG_SIZE + 1]; /* mfacts per tag */
|
float mfacts[TAG_SIZE + 1]; /* mfacts per tag */
|
||||||
unsigned int sellts[TAG_SIZE + 1]; /* selected layouts */
|
unsigned int sellts[TAG_SIZE + 1]; /* selected layouts */
|
||||||
const Layout *ltidxs[TAG_SIZE + 1][2]; /* matrix of tags and layouts indexes */
|
const Layout *ltidxs[TAG_SIZE + 1][2]; /* matrix of tags and layouts indexes */
|
||||||
int showbars[TAG_SIZE + 1]; /* display bar for the current tag */
|
int showbars[TAG_SIZE + 1]; /* display bar for the current tag */
|
||||||
int gaps[TAG_SIZE + 1]; /* current size of gaps */
|
int gaps_current[TAG_SIZE + 1]; /* current size of gaps */
|
||||||
|
int gaps_previous[TAG_SIZE + 1]; /* previous size of gaps */
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@@ -719,14 +720,15 @@ createmon(void)
|
|||||||
|
|
||||||
for (i = 0; i <= LENGTH(tags); i++) {
|
for (i = 0; i <= LENGTH(tags); i++) {
|
||||||
m->pertag->nmasters[i] = m->nmaster;
|
m->pertag->nmasters[i] = m->nmaster;
|
||||||
m->pertag->mfacts[i] = m->mfact;
|
m->pertag->mfacts[i] = m->mfact;
|
||||||
|
|
||||||
m->pertag->ltidxs[i][0] = m->lt[0];
|
m->pertag->ltidxs[i][0] = m->lt[0];
|
||||||
m->pertag->ltidxs[i][1] = m->lt[1];
|
m->pertag->ltidxs[i][1] = m->lt[1];
|
||||||
m->pertag->sellts[i] = m->sellt;
|
m->pertag->sellts[i] = m->sellt;
|
||||||
|
|
||||||
m->pertag->showbars[i] = m->showbar;
|
m->pertag->showbars[i] = m->showbar;
|
||||||
m->pertag->gaps[i] = default_gaps;
|
m->pertag->gaps_current[i] = 0;
|
||||||
|
m->pertag->gaps_previous[i] = default_gaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
@@ -760,7 +762,7 @@ deck(Monitor *m) {
|
|||||||
ns = 1;
|
ns = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
gap_size = m->pertag->gaps[m->pertag->curtag];
|
gap_size = m->pertag->gaps_current[m->pertag->curtag];
|
||||||
for(i = 0, my = gap_size, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
|
for(i = 0, my = gap_size, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
|
||||||
if(i < m->nmaster) {
|
if(i < m->nmaster) {
|
||||||
h = (m->wh - my) / (MIN(n, m->nmaster) - i) - gap_size;
|
h = (m->wh - my) / (MIN(n, m->nmaster) - i) - gap_size;
|
||||||
@@ -1252,7 +1254,7 @@ monocle(Monitor *m)
|
|||||||
n++;
|
n++;
|
||||||
if (n > 0) /* override layout symbol */
|
if (n > 0) /* override layout symbol */
|
||||||
snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n);
|
snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n);
|
||||||
const int gap_size = m->pertag->gaps[m->pertag->curtag];
|
const int gap_size = m->pertag->gaps_current[m->pertag->curtag];
|
||||||
for (c = nexttiled(m->clients); c; c = nexttiled(c->next))
|
for (c = nexttiled(m->clients); c; c = nexttiled(c->next))
|
||||||
resize(c, m->wx + gap_size, m->wy + gap_size,
|
resize(c, m->wx + gap_size, m->wy + gap_size,
|
||||||
m->ww - 2 * c->bw - (2 * gap_size),
|
m->ww - 2 * c->bw - (2 * gap_size),
|
||||||
@@ -1661,11 +1663,11 @@ setsticky(Client *c, int sticky)
|
|||||||
void
|
void
|
||||||
setgaps(const Arg *arg)
|
setgaps(const Arg *arg)
|
||||||
{
|
{
|
||||||
int *gap_size = &selmon->pertag->gaps[selmon->pertag->curtag];
|
int *gaps_current = selmon->pertag->gaps_current + selmon->pertag->curtag;
|
||||||
if ((arg->i == 0) || ((*gap_size) + arg->i < 0))
|
if ((arg->i == 0) || (*gaps_current + arg->i < 0))
|
||||||
*gap_size = 0;
|
*gaps_current = 0;
|
||||||
else
|
else
|
||||||
*gap_size += arg->i;
|
*gaps_current += arg->i;
|
||||||
arrange(selmon);
|
arrange(selmon);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1855,7 +1857,7 @@ tile(Monitor *m)
|
|||||||
if (n == 0)
|
if (n == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const int gap_size = m->pertag->gaps[m->pertag->curtag];
|
const int gap_size = m->pertag->gaps_current[m->pertag->curtag];
|
||||||
if (n > m->nmaster)
|
if (n > m->nmaster)
|
||||||
mw = m->nmaster ? m->ww * m->mfact : 0;
|
mw = m->nmaster ? m->ww * m->mfact : 0;
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ gaplessgrid(Monitor *m) {
|
|||||||
cols = 2;
|
cols = 2;
|
||||||
rows = n/cols;
|
rows = n/cols;
|
||||||
|
|
||||||
const int gap_size = m->pertag->gaps[m->pertag->curtag];
|
const int gap_size = m->pertag->gaps_current[m->pertag->curtag];
|
||||||
/* window geometries */
|
/* window geometries */
|
||||||
cw = cols ? m->ww / cols : m->ww;
|
cw = cols ? m->ww / cols : m->ww;
|
||||||
cn = 0; /* current column number */
|
cn = 0; /* current column number */
|
||||||
|
|||||||
Reference in New Issue
Block a user