aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/dwm/dwm.h
blob: 148ca8904c809e090027ce80f9c3f274d58cbb59 (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
#pragma once

#include <u.h>
#include <libn.h>

#include <wayland-server-core.h>

#define WLR_USE_UNSTABLE
#include <wlr/backend.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_data_control_v1.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_export_dmabuf_v1.h>
#include <wlr/types/wlr_gamma_control_v1.h>
#include <wlr/types/wlr_gtk_primary_selection.h>
#include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_layer_shell_v1.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_damage.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_pointer.h>
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_primary_selection_v1.h>
#include <wlr/types/wlr_screencopy_v1.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_decoration_v1.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/types/wlr_xdg_output_v1.h>
#include <wlr/util/log.h>

#include "xdg-shell.h"
#include "wlr-layer-shell.h"

#include <signal.h>
#include <wait.h>
#include <xkbcommon/xkbcommon.h>
#include <linux/input-event-codes.h>


/* global macros */
#define VISIBLEON(C, M)         ((C)->m == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
#define CLEANMASK(mask)         (mask & ~WLR_MODIFIER_CAPS)
#define TAGMASK                 ((1 << arrlen(tags)) - 1)

/* main types */

typedef union  Arg      Arg;
typedef struct Button   Button;
typedef struct Mouse    Mouse;
typedef struct Grab     Grab;
typedef struct Key      Key;
typedef struct Keyboard Keyboard;
typedef struct Monitor  Monitor;
typedef struct Layout   Layout;
typedef struct Client   Client;
typedef struct Deco     Deco;
typedef struct Layer    Layer;
typedef struct Payload  Payload;

typedef struct Rule        Rule;
typedef struct MonitorRule MonitorRule;

typedef struct WindowManager WindowManager;

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

struct Button
{
    uint mod;
    uint kind;
    void (*func)(const Arg *);
    Arg  arg;
};

enum 
{
    MouseNormal=0, MouseMove, MouseResize,
};

struct Mouse
{
    uint mode;
    struct wlr_xcursor_manager *manager;
    struct wlr_cursor          *cursor;
    struct {
        struct wl_listener axis;
        struct wl_listener frame;
        struct wl_listener button;
        struct wl_listener motion;
        struct wl_listener absmotion;
        struct wl_listener cursor;
        struct wl_listener sel;
        struct wl_listener psel;
    } ev;
};

struct Grab 
{
    Client *c;
    int    x, y;
};

struct Key
{
    uint32       mod;
    xkb_keysym_t sym;
    void (*func)(const Arg *);
    Arg  arg;
};

struct Keyboard
{
    struct wl_list          link;
    struct wlr_input_device *dev;
    struct {
        struct wl_listener modifier;
        struct wl_listener keypress;
    } ev;
};

struct Layer
{
    struct wl_list link;
    struct wlr_layer_surface_v1 *surf;

    struct {
        struct wl_listener map;
        struct wl_listener unmap;
        struct wl_listener free;
        struct wl_listener commit;
        struct wl_listener detach;
        /* struct wl_listener popup; */
    } ev;

    struct wlr_box dim;
	enum zwlr_layer_shell_v1_layer z;
};
struct Monitor {
    struct wl_list    link;
    struct wlr_output *dev;
    struct {
        struct wl_listener draw;
        struct wl_listener free;
    } ev;
    struct {
        struct wl_signal kill;
    } sig;
    struct {
        struct wlr_box all;
        struct wlr_box win;
    } area;

    struct wl_list layers[4];
    struct wlr_output_damage damage;

    const  Layout *lt[2];
    uint   seltags;
    uint   sellt;
    uint   tagset[2];
    double mfact;
    int    nmaster;
};

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

struct MonitorRule {
	char *name;
	float mfact;
	int   nmaster;
	float scale;
	const Layout *lt;
	enum wl_output_transform rr;
};

struct Rule {
	char *id;
	char *title;
	uint tags;
	int  floating;
	int  monitor;
};

struct Client
{
    struct wlr_xdg_surface *surf;
    struct wlr_box          dim;
    struct {
        struct wl_list tiles;
        struct wl_list stack;
        struct wl_list focus;
    } link;
    struct {
        struct wl_listener map;
        struct wl_listener unmap;
        struct wl_listener free;
    } ev;
    int   bw;
    uint  tags;
    int   floating;
    Monitor *m;
};

struct Deco
{
	struct wl_list link;
	struct wlr_server_decoration *wlr;

    struct {
        struct wl_listener free;
        struct wl_listener mode;
    } ev;
};

struct Payload
{
    struct wlr_output *dev;
    struct timespec   *now;
    int x, y;
};

struct WindowManager 
{
    struct wl_display         *display;
    struct wlr_backend        *backend;
    struct wlr_renderer       *draw;
    struct wlr_compositor     *compositor;
    struct wlr_xdg_shell      *xdgsh;
    struct wlr_layer_shell_v1 *laysh;
    struct wlr_output_layout  *layout;
    struct wlr_idle           *idle;
    struct wlr_seat           *seat;

    struct {
        struct wlr_server_decoration_manager *deco;
        struct wlr_xdg_decoration_manager    *xdeco;
    } mngr;

    struct {
        struct wl_event_loop *loop;
        /* i/o devices */
        struct wl_listener input;
        struct wl_listener output;
        struct wl_listener client;
        /* shells */
        struct wl_listener layer;
        struct wl_listener deco;
    } ev; 

    struct {
        struct wl_list odevs;
        struct wl_list idevs;
        struct wl_list tiles; /* order of tiles */
        struct wl_list stack; /* order w/in stack */
        struct wl_list focus; /* order of focus */
        struct wl_list keyboards;
        struct wl_list decos;
    };

    /* geometry of union of output devices */
    struct wlr_box dim;
};

/* funcs.c */
void chvt(const Arg *arg);
void incmaster(const Arg *arg);
void focusmonitor(const Arg *arg);
void focusstack(const Arg *arg);
void moveresize(const Arg *arg);
void quit(const Arg *arg);
void setlayout(const Arg *arg);
void setmfact(const Arg *arg);
void spawn(const Arg *arg);
void tag(const Arg *arg);
void tagmonitor(const Arg *arg);
void togglefloating(const Arg *arg);
void toggletag(const Arg *arg);
void toggleview(const Arg *arg);
void view(const Arg *arg);

/* layouts */
void tile(Monitor *m);

#include "config.h"

// -----------------------------------------------------------------------
// global variables

extern Mouse         mouse;
extern Grab          grab;
extern Monitor      *monitor; /* currently focused */
extern WindowManager dwm;

// -----------------------------------------------------------------------
// global functions

/* util.c */
void     fatal(byte *fmt, ...);
void     scale(struct wlr_box *box, float by);

/* input.c */
void     ev·newinput(struct wl_listener *ev, void *arg);

/* client.c */
void     ev·newclient(struct wl_listener *ev, void *arg);

void     applybounds(Client *c, struct wlr_box *bbox);
void     applyrules(Client *c);
Client  *clientat(double x, double y);
Client  *getclient(void);
Client  *lastfocus(void);
void     resize(Client *c, int x, int y, int w, int h, int interact);
void     setfocus(Client *c, struct wlr_surface *surf, int lift);
void     setfloating(Client *c, int f);
void     pointerfocus(Client *c, struct wlr_surface *surf, double sx, double sy, uint32 time);

/* output.c */
void     ev·newmonitor(struct wl_listener *ev, void *arg);

void     arrange(Monitor *m);
void     setmonitor(Client *c, Monitor *m, uint newtags);
Monitor *getmonitor(int dir);
Monitor *monitorat(double x, double y);

/* layer.c */
void     ev·newlayershell(struct wl_listener *ev, void *arg);
void     arrangelayers(Monitor *m);

/* decoration.c */
void     ev·newdecoration(struct wl_listener *ev, void *arg);