initial config
This commit is contained in:
parent
9f8855343c
commit
5899adaea5
8 changed files with 1252 additions and 118 deletions
173
dwm.c
173
dwm.c
|
@ -56,6 +56,7 @@
|
|||
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
|
||||
#define TAGMASK ((1 << LENGTH(tags)) - 1)
|
||||
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
||||
#define OPAQUE 0xffU
|
||||
|
||||
/* enums */
|
||||
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
|
||||
|
@ -87,6 +88,7 @@ typedef struct Client Client;
|
|||
struct Client {
|
||||
char name[256];
|
||||
float mina, maxa;
|
||||
float cfact;
|
||||
int x, y, w, h;
|
||||
int oldx, oldy, oldw, oldh;
|
||||
int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvalid;
|
||||
|
@ -119,6 +121,10 @@ struct Monitor {
|
|||
int by; /* bar geometry */
|
||||
int mx, my, mw, mh; /* screen size */
|
||||
int wx, wy, ww, wh; /* window area */
|
||||
int gappih; /* horizontal gap between windows */
|
||||
int gappiv; /* vertical gap between windows */
|
||||
int gappoh; /* horizontal outer gaps */
|
||||
int gappov; /* vertical outer gaps */
|
||||
unsigned int seltags;
|
||||
unsigned int sellt;
|
||||
unsigned int tagset[2];
|
||||
|
@ -147,6 +153,7 @@ static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interac
|
|||
static void arrange(Monitor *m);
|
||||
static void arrangemon(Monitor *m);
|
||||
static void attach(Client *c);
|
||||
static void attachbottom(Client *c);
|
||||
static void attachstack(Client *c);
|
||||
static void buttonpress(XEvent *e);
|
||||
static void checkotherwm(void);
|
||||
|
@ -201,16 +208,19 @@ static void setclientstate(Client *c, long state);
|
|||
static void setfocus(Client *c);
|
||||
static void setfullscreen(Client *c, int fullscreen);
|
||||
static void setlayout(const Arg *arg);
|
||||
static void setcfact(const Arg *arg);
|
||||
static void setmfact(const Arg *arg);
|
||||
static void setup(void);
|
||||
static void seturgent(Client *c, int urg);
|
||||
static void showhide(Client *c);
|
||||
static int solitary(Client *c);
|
||||
static void spawn(const Arg *arg);
|
||||
static void tag(const Arg *arg);
|
||||
static void tagview(const Arg *arg);
|
||||
static void tagmon(const Arg *arg);
|
||||
static void tile(Monitor *m);
|
||||
static void togglebar(const Arg *arg);
|
||||
static void togglefloating(const Arg *arg);
|
||||
static void togglefullscr(const Arg *arg);
|
||||
static void toggletag(const Arg *arg);
|
||||
static void toggleview(const Arg *arg);
|
||||
static void unfocus(Client *c, int setfocus);
|
||||
|
@ -232,6 +242,7 @@ static Monitor *wintomon(Window w);
|
|||
static int xerror(Display *dpy, XErrorEvent *ee);
|
||||
static int xerrordummy(Display *dpy, XErrorEvent *ee);
|
||||
static int xerrorstart(Display *dpy, XErrorEvent *ee);
|
||||
static void xinitvisual();
|
||||
static void zoom(const Arg *arg);
|
||||
|
||||
/* variables */
|
||||
|
@ -268,6 +279,11 @@ static Drw *drw;
|
|||
static Monitor *mons, *selmon;
|
||||
static Window root, wmcheckwin;
|
||||
|
||||
static int useargb = 0;
|
||||
static Visual *visual;
|
||||
static int depth;
|
||||
static Colormap cmap;
|
||||
|
||||
/* configuration, allows nested code to access above variables */
|
||||
#include "config.h"
|
||||
|
||||
|
@ -408,6 +424,15 @@ attach(Client *c)
|
|||
c->mon->clients = c;
|
||||
}
|
||||
|
||||
void
|
||||
attachbottom(Client *c)
|
||||
{
|
||||
Client **tc;
|
||||
c->next = NULL;
|
||||
for (tc = &c->mon->clients; *tc; tc = &(*tc)->next);
|
||||
*tc = c;
|
||||
}
|
||||
|
||||
void
|
||||
attachstack(Client *c)
|
||||
{
|
||||
|
@ -641,6 +666,10 @@ createmon(void)
|
|||
m->nmaster = nmaster;
|
||||
m->showbar = showbar;
|
||||
m->topbar = topbar;
|
||||
m->gappih = gappih;
|
||||
m->gappiv = gappiv;
|
||||
m->gappoh = gappoh;
|
||||
m->gappov = gappov;
|
||||
m->lt[0] = &layouts[0];
|
||||
m->lt[1] = &layouts[1 % LENGTH(layouts)];
|
||||
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
|
||||
|
@ -801,7 +830,11 @@ focus(Client *c)
|
|||
detachstack(c);
|
||||
attachstack(c);
|
||||
grabbuttons(c, 1);
|
||||
XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel);
|
||||
/* Avoid flickering when another client appears and the border
|
||||
* is restored */
|
||||
if (!solitary(c)) {
|
||||
XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel);
|
||||
}
|
||||
setfocus(c);
|
||||
} else {
|
||||
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
|
||||
|
@ -1043,6 +1076,7 @@ manage(Window w, XWindowAttributes *wa)
|
|||
c->w = c->oldw = wa->width;
|
||||
c->h = c->oldh = wa->height;
|
||||
c->oldbw = wa->border_width;
|
||||
c->cfact = 1.0;
|
||||
|
||||
updatetitle(c);
|
||||
if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) {
|
||||
|
@ -1074,7 +1108,11 @@ manage(Window w, XWindowAttributes *wa)
|
|||
c->isfloating = c->oldstate = trans != None || c->isfixed;
|
||||
if (c->isfloating)
|
||||
XRaiseWindow(dpy, c->win);
|
||||
attach(c);
|
||||
if (inversedirection) {
|
||||
attachbottom(c);
|
||||
} else {
|
||||
attach(c);
|
||||
}
|
||||
attachstack(c);
|
||||
XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
|
||||
(unsigned char *) &(c->win), 1);
|
||||
|
@ -1292,6 +1330,11 @@ resizeclient(Client *c, int x, int y, int w, int h)
|
|||
c->oldw = c->w; c->w = wc.width = w;
|
||||
c->oldh = c->h; c->h = wc.height = h;
|
||||
wc.border_width = c->bw;
|
||||
if (solitary(c)) {
|
||||
c->w = wc.width += c->bw * 2;
|
||||
c->h = wc.height += c->bw * 2;
|
||||
wc.border_width = 0;
|
||||
}
|
||||
XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
|
||||
configure(c);
|
||||
XSync(dpy, False);
|
||||
|
@ -1427,7 +1470,11 @@ sendmon(Client *c, Monitor *m)
|
|||
detachstack(c);
|
||||
c->mon = m;
|
||||
c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
|
||||
attach(c);
|
||||
if (inversedirection) {
|
||||
attachbottom(c);
|
||||
} else {
|
||||
attach(c);
|
||||
}
|
||||
attachstack(c);
|
||||
focus(NULL);
|
||||
arrange(NULL);
|
||||
|
@ -1521,6 +1568,24 @@ setlayout(const Arg *arg)
|
|||
drawbar(selmon);
|
||||
}
|
||||
|
||||
void
|
||||
setcfact(const Arg *arg) {
|
||||
float f;
|
||||
Client *c;
|
||||
|
||||
c = selmon->sel;
|
||||
|
||||
if(!arg || !c || !selmon->lt[selmon->sellt]->arrange)
|
||||
return;
|
||||
f = arg->f + c->cfact;
|
||||
if(arg->f == 0.0)
|
||||
f = 1.0;
|
||||
else if(f < 0.25 || f > 4.0)
|
||||
return;
|
||||
c->cfact = f;
|
||||
arrange(selmon);
|
||||
}
|
||||
|
||||
/* arg > 1.0 will set mfact absolutely */
|
||||
void
|
||||
setmfact(const Arg *arg)
|
||||
|
@ -1558,7 +1623,8 @@ setup(void)
|
|||
sw = DisplayWidth(dpy, screen);
|
||||
sh = DisplayHeight(dpy, screen);
|
||||
root = RootWindow(dpy, screen);
|
||||
drw = drw_create(dpy, screen, root, sw, sh);
|
||||
xinitvisual();
|
||||
drw = drw_create(dpy, screen, root, sw, sh, visual, depth, cmap);
|
||||
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
|
||||
die("no fonts could be loaded.");
|
||||
lrpad = drw->fonts->h;
|
||||
|
@ -1586,7 +1652,7 @@ setup(void)
|
|||
/* init appearance */
|
||||
scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
|
||||
for (i = 0; i < LENGTH(colors); i++)
|
||||
scheme[i] = drw_scm_create(drw, colors[i], 3);
|
||||
scheme[i] = drw_scm_create(drw, colors[i], alphas[i], 3);
|
||||
/* init bars */
|
||||
updatebars();
|
||||
updatestatus();
|
||||
|
@ -1644,6 +1710,15 @@ showhide(Client *c)
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
solitary(Client *c)
|
||||
{
|
||||
return ((nexttiled(c->mon->clients) == c && !nexttiled(c->next))
|
||||
|| &monocle == c->mon->lt[c->mon->sellt]->arrange)
|
||||
&& !c->isfullscreen && !c->isfloating
|
||||
&& NULL != c->mon->lt[c->mon->sellt]->arrange;
|
||||
}
|
||||
|
||||
void
|
||||
spawn(const Arg *arg)
|
||||
{
|
||||
|
@ -1685,31 +1760,10 @@ tagmon(const Arg *arg)
|
|||
}
|
||||
|
||||
void
|
||||
tile(Monitor *m)
|
||||
tagview(const Arg *arg)
|
||||
{
|
||||
unsigned int i, n, h, mw, my, ty;
|
||||
Client *c;
|
||||
|
||||
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
if (n > m->nmaster)
|
||||
mw = m->nmaster ? m->ww * m->mfact : 0;
|
||||
else
|
||||
mw = m->ww;
|
||||
for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
|
||||
if (i < m->nmaster) {
|
||||
h = (m->wh - my) / (MIN(n, m->nmaster) - i);
|
||||
resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
|
||||
if (my + HEIGHT(c) < m->wh)
|
||||
my += HEIGHT(c);
|
||||
} else {
|
||||
h = (m->wh - ty) / (n - i);
|
||||
resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
|
||||
if (ty + HEIGHT(c) < m->wh)
|
||||
ty += HEIGHT(c);
|
||||
}
|
||||
tag(arg);
|
||||
view(arg);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1735,6 +1789,13 @@ togglefloating(const Arg *arg)
|
|||
arrange(selmon);
|
||||
}
|
||||
|
||||
void
|
||||
togglefullscr(const Arg *arg)
|
||||
{
|
||||
if(selmon->sel)
|
||||
setfullscreen(selmon->sel, !selmon->sel->isfullscreen);
|
||||
}
|
||||
|
||||
void
|
||||
toggletag(const Arg *arg)
|
||||
{
|
||||
|
@ -1821,16 +1882,18 @@ updatebars(void)
|
|||
Monitor *m;
|
||||
XSetWindowAttributes wa = {
|
||||
.override_redirect = True,
|
||||
.background_pixmap = ParentRelative,
|
||||
.background_pixel = 0,
|
||||
.border_pixel = 0,
|
||||
.colormap = cmap,
|
||||
.event_mask = ButtonPressMask|ExposureMask
|
||||
};
|
||||
XClassHint ch = {"dwm", "dwm"};
|
||||
for (m = mons; m; m = m->next) {
|
||||
if (m->barwin)
|
||||
continue;
|
||||
m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
|
||||
CopyFromParent, DefaultVisual(dpy, screen),
|
||||
CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
|
||||
m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, depth,
|
||||
InputOutput, visual,
|
||||
CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &wa);
|
||||
XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
|
||||
XMapRaised(dpy, m->barwin);
|
||||
XSetClassHint(dpy, m->barwin, &ch);
|
||||
|
@ -1915,6 +1978,11 @@ updategeom(void)
|
|||
m->clients = c->next;
|
||||
detachstack(c);
|
||||
c->mon = mons;
|
||||
if (inversedirection) {
|
||||
attachbottom(c);
|
||||
} else {
|
||||
attach(c);
|
||||
}
|
||||
attach(c);
|
||||
attachstack(c);
|
||||
}
|
||||
|
@ -2128,6 +2196,43 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
|
|||
return -1;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
zoom(const Arg *arg)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue