compositor.h (6489B)
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 "swc.h" 28 #include "view.h" 29 30 #include <pixman.h> 31 #include <stdbool.h> 32 #include <wayland-server.h> 33 34 struct screen; 35 struct wld_buffer; 36 struct wld_font; 37 38 struct decor_part_buffer { 39 void *data; 40 struct wld_buffer *buffer; 41 struct wld_buffer *tiled_buffer; 42 uint32_t width, height, stride; 43 uint32_t tiled_width, tiled_height; 44 bool opaque; 45 }; 46 47 struct swc_compositor { 48 struct pointer_handler *const pointer_handler; 49 struct { 50 /** 51 * Emitted when a new surface is created. 52 * 53 * The data argument of the signal refers to the surface that has been 54 * created. 55 */ 56 struct wl_signal new_surface; 57 } signal; 58 }; 59 60 bool 61 compositor_initialize(void); 62 void 63 compositor_finalize(void); 64 void 65 compositor_damage_all(void); 66 /* adds a rectangle of the global space to what the next frame repaints */ 67 void 68 compositor_damage_rect(int32_t x, int32_t y, uint32_t width, uint32_t height); 69 /* what the frame being presented changed, in its screen's coordinates: 70 * a backend that copies the frame copies only this */ 71 const pixman_region32_t * 72 compositor_frame_damage(void); 73 74 struct compositor_view { 75 struct view base; 76 struct surface *surface; 77 struct wld_buffer *buffer; 78 bool buffer_opaque_valid; 79 bool buffer_opaque; 80 struct window *window; 81 struct compositor_view *parent; 82 /* moves with its parent */ 83 bool attached; 84 int32_t buffer_offset_x; 85 int32_t buffer_offset_y; 86 87 /* Whether or not the view is visible (mapped). */ 88 bool visible; 89 90 /* Whether or not to make it always be on top of other windows */ 91 bool always_top; 92 93 /* a drag icon, never under the pointer */ 94 bool no_input; 95 96 /* Global stacking layer for this view */ 97 /* depth: a higher one is drawn over a lower, see swc_window_set_z */ 98 int32_t z; 99 100 /* The box that the surface covers (including it's border). */ 101 pixman_box32_t extents; 102 /* see swc_window_set_backdrop */ 103 struct { 104 uint32_t margin; 105 void (*hook)(void *data, const struct swc_backdrop *backdrop); 106 void *data; 107 } backdrop; 108 109 /* The region that is covered by opaque regions of surfaces above this 110 * surface. */ 111 pixman_region32_t clip; 112 113 struct { 114 uint32_t outwidth; 115 uint32_t outcolor; 116 117 bool damaged_border1; 118 119 /* sir, a second border has hit the compositor! */ 120 uint32_t inwidth; 121 uint32_t incolor; 122 123 bool damaged_border2; 124 125 /* border goes around the decor too */ 126 bool frame; 127 } border; 128 129 struct { 130 uint32_t color; 131 uint32_t top, right, bottom, left; 132 struct swc_decor_text text; 133 const struct swc_decor_parts *parts_key; 134 struct decor_part_buffer parts[8]; 135 char *string; 136 char *font_name; 137 struct wld_font *font; 138 bool damaged; 139 } decor; 140 141 struct wl_list link; 142 struct wl_signal destroy_signal; 143 }; 144 145 struct compositor_view * 146 compositor_create_view(struct surface *surface); 147 148 void 149 compositor_view_destroy(struct compositor_view *view); 150 151 /** 152 * Returns view as a compositor_view, or NULL if view is not a compositor_view. 153 */ 154 struct compositor_view * 155 compositor_view(struct view *view); 156 157 void 158 compositor_view_set_parent(struct compositor_view *view, 159 struct compositor_view *parent); 160 void 161 compositor_view_restack(struct compositor_view *view, 162 struct compositor_view *sibling, bool above); 163 164 /* the view whose content is under x, y, NULL on a window's decoration or 165 * border, which are the compositor's and not the client's */ 166 struct compositor_view * 167 compositor_content_view_at(int32_t x, int32_t y); 168 169 /* topmost view taking input at x, y, or NULL */ 170 struct compositor_view * 171 compositor_view_at(int32_t x, int32_t y); 172 173 void 174 compositor_view_show(struct compositor_view *view); 175 void 176 compositor_view_hide(struct compositor_view *view); 177 178 void 179 compositor_view_set_border_color(struct compositor_view *view, 180 uint32_t outcolor, uint32_t incolor); 181 void 182 compositor_view_set_border_frame(struct compositor_view *view, bool frame); 183 void 184 compositor_view_set_border_width(struct compositor_view *view, 185 uint32_t outwidth, uint32_t inwidth); 186 void 187 compositor_view_set_decor(struct compositor_view *view, 188 const struct swc_decor *decor); 189 void 190 compositor_view_damage_decor(struct compositor_view *view); 191 192 /** 193 * get the current composited buffer for a screen for screenshots. 194 * returns null if no buffer 195 */ 196 struct wld_buffer * 197 compositor_get_buffer(struct screen *screen); 198 199 /* recreate the render target after the screen geometry changed */ 200 void 201 compositor_screen_resize(struct screen *screen); 202 203 /** 204 * render the compositor scene into a shm buffer 205 * caller must free with wld_buffer_unreference() 206 */ 207 struct wld_buffer * 208 compositor_render_to_shm(struct screen *screen); 209 210 void 211 raise_window(struct compositor_view *view); 212 void 213 compositor_view_set_backdrop(struct compositor_view *view, uint32_t margin, 214 void (*hook)(void *data, const struct swc_backdrop *backdrop), void *data); 215 void 216 raise_window_top(struct compositor_view *view); 217 218 enum compositor_stack_layer { 219 STACK_LAYER_BACKGROUND = SWC_Z_BACKGROUND, 220 STACK_LAYER_BOTTOM = SWC_Z_BOTTOM, 221 STACK_LAYER_NORMAL = SWC_Z_WINDOW, 222 STACK_LAYER_TOP = SWC_Z_TOP, 223 STACK_LAYER_OVERLAY = SWC_Z_OVERLAY, 224 }; 225 226 void 227 compositor_view_set_z(struct compositor_view *view, int32_t layer, 228 bool raise); 229 230 #endif