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