first commit
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
void
|
||||
runautostart(void)
|
||||
{
|
||||
char *pathpfx;
|
||||
char *path;
|
||||
char *xdgdatahome;
|
||||
char *home;
|
||||
|
||||
if ((home = getenv("HOME")) == NULL)
|
||||
/* this is almost impossible */
|
||||
return;
|
||||
|
||||
/* if $XDG_DATA_HOME is defined, use $XDG_DATA_HOME/dwm,
|
||||
* otherwise use ~/.local/share/dwm as autostart script directory
|
||||
*/
|
||||
if ((xdgdatahome = getenv("XDG_DATA_HOME")) != NULL) {
|
||||
/* space for path segments, separators and nul */
|
||||
if ((pathpfx = malloc(strlen(xdgdatahome) + strlen(dwmdir) + 2)) == NULL)
|
||||
return;
|
||||
|
||||
if (sprintf(pathpfx, "%s/%s", xdgdatahome, dwmdir) <= 0) {
|
||||
free(pathpfx);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
/* space for path segments, separators and nul */
|
||||
if ((pathpfx = malloc(strlen(home) + strlen(localshare) + strlen(dwmdir) + 3)) == NULL)
|
||||
return;
|
||||
|
||||
if (sprintf(pathpfx, "%s/%s/%s", home, localshare, dwmdir) < 0) {
|
||||
free(pathpfx);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* check if the autostart script directory exists */
|
||||
struct stat sb;
|
||||
|
||||
if (! (stat(pathpfx, &sb) == 0 && S_ISDIR(sb.st_mode))) {
|
||||
/* the XDG conformant path does not exist or are not directories
|
||||
* so we try ~/.dwm instead
|
||||
*/
|
||||
if (realloc(pathpfx, strlen(home) + strlen(dwmdir) + 3) == NULL) {
|
||||
free(pathpfx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sprintf(pathpfx, "%s/.%s", home, dwmdir) <= 0) {
|
||||
free(pathpfx);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* try the blocking script first */
|
||||
if ((path = malloc(strlen(pathpfx) + strlen(autostartblocksh) + 2)) == NULL) {
|
||||
free(pathpfx);
|
||||
return;
|
||||
} else
|
||||
if (sprintf(path, "%s/%s", pathpfx, autostartblocksh) <= 0) {
|
||||
free(path);
|
||||
free(pathpfx);
|
||||
}
|
||||
|
||||
if (access(path, X_OK) == 0)
|
||||
system(path);
|
||||
|
||||
/* now the non-blocking script */
|
||||
if ((path = realloc(path, strlen(pathpfx) + strlen(autostartsh) + 4)) == NULL) {
|
||||
free(pathpfx);
|
||||
free(path);
|
||||
return;
|
||||
} else
|
||||
if (sprintf(path, "%s/%s", pathpfx, autostartsh) <= 0) {
|
||||
free(path);
|
||||
free(pathpfx);
|
||||
}
|
||||
|
||||
if (access(path, X_OK) == 0) {
|
||||
system(strcat(path, " &"));
|
||||
free(pathpfx);
|
||||
free(path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
static void runautostart(void);
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
static int useargb = 0;
|
||||
static Visual *visual;
|
||||
static int depth;
|
||||
static Colormap cmap;
|
||||
|
||||
void
|
||||
xinitvisual()
|
||||
{
|
||||
XVisualInfo *infos;
|
||||
XRenderPictFormat *fmt;
|
||||
int nitems;
|
||||
int i;
|
||||
|
||||
XVisualInfo tpl = {
|
||||
.screen = screen,
|
||||
.depth = 32,
|
||||
.class = TrueColor
|
||||
};
|
||||
long masks = VisualScreenMask | VisualDepthMask | VisualClassMask;
|
||||
|
||||
infos = XGetVisualInfo(dpy, masks, &tpl, &nitems);
|
||||
visual = NULL;
|
||||
for (i = 0; i < nitems; i ++) {
|
||||
fmt = XRenderFindVisualFormat(dpy, infos[i].visual);
|
||||
if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
|
||||
visual = infos[i].visual;
|
||||
depth = infos[i].depth;
|
||||
cmap = XCreateColormap(dpy, root, visual, AllocNone);
|
||||
useargb = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
XFree(infos);
|
||||
|
||||
if (!visual) {
|
||||
visual = DefaultVisual(dpy, screen);
|
||||
depth = DefaultDepth(dpy, screen);
|
||||
cmap = DefaultColormap(dpy, screen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
#define OPAQUE 0xffU
|
||||
|
||||
static void xinitvisual();
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
static int statussig;
|
||||
pid_t statuspid = -1;
|
||||
|
||||
pid_t
|
||||
getstatusbarpid()
|
||||
{
|
||||
char buf[32], *str = buf, *c;
|
||||
FILE *fp;
|
||||
|
||||
if (statuspid > 0) {
|
||||
snprintf(buf, sizeof(buf), "/proc/%u/cmdline", statuspid);
|
||||
if ((fp = fopen(buf, "r"))) {
|
||||
fgets(buf, sizeof(buf), fp);
|
||||
while ((c = strchr(str, '/')))
|
||||
str = c + 1;
|
||||
fclose(fp);
|
||||
if (!strcmp(str, STATUSBAR))
|
||||
return statuspid;
|
||||
}
|
||||
}
|
||||
if (!(fp = popen("pgrep -o "STATUSBAR, "r")))
|
||||
return -1;
|
||||
fgets(buf, sizeof(buf), fp);
|
||||
pclose(fp);
|
||||
return strtol(buf, NULL, 10);
|
||||
}
|
||||
|
||||
void
|
||||
sigstatusbar(const Arg *arg)
|
||||
{
|
||||
union sigval sv;
|
||||
|
||||
if (!statussig)
|
||||
return;
|
||||
if ((statuspid = getstatusbarpid()) <= 0)
|
||||
return;
|
||||
|
||||
sv.sival_int = arg->i;
|
||||
sigqueue(statuspid, SIGRTMIN+statussig, sv);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
static int getstatusbarpid();
|
||||
static void sigstatusbar(const Arg *arg);
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
void
|
||||
setcurrentdesktop(void)
|
||||
{
|
||||
long data[] = { 0 };
|
||||
XChangeProperty(dpy, root, netatom[NetCurrentDesktop], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)data, 1);
|
||||
}
|
||||
|
||||
void
|
||||
setdesktopnames(void)
|
||||
{
|
||||
int i;
|
||||
XTextProperty text;
|
||||
char *tags[NUMTAGS];
|
||||
for (i = 0; i < NUMTAGS; i++)
|
||||
tags[i] = tagicon(selmon, i);
|
||||
Xutf8TextListToTextProperty(dpy, tags, NUMTAGS, XUTF8StringStyle, &text);
|
||||
XSetTextProperty(dpy, root, &text, netatom[NetDesktopNames]);
|
||||
}
|
||||
|
||||
void
|
||||
setfloatinghint(Client *c)
|
||||
{
|
||||
Atom target = XInternAtom(dpy, "_IS_FLOATING", 0);
|
||||
unsigned int floating[1] = {c->isfloating};
|
||||
XChangeProperty(dpy, c->win, target, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)floating, 1);
|
||||
}
|
||||
|
||||
void
|
||||
setnumdesktops(void)
|
||||
{
|
||||
long data[] = { NUMTAGS };
|
||||
XChangeProperty(dpy, root, netatom[NetNumberOfDesktops], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)data, 1);
|
||||
}
|
||||
|
||||
void
|
||||
setviewport(void)
|
||||
{
|
||||
long data[] = { 0, 0 };
|
||||
XChangeProperty(dpy, root, netatom[NetDesktopViewport], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)data, 2);
|
||||
}
|
||||
|
||||
void
|
||||
updatecurrentdesktop(void)
|
||||
{
|
||||
long rawdata[] = { selmon->tagset[selmon->seltags] };
|
||||
int i = 0;
|
||||
while (*rawdata >> (i + 1)) {
|
||||
i++;
|
||||
}
|
||||
long data[] = { i };
|
||||
XChangeProperty(dpy, root, netatom[NetCurrentDesktop], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)data, 1);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
static void setcurrentdesktop(void);
|
||||
static void setdesktopnames(void);
|
||||
static void setfloatinghint(Client *c);
|
||||
static void setnumdesktops(void);
|
||||
static void setviewport(void);
|
||||
static void updatecurrentdesktop(void);
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
/* Indicator properties, you can override these in your config.h if you want. */
|
||||
#ifndef TAGSINDICATOR
|
||||
#define TAGSINDICATOR 1 // 0 = off, 1 = on if >1 client/view tag, 2 = always on
|
||||
#endif
|
||||
#ifndef TAGSPX
|
||||
#define TAGSPX 5 // # pixels for tag grid boxes
|
||||
#endif
|
||||
#ifndef TAGSROWS
|
||||
#define TAGSROWS 3 // # rows in tag grid (9 tags, e.g. 3x3)
|
||||
#endif
|
||||
|
||||
void
|
||||
drawindicator(Monitor *m, Client *c, unsigned int occ, int x, int y, int w, int h, unsigned int tag, int filled, int invert, int type)
|
||||
{
|
||||
int i, boxw, boxs, indn = 0;
|
||||
if (!(occ & 1 << tag) || type == INDICATOR_NONE)
|
||||
return;
|
||||
|
||||
boxs = drw->fonts->h / 9;
|
||||
boxw = drw->fonts->h / 6 + 2;
|
||||
if (filled == -1)
|
||||
filled = m == selmon && m->sel && m->sel->tags & 1 << tag;
|
||||
|
||||
switch (type) {
|
||||
default:
|
||||
case INDICATOR_TOP_LEFT_SQUARE:
|
||||
drw_rect(drw, x + boxs, y + boxs, boxw, boxw, filled, invert);
|
||||
break;
|
||||
case INDICATOR_TOP_LEFT_LARGER_SQUARE:
|
||||
drw_rect(drw, x + boxs + 2, y + boxs+1, boxw+1, boxw+1, filled, invert);
|
||||
break;
|
||||
case INDICATOR_TOP_BAR:
|
||||
drw_rect(drw, x + boxw, y, w - ( 2 * boxw + 1), boxw/2, filled, invert);
|
||||
break;
|
||||
case INDICATOR_TOP_BAR_SLIM:
|
||||
drw_rect(drw, x + boxw, y, w - ( 2 * boxw + 1), 1, 0, invert);
|
||||
break;
|
||||
case INDICATOR_BOTTOM_BAR:
|
||||
drw_rect(drw, x + boxw, y + h - boxw/2, w - ( 2 * boxw + 1), boxw/2, filled, invert);
|
||||
break;
|
||||
case INDICATOR_BOTTOM_BAR_SLIM:
|
||||
drw_rect(drw, x + boxw, y + h - 1, w - ( 2 * boxw + 1), 1, 0, invert);
|
||||
break;
|
||||
case INDICATOR_BOX:
|
||||
drw_rect(drw, x + boxw, y, w - 2 * boxw, h, 0, invert);
|
||||
break;
|
||||
case INDICATOR_BOX_WIDER:
|
||||
drw_rect(drw, x + boxw/2, y, w - boxw, h, 0, invert);
|
||||
break;
|
||||
case INDICATOR_BOX_FULL:
|
||||
drw_rect(drw, x, y, w - 2, h, 0, invert);
|
||||
break;
|
||||
case INDICATOR_CLIENT_DOTS:
|
||||
for (c = m->clients; c; c = c->next) {
|
||||
if (c->tags & (1 << tag)) {
|
||||
drw_rect(drw, x, 1 + (indn * 2), m->sel == c ? 6 : 1, 1, 1, invert);
|
||||
indn++;
|
||||
}
|
||||
if (h <= 1 + (indn * 2)) {
|
||||
indn = 0;
|
||||
x += 2;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case INDICATOR_RIGHT_TAGS:
|
||||
if (!c)
|
||||
break;
|
||||
for (i = 0; i < NUMTAGS; i++) {
|
||||
drw_rect(drw,
|
||||
( x + w - 2 - ((NUMTAGS / TAGSROWS) * TAGSPX)
|
||||
- (i % (NUMTAGS/TAGSROWS)) + ((i % (NUMTAGS / TAGSROWS)) * TAGSPX)
|
||||
),
|
||||
( y + 2 + ((i / (NUMTAGS/TAGSROWS)) * TAGSPX)
|
||||
- ((i / (NUMTAGS/TAGSROWS)))
|
||||
),
|
||||
TAGSPX, TAGSPX, (c->tags >> i) & 1, 0
|
||||
);
|
||||
}
|
||||
break;
|
||||
case INDICATOR_PLUS_AND_LARGER_SQUARE:
|
||||
boxs += 2;
|
||||
boxw += 2;
|
||||
/* falls through */
|
||||
case INDICATOR_PLUS_AND_SQUARE:
|
||||
drw_rect(drw, x + boxs, y + boxs, boxw % 2 ? boxw : boxw + 1, boxw % 2 ? boxw : boxw + 1, filled, invert);
|
||||
/* falls through */
|
||||
case INDICATOR_PLUS:
|
||||
if (!(boxw % 2))
|
||||
boxw += 1;
|
||||
drw_rect(drw, x + boxs + boxw / 2, y + boxs, 1, boxw, filled, invert); // |
|
||||
drw_rect(drw, x + boxs, y + boxs + boxw / 2, boxw + 1, 1, filled, invert); // ‒
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
drawstateindicator(Monitor *m, Client *c, unsigned int occ, int x, int y, int w, int h, unsigned int tag, int filled, int invert)
|
||||
{
|
||||
if (c->fakefullscreen && c->isfloating)
|
||||
drawindicator(m, c, occ, x, y, w, h, tag, filled, invert, floatfakefsindicatortype);
|
||||
else if (c->fakefullscreen)
|
||||
drawindicator(m, c, occ, x, y, w, h, tag, filled, invert, fakefsindicatortype);
|
||||
else
|
||||
if (c->isfloating)
|
||||
drawindicator(m, c, occ, x, y, w, h, tag, filled, invert, floatindicatortype);
|
||||
else
|
||||
drawindicator(m, c, occ, x, y, w, h, tag, filled, invert, tiledindicatortype);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
enum {
|
||||
INDICATOR_NONE,
|
||||
INDICATOR_TOP_LEFT_SQUARE,
|
||||
INDICATOR_TOP_LEFT_LARGER_SQUARE,
|
||||
INDICATOR_TOP_BAR,
|
||||
INDICATOR_TOP_BAR_SLIM,
|
||||
INDICATOR_BOTTOM_BAR,
|
||||
INDICATOR_BOTTOM_BAR_SLIM,
|
||||
INDICATOR_BOX,
|
||||
INDICATOR_BOX_WIDER,
|
||||
INDICATOR_BOX_FULL,
|
||||
INDICATOR_CLIENT_DOTS,
|
||||
INDICATOR_RIGHT_TAGS,
|
||||
INDICATOR_PLUS,
|
||||
INDICATOR_PLUS_AND_SQUARE,
|
||||
INDICATOR_PLUS_AND_LARGER_SQUARE,
|
||||
};
|
||||
|
||||
static void drawindicator(Monitor *m, Client *c, unsigned int occ, int x, int y, int w, int h, unsigned int tag, int filled, int invert, int type);
|
||||
static void drawstateindicator(Monitor *m, Client *c, unsigned int occ, int x, int y, int w, int h, unsigned int tag, int filled, int invert);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
int
|
||||
width_ltsymbol(Bar *bar, BarArg *a)
|
||||
{
|
||||
return TEXTW(bar->mon->ltsymbol);
|
||||
}
|
||||
|
||||
int
|
||||
draw_ltsymbol(Bar *bar, BarArg *a)
|
||||
{
|
||||
return drw_text(drw, a->x, a->y, a->w, a->h, lrpad / 2, bar->mon->ltsymbol, 0, False);
|
||||
}
|
||||
|
||||
int
|
||||
click_ltsymbol(Bar *bar, Arg *arg, BarArg *a)
|
||||
{
|
||||
return ClkLtSymbol;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
static int width_ltsymbol(Bar *bar, BarArg *a);
|
||||
static int draw_ltsymbol(Bar *bar, BarArg *a);
|
||||
static int click_ltsymbol(Bar *bar, Arg *arg, BarArg *a);
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
int
|
||||
width_pwrl_tags(Bar *bar, BarArg *a)
|
||||
{
|
||||
int w, i;
|
||||
int plw = drw->fonts->h / 2 + 1;
|
||||
Client *c;
|
||||
unsigned int occ = 0;
|
||||
for (c = bar->mon->clients; c; c = c->next)
|
||||
occ |= c->tags == 255 ? 0 : c->tags;
|
||||
|
||||
for (w = 0, i = 0; i < NUMTAGS; i++) {
|
||||
if (!(occ & 1 << i || bar->mon->tagset[bar->mon->seltags] & 1 << i))
|
||||
continue;
|
||||
w += TEXTW(tagicon(bar->mon, i)) + plw;
|
||||
}
|
||||
return w + lrpad;
|
||||
}
|
||||
|
||||
int
|
||||
draw_pwrl_tags(Bar *bar, BarArg *a)
|
||||
{
|
||||
int x, w;
|
||||
int invert;
|
||||
int plw = drw->fonts->h / 2 + 1;
|
||||
unsigned int i, occ = 0, urg = 0;
|
||||
char *icon;
|
||||
Client *c;
|
||||
Clr *prevscheme, *nxtscheme;
|
||||
|
||||
for (c = bar->mon->clients; c; c = c->next) {
|
||||
occ |= c->tags == 255 ? 0 : c->tags;
|
||||
if (c->isurgent)
|
||||
urg |= c->tags;
|
||||
}
|
||||
x = a->x;
|
||||
prevscheme = scheme[SchemeNorm];
|
||||
for (i = 0; i < NUMTAGS; i++) {
|
||||
/* do not draw vacant tags */
|
||||
if (!(occ & 1 << i || bar->mon->tagset[bar->mon->seltags] & 1 << i))
|
||||
continue;
|
||||
|
||||
icon = tagicon(bar->mon, i);
|
||||
invert = 0;
|
||||
w = TEXTW(icon);
|
||||
if (urg & 1 << i) {
|
||||
drw_settrans(drw, prevscheme, (nxtscheme = scheme[bar->mon->tagset[bar->mon->seltags] & 1 << i ? SchemeSel : SchemeUrg]));
|
||||
} else {
|
||||
drw_settrans(drw, prevscheme, (nxtscheme = scheme[bar->mon->tagset[bar->mon->seltags] & 1 << i ? SchemeSel : SchemeNorm]));
|
||||
}
|
||||
drw_arrow(drw, x, a->y, plw, a->h, 1, 1);
|
||||
x += plw;
|
||||
drw_setscheme(drw, nxtscheme);
|
||||
drw_text(drw, x, a->y, w, a->h, lrpad / 2, icon, invert, False);
|
||||
drawindicator(bar->mon, NULL, occ, x, a->y, w, a->h, i, -1, invert, tagindicatortype);
|
||||
x += w;
|
||||
prevscheme = nxtscheme;
|
||||
}
|
||||
nxtscheme = scheme[SchemeNorm];
|
||||
|
||||
drw_settrans(drw, prevscheme, nxtscheme);
|
||||
drw_arrow(drw, x, a->y, plw, a->h, 1, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
click_pwrl_tags(Bar *bar, Arg *arg, BarArg *a)
|
||||
{
|
||||
int i = 0, x = lrpad / 2;
|
||||
int plw = drw->fonts->h / 2 + 1;
|
||||
Client *c;
|
||||
unsigned int occ = 0;
|
||||
for (c = bar->mon->clients; c; c = c->next)
|
||||
occ |= c->tags == 255 ? 0 : c->tags;
|
||||
|
||||
do {
|
||||
if (!(occ & 1 << i || bar->mon->tagset[bar->mon->seltags] & 1 << i))
|
||||
continue;
|
||||
x += TEXTW(tagicon(bar->mon, i)) + plw;
|
||||
} while (a->x >= x && ++i < NUMTAGS);
|
||||
if (i < NUMTAGS) {
|
||||
arg->ui = 1 << i;
|
||||
}
|
||||
return ClkTagBar;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
static int width_pwrl_tags(Bar *bar, BarArg *a);
|
||||
static int draw_pwrl_tags(Bar *bar, BarArg *a);
|
||||
static int click_pwrl_tags(Bar *bar, Arg *arg, BarArg *a);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
int
|
||||
width_status(Bar *bar, BarArg *a)
|
||||
{
|
||||
return TEXTWM(stext);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
draw_status(Bar *bar, BarArg *a)
|
||||
{
|
||||
return drw_text(drw, a->x, a->y, a->w, a->h, lrpad / 2, stext, 0, True);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
click_status(Bar *bar, Arg *arg, BarArg *a)
|
||||
{
|
||||
return ClkStatusText;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
static int width_status(Bar *bar, BarArg *a);
|
||||
static int draw_status(Bar *bar, BarArg *a);
|
||||
static int click_status(Bar *bar, Arg *arg, BarArg *a);
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
|
||||
int
|
||||
click_statuscmd(Bar *bar, Arg *arg, BarArg *a)
|
||||
{
|
||||
return click_statuscmd_text(arg, a->x, rawstext);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
click_statuscmd_text(Arg *arg, int rel_x, char *text)
|
||||
{
|
||||
int i = -1;
|
||||
int x = 0;
|
||||
char ch;
|
||||
statussig = -1;
|
||||
while (text[++i]) {
|
||||
if ((unsigned char)text[i] < ' ') {
|
||||
ch = text[i];
|
||||
text[i] = '\0';
|
||||
x += TEXTWM(text) - lrpad;
|
||||
text[i] = ch;
|
||||
text += i+1;
|
||||
i = -1;
|
||||
if (x >= rel_x && statussig != -1)
|
||||
break;
|
||||
statussig = ch;
|
||||
}
|
||||
}
|
||||
if (statussig == -1)
|
||||
statussig = 0;
|
||||
return ClkStatusText;
|
||||
}
|
||||
|
||||
void
|
||||
copyvalidchars(char *text, char *rawtext)
|
||||
{
|
||||
int i = -1, j = 0;
|
||||
|
||||
while (rawtext[++i]) {
|
||||
if ((unsigned char)rawtext[i] >= ' ') {
|
||||
text[j++] = rawtext[i];
|
||||
}
|
||||
}
|
||||
text[j] = '\0';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
static int click_statuscmd(Bar *bar, Arg *arg, BarArg *a);
|
||||
static int click_statuscmd_text(Arg *arg, int rel_x, char *text);
|
||||
static void copyvalidchars(char *text, char *rawtext);
|
||||
|
||||
typedef struct {
|
||||
const char *cmd;
|
||||
int id;
|
||||
} StatusCmd;
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
static Systray *systray = NULL;
|
||||
static unsigned long systrayorientation = _NET_SYSTEM_TRAY_ORIENTATION_HORZ;
|
||||
|
||||
int
|
||||
width_systray(Bar *bar, BarArg *a)
|
||||
{
|
||||
unsigned int w = 0;
|
||||
Client *i;
|
||||
if (!systray)
|
||||
return 1;
|
||||
if (showsystray)
|
||||
for (i = systray->icons; i; w += i->w + systrayspacing, i = i->next);
|
||||
return w ? w + lrpad - systrayspacing : 0;
|
||||
}
|
||||
|
||||
int
|
||||
draw_systray(Bar *bar, BarArg *a)
|
||||
{
|
||||
if (!showsystray)
|
||||
return 0;
|
||||
|
||||
XSetWindowAttributes wa;
|
||||
XWindowChanges wc;
|
||||
Client *i;
|
||||
unsigned int w;
|
||||
|
||||
if (!systray) {
|
||||
/* init systray */
|
||||
if (!(systray = (Systray *)calloc(1, sizeof(Systray))))
|
||||
die("fatal: could not malloc() %u bytes\n", sizeof(Systray));
|
||||
|
||||
wa.override_redirect = True;
|
||||
wa.event_mask = ButtonPressMask|ExposureMask;
|
||||
wa.border_pixel = 0;
|
||||
systray->h = MIN(a->h, drw->fonts->h);
|
||||
wa.background_pixel = 0;
|
||||
wa.colormap = cmap;
|
||||
systray->win = XCreateWindow(dpy, root, bar->bx + a->x + lrpad / 2, bar->by + a->y + (a->h - systray->h) / 2, MAX(a->w + 40, 1), systray->h, 0, depth,
|
||||
InputOutput, visual,
|
||||
CWOverrideRedirect|CWBorderPixel|CWBackPixel|CWColormap|CWEventMask, &wa); // CWBackPixmap
|
||||
|
||||
XSelectInput(dpy, systray->win, SubstructureNotifyMask);
|
||||
XChangeProperty(dpy, systray->win, netatom[NetSystemTrayOrientation], XA_CARDINAL, 32,
|
||||
PropModeReplace, (unsigned char *)&systrayorientation, 1);
|
||||
XChangeProperty(dpy, systray->win, netatom[NetSystemTrayVisual], XA_VISUALID, 32,
|
||||
PropModeReplace, (unsigned char *)&visual->visualid, 1);
|
||||
XChangeProperty(dpy, systray->win, netatom[NetWMWindowType], XA_ATOM, 32,
|
||||
PropModeReplace, (unsigned char *)&netatom[NetWMWindowTypeDock], 1);
|
||||
XMapRaised(dpy, systray->win);
|
||||
XSetSelectionOwner(dpy, netatom[NetSystemTray], systray->win, CurrentTime);
|
||||
if (XGetSelectionOwner(dpy, netatom[NetSystemTray]) == systray->win) {
|
||||
sendevent(root, xatom[Manager], StructureNotifyMask, CurrentTime, netatom[NetSystemTray], systray->win, 0, 0);
|
||||
XSync(dpy, False);
|
||||
} else {
|
||||
fprintf(stderr, "dwm: unable to obtain system tray.\n");
|
||||
free(systray);
|
||||
systray = NULL;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
systray->bar = bar;
|
||||
|
||||
wc.stack_mode = Above;
|
||||
wc.sibling = bar->win;
|
||||
XConfigureWindow(dpy, systray->win, CWSibling|CWStackMode, &wc);
|
||||
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
for (w = 0, i = systray->icons; i; i = i->next) {
|
||||
wa.background_pixel = 0;
|
||||
XChangeWindowAttributes(dpy, i->win, CWBackPixel, &wa);
|
||||
XMapRaised(dpy, i->win);
|
||||
i->x = w;
|
||||
XMoveResizeWindow(dpy, i->win, i->x, 0, i->w, i->h);
|
||||
w += i->w;
|
||||
if (i->next)
|
||||
w += systrayspacing;
|
||||
if (i->mon != bar->mon)
|
||||
i->mon = bar->mon;
|
||||
}
|
||||
|
||||
XMoveResizeWindow(dpy, systray->win, bar->bx + a->x + lrpad / 2, (w ? bar->by + a->y + (a->h - systray->h) / 2: -bar->by - a->y), MAX(w, 1), systray->h);
|
||||
return w;
|
||||
}
|
||||
|
||||
int
|
||||
click_systray(Bar *bar, Arg *arg, BarArg *a)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
removesystrayicon(Client *i)
|
||||
{
|
||||
Client **ii;
|
||||
|
||||
if (!showsystray || !i)
|
||||
return;
|
||||
for (ii = &systray->icons; *ii && *ii != i; ii = &(*ii)->next);
|
||||
if (ii)
|
||||
*ii = i->next;
|
||||
free(i);
|
||||
drawbarwin(systray->bar);
|
||||
}
|
||||
|
||||
void
|
||||
resizerequest(XEvent *e)
|
||||
{
|
||||
XResizeRequestEvent *ev = &e->xresizerequest;
|
||||
Client *i;
|
||||
|
||||
if ((i = wintosystrayicon(ev->window))) {
|
||||
updatesystrayicongeom(i, ev->width, ev->height);
|
||||
drawbarwin(systray->bar);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
updatesystrayicongeom(Client *i, int w, int h)
|
||||
{
|
||||
if (!systray)
|
||||
return;
|
||||
|
||||
int icon_height = systray->h;
|
||||
if (i) {
|
||||
i->h = icon_height;
|
||||
if (w == h)
|
||||
i->w = icon_height;
|
||||
else if (h == icon_height)
|
||||
i->w = w;
|
||||
else
|
||||
i->w = (int) ((float)icon_height * ((float)w / (float)h));
|
||||
applysizehints(i, &(i->x), &(i->y), &(i->w), &(i->h), False);
|
||||
/* force icons into the systray dimensions if they don't want to */
|
||||
if (i->h > icon_height) {
|
||||
if (i->w == i->h)
|
||||
i->w = icon_height;
|
||||
else
|
||||
i->w = (int) ((float)icon_height * ((float)i->w / (float)i->h));
|
||||
i->h = icon_height;
|
||||
}
|
||||
if (i->w > 2 * icon_height)
|
||||
i->w = icon_height;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
updatesystrayiconstate(Client *i, XPropertyEvent *ev)
|
||||
{
|
||||
long flags;
|
||||
int code = 0;
|
||||
|
||||
if (!showsystray || !systray || !i || ev->atom != xatom[XembedInfo] ||
|
||||
!(flags = getatomprop(i, xatom[XembedInfo])))
|
||||
return;
|
||||
|
||||
if (flags & XEMBED_MAPPED && !i->tags) {
|
||||
i->tags = 1;
|
||||
code = XEMBED_WINDOW_ACTIVATE;
|
||||
XMapRaised(dpy, i->win);
|
||||
setclientstate(i, NormalState);
|
||||
}
|
||||
else if (!(flags & XEMBED_MAPPED) && i->tags) {
|
||||
i->tags = 0;
|
||||
code = XEMBED_WINDOW_DEACTIVATE;
|
||||
XUnmapWindow(dpy, i->win);
|
||||
setclientstate(i, WithdrawnState);
|
||||
}
|
||||
else
|
||||
return;
|
||||
sendevent(i->win, xatom[Xembed], StructureNotifyMask, CurrentTime, code, 0,
|
||||
systray->win, XEMBED_EMBEDDED_VERSION);
|
||||
}
|
||||
|
||||
Client *
|
||||
wintosystrayicon(Window w)
|
||||
{
|
||||
if (!systray)
|
||||
return NULL;
|
||||
Client *i = NULL;
|
||||
if (!showsystray || !w)
|
||||
return i;
|
||||
for (i = systray->icons; i && i->win != w; i = i->next);
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#define SYSTEM_TRAY_REQUEST_DOCK 0
|
||||
#define _NET_SYSTEM_TRAY_ORIENTATION_HORZ 0
|
||||
|
||||
/* XEMBED messages */
|
||||
#define XEMBED_EMBEDDED_NOTIFY 0
|
||||
#define XEMBED_WINDOW_ACTIVATE 1
|
||||
#define XEMBED_FOCUS_IN 4
|
||||
#define XEMBED_MODALITY_ON 10
|
||||
|
||||
#define XEMBED_MAPPED (1 << 0)
|
||||
#define XEMBED_WINDOW_ACTIVATE 1
|
||||
#define XEMBED_WINDOW_DEACTIVATE 2
|
||||
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 0
|
||||
#define XEMBED_EMBEDDED_VERSION (VERSION_MAJOR << 16) | VERSION_MINOR
|
||||
|
||||
/* enums */
|
||||
enum { Manager, Xembed, XembedInfo, XLast }; /* Xembed atoms */
|
||||
|
||||
typedef struct Systray Systray;
|
||||
struct Systray {
|
||||
Window win;
|
||||
Client *icons;
|
||||
Bar *bar;
|
||||
int h;
|
||||
};
|
||||
|
||||
/* bar integration */
|
||||
static int width_systray(Bar *bar, BarArg *a);
|
||||
static int draw_systray(Bar *bar, BarArg *a);
|
||||
static int click_systray(Bar *bar, Arg *arg, BarArg *a);
|
||||
|
||||
/* function declarations */
|
||||
static Atom getatomprop(Client *c, Atom prop);
|
||||
static void removesystrayicon(Client *i);
|
||||
static void resizerequest(XEvent *e);
|
||||
static void updatesystrayicongeom(Client *i, int w, int h);
|
||||
static void updatesystrayiconstate(Client *i, XPropertyEvent *ev);
|
||||
static Client *wintosystrayicon(Window w);
|
||||
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
/* Bartabgroups properties, you can override these in your config.h if you want. */
|
||||
#ifndef BARTAB_BORDERS
|
||||
#define BARTAB_BORDERS 1 // 0 = off, 1 = on
|
||||
#endif
|
||||
#ifndef BARTAB_SHOWFLOATING
|
||||
#define BARTAB_SHOWFLOATING 0 // whether to show titles for floating windows, hidden clients are always shown
|
||||
#endif
|
||||
#ifndef BARTAB_STACKWEIGHT
|
||||
#define BARTAB_STACKWEIGHT 1 // stack weight compared to hidden and floating window titles
|
||||
#endif
|
||||
#ifndef BARTAB_HIDDENWEIGHT
|
||||
#define BARTAB_HIDDENWEIGHT 1 // hidden window title weight
|
||||
#endif
|
||||
#ifndef BARTAB_FLOATWEIGHT
|
||||
#define BARTAB_FLOATWEIGHT 1 // floating window title weight, set to 0 to not show floating windows
|
||||
#endif
|
||||
|
||||
int
|
||||
width_bartabgroups(Bar *bar, BarArg *a)
|
||||
{
|
||||
return a->w;
|
||||
}
|
||||
|
||||
int
|
||||
draw_bartabgroups(Bar *bar, BarArg *a)
|
||||
{
|
||||
drw_rect(drw, a->x, a->y, a->w, a->h, 1, 1);
|
||||
return bartabcalculate(bar->mon, a->x, a->w, -1, bartabdraw, NULL, a);
|
||||
}
|
||||
|
||||
int
|
||||
click_bartabgroups(Bar *bar, Arg *arg, BarArg *a)
|
||||
{
|
||||
bartabcalculate(bar->mon, 0, a->w, a->x, bartabclick, arg, a);
|
||||
return ClkWinTitle;
|
||||
}
|
||||
|
||||
void
|
||||
bartabdraw(Monitor *m, Client *c, int unused, int x, int w, int groupactive, Arg *arg, BarArg *barg)
|
||||
{
|
||||
if (!c)
|
||||
return;
|
||||
int i, nclienttags = 0, nviewtags = 0, pad = lrpad / 2;
|
||||
drw_setscheme(drw, scheme[
|
||||
m->sel == c
|
||||
#ifdef HIDDEN
|
||||
&& HIDDEN(c)
|
||||
? SchemeHidSel
|
||||
: HIDDEN(c)
|
||||
? SchemeHidNorm
|
||||
: m->sel == c
|
||||
#endif
|
||||
? SchemeSel
|
||||
: groupactive
|
||||
? SchemeTitleSel
|
||||
: SchemeTitleNorm
|
||||
]);
|
||||
if (w <= TEXTW("A") - lrpad + pad) // reduce text padding if wintitle is too small
|
||||
pad = (w - TEXTW("A") + lrpad < 0 ? 0 : (w - TEXTW("A") + lrpad) / 2);
|
||||
else if (TEXTW(c->name) < w)
|
||||
pad = (w - TEXTW(c->name) + lrpad) / 2;
|
||||
|
||||
drw_text(drw, x, barg->y, w, barg->h, pad, c->name, 0, False);
|
||||
|
||||
drawstateindicator(m, c, 1, x, barg->y, w, barg->h, 0, 0, c->isfixed);
|
||||
|
||||
if (BARTAB_BORDERS) {
|
||||
XSetForeground(drw->dpy, drw->gc, scheme[SchemeSel][ColBorder].pixel);
|
||||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, barg->y, 1, barg->h);
|
||||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x + w - (x + w >= barg->w ? 1 : 0), barg->y, 1, barg->h);
|
||||
}
|
||||
/* Optional tags icons */
|
||||
for (i = 0; i < NUMTAGS; i++) {
|
||||
if ((m->tagset[m->seltags] >> i) & 1)
|
||||
nviewtags++;
|
||||
if ((c->tags >> i) & 1)
|
||||
nclienttags++;
|
||||
}
|
||||
|
||||
if (TAGSINDICATOR == 2 || nclienttags > 1 || nviewtags > 1)
|
||||
drawindicator(m, c, 1, x, barg->y, w, barg->h, 0, 0, 0, INDICATOR_RIGHT_TAGS);
|
||||
}
|
||||
|
||||
#ifndef HIDDEN
|
||||
#define HIDDEN(C) 0
|
||||
#endif
|
||||
|
||||
void
|
||||
bartabclick(Monitor *m, Client *c, int passx, int x, int w, int unused, Arg *arg, BarArg *barg)
|
||||
{
|
||||
if (passx >= x && passx <= x + w)
|
||||
arg->v = c;
|
||||
}
|
||||
|
||||
int
|
||||
bartabcalculate(
|
||||
Monitor *m, int offx, int tabw, int passx,
|
||||
void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg, BarArg *barg),
|
||||
Arg *arg, BarArg *barg
|
||||
) {
|
||||
Client *c;
|
||||
int
|
||||
i, clientsnmaster = 0, clientsnstack = 0, clientsnfloating = 0, clientsnhidden = 0,
|
||||
masteractive = 0, fulllayout = 0,
|
||||
x = offx, w, r, num = 0, den, tgactive;
|
||||
|
||||
for (i = 0; i < LENGTH(bartabmonfns); i++)
|
||||
if (m ->lt[m->sellt]->arrange == bartabmonfns[i]) {
|
||||
fulllayout = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0, c = m->clients; c; c = c->next) {
|
||||
if (!ISVISIBLE(c))
|
||||
continue;
|
||||
if (HIDDEN(c)) {
|
||||
clientsnhidden++;
|
||||
continue;
|
||||
}
|
||||
if (c->isfloating) {
|
||||
clientsnfloating++;
|
||||
continue;
|
||||
}
|
||||
if (m->sel == c)
|
||||
masteractive = i < m->nmaster;
|
||||
if (i < m->nmaster)
|
||||
clientsnmaster++;
|
||||
else
|
||||
clientsnstack++;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (clientsnmaster + clientsnstack + clientsnfloating + clientsnhidden == 0)
|
||||
return 0;
|
||||
|
||||
tgactive = 1;
|
||||
num = tabw;
|
||||
/* floating mode */
|
||||
if ((fulllayout && BARTAB_FLOATWEIGHT) || clientsnmaster + clientsnstack == 0 || !m->lt[m->sellt]->arrange) {
|
||||
den = clientsnmaster + clientsnstack + clientsnfloating + clientsnhidden;
|
||||
r = num % den;
|
||||
w = num / den;
|
||||
for (c = m->clients, i = 0; c; c = c->next) {
|
||||
if (!ISVISIBLE(c))
|
||||
continue;
|
||||
tabfn(m, c, passx, x, w + (i < r ? 1 : 0), tgactive, arg, barg);
|
||||
x += w + (i < r ? 1 : 0);
|
||||
i++;
|
||||
}
|
||||
/* no master and stack mode, e.g. monocole, grid layouts, fibonacci */
|
||||
} else if (fulllayout) {
|
||||
den = clientsnmaster + clientsnstack + clientsnhidden;
|
||||
r = num % den;
|
||||
w = num / den;
|
||||
for (c = m->clients, i = 0; c; c = c->next) {
|
||||
if (!ISVISIBLE(c) || (c->isfloating && !HIDDEN(c)))
|
||||
continue;
|
||||
tabfn(m, c, passx, x, w + (i < r ? 1 : 0), tgactive, arg, barg);
|
||||
x += w + (i < r ? 1 : 0);
|
||||
i++;
|
||||
}
|
||||
/* tiled mode */
|
||||
} else {
|
||||
den = clientsnmaster;
|
||||
c = m->clients;
|
||||
i = 0;
|
||||
if (den) {
|
||||
if (clientsnstack + clientsnfloating * BARTAB_FLOATWEIGHT + clientsnhidden) {
|
||||
tgactive = masteractive;
|
||||
num = tabw * m->mfact;
|
||||
}
|
||||
r = num % den;
|
||||
w = num / den;
|
||||
for (; c && i < m->nmaster; c = c->next) { // tiled master
|
||||
if (!ISVISIBLE(c) || c->isfloating || HIDDEN(c))
|
||||
continue;
|
||||
tabfn(m, c, passx, x, w + (i < r ? 1 : 0), tgactive, arg, barg);
|
||||
x += w + (i < r ? 1 : 0);
|
||||
i++;
|
||||
}
|
||||
tgactive = !tgactive;
|
||||
num = tabw - num;
|
||||
}
|
||||
|
||||
den = clientsnstack * BARTAB_STACKWEIGHT + clientsnfloating * BARTAB_FLOATWEIGHT + clientsnhidden * BARTAB_HIDDENWEIGHT;
|
||||
if (!den)
|
||||
return 1;
|
||||
|
||||
r = num % den;
|
||||
w = num / den;
|
||||
#if BARTAB_STACKWEIGHT
|
||||
for (; c; c = c->next) { // tiled stack
|
||||
if (!ISVISIBLE(c) || HIDDEN(c) || c->isfloating)
|
||||
continue;
|
||||
tabfn(m, c, passx, x, w * BARTAB_STACKWEIGHT + (i - m->nmaster < r ? 1 : 0), tgactive, arg, barg);
|
||||
x += w * BARTAB_STACKWEIGHT + (i - m->nmaster < r ? 1 : 0);
|
||||
i++;
|
||||
}
|
||||
#endif // BARTAB_STACKWEIGHT
|
||||
|
||||
#if BARTAB_HIDDENWEIGHT
|
||||
for (c = m->clients; c; c = c->next) { // hidden windows
|
||||
if (!ISVISIBLE(c) || !HIDDEN(c))
|
||||
continue;
|
||||
tabfn(m, c, passx, x, w * BARTAB_HIDDENWEIGHT + (i - m->nmaster < r ? 1 : 0), tgactive, arg, barg);
|
||||
x += w * BARTAB_HIDDENWEIGHT + (i - m->nmaster < r ? 1 : 0);
|
||||
i++;
|
||||
}
|
||||
#endif // BARTAB_HIDDENWEIGHT
|
||||
|
||||
#if BARTAB_FLOATWEIGHT
|
||||
for (c = m->clients; c; c = c->next) { // floating windows
|
||||
if (!ISVISIBLE(c) || HIDDEN(c) || !c->isfloating)
|
||||
continue;
|
||||
tabfn(m, c, passx, x, w * BARTAB_FLOATWEIGHT + (i - m->nmaster < r ? 1 : 0), tgactive, arg, barg);
|
||||
x += w * BARTAB_FLOATWEIGHT + (i - m->nmaster < r ? 1 : 0);
|
||||
i++;
|
||||
}
|
||||
#endif // BARTAB_FLOATWEIGHT
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
static int width_bartabgroups(Bar *bar, BarArg *a);
|
||||
static int draw_bartabgroups(Bar *bar, BarArg *a);
|
||||
static int click_bartabgroups(Bar *bar, Arg *arg, BarArg *a);
|
||||
|
||||
static void bartabdraw(Monitor *m, Client *c, int unused, int x, int w, int groupactive, Arg *arg, BarArg *barg);
|
||||
static void bartabclick(Monitor *m, Client *c, int passx, int x, int w, int unused, Arg *arg, BarArg *barg);
|
||||
static int bartabcalculate(Monitor *m, int offx, int w, int passx, void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg, BarArg *barg), Arg *arg, BarArg *barg);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
char *
|
||||
tagicon(Monitor *m, int tag)
|
||||
{
|
||||
int tagindex = tag + NUMTAGS * m->index;
|
||||
if (tagindex >= LENGTH(tagicons[DEFAULT_TAGS]))
|
||||
tagindex = tagindex % LENGTH(tagicons[DEFAULT_TAGS]);
|
||||
return tagicons[DEFAULT_TAGS][tagindex];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
enum {
|
||||
DEFAULT_TAGS,
|
||||
ALTERNATIVE_TAGS,
|
||||
ALT_TAGS_DECORATION,
|
||||
};
|
||||
|
||||
static char * tagicon(Monitor *m, int tag);
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
int
|
||||
width_tags(Bar *bar, BarArg *a)
|
||||
{
|
||||
int w, i;
|
||||
Client *c;
|
||||
unsigned int occ = 0;
|
||||
for (c = bar->mon->clients; c; c = c->next)
|
||||
occ |= c->tags == 255 ? 0 : c->tags;
|
||||
|
||||
for (w = 0, i = 0; i < NUMTAGS; i++) {
|
||||
if (!(occ & 1 << i || bar->mon->tagset[bar->mon->seltags] & 1 << i))
|
||||
continue;
|
||||
w += TEXTW(tagicon(bar->mon, i));
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
int
|
||||
draw_tags(Bar *bar, BarArg *a)
|
||||
{
|
||||
int invert;
|
||||
int w, x = a->x;
|
||||
unsigned int i, occ = 0, urg = 0;
|
||||
char *icon;
|
||||
Client *c;
|
||||
Monitor *m = bar->mon;
|
||||
|
||||
for (c = m->clients; c; c = c->next) {
|
||||
occ |= c->tags == 255 ? 0 : c->tags;
|
||||
if (c->isurgent)
|
||||
urg |= c->tags;
|
||||
}
|
||||
for (i = 0; i < NUMTAGS; i++) {
|
||||
/* do not draw vacant tags */
|
||||
if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
|
||||
continue;
|
||||
|
||||
icon = tagicon(bar->mon, i);
|
||||
invert = 0;
|
||||
w = TEXTW(icon);
|
||||
drw_setscheme(drw, scheme[
|
||||
m->tagset[m->seltags] & 1 << i
|
||||
? SchemeTagsSel
|
||||
: urg & 1 << i
|
||||
? SchemeUrg
|
||||
: SchemeTagsNorm
|
||||
]);
|
||||
drw_text(drw, x, a->y, w, a->h, lrpad / 2, icon, invert, False);
|
||||
drawindicator(m, NULL, occ, x, a->y, w, a->h, i, -1, invert, tagindicatortype);
|
||||
x += w;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
click_tags(Bar *bar, Arg *arg, BarArg *a)
|
||||
{
|
||||
int i = 0, x = lrpad / 2;
|
||||
Client *c;
|
||||
unsigned int occ = 0;
|
||||
for (c = bar->mon->clients; c; c = c->next)
|
||||
occ |= c->tags == 255 ? 0 : c->tags;
|
||||
|
||||
do {
|
||||
if (!(occ & 1 << i || bar->mon->tagset[bar->mon->seltags] & 1 << i))
|
||||
continue;
|
||||
x += TEXTW(tagicon(bar->mon, i));
|
||||
} while (a->x >= x && ++i < NUMTAGS);
|
||||
if (i < NUMTAGS) {
|
||||
arg->ui = 1 << i;
|
||||
}
|
||||
return ClkTagBar;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
static int width_tags(Bar *bar, BarArg *a);
|
||||
static int draw_tags(Bar *bar, BarArg *a);
|
||||
static int click_tags(Bar *bar, Arg *arg, BarArg *a);
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
int
|
||||
width_wintitle(Bar *bar, BarArg *a)
|
||||
{
|
||||
return a->w;
|
||||
}
|
||||
|
||||
int
|
||||
draw_wintitle(Bar *bar, BarArg *a)
|
||||
{
|
||||
int x = a->x + lrpad / 2, w = a->w - lrpad / 2;
|
||||
Monitor *m = bar->mon;
|
||||
Client *c = m->sel;
|
||||
int pad = lrpad / 2;
|
||||
|
||||
if (!c) {
|
||||
drw_setscheme(drw, scheme[SchemeTitleNorm]);
|
||||
drw_rect(drw, x, a->y, w, a->h, 1, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
drw_setscheme(drw, scheme[m == selmon ? SchemeTitleSel : SchemeTitleNorm]);
|
||||
XSetErrorHandler(xerrordummy);
|
||||
if (TEXTW(c->name) < w)
|
||||
pad = (w - TEXTW(c->name) + lrpad) / 2;
|
||||
|
||||
drw_text(drw, x, a->y, w, a->h, pad, c->name, 0, False);
|
||||
|
||||
XSync(dpy, False);
|
||||
XSetErrorHandler(xerror);
|
||||
drawstateindicator(m, c, 1, x, a->y, w, a->h, 0, 0, c->isfixed);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
click_wintitle(Bar *bar, Arg *arg, BarArg *a)
|
||||
{
|
||||
return ClkWinTitle;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
static int width_wintitle(Bar *bar, BarArg *a);
|
||||
static int draw_wintitle(Bar *bar, BarArg *a);
|
||||
static int click_wintitle(Bar *bar, Arg *arg, BarArg *a);
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
void
|
||||
hide(Client *c) {
|
||||
|
||||
Client *n;
|
||||
if (!c || HIDDEN(c))
|
||||
return;
|
||||
|
||||
Window w = c->win;
|
||||
static XWindowAttributes ra, ca;
|
||||
|
||||
// more or less taken directly from blackbox's hide() function
|
||||
XGrabServer(dpy);
|
||||
XGetWindowAttributes(dpy, root, &ra);
|
||||
XGetWindowAttributes(dpy, w, &ca);
|
||||
// prevent UnmapNotify events
|
||||
XSelectInput(dpy, root, ra.your_event_mask & ~SubstructureNotifyMask);
|
||||
XSelectInput(dpy, w, ca.your_event_mask & ~StructureNotifyMask);
|
||||
XUnmapWindow(dpy, w);
|
||||
setclientstate(c, IconicState);
|
||||
XSelectInput(dpy, root, ra.your_event_mask);
|
||||
XSelectInput(dpy, w, ca.your_event_mask);
|
||||
XUngrabServer(dpy);
|
||||
|
||||
if (c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) {
|
||||
for (n = c->snext; n && (!ISVISIBLE(n) || HIDDEN(n)); n = n->snext);
|
||||
if (!n)
|
||||
for (n = c->mon->stack; n && (!ISVISIBLE(n) || HIDDEN(n)); n = n->snext);
|
||||
} else {
|
||||
n = nexttiled(c);
|
||||
if (!n)
|
||||
n = prevtiled(c);
|
||||
}
|
||||
focus(n);
|
||||
arrange(c->mon);
|
||||
}
|
||||
|
||||
void
|
||||
show(Client *c)
|
||||
{
|
||||
if (!c || !HIDDEN(c))
|
||||
return;
|
||||
|
||||
XMapWindow(dpy, c->win);
|
||||
setclientstate(c, NormalState);
|
||||
arrange(c->mon);
|
||||
}
|
||||
|
||||
void
|
||||
togglewin(const Arg *arg)
|
||||
{
|
||||
Client *c = (Client*)arg->v;
|
||||
if (!c)
|
||||
return;
|
||||
if (c == selmon->sel)
|
||||
hide(c);
|
||||
else {
|
||||
if (HIDDEN(c))
|
||||
show(c);
|
||||
focus(c);
|
||||
restack(c->mon);
|
||||
}
|
||||
}
|
||||
|
||||
Client *
|
||||
prevtiled(Client *c)
|
||||
{
|
||||
Client *p, *i;
|
||||
for (p = NULL, i = c->mon->clients; c && i != c; i = i->next)
|
||||
if (ISVISIBLE(i) && !HIDDEN(i))
|
||||
p = i;
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
showhideclient(const Arg *arg)
|
||||
{
|
||||
Client *c = (Client*)arg->v;
|
||||
if (!c)
|
||||
c = selmon->sel;
|
||||
if (!c)
|
||||
return;
|
||||
|
||||
if (HIDDEN(c)) {
|
||||
show(c);
|
||||
focus(c);
|
||||
restack(c->mon);
|
||||
} else {
|
||||
hide(c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
static void hide(Client *c);
|
||||
static void show(Client *c);
|
||||
static void togglewin(const Arg *arg);
|
||||
static Client * prevtiled(Client *c);
|
||||
static void showhideclient(const Arg *arg);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
static Atom motifatom;
|
||||
|
||||
void
|
||||
updatemotifhints(Client *c)
|
||||
{
|
||||
Atom real;
|
||||
int format;
|
||||
unsigned char *p = NULL;
|
||||
unsigned long n, extra;
|
||||
unsigned long *motif;
|
||||
int width, height;
|
||||
|
||||
if (!decorhints)
|
||||
return;
|
||||
|
||||
if (XGetWindowProperty(dpy, c->win, motifatom, 0L, 5L, False, motifatom,
|
||||
&real, &format, &n, &extra, &p) == Success && p != NULL) {
|
||||
motif = (unsigned long*)p;
|
||||
if (motif[MWM_HINTS_FLAGS_FIELD] & MWM_HINTS_DECORATIONS) {
|
||||
width = WIDTH(c);
|
||||
height = HEIGHT(c);
|
||||
|
||||
if (motif[MWM_HINTS_DECORATIONS_FIELD] & MWM_DECOR_ALL ||
|
||||
motif[MWM_HINTS_DECORATIONS_FIELD] & MWM_DECOR_BORDER ||
|
||||
motif[MWM_HINTS_DECORATIONS_FIELD] & MWM_DECOR_TITLE)
|
||||
c->bw = c->oldbw = borderpx;
|
||||
else
|
||||
c->bw = c->oldbw = 0;
|
||||
|
||||
resize(c, c->x, c->y, width - (2*c->bw), height - (2*c->bw), 0);
|
||||
}
|
||||
XFree(p);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#define MWM_HINTS_FLAGS_FIELD 0
|
||||
#define MWM_HINTS_DECORATIONS_FIELD 2
|
||||
#define MWM_HINTS_DECORATIONS (1 << 1)
|
||||
#define MWM_DECOR_ALL (1 << 0)
|
||||
#define MWM_DECOR_BORDER (1 << 1)
|
||||
#define MWM_DECOR_TITLE (1 << 3)
|
||||
|
||||
static void updatemotifhints(Client *c);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
void
|
||||
togglefakefullscreen(const Arg *arg)
|
||||
{
|
||||
Client *c = selmon->sel;
|
||||
if (!c)
|
||||
return;
|
||||
|
||||
if (c->fakefullscreen != 1 && c->isfullscreen) { // exit fullscreen --> fake fullscreen
|
||||
c->fakefullscreen = 2;
|
||||
setfullscreen(c, 0);
|
||||
} else if (c->fakefullscreen == 1) {
|
||||
setfullscreen(c, 0);
|
||||
c->fakefullscreen = 0;
|
||||
} else {
|
||||
c->fakefullscreen = 1;
|
||||
setfullscreen(c, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
static void togglefakefullscreen(const Arg *arg);
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
void
|
||||
tagtoleft(const Arg *arg)
|
||||
{
|
||||
if (selmon->sel != NULL
|
||||
&& __builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1
|
||||
&& selmon->tagset[selmon->seltags] > 1) {
|
||||
selmon->sel->tags >>= 1;
|
||||
focus(NULL);
|
||||
arrange(selmon);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tagtoright(const Arg *arg)
|
||||
{
|
||||
if (selmon->sel != NULL
|
||||
&& __builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1
|
||||
&& selmon->tagset[selmon->seltags] & (TAGMASK >> 1)) {
|
||||
selmon->sel->tags <<= 1;
|
||||
focus(NULL);
|
||||
arrange(selmon);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
viewtoleft(const Arg *arg)
|
||||
{
|
||||
if (__builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1
|
||||
&& selmon->tagset[selmon->seltags] > 1) {
|
||||
selmon->seltags ^= 1; /* toggle sel tagset */
|
||||
pertagview(&((Arg) { .ui = selmon->tagset[selmon->seltags ^ 1] >> 1 }));
|
||||
focus(NULL);
|
||||
arrange(selmon);
|
||||
updatecurrentdesktop();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
viewtoright(const Arg *arg)
|
||||
{
|
||||
if (__builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1
|
||||
&& selmon->tagset[selmon->seltags] & (TAGMASK >> 1)) {
|
||||
selmon->seltags ^= 1; /* toggle sel tagset */
|
||||
pertagview(&((Arg) { .ui = selmon->tagset[selmon->seltags ^ 1] << 1 }));
|
||||
focus(NULL);
|
||||
arrange(selmon);
|
||||
updatecurrentdesktop();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tagandviewtoleft(const Arg *arg)
|
||||
{
|
||||
if (selmon->sel != NULL
|
||||
&& __builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1
|
||||
&& selmon->tagset[selmon->seltags] > 1) {
|
||||
selmon->sel->tags >>= 1;
|
||||
selmon->seltags ^= 1; /* toggle sel tagset */
|
||||
pertagview(&((Arg) { .ui = selmon->tagset[selmon->seltags ^ 1] >> 1 }));
|
||||
focus(selmon->sel);
|
||||
arrange(selmon);
|
||||
updatecurrentdesktop();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tagandviewtoright(const Arg *arg)
|
||||
{
|
||||
if (selmon->sel != NULL
|
||||
&& __builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1
|
||||
&& selmon->tagset[selmon->seltags] & (TAGMASK >> 1)) {
|
||||
selmon->sel->tags <<= 1;
|
||||
selmon->seltags ^= 1; /* toggle sel tagset */
|
||||
pertagview(&((Arg) { .ui = selmon->tagset[selmon->seltags ^ 1] << 1 }));
|
||||
focus(selmon->sel);
|
||||
arrange(selmon);
|
||||
updatecurrentdesktop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
static void tagtoleft(const Arg *arg);
|
||||
static void tagtoright(const Arg *arg);
|
||||
static void viewtoleft(const Arg *arg);
|
||||
static void viewtoright(const Arg *arg);
|
||||
static void tagandviewtoleft(const Arg *arg);
|
||||
static void tagandviewtoright(const Arg *arg);
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/* Bar functionality */
|
||||
#include "bar_indicators.c"
|
||||
#include "bar_tagicons.c"
|
||||
|
||||
#include "bar_alpha.c"
|
||||
#include "bar_dwmblocks.c"
|
||||
#include "bar_ewmhtags.c"
|
||||
#include "bar_ltsymbol.c"
|
||||
#include "bar_powerline_tags.c"
|
||||
#include "bar_status.c"
|
||||
#include "bar_statuscmd.c"
|
||||
#include "bar_tabgroups.c"
|
||||
#include "bar_tags.c"
|
||||
#include "bar_wintitle.c"
|
||||
#include "bar_systray.c"
|
||||
#include "bar_wintitleactions.c"
|
||||
|
||||
/* Other patches */
|
||||
#include "autostart.c"
|
||||
#include "decorationhints.c"
|
||||
#include "fakefullscreenclient.c"
|
||||
#include "focusadjacenttag.c"
|
||||
#include "inplacerotate.c"
|
||||
#include "pertag.c"
|
||||
#include "scratchpad_alt_1.c"
|
||||
#include "sticky.c"
|
||||
#include "swallow.c"
|
||||
#include "tagallmon.c"
|
||||
#include "tagswapmon.c"
|
||||
#include "transfer.c"
|
||||
#include "vanitygaps.c"
|
||||
/* Layouts */
|
||||
#include "layout_facts.c"
|
||||
#include "layout_centeredmaster.c"
|
||||
#include "layout_centeredfloatingmaster.c"
|
||||
#include "layout_fibonacci.c"
|
||||
#include "layout_monocle.c"
|
||||
#include "layout_nrowgrid.c"
|
||||
#include "layout_tile.c"
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/* Bar functionality */
|
||||
#include "bar_indicators.h"
|
||||
#include "bar_tagicons.h"
|
||||
|
||||
#include "bar_alpha.h"
|
||||
#include "bar_dwmblocks.h"
|
||||
#include "bar_ewmhtags.h"
|
||||
#include "bar_ltsymbol.h"
|
||||
#include "bar_powerline_tags.h"
|
||||
#include "bar_status.h"
|
||||
#include "bar_statuscmd.h"
|
||||
#include "bar_tabgroups.h"
|
||||
#include "bar_tags.h"
|
||||
#include "bar_wintitle.h"
|
||||
#include "bar_systray.h"
|
||||
#include "bar_wintitleactions.h"
|
||||
|
||||
/* Other patches */
|
||||
#include "autostart.h"
|
||||
#include "decorationhints.h"
|
||||
#include "fakefullscreenclient.h"
|
||||
#include "focusadjacenttag.h"
|
||||
#include "inplacerotate.h"
|
||||
#include "pertag.h"
|
||||
#include "scratchpad_alt_1.h"
|
||||
#include "sticky.h"
|
||||
#include "swallow.h"
|
||||
#include "tagallmon.h"
|
||||
#include "tagswapmon.h"
|
||||
#include "transfer.h"
|
||||
#include "vanitygaps.h"
|
||||
/* Layouts */
|
||||
#include "layout_centeredmaster.h"
|
||||
#include "layout_centeredfloatingmaster.h"
|
||||
#include "layout_fibonacci.h"
|
||||
#include "layout_monocle.h"
|
||||
#include "layout_nrowgrid.h"
|
||||
#include "layout_tile.h"
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
void
|
||||
insertclient(Client *item, Client *insertItem, int after)
|
||||
{
|
||||
Client *c;
|
||||
if (item == NULL || insertItem == NULL || item == insertItem)
|
||||
return;
|
||||
detach(insertItem);
|
||||
if (!after && selmon->clients == item) {
|
||||
attach(insertItem);
|
||||
return;
|
||||
}
|
||||
if (after) {
|
||||
c = item;
|
||||
} else {
|
||||
for (c = selmon->clients; c; c = c->next) {
|
||||
if (c->next == item)
|
||||
break;
|
||||
}
|
||||
}
|
||||
insertItem->next = c->next;
|
||||
c->next = insertItem;
|
||||
}
|
||||
|
||||
void
|
||||
inplacerotate(const Arg *arg)
|
||||
{
|
||||
if (!selmon->sel || (selmon->sel->isfloating && !arg->f))
|
||||
return;
|
||||
|
||||
unsigned int selidx = 0, i = 0;
|
||||
Client *c = NULL, *stail = NULL, *mhead = NULL, *mtail = NULL, *shead = NULL;
|
||||
|
||||
// Determine positionings for insertclient
|
||||
for (c = selmon->clients; c; c = c->next) {
|
||||
if (ISVISIBLE(c) && !(c->isfloating)) {
|
||||
if (selmon->sel == c)
|
||||
selidx = i;
|
||||
if (i == selmon->nmaster - 1)
|
||||
mtail = c;
|
||||
if (i == selmon->nmaster)
|
||||
shead = c;
|
||||
if (mhead == NULL)
|
||||
mhead = c;
|
||||
stail = c;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
switch(arg->i) {
|
||||
case 1:
|
||||
if (selidx >= selmon->nmaster)
|
||||
insertclient(shead, stail, 0);
|
||||
else
|
||||
insertclient(mhead, mtail, 0);
|
||||
break;
|
||||
case -1:
|
||||
if (selidx >= selmon->nmaster)
|
||||
insertclient(stail, shead, 1);
|
||||
else
|
||||
insertclient(mtail, mhead, 1);
|
||||
break;
|
||||
case 2:
|
||||
insertclient(selmon->clients, stail, 0);
|
||||
break;
|
||||
case -2:
|
||||
insertclient(stail, selmon->clients, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
// Restore focus position
|
||||
i = 0;
|
||||
for (c = selmon->clients; c; c = c->next) {
|
||||
if (!ISVISIBLE(c) || (c->isfloating))
|
||||
continue;
|
||||
if (i == selidx) {
|
||||
focus(c);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
arrange(selmon);
|
||||
focus(c);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
static void inplacerotate(const Arg *arg);
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#ifndef IPC_CLIENT_H_
|
||||
#define IPC_CLIENT_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/epoll.h>
|
||||
|
||||
typedef struct IPCClient IPCClient;
|
||||
/**
|
||||
* This structure contains the details of an IPC Client and pointers for a
|
||||
* linked list
|
||||
*/
|
||||
struct IPCClient {
|
||||
int fd;
|
||||
int subscriptions;
|
||||
|
||||
char *buffer;
|
||||
uint32_t buffer_size;
|
||||
|
||||
struct epoll_event event;
|
||||
IPCClient *next;
|
||||
IPCClient *prev;
|
||||
};
|
||||
|
||||
typedef IPCClient *IPCClientList;
|
||||
|
||||
/**
|
||||
* Allocate memory for new IPCClient with the specified file descriptor and
|
||||
* initialize struct.
|
||||
*
|
||||
* @param fd File descriptor of IPC client
|
||||
*
|
||||
* @return Address to allocated IPCClient struct
|
||||
*/
|
||||
IPCClient *ipc_client_new(int fd);
|
||||
|
||||
/**
|
||||
* Add an IPC Client to the specified list
|
||||
*
|
||||
* @param list Address of the list to add the client to
|
||||
* @param nc Address of the IPCClient
|
||||
*/
|
||||
void ipc_list_add_client(IPCClientList *list, IPCClient *nc);
|
||||
|
||||
/**
|
||||
* Remove an IPCClient from the specified list
|
||||
*
|
||||
* @param list Address of the list to remove the client from
|
||||
* @param c Address of the IPCClient
|
||||
*/
|
||||
void ipc_list_remove_client(IPCClientList *list, IPCClient *c);
|
||||
|
||||
/**
|
||||
* Get an IPCClient from the specified IPCClient list
|
||||
*
|
||||
* @param list List to remove the client from
|
||||
* @param fd File descriptor of the IPCClient
|
||||
*/
|
||||
IPCClient *ipc_list_get_client(IPCClientList list, int fd);
|
||||
|
||||
#endif // IPC_CLIENT_H_
|
||||
|
||||
@@ -0,0 +1,549 @@
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <yajl/yajl_gen.h>
|
||||
|
||||
#define IPC_MAGIC "DWM-IPC"
|
||||
// clang-format off
|
||||
#define IPC_MAGIC_ARR { 'D', 'W', 'M', '-', 'I', 'P', 'C' }
|
||||
// clang-format on
|
||||
#define IPC_MAGIC_LEN 7 // Not including null char
|
||||
|
||||
#define IPC_EVENT_TAG_CHANGE "tag_change_event"
|
||||
#define IPC_EVENT_CLIENT_FOCUS_CHANGE "client_focus_change_event"
|
||||
#define IPC_EVENT_LAYOUT_CHANGE "layout_change_event"
|
||||
#define IPC_EVENT_MONITOR_FOCUS_CHANGE "monitor_focus_change_event"
|
||||
#define IPC_EVENT_FOCUSED_TITLE_CHANGE "focused_title_change_event"
|
||||
#define IPC_EVENT_FOCUSED_STATE_CHANGE "focused_state_change_event"
|
||||
|
||||
#define YSTR(str) yajl_gen_string(gen, (unsigned char *)str, strlen(str))
|
||||
#define YINT(num) yajl_gen_integer(gen, num)
|
||||
#define YDOUBLE(num) yajl_gen_double(gen, num)
|
||||
#define YBOOL(v) yajl_gen_bool(gen, v)
|
||||
#define YNULL() yajl_gen_null(gen)
|
||||
#define YARR(body) \
|
||||
{ \
|
||||
yajl_gen_array_open(gen); \
|
||||
body; \
|
||||
yajl_gen_array_close(gen); \
|
||||
}
|
||||
#define YMAP(body) \
|
||||
{ \
|
||||
yajl_gen_map_open(gen); \
|
||||
body; \
|
||||
yajl_gen_map_close(gen); \
|
||||
}
|
||||
|
||||
typedef unsigned long Window;
|
||||
|
||||
const char *DEFAULT_SOCKET_PATH = "/tmp/dwm.sock";
|
||||
static int sock_fd = -1;
|
||||
static unsigned int ignore_reply = 0;
|
||||
|
||||
typedef enum IPCMessageType {
|
||||
IPC_TYPE_RUN_COMMAND = 0,
|
||||
IPC_TYPE_GET_MONITORS = 1,
|
||||
IPC_TYPE_GET_TAGS = 2,
|
||||
IPC_TYPE_GET_LAYOUTS = 3,
|
||||
IPC_TYPE_GET_DWM_CLIENT = 4,
|
||||
IPC_TYPE_SUBSCRIBE = 5,
|
||||
IPC_TYPE_EVENT = 6
|
||||
} IPCMessageType;
|
||||
|
||||
// Every IPC message must begin with this
|
||||
typedef struct dwm_ipc_header {
|
||||
uint8_t magic[IPC_MAGIC_LEN];
|
||||
uint32_t size;
|
||||
uint8_t type;
|
||||
} __attribute((packed)) dwm_ipc_header_t;
|
||||
|
||||
static int
|
||||
recv_message(uint8_t *msg_type, uint32_t *reply_size, uint8_t **reply)
|
||||
{
|
||||
uint32_t read_bytes = 0;
|
||||
const int32_t to_read = sizeof(dwm_ipc_header_t);
|
||||
char header[to_read];
|
||||
char *walk = header;
|
||||
|
||||
// Try to read header
|
||||
while (read_bytes < to_read) {
|
||||
ssize_t n = read(sock_fd, header + read_bytes, to_read - read_bytes);
|
||||
|
||||
if (n == 0) {
|
||||
if (read_bytes == 0) {
|
||||
fprintf(stderr, "Unexpectedly reached EOF while reading header.");
|
||||
fprintf(stderr,
|
||||
"Read %" PRIu32 " bytes, expected %" PRIu32 " total bytes.\n",
|
||||
read_bytes, to_read);
|
||||
return -2;
|
||||
} else {
|
||||
fprintf(stderr, "Unexpectedly reached EOF while reading header.");
|
||||
fprintf(stderr,
|
||||
"Read %" PRIu32 " bytes, expected %" PRIu32 " total bytes.\n",
|
||||
read_bytes, to_read);
|
||||
return -3;
|
||||
}
|
||||
} else if (n == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
read_bytes += n;
|
||||
}
|
||||
|
||||
// Check if magic string in header matches
|
||||
if (memcmp(walk, IPC_MAGIC, IPC_MAGIC_LEN) != 0) {
|
||||
fprintf(stderr, "Invalid magic string. Got '%.*s', expected '%s'\n",
|
||||
IPC_MAGIC_LEN, walk, IPC_MAGIC);
|
||||
return -3;
|
||||
}
|
||||
|
||||
walk += IPC_MAGIC_LEN;
|
||||
|
||||
// Extract reply size
|
||||
memcpy(reply_size, walk, sizeof(uint32_t));
|
||||
walk += sizeof(uint32_t);
|
||||
|
||||
// Extract message type
|
||||
memcpy(msg_type, walk, sizeof(uint8_t));
|
||||
walk += sizeof(uint8_t);
|
||||
|
||||
(*reply) = malloc(*reply_size);
|
||||
|
||||
// Extract payload
|
||||
read_bytes = 0;
|
||||
while (read_bytes < *reply_size) {
|
||||
ssize_t n = read(sock_fd, *reply + read_bytes, *reply_size - read_bytes);
|
||||
|
||||
if (n == 0) {
|
||||
fprintf(stderr, "Unexpectedly reached EOF while reading payload.");
|
||||
fprintf(stderr, "Read %" PRIu32 " bytes, expected %" PRIu32 " bytes.\n",
|
||||
read_bytes, *reply_size);
|
||||
free(*reply);
|
||||
return -2;
|
||||
} else if (n == -1) {
|
||||
if (errno == EINTR || errno == EAGAIN) continue;
|
||||
free(*reply);
|
||||
return -1;
|
||||
}
|
||||
|
||||
read_bytes += n;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
read_socket(IPCMessageType *msg_type, uint32_t *msg_size, char **msg)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
while (ret != 0) {
|
||||
ret = recv_message((uint8_t *)msg_type, msg_size, (uint8_t **)msg);
|
||||
|
||||
if (ret < 0) {
|
||||
// Try again (non-fatal error)
|
||||
if (ret == -1 && (errno == EINTR || errno == EAGAIN)) continue;
|
||||
|
||||
fprintf(stderr, "Error receiving response from socket. ");
|
||||
fprintf(stderr, "The connection might have been lost.\n");
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
write_socket(const void *buf, size_t count)
|
||||
{
|
||||
size_t written = 0;
|
||||
|
||||
while (written < count) {
|
||||
const ssize_t n =
|
||||
write(sock_fd, ((uint8_t *)buf) + written, count - written);
|
||||
|
||||
if (n == -1) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
|
||||
continue;
|
||||
else
|
||||
return n;
|
||||
}
|
||||
written += n;
|
||||
}
|
||||
return written;
|
||||
}
|
||||
|
||||
static void
|
||||
connect_to_socket()
|
||||
{
|
||||
struct sockaddr_un addr;
|
||||
|
||||
int sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
|
||||
// Initialize struct to 0
|
||||
memset(&addr, 0, sizeof(struct sockaddr_un));
|
||||
|
||||
addr.sun_family = AF_UNIX;
|
||||
strcpy(addr.sun_path, DEFAULT_SOCKET_PATH);
|
||||
|
||||
connect(sock, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un));
|
||||
|
||||
sock_fd = sock;
|
||||
}
|
||||
|
||||
static int
|
||||
send_message(IPCMessageType msg_type, uint32_t msg_size, uint8_t *msg)
|
||||
{
|
||||
dwm_ipc_header_t header = {
|
||||
.magic = IPC_MAGIC_ARR, .size = msg_size, .type = msg_type};
|
||||
|
||||
size_t header_size = sizeof(dwm_ipc_header_t);
|
||||
size_t total_size = header_size + msg_size;
|
||||
|
||||
uint8_t buffer[total_size];
|
||||
|
||||
// Copy header to buffer
|
||||
memcpy(buffer, &header, header_size);
|
||||
// Copy message to buffer
|
||||
memcpy(buffer + header_size, msg, header.size);
|
||||
|
||||
write_socket(buffer, total_size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
is_float(const char *s)
|
||||
{
|
||||
size_t len = strlen(s);
|
||||
int is_dot_used = 0;
|
||||
int is_minus_used = 0;
|
||||
|
||||
// Floats can only have one decimal point in between or digits
|
||||
// Optionally, floats can also be below zero (negative)
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (isdigit(s[i]))
|
||||
continue;
|
||||
else if (!is_dot_used && s[i] == '.' && i != 0 && i != len - 1) {
|
||||
is_dot_used = 1;
|
||||
continue;
|
||||
} else if (!is_minus_used && s[i] == '-' && i == 0) {
|
||||
is_minus_used = 1;
|
||||
continue;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
is_unsigned_int(const char *s)
|
||||
{
|
||||
size_t len = strlen(s);
|
||||
|
||||
// Unsigned int can only have digits
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (isdigit(s[i]))
|
||||
continue;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
is_signed_int(const char *s)
|
||||
{
|
||||
size_t len = strlen(s);
|
||||
|
||||
// Signed int can only have digits and a negative sign at the start
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (isdigit(s[i]))
|
||||
continue;
|
||||
else if (i == 0 && s[i] == '-') {
|
||||
continue;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
flush_socket_reply()
|
||||
{
|
||||
IPCMessageType reply_type;
|
||||
uint32_t reply_size;
|
||||
char *reply;
|
||||
|
||||
read_socket(&reply_type, &reply_size, &reply);
|
||||
|
||||
free(reply);
|
||||
}
|
||||
|
||||
static void
|
||||
print_socket_reply()
|
||||
{
|
||||
IPCMessageType reply_type;
|
||||
uint32_t reply_size;
|
||||
char *reply;
|
||||
|
||||
read_socket(&reply_type, &reply_size, &reply);
|
||||
|
||||
printf("%.*s\n", reply_size, reply);
|
||||
fflush(stdout);
|
||||
free(reply);
|
||||
}
|
||||
|
||||
static int
|
||||
run_command(const char *name, char *args[], int argc)
|
||||
{
|
||||
const unsigned char *msg;
|
||||
size_t msg_size;
|
||||
|
||||
yajl_gen gen = yajl_gen_alloc(NULL);
|
||||
|
||||
// Message format:
|
||||
// {
|
||||
// "command": "<name>",
|
||||
// "args": [ ... ]
|
||||
// }
|
||||
// clang-format off
|
||||
YMAP(
|
||||
YSTR("command"); YSTR(name);
|
||||
YSTR("args"); YARR(
|
||||
for (int i = 0; i < argc; i++) {
|
||||
if (is_signed_int(args[i])) {
|
||||
long long num = atoll(args[i]);
|
||||
YINT(num);
|
||||
} else if (is_float(args[i])) {
|
||||
float num = atof(args[i]);
|
||||
YDOUBLE(num);
|
||||
} else {
|
||||
YSTR(args[i]);
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
// clang-format on
|
||||
|
||||
yajl_gen_get_buf(gen, &msg, &msg_size);
|
||||
|
||||
send_message(IPC_TYPE_RUN_COMMAND, msg_size, (uint8_t *)msg);
|
||||
|
||||
if (!ignore_reply)
|
||||
print_socket_reply();
|
||||
else
|
||||
flush_socket_reply();
|
||||
|
||||
yajl_gen_free(gen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
get_monitors()
|
||||
{
|
||||
send_message(IPC_TYPE_GET_MONITORS, 1, (uint8_t *)"");
|
||||
print_socket_reply();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
get_tags()
|
||||
{
|
||||
send_message(IPC_TYPE_GET_TAGS, 1, (uint8_t *)"");
|
||||
print_socket_reply();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
get_layouts()
|
||||
{
|
||||
send_message(IPC_TYPE_GET_LAYOUTS, 1, (uint8_t *)"");
|
||||
print_socket_reply();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
get_dwm_client(Window win)
|
||||
{
|
||||
const unsigned char *msg;
|
||||
size_t msg_size;
|
||||
|
||||
yajl_gen gen = yajl_gen_alloc(NULL);
|
||||
|
||||
// Message format:
|
||||
// {
|
||||
// "client_window_id": "<win>"
|
||||
// }
|
||||
// clang-format off
|
||||
YMAP(
|
||||
YSTR("client_window_id"); YINT(win);
|
||||
)
|
||||
// clang-format on
|
||||
|
||||
yajl_gen_get_buf(gen, &msg, &msg_size);
|
||||
|
||||
send_message(IPC_TYPE_GET_DWM_CLIENT, msg_size, (uint8_t *)msg);
|
||||
|
||||
print_socket_reply();
|
||||
|
||||
yajl_gen_free(gen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
subscribe(const char *event)
|
||||
{
|
||||
const unsigned char *msg;
|
||||
size_t msg_size;
|
||||
|
||||
yajl_gen gen = yajl_gen_alloc(NULL);
|
||||
|
||||
// Message format:
|
||||
// {
|
||||
// "event": "<event>",
|
||||
// "action": "subscribe"
|
||||
// }
|
||||
// clang-format off
|
||||
YMAP(
|
||||
YSTR("event"); YSTR(event);
|
||||
YSTR("action"); YSTR("subscribe");
|
||||
)
|
||||
// clang-format on
|
||||
|
||||
yajl_gen_get_buf(gen, &msg, &msg_size);
|
||||
|
||||
send_message(IPC_TYPE_SUBSCRIBE, msg_size, (uint8_t *)msg);
|
||||
|
||||
if (!ignore_reply)
|
||||
print_socket_reply();
|
||||
else
|
||||
flush_socket_reply();
|
||||
|
||||
yajl_gen_free(gen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
usage_error(const char *prog_name, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
fprintf(stderr, "Error: ");
|
||||
vfprintf(stderr, format, args);
|
||||
fprintf(stderr, "\nusage: %s <command> [...]\n", prog_name);
|
||||
fprintf(stderr, "Try '%s help'\n", prog_name);
|
||||
|
||||
va_end(args);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
print_usage(const char *name)
|
||||
{
|
||||
printf("usage: %s [options] <command> [...]\n", name);
|
||||
puts("");
|
||||
puts("Commands:");
|
||||
puts(" run_command <name> [args...] Run an IPC command");
|
||||
puts("");
|
||||
puts(" get_monitors Get monitor properties");
|
||||
puts("");
|
||||
puts(" get_tags Get list of tags");
|
||||
puts("");
|
||||
puts(" get_layouts Get list of layouts");
|
||||
puts("");
|
||||
puts(" get_dwm_client <window_id> Get dwm client proprties");
|
||||
puts("");
|
||||
puts(" subscribe [events...] Subscribe to specified events");
|
||||
puts(" Options: " IPC_EVENT_TAG_CHANGE ",");
|
||||
puts(" " IPC_EVENT_LAYOUT_CHANGE ",");
|
||||
puts(" " IPC_EVENT_CLIENT_FOCUS_CHANGE ",");
|
||||
puts(" " IPC_EVENT_MONITOR_FOCUS_CHANGE ",");
|
||||
puts(" " IPC_EVENT_FOCUSED_TITLE_CHANGE ",");
|
||||
puts(" " IPC_EVENT_FOCUSED_STATE_CHANGE);
|
||||
puts("");
|
||||
puts(" help Display this message");
|
||||
puts("");
|
||||
puts("Options:");
|
||||
puts(" --ignore-reply Don't print reply messages from");
|
||||
puts(" run_command and subscribe.");
|
||||
puts("");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
const char *prog_name = argv[0];
|
||||
|
||||
connect_to_socket();
|
||||
if (sock_fd == -1) {
|
||||
fprintf(stderr, "Failed to connect to socket\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int i = 1;
|
||||
if (i < argc && strcmp(argv[i], "--ignore-reply") == 0) {
|
||||
ignore_reply = 1;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i >= argc) usage_error(prog_name, "Expected an argument, got none");
|
||||
|
||||
if (!argc || strcmp(argv[i], "help") == 0)
|
||||
print_usage(prog_name);
|
||||
else if (strcmp(argv[i], "run_command") == 0) {
|
||||
if (++i >= argc) usage_error(prog_name, "No command specified");
|
||||
// Command name
|
||||
char *command = argv[i];
|
||||
// Command arguments are everything after command name
|
||||
char **command_args = argv + ++i;
|
||||
// Number of command arguments
|
||||
int command_argc = argc - i;
|
||||
run_command(command, command_args, command_argc);
|
||||
} else if (strcmp(argv[i], "get_monitors") == 0) {
|
||||
get_monitors();
|
||||
} else if (strcmp(argv[i], "get_tags") == 0) {
|
||||
get_tags();
|
||||
} else if (strcmp(argv[i], "get_layouts") == 0) {
|
||||
get_layouts();
|
||||
} else if (strcmp(argv[i], "get_dwm_client") == 0) {
|
||||
if (++i < argc) {
|
||||
if (is_unsigned_int(argv[i])) {
|
||||
Window win = atol(argv[i]);
|
||||
get_dwm_client(win);
|
||||
} else
|
||||
usage_error(prog_name, "Expected unsigned integer argument");
|
||||
} else
|
||||
usage_error(prog_name, "Expected the window id");
|
||||
} else if (strcmp(argv[i], "subscribe") == 0) {
|
||||
if (++i < argc) {
|
||||
for (int j = i; j < argc; j++) subscribe(argv[j]);
|
||||
} else
|
||||
usage_error(prog_name, "Expected event name");
|
||||
// Keep listening for events forever
|
||||
while (1) {
|
||||
print_socket_reply();
|
||||
}
|
||||
} else
|
||||
usage_error(prog_name, "Invalid argument '%s'", argv[i]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
#ifndef YAJL_DUMPS_H_
|
||||
#define YAJL_DUMPS_H_
|
||||
|
||||
#include <string.h>
|
||||
#include <yajl/yajl_gen.h>
|
||||
|
||||
#define YSTR(str) yajl_gen_string(gen, (unsigned char *)str, strlen(str))
|
||||
#define YINT(num) yajl_gen_integer(gen, num)
|
||||
#define YDOUBLE(num) yajl_gen_double(gen, num)
|
||||
#define YBOOL(v) yajl_gen_bool(gen, v)
|
||||
#define YNULL() yajl_gen_null(gen)
|
||||
#define YARR(body) \
|
||||
{ \
|
||||
yajl_gen_array_open(gen); \
|
||||
body; \
|
||||
yajl_gen_array_close(gen); \
|
||||
}
|
||||
#define YMAP(body) \
|
||||
{ \
|
||||
yajl_gen_map_open(gen); \
|
||||
body; \
|
||||
yajl_gen_map_close(gen); \
|
||||
}
|
||||
|
||||
int dump_tag(yajl_gen gen, const char *name, const int tag_mask);
|
||||
|
||||
int dump_tags(yajl_gen gen, int tags_len);
|
||||
|
||||
int dump_client(yajl_gen gen, Client *c);
|
||||
|
||||
int dump_monitor(yajl_gen gen, Monitor *mon, int is_selected);
|
||||
|
||||
int dump_monitors(yajl_gen gen, Monitor *mons, Monitor *selmon);
|
||||
|
||||
int dump_layouts(yajl_gen gen, const Layout layouts[], const int layouts_len);
|
||||
|
||||
int dump_tag_state(yajl_gen gen, TagState state);
|
||||
|
||||
int dump_tag_event(yajl_gen gen, int mon_num, TagState old_state,
|
||||
TagState new_state);
|
||||
|
||||
int dump_client_focus_change_event(yajl_gen gen, Client *old_client,
|
||||
Client *new_client, int mon_num);
|
||||
|
||||
int dump_layout_change_event(yajl_gen gen, const int mon_num,
|
||||
const char *old_symbol, const Layout *old_layout,
|
||||
const char *new_symbol, const Layout *new_layout);
|
||||
|
||||
int dump_monitor_focus_change_event(yajl_gen gen, const int last_mon_num,
|
||||
const int new_mon_num);
|
||||
|
||||
int dump_focused_title_change_event(yajl_gen gen, const int mon_num,
|
||||
const Window client_id,
|
||||
const char *old_name, const char *new_name);
|
||||
|
||||
int dump_client_state(yajl_gen gen, const ClientState *state);
|
||||
|
||||
int dump_focused_state_change_event(yajl_gen gen, const int mon_num,
|
||||
const Window client_id,
|
||||
const ClientState *old_state,
|
||||
const ClientState *new_state);
|
||||
|
||||
int dump_error_message(yajl_gen gen, const char *reason);
|
||||
|
||||
#endif // YAJL_DUMPS_H_
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
void
|
||||
centeredfloatingmaster(Monitor *m)
|
||||
{
|
||||
unsigned int i, n;
|
||||
float mfacts, sfacts;
|
||||
int mrest, srest;
|
||||
int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
int sx = 0, sy = 0, sh = 0, sw = 0;
|
||||
Client *c;
|
||||
|
||||
float mivf = 1.0; // master inner vertical gap factor
|
||||
int oh, ov, ih, iv;
|
||||
getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
sx = mx = m->wx + ov;
|
||||
sy = my = m->wy + oh;
|
||||
sh = mh = m->wh - 2*oh;
|
||||
mw = m->ww - 2*ov - iv*(n - 1);
|
||||
sw = m->ww - 2*ov - iv*(n - m->nmaster - 1);
|
||||
|
||||
if (m->nmaster && n > m->nmaster) {
|
||||
mivf = 0.8;
|
||||
/* go mfact box in the center if more than nmaster clients */
|
||||
if (m->ww > m->wh) {
|
||||
mw = m->ww * m->mfact - iv*mivf*(MIN(n, m->nmaster) - 1);
|
||||
mh = m->wh * 0.9;
|
||||
} else {
|
||||
mw = m->ww * 0.9 - iv*mivf*(MIN(n, m->nmaster) - 1);
|
||||
mh = m->wh * m->mfact;
|
||||
}
|
||||
mx = m->wx + (m->ww - mw) / 2;
|
||||
my = m->wy + (m->wh - mh - 2*oh) / 2;
|
||||
|
||||
sx = m->wx + ov;
|
||||
sy = m->wy + oh;
|
||||
sh = m->wh - 2*oh;
|
||||
}
|
||||
|
||||
getfacts(m, mw, sw, &mfacts, &sfacts, &mrest, &srest);
|
||||
|
||||
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
|
||||
if (i < m->nmaster) {
|
||||
/* nmaster clients are stacked horizontally, in the center of the screen */
|
||||
resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
|
||||
mx += WIDTH(c) + iv*mivf;
|
||||
} else {
|
||||
/* stack clients are stacked horizontally */
|
||||
resize(c, sx, sy, (sw / sfacts) + ((i - m->nmaster) < srest ? 1 : 0) - (2*c->bw), sh - (2*c->bw), 0);
|
||||
sx += WIDTH(c) + iv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
static void centeredfloatingmaster(Monitor *m);
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
void
|
||||
centeredmaster(Monitor *m)
|
||||
{
|
||||
unsigned int i, n;
|
||||
int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
int lx = 0, ly = 0, lw = 0, lh = 0;
|
||||
int rx = 0, ry = 0, rw = 0, rh = 0;
|
||||
float mfacts = 0, lfacts = 0, rfacts = 0;
|
||||
int mtotal = 0, ltotal = 0, rtotal = 0;
|
||||
int mrest = 0, lrest = 0, rrest = 0;
|
||||
Client *c;
|
||||
|
||||
int oh, ov, ih, iv;
|
||||
getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
/* initialize areas */
|
||||
mx = m->wx + ov;
|
||||
my = m->wy + oh;
|
||||
mh = m->wh - 2*oh - ih * ((!m->nmaster ? n : MIN(n, m->nmaster)) - 1);
|
||||
mw = m->ww - 2*ov;
|
||||
lh = m->wh - 2*oh - ih * (((n - m->nmaster) / 2) - 1);
|
||||
rh = m->wh - 2*oh - ih * (((n - m->nmaster) / 2) - ((n - m->nmaster) % 2 ? 0 : 1));
|
||||
|
||||
if (m->nmaster && n > m->nmaster) {
|
||||
/* go mfact box in the center if more than nmaster clients */
|
||||
if (n - m->nmaster > 1) {
|
||||
/* ||<-S->|<---M--->|<-S->|| */
|
||||
mw = (m->ww - 2*ov - 2*iv) * m->mfact;
|
||||
lw = (m->ww - mw - 2*ov - 2*iv) / 2;
|
||||
mx += lw + iv;
|
||||
} else {
|
||||
/* ||<---M--->|<-S->|| */
|
||||
mw = (mw - iv) * m->mfact;
|
||||
lw = m->ww - mw - iv - 2*ov;
|
||||
}
|
||||
rw = lw;
|
||||
lx = m->wx + ov;
|
||||
ly = m->wy + oh;
|
||||
rx = mx + mw + iv;
|
||||
ry = m->wy + oh;
|
||||
}
|
||||
|
||||
/* calculate facts */
|
||||
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
|
||||
if (!m->nmaster || n < m->nmaster)
|
||||
mfacts += 1;
|
||||
else if ((n - m->nmaster) % 2)
|
||||
lfacts += 1; // total factor of left hand stack area
|
||||
else
|
||||
rfacts += 1; // total factor of right hand stack area
|
||||
}
|
||||
|
||||
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
|
||||
if (!m->nmaster || n < m->nmaster)
|
||||
mtotal += mh / mfacts;
|
||||
else if ((n - m->nmaster) % 2)
|
||||
ltotal += lh / lfacts;
|
||||
else
|
||||
rtotal += rh / rfacts;
|
||||
|
||||
mrest = mh - mtotal;
|
||||
lrest = lh - ltotal;
|
||||
rrest = rh - rtotal;
|
||||
|
||||
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
||||
if (!m->nmaster || i < m->nmaster) {
|
||||
/* nmaster clients are stacked vertically, in the center of the screen */
|
||||
resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
|
||||
my += HEIGHT(c) + ih;
|
||||
} else {
|
||||
/* stack clients are stacked vertically */
|
||||
if ((i - m->nmaster) % 2 ) {
|
||||
resize(c, lx, ly, lw - (2*c->bw), (lh / lfacts) + ((i - 2*m->nmaster) < 2*lrest ? 1 : 0) - (2*c->bw), 0);
|
||||
ly += HEIGHT(c) + ih;
|
||||
} else {
|
||||
resize(c, rx, ry, rw - (2*c->bw), (rh / rfacts) + ((i - 2*m->nmaster) < 2*rrest ? 1 : 0) - (2*c->bw), 0);
|
||||
ry += HEIGHT(c) + ih;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
static void centeredmaster(Monitor *m);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
void
|
||||
getfacts(Monitor *m, int msize, int ssize, float *mf, float *sf, int *mr, int *sr)
|
||||
{
|
||||
unsigned int n;
|
||||
float mfacts, sfacts;
|
||||
int mtotal = 0, stotal = 0;
|
||||
Client *c;
|
||||
|
||||
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
||||
mfacts = MIN(n, m->nmaster);
|
||||
sfacts = n - m->nmaster;
|
||||
|
||||
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
|
||||
if (n < m->nmaster)
|
||||
mtotal += msize / mfacts;
|
||||
else
|
||||
stotal += ssize / sfacts;
|
||||
|
||||
*mf = mfacts; // total factor of master area
|
||||
*sf = sfacts; // total factor of stack area
|
||||
*mr = msize - mtotal; // the remainder (rest) of pixels after an even master split
|
||||
*sr = ssize - stotal; // the remainder (rest) of pixels after an even stack split
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
void
|
||||
fibonacci(Monitor *m, int s)
|
||||
{
|
||||
unsigned int i, n;
|
||||
int nx, ny, nw, nh;
|
||||
int oh, ov, ih, iv;
|
||||
int nv, hrest = 0, wrest = 0, r = 1;
|
||||
Client *c;
|
||||
|
||||
getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
nx = m->wx + ov;
|
||||
ny = oh;
|
||||
nw = m->ww - 2*ov;
|
||||
nh = m->wh - 2*oh;
|
||||
|
||||
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
|
||||
if (r) {
|
||||
if ((i % 2 && (nh - ih) / 2 <= (bh + 2*c->bw))
|
||||
|| (!(i % 2) && (nw - iv) / 2 <= (bh + 2*c->bw))) {
|
||||
r = 0;
|
||||
}
|
||||
if (r && i < n - 1) {
|
||||
if (i % 2) {
|
||||
nv = (nh - ih) / 2;
|
||||
hrest = nh - 2*nv - ih;
|
||||
nh = nv;
|
||||
} else {
|
||||
nv = (nw - iv) / 2;
|
||||
wrest = nw - 2*nv - iv;
|
||||
nw = nv;
|
||||
}
|
||||
|
||||
if ((i % 4) == 2 && !s)
|
||||
nx += nw + iv;
|
||||
else if ((i % 4) == 3 && !s)
|
||||
ny += nh + ih;
|
||||
}
|
||||
|
||||
if ((i % 4) == 0) {
|
||||
if (s) {
|
||||
ny += nh + ih;
|
||||
nh += hrest;
|
||||
}
|
||||
else {
|
||||
nh -= hrest;
|
||||
ny -= nh + ih;
|
||||
}
|
||||
}
|
||||
else if ((i % 4) == 1) {
|
||||
nx += nw + iv;
|
||||
nw += wrest;
|
||||
}
|
||||
else if ((i % 4) == 2) {
|
||||
ny += nh + ih;
|
||||
nh += hrest;
|
||||
if (i < n - 1)
|
||||
nw += wrest;
|
||||
}
|
||||
else if ((i % 4) == 3) {
|
||||
if (s) {
|
||||
nx += nw + iv;
|
||||
nw -= wrest;
|
||||
} else {
|
||||
nw -= wrest;
|
||||
nx -= nw + iv;
|
||||
nh += hrest;
|
||||
}
|
||||
}
|
||||
if (i == 0) {
|
||||
if (n != 1) {
|
||||
nw = (m->ww - iv - 2*ov) - (m->ww - iv - 2*ov) * (1 - m->mfact);
|
||||
wrest = 0;
|
||||
}
|
||||
ny = m->wy + oh;
|
||||
}
|
||||
else if (i == 1)
|
||||
nw = m->ww - nw - iv - 2*ov;
|
||||
i++;
|
||||
}
|
||||
|
||||
resize(c, nx, ny, nw - (2*c->bw), nh - (2*c->bw), False);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
dwindle(Monitor *m)
|
||||
{
|
||||
fibonacci(m, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
static void dwindle(Monitor *m);
|
||||
static void fibonacci(Monitor *m, int s);
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
void
|
||||
monocle(Monitor *m)
|
||||
{
|
||||
unsigned int n = 0;
|
||||
Client *c;
|
||||
|
||||
for (c = m->clients; c; c = c->next)
|
||||
if (ISVISIBLE(c))
|
||||
n++;
|
||||
if (n > 0) /* override layout symbol */
|
||||
snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n);
|
||||
for (c = nexttiled(m->clients); c; c = nexttiled(c->next))
|
||||
resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
static void monocle(Monitor *m);
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
void
|
||||
nrowgrid(Monitor *m)
|
||||
{
|
||||
unsigned int n = 0, i = 0, ri = 0, ci = 0; /* counters */
|
||||
int oh, ov, ih, iv; /* vanitygap settings */
|
||||
unsigned int cx, cy, cw, ch; /* client geometry */
|
||||
unsigned int uw = 0, uh = 0, uc = 0; /* utilization trackers */
|
||||
unsigned int cols, rows = m->nmaster + 1;
|
||||
Client *c;
|
||||
|
||||
/* count clients */
|
||||
getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
|
||||
/* nothing to do here */
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
/* force 2 clients to always split vertically */
|
||||
if (FORCE_VSPLIT && n == 2)
|
||||
rows = 1;
|
||||
|
||||
/* never allow empty rows */
|
||||
if (n < rows)
|
||||
rows = n;
|
||||
|
||||
/* define first row */
|
||||
cols = n / rows;
|
||||
uc = cols;
|
||||
cy = m->wy + oh;
|
||||
ch = (m->wh - 2*oh - ih*(rows - 1)) / rows;
|
||||
uh = ch;
|
||||
|
||||
for (c = nexttiled(m->clients); c; c = nexttiled(c->next), i++, ci++) {
|
||||
if (ci == cols) {
|
||||
uw = 0;
|
||||
ci = 0;
|
||||
ri++;
|
||||
|
||||
/* next row */
|
||||
cols = (n - uc) / (rows - ri);
|
||||
uc += cols;
|
||||
cy = m->wy + oh + uh + ih;
|
||||
uh += ch + ih;
|
||||
}
|
||||
|
||||
cx = m->wx + ov + uw;
|
||||
cw = (m->ww - 2*ov - uw) / (cols - ci);
|
||||
uw += cw + iv;
|
||||
|
||||
resize(c, cx, cy, cw - (2*c->bw), ch - (2*c->bw), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
static void nrowgrid(Monitor *m);
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
static void
|
||||
tile(Monitor *m)
|
||||
{
|
||||
unsigned int i, n;
|
||||
int mx = 0, my = 0, mh = 0, mw = 0;
|
||||
int sx = 0, sy = 0, sh = 0, sw = 0;
|
||||
float mfacts, sfacts;
|
||||
int mrest, srest;
|
||||
Client *c;
|
||||
|
||||
|
||||
int oh, ov, ih, iv;
|
||||
getgaps(m, &oh, &ov, &ih, &iv, &n);
|
||||
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
sx = mx = m->wx + ov;
|
||||
sy = my = m->wy + oh;
|
||||
mh = m->wh - 2*oh - ih * (MIN(n, m->nmaster) - 1);
|
||||
sh = m->wh - 2*oh - ih * (n - m->nmaster - 1);
|
||||
sw = mw = m->ww - 2*ov;
|
||||
|
||||
if (m->nmaster && n > m->nmaster) {
|
||||
sw = (mw - iv) * (1 - m->mfact);
|
||||
mw = (mw - iv) * m->mfact;
|
||||
sx = mx + mw + iv;
|
||||
}
|
||||
|
||||
getfacts(m, mh, sh, &mfacts, &sfacts, &mrest, &srest);
|
||||
|
||||
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
|
||||
if (i < m->nmaster) {
|
||||
resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
|
||||
my += HEIGHT(c) + ih;
|
||||
} else {
|
||||
resize(c, sx, sy, sw - (2*c->bw), (sh / sfacts) + ((i - m->nmaster) < srest ? 1 : 0) - (2*c->bw), 0);
|
||||
sy += HEIGHT(c) + ih;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
static void tile(Monitor *);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
struct Pertag {
|
||||
unsigned int curtag, prevtag; /* current and previous tag */
|
||||
int nmasters[NUMTAGS + 1]; /* number of windows in master area */
|
||||
const Layout *ltidxs[NUMTAGS + 1][2]; /* matrix of tags and layouts indexes */
|
||||
float mfacts[NUMTAGS + 1]; /* mfacts per tag */
|
||||
unsigned int sellts[NUMTAGS + 1]; /* selected layouts */
|
||||
};
|
||||
|
||||
void
|
||||
pertagview(const Arg *arg)
|
||||
{
|
||||
int i;
|
||||
unsigned int tmptag;
|
||||
if (arg->ui & TAGMASK) {
|
||||
selmon->pertag->prevtag = selmon->pertag->curtag;
|
||||
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
|
||||
if (arg->ui == ~0)
|
||||
selmon->pertag->curtag = 0;
|
||||
else {
|
||||
for (i = 0; !(arg->ui & 1 << i); i++) ;
|
||||
selmon->pertag->curtag = i + 1;
|
||||
}
|
||||
} else {
|
||||
tmptag = selmon->pertag->prevtag;
|
||||
selmon->pertag->prevtag = selmon->pertag->curtag;
|
||||
selmon->pertag->curtag = tmptag;
|
||||
}
|
||||
selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
|
||||
selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
|
||||
selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
|
||||
selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
|
||||
selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
static void pertagview(const Arg *arg);
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
static Client * scratchpad_last_showed = NULL;
|
||||
|
||||
void
|
||||
scratchpad_hide()
|
||||
{
|
||||
if (selmon->sel) {
|
||||
selmon->sel->tags = SCRATCHPAD_MASK;
|
||||
selmon->sel->isfloating = 1;
|
||||
focus(NULL);
|
||||
arrange(selmon);
|
||||
}
|
||||
}
|
||||
|
||||
_Bool
|
||||
scratchpad_last_showed_is_killed(void)
|
||||
{
|
||||
Client *c;
|
||||
for (c = selmon->clients; c && c != scratchpad_last_showed; c = c->next);
|
||||
return (c == NULL);
|
||||
}
|
||||
|
||||
void
|
||||
scratchpad_remove()
|
||||
{
|
||||
if (selmon->sel && scratchpad_last_showed != NULL && selmon->sel == scratchpad_last_showed)
|
||||
scratchpad_last_showed = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
scratchpad_show()
|
||||
{
|
||||
if (scratchpad_last_showed == NULL || scratchpad_last_showed_is_killed()) {
|
||||
scratchpad_show_first();
|
||||
return;
|
||||
}
|
||||
|
||||
if (scratchpad_last_showed->tags != SCRATCHPAD_MASK) {
|
||||
scratchpad_last_showed->tags = SCRATCHPAD_MASK;
|
||||
focus(NULL);
|
||||
arrange(selmon);
|
||||
return;
|
||||
}
|
||||
|
||||
Client *c;
|
||||
|
||||
for (c = selmon->clients; c && c != scratchpad_last_showed; c = c->next);
|
||||
for (c = (c ? c->next : NULL); c && c->tags != SCRATCHPAD_MASK; c = c->next);
|
||||
|
||||
if (c)
|
||||
scratchpad_show_client(c);
|
||||
else
|
||||
scratchpad_show_first();
|
||||
}
|
||||
|
||||
void
|
||||
scratchpad_show_client(Client* c)
|
||||
{
|
||||
scratchpad_last_showed = c;
|
||||
c->tags = selmon->tagset[selmon->seltags];
|
||||
focus(c);
|
||||
arrange(selmon);
|
||||
}
|
||||
|
||||
void
|
||||
scratchpad_show_first(void)
|
||||
{
|
||||
Client *c;
|
||||
for (c = selmon->clients; c && c->tags != SCRATCHPAD_MASK; c = c->next);
|
||||
if (c)
|
||||
scratchpad_show_client(c);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#define SCRATCHPAD_MASK (1u << NUMTAGS)
|
||||
|
||||
static void scratchpad_hide();
|
||||
static _Bool scratchpad_last_showed_is_killed(void);
|
||||
static void scratchpad_remove();
|
||||
static void scratchpad_show();
|
||||
static void scratchpad_show_client(Client *c);
|
||||
static void scratchpad_show_first(void);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
void
|
||||
togglesticky(const Arg *arg)
|
||||
{
|
||||
if (!selmon->sel)
|
||||
return;
|
||||
selmon->sel->issticky = !selmon->sel->issticky;
|
||||
arrange(selmon);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
static void togglesticky(const Arg *arg);
|
||||
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
#include <X11/Xlib-xcb.h>
|
||||
#include <xcb/res.h>
|
||||
#ifdef __OpenBSD__
|
||||
#include <sys/sysctl.h>
|
||||
#include <kvm.h>
|
||||
#endif /* __OpenBSD__ */
|
||||
|
||||
static int scanner;
|
||||
static xcb_connection_t *xcon;
|
||||
|
||||
int
|
||||
swallow(Client *p, Client *c)
|
||||
{
|
||||
Client *s;
|
||||
XWindowChanges wc;
|
||||
|
||||
if (c->noswallow > 0 || c->isterminal)
|
||||
return 0;
|
||||
if (c->noswallow < 0 && !swallowfloating && c->isfloating)
|
||||
return 0;
|
||||
|
||||
XMapWindow(dpy, c->win);
|
||||
|
||||
detach(c);
|
||||
detachstack(c);
|
||||
|
||||
setclientstate(c, WithdrawnState);
|
||||
XUnmapWindow(dpy, p->win);
|
||||
|
||||
p->swallowing = c;
|
||||
c->mon = p->mon;
|
||||
|
||||
Window w = p->win;
|
||||
p->win = c->win;
|
||||
c->win = w;
|
||||
|
||||
XChangeProperty(dpy, c->win, netatom[NetClientList], XA_WINDOW, 32, PropModeReplace,
|
||||
(unsigned char *) &(p->win), 1);
|
||||
|
||||
updatetitle(p);
|
||||
s = scanner ? c : p;
|
||||
setfloatinghint(s);
|
||||
|
||||
wc.border_width = p->bw;
|
||||
XConfigureWindow(dpy, p->win, CWBorderWidth, &wc);
|
||||
XMoveResizeWindow(dpy, p->win, s->x, s->y, s->w, s->h);
|
||||
XSetWindowBorder(dpy, p->win, scheme[SchemeNorm][ColBorder].pixel);
|
||||
|
||||
arrange(p->mon);
|
||||
configure(p);
|
||||
updateclientlist();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
unswallow(Client *c)
|
||||
{
|
||||
XWindowChanges wc;
|
||||
c->win = c->swallowing->win;
|
||||
|
||||
free(c->swallowing);
|
||||
c->swallowing = NULL;
|
||||
|
||||
XDeleteProperty(dpy, c->win, netatom[NetClientList]);
|
||||
|
||||
/* unfullscreen the client */
|
||||
setfullscreen(c, 0);
|
||||
updatetitle(c);
|
||||
arrange(c->mon);
|
||||
XMapWindow(dpy, c->win);
|
||||
|
||||
wc.border_width = c->bw;
|
||||
XConfigureWindow(dpy, c->win, CWBorderWidth, &wc);
|
||||
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
|
||||
XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel);
|
||||
|
||||
setfloatinghint(c);
|
||||
setclientstate(c, NormalState);
|
||||
focus(NULL);
|
||||
arrange(c->mon);
|
||||
}
|
||||
|
||||
pid_t
|
||||
winpid(Window w)
|
||||
{
|
||||
pid_t result = 0;
|
||||
|
||||
#ifdef __linux__
|
||||
xcb_res_client_id_spec_t spec = {0};
|
||||
spec.client = w;
|
||||
spec.mask = XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID;
|
||||
|
||||
xcb_generic_error_t *e = NULL;
|
||||
xcb_res_query_client_ids_cookie_t c = xcb_res_query_client_ids(xcon, 1, &spec);
|
||||
xcb_res_query_client_ids_reply_t *r = xcb_res_query_client_ids_reply(xcon, c, &e);
|
||||
|
||||
if (!r)
|
||||
return (pid_t)0;
|
||||
|
||||
xcb_res_client_id_value_iterator_t i = xcb_res_query_client_ids_ids_iterator(r);
|
||||
for (; i.rem; xcb_res_client_id_value_next(&i)) {
|
||||
spec = i.data->spec;
|
||||
if (spec.mask & XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID) {
|
||||
uint32_t *t = xcb_res_client_id_value_value(i.data);
|
||||
result = *t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(r);
|
||||
|
||||
if (result == (pid_t)-1)
|
||||
result = 0;
|
||||
|
||||
#endif /* __linux__ */
|
||||
#ifdef __OpenBSD__
|
||||
Atom type;
|
||||
int format;
|
||||
unsigned long len, bytes;
|
||||
unsigned char *prop;
|
||||
pid_t ret;
|
||||
|
||||
if (XGetWindowProperty(dpy, w, XInternAtom(dpy, "_NET_WM_PID", 1), 0, 1, False, AnyPropertyType, &type, &format, &len, &bytes, &prop) != Success || !prop)
|
||||
return 0;
|
||||
|
||||
ret = *(pid_t*)prop;
|
||||
XFree(prop);
|
||||
result = ret;
|
||||
#endif /* __OpenBSD__ */
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
pid_t
|
||||
getparentprocess(pid_t p)
|
||||
{
|
||||
unsigned int v = 0;
|
||||
|
||||
#ifdef __linux__
|
||||
FILE *f;
|
||||
char buf[256];
|
||||
snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p);
|
||||
|
||||
if (!(f = fopen(buf, "r")))
|
||||
return (pid_t)0;
|
||||
|
||||
if (fscanf(f, "%*u %*s %*c %u", (unsigned *)&v) != 1)
|
||||
v = (pid_t)0;
|
||||
fclose(f);
|
||||
#endif /* __linux__ */
|
||||
#ifdef __OpenBSD__
|
||||
int n;
|
||||
kvm_t *kd;
|
||||
struct kinfo_proc *kp;
|
||||
|
||||
kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, NULL);
|
||||
if (!kd)
|
||||
return 0;
|
||||
|
||||
kp = kvm_getprocs(kd, KERN_PROC_PID, p, sizeof(*kp), &n);
|
||||
v = kp->p_ppid;
|
||||
#endif /* __OpenBSD__ */
|
||||
return (pid_t)v;
|
||||
}
|
||||
|
||||
int
|
||||
isdescprocess(pid_t p, pid_t c)
|
||||
{
|
||||
while (p != c && c != 0)
|
||||
c = getparentprocess(c);
|
||||
|
||||
return (int)c;
|
||||
}
|
||||
|
||||
Client *
|
||||
termforwin(const Client *w)
|
||||
{
|
||||
Client *c;
|
||||
Monitor *m;
|
||||
|
||||
if (!w->pid || w->isterminal)
|
||||
return NULL;
|
||||
|
||||
c = selmon->sel;
|
||||
if (c && c->isterminal && !c->swallowing && c->pid && isdescprocess(c->pid, w->pid))
|
||||
return c;
|
||||
|
||||
for (m = mons; m; m = m->next) {
|
||||
for (c = m->clients; c; c = c->next) {
|
||||
if (c->isterminal && !c->swallowing && c->pid && isdescprocess(c->pid, w->pid))
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Client *
|
||||
swallowingclient(Window w)
|
||||
{
|
||||
Client *c;
|
||||
Monitor *m;
|
||||
|
||||
for (m = mons; m; m = m->next) {
|
||||
for (c = m->clients; c; c = c->next) {
|
||||
if (c->swallowing && c->swallowing->win == w)
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
static pid_t getparentprocess(pid_t p);
|
||||
static int isdescprocess(pid_t p, pid_t c);
|
||||
static int swallow(Client *p, Client *c);
|
||||
static Client *swallowingclient(Window w);
|
||||
static Client *termforwin(const Client *c);
|
||||
static void unswallow(Client *c);
|
||||
static pid_t winpid(Window w);
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
void
|
||||
tagallmon(const Arg *arg)
|
||||
{
|
||||
Monitor *m;
|
||||
Client *c, *last, *slast, *next;
|
||||
|
||||
if (!mons->next)
|
||||
return;
|
||||
|
||||
m = dirtomon(arg->i);
|
||||
for (last = m->clients; last && last->next; last = last->next);
|
||||
for (slast = m->stack; slast && slast->snext; slast = slast->snext);
|
||||
|
||||
for (c = selmon->clients; c; c = next) {
|
||||
next = c->next;
|
||||
if (!ISVISIBLE(c))
|
||||
continue;
|
||||
unfocus(c, 1, NULL);
|
||||
detach(c);
|
||||
detachstack(c);
|
||||
c->mon = m;
|
||||
c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
|
||||
c->next = NULL;
|
||||
c->snext = NULL;
|
||||
if (last)
|
||||
last = last->next = c;
|
||||
else
|
||||
m->clients = last = c;
|
||||
if (slast)
|
||||
slast = slast->snext = c;
|
||||
else
|
||||
m->stack = slast = c;
|
||||
if (c->isfullscreen) {
|
||||
if (c->fakefullscreen != 1) {
|
||||
resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh);
|
||||
XRaiseWindow(dpy, c->win);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
focus(NULL);
|
||||
arrange(NULL);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
static void tagallmon(const Arg *arg);
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
void
|
||||
tagswapmon(const Arg *arg)
|
||||
{
|
||||
Monitor *m;
|
||||
Client *c, *sc = NULL, *mc = NULL, *next;
|
||||
|
||||
if (!mons->next)
|
||||
return;
|
||||
|
||||
m = dirtomon(arg->i);
|
||||
|
||||
for (c = selmon->clients; c; c = next) {
|
||||
next = c->next;
|
||||
if (!ISVISIBLE(c))
|
||||
continue;
|
||||
unfocus(c, 1, NULL);
|
||||
detach(c);
|
||||
detachstack(c);
|
||||
c->next = sc;
|
||||
sc = c;
|
||||
}
|
||||
|
||||
for (c = m->clients; c; c = next) {
|
||||
next = c->next;
|
||||
if (!ISVISIBLE(c))
|
||||
continue;
|
||||
unfocus(c, 1, NULL);
|
||||
detach(c);
|
||||
detachstack(c);
|
||||
c->next = mc;
|
||||
mc = c;
|
||||
}
|
||||
|
||||
for (c = sc; c; c = next) {
|
||||
next = c->next;
|
||||
c->mon = m;
|
||||
c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
|
||||
attach(c);
|
||||
attachstack(c);
|
||||
if (c->isfullscreen) {
|
||||
if (c->fakefullscreen != 1) {
|
||||
resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh);
|
||||
XRaiseWindow(dpy, c->win);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (c = mc; c; c = next) {
|
||||
next = c->next;
|
||||
c->mon = selmon;
|
||||
c->tags = selmon->tagset[selmon->seltags]; /* assign tags of target monitor */
|
||||
attach(c);
|
||||
attachstack(c);
|
||||
if (c->isfullscreen) {
|
||||
if (c->fakefullscreen != 1) {
|
||||
resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh);
|
||||
XRaiseWindow(dpy, c->win);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
focus(NULL);
|
||||
arrange(NULL);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
static void tagswapmon(const Arg *arg);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
void
|
||||
transfer(const Arg *arg)
|
||||
{
|
||||
Client *c, *mtail = selmon->clients, *stail = NULL, *insertafter;
|
||||
int transfertostack = 0, i, nmasterclients;
|
||||
|
||||
for (i = 0, c = selmon->clients; c; c = c->next) {
|
||||
if (!ISVISIBLE(c) || c->isfloating) continue;
|
||||
if (selmon->sel == c) { transfertostack = i < selmon->nmaster && selmon->nmaster != 0; }
|
||||
if (i < selmon->nmaster) { nmasterclients++; mtail = c; }
|
||||
stail = c;
|
||||
i++;
|
||||
}
|
||||
if (!selmon->sel || selmon->sel->isfloating || i == 0) {
|
||||
return;
|
||||
} else if (transfertostack) {
|
||||
selmon->nmaster = MIN(i, selmon->nmaster) - 1;
|
||||
insertafter = stail;
|
||||
} else {
|
||||
selmon->nmaster = selmon->nmaster + 1;
|
||||
insertafter = mtail;
|
||||
}
|
||||
if (insertafter != selmon->sel) {
|
||||
detach(selmon->sel);
|
||||
if (selmon->nmaster == 1 && !transfertostack) {
|
||||
attach(selmon->sel); // Head prepend case
|
||||
} else {
|
||||
selmon->sel->next = insertafter->next;
|
||||
insertafter->next = selmon->sel;
|
||||
}
|
||||
}
|
||||
arrange(selmon);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
static void transfer(const Arg *arg);
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
/* Settings */
|
||||
static int enablegaps = 1;
|
||||
|
||||
static void
|
||||
setgaps(int oh, int ov, int ih, int iv)
|
||||
{
|
||||
if (oh < 0) oh = 0;
|
||||
if (ov < 0) ov = 0;
|
||||
if (ih < 0) ih = 0;
|
||||
if (iv < 0) iv = 0;
|
||||
|
||||
selmon->gappoh = oh;
|
||||
selmon->gappov = ov;
|
||||
selmon->gappih = ih;
|
||||
selmon->gappiv = iv;
|
||||
|
||||
|
||||
arrange(selmon);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
togglegaps(const Arg *arg)
|
||||
{
|
||||
enablegaps = !enablegaps;
|
||||
arrange(NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
defaultgaps(const Arg *arg)
|
||||
{
|
||||
setgaps(gappoh, gappov, gappih, gappiv);
|
||||
}
|
||||
|
||||
static void
|
||||
incrgaps(const Arg *arg)
|
||||
{
|
||||
setgaps(
|
||||
selmon->gappoh + arg->i,
|
||||
selmon->gappov + arg->i,
|
||||
selmon->gappih + arg->i,
|
||||
selmon->gappiv + arg->i
|
||||
);
|
||||
}
|
||||
|
||||
static void
|
||||
incrigaps(const Arg *arg)
|
||||
{
|
||||
setgaps(
|
||||
selmon->gappoh,
|
||||
selmon->gappov,
|
||||
selmon->gappih + arg->i,
|
||||
selmon->gappiv + arg->i
|
||||
);
|
||||
}
|
||||
|
||||
static void
|
||||
incrogaps(const Arg *arg)
|
||||
{
|
||||
setgaps(
|
||||
selmon->gappoh + arg->i,
|
||||
selmon->gappov + arg->i,
|
||||
selmon->gappih,
|
||||
selmon->gappiv
|
||||
);
|
||||
}
|
||||
|
||||
static void
|
||||
incrohgaps(const Arg *arg)
|
||||
{
|
||||
setgaps(
|
||||
selmon->gappoh + arg->i,
|
||||
selmon->gappov,
|
||||
selmon->gappih,
|
||||
selmon->gappiv
|
||||
);
|
||||
}
|
||||
|
||||
static void
|
||||
incrovgaps(const Arg *arg)
|
||||
{
|
||||
setgaps(
|
||||
selmon->gappoh,
|
||||
selmon->gappov + arg->i,
|
||||
selmon->gappih,
|
||||
selmon->gappiv
|
||||
);
|
||||
}
|
||||
|
||||
static void
|
||||
incrihgaps(const Arg *arg)
|
||||
{
|
||||
setgaps(
|
||||
selmon->gappoh,
|
||||
selmon->gappov,
|
||||
selmon->gappih + arg->i,
|
||||
selmon->gappiv
|
||||
);
|
||||
}
|
||||
|
||||
static void
|
||||
incrivgaps(const Arg *arg)
|
||||
{
|
||||
setgaps(
|
||||
selmon->gappoh,
|
||||
selmon->gappov,
|
||||
selmon->gappih,
|
||||
selmon->gappiv + arg->i
|
||||
);
|
||||
}
|
||||
|
||||
static void
|
||||
getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc)
|
||||
{
|
||||
unsigned int n, oe, ie;
|
||||
oe = ie = enablegaps;
|
||||
Client *c;
|
||||
|
||||
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
||||
if (n == 1) {
|
||||
oe *= smartgaps_fact; // outer gaps disabled or multiplied when only one client
|
||||
}
|
||||
|
||||
*oh = m->gappoh*oe; // outer horizontal gap
|
||||
*ov = m->gappov*oe; // outer vertical gap
|
||||
*ih = m->gappih*ie; // inner horizontal gap
|
||||
*iv = m->gappiv*ie; // inner vertical gap
|
||||
*nc = n; // number of clients
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/* Key binding functions */
|
||||
static void defaultgaps(const Arg *arg);
|
||||
static void incrgaps(const Arg *arg);
|
||||
static void incrigaps(const Arg *arg);
|
||||
static void incrogaps(const Arg *arg);
|
||||
static void incrohgaps(const Arg *arg);
|
||||
static void incrovgaps(const Arg *arg);
|
||||
static void incrihgaps(const Arg *arg);
|
||||
static void incrivgaps(const Arg *arg);
|
||||
static void togglegaps(const Arg *arg);
|
||||
|
||||
/* Internals */
|
||||
static void getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc);
|
||||
static void setgaps(int oh, int ov, int ih, int iv);
|
||||
|
||||
Reference in New Issue
Block a user