main shrub/neuswc / libswc / compositor.h
  1/* swc: libswc/compositor.h
  2 *
  3 * Copyright (c) 2013, 2014 Michael Forney
  4 *
  5 * Permission is hereby granted, free of charge, to any person obtaining a copy
  6 * of this software and associated documentation files (the "Software"), to deal
  7 * in the Software without restriction, including without limitation the rights
  8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9 * copies of the Software, and to permit persons to whom the Software is
 10 * furnished to do so, subject to the following conditions:
 11 *
 12 * The above copyright notice and this permission notice shall be included in
 13 * all copies or substantial portions of the Software.
 14 *
 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 21 * SOFTWARE.
 22 */
 23
 24#ifndef SWC_COMPOSITOR_H
 25#define SWC_COMPOSITOR_H
 26
 27#include "view.h"
 28
 29#include <pixman.h>
 30#include <stdbool.h>
 31#include <wayland-server.h>
 32
 33struct screen;
 34struct wld_buffer;
 35struct wld_font;
 36
 37struct decor_part_buffer {
 38	void *data;
 39	struct wld_buffer *buffer;
 40	struct wld_buffer *tiled_buffer;
 41	uint32_t width, height, stride;
 42	uint32_t tiled_width, tiled_height;
 43	bool opaque;
 44};
 45
 46struct swc_compositor {
 47	struct pointer_handler *const pointer_handler;
 48	struct {
 49		/**
 50		 * Emitted when a new surface is created.
 51		 *
 52		 * The data argument of the signal refers to the surface that has been
 53		 * created.
 54		 */
 55		struct wl_signal new_surface;
 56	} signal;
 57};
 58
 59bool
 60compositor_initialize(void);
 61void
 62compositor_finalize(void);
 63void
 64compositor_damage_all(void);
 65
 66struct compositor_view {
 67	struct view base;
 68	struct surface *surface;
 69	struct wld_buffer *buffer;
 70	bool buffer_opaque_valid;
 71	bool buffer_opaque;
 72	struct window *window;
 73	struct compositor_view *parent;
 74	int32_t buffer_offset_x;
 75	int32_t buffer_offset_y;
 76
 77	/* Whether or not the view is visible (mapped). */
 78	bool visible;
 79
 80	/* Whether or not to make it always be on top of other windows */
 81	bool always_top;
 82
 83	/* Global stacking layer for this view */
 84	uint32_t stack_layer;
 85
 86	/* The box that the surface covers (including it's border). */
 87	pixman_box32_t extents;
 88
 89	/* The region that is covered by opaque regions of surfaces above this
 90	 * surface. */
 91	pixman_region32_t clip;
 92
 93	struct {
 94		uint32_t outwidth;
 95		uint32_t outcolor;
 96
 97		bool damaged_border1;
 98
 99		/* sir, a second border has hit the compositor! */
100		uint32_t inwidth;
101		uint32_t incolor;
102
103		bool damaged_border2;
104	} border;
105
106	struct {
107		uint32_t color;
108		uint32_t top, right, bottom, left;
109		struct swc_decor_text text;
110		const struct swc_decor_parts *parts_key;
111		struct decor_part_buffer parts[8];
112		char *string;
113		char *font_name;
114		struct wld_font *font;
115		bool damaged;
116	} decor;
117
118	struct wl_list link;
119	struct wl_signal destroy_signal;
120};
121
122struct compositor_view *
123compositor_create_view(struct surface *surface);
124
125void
126compositor_view_destroy(struct compositor_view *view);
127
128/**
129 * Returns view as a compositor_view, or NULL if view is not a compositor_view.
130 */
131struct compositor_view *
132compositor_view(struct view *view);
133
134void
135compositor_view_set_parent(struct compositor_view *view,
136                           struct compositor_view *parent);
137void
138compositor_view_restack(struct compositor_view *view,
139                        struct compositor_view *sibling, bool above);
140
141void
142compositor_view_show(struct compositor_view *view);
143void
144compositor_view_hide(struct compositor_view *view);
145
146void
147compositor_view_set_border_color(struct compositor_view *view,
148                                 uint32_t outcolor, uint32_t incolor);
149void
150compositor_view_set_border_width(struct compositor_view *view,
151                                 uint32_t outwidth, uint32_t inwidth);
152void
153compositor_view_set_decor(struct compositor_view *view,
154                           const struct swc_decor *decor);
155void
156compositor_view_damage_decor(struct compositor_view *view);
157
158/**
159 * get the current composited buffer for a screen for screenshots.
160 * returns null if no buffer
161 */
162struct wld_buffer *
163compositor_get_buffer(struct screen *screen);
164
165/**
166 * render the compositor scene into a shm buffer
167 * caller must free with wld_buffer_unreference()
168 */
169struct wld_buffer *
170compositor_render_to_shm(struct screen *screen);
171
172void
173raise_window(struct compositor_view *view);
174void
175raise_window_top(struct compositor_view *view);
176
177enum compositor_stack_layer {
178	STACK_LAYER_BACKGROUND = 0,
179	STACK_LAYER_BOTTOM = 1,
180	STACK_LAYER_NORMAL = 2,
181	STACK_LAYER_TOP = 3,
182	STACK_LAYER_OVERLAY = 4,
183};
184
185void
186compositor_view_set_stack_layer(struct compositor_view *view, uint32_t layer,
187	                            bool raise);
188
189#endif