blob: 019424eafbb3f61945744e3bed0b7f699e9ba7b5 [file] [log] [blame]
Kristian Høgsbergffd710e2008-12-02 15:15:01 -05001/*
2 * Copyright © 2008 Kristian Høgsberg
3 *
Bryce Harrington6c6164c2015-06-11 14:20:17 -07004 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
Kristian Høgsbergffd710e2008-12-02 15:15:01 -050011 *
Bryce Harrington6c6164c2015-06-11 14:20:17 -070012 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
Kristian Høgsbergffd710e2008-12-02 15:15:01 -050024 */
25
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050026#ifndef _CAIRO_UTIL_H
27#define _CAIRO_UTIL_H
28
Jason Ekstrand01c9ec32013-10-13 19:08:39 -050029#include <stdint.h>
Pekka Paalanen4fbb6532012-11-30 13:37:28 +020030#include <cairo.h>
Kristian Høgsberg6006ecb2012-11-29 12:23:36 -050031
Boyan Ding850a5142014-08-05 15:22:04 +080032#include <wayland-util.h>
33
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050034void
Benjamin Franzke47eb8f42011-10-07 09:08:56 +020035surface_flush_device(cairo_surface_t *surface);
36
37void
Marek Chalupa0d7fe8d2014-10-29 14:51:22 +010038render_shadow(cairo_t *cr, cairo_surface_t *surface,
39 int x, int y, int width, int height, int margin, int top_margin);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040040
41void
42tile_source(cairo_t *cr, cairo_surface_t *surface,
Kristian Høgsberg9a686242010-08-18 15:28:04 -040043 int x, int y, int width, int height, int margin, int top_margin);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040044
Kristian Høgsberg1e164b92011-09-13 14:47:46 -040045void
46rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius);
47
Kristian Høgsberg27d38662011-10-20 13:11:12 -040048cairo_surface_t *
Kristian Høgsbergf02a6492012-03-12 01:05:25 -040049load_cairo_surface(const char *filename);
Kristian Høgsberg27d38662011-10-20 13:11:12 -040050
Kristian Høgsberg42abdf52012-05-15 22:14:27 -040051struct theme {
52 cairo_surface_t *active_frame;
53 cairo_surface_t *inactive_frame;
54 cairo_surface_t *shadow;
55 int frame_radius;
56 int margin;
57 int width;
58 int titlebar_height;
59};
60
Kristian Høgsberg5adb4802012-05-15 22:25:28 -040061struct theme *
62theme_create(void);
Kristian Høgsberg42abdf52012-05-15 22:14:27 -040063void
Kristian Høgsberg5adb4802012-05-15 22:25:28 -040064theme_destroy(struct theme *t);
65
Scott Moreauc6a7e4b2012-09-28 02:45:06 -060066enum {
67 THEME_FRAME_ACTIVE = 1,
Kristian Høgsberg89f4bc42013-10-23 22:12:13 -070068 THEME_FRAME_MAXIMIZED = 2,
69 THEME_FRAME_NO_TITLE = 4
Scott Moreauc6a7e4b2012-09-28 02:45:06 -060070};
Kristian Høgsberg5adb4802012-05-15 22:25:28 -040071
Kristian Høgsberg42abdf52012-05-15 22:14:27 -040072void
Kristian Høgsbergc680e902013-10-23 21:49:30 -070073theme_set_background_source(struct theme *t, cairo_t *cr, uint32_t flags);
74void
Murray Calavera883ac022015-06-06 13:02:22 +000075theme_render_frame(struct theme *t,
Kristian Høgsberg5adb4802012-05-15 22:25:28 -040076 cairo_t *cr, int width, int height,
Boyan Ding850a5142014-08-05 15:22:04 +080077 const char *title, struct wl_list *buttons,
78 uint32_t flags);
Kristian Høgsberg42abdf52012-05-15 22:14:27 -040079
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -040080enum theme_location {
81 THEME_LOCATION_INTERIOR = 0,
82 THEME_LOCATION_RESIZING_TOP = 1,
83 THEME_LOCATION_RESIZING_BOTTOM = 2,
84 THEME_LOCATION_RESIZING_LEFT = 4,
85 THEME_LOCATION_RESIZING_TOP_LEFT = 5,
86 THEME_LOCATION_RESIZING_BOTTOM_LEFT = 6,
87 THEME_LOCATION_RESIZING_RIGHT = 8,
88 THEME_LOCATION_RESIZING_TOP_RIGHT = 9,
89 THEME_LOCATION_RESIZING_BOTTOM_RIGHT = 10,
90 THEME_LOCATION_RESIZING_MASK = 15,
91 THEME_LOCATION_EXTERIOR = 16,
92 THEME_LOCATION_TITLEBAR = 17,
93 THEME_LOCATION_CLIENT_AREA = 18,
94};
95
96enum theme_location
Scott Moreauc6a7e4b2012-09-28 02:45:06 -060097theme_get_location(struct theme *t, int x, int y, int width, int height, int flags);
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -040098
Jason Ekstrand01c9ec32013-10-13 19:08:39 -050099struct frame;
100
101enum frame_status {
102 FRAME_STATUS_NONE = 0,
103 FRAME_STATUS_REPAINT = 0x1,
104 FRAME_STATUS_MINIMIZE = 0x2,
105 FRAME_STATUS_MAXIMIZE = 0x4,
106 FRAME_STATUS_CLOSE = 0x8,
107 FRAME_STATUS_MENU = 0x10,
108 FRAME_STATUS_RESIZE = 0x20,
109 FRAME_STATUS_MOVE = 0x40,
110 FRAME_STATUS_ALL = 0x7f
111};
112
113enum frame_flag {
114 FRAME_FLAG_ACTIVE = 0x1,
115 FRAME_FLAG_MAXIMIZED = 0x2
116};
117
118enum {
119 FRAME_BUTTON_NONE = 0,
120 FRAME_BUTTON_CLOSE = 0x1,
121 FRAME_BUTTON_MAXIMIZE = 0x2,
122 FRAME_BUTTON_MINIMIZE = 0x4,
123 FRAME_BUTTON_ALL = 0x7
124};
125
126enum frame_button_state {
127 FRAME_BUTTON_RELEASED = 0,
128 FRAME_BUTTON_PRESSED = 1
129};
130
131struct frame *
132frame_create(struct theme *t, int32_t width, int32_t height, uint32_t buttons,
133 const char *title);
134
135void
136frame_destroy(struct frame *frame);
137
138/* May set FRAME_STATUS_REPAINT */
139int
140frame_set_title(struct frame *frame, const char *title);
141
142/* May set FRAME_STATUS_REPAINT */
143void
144frame_set_flag(struct frame *frame, enum frame_flag flag);
145
146/* May set FRAME_STATUS_REPAINT */
147void
148frame_unset_flag(struct frame *frame, enum frame_flag flag);
149
150/* May set FRAME_STATUS_REPAINT */
151void
152frame_resize(struct frame *frame, int32_t width, int32_t height);
153
154/* May set FRAME_STATUS_REPAINT */
155void
156frame_resize_inside(struct frame *frame, int32_t width, int32_t height);
157
158int32_t
159frame_width(struct frame *frame);
160
161int32_t
162frame_height(struct frame *frame);
163
164void
165frame_interior(struct frame *frame, int32_t *x, int32_t *y,
166 int32_t *width, int32_t *height);
167void
168frame_input_rect(struct frame *frame, int32_t *x, int32_t *y,
169 int32_t *width, int32_t *height);
170void
171frame_opaque_rect(struct frame *frame, int32_t *x, int32_t *y,
172 int32_t *width, int32_t *height);
173
Jasper St. Pierre74073452014-02-01 18:36:41 -0500174int
175frame_get_shadow_margin(struct frame *frame);
176
Jason Ekstrand01c9ec32013-10-13 19:08:39 -0500177uint32_t
178frame_status(struct frame *frame);
179
180void
181frame_status_clear(struct frame *frame, enum frame_status status);
182
183/* May set FRAME_STATUS_REPAINT */
184enum theme_location
185frame_pointer_enter(struct frame *frame, void *pointer, int x, int y);
186
187/* May set FRAME_STATUS_REPAINT */
188enum theme_location
189frame_pointer_motion(struct frame *frame, void *pointer, int x, int y);
190
191/* May set FRAME_STATUS_REPAINT */
192void
193frame_pointer_leave(struct frame *frame, void *pointer);
194
Jason Ekstrand0bdd58f2013-10-27 22:25:03 -0500195/* Call to indicate that a button has been pressed/released. The return
196 * value for a button release will be the same as for the corresponding
197 * press. This allows you to more easily track grabs. If you want the
198 * actual location, simply keep the location from the last
199 * frame_pointer_motion call.
200 *
201 * May set:
Jason Ekstrand01c9ec32013-10-13 19:08:39 -0500202 * FRAME_STATUS_MINIMIZE
203 * FRAME_STATUS_MAXIMIZE
204 * FRAME_STATUS_CLOSE
205 * FRAME_STATUS_MENU
206 * FRAME_STATUS_RESIZE
207 * FRAME_STATUS_MOVE
208 */
209enum theme_location
210frame_pointer_button(struct frame *frame, void *pointer,
211 uint32_t button, enum frame_button_state state);
212
Jason Ekstrand3f66cf92013-10-13 19:08:40 -0500213void
214frame_touch_down(struct frame *frame, void *data, int32_t id, int x, int y);
215
216void
217frame_touch_up(struct frame *frame, void *data, int32_t id);
Jason Ekstrand01c9ec32013-10-13 19:08:39 -0500218
Xiong Zhangbfb4ade2014-06-12 11:06:25 +0800219enum theme_location
220frame_double_click(struct frame *frame, void *pointer,
221 uint32_t button, enum frame_button_state state);
222
Jason Ekstrand01c9ec32013-10-13 19:08:39 -0500223void
Xiong Zhang382de462014-06-12 11:06:26 +0800224frame_double_touch_down(struct frame *frame, void *data, int32_t id,
225 int x, int y);
226
227void
228frame_double_touch_up(struct frame *frame, void *data, int32_t id);
229
230void
Jason Ekstrand01c9ec32013-10-13 19:08:39 -0500231frame_repaint(struct frame *frame, cairo_t *cr);
232
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -0500233#endif