1 /*
2  * Copyright © 2006 Novell, Inc.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software
5  * and its documentation for any purpose is hereby granted without
6  * fee, provided that the above copyright notice appear in all copies
7  * and that both that copyright notice and this permission notice
8  * appear in supporting documentation, and that the name of
9  * Novell, Inc. not be used in advertising or publicity pertaining to
10  * distribution of the software without specific, written prior permission.
11  * Novell, Inc. makes no representations about the suitability of this
12  * software for any purpose. It is provided "as is" without express or
13  * implied warranty.
14  *
15  * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17  * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  *
23  * Author: David Reveman <davidr@novell.com>
24  */
25 
26 #ifndef _DECORATION_H
27 #define _DECORATION_H
28 
29 #include <string.h>
30 #include <limits.h>
31 
32 #include <X11/Xlib.h>
33 #include <X11/extensions/Xrender.h>
34 
35 #ifdef  __cplusplus
36 extern "C" {
37 #endif
38 
39 #define DECOR_SUPPORTING_DM_CHECK_ATOM_NAME     "_COMPIZ_SUPPORTING_DM_CHECK"
40 #define DECOR_BARE_ATOM_NAME                    "_COMPIZ_WINDOW_DECOR_BARE"
41 #define DECOR_NORMAL_ATOM_NAME                  "_COMPIZ_WINDOW_DECOR_NORMAL"
42 #define DECOR_ACTIVE_ATOM_NAME                  "_COMPIZ_WINDOW_DECOR_ACTIVE"
43 #define DECOR_WINDOW_ATOM_NAME                  "_COMPIZ_WINDOW_DECOR"
44 #define DECOR_BLUR_ATOM_NAME                    "_COMPIZ_WM_WINDOW_BLUR_DECOR"
45 #define DECOR_SWITCH_WINDOW_ATOM_NAME           "_COMPIZ_SWITCH_SELECT_WINDOW"
46 #define DECOR_SWITCH_FOREGROUND_COLOR_ATOM_NAME "_COMPIZ_SWITCH_FOREGROUND_COLOR"
47 
48 #define GRAVITY_WEST  (1 << 0)
49 #define GRAVITY_EAST  (1 << 1)
50 #define GRAVITY_NORTH (1 << 2)
51 #define GRAVITY_SOUTH (1 << 3)
52 
53 #define ALIGN_LEFT   (0)
54 #define ALIGN_RIGHT  (1 << 0)
55 #define ALIGN_TOP    (0)
56 #define ALIGN_BOTTOM (1 << 1)
57 
58 #define CLAMP_HORZ (1 << 0)
59 #define CLAMP_VERT (1 << 1)
60 
61 #define STRETCH_X (1 << 0)
62 #define STRETCH_Y (1 << 1)
63 
64 #define XX_MASK (1 << 16)
65 #define XY_MASK (1 << 17)
66 #define YX_MASK (1 << 18)
67 #define YY_MASK (1 << 19)
68 
69 #define PAD_TOP    (1 << 0)
70 #define PAD_BOTTOM (1 << 1)
71 #define PAD_LEFT   (1 << 2)
72 #define PAD_RIGHT  (1 << 3)
73 
74 #define BORDER_TOP    0
75 #define BORDER_BOTTOM 1
76 #define BORDER_LEFT   2
77 #define BORDER_RIGHT  3
78 
79 typedef struct _decor_point {
80     int x;
81     int y;
82     int gravity;
83 } decor_point_t;
84 
85 typedef struct _decor_matrix {
86     double xx; double yx;
87     double xy; double yy;
88     double x0; double y0;
89 } decor_matrix_t;
90 
91 typedef struct _decor_quad {
92     decor_point_t  p1;
93     decor_point_t  p2;
94     int		   max_width;
95     int		   max_height;
96     int		   align;
97     int		   clamp;
98     int            stretch;
99     decor_matrix_t m;
100 } decor_quad_t;
101 
102 typedef struct _decor_extents {
103     int left;
104     int right;
105     int top;
106     int bottom;
107 } decor_extents_t;
108 
109 typedef struct _decor_context {
110     decor_extents_t extents;
111 
112     int left_space;
113     int right_space;
114     int top_space;
115     int bottom_space;
116 
117     int left_corner_space;
118     int right_corner_space;
119     int top_corner_space;
120     int bottom_corner_space;
121 } decor_context_t;
122 
123 typedef struct _decor_box {
124     int x1;
125     int y1;
126     int x2;
127     int y2;
128 
129     int pad;
130 } decor_box_t;
131 
132 typedef struct _decor_layout {
133     int width;
134     int height;
135 
136     decor_box_t left;
137     decor_box_t right;
138     decor_box_t top;
139     decor_box_t bottom;
140 
141     int rotation;
142 } decor_layout_t;
143 
144 typedef struct _decor_shadow_options {
145     double	   shadow_radius;
146     double	   shadow_opacity;
147     unsigned short shadow_color[3];
148     int		   shadow_offset_x;
149     int		   shadow_offset_y;
150 } decor_shadow_options_t;
151 
152 typedef struct _decor_shadow {
153     int     ref_count;
154     Pixmap  pixmap;
155     Picture picture;
156     int	    width;
157     int	    height;
158 } decor_shadow_t;
159 
160 typedef void (*decor_draw_func_t) (Display	   *xdisplay,
161 				   Pixmap	   pixmap,
162 				   Picture	   picture,
163 				   int		   width,
164 				   int		   height,
165 				   decor_context_t *context,
166 				   void		   *closure);
167 
168 #define BASE_PROP_SIZE 12
169 #define QUAD_PROP_SIZE 9
170 #define N_QUADS_MAX    24
171 
172 int
173 decor_version (void);
174 
175 void
176 decor_quads_to_property (long		 *data,
177 			 Pixmap		 pixmap,
178 			 decor_extents_t *input,
179 			 decor_extents_t *max_input,
180 			 int		 min_width,
181 			 int		 min_height,
182 			 decor_quad_t    *quad,
183 			 int		 nQuad);
184 
185 int
186 decor_property_get_version (long *data);
187 
188 int
189 decor_property_to_quads (long		 *data,
190 			 int		 size,
191 			 Pixmap		 *pixmap,
192 			 decor_extents_t *input,
193 			 decor_extents_t *max_input,
194 			 int		 *min_width,
195 			 int		 *min_height,
196 			 decor_quad_t    *quad);
197 
198 void
199 decor_region_to_blur_property (long   *data,
200 			       int    threshold,
201 			       int    filter,
202 			       int    width,
203 			       int    height,
204 			       Region topRegion,
205 			       int    topOffset,
206 			       Region bottomRegion,
207 			       int    bottomOffset,
208 			       Region leftRegion,
209 			       int    leftOffset,
210 			       Region rightRegion,
211 			       int    rightOffset);
212 
213 void
214 decor_apply_gravity (int gravity,
215 		     int x,
216 		     int y,
217 		     int width,
218 		     int height,
219 		     int *return_x,
220 		     int *return_y);
221 
222 int
223 decor_set_vert_quad_row (decor_quad_t *q,
224 			 int	      top,
225 			 int	      top_corner,
226 			 int	      bottom,
227 			 int	      bottom_corner,
228 			 int	      left,
229 			 int	      right,
230 			 int	      gravity,
231 			 int	      height,
232 			 int	      splitY,
233 			 int	      splitGravity,
234 			 double	      x0,
235 			 double	      y0,
236 			 int	      rotation);
237 
238 int
239 decor_set_horz_quad_line (decor_quad_t *q,
240 			  int	       left,
241 			  int	       left_corner,
242 			  int	       right,
243 			  int	       right_corner,
244 			  int	       top,
245 			  int	       bottom,
246 			  int	       gravity,
247 			  int	       width,
248 			  int	       splitX,
249 			  int	       splitGravity,
250 			  double       x0,
251 			  double       y0);
252 
253 int
254 decor_set_lSrS_window_quads (decor_quad_t    *q,
255 			     decor_context_t *c,
256 			     decor_layout_t  *l);
257 
258 int
259 decor_set_lSrStSbS_window_quads (decor_quad_t    *q,
260 				 decor_context_t *c,
261 				 decor_layout_t  *l);
262 
263 int
264 decor_set_lSrStXbS_window_quads (decor_quad_t    *q,
265 				 decor_context_t *c,
266 				 decor_layout_t  *l,
267 				 int		 top_stretch_offset);
268 
269 int
270 decor_set_lSrStSbX_window_quads (decor_quad_t    *q,
271 				 decor_context_t *c,
272 				 decor_layout_t  *l,
273 				 int		 bottom_stretch_offset);
274 
275 int
276 decor_set_lXrXtXbX_window_quads (decor_quad_t    *q,
277 				 decor_context_t *c,
278 				 decor_layout_t  *l,
279 				 int		 left_stretch_offset,
280 				 int		 right_stretch_offset,
281 				 int		 top_stretch_offset,
282 				 int		 bottom_stretch_offset);
283 
284 decor_shadow_t *
285 decor_shadow_create (Display		    *xdisplay,
286 		     Screen		    *screen,
287 		     int		    width,
288 		     int		    height,
289 		     int		    left,
290 		     int		    right,
291 		     int		    top,
292 		     int		    bottom,
293 		     int		    solid_left,
294 		     int		    solid_right,
295 		     int		    solid_top,
296 		     int		    solid_bottom,
297 		     decor_shadow_options_t *opt,
298 		     decor_context_t	    *context,
299 		     decor_draw_func_t      draw,
300 		     void		    *closure);
301 
302 void
303 decor_shadow_destroy (Display	     *xdisplay,
304 		      decor_shadow_t *shadow);
305 
306 void
307 decor_shadow_reference (decor_shadow_t *shadow);
308 
309 void
310 decor_shadow (Display	     *xdisplay,
311 		      decor_shadow_t *shadow);
312 
313 void
314 decor_draw_simple (Display	   *xdisplay,
315 		   Pixmap	   pixmap,
316 		   Picture	   picture,
317 		   int		   width,
318 		   int		   height,
319 		   decor_context_t *c,
320 		   void		   *closure);
321 
322 void
323 decor_get_default_layout (decor_context_t *c,
324 			  int	          width,
325 			  int	          height,
326 			  decor_layout_t  *layout);
327 
328 void
329 decor_get_best_layout (decor_context_t *c,
330 		       int	       width,
331 		       int	       height,
332 		       decor_layout_t  *layout);
333 
334 void
335 decor_fill_picture_extents_with_shadow (Display	        *xdisplay,
336 					decor_shadow_t  *shadow,
337 					decor_context_t *context,
338 					Picture	        picture,
339 					decor_layout_t  *layout);
340 
341 void
342 decor_blend_transform_picture (Display	       *xdisplay,
343 			       decor_context_t *context,
344 			       Picture	       src,
345 			       int	       xSrc,
346 			       int	       ySrc,
347 			       Picture	       dst,
348 			       decor_layout_t  *layout,
349 			       Region	       region,
350 			       unsigned short  alpha,
351 			       int	       shade_alpha);
352 
353 void
354 decor_blend_border_picture (Display	    *xdisplay,
355 			    decor_context_t *context,
356 			    Picture	    src,
357 			    int	            xSrc,
358 			    int	            ySrc,
359 			    Picture	    dst,
360 			    decor_layout_t  *layout,
361 			    unsigned int    border,
362 			    Region	    region,
363 			    unsigned short  alpha,
364 			    int	            shade_alpha,
365 			    int             ignore_src_alpha);
366 
367 #define DECOR_ACQUIRE_STATUS_SUCCESS	      0
368 #define DECOR_ACQUIRE_STATUS_FAILED	      1
369 #define DECOR_ACQUIRE_STATUS_OTHER_DM_RUNNING 2
370 
371 int
372 decor_acquire_dm_session (Display    *xdisplay,
373 			  int	     screen,
374 			  const char *name,
375 			  int	     replace_current_dm,
376 			  Time	     *timestamp);
377 
378 void
379 decor_set_dm_check_hint (Display *xdisplay,
380 			 int	 screen);
381 
382 #define DECOR_SELECTION_KEEP    0
383 #define DECOR_SELECTION_GIVE_UP 1
384 
385 int
386 decor_handle_selection_clear (Display *xdisplay,
387 			      XEvent  *xevent,
388 			      int     screen);
389 
390 void
391 decor_handle_selection_request (Display *xdisplay,
392 				XEvent  *event,
393 				Time    dm_sn_timestamp);
394 
395 #ifdef  __cplusplus
396 }
397 #endif
398 
399 #endif
400