compositor.h 60.3 KB
Newer Older
1 2
/*
 * Copyright © 2008-2011 Kristian Høgsberg
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

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
struct weston_animation {
	void (*frame)(struct weston_animation *animation,
104 105
		      struct weston_output *output,
		      const struct timespec *time);
106 107 108 109
	int frame_counter;
	struct wl_list link;
};

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

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

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

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

150 151 152 153 154 155
/** Represents a monitor
 *
 * This object represents a monitor (hardware backends like DRM) or a window
 * (windowed nested backends).
 */
struct weston_head {
156 157
	struct weston_compositor *compositor;	/**< owning compositor */
	struct wl_list compositor_link;	/**< in weston_compositor::head_list */
158
	struct wl_signal destroy_signal;	/**< destroy callbacks */
159

160
	struct weston_output *output;	/**< the output driving this head */
161
	struct wl_list output_link;	/**< in weston_output::head_list */
162

163 164 165
	struct wl_list resource_list;	/**< wl_output protocol objects */
	struct wl_global *global;	/**< wl_output global */

166 167 168 169 170 171 172
	int32_t mm_width;		/**< physical image width in mm */
	int32_t mm_height;		/**< physical image height in mm */
	char *make;			/**< monitor manufacturer (PNP ID) */
	char *model;			/**< monitor model */
	char *serial_number;		/**< monitor serial */
	uint32_t subpixel;		/**< enum wl_output_subpixel */
	bool connection_internal;	/**< embedded monitor (e.g. laptop) */
173
	bool device_changed;		/**< monitor information has changed */
174 175

	char *name;			/**< head name, e.g. connector name */
176
	bool connected;			/**< is physically connected */
177 178
};

179
struct weston_output {
180
	uint32_t id;
181
	char *name;
182

183 184 185
	/** Matches the lifetime from the user perspective */
	struct wl_signal user_destroy_signal;

186 187
	void *renderer_state;

188 189
	struct wl_list link;
	struct weston_compositor *compositor;
190 191

	/** From global to output buffer coordinates. */
192
	struct weston_matrix matrix;
193 194
	/** From output buffer to global coordinates. */
	struct weston_matrix inverse_matrix;
195

196
	struct wl_list animation_list;
197
	int32_t x, y, width, height;
198 199

	/** Output area in global coordinates, simple rect */
200
	pixman_region32_t region;
201

202
	pixman_region32_t previous_damage;
203 204 205 206

	/** True if damage has occurred since the last repaint for this output;
	 *  if set, a repaint will eventually occur. */
	bool repaint_needed;
207 208 209 210 211 212 213 214 215

	/** 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;

216 217 218 219
	/** If repaint_status is REPAINT_SCHEDULED, contains the time the
	 *  next repaint should be run */
	struct timespec next_repaint;

220 221 222
	/** For cancelling the idle_repaint callback on output destruction. */
	struct wl_event_source *idle_repaint_source;

Scott Moreau's avatar
Scott Moreau committed
223 224
	struct weston_output_zoom zoom;
	int dirty;
225
	struct wl_signal frame_signal;
226
	struct wl_signal destroy_signal;	/**< sent when disabled */
227
	int move_x, move_y;
228
	struct timespec frame_time; /* presentation timestamp */
229
	uint64_t msc;        /* media stream counter */
230
	int disable_planes;
231
	int destroying;
232
	struct wl_list feedback_list;
233

234
	uint32_t transform;
235
	int32_t native_scale;
236
	int32_t current_scale;
237
	int32_t original_scale;
238

239
	struct weston_mode *native_mode;
240 241
	struct weston_mode *current_mode;
	struct weston_mode *original_mode;
242 243
	struct wl_list mode_list;

244
	struct wl_list head_list; /**< List of driven weston_heads */
245

246
	void (*start_repaint_loop)(struct weston_output *output);
247
	int (*repaint)(struct weston_output *output,
248 249
			pixman_region32_t *damage,
			void *repaint_data);
250
	void (*destroy)(struct weston_output *output);
251
	void (*assign_planes)(struct weston_output *output, void *repaint_data);
252
	int (*switch_mode)(struct weston_output *output, struct weston_mode *mode);
253

254
	/* backlight values are on 0-255 range, where higher is brighter */
255
	int32_t backlight_current;
256 257
	void (*set_backlight)(struct weston_output *output, uint32_t value);
	void (*set_dpms)(struct weston_output *output, enum dpms_enum level);
258 259 260 261 262 263 264

	uint16_t gamma_size;
	void (*set_gamma)(struct weston_output *output,
			  uint16_t size,
			  uint16_t *r,
			  uint16_t *g,
			  uint16_t *b);
265 266

	struct weston_timeline_object timeline;
267

268
	bool enabled; /**< is in the output_list, not pending list */
269 270 271 272
	int scale;

	int (*enable)(struct weston_output *output);
	int (*disable)(struct weston_output *output);
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

	/** Attach a head in the backend
	 *
	 * @param output The output to attach to.
	 * @param head The head to attach.
	 * @return 0 on success, -1 on failure.
	 *
	 * Do anything necessary to account for a new head being attached to
	 * the output, and check any conditions possible. On failure, both
	 * the head and the output must be left as before the call.
	 *
	 * Libweston core will add the head to the head_list after a successful
	 * call.
	 */
	int (*attach_head)(struct weston_output *output,
			   struct weston_head *head);

	/** Detach a head in the backend
	 *
	 * @param output The output to detach from.
	 * @param head The head to detach.
	 *
	 * Do any clean-up necessary to detach this head from the output.
	 * The head has already been removed from the output's head_list.
	 */
	void (*detach_head)(struct weston_output *output,
			    struct weston_head *head);
300 301
};

302 303 304
enum weston_pointer_motion_mask {
	WESTON_POINTER_MOTION_ABS = 1 << 0,
	WESTON_POINTER_MOTION_REL = 1 << 1,
305
	WESTON_POINTER_MOTION_REL_UNACCEL = 1 << 2,
306 307 308 309
};

struct weston_pointer_motion_event {
	uint32_t mask;
310
	struct timespec time;
311 312 313 314
	double x;
	double y;
	double dx;
	double dy;
315 316
	double dx_unaccel;
	double dy_unaccel;
317 318
};

319 320
struct weston_pointer_axis_event {
	uint32_t axis;
321
	double value;
322 323
	bool has_discrete;
	int32_t discrete;
324 325
};

326 327
struct weston_pointer_grab;
struct weston_pointer_grab_interface {
328
	void (*focus)(struct weston_pointer_grab *grab);
329 330
	void (*motion)(struct weston_pointer_grab *grab,
		       const struct timespec *time,
331
		       struct weston_pointer_motion_event *event);
332
	void (*button)(struct weston_pointer_grab *grab,
333 334
		       const struct timespec *time,
		       uint32_t button, uint32_t state);
335
	void (*axis)(struct weston_pointer_grab *grab,
336
		     const struct timespec *time,
337
		     struct weston_pointer_axis_event *event);
338 339
	void (*axis_source)(struct weston_pointer_grab *grab, uint32_t source);
	void (*frame)(struct weston_pointer_grab *grab);
340
	void (*cancel)(struct weston_pointer_grab *grab);
341 342
};

343 344 345
struct weston_pointer_grab {
	const struct weston_pointer_grab_interface *interface;
	struct weston_pointer *pointer;
346 347
};

348 349
struct weston_keyboard_grab;
struct weston_keyboard_grab_interface {
350 351
	void (*key)(struct weston_keyboard_grab *grab,
		    const struct timespec *time, uint32_t key, uint32_t state);
352
	void (*modifiers)(struct weston_keyboard_grab *grab, uint32_t serial,
353 354
			  uint32_t mods_depressed, uint32_t mods_latched,
			  uint32_t mods_locked, uint32_t group);
355
	void (*cancel)(struct weston_keyboard_grab *grab);
356 357
};

358 359 360
struct weston_keyboard_grab {
	const struct weston_keyboard_grab_interface *interface;
	struct weston_keyboard *keyboard;
361 362
};

363 364 365
struct weston_touch_grab;
struct weston_touch_grab_interface {
	void (*down)(struct weston_touch_grab *grab,
366
			const struct timespec *time,
367 368 369
			int touch_id,
			wl_fixed_t sx,
			wl_fixed_t sy);
370
	void (*up)(struct weston_touch_grab *grab,
371
			const struct timespec *time,
372
			int touch_id);
373
	void (*motion)(struct weston_touch_grab *grab,
374
			const struct timespec *time,
375 376 377
			int touch_id,
			wl_fixed_t sx,
			wl_fixed_t sy);
378
	void (*frame)(struct weston_touch_grab *grab);
379
	void (*cancel)(struct weston_touch_grab *grab);
380 381
};

382 383 384
struct weston_touch_grab {
	const struct weston_touch_grab_interface *interface;
	struct weston_touch *touch;
385 386
};

387
struct weston_data_offer {
388
	struct wl_resource *resource;
389
	struct weston_data_source *source;
390
	struct wl_listener source_destroy_listener;
391 392 393
	uint32_t dnd_actions;
	enum wl_data_device_manager_dnd_action preferred_dnd_action;
	bool in_ask;
394 395
};

396
struct weston_data_source {
397 398
	struct wl_resource *resource;
	struct wl_signal destroy_signal;
399
	struct wl_array mime_types;
400 401 402
	struct weston_data_offer *offer;
	struct weston_seat *seat;
	bool accepted;
403 404 405
	bool actions_set;
	uint32_t dnd_actions;
	enum wl_data_device_manager_dnd_action current_dnd_action;
406
	enum wl_data_device_manager_dnd_action compositor_action;
407

408
	void (*accept)(struct weston_data_source *source,
409
		       uint32_t serial, const char *mime_type);
410
	void (*send)(struct weston_data_source *source,
411
		     const char *mime_type, int32_t fd);
412
	void (*cancel)(struct weston_data_source *source);
413 414
};

415 416 417 418
struct weston_pointer_client {
	struct wl_list link;
	struct wl_client *client;
	struct wl_list pointer_resources;
419
	struct wl_list relative_pointer_resources;
420 421
};

422
struct weston_pointer {
423
	struct weston_seat *seat;
424

425 426
	struct wl_list pointer_clients;

427
	struct weston_view *focus;
428
	struct weston_pointer_client *focus_client;
429
	uint32_t focus_serial;
430 431
	struct wl_listener focus_view_listener;
	struct wl_listener focus_resource_listener;
432
	struct wl_signal focus_signal;
433
	struct wl_signal motion_signal;
434
	struct wl_signal destroy_signal;
435

436
	struct weston_view *sprite;
437 438 439
	struct wl_listener sprite_destroy_listener;
	int32_t hotspot_x, hotspot_y;

440 441
	struct weston_pointer_grab *grab;
	struct weston_pointer_grab default_grab;
442 443 444
	wl_fixed_t grab_x, grab_y;
	uint32_t grab_button;
	uint32_t grab_serial;
445
	struct timespec grab_time;
446 447

	wl_fixed_t x, y;
448
	wl_fixed_t sx, sy;
449
	uint32_t button_count;
450 451

	struct wl_listener output_destroy_listener;
452 453

	struct wl_list timestamps_list;
454 455 456
};


457
struct weston_touch {
458
	struct weston_seat *seat;
459 460

	struct wl_list resource_list;
461
	struct wl_list focus_resource_list;
462
	struct weston_view *focus;
463 464
	struct wl_listener focus_view_listener;
	struct wl_listener focus_resource_listener;
465 466 467
	uint32_t focus_serial;
	struct wl_signal focus_signal;

468 469
	uint32_t num_tp;

470 471
	struct weston_touch_grab *grab;
	struct weston_touch_grab default_grab;
472
	int grab_touch_id;
473 474
	wl_fixed_t grab_x, grab_y;
	uint32_t grab_serial;
475
	struct timespec grab_time;
476 477

	struct wl_list timestamps_list;
478 479
};

480 481 482 483 484
void
weston_pointer_motion_to_abs(struct weston_pointer *pointer,
			     struct weston_pointer_motion_event *event,
			     wl_fixed_t *x, wl_fixed_t *y);

485
struct weston_pointer *
486
weston_pointer_create(struct weston_seat *seat);
487
void
488
weston_pointer_destroy(struct weston_pointer *pointer);
489
void
490 491
weston_pointer_send_motion(struct weston_pointer *pointer,
			   const struct timespec *time,
492 493 494 495 496
			   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,
497 498
			   const struct timespec *time,
			   uint32_t button, uint32_t state_w);
499
void
500
weston_pointer_send_axis(struct weston_pointer *pointer,
501
			 const struct timespec *time,
502
			 struct weston_pointer_axis_event *event);
503 504 505 506 507 508
void
weston_pointer_send_axis_source(struct weston_pointer *pointer,
				uint32_t source);
void
weston_pointer_send_frame(struct weston_pointer *pointer);

509
void
510
weston_pointer_set_focus(struct weston_pointer *pointer,
511
			 struct weston_view *view,
512
			 wl_fixed_t sx, wl_fixed_t sy);
513
void
514 515
weston_pointer_clear_focus(struct weston_pointer *pointer);
void
516 517
weston_pointer_start_grab(struct weston_pointer *pointer,
			  struct weston_pointer_grab *grab);
518
void
519
weston_pointer_end_grab(struct weston_pointer *pointer);
520 521 522
void
weston_pointer_clamp(struct weston_pointer *pointer,
			    wl_fixed_t *fx, wl_fixed_t *fy);
523 524
void
weston_pointer_move(struct weston_pointer *pointer,
525
		    struct weston_pointer_motion_event *event);
526 527 528
void
weston_pointer_set_default_grab(struct weston_pointer *pointer,
		const struct weston_pointer_grab_interface *interface);
529

530 531 532
void
weston_pointer_constraint_destroy(struct weston_pointer_constraint *constraint);

533 534
struct weston_keyboard *
weston_keyboard_create(void);
535
void
536
weston_keyboard_destroy(struct weston_keyboard *keyboard);
537
void
538
weston_keyboard_set_focus(struct weston_keyboard *keyboard,
539
			  struct weston_surface *surface);
540
void
541 542
weston_keyboard_start_grab(struct weston_keyboard *device,
			   struct weston_keyboard_grab *grab);
543
void
544
weston_keyboard_end_grab(struct weston_keyboard *keyboard);
545 546 547 548 549 550 551
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);
552

553 554 555 556
bool
weston_keyboard_has_focus_resource(struct weston_keyboard *keyboard);
void
weston_keyboard_send_key(struct weston_keyboard *keyboard,
557
			 const struct timespec *time, uint32_t key,
558 559 560 561 562 563 564
			 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);

565 566
struct weston_touch *
weston_touch_create(void);
567
void
568
weston_touch_destroy(struct weston_touch *touch);
569
void
570
weston_touch_set_focus(struct weston_touch *touch,
571
		       struct weston_view *view);
Michael Fu's avatar
Michael Fu committed
572
void
573 574
weston_touch_start_grab(struct weston_touch *device,
			struct weston_touch_grab *grab);
575
void
576
weston_touch_end_grab(struct weston_touch *touch);
577

578 579 580
bool
weston_touch_has_focus_resource(struct weston_touch *touch);
void
581
weston_touch_send_down(struct weston_touch *touch, const struct timespec *time,
582 583
		       int touch_id, wl_fixed_t x, wl_fixed_t y);
void
584 585
weston_touch_send_up(struct weston_touch *touch, const struct timespec *time,
		     int touch_id);
586
void
587 588 589
weston_touch_send_motion(struct weston_touch *touch,
			 const struct timespec *time, int touch_id,
			 wl_fixed_t x, wl_fixed_t y);
590 591 592
void
weston_touch_send_frame(struct weston_touch *touch);

593
void
594
wl_data_device_set_keyboard_focus(struct weston_seat *seat);
595 596 597 598 599 600

int
wl_data_device_manager_init(struct wl_display *display);


void
601
weston_seat_set_selection(struct weston_seat *seat,
602
			  struct weston_data_source *source, uint32_t serial);
603 604 605
void
weston_seat_send_selection(struct weston_seat *seat, struct wl_client *client);

606
int
607
weston_pointer_start_drag(struct weston_pointer *pointer,
608 609 610
		       struct weston_data_source *source,
		       struct weston_surface *icon,
		       struct wl_client *client);
611 612 613 614 615
int
weston_touch_start_drag(struct weston_touch *touch,
			struct weston_data_source *source,
			struct weston_surface *icon,
			struct wl_client *client);
616

617 618
struct weston_xkb_info {
	struct xkb_keymap *keymap;
619 620 621
	int keymap_fd;
	size_t keymap_size;
	char *keymap_area;
622
	int32_t ref_count;
623 624
	xkb_mod_index_t shift_mod;
	xkb_mod_index_t caps_mod;
625 626
	xkb_mod_index_t ctrl_mod;
	xkb_mod_index_t alt_mod;
627 628
	xkb_mod_index_t mod2_mod;
	xkb_mod_index_t mod3_mod;
629
	xkb_mod_index_t super_mod;
630
	xkb_mod_index_t mod5_mod;
631 632 633 634 635
	xkb_led_index_t num_led;
	xkb_led_index_t caps_led;
	xkb_led_index_t scroll_led;
};

636
struct weston_keyboard {
637
	struct weston_seat *seat;
638 639

	struct wl_list resource_list;
640
	struct wl_list focus_resource_list;
641
	struct weston_surface *focus;
642
	struct wl_listener focus_resource_listener;
643 644 645 646 647 648 649
	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;
650
	struct timespec grab_time;
651 652 653 654 655 656 657 658 659

	struct wl_array keys;

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

661
	struct weston_keyboard_grab input_method_grab;
662
	struct wl_resource *input_method_resource;
663 664 665 666 667 668 669

	struct weston_xkb_info *xkb_info;
	struct {
		struct xkb_state *state;
		enum weston_led leds;
	} xkb_state;
	struct xkb_keymap *pending_keymap;
670 671

	struct wl_list timestamps_list;
672 673
};

674
struct weston_seat {
675 676
	struct wl_list base_resource_list;

677
	struct wl_global *global;
678 679 680
	struct weston_pointer *pointer_state;
	struct weston_keyboard *keyboard_state;
	struct weston_touch *touch_state;
681 682 683
	int pointer_device_count;
	int keyboard_device_count;
	int touch_device_count;
684

685 686
	struct weston_output *output; /* constraint */

687
	struct wl_signal destroy_signal;
688
	struct wl_signal updated_caps_signal;
689

690 691
	struct weston_compositor *compositor;
	struct wl_list link;
692
	enum weston_keyboard_modifier modifier_state;
693
	struct weston_surface *saved_kbd_focus;
694
	struct wl_listener saved_kbd_focus_listener;
695
	struct wl_list drag_resource_list;
696

697
	uint32_t selection_serial;
698
	struct weston_data_source *selection_data_source;
699 700 701
	struct wl_listener selection_data_source_listener;
	struct wl_signal selection_signal;

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

704
	struct input_method *input_method;
705
	char *seat_name;
706 707 708
};

enum {
709
	WESTON_COMPOSITOR_ACTIVE,	/* normal rendering and events */
710
	WESTON_COMPOSITOR_IDLE,		/* shell->unlock called on activity */
711
	WESTON_COMPOSITOR_OFFSCREEN,	/* no rendering, no frame events */
712 713
	WESTON_COMPOSITOR_SLEEPING	/* same as offscreen, but also set dpms
                                         * to off */
714 715
};

716 717 718 719 720
struct weston_layer_entry {
	struct wl_list link;
	struct weston_layer *layer;
};

721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
/**
 * 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,
};

777
struct weston_layer {
778 779 780
	struct weston_compositor *compositor;
	struct wl_list link; /* weston_compositor::layer_list */
	enum weston_layer_position position;
781
	pixman_box32_t mask;
782
	struct weston_layer_entry view_list;
783 784
};

785
struct weston_plane {
786
	struct weston_compositor *compositor;
787
	pixman_region32_t damage; /**< in global coords */
788
	pixman_region32_t clip;
789
	int32_t x, y;
790
	struct wl_list link;
791 792
};

793
struct weston_renderer {
794 795 796 797
	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);
798 799 800
	void (*repaint_output)(struct weston_output *output,
			       pixman_region32_t *output_damage);
	void (*flush_damage)(struct weston_surface *surface);
801
	void (*attach)(struct weston_surface *es, struct weston_buffer *buffer);
802 803 804
	void (*surface_set_color)(struct weston_surface *surface,
			       float red, float green,
			       float blue, float alpha);
805
	void (*destroy)(struct weston_compositor *ec);
806 807 808 809 810 811 812 813 814 815 816


	/** 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);
817 818 819 820

	/** See weston_compositor_import_dmabuf() */
	bool (*import_dmabuf)(struct weston_compositor *ec,
			      struct linux_dmabuf_buffer *buffer);
821

822 823
	/** On error sets num_formats to zero */
	void (*query_dmabuf_formats)(struct weston_compositor *ec,
824 825
				int **formats, int *num_formats);

826 827
	/** On error sets num_modifiers to zero */
	void (*query_dmabuf_modifiers)(struct weston_compositor *ec,
828 829
				int format, uint64_t **modifiers,
				int *num_modifiers);
830 831
};

832 833 834
enum weston_capability {
	/* backend/renderer supports arbitrary rotation */
	WESTON_CAP_ROTATION_ANY			= 0x0001,
835 836 837

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

Bryce Harrington's avatar
Bryce Harrington committed
839
	/* backend/renderer has a separate cursor plane */
840 841 842 843
	WESTON_CAP_CURSOR_PLANE			= 0x0004,

	/* backend supports setting arbitrary resolutions */
	WESTON_CAP_ARBITRARY_MODES		= 0x0008,
844 845 846

	/* renderer supports weston_view_set_mask() clipping */
	WESTON_CAP_VIEW_CLIP_MASK		= 0x0010,
847 848
};

849 850 851 852 853 854
/* 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.
855 856 857 858 859 860 861 862 863 864
 *
 * 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
865 866
 */
struct weston_backend_config {
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
   /** 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;
883 884
};

885
struct weston_backend {
886
	void (*destroy)(struct weston_compositor *compositor);
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919

	/** Begin a repaint sequence
	 *
	 * Provides the backend with explicit markers around repaint
	 * sequences, which may allow the backend to aggregate state
	 * application. This call will be bracketed by the repaint_flush (on
	 * success), or repaint_cancel (when any output in the grouping fails
	 * repaint).
	 *
	 * Returns an opaque pointer, which the backend may use as private
	 * data referring to the repaint cycle.
	 */
	void * (*repaint_begin)(struct weston_compositor *compositor);

	/** Cancel a repaint sequence
	 *
	 * Cancels a repaint sequence, when an error has occurred during
	 * one output's repaint; see repaint_begin.
	 *
	 * @param repaint_data Data returned by repaint_begin
	 */
	void (*repaint_cancel)(struct weston_compositor *compositor,
			       void *repaint_data);

	/** Conclude a repaint sequence
	 *
	 * Called on successful completion of a repaint sequence; see
	 * repaint_begin.
	 *
	 * @param repaint_data Data returned by repaint_begin
	 */
	void (*repaint_flush)(struct weston_compositor *compositor,
			      void *repaint_data);
920 921 922 923 924 925 926 927 928 929 930 931 932 933 934

	/** Allocate a new output
	 *
	 * @param compositor The compositor.
	 * @param name Name for the new output.
	 *
	 * Allocates a new output structure that embeds a weston_output,
	 * initializes it, and returns the pointer to the weston_output
	 * member.
	 *
	 * Must set weston_output members @c destroy, @c enable and @c disable.
	 */
	struct weston_output *
	(*create_output)(struct weston_compositor *compositor,
			 const char *name);
935 936
};

937 938 939
struct weston_desktop_xwayland;
struct weston_desktop_xwayland_interface;

940
struct weston_compositor {
941
	struct wl_signal destroy_signal;
942 943

	struct wl_display *wl_display;
944 945
	struct weston_desktop_xwayland *xwayland;
	const struct weston_desktop_xwayland_interface *xwayland_interface;
946

947
	/* surface signals */
948
	struct wl_signal create_surface_signal;
949
	struct wl_signal activate_signal;
950 951
	struct wl_signal transform_signal;

952
	struct wl_signal kill_signal;
953 954
	struct wl_signal idle_signal;
	struct wl_signal wake_signal;
955

956 957
	struct wl_signal show_input_panel_signal;
	struct wl_signal hide_input_panel_signal;
958
	struct wl_signal update_input_panel_signal;
959

960
	struct wl_signal seat_created_signal;
961
	struct wl_signal output_created_signal;
962
	struct wl_signal output_destroyed_signal;
963
	struct wl_signal output_moved_signal;
964
	struct wl_signal output_resized_signal; /* callback argument: resized output */
965

966 967 968 969 970
	/* Signal for output changes triggered by configuration from frontend
	 * or head state changes from backend.
	 */
	struct wl_signal output_heads_changed_signal; /* arg: weston_output */

971 972 973
	struct wl_signal session_signal;
	int session_active;

974 975 976
	struct weston_layer fade_layer;
	struct weston_layer cursor_layer;

977
	struct wl_list pending_output_list;
978
	struct wl_list output_list;
979
	struct wl_list head_list;	/* struct weston_head::compositor_link */
980
	struct wl_list seat_list;
981
	struct wl_list layer_list;	/* struct weston_layer::link */
982
	struct wl_list view_list;	/* struct weston_view::link */
983
	struct wl_list plane_list;
984
	struct wl_list key_binding_list;
Daniel Stone's avatar
Daniel Stone committed
985
	struct wl_list modifier_binding_list;
986
	struct wl_list button_binding_list;
987
	struct wl_list touch_binding_list;
988
	struct wl_list axis_binding_list;
989
	struct wl_list debug_binding_list;
990 991 992 993

	uint32_t state;
	struct wl_event_source *idle_source;
	uint32_t idle_inhibit;
994
	int idle_time;			/* timeout, s */
995
	struct wl_event_source *repaint_timer;
996

997 998
	const struct weston_pointer_grab_interface *default_pointer_grab;

999
	/* Repaint state. */
1000
	struct weston_plane primary_plane;
1001
	uint32_t capabilities; /* combination of enum weston_capability */
1002

1003 1004
	struct weston_renderer *renderer;

1005
	pixman_format_code_t read_format;
1006

1007
	struct weston_backend *backend;
1008

1009
	struct weston_launcher *launcher;
1010

1011 1012
	struct wl_list plugin_api_list; /* struct weston_plugin_api::link */

1013
	uint32_t output_id_pool;
1014

1015 1016
	struct xkb_rule_names xkb_names;
	struct xkb_context *xkb_context;
1017
	struct weston_xkb_info *xkb_info;
1018

1019 1020
	int32_t kb_repeat_rate;
	int32_t kb_repeat_delay;
1021

1022 1023
	bool vt_switching;

1024
	clockid_t presentation_clock;
1025
	int32_t repaint_msec;
1026

1027 1028
	unsigned int activate_serial;

1029 1030
	struct wl_global *pointer_constraints;

1031
	int exit_code;
1032 1033 1034

	void *user_data;
	void (*exit)(struct weston_compositor *c);
1035 1036 1037 1038

	/* Whether to let the compositor run without any input device. */
	bool require_input;

1039 1040 1041
	/* Signal for a backend to inform a frontend about possible changes
	 * in head status.
	 */
1042 1043
	struct wl_signal heads_changed_signal;
	struct wl_event_source *heads_changed_source;
1044 1045
};

1046 1047 1048 1049 1050 1051 1052
struct weston_buffer {
	struct wl_resource *resource;
	struct wl_signal destroy_signal;
	struct wl_listener destroy_listener;

	union {
		struct wl_shm_buffer *shm_buffer;
1053
		void *legacy_buffer;
1054 1055 1056
	};
	int32_t width, height;
	uint32_t busy_count;
1057
	int y_inverted;
1058 1059
};

1060
struct weston_buffer_reference {
1061
	struct weston_buffer *buffer;
1062 1063 1064
	struct wl_listener destroy_listener;
};

1065
struct weston_buffer_viewport {
1066 1067 1068
	struct {
		/* wl_surface.set_buffer_transform */
		uint32_t transform;
1069

1070 1071
		/* wl_surface.set_scaling_factor */
		int32_t scale;
1072

1073 1074 1075 1076
		/*
		 * If src_width != wl_fixed_from_int(-1),
		 * then and only then src_* are used.
		 */
1077 1078 1079 1080 1081
		wl_fixed_t src_x, src_y;
		wl_fixed_t src_width, src_height;
	} buffer;

	struct {
1082 1083 1084
		/*
		 * If width == -1, the size is inferred from the buffer.
		 */
1085 1086
		int32_t width, height;
	} surface;
1087 1088

	int changed;
1089 1090
};

1091
struct weston_region {
1092
	struct wl_resource *resource;
1093 1094 1095
	pixman_region32_t region;
};

1096
/* Using weston_view transformations
1097
 *
1098 1099 1100
 * To add a transformation to a view, create a struct weston_transform, and
 * add it to the list view->geometry.transformation_list. Whenever you
 * change the list, anything under view->geometry, or anything in the
1101
 * weston_transforms linked into the list, you must call
1102
 * weston_view_geometry_dirty().
1103 1104 1105
 *
 * The order in the list defines the order of transformations. Let the list
 * contain the transformation matrices M1, ..., Mn as head to tail. The
1106
 * transformation is applied to view-local coordinate vector p as
1107 1108 1109
 *    P = Mn * ... * M2 * M1 * p
 * to produce the global coordinate vector P. The total transform
 *    Mn * ... * M2 * M1
1110 1111
 * is cached in view->transform.matrix, and the inverse of it in
 * view->transform.inverse.
1112
 *
1113 1114
 * The list always contains view->transform.position transformation, which
 * is the translation by view->geometry.x and y.
1115 1116 1117 1118
 *
 * If you want to apply a transformation in local coordinates, add your
 * weston_transform to the head of the list. If you want to apply a
 * transformation in global coordinates, add it to the tail of the list.
1119
 *
1120 1121
 * If view->geometry.parent is set, the total transformation of this
 * view will be the parent's total transformation and this transformation
1122 1123
 * combined:
 *    Mparent * Mn * ... * M2 * M1
1124 1125
 */

1126 1127 1128
struct weston_view {
	struct weston_surface *surface;
	struct wl_list surface_link;
1129
	struct wl_signal destroy_signal;
1130

1131
	struct wl_list link;             /* weston_compositor::view_list */
1132
	struct weston_layer_entry layer_link; /* part of geometry */
1133
	struct weston_plane *plane;
1134 1135

	/* For weston_layer inheritance from another view */
1136
	struct weston_view *parent_view;
1137

1138 1139
	unsigned int click_to_activate_serial;

1140
	pixman_region32_t clip;          /* See weston_view_damage_below() */
1141
	float alpha;                     /* part of geometry, see below */
1142

1143 1144
	void *renderer_state;

1145
	/* Surface geometry state, mutable.
1146
	 * If you change anything, call weston_surface_geometry_dirty().
1147 1148
	 * That includes the transformations referenced from the list.
	 */
1149
	struct {
1150
		float x, y; /* surface translation on display */
1151

1152 1153
		/* struct weston_transform */
		struct wl_list transformation_list;
1154 1155

		/* managed by weston_surface_set_transform_parent() */
1156
		struct weston_view *parent;
1157 1158 1159
		struct wl_listener parent_destroy_listener;
		struct wl_list child_list; /* geometry.parent_link */
		struct wl_list parent_link;
1160 1161 1162 1163

		/* managed by weston_view_set_mask() */
		bool scissor_enabled;
		pixman_region32_t scissor; /* always a simple rect */
1164
	} geometry;
1165

1166
	/* State derived from geometry state, read-only.
1167
	 * This is updated by weston_view_update_transform().
1168 1169
	 */
	struct {
1170 1171
		int dirty;

1172 1173 1174 1175 1176 1177
		/* Approximations in global coordinates:
		 * - boundingbox is guaranteed to include the whole view in
		 *   the smallest possible single rectangle.
		 * - opaque is guaranteed to be fully opaque, though not
		 *   necessarily include all opaque areas.
		 */
1178
		pixman_region32_t boundingbox;
1179
		pixman_region32_t opaque;
1180

1181 1182 1183 1184
		/* matrix and inverse are used only if enabled = 1.
		 * If enabled = 0, use x, y, width, height directly.
		 */
		int enabled;
1185
		struct weston_matrix matrix;
1186
		struct weston_matrix inverse;
1187 1188

		struct weston_transform position; /* matrix from x, y */
1189 1190
	} transform;

1191
	/*
1192 1193 1194
	 * The primary output for this view.
	 * Used for picking the output for driving internal animations on the
	 * view, inheriting the primary output for related views in shells, etc.
1195 1196 1197
	 */
	struct weston_output *output;

1198 1199 1200 1201 1202
	/*
	 * A more complete representation of all outputs this surface is
	 * displayed on.
	 */
	uint32_t output_mask;
1203 1204 1205

	/* Per-surface Presentation feedback flags, controlled by backend. */
	uint32_t psf_flags;
1206 1207

	bool is_mapped;
1208 1209
};

1210 1211 1212 1213 1214 1215 1216 1217 1218
struct weston_surface_state {
	/* wl_surface.attach */
	int newly_attached;
	struct weston_buffer *buffer;
	struct wl_listener buffer_destroy_listener;
	int32_t sx;
	int32_t sy;

	/* wl_surface.damage */
1219 1220 1221
	pixman_region32_t damage_surface;
	/* wl_surface.damage_buffer */
	pixman_region32_t damage_buffer;
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231

	/* wl_surface.set_opaque_region */
	pixman_region32_t opaque;

	/* wl_surface.set_input_region */
	pixman_region32_t input;

	/* wl_surface.frame */
	struct wl_list frame_callback_list;

1232 1233 1234
	/* presentation.feedback */
	struct wl_list feedback_list;

1235 1236
	/* wl_surface.set_buffer_transform */
	/* wl_surface.set_scaling_factor */
1237 1238
	/* wp_viewport.set_source */
	/* wp_viewport.set_destination */
1239 1240 1241
	struct weston_buffer_viewport buffer_viewport;