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> |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 33 | #include <sys/timerfd.h> |
| 34 | #include <sys/epoll.h> |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 35 | #include <linux/input.h> |
Tiago Vignatti | 6150072 | 2012-05-23 22:06:28 +0300 | [diff] [blame] | 36 | #include <libgen.h> |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 37 | #include <time.h> |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 38 | |
Pekka Paalanen | 50719bc | 2011-11-22 14:18:50 +0200 | [diff] [blame] | 39 | #include <wayland-client.h> |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 40 | #include "window.h" |
Kristian Høgsberg | 5a315bc | 2012-05-15 22:33:43 -0400 | [diff] [blame] | 41 | #include "../shared/cairo-util.h" |
Kristian Høgsberg | 9b935c8 | 2011-12-08 12:44:27 -0500 | [diff] [blame] | 42 | #include "../shared/config-parser.h" |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 43 | |
Pekka Paalanen | 50719bc | 2011-11-22 14:18:50 +0200 | [diff] [blame] | 44 | #include "desktop-shell-client-protocol.h" |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 45 | |
| 46 | struct desktop { |
| 47 | struct display *display; |
| 48 | struct desktop_shell *shell; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 49 | struct unlock_dialog *unlock_dialog; |
| 50 | struct task unlock_task; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 51 | struct wl_list outputs; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 52 | |
| 53 | struct window *busy_window; |
| 54 | struct widget *busy_widget; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | struct surface { |
| 58 | void (*configure)(void *data, |
| 59 | struct desktop_shell *desktop_shell, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 60 | uint32_t edges, struct window *window, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 61 | int32_t width, int32_t height); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | struct panel { |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 65 | struct surface base; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 66 | struct window *window; |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 67 | struct widget *widget; |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 68 | struct wl_list launcher_list; |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 69 | struct panel_clock *clock; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 70 | }; |
| 71 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 72 | struct background { |
| 73 | struct surface base; |
| 74 | struct window *window; |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 75 | struct widget *widget; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | struct output { |
| 79 | struct wl_output *output; |
| 80 | struct wl_list link; |
| 81 | |
| 82 | struct panel *panel; |
| 83 | struct background *background; |
| 84 | }; |
| 85 | |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 86 | struct panel_launcher { |
Kristian Høgsberg | c51f799 | 2012-01-08 15:09:53 -0500 | [diff] [blame] | 87 | struct widget *widget; |
Kristian Høgsberg | e28d05b | 2011-09-20 21:43:54 -0400 | [diff] [blame] | 88 | struct panel *panel; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 89 | cairo_surface_t *icon; |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 90 | int focused, pressed; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 91 | const char *path; |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 92 | struct wl_list link; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 93 | }; |
| 94 | |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 95 | struct panel_clock { |
| 96 | struct widget *widget; |
| 97 | struct panel *panel; |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 98 | struct task clock_task; |
| 99 | int clock_fd; |
| 100 | }; |
| 101 | |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 102 | struct unlock_dialog { |
| 103 | struct window *window; |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 104 | struct widget *widget; |
Kristian Høgsberg | c51f799 | 2012-01-08 15:09:53 -0500 | [diff] [blame] | 105 | struct widget *button; |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 106 | int button_focused; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 107 | int closing; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 108 | struct desktop *desktop; |
| 109 | }; |
| 110 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 111 | static char *key_background_image = DATADIR "/weston/pattern.png"; |
| 112 | static char *key_background_type = "tile"; |
| 113 | static uint32_t key_panel_color = 0xaa000000; |
| 114 | static uint32_t key_background_color = 0xff002244; |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 115 | static char *key_launcher_icon; |
| 116 | static char *key_launcher_path; |
| 117 | static void launcher_section_done(void *data); |
Pekka Paalanen | fd83b6d | 2011-12-08 10:06:53 +0200 | [diff] [blame] | 118 | static int key_locking = 1; |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 119 | |
| 120 | static const struct config_key shell_config_keys[] = { |
| 121 | { "background-image", CONFIG_KEY_STRING, &key_background_image }, |
Kristian Høgsberg | 07f7294 | 2012-01-25 16:34:36 -0500 | [diff] [blame] | 122 | { "background-type", CONFIG_KEY_STRING, &key_background_type }, |
Scott Moreau | fa1de69 | 2012-01-27 13:25:49 -0700 | [diff] [blame] | 123 | { "panel-color", CONFIG_KEY_UNSIGNED_INTEGER, &key_panel_color }, |
| 124 | { "background-color", CONFIG_KEY_UNSIGNED_INTEGER, &key_background_color }, |
Pekka Paalanen | fd83b6d | 2011-12-08 10:06:53 +0200 | [diff] [blame] | 125 | { "locking", CONFIG_KEY_BOOLEAN, &key_locking }, |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | static const struct config_key launcher_config_keys[] = { |
| 129 | { "icon", CONFIG_KEY_STRING, &key_launcher_icon }, |
| 130 | { "path", CONFIG_KEY_STRING, &key_launcher_path }, |
| 131 | }; |
| 132 | |
| 133 | static const struct config_section config_sections[] = { |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 134 | { "shell", |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 135 | shell_config_keys, ARRAY_LENGTH(shell_config_keys) }, |
| 136 | { "launcher", |
| 137 | launcher_config_keys, ARRAY_LENGTH(launcher_config_keys), |
| 138 | launcher_section_done } |
| 139 | }; |
| 140 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 141 | static void |
| 142 | sigchild_handler(int s) |
| 143 | { |
| 144 | int status; |
| 145 | pid_t pid; |
| 146 | |
| 147 | while (pid = waitpid(-1, &status, WNOHANG), pid > 0) |
| 148 | fprintf(stderr, "child %d exited\n", pid); |
| 149 | } |
| 150 | |
| 151 | static void |
Pekka Paalanen | 9e30a82 | 2012-01-19 16:40:28 +0200 | [diff] [blame] | 152 | menu_func(struct window *window, int index, void *data) |
| 153 | { |
| 154 | printf("Selected index %d from a panel menu.\n", index); |
| 155 | } |
| 156 | |
| 157 | static void |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 158 | show_menu(struct panel *panel, struct input *input, uint32_t time) |
Kristian Høgsberg | bcee9a4 | 2011-10-12 00:36:16 -0400 | [diff] [blame] | 159 | { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 160 | int32_t x, y; |
| 161 | static const char *entries[] = { |
| 162 | "Roy", "Pris", "Leon", "Zhora" |
| 163 | }; |
Kristian Høgsberg | bcee9a4 | 2011-10-12 00:36:16 -0400 | [diff] [blame] | 164 | |
| 165 | input_get_position(input, &x, &y); |
Pekka Paalanen | 6d174cf | 2012-01-19 15:17:59 +0200 | [diff] [blame] | 166 | window_show_menu(window_get_display(panel->window), |
| 167 | input, time, panel->window, |
Pekka Paalanen | 9e30a82 | 2012-01-19 16:40:28 +0200 | [diff] [blame] | 168 | x - 10, y - 10, menu_func, entries, 4); |
Kristian Høgsberg | bcee9a4 | 2011-10-12 00:36:16 -0400 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | static void |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 172 | panel_launcher_activate(struct panel_launcher *widget) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 173 | { |
| 174 | pid_t pid; |
| 175 | |
| 176 | pid = fork(); |
| 177 | if (pid < 0) { |
| 178 | fprintf(stderr, "fork failed: %m\n"); |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | if (pid) |
| 183 | return; |
Benjamin Franzke | d775971 | 2011-11-22 12:38:48 +0100 | [diff] [blame] | 184 | |
Kristian Høgsberg | c51f799 | 2012-01-08 15:09:53 -0500 | [diff] [blame] | 185 | if (execl(widget->path, widget->path, NULL) < 0) { |
Pekka Paalanen | a291ae5 | 2012-01-27 09:50:02 +0200 | [diff] [blame] | 186 | fprintf(stderr, "execl '%s' failed: %m\n", widget->path); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 187 | exit(1); |
| 188 | } |
| 189 | } |
| 190 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 191 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 192 | panel_launcher_redraw_handler(struct widget *widget, void *data) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 193 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 194 | struct panel_launcher *launcher = data; |
| 195 | cairo_surface_t *surface; |
| 196 | struct rectangle allocation; |
| 197 | cairo_t *cr; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 198 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 199 | surface = window_get_surface(launcher->panel->window); |
| 200 | cr = cairo_create(surface); |
| 201 | |
| 202 | widget_get_allocation(widget, &allocation); |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 203 | if (launcher->pressed) { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 204 | allocation.x++; |
| 205 | allocation.y++; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 206 | } |
| 207 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 208 | cairo_set_source_surface(cr, launcher->icon, |
| 209 | allocation.x, allocation.y); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 210 | cairo_paint(cr); |
| 211 | |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 212 | if (launcher->focused) { |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 213 | 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] | 214 | cairo_mask_surface(cr, launcher->icon, |
| 215 | allocation.x, allocation.y); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 216 | } |
Kristian Høgsberg | e28d05b | 2011-09-20 21:43:54 -0400 | [diff] [blame] | 217 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 218 | cairo_destroy(cr); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 219 | } |
| 220 | |
Tiago Vignatti | 6150072 | 2012-05-23 22:06:28 +0300 | [diff] [blame] | 221 | static int |
| 222 | panel_launcher_motion_handler(struct widget *widget, struct input *input, |
| 223 | uint32_t time, float x, float y, void *data) |
| 224 | { |
| 225 | struct panel_launcher *launcher = data; |
| 226 | |
| 227 | widget_set_tooltip(widget, basename((char *)launcher->path), x, y); |
| 228 | |
Ander Conselvan de Oliveira | dc8c8fc | 2012-05-25 16:01:41 +0300 | [diff] [blame] | 229 | return CURSOR_LEFT_PTR; |
Tiago Vignatti | 6150072 | 2012-05-23 22:06:28 +0300 | [diff] [blame] | 230 | } |
| 231 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 232 | static void |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 233 | set_hex_color(cairo_t *cr, uint32_t color) |
| 234 | { |
| 235 | cairo_set_source_rgba(cr, |
| 236 | ((color >> 16) & 0xff) / 255.0, |
| 237 | ((color >> 8) & 0xff) / 255.0, |
| 238 | ((color >> 0) & 0xff) / 255.0, |
| 239 | ((color >> 24) & 0xff) / 255.0); |
| 240 | } |
| 241 | |
| 242 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 243 | panel_redraw_handler(struct widget *widget, void *data) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 244 | { |
| 245 | cairo_surface_t *surface; |
| 246 | cairo_t *cr; |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 247 | struct panel *panel = data; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 248 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 249 | surface = window_get_surface(panel->window); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 250 | cr = cairo_create(surface); |
| 251 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 252 | set_hex_color(cr, key_panel_color); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 253 | cairo_paint(cr); |
| 254 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 255 | cairo_destroy(cr); |
| 256 | cairo_surface_destroy(surface); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 257 | } |
| 258 | |
Kristian Høgsberg | bb901fa | 2012-01-09 11:22:32 -0500 | [diff] [blame] | 259 | static int |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 260 | panel_launcher_enter_handler(struct widget *widget, struct input *input, |
Kristian Høgsberg | 80680c7 | 2012-05-10 12:21:37 -0400 | [diff] [blame] | 261 | float x, float y, void *data) |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 262 | { |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 263 | struct panel_launcher *launcher = data; |
| 264 | |
| 265 | launcher->focused = 1; |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 266 | widget_schedule_redraw(widget); |
Kristian Høgsberg | bb901fa | 2012-01-09 11:22:32 -0500 | [diff] [blame] | 267 | |
Ander Conselvan de Oliveira | dc8c8fc | 2012-05-25 16:01:41 +0300 | [diff] [blame] | 268 | return CURSOR_LEFT_PTR; |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | static void |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 272 | panel_launcher_leave_handler(struct widget *widget, |
| 273 | struct input *input, void *data) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 274 | { |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 275 | struct panel_launcher *launcher = data; |
| 276 | |
| 277 | launcher->focused = 0; |
Tiago Vignatti | 6150072 | 2012-05-23 22:06:28 +0300 | [diff] [blame] | 278 | widget_destroy_tooltip(widget); |
Kristian Høgsberg | 9a13dab | 2012-01-08 15:18:19 -0500 | [diff] [blame] | 279 | widget_schedule_redraw(widget); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | static void |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 283 | panel_launcher_button_handler(struct widget *widget, |
| 284 | struct input *input, uint32_t time, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 285 | uint32_t button, |
| 286 | enum wl_pointer_button_state state, void *data) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 287 | { |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 288 | struct panel_launcher *launcher; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 289 | |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 290 | launcher = widget_get_user_data(widget); |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 291 | widget_schedule_redraw(widget); |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 292 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 293 | panel_launcher_activate(launcher); |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 294 | } |
| 295 | |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 296 | static void |
| 297 | clock_func(struct task *task, uint32_t events) |
| 298 | { |
| 299 | struct panel_clock *clock = |
Kristian Høgsberg | bb262cf | 2012-06-11 11:03:03 -0400 | [diff] [blame] | 300 | container_of(task, struct panel_clock, clock_task); |
Kristian Høgsberg | 70226bb | 2012-06-08 16:54:52 -0400 | [diff] [blame] | 301 | uint64_t exp; |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 302 | |
Kristian Høgsberg | 70226bb | 2012-06-08 16:54:52 -0400 | [diff] [blame] | 303 | read(clock->clock_fd, &exp, sizeof exp); |
Kristian Høgsberg | 92a984a | 2012-06-11 11:10:57 -0400 | [diff] [blame] | 304 | widget_schedule_redraw(clock->widget); |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | static void |
| 308 | panel_clock_redraw_handler(struct widget *widget, void *data) |
| 309 | { |
| 310 | cairo_surface_t *surface; |
| 311 | struct panel_clock *clock = data; |
| 312 | cairo_t *cr; |
| 313 | struct rectangle allocation; |
| 314 | cairo_text_extents_t extents; |
| 315 | cairo_font_extents_t font_extents; |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 316 | time_t rawtime; |
| 317 | struct tm * timeinfo; |
Kristian Høgsberg | 92a984a | 2012-06-11 11:10:57 -0400 | [diff] [blame] | 318 | char string[128]; |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 319 | |
Kristian Høgsberg | bb262cf | 2012-06-11 11:03:03 -0400 | [diff] [blame] | 320 | time(&rawtime); |
| 321 | timeinfo = localtime(&rawtime); |
Kristian Høgsberg | e9f68f6 | 2012-06-11 12:24:12 -0400 | [diff] [blame] | 322 | strftime(string, sizeof string, "%a %b %d, %I:%M %p", timeinfo); |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 323 | |
| 324 | widget_get_allocation(widget, &allocation); |
Kristian Høgsberg | bb262cf | 2012-06-11 11:03:03 -0400 | [diff] [blame] | 325 | if (allocation.width == 0) |
| 326 | return; |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 327 | |
| 328 | surface = window_get_surface(clock->panel->window); |
| 329 | cr = cairo_create(surface); |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 330 | cairo_select_font_face(cr, "sans", |
| 331 | CAIRO_FONT_SLANT_NORMAL, |
| 332 | CAIRO_FONT_WEIGHT_NORMAL); |
| 333 | cairo_set_font_size(cr, 14); |
Kristian Høgsberg | 92a984a | 2012-06-11 11:10:57 -0400 | [diff] [blame] | 334 | cairo_text_extents(cr, string, &extents); |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 335 | cairo_font_extents (cr, &font_extents); |
Kristian Høgsberg | bb262cf | 2012-06-11 11:03:03 -0400 | [diff] [blame] | 336 | cairo_move_to(cr, allocation.x + 5, |
| 337 | allocation.y + 3 * (allocation.height >> 2) + 1); |
| 338 | cairo_set_source_rgb(cr, 0, 0, 0); |
Kristian Høgsberg | 92a984a | 2012-06-11 11:10:57 -0400 | [diff] [blame] | 339 | cairo_show_text(cr, string); |
Kristian Høgsberg | bb262cf | 2012-06-11 11:03:03 -0400 | [diff] [blame] | 340 | cairo_move_to(cr, allocation.x + 4, |
| 341 | allocation.y + 3 * (allocation.height >> 2)); |
| 342 | cairo_set_source_rgb(cr, 1, 1, 1); |
Kristian Høgsberg | 92a984a | 2012-06-11 11:10:57 -0400 | [diff] [blame] | 343 | cairo_show_text(cr, string); |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 344 | cairo_destroy(cr); |
| 345 | } |
| 346 | |
| 347 | static int |
| 348 | clock_timer_reset(struct panel_clock *clock) |
| 349 | { |
| 350 | struct itimerspec its; |
Kristian Høgsberg | bb262cf | 2012-06-11 11:03:03 -0400 | [diff] [blame] | 351 | |
Kristian Høgsberg | e9f68f6 | 2012-06-11 12:24:12 -0400 | [diff] [blame] | 352 | its.it_interval.tv_sec = 60; |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 353 | its.it_interval.tv_nsec = 0; |
Kristian Høgsberg | e9f68f6 | 2012-06-11 12:24:12 -0400 | [diff] [blame] | 354 | its.it_value.tv_sec = 60; |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 355 | its.it_value.tv_nsec = 0; |
| 356 | if (timerfd_settime(clock->clock_fd, 0, &its, NULL) < 0) { |
| 357 | fprintf(stderr, "could not set timerfd\n: %m"); |
| 358 | return -1; |
| 359 | } |
| 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | static void |
| 365 | panel_add_clock(struct panel *panel) |
| 366 | { |
| 367 | struct panel_clock *clock; |
| 368 | int timerfd; |
| 369 | |
| 370 | timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC); |
| 371 | if (timerfd < 0) { |
| 372 | fprintf(stderr, "could not create timerfd\n: %m"); |
| 373 | return; |
| 374 | } |
| 375 | |
| 376 | clock = malloc(sizeof *clock); |
| 377 | memset(clock, 0, sizeof *clock); |
| 378 | clock->panel = panel; |
| 379 | panel->clock = clock; |
| 380 | clock->clock_fd = timerfd; |
| 381 | |
| 382 | clock->clock_task.run = clock_func; |
Kristian Høgsberg | bb262cf | 2012-06-11 11:03:03 -0400 | [diff] [blame] | 383 | display_watch_fd(window_get_display(panel->window), clock->clock_fd, |
| 384 | EPOLLIN, &clock->clock_task); |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 385 | clock_timer_reset(clock); |
| 386 | |
| 387 | clock->widget = widget_add_widget(panel->widget, clock); |
Kristian Høgsberg | bb262cf | 2012-06-11 11:03:03 -0400 | [diff] [blame] | 388 | widget_set_redraw_handler(clock->widget, panel_clock_redraw_handler); |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 389 | } |
| 390 | |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 391 | static void |
| 392 | panel_button_handler(struct widget *widget, |
| 393 | struct input *input, uint32_t time, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 394 | uint32_t button, |
| 395 | enum wl_pointer_button_state state, void *data) |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 396 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 397 | struct panel *panel = data; |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 398 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 399 | if (button == BTN_RIGHT && state == WL_POINTER_BUTTON_STATE_PRESSED) |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 400 | show_menu(panel, input, time); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 401 | } |
| 402 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 403 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 404 | panel_resize_handler(struct widget *widget, |
| 405 | int32_t width, int32_t height, void *data) |
| 406 | { |
| 407 | struct panel_launcher *launcher; |
| 408 | struct panel *panel = data; |
| 409 | int x, y, w, h; |
| 410 | |
| 411 | x = 10; |
| 412 | y = 16; |
| 413 | wl_list_for_each(launcher, &panel->launcher_list, link) { |
| 414 | w = cairo_image_surface_get_width(launcher->icon); |
| 415 | h = cairo_image_surface_get_height(launcher->icon); |
| 416 | widget_set_allocation(launcher->widget, |
| 417 | x, y - h / 2, w + 1, h + 1); |
| 418 | x += w + 10; |
| 419 | } |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 420 | h=20; |
| 421 | w=170; |
Pekka Paalanen | 01b1725 | 2012-06-12 17:42:26 +0300 | [diff] [blame] | 422 | |
| 423 | if (panel->clock) |
| 424 | widget_set_allocation(panel->clock->widget, |
| 425 | width - w - 8, y - h / 2, w + 1, h + 1); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | static void |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 429 | panel_configure(void *data, |
| 430 | struct desktop_shell *desktop_shell, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 431 | uint32_t edges, struct window *window, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 432 | int32_t width, int32_t height) |
| 433 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 434 | struct surface *surface = window_get_user_data(window); |
| 435 | struct panel *panel = container_of(surface, struct panel, base); |
| 436 | |
| 437 | window_schedule_resize(panel->window, width, 32); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 438 | } |
| 439 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 440 | static struct panel * |
| 441 | panel_create(struct display *display) |
| 442 | { |
| 443 | struct panel *panel; |
| 444 | |
| 445 | panel = malloc(sizeof *panel); |
| 446 | memset(panel, 0, sizeof *panel); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 447 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 448 | panel->base.configure = panel_configure; |
Kristian Høgsberg | 009ac0a | 2012-01-31 15:24:48 -0500 | [diff] [blame] | 449 | panel->window = window_create(display); |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 450 | panel->widget = window_add_widget(panel->window, panel); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 451 | wl_list_init(&panel->launcher_list); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 452 | |
| 453 | window_set_title(panel->window, "panel"); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 454 | window_set_custom(panel->window); |
| 455 | window_set_user_data(panel->window, panel); |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 456 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 457 | widget_set_redraw_handler(panel->widget, panel_redraw_handler); |
| 458 | widget_set_resize_handler(panel->widget, panel_resize_handler); |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 459 | widget_set_button_handler(panel->widget, panel_button_handler); |
Rafal Mielniczuk | b9e513c | 2012-06-09 20:33:29 +0200 | [diff] [blame] | 460 | |
| 461 | panel_add_clock(panel); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 462 | |
| 463 | return panel; |
| 464 | } |
| 465 | |
| 466 | static void |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 467 | 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] | 468 | { |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 469 | struct panel_launcher *launcher; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 470 | |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 471 | launcher = malloc(sizeof *launcher); |
| 472 | memset(launcher, 0, sizeof *launcher); |
| 473 | launcher->icon = cairo_image_surface_create_from_png(icon); |
| 474 | launcher->path = strdup(path); |
| 475 | launcher->panel = panel; |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 476 | wl_list_insert(panel->launcher_list.prev, &launcher->link); |
| 477 | |
Kristian Høgsberg | 441338c | 2012-01-10 13:52:34 -0500 | [diff] [blame] | 478 | launcher->widget = widget_add_widget(panel->widget, launcher); |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 479 | widget_set_enter_handler(launcher->widget, |
| 480 | panel_launcher_enter_handler); |
| 481 | widget_set_leave_handler(launcher->widget, |
| 482 | panel_launcher_leave_handler); |
| 483 | widget_set_button_handler(launcher->widget, |
| 484 | panel_launcher_button_handler); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 485 | widget_set_redraw_handler(launcher->widget, |
| 486 | panel_launcher_redraw_handler); |
Tiago Vignatti | 6150072 | 2012-05-23 22:06:28 +0300 | [diff] [blame] | 487 | widget_set_motion_handler(launcher->widget, |
| 488 | panel_launcher_motion_handler); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 489 | } |
| 490 | |
Kristian Høgsberg | 07f7294 | 2012-01-25 16:34:36 -0500 | [diff] [blame] | 491 | enum { |
| 492 | BACKGROUND_SCALE, |
| 493 | BACKGROUND_TILE |
| 494 | }; |
| 495 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 496 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 497 | background_draw(struct widget *widget, void *data) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 498 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 499 | struct background *background = data; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 500 | cairo_surface_t *surface, *image; |
Kristian Høgsberg | 7e69000 | 2011-09-08 18:18:02 -0400 | [diff] [blame] | 501 | cairo_pattern_t *pattern; |
| 502 | cairo_matrix_t matrix; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 503 | cairo_t *cr; |
Kristian Høgsberg | 7e69000 | 2011-09-08 18:18:02 -0400 | [diff] [blame] | 504 | double sx, sy; |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 505 | struct rectangle allocation; |
Kristian Høgsberg | 07f7294 | 2012-01-25 16:34:36 -0500 | [diff] [blame] | 506 | int type = -1; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 507 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 508 | surface = window_get_surface(background->window); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 509 | |
| 510 | cr = cairo_create(surface); |
| 511 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
| 512 | cairo_set_source_rgba(cr, 0.0, 0.0, 0.2, 1.0); |
| 513 | cairo_paint(cr); |
| 514 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 515 | widget_get_allocation(widget, &allocation); |
Kristian Høgsberg | 8129bc0 | 2012-01-25 14:55:33 -0500 | [diff] [blame] | 516 | image = NULL; |
| 517 | if (key_background_image) |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 518 | image = load_cairo_surface(key_background_image); |
Kristian Høgsberg | 07f7294 | 2012-01-25 16:34:36 -0500 | [diff] [blame] | 519 | |
| 520 | if (strcmp(key_background_type, "scale") == 0) |
| 521 | type = BACKGROUND_SCALE; |
| 522 | else if (strcmp(key_background_type, "tile") == 0) |
| 523 | type = BACKGROUND_TILE; |
| 524 | else |
| 525 | fprintf(stderr, "invalid background-type: %s\n", |
| 526 | key_background_type); |
| 527 | |
| 528 | if (image && type != -1) { |
Kristian Høgsberg | 7e69000 | 2011-09-08 18:18:02 -0400 | [diff] [blame] | 529 | pattern = cairo_pattern_create_for_surface(image); |
Kristian Høgsberg | 07f7294 | 2012-01-25 16:34:36 -0500 | [diff] [blame] | 530 | switch (type) { |
| 531 | case BACKGROUND_SCALE: |
| 532 | sx = (double) cairo_image_surface_get_width(image) / |
| 533 | allocation.width; |
| 534 | sy = (double) cairo_image_surface_get_height(image) / |
| 535 | allocation.height; |
| 536 | cairo_matrix_init_scale(&matrix, sx, sy); |
| 537 | cairo_pattern_set_matrix(pattern, &matrix); |
| 538 | break; |
| 539 | case BACKGROUND_TILE: |
| 540 | cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); |
| 541 | break; |
| 542 | } |
Kristian Høgsberg | 7e69000 | 2011-09-08 18:18:02 -0400 | [diff] [blame] | 543 | cairo_set_source(cr, pattern); |
| 544 | cairo_pattern_destroy (pattern); |
Kristian Høgsberg | 27d3866 | 2011-10-20 13:11:12 -0400 | [diff] [blame] | 545 | cairo_surface_destroy(image); |
Kristian Høgsberg | 8129bc0 | 2012-01-25 14:55:33 -0500 | [diff] [blame] | 546 | } else { |
| 547 | set_hex_color(cr, key_background_color); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 548 | } |
| 549 | |
Kristian Høgsberg | 8129bc0 | 2012-01-25 14:55:33 -0500 | [diff] [blame] | 550 | cairo_paint(cr); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 551 | cairo_destroy(cr); |
| 552 | cairo_surface_destroy(surface); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | static void |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 556 | background_configure(void *data, |
| 557 | struct desktop_shell *desktop_shell, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 558 | uint32_t edges, struct window *window, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 559 | int32_t width, int32_t height) |
| 560 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 561 | struct background *background = |
| 562 | (struct background *) window_get_user_data(window); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 563 | |
Kristian Høgsberg | bb97700 | 2012-01-10 19:11:42 -0500 | [diff] [blame] | 564 | widget_schedule_resize(background->widget, width, height); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 568 | unlock_dialog_redraw_handler(struct widget *widget, void *data) |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 569 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 570 | struct unlock_dialog *dialog = data; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 571 | struct rectangle allocation; |
| 572 | cairo_t *cr; |
| 573 | cairo_surface_t *surface; |
| 574 | cairo_pattern_t *pat; |
| 575 | double cx, cy, r, f; |
| 576 | |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 577 | surface = window_get_surface(dialog->window); |
| 578 | cr = cairo_create(surface); |
Kristian Høgsberg | 41c5c4e | 2012-03-05 20:37:51 -0500 | [diff] [blame] | 579 | |
Kristian Høgsberg | bb97700 | 2012-01-10 19:11:42 -0500 | [diff] [blame] | 580 | widget_get_allocation(dialog->widget, &allocation); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 581 | cairo_rectangle(cr, allocation.x, allocation.y, |
| 582 | allocation.width, allocation.height); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 583 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
| 584 | cairo_set_source_rgba(cr, 0, 0, 0, 0.6); |
Kristian Høgsberg | 41c5c4e | 2012-03-05 20:37:51 -0500 | [diff] [blame] | 585 | cairo_fill(cr); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 586 | |
Kristian Høgsberg | 41c5c4e | 2012-03-05 20:37:51 -0500 | [diff] [blame] | 587 | cairo_translate(cr, allocation.x, allocation.y); |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 588 | if (dialog->button_focused) |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 589 | f = 1.0; |
| 590 | else |
| 591 | f = 0.7; |
| 592 | |
| 593 | cx = allocation.width / 2.0; |
| 594 | cy = allocation.height / 2.0; |
| 595 | r = (cx < cy ? cx : cy) * 0.4; |
| 596 | pat = cairo_pattern_create_radial(cx, cy, r * 0.7, cx, cy, r); |
| 597 | cairo_pattern_add_color_stop_rgb(pat, 0.0, 0, 0.86 * f, 0); |
| 598 | cairo_pattern_add_color_stop_rgb(pat, 0.85, 0.2 * f, f, 0.2 * f); |
| 599 | cairo_pattern_add_color_stop_rgb(pat, 1.0, 0, 0.86 * f, 0); |
| 600 | cairo_set_source(cr, pat); |
Kristian Høgsberg | 41c5c4e | 2012-03-05 20:37:51 -0500 | [diff] [blame] | 601 | cairo_pattern_destroy(pat); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 602 | cairo_arc(cr, cx, cy, r, 0.0, 2.0 * M_PI); |
| 603 | cairo_fill(cr); |
| 604 | |
Kristian Høgsberg | c51f799 | 2012-01-08 15:09:53 -0500 | [diff] [blame] | 605 | widget_set_allocation(dialog->button, |
Kristian Høgsberg | 41c5c4e | 2012-03-05 20:37:51 -0500 | [diff] [blame] | 606 | allocation.x + cx - r, |
| 607 | allocation.y + cy - r, 2 * r, 2 * r); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 608 | |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 609 | cairo_destroy(cr); |
| 610 | |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 611 | cairo_surface_destroy(surface); |
| 612 | } |
| 613 | |
| 614 | static void |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 615 | unlock_dialog_button_handler(struct widget *widget, |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 616 | struct input *input, uint32_t time, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 617 | uint32_t button, |
| 618 | enum wl_pointer_button_state state, void *data) |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 619 | { |
| 620 | struct unlock_dialog *dialog = data; |
| 621 | struct desktop *desktop = dialog->desktop; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 622 | |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 623 | if (button == BTN_LEFT) { |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 624 | if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
| 625 | !dialog->closing) { |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 626 | display_defer(desktop->display, &desktop->unlock_task); |
| 627 | dialog->closing = 1; |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | static void |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 633 | unlock_dialog_keyboard_focus_handler(struct window *window, |
| 634 | struct input *device, void *data) |
| 635 | { |
| 636 | window_schedule_redraw(window); |
| 637 | } |
| 638 | |
Kristian Høgsberg | bb901fa | 2012-01-09 11:22:32 -0500 | [diff] [blame] | 639 | static int |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 640 | unlock_dialog_widget_enter_handler(struct widget *widget, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 641 | struct input *input, |
Kristian Høgsberg | 80680c7 | 2012-05-10 12:21:37 -0400 | [diff] [blame] | 642 | float x, float y, void *data) |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 643 | { |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 644 | struct unlock_dialog *dialog = data; |
| 645 | |
| 646 | dialog->button_focused = 1; |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 647 | widget_schedule_redraw(widget); |
Kristian Høgsberg | bb901fa | 2012-01-09 11:22:32 -0500 | [diff] [blame] | 648 | |
Ander Conselvan de Oliveira | dc8c8fc | 2012-05-25 16:01:41 +0300 | [diff] [blame] | 649 | return CURSOR_LEFT_PTR; |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | static void |
| 653 | unlock_dialog_widget_leave_handler(struct widget *widget, |
| 654 | struct input *input, void *data) |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 655 | { |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 656 | struct unlock_dialog *dialog = data; |
| 657 | |
| 658 | dialog->button_focused = 0; |
Kristian Høgsberg | 9a13dab | 2012-01-08 15:18:19 -0500 | [diff] [blame] | 659 | widget_schedule_redraw(widget); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static struct unlock_dialog * |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 663 | unlock_dialog_create(struct desktop *desktop) |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 664 | { |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 665 | struct display *display = desktop->display; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 666 | struct unlock_dialog *dialog; |
| 667 | |
| 668 | dialog = malloc(sizeof *dialog); |
| 669 | if (!dialog) |
| 670 | return NULL; |
| 671 | memset(dialog, 0, sizeof *dialog); |
| 672 | |
Kristian Høgsberg | 009ac0a | 2012-01-31 15:24:48 -0500 | [diff] [blame] | 673 | dialog->window = window_create(display); |
Kristian Høgsberg | 29af3eb | 2012-01-10 22:41:05 -0500 | [diff] [blame] | 674 | dialog->widget = frame_create(dialog->window, dialog); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 675 | window_set_title(dialog->window, "Unlock your desktop"); |
Benjamin Franzke | 8193bc1 | 2011-11-23 19:35:07 +0100 | [diff] [blame] | 676 | window_set_custom(dialog->window); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 677 | |
| 678 | window_set_user_data(dialog->window, dialog); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 679 | window_set_keyboard_focus_handler(dialog->window, |
| 680 | unlock_dialog_keyboard_focus_handler); |
Kristian Høgsberg | 441338c | 2012-01-10 13:52:34 -0500 | [diff] [blame] | 681 | dialog->button = widget_add_widget(dialog->widget, dialog); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 682 | widget_set_redraw_handler(dialog->widget, |
| 683 | unlock_dialog_redraw_handler); |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 684 | widget_set_enter_handler(dialog->button, |
| 685 | unlock_dialog_widget_enter_handler); |
| 686 | widget_set_leave_handler(dialog->button, |
| 687 | unlock_dialog_widget_leave_handler); |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 688 | widget_set_button_handler(dialog->button, |
| 689 | unlock_dialog_button_handler); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 690 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 691 | desktop_shell_set_lock_surface(desktop->shell, |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 692 | window_get_wl_shell_surface(dialog->window)); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 693 | |
Pekka Paalanen | 40e49ac | 2012-01-18 16:51:30 +0200 | [diff] [blame] | 694 | window_schedule_resize(dialog->window, 260, 230); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 695 | |
| 696 | return dialog; |
| 697 | } |
| 698 | |
| 699 | static void |
| 700 | unlock_dialog_destroy(struct unlock_dialog *dialog) |
| 701 | { |
| 702 | window_destroy(dialog->window); |
| 703 | free(dialog); |
| 704 | } |
| 705 | |
| 706 | static void |
| 707 | unlock_dialog_finish(struct task *task, uint32_t events) |
| 708 | { |
| 709 | struct desktop *desktop = |
Benjamin Franzke | d775971 | 2011-11-22 12:38:48 +0100 | [diff] [blame] | 710 | container_of(task, struct desktop, unlock_task); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 711 | |
| 712 | desktop_shell_unlock(desktop->shell); |
| 713 | unlock_dialog_destroy(desktop->unlock_dialog); |
| 714 | desktop->unlock_dialog = NULL; |
| 715 | } |
| 716 | |
| 717 | static void |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 718 | desktop_shell_configure(void *data, |
| 719 | struct desktop_shell *desktop_shell, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 720 | uint32_t edges, |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame^] | 721 | struct wl_surface *surface, |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 722 | int32_t width, int32_t height) |
| 723 | { |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame^] | 724 | struct window *window = wl_surface_get_user_data(surface); |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 725 | struct surface *s = window_get_user_data(window); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 726 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 727 | s->configure(data, desktop_shell, edges, window, width, height); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 728 | } |
| 729 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 730 | static void |
| 731 | desktop_shell_prepare_lock_surface(void *data, |
| 732 | struct desktop_shell *desktop_shell) |
| 733 | { |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 734 | struct desktop *desktop = data; |
| 735 | |
Pekka Paalanen | fd83b6d | 2011-12-08 10:06:53 +0200 | [diff] [blame] | 736 | if (!key_locking) { |
| 737 | desktop_shell_unlock(desktop->shell); |
| 738 | return; |
| 739 | } |
| 740 | |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 741 | if (!desktop->unlock_dialog) { |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 742 | desktop->unlock_dialog = unlock_dialog_create(desktop); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 743 | desktop->unlock_dialog->desktop = desktop; |
| 744 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 745 | } |
| 746 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 747 | static const struct desktop_shell_listener listener = { |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 748 | desktop_shell_configure, |
| 749 | desktop_shell_prepare_lock_surface |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 750 | }; |
| 751 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 752 | static struct background * |
| 753 | background_create(struct desktop *desktop) |
| 754 | { |
| 755 | struct background *background; |
| 756 | |
| 757 | background = malloc(sizeof *background); |
| 758 | memset(background, 0, sizeof *background); |
| 759 | |
| 760 | background->base.configure = background_configure; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame^] | 761 | background->window = window_create_custom(desktop->display); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 762 | background->widget = window_add_widget(background->window, background); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 763 | window_set_user_data(background->window, background); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 764 | widget_set_redraw_handler(background->widget, background_draw); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 765 | |
| 766 | return background; |
| 767 | } |
| 768 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 769 | static int |
| 770 | busy_surface_enter_handler(struct widget *widget, struct input *input, |
| 771 | float x, float y, void *data) |
| 772 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 773 | return CURSOR_WATCH; |
| 774 | } |
| 775 | |
| 776 | static void |
| 777 | busy_surface_create(struct desktop *desktop) |
| 778 | { |
| 779 | struct wl_surface *s; |
| 780 | |
| 781 | desktop->busy_window = window_create(desktop->display); |
| 782 | s = window_get_wl_surface(desktop->busy_window); |
| 783 | desktop_shell_set_busy_surface(desktop->shell, s); |
| 784 | |
| 785 | desktop->busy_widget = |
| 786 | window_add_widget(desktop->busy_window, desktop); |
| 787 | /* We set the allocation to 1x1 at 0,0 so the fake enter event |
| 788 | * at 0,0 will go to this widget. */ |
| 789 | widget_set_allocation(desktop->busy_widget, 0, 0, 1, 1); |
| 790 | |
| 791 | widget_set_enter_handler(desktop->busy_widget, |
| 792 | busy_surface_enter_handler); |
| 793 | } |
| 794 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 795 | static void |
| 796 | create_output(struct desktop *desktop, uint32_t id) |
| 797 | { |
| 798 | struct output *output; |
| 799 | |
| 800 | output = calloc(1, sizeof *output); |
| 801 | if (!output) |
| 802 | return; |
| 803 | |
| 804 | output->output = wl_display_bind(display_get_display(desktop->display), |
| 805 | id, &wl_output_interface); |
| 806 | |
| 807 | wl_list_insert(&desktop->outputs, &output->link); |
| 808 | } |
| 809 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 810 | static void |
| 811 | global_handler(struct wl_display *display, uint32_t id, |
| 812 | const char *interface, uint32_t version, void *data) |
| 813 | { |
| 814 | struct desktop *desktop = data; |
| 815 | |
| 816 | if (!strcmp(interface, "desktop_shell")) { |
| 817 | desktop->shell = |
| 818 | wl_display_bind(display, id, &desktop_shell_interface); |
| 819 | desktop_shell_add_listener(desktop->shell, &listener, desktop); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 820 | } else if (!strcmp(interface, "wl_output")) { |
| 821 | create_output(desktop, id); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 822 | } |
| 823 | } |
| 824 | |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 825 | static void |
| 826 | launcher_section_done(void *data) |
| 827 | { |
| 828 | struct desktop *desktop = data; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 829 | struct output *output; |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 830 | |
| 831 | if (key_launcher_icon == NULL || key_launcher_path == NULL) { |
| 832 | fprintf(stderr, "invalid launcher section\n"); |
| 833 | return; |
| 834 | } |
| 835 | |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 836 | wl_list_for_each(output, &desktop->outputs, link) { |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 837 | panel_add_launcher(output->panel, |
| 838 | key_launcher_icon, key_launcher_path); |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 839 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 840 | |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 841 | free(key_launcher_icon); |
| 842 | key_launcher_icon = NULL; |
| 843 | free(key_launcher_path); |
| 844 | key_launcher_path = NULL; |
| 845 | } |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 846 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 847 | static void |
| 848 | add_default_launcher(struct desktop *desktop) |
| 849 | { |
| 850 | struct output *output; |
| 851 | |
| 852 | wl_list_for_each(output, &desktop->outputs, link) |
| 853 | panel_add_launcher(output->panel, |
| 854 | DATADIR "/weston/terminal.png", |
Rodney Lorrimar | 99ff01b | 2012-02-29 17:31:03 +0100 | [diff] [blame] | 855 | BINDIR "/weston-terminal"); |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 856 | } |
| 857 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 858 | int main(int argc, char *argv[]) |
| 859 | { |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 860 | struct desktop desktop = { 0 }; |
Pekka Paalanen | 668dd56 | 2011-11-15 11:45:40 +0200 | [diff] [blame] | 861 | char *config_file; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 862 | struct output *output; |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 863 | int ret; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 864 | |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 865 | desktop.unlock_task.run = unlock_dialog_finish; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 866 | wl_list_init(&desktop.outputs); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 867 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 868 | desktop.display = display_create(argc, argv); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 869 | if (desktop.display == NULL) { |
| 870 | fprintf(stderr, "failed to create display: %m\n"); |
| 871 | return -1; |
| 872 | } |
| 873 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 874 | display_set_user_data(desktop.display, &desktop); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 875 | wl_display_add_global_listener(display_get_display(desktop.display), |
| 876 | global_handler, &desktop); |
| 877 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 878 | wl_list_for_each(output, &desktop.outputs, link) { |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame^] | 879 | struct wl_shell_surface *shsurf; |
| 880 | struct wl_surface *surface; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 881 | |
| 882 | output->panel = panel_create(desktop.display); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame^] | 883 | shsurf = window_get_wl_shell_surface(output->panel->window); |
| 884 | desktop_shell_set_panel(desktop.shell, output->output, shsurf); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 885 | |
| 886 | output->background = background_create(&desktop); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame^] | 887 | surface = window_get_wl_surface(output->background->window); |
| 888 | desktop_shell_set_background(desktop.shell, |
| 889 | output->output, surface); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 890 | } |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 891 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 892 | busy_surface_create(&desktop); |
| 893 | |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 894 | config_file = config_file_path("weston.ini"); |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 895 | ret = parse_config_file(config_file, |
| 896 | config_sections, ARRAY_LENGTH(config_sections), |
| 897 | &desktop); |
Pekka Paalanen | 668dd56 | 2011-11-15 11:45:40 +0200 | [diff] [blame] | 898 | free(config_file); |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 899 | if (ret < 0) |
| 900 | add_default_launcher(&desktop); |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 901 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 902 | signal(SIGCHLD, sigchild_handler); |
| 903 | |
| 904 | display_run(desktop.display); |
| 905 | |
| 906 | return 0; |
| 907 | } |