aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/wm/wm.h
blob: 1e9e41e76185a61ee72c047293f2f3c5a0586565 (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
#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_cursor.h>
#include <wlr/types/wlr_compositor.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_input_device.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output_management_v1.h>
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_primary_selection_v1.h>
#include <wlr/types/wlr_pointer.h>
#include <wlr/types/wlr_presentation_time.h>
#include <wlr/types/wlr_screencopy_v1.h>
#include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_viewporter.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_activation_v1.h>
#include <wlr/types/wlr_xdg_decoration_v1.h>
#include <wlr/types/wlr_xdg_output_v1.h>
#include <wlr/types/wlr_xdg_shell.h>

#include <wlr/util/log.h>

#include <xkbcommon/xkbcommon.h>

// -----------------------------------------------------------------------
// macros

#define ROUND(x)    ((int)((x)+0.5))

// -----------------------------------------------------------------------
// types

enum
{
    CursorPassthrough,
    CursorMove,
    CursorResize,
};

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

typedef struct MonitorRule MonitorRule;

struct Rectangle
{
    int x, y;
    int w, h;
};

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

struct Key
{
    uint           modifier;
    xkb_keysym_t   sym;
    void (*action)(Arg *);
    Arg            arg;
};

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

struct Keyboard
{
    struct wl_list link;
    struct wlr_input_device *device;
    struct {
        struct wl_listener press;
        struct wl_listener modify;
        struct wl_listener destroy;
    } event;
};

struct Client
{
    struct wl_list link;
    struct wl_list stack;

    struct wlr_xdg_surface *xdg;

    struct {
        struct wl_listener map;
        struct wl_listener unmap;
        struct wl_listener commit;
        struct wl_listener destroy;
        struct wl_listener request_move;
        struct wl_listener request_title;
        struct wl_listener request_resize;
        struct wl_listener request_fullscreen;
    } event;

    struct wlr_box geo, oldgeo;

    Monitor *monitor;

    uint tags;
    int  border       : 4;
    int  ismapped     : 1;
    int  isfloating   : 1;
    int  isurgent     : 1;
    int  isfullscreen : 1;

    uint32 resize;
};

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

struct Monitor
{
    struct wl_list link;
    struct wlr_output *output;
    struct {
        struct wl_listener render;
        struct wl_listener destroy;
    } event;

    struct wlr_box geometry;
    struct wlr_box window;

    Layout *layout[2];
    struct {
        uint set[2];
        uint selected;
    } tag;
    struct {
        double frac;
        int    len;
    } master;
};

struct MonitorRule
{
    char   *name;
    Layout *layout;
    int     x, y;
    float   scale;
    enum wl_output_transform transform;
    struct {
        double frac;
        int    len;
    } master;
};

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

struct Server
{
    struct wl_display       *display;
    struct wlr_backend      *backend;
    struct wlr_renderer     *renderer;
    struct wlr_presentation *present;

    struct {
        struct wlr_xdg_shell *xdg;
    } shell;

    struct {
        struct wl_list list;
        struct wl_list stack;
    } client;
    Client *selected;

    struct {
        Client *client;
        double x, y;
        struct wlr_box box;
    } grab;
    uint32 resize;

    struct {
        struct wlr_output_layout *layout;
        struct wl_list            list;
        struct wlr_box            geometry;
    } monitor;

    struct {
        struct wlr_cursor          *dot;
        struct wlr_xcursor_manager *manager;
        int                         mode;
    } cursor;

    struct {
        struct wlr_seat *seat;
        struct wl_list   keyboards;
    } input;

    struct {
        struct wl_listener make_input;
        struct wl_listener make_monitor;
        struct wl_listener make_xdg_surface;
        struct wl_listener make_layer_surface;

        struct wl_listener cursor_move;
        struct wl_listener cursor_move_abs;
        struct wl_listener cursor_button;
        struct wl_listener cursor_axis;
        struct wl_listener cursor_frame;

        struct wl_listener request_cursor;
        struct wl_listener request_set_selection;
    } event;
};

extern struct Server server;

// -----------------------------------------------------------------------
// functions

/* util.c */
void scale_box(struct wlr_box *, float);

/* output.c */
void make_monitor(struct wl_listener *, void *);

/* xdg.c */
void make_xdg_surface(struct wl_listener *, void *);

/* input.c */
void make_input(struct wl_listener *, void *);

void cursor_axis(struct wl_listener *, void *);
void cursor_frame(struct wl_listener *, void *);
void cursor_button(struct wl_listener *, void *);
void cursor_move(struct wl_listener *, void *);
void cursor_move_abs(struct wl_listener *, void *);

void request_cursor(struct wl_listener *, void *);
void request_set_selection(struct wl_listener *, void *);

/* client.c */
void    focus(Client *, struct wlr_surface *);
void    resize(Client *, int x, int y, int w, int h, int interact);
Client* client_at(double, double, struct wlr_surface **, double *, double *);
int     client_has(Client *, double, double, struct wlr_surface **, double *, double *);
void    setinteractive(Client *client, int mode, uint32 edges);

#define CONFIG(a,b,...) extern a cfg·##b
#include "config.h"
#undef CONFIG