main 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	uint32_t width, height, stride;
 41};
 42
 43struct swc_compositor {
 44	struct pointer_handler *const pointer_handler;
 45	struct {
 46		/**
 47		 * Emitted when a new surface is created.
 48		 *
 49		 * The data argument of the signal refers to the surface that has been
 50		 * created.
 51		 */
 52		struct wl_signal new_surface;
 53	} signal;
 54};
 55
 56bool
 57compositor_initialize(void);
 58void
 59compositor_finalize(void);
 60void
 61compositor_damage_all(void);
 62
 63struct compositor_view {
 64	struct view base;
 65	struct surface *surface;
 66	struct wld_buffer *buffer;
 67	struct window *window;
 68	struct compositor_view *parent;
 69	int32_t buffer_offset_x;
 70	int32_t buffer_offset_y;
 71
 72	/* Whether or not the view is visible (mapped). */
 73	bool visible;
 74
 75	/* Whether or not to make it always be on top of other windows */
 76	bool always_top;
 77
 78	/* Global stacking layer for this view */
 79	uint32_t stack_layer;
 80
 81	/* The box that the surface covers (including it's border). */
 82	pixman_box32_t extents;
 83
 84	/* The region that is covered by opaque regions of surfaces above this
 85	 * surface. */
 86	pixman_region32_t clip;
 87
 88	struct {
 89		uint32_t outwidth;
 90		uint32_t outcolor;
 91
 92		bool damaged_border1;
 93
 94		/* sir, a second border has hit the compositor! */
 95		uint32_t inwidth;
 96		uint32_t incolor;
 97
 98		bool damaged_border2;
 99	} border;
100
101	struct {
102		uint32_t color;
103		uint32_t top, right, bottom, left;
104		struct swc_decor_text text;
105		const struct swc_decor_parts *parts_key;
106		struct decor_part_buffer parts[8];
107		char *string;
108		char *font_name;
109		struct wld_font *font;
110		bool damaged;
111	} decor;
112
113	struct wl_list link;
114	struct wl_signal destroy_signal;
115};
116
117struct compositor_view *
118compositor_create_view(struct surface *surface);
119
120void
121compositor_view_destroy(struct compositor_view *view);
122
123/**
124 * Returns view as a compositor_view, or NULL if view is not a compositor_view.
125 */
126struct compositor_view *
127compositor_view(struct view *view);
128
129void
130compositor_view_set_parent(struct compositor_view *view,
131                           struct compositor_view *parent);
132void
133compositor_view_restack(struct compositor_view *view,
134                        struct compositor_view *sibling, bool above);
135
136void
137compositor_view_show(struct compositor_view *view);
138void
139compositor_view_hide(struct compositor_view *view);
140
141void
142compositor_view_set_border_color(struct compositor_view *view,
143                                 uint32_t outcolor, uint32_t incolor);
144void
145compositor_view_set_border_width(struct compositor_view *view,
146                                 uint32_t outwidth, uint32_t inwidth);
147void
148compositor_view_set_decor(struct compositor_view *view,
149                           const struct swc_decor *decor);
150void
151compositor_view_damage_decor(struct compositor_view *view);
152
153/**
154 * get the current composited buffer for a screen for screenshotss.
155 * returns null if no buffer
156 */
157struct wld_buffer *
158compositor_get_buffer(struct screen *screen);
159
160/**
161 * render the compositor scene into a shm buffer
162 * caller must free with wld_buffer_unreference()
163 */
164struct wld_buffer *
165compositor_render_to_shm(struct screen *screen);
166
167void
168raise_window(struct compositor_view *view);
169void
170raise_window_top(struct compositor_view *view);
171
172enum compositor_stack_layer {
173	STACK_LAYER_BACKGROUND = 0,
174	STACK_LAYER_BOTTOM = 1,
175	STACK_LAYER_NORMAL = 2,
176	STACK_LAYER_TOP = 3,
177	STACK_LAYER_OVERLAY = 4,
178};
179
180void
181compositor_view_set_stack_layer(struct compositor_view *view, uint32_t layer,
182	                            bool raise);
183
184#endif