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