Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011 Kristian Høgsberg |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 3 | * Copyright © 2011 Collabora, Ltd. |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 4 | * |
| 5 | * Permission to use, copy, modify, distribute, and sell this software and its |
| 6 | * documentation for any purpose is hereby granted without fee, provided that |
| 7 | * the above copyright notice appear in all copies and that both that copyright |
| 8 | * notice and this permission notice appear in supporting documentation, and |
| 9 | * that the name of the copyright holders not be used in advertising or |
| 10 | * publicity pertaining to distribution of the software without specific, |
| 11 | * written prior permission. The copyright holders make no representations |
| 12 | * about the suitability of this software for any purpose. It is provided "as |
| 13 | * is" without express or implied warranty. |
| 14 | * |
| 15 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 16 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 17 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 18 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 19 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 20 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 21 | * OF THIS SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #include <stdint.h> |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <fcntl.h> |
| 29 | #include <unistd.h> |
| 30 | #include <math.h> |
| 31 | #include <cairo.h> |
| 32 | #include <sys/wait.h> |
| 33 | #include <linux/input.h> |
Tiago Vignatti | 6150072 | 2012-05-23 22:06:28 +0300 | [diff] [blame^] | 34 | #include <libgen.h> |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 35 | |
Pekka Paalanen | 50719bc | 2011-11-22 14:18:50 +0200 | [diff] [blame] | 36 | #include <wayland-client.h> |
Ander Conselvan de Oliveira | 1042dc1 | 2012-05-22 15:39:42 +0300 | [diff] [blame] | 37 | #include <wayland-cursor.h> |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 38 | #include "window.h" |
Kristian Høgsberg | 5a315bc | 2012-05-15 22:33:43 -0400 | [diff] [blame] | 39 | #include "../shared/cairo-util.h" |
Kristian Høgsberg | 9b935c8 | 2011-12-08 12:44:27 -0500 | [diff] [blame] | 40 | #include "../shared/config-parser.h" |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 41 | |
Pekka Paalanen | 50719bc | 2011-11-22 14:18:50 +0200 | [diff] [blame] | 42 | #include "desktop-shell-client-protocol.h" |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 43 | |
| 44 | struct desktop { |
| 45 | struct display *display; |
| 46 | struct desktop_shell *shell; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 47 | struct unlock_dialog *unlock_dialog; |
| 48 | struct task unlock_task; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 49 | struct wl_list outputs; |
| 50 | }; |
| 51 | |
| 52 | struct surface { |
| 53 | void (*configure)(void *data, |
| 54 | struct desktop_shell *desktop_shell, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 55 | uint32_t edges, struct window *window, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 56 | int32_t width, int32_t height); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | struct panel { |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 60 | struct surface base; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 61 | struct window *window; |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 62 | struct widget *widget; |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 63 | struct wl_list launcher_list; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 64 | }; |
| 65 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 66 | struct background { |
| 67 | struct surface base; |
| 68 | struct window *window; |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 69 | struct widget *widget; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | struct output { |
| 73 | struct wl_output *output; |
| 74 | struct wl_list link; |
| 75 | |
| 76 | struct panel *panel; |
| 77 | struct background *background; |
| 78 | }; |
| 79 | |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 80 | struct panel_launcher { |
Kristian Høgsberg | c51f799 | 2012-01-08 15:09:53 -0500 | [diff] [blame] | 81 | struct widget *widget; |
Kristian Høgsberg | e28d05b | 2011-09-20 21:43:54 -0400 | [diff] [blame] | 82 | struct panel *panel; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 83 | cairo_surface_t *icon; |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 84 | int focused, pressed; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 85 | const char *path; |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 86 | struct wl_list link; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 87 | }; |
| 88 | |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 89 | struct unlock_dialog { |
| 90 | struct window *window; |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 91 | struct widget *widget; |
Kristian Høgsberg | c51f799 | 2012-01-08 15:09:53 -0500 | [diff] [blame] | 92 | struct widget *button; |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 93 | int button_focused; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 94 | int closing; |
| 95 | |
| 96 | struct desktop *desktop; |
| 97 | }; |
| 98 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 99 | static char *key_background_image = DATADIR "/weston/pattern.png"; |
| 100 | static char *key_background_type = "tile"; |
| 101 | static uint32_t key_panel_color = 0xaa000000; |
| 102 | static uint32_t key_background_color = 0xff002244; |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 103 | static char *key_launcher_icon; |
| 104 | static char *key_launcher_path; |
| 105 | static void launcher_section_done(void *data); |
Pekka Paalanen | fd83b6d | 2011-12-08 10:06:53 +0200 | [diff] [blame] | 106 | static int key_locking = 1; |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 107 | |
| 108 | static const struct config_key shell_config_keys[] = { |
| 109 | { "background-image", CONFIG_KEY_STRING, &key_background_image }, |
Kristian Høgsberg | 07f7294 | 2012-01-25 16:34:36 -0500 | [diff] [blame] | 110 | { "background-type", CONFIG_KEY_STRING, &key_background_type }, |
Scott Moreau | fa1de69 | 2012-01-27 13:25:49 -0700 | [diff] [blame] | 111 | { "panel-color", CONFIG_KEY_UNSIGNED_INTEGER, &key_panel_color }, |
| 112 | { "background-color", CONFIG_KEY_UNSIGNED_INTEGER, &key_background_color }, |
Pekka Paalanen | fd83b6d | 2011-12-08 10:06:53 +0200 | [diff] [blame] | 113 | { "locking", CONFIG_KEY_BOOLEAN, &key_locking }, |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | static const struct config_key launcher_config_keys[] = { |
| 117 | { "icon", CONFIG_KEY_STRING, &key_launcher_icon }, |
| 118 | { "path", CONFIG_KEY_STRING, &key_launcher_path }, |
| 119 | }; |
| 120 | |
| 121 | static const struct config_section config_sections[] = { |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 122 | { "shell", |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 123 | shell_config_keys, ARRAY_LENGTH(shell_config_keys) }, |
| 124 | { "launcher", |
| 125 | launcher_config_keys, ARRAY_LENGTH(launcher_config_keys), |
| 126 | launcher_section_done } |
| 127 | }; |
| 128 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 129 | static void |
| 130 | sigchild_handler(int s) |
| 131 | { |
| 132 | int status; |
| 133 | pid_t pid; |
| 134 | |
| 135 | while (pid = waitpid(-1, &status, WNOHANG), pid > 0) |
| 136 | fprintf(stderr, "child %d exited\n", pid); |
| 137 | } |
| 138 | |
| 139 | static void |
Pekka Paalanen | 9e30a82 | 2012-01-19 16:40:28 +0200 | [diff] [blame] | 140 | menu_func(struct window *window, int index, void *data) |
| 141 | { |
| 142 | printf("Selected index %d from a panel menu.\n", index); |
| 143 | } |
| 144 | |
| 145 | static void |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 146 | show_menu(struct panel *panel, struct input *input, uint32_t time) |
Kristian Høgsberg | bcee9a4 | 2011-10-12 00:36:16 -0400 | [diff] [blame] | 147 | { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 148 | int32_t x, y; |
| 149 | static const char *entries[] = { |
| 150 | "Roy", "Pris", "Leon", "Zhora" |
| 151 | }; |
Kristian Høgsberg | bcee9a4 | 2011-10-12 00:36:16 -0400 | [diff] [blame] | 152 | |
| 153 | input_get_position(input, &x, &y); |
Pekka Paalanen | 6d174cf | 2012-01-19 15:17:59 +0200 | [diff] [blame] | 154 | window_show_menu(window_get_display(panel->window), |
| 155 | input, time, panel->window, |
Pekka Paalanen | 9e30a82 | 2012-01-19 16:40:28 +0200 | [diff] [blame] | 156 | x - 10, y - 10, menu_func, entries, 4); |
Kristian Høgsberg | bcee9a4 | 2011-10-12 00:36:16 -0400 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | static void |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 160 | panel_launcher_activate(struct panel_launcher *widget) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 161 | { |
| 162 | pid_t pid; |
| 163 | |
| 164 | pid = fork(); |
| 165 | if (pid < 0) { |
| 166 | fprintf(stderr, "fork failed: %m\n"); |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | if (pid) |
| 171 | return; |
Benjamin Franzke | d775971 | 2011-11-22 12:38:48 +0100 | [diff] [blame] | 172 | |
Kristian Høgsberg | c51f799 | 2012-01-08 15:09:53 -0500 | [diff] [blame] | 173 | if (execl(widget->path, widget->path, NULL) < 0) { |
Pekka Paalanen | a291ae5 | 2012-01-27 09:50:02 +0200 | [diff] [blame] | 174 | fprintf(stderr, "execl '%s' failed: %m\n", widget->path); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 175 | exit(1); |
| 176 | } |
| 177 | } |
| 178 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 179 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 180 | panel_launcher_redraw_handler(struct widget *widget, void *data) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 181 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 182 | struct panel_launcher *launcher = data; |
| 183 | cairo_surface_t *surface; |
| 184 | struct rectangle allocation; |
| 185 | cairo_t *cr; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 186 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 187 | surface = window_get_surface(launcher->panel->window); |
| 188 | cr = cairo_create(surface); |
| 189 | |
| 190 | widget_get_allocation(widget, &allocation); |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 191 | if (launcher->pressed) { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 192 | allocation.x++; |
| 193 | allocation.y++; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 194 | } |
| 195 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 196 | cairo_set_source_surface(cr, launcher->icon, |
| 197 | allocation.x, allocation.y); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 198 | cairo_paint(cr); |
| 199 | |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 200 | if (launcher->focused) { |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 201 | cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.4); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 202 | cairo_mask_surface(cr, launcher->icon, |
| 203 | allocation.x, allocation.y); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 204 | } |
Kristian Høgsberg | e28d05b | 2011-09-20 21:43:54 -0400 | [diff] [blame] | 205 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 206 | cairo_destroy(cr); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 207 | } |
| 208 | |
Tiago Vignatti | 6150072 | 2012-05-23 22:06:28 +0300 | [diff] [blame^] | 209 | static int |
| 210 | panel_launcher_motion_handler(struct widget *widget, struct input *input, |
| 211 | uint32_t time, float x, float y, void *data) |
| 212 | { |
| 213 | struct panel_launcher *launcher = data; |
| 214 | |
| 215 | widget_set_tooltip(widget, basename((char *)launcher->path), x, y); |
| 216 | |
| 217 | return POINTER_LEFT_PTR; |
| 218 | } |
| 219 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 220 | static void |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 221 | set_hex_color(cairo_t *cr, uint32_t color) |
| 222 | { |
| 223 | cairo_set_source_rgba(cr, |
| 224 | ((color >> 16) & 0xff) / 255.0, |
| 225 | ((color >> 8) & 0xff) / 255.0, |
| 226 | ((color >> 0) & 0xff) / 255.0, |
| 227 | ((color >> 24) & 0xff) / 255.0); |
| 228 | } |
| 229 | |
| 230 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 231 | panel_redraw_handler(struct widget *widget, void *data) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 232 | { |
| 233 | cairo_surface_t *surface; |
| 234 | cairo_t *cr; |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 235 | struct panel *panel = data; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 236 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 237 | surface = window_get_surface(panel->window); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 238 | cr = cairo_create(surface); |
| 239 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 240 | set_hex_color(cr, key_panel_color); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 241 | cairo_paint(cr); |
| 242 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 243 | cairo_destroy(cr); |
| 244 | cairo_surface_destroy(surface); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 245 | } |
| 246 | |
Kristian Høgsberg | bb901fa | 2012-01-09 11:22:32 -0500 | [diff] [blame] | 247 | static int |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 248 | panel_launcher_enter_handler(struct widget *widget, struct input *input, |
Kristian Høgsberg | 80680c7 | 2012-05-10 12:21:37 -0400 | [diff] [blame] | 249 | float x, float y, void *data) |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 250 | { |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 251 | struct panel_launcher *launcher = data; |
| 252 | |
| 253 | launcher->focused = 1; |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 254 | widget_schedule_redraw(widget); |
Kristian Høgsberg | bb901fa | 2012-01-09 11:22:32 -0500 | [diff] [blame] | 255 | |
Ander Conselvan de Oliveira | 1042dc1 | 2012-05-22 15:39:42 +0300 | [diff] [blame] | 256 | return WL_CURSOR_LEFT_PTR; |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | static void |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 260 | panel_launcher_leave_handler(struct widget *widget, |
| 261 | struct input *input, void *data) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 262 | { |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 263 | struct panel_launcher *launcher = data; |
| 264 | |
| 265 | launcher->focused = 0; |
Tiago Vignatti | 6150072 | 2012-05-23 22:06:28 +0300 | [diff] [blame^] | 266 | widget_destroy_tooltip(widget); |
Kristian Høgsberg | 9a13dab | 2012-01-08 15:18:19 -0500 | [diff] [blame] | 267 | widget_schedule_redraw(widget); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | static void |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 271 | panel_launcher_button_handler(struct widget *widget, |
| 272 | struct input *input, uint32_t time, |
Daniel Stone | 5d66371 | 2012-05-04 11:21:55 +0100 | [diff] [blame] | 273 | uint32_t button, uint32_t state, void *data) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 274 | { |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 275 | struct panel_launcher *launcher; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 276 | |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 277 | launcher = widget_get_user_data(widget); |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 278 | widget_schedule_redraw(widget); |
| 279 | if (state == 0) |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 280 | panel_launcher_activate(launcher); |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | static void |
| 284 | panel_button_handler(struct widget *widget, |
| 285 | struct input *input, uint32_t time, |
Daniel Stone | 5d66371 | 2012-05-04 11:21:55 +0100 | [diff] [blame] | 286 | uint32_t button, uint32_t state, void *data) |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 287 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 288 | struct panel *panel = data; |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 289 | |
| 290 | if (button == BTN_RIGHT && state) |
| 291 | show_menu(panel, input, time); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 292 | } |
| 293 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 294 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 295 | panel_resize_handler(struct widget *widget, |
| 296 | int32_t width, int32_t height, void *data) |
| 297 | { |
| 298 | struct panel_launcher *launcher; |
| 299 | struct panel *panel = data; |
| 300 | int x, y, w, h; |
| 301 | |
| 302 | x = 10; |
| 303 | y = 16; |
| 304 | wl_list_for_each(launcher, &panel->launcher_list, link) { |
| 305 | w = cairo_image_surface_get_width(launcher->icon); |
| 306 | h = cairo_image_surface_get_height(launcher->icon); |
| 307 | widget_set_allocation(launcher->widget, |
| 308 | x, y - h / 2, w + 1, h + 1); |
| 309 | x += w + 10; |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | static void |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 314 | panel_configure(void *data, |
| 315 | struct desktop_shell *desktop_shell, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 316 | uint32_t edges, struct window *window, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 317 | int32_t width, int32_t height) |
| 318 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 319 | struct surface *surface = window_get_user_data(window); |
| 320 | struct panel *panel = container_of(surface, struct panel, base); |
| 321 | |
| 322 | window_schedule_resize(panel->window, width, 32); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 323 | } |
| 324 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 325 | static struct panel * |
| 326 | panel_create(struct display *display) |
| 327 | { |
| 328 | struct panel *panel; |
| 329 | |
| 330 | panel = malloc(sizeof *panel); |
| 331 | memset(panel, 0, sizeof *panel); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 332 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 333 | panel->base.configure = panel_configure; |
Kristian Høgsberg | 009ac0a | 2012-01-31 15:24:48 -0500 | [diff] [blame] | 334 | panel->window = window_create(display); |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 335 | panel->widget = window_add_widget(panel->window, panel); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 336 | wl_list_init(&panel->launcher_list); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 337 | |
| 338 | window_set_title(panel->window, "panel"); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 339 | window_set_custom(panel->window); |
| 340 | window_set_user_data(panel->window, panel); |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 341 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 342 | widget_set_redraw_handler(panel->widget, panel_redraw_handler); |
| 343 | widget_set_resize_handler(panel->widget, panel_resize_handler); |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 344 | widget_set_button_handler(panel->widget, panel_button_handler); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 345 | |
| 346 | return panel; |
| 347 | } |
| 348 | |
| 349 | static void |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 350 | panel_add_launcher(struct panel *panel, const char *icon, const char *path) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 351 | { |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 352 | struct panel_launcher *launcher; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 353 | |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 354 | launcher = malloc(sizeof *launcher); |
| 355 | memset(launcher, 0, sizeof *launcher); |
| 356 | launcher->icon = cairo_image_surface_create_from_png(icon); |
| 357 | launcher->path = strdup(path); |
| 358 | launcher->panel = panel; |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 359 | wl_list_insert(panel->launcher_list.prev, &launcher->link); |
| 360 | |
Kristian Høgsberg | 441338c | 2012-01-10 13:52:34 -0500 | [diff] [blame] | 361 | launcher->widget = widget_add_widget(panel->widget, launcher); |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 362 | widget_set_enter_handler(launcher->widget, |
| 363 | panel_launcher_enter_handler); |
| 364 | widget_set_leave_handler(launcher->widget, |
| 365 | panel_launcher_leave_handler); |
| 366 | widget_set_button_handler(launcher->widget, |
| 367 | panel_launcher_button_handler); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 368 | widget_set_redraw_handler(launcher->widget, |
| 369 | panel_launcher_redraw_handler); |
Tiago Vignatti | 6150072 | 2012-05-23 22:06:28 +0300 | [diff] [blame^] | 370 | widget_set_motion_handler(launcher->widget, |
| 371 | panel_launcher_motion_handler); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 372 | } |
| 373 | |
Kristian Høgsberg | 07f7294 | 2012-01-25 16:34:36 -0500 | [diff] [blame] | 374 | enum { |
| 375 | BACKGROUND_SCALE, |
| 376 | BACKGROUND_TILE |
| 377 | }; |
| 378 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 379 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 380 | background_draw(struct widget *widget, void *data) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 381 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 382 | struct background *background = data; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 383 | cairo_surface_t *surface, *image; |
Kristian Høgsberg | 7e69000 | 2011-09-08 18:18:02 -0400 | [diff] [blame] | 384 | cairo_pattern_t *pattern; |
| 385 | cairo_matrix_t matrix; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 386 | cairo_t *cr; |
Kristian Høgsberg | 7e69000 | 2011-09-08 18:18:02 -0400 | [diff] [blame] | 387 | double sx, sy; |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 388 | struct rectangle allocation; |
Kristian Høgsberg | 07f7294 | 2012-01-25 16:34:36 -0500 | [diff] [blame] | 389 | int type = -1; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 390 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 391 | surface = window_get_surface(background->window); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 392 | |
| 393 | cr = cairo_create(surface); |
| 394 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
| 395 | cairo_set_source_rgba(cr, 0.0, 0.0, 0.2, 1.0); |
| 396 | cairo_paint(cr); |
| 397 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 398 | widget_get_allocation(widget, &allocation); |
Kristian Høgsberg | 8129bc0 | 2012-01-25 14:55:33 -0500 | [diff] [blame] | 399 | image = NULL; |
| 400 | if (key_background_image) |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 401 | image = load_cairo_surface(key_background_image); |
Kristian Høgsberg | 07f7294 | 2012-01-25 16:34:36 -0500 | [diff] [blame] | 402 | |
| 403 | if (strcmp(key_background_type, "scale") == 0) |
| 404 | type = BACKGROUND_SCALE; |
| 405 | else if (strcmp(key_background_type, "tile") == 0) |
| 406 | type = BACKGROUND_TILE; |
| 407 | else |
| 408 | fprintf(stderr, "invalid background-type: %s\n", |
| 409 | key_background_type); |
| 410 | |
| 411 | if (image && type != -1) { |
Kristian Høgsberg | 7e69000 | 2011-09-08 18:18:02 -0400 | [diff] [blame] | 412 | pattern = cairo_pattern_create_for_surface(image); |
Kristian Høgsberg | 07f7294 | 2012-01-25 16:34:36 -0500 | [diff] [blame] | 413 | switch (type) { |
| 414 | case BACKGROUND_SCALE: |
| 415 | sx = (double) cairo_image_surface_get_width(image) / |
| 416 | allocation.width; |
| 417 | sy = (double) cairo_image_surface_get_height(image) / |
| 418 | allocation.height; |
| 419 | cairo_matrix_init_scale(&matrix, sx, sy); |
| 420 | cairo_pattern_set_matrix(pattern, &matrix); |
| 421 | break; |
| 422 | case BACKGROUND_TILE: |
| 423 | cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); |
| 424 | break; |
| 425 | } |
Kristian Høgsberg | 7e69000 | 2011-09-08 18:18:02 -0400 | [diff] [blame] | 426 | cairo_set_source(cr, pattern); |
| 427 | cairo_pattern_destroy (pattern); |
Kristian Høgsberg | 27d3866 | 2011-10-20 13:11:12 -0400 | [diff] [blame] | 428 | cairo_surface_destroy(image); |
Kristian Høgsberg | 8129bc0 | 2012-01-25 14:55:33 -0500 | [diff] [blame] | 429 | } else { |
| 430 | set_hex_color(cr, key_background_color); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 431 | } |
| 432 | |
Kristian Høgsberg | 8129bc0 | 2012-01-25 14:55:33 -0500 | [diff] [blame] | 433 | cairo_paint(cr); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 434 | cairo_destroy(cr); |
| 435 | cairo_surface_destroy(surface); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | static void |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 439 | background_configure(void *data, |
| 440 | struct desktop_shell *desktop_shell, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 441 | uint32_t edges, struct window *window, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 442 | int32_t width, int32_t height) |
| 443 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 444 | struct background *background = |
| 445 | (struct background *) window_get_user_data(window); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 446 | |
Kristian Høgsberg | bb97700 | 2012-01-10 19:11:42 -0500 | [diff] [blame] | 447 | widget_schedule_resize(background->widget, width, height); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 451 | unlock_dialog_redraw_handler(struct widget *widget, void *data) |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 452 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 453 | struct unlock_dialog *dialog = data; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 454 | struct rectangle allocation; |
| 455 | cairo_t *cr; |
| 456 | cairo_surface_t *surface; |
| 457 | cairo_pattern_t *pat; |
| 458 | double cx, cy, r, f; |
| 459 | |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 460 | surface = window_get_surface(dialog->window); |
| 461 | cr = cairo_create(surface); |
Kristian Høgsberg | 41c5c4e | 2012-03-05 20:37:51 -0500 | [diff] [blame] | 462 | |
Kristian Høgsberg | bb97700 | 2012-01-10 19:11:42 -0500 | [diff] [blame] | 463 | widget_get_allocation(dialog->widget, &allocation); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 464 | cairo_rectangle(cr, allocation.x, allocation.y, |
| 465 | allocation.width, allocation.height); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 466 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
| 467 | cairo_set_source_rgba(cr, 0, 0, 0, 0.6); |
Kristian Høgsberg | 41c5c4e | 2012-03-05 20:37:51 -0500 | [diff] [blame] | 468 | cairo_fill(cr); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 469 | |
Kristian Høgsberg | 41c5c4e | 2012-03-05 20:37:51 -0500 | [diff] [blame] | 470 | cairo_translate(cr, allocation.x, allocation.y); |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 471 | if (dialog->button_focused) |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 472 | f = 1.0; |
| 473 | else |
| 474 | f = 0.7; |
| 475 | |
| 476 | cx = allocation.width / 2.0; |
| 477 | cy = allocation.height / 2.0; |
| 478 | r = (cx < cy ? cx : cy) * 0.4; |
| 479 | pat = cairo_pattern_create_radial(cx, cy, r * 0.7, cx, cy, r); |
| 480 | cairo_pattern_add_color_stop_rgb(pat, 0.0, 0, 0.86 * f, 0); |
| 481 | cairo_pattern_add_color_stop_rgb(pat, 0.85, 0.2 * f, f, 0.2 * f); |
| 482 | cairo_pattern_add_color_stop_rgb(pat, 1.0, 0, 0.86 * f, 0); |
| 483 | cairo_set_source(cr, pat); |
Kristian Høgsberg | 41c5c4e | 2012-03-05 20:37:51 -0500 | [diff] [blame] | 484 | cairo_pattern_destroy(pat); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 485 | cairo_arc(cr, cx, cy, r, 0.0, 2.0 * M_PI); |
| 486 | cairo_fill(cr); |
| 487 | |
Kristian Høgsberg | c51f799 | 2012-01-08 15:09:53 -0500 | [diff] [blame] | 488 | widget_set_allocation(dialog->button, |
Kristian Høgsberg | 41c5c4e | 2012-03-05 20:37:51 -0500 | [diff] [blame] | 489 | allocation.x + cx - r, |
| 490 | allocation.y + cy - r, 2 * r, 2 * r); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 491 | |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 492 | cairo_destroy(cr); |
| 493 | |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 494 | cairo_surface_destroy(surface); |
| 495 | } |
| 496 | |
| 497 | static void |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 498 | unlock_dialog_button_handler(struct widget *widget, |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 499 | struct input *input, uint32_t time, |
Daniel Stone | 5d66371 | 2012-05-04 11:21:55 +0100 | [diff] [blame] | 500 | uint32_t button, uint32_t state, void *data) |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 501 | { |
| 502 | struct unlock_dialog *dialog = data; |
| 503 | struct desktop *desktop = dialog->desktop; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 504 | |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 505 | if (button == BTN_LEFT) { |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 506 | if (state == 0 && !dialog->closing) { |
| 507 | display_defer(desktop->display, &desktop->unlock_task); |
| 508 | dialog->closing = 1; |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | static void |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 514 | unlock_dialog_keyboard_focus_handler(struct window *window, |
| 515 | struct input *device, void *data) |
| 516 | { |
| 517 | window_schedule_redraw(window); |
| 518 | } |
| 519 | |
Kristian Høgsberg | bb901fa | 2012-01-09 11:22:32 -0500 | [diff] [blame] | 520 | static int |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 521 | unlock_dialog_widget_enter_handler(struct widget *widget, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 522 | struct input *input, |
Kristian Høgsberg | 80680c7 | 2012-05-10 12:21:37 -0400 | [diff] [blame] | 523 | float x, float y, void *data) |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 524 | { |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 525 | struct unlock_dialog *dialog = data; |
| 526 | |
| 527 | dialog->button_focused = 1; |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 528 | widget_schedule_redraw(widget); |
Kristian Høgsberg | bb901fa | 2012-01-09 11:22:32 -0500 | [diff] [blame] | 529 | |
Ander Conselvan de Oliveira | 1042dc1 | 2012-05-22 15:39:42 +0300 | [diff] [blame] | 530 | return WL_CURSOR_LEFT_PTR; |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | static void |
| 534 | unlock_dialog_widget_leave_handler(struct widget *widget, |
| 535 | struct input *input, void *data) |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 536 | { |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 537 | struct unlock_dialog *dialog = data; |
| 538 | |
| 539 | dialog->button_focused = 0; |
Kristian Høgsberg | 9a13dab | 2012-01-08 15:18:19 -0500 | [diff] [blame] | 540 | widget_schedule_redraw(widget); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | static struct unlock_dialog * |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 544 | unlock_dialog_create(struct desktop *desktop) |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 545 | { |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 546 | struct display *display = desktop->display; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 547 | struct unlock_dialog *dialog; |
| 548 | |
| 549 | dialog = malloc(sizeof *dialog); |
| 550 | if (!dialog) |
| 551 | return NULL; |
| 552 | memset(dialog, 0, sizeof *dialog); |
| 553 | |
Kristian Høgsberg | 009ac0a | 2012-01-31 15:24:48 -0500 | [diff] [blame] | 554 | dialog->window = window_create(display); |
Kristian Høgsberg | 29af3eb | 2012-01-10 22:41:05 -0500 | [diff] [blame] | 555 | dialog->widget = frame_create(dialog->window, dialog); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 556 | window_set_title(dialog->window, "Unlock your desktop"); |
Benjamin Franzke | 8193bc1 | 2011-11-23 19:35:07 +0100 | [diff] [blame] | 557 | window_set_custom(dialog->window); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 558 | |
| 559 | window_set_user_data(dialog->window, dialog); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 560 | window_set_keyboard_focus_handler(dialog->window, |
| 561 | unlock_dialog_keyboard_focus_handler); |
Kristian Høgsberg | 441338c | 2012-01-10 13:52:34 -0500 | [diff] [blame] | 562 | dialog->button = widget_add_widget(dialog->widget, dialog); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 563 | widget_set_redraw_handler(dialog->widget, |
| 564 | unlock_dialog_redraw_handler); |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 565 | widget_set_enter_handler(dialog->button, |
| 566 | unlock_dialog_widget_enter_handler); |
| 567 | widget_set_leave_handler(dialog->button, |
| 568 | unlock_dialog_widget_leave_handler); |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 569 | widget_set_button_handler(dialog->button, |
| 570 | unlock_dialog_button_handler); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 571 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 572 | desktop_shell_set_lock_surface(desktop->shell, |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 573 | window_get_wl_shell_surface(dialog->window)); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 574 | |
Pekka Paalanen | 40e49ac | 2012-01-18 16:51:30 +0200 | [diff] [blame] | 575 | window_schedule_resize(dialog->window, 260, 230); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 576 | |
| 577 | return dialog; |
| 578 | } |
| 579 | |
| 580 | static void |
| 581 | unlock_dialog_destroy(struct unlock_dialog *dialog) |
| 582 | { |
| 583 | window_destroy(dialog->window); |
| 584 | free(dialog); |
| 585 | } |
| 586 | |
| 587 | static void |
| 588 | unlock_dialog_finish(struct task *task, uint32_t events) |
| 589 | { |
| 590 | struct desktop *desktop = |
Benjamin Franzke | d775971 | 2011-11-22 12:38:48 +0100 | [diff] [blame] | 591 | container_of(task, struct desktop, unlock_task); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 592 | |
| 593 | desktop_shell_unlock(desktop->shell); |
| 594 | unlock_dialog_destroy(desktop->unlock_dialog); |
| 595 | desktop->unlock_dialog = NULL; |
| 596 | } |
| 597 | |
| 598 | static void |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 599 | desktop_shell_configure(void *data, |
| 600 | struct desktop_shell *desktop_shell, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 601 | uint32_t edges, |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 602 | struct wl_shell_surface *shell_surface, |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 603 | int32_t width, int32_t height) |
| 604 | { |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 605 | struct window *window = wl_shell_surface_get_user_data(shell_surface); |
| 606 | struct surface *s = window_get_user_data(window); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 607 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 608 | s->configure(data, desktop_shell, edges, window, width, height); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 609 | } |
| 610 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 611 | static void |
| 612 | desktop_shell_prepare_lock_surface(void *data, |
| 613 | struct desktop_shell *desktop_shell) |
| 614 | { |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 615 | struct desktop *desktop = data; |
| 616 | |
Pekka Paalanen | fd83b6d | 2011-12-08 10:06:53 +0200 | [diff] [blame] | 617 | if (!key_locking) { |
| 618 | desktop_shell_unlock(desktop->shell); |
| 619 | return; |
| 620 | } |
| 621 | |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 622 | if (!desktop->unlock_dialog) { |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 623 | desktop->unlock_dialog = unlock_dialog_create(desktop); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 624 | desktop->unlock_dialog->desktop = desktop; |
| 625 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 626 | } |
| 627 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 628 | static const struct desktop_shell_listener listener = { |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 629 | desktop_shell_configure, |
| 630 | desktop_shell_prepare_lock_surface |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 631 | }; |
| 632 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 633 | static struct background * |
| 634 | background_create(struct desktop *desktop) |
| 635 | { |
| 636 | struct background *background; |
| 637 | |
| 638 | background = malloc(sizeof *background); |
| 639 | memset(background, 0, sizeof *background); |
| 640 | |
| 641 | background->base.configure = background_configure; |
Kristian Høgsberg | 009ac0a | 2012-01-31 15:24:48 -0500 | [diff] [blame] | 642 | background->window = window_create(desktop->display); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 643 | background->widget = window_add_widget(background->window, background); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 644 | window_set_custom(background->window); |
| 645 | window_set_user_data(background->window, background); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 646 | widget_set_redraw_handler(background->widget, background_draw); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 647 | |
| 648 | return background; |
| 649 | } |
| 650 | |
| 651 | static void |
| 652 | create_output(struct desktop *desktop, uint32_t id) |
| 653 | { |
| 654 | struct output *output; |
| 655 | |
| 656 | output = calloc(1, sizeof *output); |
| 657 | if (!output) |
| 658 | return; |
| 659 | |
| 660 | output->output = wl_display_bind(display_get_display(desktop->display), |
| 661 | id, &wl_output_interface); |
| 662 | |
| 663 | wl_list_insert(&desktop->outputs, &output->link); |
| 664 | } |
| 665 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 666 | static void |
| 667 | global_handler(struct wl_display *display, uint32_t id, |
| 668 | const char *interface, uint32_t version, void *data) |
| 669 | { |
| 670 | struct desktop *desktop = data; |
| 671 | |
| 672 | if (!strcmp(interface, "desktop_shell")) { |
| 673 | desktop->shell = |
| 674 | wl_display_bind(display, id, &desktop_shell_interface); |
| 675 | desktop_shell_add_listener(desktop->shell, &listener, desktop); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 676 | } else if (!strcmp(interface, "wl_output")) { |
| 677 | create_output(desktop, id); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 681 | static void |
| 682 | launcher_section_done(void *data) |
| 683 | { |
| 684 | struct desktop *desktop = data; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 685 | struct output *output; |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 686 | |
| 687 | if (key_launcher_icon == NULL || key_launcher_path == NULL) { |
| 688 | fprintf(stderr, "invalid launcher section\n"); |
| 689 | return; |
| 690 | } |
| 691 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 692 | wl_list_for_each(output, &desktop->outputs, link) |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 693 | panel_add_launcher(output->panel, |
| 694 | key_launcher_icon, key_launcher_path); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 695 | |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 696 | free(key_launcher_icon); |
| 697 | key_launcher_icon = NULL; |
| 698 | free(key_launcher_path); |
| 699 | key_launcher_path = NULL; |
| 700 | } |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 701 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 702 | static void |
| 703 | add_default_launcher(struct desktop *desktop) |
| 704 | { |
| 705 | struct output *output; |
| 706 | |
| 707 | wl_list_for_each(output, &desktop->outputs, link) |
| 708 | panel_add_launcher(output->panel, |
| 709 | DATADIR "/weston/terminal.png", |
Rodney Lorrimar | 99ff01b | 2012-02-29 17:31:03 +0100 | [diff] [blame] | 710 | BINDIR "/weston-terminal"); |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 711 | } |
| 712 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 713 | int main(int argc, char *argv[]) |
| 714 | { |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 715 | struct desktop desktop = { 0 }; |
Pekka Paalanen | 668dd56 | 2011-11-15 11:45:40 +0200 | [diff] [blame] | 716 | char *config_file; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 717 | struct output *output; |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 718 | int ret; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 719 | |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 720 | desktop.unlock_task.run = unlock_dialog_finish; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 721 | wl_list_init(&desktop.outputs); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 722 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 723 | desktop.display = display_create(argc, argv); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 724 | if (desktop.display == NULL) { |
| 725 | fprintf(stderr, "failed to create display: %m\n"); |
| 726 | return -1; |
| 727 | } |
| 728 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 729 | wl_display_add_global_listener(display_get_display(desktop.display), |
| 730 | global_handler, &desktop); |
| 731 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 732 | wl_list_for_each(output, &desktop.outputs, link) { |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 733 | struct wl_shell_surface *s; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 734 | |
| 735 | output->panel = panel_create(desktop.display); |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 736 | s = window_get_wl_shell_surface(output->panel->window); |
| 737 | desktop_shell_set_panel(desktop.shell, output->output, s); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 738 | |
| 739 | output->background = background_create(&desktop); |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 740 | s = window_get_wl_shell_surface(output->background->window); |
| 741 | desktop_shell_set_background(desktop.shell, output->output, s); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 742 | } |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 743 | |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 744 | config_file = config_file_path("weston.ini"); |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 745 | ret = parse_config_file(config_file, |
| 746 | config_sections, ARRAY_LENGTH(config_sections), |
| 747 | &desktop); |
Pekka Paalanen | 668dd56 | 2011-11-15 11:45:40 +0200 | [diff] [blame] | 748 | free(config_file); |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 749 | if (ret < 0) |
| 750 | add_default_launcher(&desktop); |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 751 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 752 | signal(SIGCHLD, sigchild_handler); |
| 753 | |
| 754 | display_run(desktop.display); |
| 755 | |
| 756 | return 0; |
| 757 | } |