compositor.h 53 KB
Newer Older
1 2
/*
 * Copyright © 2008-2011 Kristian Høgsberg
Pekka Paalanen's avatar
Pekka Paalanen committed
3
 * Copyright © 2012 Collabora, Ltd.
4
 *
5 6 7 8 9 10 11
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
12
 *
13 14 15 16 17 18 19 20 21 22 23 24
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
25 26 27 28 29
 */

#ifndef _WAYLAND_SYSTEM_COMPOSITOR_H_
#define _WAYLAND_SYSTEM_COMPOSITOR_H_

Giulio Camuffo's avatar
Giulio Camuffo committed
30 31 32 33
#ifdef  __cplusplus
extern "C" {
#endif

34
#include <stdbool.h>
35
#include <stdint.h>
36
#include <time.h>
37
#include <pixman.h>
38
#include <xkbcommon/xkbcommon.h>
39 40

#define WL_HIDE_DEPRECATED
41 42
#include <wayland-server.h>

43 44
#include "matrix.h"
#include "config-parser.h"
45
#include "zalloc.h"
46
#include "timeline-object.h"
47

Quentin Glidic's avatar
Quentin Glidic committed
48 49 50 51 52 53 54 55 56 57 58 59 60
struct weston_geometry {
	int32_t x, y;
	int32_t width, height;
};

struct weston_position {
	int32_t x, y;
};

struct weston_size {
	int32_t width, height;
};

61 62
struct weston_transform {
	struct weston_matrix matrix;
63
	struct wl_list link;
64 65 66
};

struct weston_surface;
67
struct weston_buffer;
68
struct shell_surface;
69
struct weston_seat;
70
struct weston_output;
71
struct input_method;
72
struct weston_pointer;
73
struct linux_dmabuf_buffer;
74
struct weston_recorder;
75
struct weston_pointer_constraint;
76

77 78 79 80
enum weston_keyboard_modifier {
	MODIFIER_CTRL = (1 << 0),
	MODIFIER_ALT = (1 << 1),
	MODIFIER_SUPER = (1 << 2),
81
	MODIFIER_SHIFT = (1 << 3),
82 83
};

84 85 86 87 88
enum weston_keyboard_locks {
	WESTON_NUM_LOCK = (1 << 0),
	WESTON_CAPS_LOCK = (1 << 1),
};

Daniel Stone's avatar
Daniel Stone committed
89 90 91 92 93 94
enum weston_led {
	LED_NUM_LOCK = (1 << 0),
	LED_CAPS_LOCK = (1 << 1),
	LED_SCROLL_LOCK = (1 << 2),
};

95 96 97 98 99 100 101
struct weston_mode {
	uint32_t flags;
	int32_t width, height;
	uint32_t refresh;
	struct wl_list link;
};

102 103 104 105 106 107 108
struct weston_animation {
	void (*frame)(struct weston_animation *animation,
		      struct weston_output *output, uint32_t msecs);
	int frame_counter;
	struct wl_list link;
};

109 110 111 112 113 114
enum {
	WESTON_SPRING_OVERSHOOT,
	WESTON_SPRING_CLAMP,
	WESTON_SPRING_BOUNCE
};

115 116 117 118 119 120
struct weston_spring {
	double k;
	double friction;
	double current;
	double target;
	double previous;
121
	double min, max;
122
	uint32_t timestamp;
123
	uint32_t clip;
124 125
};

Scott Moreau's avatar
Scott Moreau committed
126
struct weston_output_zoom {
127
	bool active;
Scott Moreau's avatar
Scott Moreau committed
128 129
	float increment;
	float level;
130
	float max_level;
Scott Moreau's avatar
Scott Moreau committed
131
	float trans_x, trans_y;
132 133 134
	struct {
		double x, y;
	} current;
135
	struct weston_seat *seat;
136 137
	struct weston_animation animation_z;
	struct weston_spring spring_z;
138
	struct wl_listener motion_listener;
Scott Moreau's avatar
Scott Moreau committed
139 140
};

141 142 143 144 145 146 147 148
/* bit compatible with drm definitions. */
enum dpms_enum {
	WESTON_DPMS_ON,
	WESTON_DPMS_STANDBY,
	WESTON_DPMS_SUSPEND,
	WESTON_DPMS_OFF
};

149
struct weston_output {
Casey Dahlin's avatar
Casey Dahlin committed
150
	uint32_t id;
151
	char *name;
Casey Dahlin's avatar
Casey Dahlin committed
152

153 154
	void *renderer_state;

155
	struct wl_list link;
Casey Dahlin's avatar
Casey Dahlin committed
156
	struct wl_list resource_list;
157
	struct wl_global *global;
158
	struct weston_compositor *compositor;
159 160

	/** From global to output buffer coordinates. */
161
	struct weston_matrix matrix;
162 163
	/** From output buffer to global coordinates. */
	struct weston_matrix inverse_matrix;
164

165
	struct wl_list animation_list;
166 167
	int32_t x, y, width, height;
	int32_t mm_width, mm_height;
168 169

	/** Output area in global coordinates, simple rect */
170
	pixman_region32_t region;
171

172
	pixman_region32_t previous_damage;
Daniel Stone's avatar
Daniel Stone committed
173 174 175 176

	/** True if damage has occurred since the last repaint for this output;
	 *  if set, a repaint will eventually occur. */
	bool repaint_needed;
177 178 179 180 181 182 183 184 185

	/** State of the repaint loop */
	enum {
		REPAINT_NOT_SCHEDULED = 0, /**< idle; no repaint will occur */
		REPAINT_BEGIN_FROM_IDLE, /**< start_repaint_loop scheduled */
		REPAINT_SCHEDULED, /**< repaint is scheduled to occur */
		REPAINT_AWAITING_COMPLETION, /**< last repaint not yet finished */
	} repaint_status;

186 187 188 189
	/** If repaint_status is REPAINT_SCHEDULED, contains the time the
	 *  next repaint should be run */
	struct timespec next_repaint;

Scott Moreau's avatar
Scott Moreau committed
190 191
	struct weston_output_zoom zoom;
	int dirty;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
192
	struct wl_signal frame_signal;
193
	struct wl_signal destroy_signal;
194
	int move_x, move_y;
195
	uint32_t frame_time; /* presentation timestamp in milliseconds */
196
	uint64_t msc;        /* media stream counter */
197
	int disable_planes;
198
	int destroying;
199
	struct wl_list feedback_list;
200

201
	char *make, *model, *serial_number;
202
	uint32_t subpixel;
203
	uint32_t transform;
David Fort's avatar
David Fort committed
204
	int32_t native_scale;
205
	int32_t current_scale;
David Fort's avatar
David Fort committed
206
	int32_t original_scale;
207

David Fort's avatar
David Fort committed
208
	struct weston_mode *native_mode;
209 210
	struct weston_mode *current_mode;
	struct weston_mode *original_mode;
211 212
	struct wl_list mode_list;

213
	void (*start_repaint_loop)(struct weston_output *output);
214
	int (*repaint)(struct weston_output *output,
215
			pixman_region32_t *damage);
216
	void (*destroy)(struct weston_output *output);
217
	void (*assign_planes)(struct weston_output *output);
218
	int (*switch_mode)(struct weston_output *output, struct weston_mode *mode);
219

220
	/* backlight values are on 0-255 range, where higher is brighter */
221
	int32_t backlight_current;
222 223
	void (*set_backlight)(struct weston_output *output, uint32_t value);
	void (*set_dpms)(struct weston_output *output, enum dpms_enum level);
224

225
	int connection_internal;
226 227 228 229 230 231
	uint16_t gamma_size;
	void (*set_gamma)(struct weston_output *output,
			  uint16_t size,
			  uint16_t *r,
			  uint16_t *g,
			  uint16_t *b);
232 233

	struct weston_timeline_object timeline;
234 235 236 237 238 239

	bool enabled;
	int scale;

	int (*enable)(struct weston_output *output);
	int (*disable)(struct weston_output *output);
240 241
};

242 243 244
enum weston_pointer_motion_mask {
	WESTON_POINTER_MOTION_ABS = 1 << 0,
	WESTON_POINTER_MOTION_REL = 1 << 1,
245
	WESTON_POINTER_MOTION_REL_UNACCEL = 1 << 2,
246 247 248 249
};

struct weston_pointer_motion_event {
	uint32_t mask;
250
	uint64_t time_usec;
251 252 253 254
	double x;
	double y;
	double dx;
	double dy;
255 256
	double dx_unaccel;
	double dy_unaccel;
257 258
};

259 260
struct weston_pointer_axis_event {
	uint32_t axis;
261
	double value;
262 263
	bool has_discrete;
	int32_t discrete;
264 265
};

266 267
struct weston_pointer_grab;
struct weston_pointer_grab_interface {
268
	void (*focus)(struct weston_pointer_grab *grab);
269
	void (*motion)(struct weston_pointer_grab *grab, uint32_t time,
270
		       struct weston_pointer_motion_event *event);
271
	void (*button)(struct weston_pointer_grab *grab,
272
		       uint32_t time, uint32_t button, uint32_t state);
273
	void (*axis)(struct weston_pointer_grab *grab,
274 275
		     uint32_t time,
		     struct weston_pointer_axis_event *event);
276 277
	void (*axis_source)(struct weston_pointer_grab *grab, uint32_t source);
	void (*frame)(struct weston_pointer_grab *grab);
278
	void (*cancel)(struct weston_pointer_grab *grab);
279 280
};

281 282 283
struct weston_pointer_grab {
	const struct weston_pointer_grab_interface *interface;
	struct weston_pointer *pointer;
284 285
};

286 287 288
struct weston_keyboard_grab;
struct weston_keyboard_grab_interface {
	void (*key)(struct weston_keyboard_grab *grab, uint32_t time,
289
		    uint32_t key, uint32_t state);
290
	void (*modifiers)(struct weston_keyboard_grab *grab, uint32_t serial,
291 292
			  uint32_t mods_depressed, uint32_t mods_latched,
			  uint32_t mods_locked, uint32_t group);
293
	void (*cancel)(struct weston_keyboard_grab *grab);
294 295
};

296 297 298
struct weston_keyboard_grab {
	const struct weston_keyboard_grab_interface *interface;
	struct weston_keyboard *keyboard;
299 300
};

301 302 303
struct weston_touch_grab;
struct weston_touch_grab_interface {
	void (*down)(struct weston_touch_grab *grab,
304 305 306 307
			uint32_t time,
			int touch_id,
			wl_fixed_t sx,
			wl_fixed_t sy);
308
	void (*up)(struct weston_touch_grab *grab,
309 310
			uint32_t time,
			int touch_id);
311
	void (*motion)(struct weston_touch_grab *grab,
312 313 314 315
			uint32_t time,
			int touch_id,
			wl_fixed_t sx,
			wl_fixed_t sy);
316
	void (*frame)(struct weston_touch_grab *grab);
317
	void (*cancel)(struct weston_touch_grab *grab);
318 319
};

320 321 322
struct weston_touch_grab {
	const struct weston_touch_grab_interface *interface;
	struct weston_touch *touch;
323 324
};

325
struct weston_data_offer {
326
	struct wl_resource *resource;
327
	struct weston_data_source *source;
328
	struct wl_listener source_destroy_listener;
329 330 331
	uint32_t dnd_actions;
	enum wl_data_device_manager_dnd_action preferred_dnd_action;
	bool in_ask;
332 333
};

334
struct weston_data_source {
335 336
	struct wl_resource *resource;
	struct wl_signal destroy_signal;
337
	struct wl_array mime_types;
338 339 340
	struct weston_data_offer *offer;
	struct weston_seat *seat;
	bool accepted;
341 342 343
	bool actions_set;
	uint32_t dnd_actions;
	enum wl_data_device_manager_dnd_action current_dnd_action;
344
	enum wl_data_device_manager_dnd_action compositor_action;
345

346
	void (*accept)(struct weston_data_source *source,
347
		       uint32_t serial, const char *mime_type);
348
	void (*send)(struct weston_data_source *source,
349
		     const char *mime_type, int32_t fd);
350
	void (*cancel)(struct weston_data_source *source);
351 352
};

353 354 355 356
struct weston_pointer_client {
	struct wl_list link;
	struct wl_client *client;
	struct wl_list pointer_resources;
357
	struct wl_list relative_pointer_resources;
358 359
};

360
struct weston_pointer {
361
	struct weston_seat *seat;
362

363 364
	struct wl_list pointer_clients;

365
	struct weston_view *focus;
366
	struct weston_pointer_client *focus_client;
367
	uint32_t focus_serial;
368 369
	struct wl_listener focus_view_listener;
	struct wl_listener focus_resource_listener;
370
	struct wl_signal focus_signal;
371
	struct wl_signal motion_signal;
372
	struct wl_signal destroy_signal;
373

374
	struct weston_view *sprite;
375 376 377
	struct wl_listener sprite_destroy_listener;
	int32_t hotspot_x, hotspot_y;

378 379
	struct weston_pointer_grab *grab;
	struct weston_pointer_grab default_grab;
380 381 382 383 384 385
	wl_fixed_t grab_x, grab_y;
	uint32_t grab_button;
	uint32_t grab_serial;
	uint32_t grab_time;

	wl_fixed_t x, y;
386
	wl_fixed_t sx, sy;
387
	uint32_t button_count;
388 389

	struct wl_listener output_destroy_listener;
390 391 392
};


393
struct weston_touch {
394
	struct weston_seat *seat;
395 396

	struct wl_list resource_list;
397
	struct wl_list focus_resource_list;
398
	struct weston_view *focus;
399 400
	struct wl_listener focus_view_listener;
	struct wl_listener focus_resource_listener;
401 402 403
	uint32_t focus_serial;
	struct wl_signal focus_signal;

404 405
	uint32_t num_tp;

406 407
	struct weston_touch_grab *grab;
	struct weston_touch_grab default_grab;
408
	int grab_touch_id;
409 410 411 412 413
	wl_fixed_t grab_x, grab_y;
	uint32_t grab_serial;
	uint32_t grab_time;
};

414 415 416 417 418
void
weston_pointer_motion_to_abs(struct weston_pointer *pointer,
			     struct weston_pointer_motion_event *event,
			     wl_fixed_t *x, wl_fixed_t *y);

419
struct weston_pointer *
420
weston_pointer_create(struct weston_seat *seat);
421
void
422
weston_pointer_destroy(struct weston_pointer *pointer);
423
void
424 425 426 427 428 429 430 431
weston_pointer_send_motion(struct weston_pointer *pointer, uint32_t time,
			   struct weston_pointer_motion_event *event);
bool
weston_pointer_has_focus_resource(struct weston_pointer *pointer);
void
weston_pointer_send_button(struct weston_pointer *pointer,
			   uint32_t time, uint32_t button, uint32_t state_w);
void
432
weston_pointer_send_axis(struct weston_pointer *pointer,
433 434
			 uint32_t time,
			 struct weston_pointer_axis_event *event);
435 436 437 438 439 440
void
weston_pointer_send_axis_source(struct weston_pointer *pointer,
				uint32_t source);
void
weston_pointer_send_frame(struct weston_pointer *pointer);

441
void
442
weston_pointer_set_focus(struct weston_pointer *pointer,
443
			 struct weston_view *view,
444
			 wl_fixed_t sx, wl_fixed_t sy);
445
void
446 447
weston_pointer_clear_focus(struct weston_pointer *pointer);
void
448 449
weston_pointer_start_grab(struct weston_pointer *pointer,
			  struct weston_pointer_grab *grab);
450
void
451
weston_pointer_end_grab(struct weston_pointer *pointer);
452 453 454
void
weston_pointer_clamp(struct weston_pointer *pointer,
			    wl_fixed_t *fx, wl_fixed_t *fy);
455 456
void
weston_pointer_move(struct weston_pointer *pointer,
457
		    struct weston_pointer_motion_event *event);
458 459 460
void
weston_pointer_set_default_grab(struct weston_pointer *pointer,
		const struct weston_pointer_grab_interface *interface);
461

462 463 464
void
weston_pointer_constraint_destroy(struct weston_pointer_constraint *constraint);

465 466
struct weston_keyboard *
weston_keyboard_create(void);
467
void
468
weston_keyboard_destroy(struct weston_keyboard *keyboard);
469
void
470
weston_keyboard_set_focus(struct weston_keyboard *keyboard,
471
			  struct weston_surface *surface);
472
void
473 474
weston_keyboard_start_grab(struct weston_keyboard *device,
			   struct weston_keyboard_grab *grab);
475
void
476
weston_keyboard_end_grab(struct weston_keyboard *keyboard);
477 478 479 480 481 482 483
int
/*
 * 'mask' and 'value' should be a bitwise mask of one or more
 * valued of the weston_keyboard_locks enum.
 */
weston_keyboard_set_locks(struct weston_keyboard *keyboard,
			  uint32_t mask, uint32_t value);
484

485 486 487 488 489 490 491 492 493 494 495 496
bool
weston_keyboard_has_focus_resource(struct weston_keyboard *keyboard);
void
weston_keyboard_send_key(struct weston_keyboard *keyboard,
			 uint32_t time, uint32_t key,
			 enum wl_keyboard_key_state state);
void
weston_keyboard_send_modifiers(struct weston_keyboard *keyboard,
			       uint32_t serial, uint32_t mods_depressed,
			       uint32_t mods_latched,
			       uint32_t mods_locked, uint32_t group);

497 498
struct weston_touch *
weston_touch_create(void);
499
void
500
weston_touch_destroy(struct weston_touch *touch);
501
void
502
weston_touch_set_focus(struct weston_touch *touch,
503
		       struct weston_view *view);
Michael Fu's avatar
Michael Fu committed
504
void
505 506
weston_touch_start_grab(struct weston_touch *device,
			struct weston_touch_grab *grab);
507
void
508
weston_touch_end_grab(struct weston_touch *touch);
509

510 511 512 513 514 515 516 517 518 519 520 521 522
bool
weston_touch_has_focus_resource(struct weston_touch *touch);
void
weston_touch_send_down(struct weston_touch *touch, uint32_t time,
		       int touch_id, wl_fixed_t x, wl_fixed_t y);
void
weston_touch_send_up(struct weston_touch *touch, uint32_t time, int touch_id);
void
weston_touch_send_motion(struct weston_touch *touch, uint32_t time,
			 int touch_id, wl_fixed_t x, wl_fixed_t y);
void
weston_touch_send_frame(struct weston_touch *touch);

523
void
524
wl_data_device_set_keyboard_focus(struct weston_seat *seat);
525 526 527 528 529 530

int
wl_data_device_manager_init(struct wl_display *display);


void
531
weston_seat_set_selection(struct weston_seat *seat,
532
			  struct weston_data_source *source, uint32_t serial);
533 534 535
void
weston_seat_send_selection(struct weston_seat *seat, struct wl_client *client);

536
int
537
weston_pointer_start_drag(struct weston_pointer *pointer,
538 539 540
		       struct weston_data_source *source,
		       struct weston_surface *icon,
		       struct wl_client *client);
541 542 543 544 545
int
weston_touch_start_drag(struct weston_touch *touch,
			struct weston_data_source *source,
			struct weston_surface *icon,
			struct wl_client *client);
546

Daniel Stone's avatar
Daniel Stone committed
547 548
struct weston_xkb_info {
	struct xkb_keymap *keymap;
549 550 551
	int keymap_fd;
	size_t keymap_size;
	char *keymap_area;
552
	int32_t ref_count;
553 554
	xkb_mod_index_t shift_mod;
	xkb_mod_index_t caps_mod;
Daniel Stone's avatar
Daniel Stone committed
555 556
	xkb_mod_index_t ctrl_mod;
	xkb_mod_index_t alt_mod;
557 558
	xkb_mod_index_t mod2_mod;
	xkb_mod_index_t mod3_mod;
Daniel Stone's avatar
Daniel Stone committed
559
	xkb_mod_index_t super_mod;
560
	xkb_mod_index_t mod5_mod;
Daniel Stone's avatar
Daniel Stone committed
561 562 563 564 565
	xkb_led_index_t num_led;
	xkb_led_index_t caps_led;
	xkb_led_index_t scroll_led;
};

566
struct weston_keyboard {
567
	struct weston_seat *seat;
568 569

	struct wl_list resource_list;
570
	struct wl_list focus_resource_list;
571
	struct weston_surface *focus;
572
	struct wl_listener focus_resource_listener;
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
	uint32_t focus_serial;
	struct wl_signal focus_signal;

	struct weston_keyboard_grab *grab;
	struct weston_keyboard_grab default_grab;
	uint32_t grab_key;
	uint32_t grab_serial;
	uint32_t grab_time;

	struct wl_array keys;

	struct {
		uint32_t mods_depressed;
		uint32_t mods_latched;
		uint32_t mods_locked;
		uint32_t group;
	} modifiers;
590

591
	struct weston_keyboard_grab input_method_grab;
592
	struct wl_resource *input_method_resource;
593 594 595 596 597 598 599

	struct weston_xkb_info *xkb_info;
	struct {
		struct xkb_state *state;
		enum weston_led leds;
	} xkb_state;
	struct xkb_keymap *pending_keymap;
600 601
};

602
struct weston_seat {
603 604
	struct wl_list base_resource_list;

605
	struct wl_global *global;
606 607 608
	struct weston_pointer *pointer_state;
	struct weston_keyboard *keyboard_state;
	struct weston_touch *touch_state;
609 610 611
	int pointer_device_count;
	int keyboard_device_count;
	int touch_device_count;
612

613 614
	struct weston_output *output; /* constraint */

Giulio Camuffo's avatar
Giulio Camuffo committed
615
	struct wl_signal destroy_signal;
616
	struct wl_signal updated_caps_signal;
617

618 619
	struct weston_compositor *compositor;
	struct wl_list link;
620
	enum weston_keyboard_modifier modifier_state;
621
	struct weston_surface *saved_kbd_focus;
622
	struct wl_listener saved_kbd_focus_listener;
623
	struct wl_list drag_resource_list;
624

625
	uint32_t selection_serial;
626
	struct weston_data_source *selection_data_source;
627 628 629
	struct wl_listener selection_data_source_listener;
	struct wl_signal selection_signal;

Daniel Stone's avatar
Daniel Stone committed
630 631
	void (*led_update)(struct weston_seat *ws, enum weston_led leds);

632
	struct input_method *input_method;
633
	char *seat_name;
634 635 636
};

enum {
637
	WESTON_COMPOSITOR_ACTIVE,	/* normal rendering and events */
638
	WESTON_COMPOSITOR_IDLE,		/* shell->unlock called on activity */
639
	WESTON_COMPOSITOR_OFFSCREEN,	/* no rendering, no frame events */
640 641
	WESTON_COMPOSITOR_SLEEPING	/* same as offscreen, but also set dpms
                                         * to off */
642 643
};

644 645 646 647 648
struct weston_layer_entry {
	struct wl_list link;
	struct weston_layer *layer;
};

649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
/**
 * Higher value means higher in the stack.
 *
 * These values are based on well-known concepts in a classic desktop
 * environment. Third-party modules based on libweston are encouraged to use
 * them to integrate better with other projects.
 *
 * A fully integrated environment can use any value, based on these or not,
 * at their discretion.
 */
enum weston_layer_position {
	/*
	 * Special value to make the layer invisible and still rendered.
	 * This is used by compositors wanting e.g. minimized surfaces to still
	 * receive frame callbacks.
	 */
	WESTON_LAYER_POSITION_HIDDEN     = 0x00000000,

	/*
	 * There should always be a background layer with a surface covering
	 * the visible area.
	 *
	 * If the compositor handles the background itself, it should use
	 * BACKGROUND.
	 *
	 * If the compositor supports runtime-loadable modules to set the
	 * background, it should put a solid color surface at (BACKGROUND - 1)
	 * and modules must use BACKGROUND.
	 */
	WESTON_LAYER_POSITION_BACKGROUND = 0x00000002,

	/* For "desktop widgets" and applications like conky. */
	WESTON_LAYER_POSITION_BOTTOM_UI  = 0x30000000,

	/* For regular applications, only one layer should have this value
	 * to ensure proper stacking control. */
	WESTON_LAYER_POSITION_NORMAL     = 0x50000000,

	/* For desktop UI, like panels. */
	WESTON_LAYER_POSITION_UI         = 0x80000000,

	/* For fullscreen applications that should cover UI. */
	WESTON_LAYER_POSITION_FULLSCREEN = 0xb0000000,

	/* For special UI like on-screen keyboard that fullscreen applications
	 * will need. */
	WESTON_LAYER_POSITION_TOP_UI     = 0xe0000000,

	/* For the lock surface. */
	WESTON_LAYER_POSITION_LOCK       = 0xffff0000,

	/* Values reserved for libweston internal usage */
	WESTON_LAYER_POSITION_CURSOR     = 0xfffffffe,
	WESTON_LAYER_POSITION_FADE       = 0xffffffff,
};

705
struct weston_layer {
706 707 708
	struct weston_compositor *compositor;
	struct wl_list link; /* weston_compositor::layer_list */
	enum weston_layer_position position;
709
	pixman_box32_t mask;
710
	struct weston_layer_entry view_list;
711 712
};

713
struct weston_plane {
714
	struct weston_compositor *compositor;
715
	pixman_region32_t damage; /**< in global coords */
716
	pixman_region32_t clip;
717
	int32_t x, y;
718
	struct wl_list link;
719 720
};

721
struct weston_renderer {
722 723 724 725
	int (*read_pixels)(struct weston_output *output,
			       pixman_format_code_t format, void *pixels,
			       uint32_t x, uint32_t y,
			       uint32_t width, uint32_t height);
726 727 728
	void (*repaint_output)(struct weston_output *output,
			       pixman_region32_t *output_damage);
	void (*flush_damage)(struct weston_surface *surface);
729
	void (*attach)(struct weston_surface *es, struct weston_buffer *buffer);
730 731 732
	void (*surface_set_color)(struct weston_surface *surface,
			       float red, float green,
			       float blue, float alpha);
733
	void (*destroy)(struct weston_compositor *ec);
734 735 736 737 738 739 740 741 742 743 744


	/** See weston_surface_get_content_size() */
	void (*surface_get_content_size)(struct weston_surface *surface,
					 int *width, int *height);

	/** See weston_surface_copy_content() */
	int (*surface_copy_content)(struct weston_surface *surface,
				    void *target, size_t size,
				    int src_x, int src_y,
				    int width, int height);
745 746 747 748

	/** See weston_compositor_import_dmabuf() */
	bool (*import_dmabuf)(struct weston_compositor *ec,
			      struct linux_dmabuf_buffer *buffer);
749 750
};

751 752 753
enum weston_capability {
	/* backend/renderer supports arbitrary rotation */
	WESTON_CAP_ROTATION_ANY			= 0x0001,
754 755 756

	/* screencaptures need to be y-flipped */
	WESTON_CAP_CAPTURE_YFLIP		= 0x0002,
757

Bryce Harrington's avatar
Bryce Harrington committed
758
	/* backend/renderer has a separate cursor plane */
759 760 761 762
	WESTON_CAP_CURSOR_PLANE			= 0x0004,

	/* backend supports setting arbitrary resolutions */
	WESTON_CAP_ARBITRARY_MODES		= 0x0008,
763 764 765

	/* renderer supports weston_view_set_mask() clipping */
	WESTON_CAP_VIEW_CLIP_MASK		= 0x0010,
766 767
};

768 769 770 771 772 773
/* Configuration struct for a backend.
 *
 * This struct carries the configuration for a backend, and it's
 * passed to the backend's init entry point. The backend will
 * likely want to subclass this in order to handle backend specific
 * data.
774 775 776 777 778 779 780 781 782 783
 *
 * NOTE: Alternate designs were proposed (Feb 2016) for using opaque
 * structures[1] and for section+key/value getter/setters[2].  The rationale
 * for selecting the transparent structure design is based on several
 * assumptions[3] which may require re-evaluating the design choice if they
 * fail to hold.
 *
 * 1: https://lists.freedesktop.org/archives/wayland-devel/2016-February/026989.html
 * 2: https://lists.freedesktop.org/archives/wayland-devel/2016-February/026929.html
 * 3: https://lists.freedesktop.org/archives/wayland-devel/2016-February/027228.html
784 785
 */
struct weston_backend_config {
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801
   /** Major version for the backend-specific config struct
    *
    * This version must match exactly what the backend expects, otherwise
    * the struct is incompatible.
    */
   uint32_t struct_version;

   /** Minor version of the backend-specific config struct
    *
    * This must be set to sizeof(struct backend-specific config).
    * If the value here is smaller than what the backend expects, the
    * extra config members will assume their default values.
    *
    * A value greater than what the backend expects is incompatible.
    */
   size_t struct_size;
802 803
};

804
struct weston_backend {
805 806
	void (*destroy)(struct weston_compositor *compositor);
	void (*restore)(struct weston_compositor *compositor);
807 808
};

809 810 811
struct weston_desktop_xwayland;
struct weston_desktop_xwayland_interface;

812
struct weston_compositor {
813
	struct wl_signal destroy_signal;
814 815

	struct wl_display *wl_display;
816 817
	struct weston_desktop_xwayland *xwayland;
	const struct weston_desktop_xwayland_interface *xwayland_interface;
818

819
	/* surface signals */
820
	struct wl_signal create_surface_signal;
821
	struct wl_signal activate_signal;
822 823
	struct wl_signal transform_signal;

Tiago Vignatti's avatar
Tiago Vignatti committed
824
	struct wl_signal kill_signal;
825 826
	struct wl_signal idle_signal;
	struct wl_signal wake_signal;
827

828 829
	struct wl_signal show_input_panel_signal;
	struct wl_signal hide_input_panel_signal;
830
	struct wl_signal update_input_panel_signal;
831

832
	struct wl_signal seat_created_signal;
833
	struct wl_signal output_pending_signal;
834
	struct wl_signal output_created_signal;
835
	struct wl_signal output_destroyed_signal;
836
	struct wl_signal output_moved_signal;
837
	struct wl_signal output_resized_signal; /* callback argument: resized output */
838

839 840 841
	struct wl_signal session_signal;
	int session_active;

842 843 844
	struct weston_layer fade_layer;
	struct weston_layer cursor_layer;

845
	struct wl_list pending_output_list;
846
	struct wl_list output_list;
847
	struct wl_list seat_list;
848
	struct wl_list layer_list;	/* struct weston_layer::link */
849
	struct wl_list view_list;	/* struct weston_view::link */
850
	struct wl_list plane_list;
851
	struct wl_list key_binding_list;
Daniel Stone's avatar
Daniel Stone committed
852
	struct wl_list modifier_binding_list;
853
	struct wl_list button_binding_list;
854
	struct wl_list touch_binding_list;
855
	struct wl_list axis_binding_list;
856
	struct wl_list debug_binding_list;
857 858 859 860

	uint32_t state;
	struct wl_event_source *idle_source;
	uint32_t idle_inhibit;
861
	int idle_time;			/* timeout, s */
862
	struct wl_event_source *repaint_timer;
863

864 865
	const struct weston_pointer_grab_interface *default_pointer_grab;

866
	/* Repaint state. */
867
	struct weston_plane primary_plane;
868
	uint32_t capabilities; /* combination of enum weston_capability */
869

870 871
	struct weston_renderer *renderer;

872
	pixman_format_code_t read_format;
873

874
	struct weston_backend *backend;
875

876
	struct weston_launcher *launcher;
Casey Dahlin's avatar
Casey Dahlin committed
877

878 879
	struct wl_list plugin_api_list; /* struct weston_plugin_api::link */

Casey Dahlin's avatar
Casey Dahlin committed
880
	uint32_t output_id_pool;
881

882 883
	struct xkb_rule_names xkb_names;
	struct xkb_context *xkb_context;
884
	struct weston_xkb_info *xkb_info;
885 886 887

	/* Raw keyboard processing (no libxkbcommon initialization or handling) */
	int use_xkbcommon;
888 889 890

	int32_t kb_repeat_rate;
	int32_t kb_repeat_delay;
891

892 893
	bool vt_switching;

894
	clockid_t presentation_clock;