Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 1 | /* |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 2 | * Copyright © 2011, 2012 Intel Corporation |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 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 | |
| 23 | #include <stdint.h> |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
Daniel Stone | 6d4a3c1 | 2012-06-18 19:39:56 +0100 | [diff] [blame] | 27 | #include <unistd.h> |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 28 | #include <sys/wait.h> |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 29 | |
| 30 | #include "window.h" |
Kristian Høgsberg | 5a315bc | 2012-05-15 22:33:43 -0400 | [diff] [blame] | 31 | #include "../shared/cairo-util.h" |
Kristian Høgsberg | 9b935c8 | 2011-12-08 12:44:27 -0500 | [diff] [blame] | 32 | #include "../shared/config-parser.h" |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 33 | |
| 34 | #include "tablet-shell-client-protocol.h" |
| 35 | |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 36 | struct tablet { |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 37 | struct display *display; |
| 38 | struct tablet_shell *tablet_shell; |
| 39 | struct rectangle allocation; |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 40 | struct window *switcher; |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 41 | |
| 42 | struct homescreen *homescreen; |
| 43 | struct lockscreen *lockscreen; |
| 44 | }; |
| 45 | |
| 46 | struct homescreen { |
| 47 | struct window *window; |
| 48 | struct widget *widget; |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 49 | struct wl_list launcher_list; |
| 50 | }; |
| 51 | |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 52 | struct lockscreen { |
| 53 | struct window *window; |
| 54 | struct widget *widget; |
| 55 | }; |
| 56 | |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 57 | struct launcher { |
Alex Wu | 5b72a4d | 2012-06-18 16:52:31 +0800 | [diff] [blame] | 58 | struct widget *widget; |
| 59 | struct homescreen *homescreen; |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 60 | cairo_surface_t *icon; |
Alex Wu | 5b72a4d | 2012-06-18 16:52:31 +0800 | [diff] [blame] | 61 | int focused, pressed; |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 62 | char *path; |
| 63 | struct wl_list link; |
| 64 | }; |
| 65 | |
| 66 | static char *key_lockscreen_icon; |
| 67 | static char *key_lockscreen_background; |
| 68 | static char *key_homescreen_background; |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 69 | |
| 70 | static void |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 71 | sigchild_handler(int s) |
| 72 | { |
| 73 | int status; |
| 74 | pid_t pid; |
| 75 | |
| 76 | while (pid = waitpid(-1, &status, WNOHANG), pid > 0) |
| 77 | fprintf(stderr, "child %d exited\n", pid); |
| 78 | } |
| 79 | |
| 80 | static void |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 81 | paint_background(cairo_t *cr, const char *path, struct rectangle *allocation) |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 82 | { |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 83 | cairo_surface_t *image = NULL; |
| 84 | cairo_pattern_t *pattern; |
| 85 | cairo_matrix_t matrix; |
| 86 | double sx, sy; |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 87 | |
| 88 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 89 | if (path) |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 90 | image = load_cairo_surface(path); |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 91 | if (image) { |
| 92 | pattern = cairo_pattern_create_for_surface(image); |
| 93 | sx = (double) cairo_image_surface_get_width(image) / |
| 94 | allocation->width; |
| 95 | sy = (double) cairo_image_surface_get_height(image) / |
| 96 | allocation->height; |
| 97 | cairo_matrix_init_scale(&matrix, sx, sy); |
| 98 | cairo_pattern_set_matrix(pattern, &matrix); |
| 99 | cairo_set_source(cr, pattern); |
| 100 | cairo_pattern_destroy (pattern); |
| 101 | cairo_surface_destroy(image); |
| 102 | cairo_paint(cr); |
| 103 | } else { |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 104 | fprintf(stderr, "couldn't load background image: %s\n", path); |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 105 | cairo_set_source_rgb(cr, 0.2, 0, 0); |
| 106 | cairo_paint(cr); |
| 107 | } |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 108 | } |
| 109 | |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 110 | static void |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 111 | homescreen_draw(struct widget *widget, void *data) |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 112 | { |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 113 | struct homescreen *homescreen = data; |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 114 | cairo_surface_t *surface; |
| 115 | struct rectangle allocation; |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 116 | cairo_t *cr; |
| 117 | struct launcher *launcher; |
| 118 | const int rows = 4, columns = 5, icon_width = 128, icon_height = 128; |
| 119 | int x, y, i, width, height, vmargin, hmargin, vpadding, hpadding; |
| 120 | |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 121 | surface = window_get_surface(homescreen->window); |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 122 | cr = cairo_create(surface); |
| 123 | |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 124 | widget_get_allocation(widget, &allocation); |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 125 | paint_background(cr, key_homescreen_background, &allocation); |
| 126 | |
| 127 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
| 128 | |
| 129 | width = allocation.width - columns * icon_width; |
| 130 | hpadding = width / (columns + 1); |
| 131 | hmargin = (width - hpadding * (columns - 1)) / 2; |
| 132 | |
| 133 | height = allocation.height - rows * icon_height; |
| 134 | vpadding = height / (rows + 1); |
| 135 | vmargin = (height - vpadding * (rows - 1)) / 2; |
| 136 | |
| 137 | x = hmargin; |
| 138 | y = vmargin; |
| 139 | i = 0; |
| 140 | |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 141 | wl_list_for_each(launcher, &homescreen->launcher_list, link) { |
Alex Wu | 5b72a4d | 2012-06-18 16:52:31 +0800 | [diff] [blame] | 142 | widget_set_allocation(launcher->widget, |
| 143 | x, y, icon_width, icon_height); |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 144 | x += icon_width + hpadding; |
| 145 | i++; |
| 146 | if (i == columns) { |
| 147 | x = hmargin; |
| 148 | y += icon_height + vpadding; |
| 149 | i = 0; |
| 150 | } |
| 151 | } |
| 152 | |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 153 | cairo_destroy(cr); |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 154 | cairo_surface_destroy(surface); |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 155 | } |
| 156 | |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 157 | static void |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 158 | lockscreen_draw(struct widget *widget, void *data) |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 159 | { |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 160 | struct lockscreen *lockscreen = data; |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 161 | cairo_surface_t *surface; |
| 162 | cairo_surface_t *icon; |
| 163 | struct rectangle allocation; |
| 164 | cairo_t *cr; |
| 165 | int width, height; |
| 166 | |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 167 | surface = window_get_surface(lockscreen->window); |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 168 | cr = cairo_create(surface); |
| 169 | |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 170 | widget_get_allocation(widget, &allocation); |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 171 | paint_background(cr, key_lockscreen_background, &allocation); |
| 172 | |
| 173 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 174 | icon = load_cairo_surface(key_lockscreen_icon); |
Tiago Vignatti | d081020 | 2012-03-28 20:56:48 +0300 | [diff] [blame] | 175 | if (icon) { |
| 176 | width = cairo_image_surface_get_width(icon); |
| 177 | height = cairo_image_surface_get_height(icon); |
| 178 | cairo_set_source_surface(cr, icon, |
| 179 | allocation.x + (allocation.width - width) / 2, |
| 180 | allocation.y + (allocation.height - height) / 2); |
| 181 | } else { |
| 182 | fprintf(stderr, "couldn't load lockscreen icon: %s\n", |
| 183 | key_lockscreen_icon); |
| 184 | cairo_set_source_rgb(cr, 0.2, 0, 0); |
| 185 | } |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 186 | cairo_paint(cr); |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 187 | cairo_destroy(cr); |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 188 | cairo_surface_destroy(icon); |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 189 | cairo_surface_destroy(surface); |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | static void |
| 193 | lockscreen_button_handler(struct widget *widget, |
| 194 | struct input *input, uint32_t time, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 195 | uint32_t button, |
| 196 | enum wl_pointer_button_state state, void *data) |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 197 | { |
| 198 | struct lockscreen *lockscreen = data; |
| 199 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 200 | if (state == WL_POINTER_BUTTON_STATE_PRESSED && lockscreen->window) { |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 201 | window_destroy(lockscreen->window); |
| 202 | lockscreen->window = NULL; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | static struct homescreen * |
| 207 | homescreen_create(struct tablet *tablet) |
| 208 | { |
| 209 | struct homescreen *homescreen; |
| 210 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 211 | homescreen = zalloc (sizeof *homescreen); |
Scott Moreau | fe89f07 | 2012-07-11 20:57:15 -0600 | [diff] [blame] | 212 | homescreen->window = window_create_custom(tablet->display); |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 213 | homescreen->widget = |
| 214 | window_add_widget(homescreen->window, homescreen); |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 215 | window_set_user_data(homescreen->window, homescreen); |
| 216 | window_set_title(homescreen->window, "homescreen"); |
| 217 | widget_set_redraw_handler(homescreen->widget, homescreen_draw); |
| 218 | |
| 219 | return homescreen; |
| 220 | } |
| 221 | |
| 222 | static struct lockscreen * |
| 223 | lockscreen_create(struct tablet *tablet) |
| 224 | { |
| 225 | struct lockscreen *lockscreen; |
| 226 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 227 | lockscreen = zalloc (sizeof *lockscreen); |
Scott Moreau | fe89f07 | 2012-07-11 20:57:15 -0600 | [diff] [blame] | 228 | lockscreen->window = window_create_custom(tablet->display); |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 229 | lockscreen->widget = |
| 230 | window_add_widget(lockscreen->window, lockscreen); |
| 231 | window_set_user_data(lockscreen->window, lockscreen); |
| 232 | window_set_title(lockscreen->window, "lockscreen"); |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 233 | widget_set_redraw_handler(lockscreen->widget, lockscreen_draw); |
| 234 | widget_set_button_handler(lockscreen->widget, |
| 235 | lockscreen_button_handler); |
| 236 | |
| 237 | return lockscreen; |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 238 | } |
| 239 | |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 240 | static void |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 241 | show_lockscreen(void *data, struct tablet_shell *tablet_shell) |
| 242 | { |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 243 | struct tablet *tablet = data; |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 244 | |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 245 | tablet->lockscreen = lockscreen_create(tablet); |
| 246 | tablet_shell_set_lockscreen(tablet->tablet_shell, |
| 247 | window_get_wl_surface(tablet->lockscreen->window)); |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 248 | |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 249 | widget_schedule_resize(tablet->lockscreen->widget, |
| 250 | tablet->allocation.width, |
| 251 | tablet->allocation.height); |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | static void |
| 255 | show_switcher(void *data, struct tablet_shell *tablet_shell) |
| 256 | { |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 257 | struct tablet *tablet = data; |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 258 | |
Scott Moreau | fe89f07 | 2012-07-11 20:57:15 -0600 | [diff] [blame] | 259 | tablet->switcher = window_create_custom(tablet->display); |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 260 | window_set_user_data(tablet->switcher, tablet); |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 261 | tablet_shell_set_switcher(tablet->tablet_shell, |
| 262 | window_get_wl_surface(tablet->switcher)); |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | static void |
| 266 | hide_switcher(void *data, struct tablet_shell *tablet_shell) |
| 267 | { |
| 268 | } |
| 269 | |
| 270 | static const struct tablet_shell_listener tablet_shell_listener = { |
| 271 | show_lockscreen, |
| 272 | show_switcher, |
| 273 | hide_switcher |
| 274 | }; |
| 275 | |
Alex Wu | 5b72a4d | 2012-06-18 16:52:31 +0800 | [diff] [blame] | 276 | static int |
| 277 | launcher_enter_handler(struct widget *widget, struct input *input, |
| 278 | float x, float y, void *data) |
| 279 | { |
| 280 | struct launcher *launcher = data; |
| 281 | |
| 282 | launcher->focused = 1; |
| 283 | widget_schedule_redraw(widget); |
| 284 | |
| 285 | return CURSOR_LEFT_PTR; |
| 286 | } |
| 287 | |
| 288 | static void |
| 289 | launcher_leave_handler(struct widget *widget, |
| 290 | struct input *input, void *data) |
| 291 | { |
| 292 | struct launcher *launcher = data; |
| 293 | |
| 294 | launcher->focused = 0; |
| 295 | widget_schedule_redraw(widget); |
| 296 | } |
| 297 | |
| 298 | static void |
| 299 | launcher_activate(struct launcher *widget) |
| 300 | { |
| 301 | pid_t pid; |
| 302 | |
| 303 | pid = fork(); |
| 304 | if (pid < 0) { |
| 305 | fprintf(stderr, "fork failed: %m\n"); |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | if (pid) |
| 310 | return; |
| 311 | |
| 312 | if (execl(widget->path, widget->path, NULL) < 0) { |
| 313 | fprintf(stderr, "execl '%s' failed: %m\n", widget->path); |
| 314 | exit(1); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | static void |
| 319 | launcher_button_handler(struct widget *widget, |
| 320 | struct input *input, uint32_t time, |
| 321 | uint32_t button, |
| 322 | enum wl_pointer_button_state state, void *data) |
| 323 | { |
| 324 | struct launcher *launcher; |
| 325 | |
| 326 | launcher = widget_get_user_data(widget); |
| 327 | widget_schedule_redraw(widget); |
| 328 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 329 | launcher_activate(launcher); |
| 330 | launcher->pressed = 0; |
| 331 | } else if (state == WL_POINTER_BUTTON_STATE_PRESSED) |
| 332 | launcher->pressed = 1; |
| 333 | } |
| 334 | |
| 335 | static void |
| 336 | launcher_redraw_handler(struct widget *widget, void *data) |
| 337 | { |
| 338 | struct launcher *launcher = data; |
| 339 | cairo_surface_t *surface; |
| 340 | struct rectangle allocation; |
| 341 | cairo_t *cr; |
| 342 | |
| 343 | surface = window_get_surface(launcher->homescreen->window); |
| 344 | cr = cairo_create(surface); |
| 345 | |
| 346 | widget_get_allocation(widget, &allocation); |
| 347 | if (launcher->pressed) { |
| 348 | allocation.x++; |
| 349 | allocation.y++; |
| 350 | } |
| 351 | |
| 352 | cairo_set_source_surface(cr, launcher->icon, |
| 353 | allocation.x, allocation.y); |
| 354 | cairo_paint(cr); |
| 355 | |
| 356 | if (launcher->focused) { |
| 357 | cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.4); |
| 358 | cairo_mask_surface(cr, launcher->icon, |
| 359 | allocation.x, allocation.y); |
| 360 | } |
| 361 | |
| 362 | cairo_destroy(cr); |
| 363 | } |
| 364 | |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 365 | static void |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 366 | tablet_shell_add_launcher(struct tablet *tablet, |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 367 | const char *icon, const char *path) |
| 368 | { |
| 369 | struct launcher *launcher; |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 370 | struct homescreen *homescreen = tablet->homescreen; |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 371 | |
Brian Lovin | bc91926 | 2013-08-07 15:34:59 -0700 | [diff] [blame] | 372 | launcher = xmalloc(sizeof *launcher); |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 373 | launcher->icon = load_cairo_surface(icon); |
Juan Zhao | 8634f51 | 2012-06-20 19:29:27 -0700 | [diff] [blame] | 374 | if ( !launcher->icon || |
| 375 | cairo_surface_status (launcher->icon) != CAIRO_STATUS_SUCCESS) { |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 376 | fprintf(stderr, "couldn't load %s\n", icon); |
| 377 | free(launcher); |
| 378 | return; |
| 379 | } |
Rob Bradford | c48c34d | 2013-07-26 16:29:42 +0100 | [diff] [blame] | 380 | launcher->path = strdup(path); |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 381 | |
Alex Wu | 5b72a4d | 2012-06-18 16:52:31 +0800 | [diff] [blame] | 382 | launcher->homescreen = homescreen; |
| 383 | launcher->widget = widget_add_widget(homescreen->widget, launcher); |
| 384 | widget_set_enter_handler(launcher->widget, |
| 385 | launcher_enter_handler); |
| 386 | widget_set_leave_handler(launcher->widget, |
| 387 | launcher_leave_handler); |
| 388 | widget_set_button_handler(launcher->widget, |
| 389 | launcher_button_handler); |
| 390 | widget_set_redraw_handler(launcher->widget, |
| 391 | launcher_redraw_handler); |
| 392 | |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 393 | wl_list_insert(&homescreen->launcher_list, &launcher->link); |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | static void |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 397 | global_handler(struct display *display, uint32_t name, |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 398 | const char *interface, uint32_t version, void *data) |
| 399 | { |
| 400 | struct tablet *tablet = data; |
| 401 | |
| 402 | if (!strcmp(interface, "tablet_shell")) { |
| 403 | tablet->tablet_shell = |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 404 | display_bind(display, name, |
| 405 | &tablet_shell_interface, 1); |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 406 | tablet_shell_add_listener(tablet->tablet_shell, |
| 407 | &tablet_shell_listener, tablet); |
| 408 | } |
| 409 | } |
| 410 | |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 411 | int main(int argc, char *argv[]) |
| 412 | { |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 413 | struct tablet tablet = { 0 }; |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 414 | struct display *display; |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 415 | struct output *output; |
Kristian Høgsberg | b159560 | 2013-09-21 22:35:13 -0700 | [diff] [blame] | 416 | struct weston_config *config; |
| 417 | struct weston_config_section *s; |
| 418 | char *icon, *path; |
| 419 | const char *name; |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 420 | |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 421 | display = display_create(&argc, argv); |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 422 | if (display == NULL) { |
| 423 | fprintf(stderr, "failed to create display: %m\n"); |
| 424 | return -1; |
| 425 | } |
| 426 | |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 427 | tablet.display = display; |
| 428 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 429 | display_set_user_data(tablet.display, &tablet); |
| 430 | display_set_global_handler(tablet.display, global_handler); |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 431 | |
| 432 | tablet.homescreen = homescreen_create(&tablet); |
| 433 | tablet_shell_set_homescreen(tablet.tablet_shell, |
| 434 | window_get_wl_surface(tablet.homescreen->window)); |
Tiago Vignatti | b67c91d | 2013-04-09 11:48:06 -0300 | [diff] [blame] | 435 | |
| 436 | wl_display_roundtrip (display_get_display(tablet.display)); |
| 437 | |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 438 | wl_list_init(&tablet.homescreen->launcher_list); |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 439 | |
Kristian Høgsberg | 1abe048 | 2013-09-21 23:02:31 -0700 | [diff] [blame] | 440 | config = weston_config_parse("weston.ini"); |
Kristian Høgsberg | b159560 | 2013-09-21 22:35:13 -0700 | [diff] [blame] | 441 | s = weston_config_get_section(config, "shell", NULL, NULL); |
| 442 | weston_config_section_get_string(s, "lockscreen-icon", |
| 443 | &key_lockscreen_icon, NULL); |
| 444 | weston_config_section_get_string(s, "lockscreen", |
| 445 | &key_lockscreen_background, NULL); |
| 446 | weston_config_section_get_string(s, "homescreen", |
| 447 | &key_homescreen_background, NULL); |
| 448 | |
| 449 | s = NULL; |
| 450 | while (weston_config_next_section(config, &s, &name)) { |
| 451 | if (strcmp(name, "launcher") != 0) |
| 452 | continue; |
| 453 | |
| 454 | weston_config_section_get_string(s, "icon", &icon, NULL); |
| 455 | weston_config_section_get_string(s, "path", &path, NULL); |
| 456 | |
Kristian Høgsberg | d58e395 | 2013-10-09 13:05:55 -0700 | [diff] [blame^] | 457 | if (icon != NULL && path != NULL) |
| 458 | tablet_shell_add_launcher(&tablet, icon, path); |
| 459 | else |
Kristian Høgsberg | b159560 | 2013-09-21 22:35:13 -0700 | [diff] [blame] | 460 | fprintf(stderr, "invalid launcher section\n"); |
Kristian Høgsberg | b159560 | 2013-09-21 22:35:13 -0700 | [diff] [blame] | 461 | |
Kristian Høgsberg | b159560 | 2013-09-21 22:35:13 -0700 | [diff] [blame] | 462 | free(icon); |
| 463 | free(path); |
| 464 | } |
| 465 | |
| 466 | weston_config_destroy(config); |
| 467 | |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 468 | signal(SIGCHLD, sigchild_handler); |
Kristian Høgsberg | f033a7b | 2011-11-26 23:38:41 -0500 | [diff] [blame] | 469 | |
Tiago Vignatti | 0a38611 | 2012-03-28 13:04:02 +0300 | [diff] [blame] | 470 | output = display_get_output(tablet.display); |
| 471 | output_get_allocation(output, &tablet.allocation); |
| 472 | widget_schedule_resize(tablet.homescreen->widget, |
| 473 | tablet.allocation.width, |
| 474 | tablet.allocation.height); |
Kristian Høgsberg | 6336e46 | 2011-11-26 17:36:23 -0500 | [diff] [blame] | 475 | display_run(display); |
| 476 | |
| 477 | return 0; |
| 478 | } |