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