Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2008 Kristian Høgsberg |
| 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and its |
| 5 | * documentation for any purpose is hereby granted without fee, provided that |
| 6 | * the above copyright notice appear in all copies and that both that copyright |
| 7 | * notice and this permission notice appear in supporting documentation, and |
| 8 | * that the name of the copyright holders not be used in advertising or |
| 9 | * publicity pertaining to distribution of the software without specific, |
| 10 | * written prior permission. The copyright holders make no representations |
| 11 | * about the suitability of this software for any purpose. It is provided "as |
| 12 | * is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 16 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 17 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 18 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 19 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 20 | * OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
Kristian Høgsberg | 2f2cfae | 2008-11-08 22:46:30 -0500 | [diff] [blame] | 23 | #ifndef _CAIRO_UTIL_H |
| 24 | #define _CAIRO_UTIL_H |
| 25 | |
Jason Ekstrand | 01c9ec3 | 2013-10-13 19:08:39 -0500 | [diff] [blame] | 26 | #include <stdint.h> |
Pekka Paalanen | 4fbb653 | 2012-11-30 13:37:28 +0200 | [diff] [blame] | 27 | #include <cairo.h> |
Kristian Høgsberg | 6006ecb | 2012-11-29 12:23:36 -0500 | [diff] [blame] | 28 | |
Boyan Ding | 850a514 | 2014-08-05 15:22:04 +0800 | [diff] [blame] | 29 | #include <wayland-util.h> |
| 30 | |
Kristian Høgsberg | 2f2cfae | 2008-11-08 22:46:30 -0500 | [diff] [blame] | 31 | void |
Benjamin Franzke | 47eb8f4 | 2011-10-07 09:08:56 +0200 | [diff] [blame] | 32 | surface_flush_device(cairo_surface_t *surface); |
| 33 | |
| 34 | void |
Marek Chalupa | 0d7fe8d | 2014-10-29 14:51:22 +0100 | [diff] [blame] | 35 | render_shadow(cairo_t *cr, cairo_surface_t *surface, |
| 36 | int x, int y, int width, int height, int margin, int top_margin); |
Kristian Høgsberg | dcb71b6 | 2010-06-15 17:16:35 -0400 | [diff] [blame] | 37 | |
| 38 | void |
| 39 | tile_source(cairo_t *cr, cairo_surface_t *surface, |
Kristian Høgsberg | 9a68624 | 2010-08-18 15:28:04 -0400 | [diff] [blame] | 40 | int x, int y, int width, int height, int margin, int top_margin); |
Kristian Høgsberg | dcb71b6 | 2010-06-15 17:16:35 -0400 | [diff] [blame] | 41 | |
Kristian Høgsberg | 1e164b9 | 2011-09-13 14:47:46 -0400 | [diff] [blame] | 42 | void |
| 43 | rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius); |
| 44 | |
Kristian Høgsberg | 27d3866 | 2011-10-20 13:11:12 -0400 | [diff] [blame] | 45 | cairo_surface_t * |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 46 | load_cairo_surface(const char *filename); |
Kristian Høgsberg | 27d3866 | 2011-10-20 13:11:12 -0400 | [diff] [blame] | 47 | |
Kristian Høgsberg | 42abdf5 | 2012-05-15 22:14:27 -0400 | [diff] [blame] | 48 | struct theme { |
| 49 | cairo_surface_t *active_frame; |
| 50 | cairo_surface_t *inactive_frame; |
| 51 | cairo_surface_t *shadow; |
| 52 | int frame_radius; |
| 53 | int margin; |
| 54 | int width; |
| 55 | int titlebar_height; |
| 56 | }; |
| 57 | |
Kristian Høgsberg | 5adb480 | 2012-05-15 22:25:28 -0400 | [diff] [blame] | 58 | struct theme * |
| 59 | theme_create(void); |
Kristian Høgsberg | 42abdf5 | 2012-05-15 22:14:27 -0400 | [diff] [blame] | 60 | void |
Kristian Høgsberg | 5adb480 | 2012-05-15 22:25:28 -0400 | [diff] [blame] | 61 | theme_destroy(struct theme *t); |
| 62 | |
Scott Moreau | c6a7e4b | 2012-09-28 02:45:06 -0600 | [diff] [blame] | 63 | enum { |
| 64 | THEME_FRAME_ACTIVE = 1, |
Kristian Høgsberg | 89f4bc4 | 2013-10-23 22:12:13 -0700 | [diff] [blame] | 65 | THEME_FRAME_MAXIMIZED = 2, |
| 66 | THEME_FRAME_NO_TITLE = 4 |
Scott Moreau | c6a7e4b | 2012-09-28 02:45:06 -0600 | [diff] [blame] | 67 | }; |
Kristian Høgsberg | 5adb480 | 2012-05-15 22:25:28 -0400 | [diff] [blame] | 68 | |
Kristian Høgsberg | 42abdf5 | 2012-05-15 22:14:27 -0400 | [diff] [blame] | 69 | void |
Kristian Høgsberg | c680e90 | 2013-10-23 21:49:30 -0700 | [diff] [blame] | 70 | theme_set_background_source(struct theme *t, cairo_t *cr, uint32_t flags); |
| 71 | void |
Murray Calavera | 883ac02 | 2015-06-06 13:02:22 +0000 | [diff] [blame^] | 72 | theme_render_frame(struct theme *t, |
Kristian Høgsberg | 5adb480 | 2012-05-15 22:25:28 -0400 | [diff] [blame] | 73 | cairo_t *cr, int width, int height, |
Boyan Ding | 850a514 | 2014-08-05 15:22:04 +0800 | [diff] [blame] | 74 | const char *title, struct wl_list *buttons, |
| 75 | uint32_t flags); |
Kristian Høgsberg | 42abdf5 | 2012-05-15 22:14:27 -0400 | [diff] [blame] | 76 | |
Kristian Høgsberg | f96e6c0 | 2012-05-22 16:38:53 -0400 | [diff] [blame] | 77 | enum theme_location { |
| 78 | THEME_LOCATION_INTERIOR = 0, |
| 79 | THEME_LOCATION_RESIZING_TOP = 1, |
| 80 | THEME_LOCATION_RESIZING_BOTTOM = 2, |
| 81 | THEME_LOCATION_RESIZING_LEFT = 4, |
| 82 | THEME_LOCATION_RESIZING_TOP_LEFT = 5, |
| 83 | THEME_LOCATION_RESIZING_BOTTOM_LEFT = 6, |
| 84 | THEME_LOCATION_RESIZING_RIGHT = 8, |
| 85 | THEME_LOCATION_RESIZING_TOP_RIGHT = 9, |
| 86 | THEME_LOCATION_RESIZING_BOTTOM_RIGHT = 10, |
| 87 | THEME_LOCATION_RESIZING_MASK = 15, |
| 88 | THEME_LOCATION_EXTERIOR = 16, |
| 89 | THEME_LOCATION_TITLEBAR = 17, |
| 90 | THEME_LOCATION_CLIENT_AREA = 18, |
| 91 | }; |
| 92 | |
| 93 | enum theme_location |
Scott Moreau | c6a7e4b | 2012-09-28 02:45:06 -0600 | [diff] [blame] | 94 | theme_get_location(struct theme *t, int x, int y, int width, int height, int flags); |
Kristian Høgsberg | f96e6c0 | 2012-05-22 16:38:53 -0400 | [diff] [blame] | 95 | |
Jason Ekstrand | 01c9ec3 | 2013-10-13 19:08:39 -0500 | [diff] [blame] | 96 | struct frame; |
| 97 | |
| 98 | enum frame_status { |
| 99 | FRAME_STATUS_NONE = 0, |
| 100 | FRAME_STATUS_REPAINT = 0x1, |
| 101 | FRAME_STATUS_MINIMIZE = 0x2, |
| 102 | FRAME_STATUS_MAXIMIZE = 0x4, |
| 103 | FRAME_STATUS_CLOSE = 0x8, |
| 104 | FRAME_STATUS_MENU = 0x10, |
| 105 | FRAME_STATUS_RESIZE = 0x20, |
| 106 | FRAME_STATUS_MOVE = 0x40, |
| 107 | FRAME_STATUS_ALL = 0x7f |
| 108 | }; |
| 109 | |
| 110 | enum frame_flag { |
| 111 | FRAME_FLAG_ACTIVE = 0x1, |
| 112 | FRAME_FLAG_MAXIMIZED = 0x2 |
| 113 | }; |
| 114 | |
| 115 | enum { |
| 116 | FRAME_BUTTON_NONE = 0, |
| 117 | FRAME_BUTTON_CLOSE = 0x1, |
| 118 | FRAME_BUTTON_MAXIMIZE = 0x2, |
| 119 | FRAME_BUTTON_MINIMIZE = 0x4, |
| 120 | FRAME_BUTTON_ALL = 0x7 |
| 121 | }; |
| 122 | |
| 123 | enum frame_button_state { |
| 124 | FRAME_BUTTON_RELEASED = 0, |
| 125 | FRAME_BUTTON_PRESSED = 1 |
| 126 | }; |
| 127 | |
| 128 | struct frame * |
| 129 | frame_create(struct theme *t, int32_t width, int32_t height, uint32_t buttons, |
| 130 | const char *title); |
| 131 | |
| 132 | void |
| 133 | frame_destroy(struct frame *frame); |
| 134 | |
| 135 | /* May set FRAME_STATUS_REPAINT */ |
| 136 | int |
| 137 | frame_set_title(struct frame *frame, const char *title); |
| 138 | |
| 139 | /* May set FRAME_STATUS_REPAINT */ |
| 140 | void |
| 141 | frame_set_flag(struct frame *frame, enum frame_flag flag); |
| 142 | |
| 143 | /* May set FRAME_STATUS_REPAINT */ |
| 144 | void |
| 145 | frame_unset_flag(struct frame *frame, enum frame_flag flag); |
| 146 | |
| 147 | /* May set FRAME_STATUS_REPAINT */ |
| 148 | void |
| 149 | frame_resize(struct frame *frame, int32_t width, int32_t height); |
| 150 | |
| 151 | /* May set FRAME_STATUS_REPAINT */ |
| 152 | void |
| 153 | frame_resize_inside(struct frame *frame, int32_t width, int32_t height); |
| 154 | |
| 155 | int32_t |
| 156 | frame_width(struct frame *frame); |
| 157 | |
| 158 | int32_t |
| 159 | frame_height(struct frame *frame); |
| 160 | |
| 161 | void |
| 162 | frame_interior(struct frame *frame, int32_t *x, int32_t *y, |
| 163 | int32_t *width, int32_t *height); |
| 164 | void |
| 165 | frame_input_rect(struct frame *frame, int32_t *x, int32_t *y, |
| 166 | int32_t *width, int32_t *height); |
| 167 | void |
| 168 | frame_opaque_rect(struct frame *frame, int32_t *x, int32_t *y, |
| 169 | int32_t *width, int32_t *height); |
| 170 | |
Jasper St. Pierre | 7407345 | 2014-02-01 18:36:41 -0500 | [diff] [blame] | 171 | int |
| 172 | frame_get_shadow_margin(struct frame *frame); |
| 173 | |
Jason Ekstrand | 01c9ec3 | 2013-10-13 19:08:39 -0500 | [diff] [blame] | 174 | uint32_t |
| 175 | frame_status(struct frame *frame); |
| 176 | |
| 177 | void |
| 178 | frame_status_clear(struct frame *frame, enum frame_status status); |
| 179 | |
| 180 | /* May set FRAME_STATUS_REPAINT */ |
| 181 | enum theme_location |
| 182 | frame_pointer_enter(struct frame *frame, void *pointer, int x, int y); |
| 183 | |
| 184 | /* May set FRAME_STATUS_REPAINT */ |
| 185 | enum theme_location |
| 186 | frame_pointer_motion(struct frame *frame, void *pointer, int x, int y); |
| 187 | |
| 188 | /* May set FRAME_STATUS_REPAINT */ |
| 189 | void |
| 190 | frame_pointer_leave(struct frame *frame, void *pointer); |
| 191 | |
Jason Ekstrand | 0bdd58f | 2013-10-27 22:25:03 -0500 | [diff] [blame] | 192 | /* Call to indicate that a button has been pressed/released. The return |
| 193 | * value for a button release will be the same as for the corresponding |
| 194 | * press. This allows you to more easily track grabs. If you want the |
| 195 | * actual location, simply keep the location from the last |
| 196 | * frame_pointer_motion call. |
| 197 | * |
| 198 | * May set: |
Jason Ekstrand | 01c9ec3 | 2013-10-13 19:08:39 -0500 | [diff] [blame] | 199 | * FRAME_STATUS_MINIMIZE |
| 200 | * FRAME_STATUS_MAXIMIZE |
| 201 | * FRAME_STATUS_CLOSE |
| 202 | * FRAME_STATUS_MENU |
| 203 | * FRAME_STATUS_RESIZE |
| 204 | * FRAME_STATUS_MOVE |
| 205 | */ |
| 206 | enum theme_location |
| 207 | frame_pointer_button(struct frame *frame, void *pointer, |
| 208 | uint32_t button, enum frame_button_state state); |
| 209 | |
Jason Ekstrand | 3f66cf9 | 2013-10-13 19:08:40 -0500 | [diff] [blame] | 210 | void |
| 211 | frame_touch_down(struct frame *frame, void *data, int32_t id, int x, int y); |
| 212 | |
| 213 | void |
| 214 | frame_touch_up(struct frame *frame, void *data, int32_t id); |
Jason Ekstrand | 01c9ec3 | 2013-10-13 19:08:39 -0500 | [diff] [blame] | 215 | |
Xiong Zhang | bfb4ade | 2014-06-12 11:06:25 +0800 | [diff] [blame] | 216 | enum theme_location |
| 217 | frame_double_click(struct frame *frame, void *pointer, |
| 218 | uint32_t button, enum frame_button_state state); |
| 219 | |
Jason Ekstrand | 01c9ec3 | 2013-10-13 19:08:39 -0500 | [diff] [blame] | 220 | void |
Xiong Zhang | 382de46 | 2014-06-12 11:06:26 +0800 | [diff] [blame] | 221 | frame_double_touch_down(struct frame *frame, void *data, int32_t id, |
| 222 | int x, int y); |
| 223 | |
| 224 | void |
| 225 | frame_double_touch_up(struct frame *frame, void *data, int32_t id); |
| 226 | |
| 227 | void |
Jason Ekstrand | 01c9ec3 | 2013-10-13 19:08:39 -0500 | [diff] [blame] | 228 | frame_repaint(struct frame *frame, cairo_t *cr); |
| 229 | |
Kristian Høgsberg | 2f2cfae | 2008-11-08 22:46:30 -0500 | [diff] [blame] | 230 | #endif |