aboutsummaryrefslogtreecommitdiffstats
path: root/include/sway/tree/view.h
blob: 7dc8ac4617d2f9b0762b0a9fdc9608a25f5fda2f (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
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
#ifndef _SWAY_VIEW_H
#define _SWAY_VIEW_H
#include <wayland-server.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/xwayland.h>
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"

struct sway_container;

enum sway_view_type {
	SWAY_VIEW_XDG_SHELL_V6,
	SWAY_VIEW_XDG_SHELL,
	SWAY_VIEW_XWAYLAND,
};

enum sway_view_prop {
	VIEW_PROP_TITLE,
	VIEW_PROP_APP_ID,
	VIEW_PROP_CLASS,
	VIEW_PROP_INSTANCE,
	VIEW_PROP_WINDOW_TYPE,
	VIEW_PROP_WINDOW_ROLE,
	VIEW_PROP_X11_WINDOW_ID,
};

struct sway_view_impl {
	const char *(*get_string_prop)(struct sway_view *view,
			enum sway_view_prop prop);
	uint32_t (*get_int_prop)(struct sway_view *view, enum sway_view_prop prop);
	uint32_t (*configure)(struct sway_view *view, double lx, double ly,
			int width, int height);
	void (*set_activated)(struct sway_view *view, bool activated);
	void (*set_tiled)(struct sway_view *view, bool tiled);
	void (*set_fullscreen)(struct sway_view *view, bool fullscreen);
	bool (*wants_floating)(struct sway_view *view);
	void (*for_each_surface)(struct sway_view *view,
		wlr_surface_iterator_func_t iterator, void *user_data);
	void (*close)(struct sway_view *view);
	void (*destroy)(struct sway_view *view);
};

struct sway_view {
	enum sway_view_type type;
	const struct sway_view_impl *impl;

	struct sway_container *swayc; // NULL for unmapped views
	struct wlr_surface *surface; // NULL for unmapped views

	// Geometry of the view itself (excludes borders) in layout coordinates
	double x, y;
	int width, height;

	double saved_x, saved_y;
	int saved_width, saved_height;

	// The size the view would want to be if it weren't tiled.
	// Used when changing a view from tiled to floating.
	int natural_width, natural_height;

	bool is_fullscreen;

	char *title_format;
	enum sway_container_border border;
	int border_thickness;
	bool border_top;
	bool border_bottom;
	bool border_left;
	bool border_right;

	bool destroying;

	list_t *executed_criteria; // struct criteria *
	list_t *marks;             // char *

	struct wlr_texture *marks_focused;
	struct wlr_texture *marks_focused_inactive;
	struct wlr_texture *marks_unfocused;
	struct wlr_texture *marks_urgent;

	union {
		struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6;
		struct wlr_xdg_surface *wlr_xdg_surface;
		struct wlr_xwayland_surface *wlr_xwayland_surface;
		struct wlr_wl_shell_surface *wlr_wl_shell_surface;
	};

	struct {
		struct wl_signal unmap;
	} events;

	struct wl_listener surface_new_subsurface;
	struct wl_listener container_reparent;
};

struct sway_xdg_shell_v6_view {
	struct sway_view view;

	struct wl_listener commit;
	struct wl_listener request_move;
	struct wl_listener request_resize;
	struct wl_listener request_maximize;
	struct wl_listener request_fullscreen;
	struct wl_listener new_popup;
	struct wl_listener map;
	struct wl_listener unmap;
	struct wl_listener destroy;
};

struct sway_xdg_shell_view {
	struct sway_view view;

	struct wl_listener commit;
	struct wl_listener request_move;
	struct wl_listener request_resize;
	struct wl_listener request_maximize;
	struct wl_listener request_fullscreen;
	struct wl_listener new_popup;
	struct wl_listener map;
	struct wl_listener unmap;
	struct wl_listener destroy;
};

struct sway_xwayland_view {
	struct sway_view view;

	struct wl_listener commit;
	struct wl_listener request_move;
	struct wl_listener request_resize;
	struct wl_listener request_maximize;
	struct wl_listener request_configure;
	struct wl_listener request_fullscreen;
	struct wl_listener set_title;
	struct wl_listener set_class;
	struct wl_listener set_window_type;
	struct wl_listener map;
	struct wl_listener unmap;
	struct wl_listener destroy;
};

struct sway_xwayland_unmanaged {
	struct wlr_xwayland_surface *wlr_xwayland_surface;
	struct wl_list link;

	int lx, ly;

	struct wl_listener request_configure;
	struct wl_listener request_fullscreen;
	struct wl_listener commit;
	struct wl_listener map;
	struct wl_listener unmap;
	struct wl_listener destroy;
};

struct sway_view_child;

struct sway_view_child_impl {
	void (*destroy)(struct sway_view_child *child);
};

/**
 * A view child is a surface in the view tree, such as a subsurface or a popup.
 */
struct sway_view_child {
	const struct sway_view_child_impl *impl;

	struct sway_view *view;
	struct wlr_surface *surface;

	struct wl_listener surface_commit;
	struct wl_listener surface_new_subsurface;
	struct wl_listener surface_destroy;
	struct wl_listener view_unmap;
};

struct sway_xdg_popup_v6 {
	struct sway_view_child child;

	struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6;

	struct wl_listener new_popup;
	struct wl_listener destroy;
};

struct sway_xdg_popup {
	struct sway_view_child child;

	struct wlr_xdg_surface *wlr_xdg_surface;

	struct wl_listener new_popup;
	struct wl_listener destroy;
};

const char *view_get_title(struct sway_view *view);

const char *view_get_app_id(struct sway_view *view);

const char *view_get_class(struct sway_view *view);

const char *view_get_instance(struct sway_view *view);

uint32_t view_get_x11_window_id(struct sway_view *view);

const char *view_get_window_role(struct sway_view *view);

uint32_t view_get_window_type(struct sway_view *view);

const char *view_get_shell(struct sway_view *view);

uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
	int height);

/**
 * Center the view in its workspace and build the swayc decorations around it.
 */
void view_init_floating(struct sway_view *view);

/**
 * Configure the view's position and size based on the swayc's position and
 * size, taking borders into consideration.
 */
void view_autoconfigure(struct sway_view *view);

void view_set_activated(struct sway_view *view, bool activated);

void view_set_tiled(struct sway_view *view, bool tiled);

void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen);

void view_set_fullscreen(struct sway_view *view, bool fullscreen);

void view_close(struct sway_view *view);

void view_damage_from(struct sway_view *view);

void view_for_each_surface(struct sway_view *view,
	wlr_surface_iterator_func_t iterator, void *user_data);

// view implementation

void view_init(struct sway_view *view, enum sway_view_type type,
	const struct sway_view_impl *impl);

void view_free(struct sway_view *view);

void view_destroy(struct sway_view *view);

void view_map(struct sway_view *view, struct wlr_surface *wlr_surface);

void view_unmap(struct sway_view *view);

void view_update_position(struct sway_view *view, double lx, double ly);

void view_update_size(struct sway_view *view, int width, int height);

void view_child_init(struct sway_view_child *child,
	const struct sway_view_child_impl *impl, struct sway_view *view,
	struct wlr_surface *surface);

void view_child_destroy(struct sway_view_child *child);


struct sway_view *view_from_wlr_xdg_surface(
	struct wlr_xdg_surface *xdg_surface);
struct sway_view *view_from_wlr_xdg_surface_v6(
	struct wlr_xdg_surface_v6 *xdg_surface_v6);
struct sway_view *view_from_wlr_xwayland_surface(
	struct wlr_xwayland_surface *xsurface);

struct sway_view *view_from_wlr_surface(struct wlr_surface *surface);

/**
 * Re-read the view's title property and update any relevant title bars.
 * The force argument makes it recreate the title bars even if the title hasn't
 * changed.
 */
void view_update_title(struct sway_view *view, bool force);

/**
 * Run any criteria that match the view and haven't been run on this view
 * before.
 */
void view_execute_criteria(struct sway_view *view);

/**
 * Find any view that has the given mark and remove the mark from the view.
 * Returns true if it matched a view.
 */
bool view_find_and_unmark(char *mark);

/**
 * Remove all marks from the view.
 */
void view_clear_marks(struct sway_view *view);

bool view_has_mark(struct sway_view *view, char *mark);

void view_update_marks_textures(struct sway_view *view);

/**
 * Returns true if there's a possibility the view may be rendered on screen.
 * Intended for damage tracking.
 */
bool view_is_visible(struct sway_view *view);

#endif