about summary refs log tree commit diff stats
path: root/dwm.h
blob: 0ed778cb149230dc6eab7121bab2e5add43e6137 (plain) (blame)
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
/*
 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
 * See LICENSE file for license details.
 */

#include <X11/Xlib.h>
#include CONFIG

/* mask shorthands, used in event.c and client.c */
#define BUTTONMASK		(ButtonPressMask | ButtonReleaseMask)
#define MOUSEMASK		(BUTTONMASK | PointerMotionMask)
#define PROTODELWIN		1

typedef union Arg Arg;
typedef struct Client Client;
typedef struct DC DC;
typedef struct Fnt Fnt;

union Arg {
	const char **argv;
	int i;
};

/* atoms */
enum { NetSupported, NetWMName, NetLast };
enum { WMProtocols, WMDelete, WMLast };

/* cursor */
enum { CurNormal, CurResize, CurMove, CurLast };

/* windowcorners */
typedef enum { TopLeft, TopRight, BotLeft, BotRight } Corner;

struct Fnt {
	int ascent;
	int descent;
	int height;
	XFontSet set;
	XFontStruct *xfont;
};

struct DC { /* draw context */
	int x, y, w, h;
	unsigned long bg;
	unsigned long fg;
	unsigned long border;
	Drawable drawable;
	Fnt font;
	GC gc;
};

struct Client {
	char name[256];
	char *tags[TLast];
	int proto;
	int x, y, w, h;
	int tx, ty, tw, th; /* title */
	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
	int grav;
	unsigned int border;
	long flags; 
	Bool isfloat;
	Bool ismax;
	Client *next;
	Client *prev;
	Window win;
	Window title;
};

extern char *tags[TLast], stext[1024];
extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
extern void (*handler[LASTEvent])(XEvent *);
extern void (*arrange)(Arg *);
extern Atom wmatom[WMLast], netatom[NetLast];
extern Bool running, issel;
extern Client *clients, *sel;
extern Cursor cursor[CurLast];
extern DC dc;
extern Display *dpy;
extern Window root, barwin;

/* client.c */
extern void ban(Client *c);
extern void focus(Client *c);
extern void focusnext(Arg *arg);
extern void focusprev(Arg *arg);
extern Client *getclient(Window w);
extern Client *getctitle(Window w);
extern void gravitate(Client *c, Bool invert);
extern void higher(Client *c);
extern void killclient(Arg *arg);
extern void lower(Client *c);
extern void manage(Window w, XWindowAttributes *wa);
extern void resize(Client *c, Bool sizehints, Corner sticky);
extern void setsize(Client *c);
extern void settitle(Client *c);
extern void togglemax(Arg *arg);
extern void unmanage(Client *c);
extern void zoom(Arg *arg);

/* draw.c */
extern void drawall();
extern void drawstatus();
extern void drawtitle(Client *c);
extern unsigned long getcolor(const char *colstr);
extern void setfont(const char *fontstr);
extern unsigned int textw(char *text);

/* event.c */
extern void grabkeys();

/* main.c */
extern int getproto(Window w);
extern void quit(Arg *arg);
extern void sendevent(Window w, Atom a, long value);
extern int xerror(Display *dsply, XErrorEvent *ee);

/* tag.c */
extern void appendtag(Arg *arg);
extern void dofloat(Arg *arg);
extern void dotile(Arg *arg);
extern Client *getnext(Client *c);
extern Client *getprev(Client *c);
extern void replacetag(Arg *arg);
extern void settags(Client *c);
extern void togglemode(Arg *arg);
extern void view(Arg *arg);
extern void viewnext(Arg *arg);
extern void viewprev(Arg *arg);

/* util.c */
extern void *emallocz(unsigned int size);
extern void eprint(const char *errstr, ...);
extern void spawn(Arg *arg);
span>).) * `App.mouse_y()` -- returns the x coordinate of the current position of the mouse. (Based on [LÖVE](https://love2d.org/wiki/love.mouse.getY).) ### keyboard primitives * `App.modifier_down(key)` -- returns `true` if the given key (doesn't actually have to be just a modifier) is currently pressed. (Based on [LÖVE](https://love2d.org/wiki/love.keyboard.isDown).) ### interacting with files * `App.open_for_reading(filename)` -- returns a file handle that you can [`read()`](https://www.lua.org/manual/5.1/manual.html#pdf-file:read) from. Make sure `filename` is an absolute path so that your app can work reliably by double-clicking on it. (Based on [Lua](https://www.lua.org/manual/5.1/manual.html#pdf-io.open).) * `App.open_for_writing(filename)` -- returns a file handle that you can [`write()`](https://www.lua.org/manual/5.1/manual.html#pdf-file:write) to. Make sure `filename` is an absolute path so that your app can work reliably by double-clicking on it. (Based on [Lua](https://www.lua.org/manual/5.1/manual.html#pdf-io.open).) * `json.encode(obj)` -- returns a JSON string for an object `obj` that will recreate `obj` when passed to `json.decode`. `obj` can be of most types but has some exceptions. (From [json.lua](https://github.com/rxi/json.lua).) * `json.decode(obj)` -- turns a JSON string into a Lua object. (From [json.lua](https://github.com/rxi/json.lua).) * `love.filesystem.getDirectoryItems(dir)` -- returns an unsorted array of the files and directories available under `dir`. `dir` must be relative to [LÖVE's save directory](https://love2d.org/wiki/love.filesystem.getSaveDirectory). There is no easy, portable way in Lua/LÖVE to list directories outside the save dir. (From [LÖVE](https://love2d.org/wiki/love.filesystem.getDirectoryItems).] * `love.filesystem.getInfo(filename)` -- returns some information about `filename`, particularly whether it exists (non-`nil` return value) or not. `filename` must be relative to [LÖVE's save directory](https://love2d.org/wiki/love.filesystem.getSaveDirectory). (From [LÖVE](https://love2d.org/wiki/love.filesystem.getInfo).] * `os.remove(filename)` -- removes a file or empty directory. Definitely make sure `filename` is an absolute path. (From [Lua](https://www.lua.org/manual/5.1/manual.html#pdf-os.remove).) There's much more I could include here; check out [the LÖVE manual](https://love2d.org/wiki/love.filesystem) and [the Lua manual](https://www.lua.org/manual/5.1/manual.html#5.7). ### desiderata * `App.getTime()` -- returns the number of seconds elapsed since some unspecified start time. (Based on [LÖVE](https://love2d.org/wiki/love.timer.getTime).) * `App.getClipboardText()` -- returns a string with the current clipboard contents. (Based on [LÖVE](https://love2d.org/wiki/love.system.getClipboardText).) * `App.setClipboardText(text)` -- stores the string `text` in the clipboard. (Based on [LÖVE](https://love2d.org/wiki/love.system.setClipboardText).) There's much more I could include here; check out [the LÖVE manual](https://love2d.org/wiki) and [the Lua manual](https://www.lua.org/manual/5.1/manual.html). ### writing tests * `App.screen.init{width=.., height=..}` -- creates a fake screen for a test * `App.screen.check(y, expected_contents, msg)` -- verifies text written to the fake screen at `y`. This isn't very realistic; `y` must exactly match what was displayed, and the expected contents show everything printed to that `y` in chronological order, regardless of `x` coordinate. In spite of these limitations, you can write lots of useful tests with this. * `App.run_after_textinput(t)` -- mimics keystrokes resulting in `t` and then draws one frame. * `App.run_after_keychord(chord)` -- mimics keystrokes resulting in `chord` and then draws one frame. * `App.run_after_mouse_press(x,y, mouse_button)` -- mimics a mouse press down followed by drawing a frame. * `App.run_after_mouse_release(x,y, mouse_button)` -- mimics a mouse release up followed by drawing a frame. * `App.run_after_mouse_click(x,y, mouse_button)` -- mimics a mouse press down and mouse release up followed by drawing a frame. * `App.wait_fake_time(t)` -- simulates the passage of time for `App.getTime()`.