blob: 84cf005ec50099328c0c5fa01548e5e99ba682ec [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
Quentin Glidicd8b17bc2016-07-10 11:00:55 +020032#include <wayland-client.h>
Boyan Ding850a5142014-08-05 15:22:04 +080033#include <wayland-util.h>
34
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050035void
Benjamin Franzke47eb8f42011-10-07 09:08:56 +020036surface_flush_device(cairo_surface_t *surface);
37
38void
Marek Chalupa0d7fe8d2014-10-29 14:51:22 +010039render_shadow(cairo_t *cr, cairo_surface_t *surface,
40 int x, int y, int width, int height, int margin, int top_margin);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040041
42void
43tile_source(cairo_t *cr, cairo_surface_t *surface,
Kristian Høgsberg9a686242010-08-18 15:28:04 -040044 int x, int y, int width, int height, int margin, int top_margin);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040045
Kristian Høgsberg1e164b92011-09-13 14:47:46 -040046void
47rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius);
48
Kristian Høgsberg27d38662011-10-20 13:11:12 -040049cairo_surface_t *
Kristian Høgsbergf02a6492012-03-12 01:05:25 -040050load_cairo_surface(const char *filename);
Kristian Høgsberg27d38662011-10-20 13:11:12 -040051
Kristian Høgsberg42abdf52012-05-15 22:14:27 -040052struct theme {
53 cairo_surface_t *active_frame;
54 cairo_surface_t *inactive_frame;
55 cairo_surface_t *shadow;
56 int frame_radius;
57 int margin;
58 int width;
59 int titlebar_height;
60};
61
Kristian Høgsberg5adb4802012-05-15 22:25:28 -040062struct theme *
63theme_create(void);
Kristian Høgsberg42abdf52012-05-15 22:14:27 -040064void
Kristian Høgsberg5adb4802012-05-15 22:25:28 -040065theme_destroy(struct theme *t);
66
Scott Moreauc6a7e4b2012-09-28 02:45:06 -060067enum {
68 THEME_FRAME_ACTIVE = 1,
Kristian Høgsberg89f4bc42013-10-23 22:12:13 -070069 THEME_FRAME_MAXIMIZED = 2,
70 THEME_FRAME_NO_TITLE = 4
Scott Moreauc6a7e4b2012-09-28 02:45:06 -060071};
Kristian Høgsberg5adb4802012-05-15 22:25:28 -040072
Kristian Høgsberg42abdf52012-05-15 22:14:27 -040073void
Kristian Høgsbergc680e902013-10-23 21:49:30 -070074theme_set_background_source(struct theme *t, cairo_t *cr, uint32_t flags);
75void
Murray Calavera883ac022015-06-06 13:02:22 +000076theme_render_frame(struct theme *t,
Kristian Høgsberg5adb4802012-05-15 22:25:28 -040077 cairo_t *cr, int width, int height,
Boyan Ding850a5142014-08-05 15:22:04 +080078 const char *title, struct wl_list *buttons,
79 uint32_t flags);
Kristian Høgsberg42abdf52012-05-15 22:14:27 -040080
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -040081enum theme_location {
82 THEME_LOCATION_INTERIOR = 0,
83 THEME_LOCATION_RESIZING_TOP = 1,
84 THEME_LOCATION_RESIZING_BOTTOM = 2,
85 THEME_LOCATION_RESIZING_LEFT = 4,
86 THEME_LOCATION_RESIZING_TOP_LEFT = 5,
87 THEME_LOCATION_RESIZING_BOTTOM_LEFT = 6,
88 THEME_LOCATION_RESIZING_RIGHT = 8,
89 THEME_LOCATION_RESIZING_TOP_RIGHT = 9,
90 THEME_LOCATION_RESIZING_BOTTOM_RIGHT = 10,
91 THEME_LOCATION_RESIZING_MASK = 15,
92 THEME_LOCATION_EXTERIOR = 16,
93 THEME_LOCATION_TITLEBAR = 17,
94 THEME_LOCATION_CLIENT_AREA = 18,
95};
96
97enum theme_location
Scott Moreauc6a7e4b2012-09-28 02:45:06 -060098theme_get_location(struct theme *t, int x, int y, int width, int height, int flags);
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -040099
Jason Ekstrand01c9ec32013-10-13 19:08:39 -0500100struct frame;
101
102enum frame_status {
103 FRAME_STATUS_NONE = 0,
104 FRAME_STATUS_REPAINT = 0x1,
105 FRAME_STATUS_MINIMIZE = 0x2,
106 FRAME_STATUS_MAXIMIZE = 0x4,
107 FRAME_STATUS_CLOSE = 0x8,
108 FRAME_STATUS_MENU = 0x10,
109 FRAME_STATUS_RESIZE = 0x20,
110 FRAME_STATUS_MOVE = 0x40,
111 FRAME_STATUS_ALL = 0x7f
112};
113
114enum frame_flag {
115 FRAME_FLAG_ACTIVE = 0x1,
116 FRAME_FLAG_MAXIMIZED = 0x2
117};
118
119enum {
120 FRAME_BUTTON_NONE = 0,
121 FRAME_BUTTON_CLOSE = 0x1,
122 FRAME_BUTTON_MAXIMIZE = 0x2,
123 FRAME_BUTTON_MINIMIZE = 0x4,
124 FRAME_BUTTON_ALL = 0x7
125};
126
Jason Ekstrand01c9ec32013-10-13 19:08:39 -0500127struct frame *
128frame_create(struct theme *t, int32_t width, int32_t height, uint32_t buttons,
129 const char *title);
130
131void
132frame_destroy(struct frame *frame);
133
134/* May set FRAME_STATUS_REPAINT */
135int
136frame_set_title(struct frame *frame, const char *title);
137
138/* May set FRAME_STATUS_REPAINT */
139void
140frame_set_flag(struct frame *frame, enum frame_flag flag);
141
142/* May set FRAME_STATUS_REPAINT */
143void
144frame_unset_flag(struct frame *frame, enum frame_flag flag);
145
146/* May set FRAME_STATUS_REPAINT */
147void
148frame_resize(struct frame *frame, int32_t width, int32_t height);
149
150/* May set FRAME_STATUS_REPAINT */
151void
152frame_resize_inside(struct frame *frame, int32_t width, int32_t height);
153
154int32_t
155frame_width(struct frame *frame);
156
157int32_t
158frame_height(struct frame *frame);
159
160void
161frame_interior(struct frame *frame, int32_t *x, int32_t *y,
162 int32_t *width, int32_t *height);
163void
164frame_input_rect(struct frame *frame, int32_t *x, int32_t *y,
165 int32_t *width, int32_t *height);
166void
167frame_opaque_rect(struct frame *frame, int32_t *x, int32_t *y,
168 int32_t *width, int32_t *height);
169
Jasper St. Pierre74073452014-02-01 18:36:41 -0500170int
171frame_get_shadow_margin(struct frame *frame);
172
Jason Ekstrand01c9ec32013-10-13 19:08:39 -0500173uint32_t
174frame_status(struct frame *frame);
175
176void
177frame_status_clear(struct frame *frame, enum frame_status status);
178
179/* May set FRAME_STATUS_REPAINT */
180enum theme_location
181frame_pointer_enter(struct frame *frame, void *pointer, int x, int y);
182
183/* May set FRAME_STATUS_REPAINT */
184enum theme_location
185frame_pointer_motion(struct frame *frame, void *pointer, int x, int y);
186
187/* May set FRAME_STATUS_REPAINT */
188void
189frame_pointer_leave(struct frame *frame, void *pointer);
190
Jason Ekstrand0bdd58f2013-10-27 22:25:03 -0500191/* Call to indicate that a button has been pressed/released. The return
192 * value for a button release will be the same as for the corresponding
193 * press. This allows you to more easily track grabs. If you want the
194 * actual location, simply keep the location from the last
195 * frame_pointer_motion call.
196 *
197 * May set:
Jason Ekstrand01c9ec32013-10-13 19:08:39 -0500198 * FRAME_STATUS_MINIMIZE
199 * FRAME_STATUS_MAXIMIZE
200 * FRAME_STATUS_CLOSE
201 * FRAME_STATUS_MENU
202 * FRAME_STATUS_RESIZE
203 * FRAME_STATUS_MOVE
204 */
205enum theme_location
206frame_pointer_button(struct frame *frame, void *pointer,
Quentin Glidicd8b17bc2016-07-10 11:00:55 +0200207 uint32_t button, enum wl_pointer_button_state state);
Jason Ekstrand01c9ec32013-10-13 19:08:39 -0500208
Derek Foreman96906412015-11-06 15:56:07 -0600209enum theme_location
Jason Ekstrand3f66cf92013-10-13 19:08:40 -0500210frame_touch_down(struct frame *frame, void *data, int32_t id, int x, int y);
211
212void
213frame_touch_up(struct frame *frame, void *data, int32_t id);
Jason Ekstrand01c9ec32013-10-13 19:08:39 -0500214
Xiong Zhangbfb4ade2014-06-12 11:06:25 +0800215enum theme_location
216frame_double_click(struct frame *frame, void *pointer,
Quentin Glidicd8b17bc2016-07-10 11:00:55 +0200217 uint32_t button, enum wl_pointer_button_state state);
Xiong Zhangbfb4ade2014-06-12 11:06:25 +0800218
Jason Ekstrand01c9ec32013-10-13 19:08:39 -0500219void
Xiong Zhang382de462014-06-12 11:06:26 +0800220frame_double_touch_down(struct frame *frame, void *data, int32_t id,
221 int x, int y);
222
223void
224frame_double_touch_up(struct frame *frame, void *data, int32_t id);
225
226void
Jason Ekstrand01c9ec32013-10-13 19:08:39 -0500227frame_repaint(struct frame *frame, cairo_t *cr);
228
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -0500229#endif