aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/dwm/dwm.h
blob: a93428711ed23f3947cb338df1b2db53af01779e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/* See LICENSE file for copyright and license details. */
#pragma once
#include <u.h>
#include <libn.h>

#include <errno.h>
#include <locale.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

#include <X11/cursorfont.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <X11/Xproto.h>
#include <X11/Xutil.h>
#include <X11/Xlib-xcb.h>
#include <xcb/res.h>
#include <X11/extensions/Xinerama.h>
#include <X11/Xft/Xft.h>
#include <X11/XF86keysym.h>

/* macros */
#define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
#define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
#define INTERSECT(x,y,w,h,m)    (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
                               * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
#define ISVISIBLE(C)            ((C->tags & C->mon->tagset[C->mon->seltags]))
#define MOUSEMASK               (BUTTONMASK|PointerMotionMask)
#define WIDTH(X)                ((X)->w + 2 * (X)->bw)
#define HEIGHT(X)               ((X)->h + 2 * (X)->bw)
#define TAGMASK                 ((1 << arrlen(tags)) - 1)
#define TEXTW(X)                (drw_fontset_getwidth(drw, (X)) + lrpad)
#define BETWEEN(X, A, B)        ((A) <= (X) && (X) <= (B))


/* enums */
enum 
{
    MouseNormal, 
    MouseResize, 
    MouseMove, 
    MouseLast,
}; /* mouse states */ 

enum 
{ 
    SchemeNorm, 
    SchemeSel 
}; /* color schemes */ 

enum 
{ 
    NetSupported, 
    NetWMName, 
    NetWMState, 
    NetWMCheck,
    NetWMFullscreen, 
    NetActiveWindow, 
    NetWMWindowType,
    NetWMWindowTypeDialog, 
    NetWMWindowOpacity,
    NetClientList, 
    NetLast 
}; /* EWMH atoms */

enum 
{ 
    WMProtocols, 
    WMDelete, 
    WMState, 
    WMTakeFocus, 
    WMLast 
}; /* default atoms */

enum 
{ 
    ClkTagBar, 
    ClkLtSymbol, 
    ClkStatusText, 
    ClkWinTitle,
    ClkClientWin, 
    ClkRootWin, 
    ClkLast 
}; /* clicks */

enum 
{ 
    ColFg, 
    ColBg, 
    ColBorder 
}; /* color scheme index */

typedef struct Monitor  Monitor;
typedef struct Layout   Layout;
typedef struct Client   Client;
typedef struct Keyboard Keyboard;
typedef struct Button   Button;
typedef struct Key      Key;
typedef struct Rule     Rule;
typedef union  Arg      Arg;

union Arg {
	int i;
	uint ui;
	float f;
	void *v;
};

struct Button {
	uint click;
	uint mask;
	uint button;
	void (*func)(Arg *arg);
	Arg arg;
};

struct Client {
	char name[256];
	float mina, maxa;
	int  x, y, w, h;
	int  oldx, oldy, oldw, oldh;
	int  basew, baseh, incw, inch, maxw, maxh, minw, minh;
	int  bw, oldbw;
	uint tags;
	int  isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, isterm, noswallow;
    pid_t pid;
	Client  *next;
	Client  *snext;
    Client  *swallowing;
	Monitor *mon;
	Window   win;
};

struct Key {
	uint mod;
	KeySym keysym;
	void (*func)(Arg *);
	Arg arg;
};

struct Layout {
	char *symbol;
	void (*arrange)(Monitor *);
};

struct Monitor {
	char ltsymbol[16];
	float mfact;
	int nmaster;
	int num;
	int by;               /* bar geometry */
	int mx, my, mw, mh;   /* screen size */
	int wx, wy, ww, wh;   /* window area  */
	uint seltags;
	uint sellt;
	uint tagset[2];
	int showbar;
	int topbar;
	Client *clients;
	Client *sel;
	Client *stack;
	Monitor *next;
	Window barwin;
	Layout *lt[2];
};

struct Rule {
	char *class;
	char *instance;
	char *title;
	uint tags;
	int isfloating;
    int isterm;
    int noswallow;
	int monitor;
};

/* draw.c */
typedef struct {
    Cursor cursor;
} Cur;

typedef struct Fnt {
	Display  *dpy;
	uint      h;
	XftFont   *xfont;
	FcPattern *pattern;
	struct Fnt *next;
} Fnt;

typedef XftColor Clr;

typedef struct {
	uint w, h;
	Display *dpy;
	int      screen;
	Window   root;
	Drawable drawable;
	GC       gc;
	Clr     *scheme;
	Fnt     *fonts;
} Drw;

/* global state */

extern char broken[];
extern char stext[256];
extern int scanner;
extern int screen;
extern int sw, sh;           
extern int bh, blw;
extern int lrpad;
extern int (*xerrorxlib)(Display *, XErrorEvent *);
extern uint numlockmask;
extern void (*handler[LASTEvent]) (XEvent *);
extern int scratchtag;

extern xcb_connection_t *xcon;

extern Atom wmatom[WMLast], netatom[NetLast];
extern int running; 
extern Cur   *cursor[MouseLast]; 
extern Clr **scheme; 
extern Display *dpy; 
extern Drw *drw; 
extern Monitor *mons, *selmon;
extern Window root, wmcheckwin;

// -----------------------------------------------------------------------
// function declarations

// TODO: remove declarations that don't require global existence...
void     applyrules(Client *c);
int      applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
void     arrange(Monitor *m);
void     arrangemon(Monitor *m);
void     attach(Client *c);
void     enqueue(Client *c);
void     attachbottom(Client *c);
void     attachstack(Client *c);
void     enqueuestack(Client *c);
void     buttonpress(XEvent *e);
void     checkotherwm(void);
void     cleanup(void);
void     cleanupmon(Monitor *mon);
void     clientmessage(XEvent *e);
void     configure(Client *c);
void     configurenotify(XEvent *e);
void     configurerequest(XEvent *e);
Monitor *createmon(void);
void     destroynotify(XEvent *e);
void     detach(Client *c);
void     detachstack(Client *c);
Monitor *dirtomon(int dir);
void     drawbar(Monitor *m);
void     drawbars(void);
void     enternotify(XEvent *e);
void     expose(XEvent *e);
void     focus(Client *c);
void     focusin(XEvent *e);
void     focusmon(Arg *arg);
void     focusstack(Arg *arg);
void     focusdirection(Arg *arg);
void     rotatestack(Arg *arg);
Atom     getatomprop(Client *c, Atom prop);
int      getrootptr(int *x, int *y);
long     getstate(Window w);
int      gettextprop(Window w, Atom atom, char *text, uint size);
void     grabbuttons(Client *c, int focused);
void     grabkeys(void);
void     incnmaster(Arg *arg);
void     keypress(XEvent *e);
void     killclient(Arg *arg);
void     manage(Window w, XWindowAttributes *wa);
void     mappingnotify(XEvent *e);
void     maprequest(XEvent *e);
void     monocle(Monitor *m);
void     motionnotify(XEvent *e);
void     movemouse(Arg *arg);
Client  *nexttiled(Client *c);
void     pop(Client *);
void     propertynotify(XEvent *e);
void     quit(Arg *arg);
Monitor *recttomon(int x, int y, int w, int h);
void     resize(Client *c, int x, int y, int w, int h, int interact);
void     resizeclient(Client *c, int x, int y, int w, int h);
void     resizemouse(Arg *arg);
void     restack(Monitor *m);
void     run(void);
void     scan(void);
int      sendevent(Client *c, Atom proto);
void     sendtomon(Client *c, Monitor *m);
void     setclientstate(Client *c, long state);
void     setfocus(Client *c);
void     setfullscreen(Client *c, int fullscreen);
void     setlayout(Arg *arg);
void     setmfact(Arg *arg);
void     setup(void);
void     seturgent(Client *c, int urg);
void     showhide(Client *c);
void     sigchld(int unused);
void     swallow(Client *p, Client *c);
Client  *swallowing(Window w);
void     spawn(Arg *arg);
void     tag(Arg *arg);
void     tagmon(Arg *arg);
Client  *termof(Client *c);
void     tile(Monitor *);
void     togglebar(Arg *arg);
void     togglefocus(Arg *arg);
void     togglefloating(Arg *arg);
void     togglescratch(Arg *arg);
void     toggletag(Arg *arg);
void     toggleview(Arg *arg);
void     unfocus(Client *c, int setfocus);
void     unmanage(Client *c, int destroyed);
void     unmapnotify(XEvent *e);
void     unswallow(Client *c);
void     updatebarpos(Monitor *m);
void     updatebars(void);
void     updateclientlist(void);
int      updategeom(void);
void     updatenumlockmask(void);
void     updatesizehints(Client *c);
void     updatestatus(void);
void     updatetitle(Client *c);
void     updatewindowtype(Client *c);
void     updatewmhints(Client *c);
void     view(Arg *arg);
pid_t    winpid(Window w);
Client  *wintoclient(Window w);
Monitor *wintomon(Window w);
int      xerror(Display *dpy, XErrorEvent *ee);
int      xerrordummy(Display *dpy, XErrorEvent *ee);
int      xerrorstart(Display *dpy, XErrorEvent *ee);
void     zoom(Arg *arg);

#include "config.h"

/* draw.c */

/* Drawable abstraction */
Drw *drw_create(Display *dpy, int screen, Window win, uint w, uint h);
void drw_resize(Drw *drw, uint w, uint h);
void drw_free(Drw *drw);

/* Fnt abstraction */
Fnt *drw_fontset_create(Drw* drw, char *fonts[], size_t fontcount);
void drw_fontset_free(Fnt* set);
uint drw_fontset_getwidth(Drw *drw, char *text);
void drw_font_getexts(Fnt *font, char *text, uint len, uint *w, uint *h);

/* Colorscheme abstraction */
void   drw_clr_create(Drw *drw, Clr *dest, char *clrname);
Clr *drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount);

/* Cursor abstraction */
Cur *drw_cur_create(Drw *drw, int shape);
void drw_cur_free(Drw *drw, Cur *cursor);

/* Drawing context manipulation */
void drw_setfontset(Drw *drw, Fnt *set);
void drw_setscheme(Drw *drw, Clr *scm);

/* Drawing functions */
void drw_rect(Drw *drw, int x, int y, uint w, uint h, int filled, int invert);
int  drw_text(Drw *drw, int x, int y, uint w, uint h, uint lpad, char *text, int invert);

/* Map functions */
void drw_map(Drw *drw, Window win, int x, int y, uint w, uint h);

/* util.c */
void  fatal(char *fmt, ...);
void *ecalloc(size_t nmemb, size_t size);
pid_t getparentproc(pid_t p);
pid_t isdescendent(pid_t p, pid_t c);