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