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> |
Kristian Høgsberg | d1936b9 | 2012-07-23 22:59:33 -0400 | [diff] [blame] | 37 | #include <ctype.h> |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 38 | #include <time.h> |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 39 | |
Pekka Paalanen | 50719bc | 2011-11-22 14:18:50 +0200 | [diff] [blame] | 40 | #include <wayland-client.h> |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 41 | #include "window.h" |
Kristian Høgsberg | 5a315bc | 2012-05-15 22:33:43 -0400 | [diff] [blame] | 42 | #include "../shared/cairo-util.h" |
Kristian Høgsberg | 9b935c8 | 2011-12-08 12:44:27 -0500 | [diff] [blame] | 43 | #include "../shared/config-parser.h" |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 44 | |
Pekka Paalanen | 50719bc | 2011-11-22 14:18:50 +0200 | [diff] [blame] | 45 | #include "desktop-shell-client-protocol.h" |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 46 | |
Pekka Paalanen | b6df4f7 | 2012-08-03 14:39:15 +0300 | [diff] [blame] | 47 | extern char **environ; /* defined by libc */ |
| 48 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 49 | struct desktop { |
| 50 | struct display *display; |
| 51 | struct desktop_shell *shell; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 52 | uint32_t interface_version; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 53 | struct unlock_dialog *unlock_dialog; |
| 54 | struct task unlock_task; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 55 | struct wl_list outputs; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 56 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 57 | struct window *grab_window; |
| 58 | struct widget *grab_widget; |
| 59 | |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 60 | struct weston_config *config; |
| 61 | int locking; |
| 62 | |
Scott Moreau | ec11602 | 2012-07-22 18:23:52 -0600 | [diff] [blame] | 63 | enum cursor_type grab_cursor; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 64 | |
| 65 | int painted; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | struct surface { |
| 69 | void (*configure)(void *data, |
| 70 | struct desktop_shell *desktop_shell, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 71 | uint32_t edges, struct window *window, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 72 | int32_t width, int32_t height); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | struct panel { |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 76 | struct surface base; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 77 | struct window *window; |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 78 | struct widget *widget; |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 79 | struct wl_list launcher_list; |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 80 | struct panel_clock *clock; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 81 | int painted; |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 82 | uint32_t color; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 83 | }; |
| 84 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 85 | struct background { |
| 86 | struct surface base; |
| 87 | struct window *window; |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 88 | struct widget *widget; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 89 | int painted; |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 90 | |
| 91 | char *image; |
| 92 | int type; |
| 93 | uint32_t color; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | struct output { |
| 97 | struct wl_output *output; |
| 98 | struct wl_list link; |
| 99 | |
| 100 | struct panel *panel; |
| 101 | struct background *background; |
| 102 | }; |
| 103 | |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 104 | struct panel_launcher { |
Kristian Høgsberg | c51f799 | 2012-01-08 15:09:53 -0500 | [diff] [blame] | 105 | struct widget *widget; |
Kristian Høgsberg | e28d05b | 2011-09-20 21:43:54 -0400 | [diff] [blame] | 106 | struct panel *panel; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 107 | cairo_surface_t *icon; |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 108 | int focused, pressed; |
Kristian Høgsberg | d1936b9 | 2012-07-23 22:59:33 -0400 | [diff] [blame] | 109 | char *path; |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 110 | struct wl_list link; |
Kristian Høgsberg | d1936b9 | 2012-07-23 22:59:33 -0400 | [diff] [blame] | 111 | struct wl_array envp; |
| 112 | struct wl_array argv; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 113 | }; |
| 114 | |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 115 | struct panel_clock { |
| 116 | struct widget *widget; |
| 117 | struct panel *panel; |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 118 | struct task clock_task; |
| 119 | int clock_fd; |
| 120 | }; |
| 121 | |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 122 | struct unlock_dialog { |
| 123 | struct window *window; |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 124 | struct widget *widget; |
Kristian Høgsberg | c51f799 | 2012-01-08 15:09:53 -0500 | [diff] [blame] | 125 | struct widget *button; |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 126 | int button_focused; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 127 | int closing; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 128 | struct desktop *desktop; |
| 129 | }; |
| 130 | |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 131 | static void |
| 132 | panel_add_launchers(struct panel *panel, struct desktop *desktop); |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 133 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 134 | static void |
| 135 | sigchild_handler(int s) |
| 136 | { |
| 137 | int status; |
| 138 | pid_t pid; |
| 139 | |
| 140 | while (pid = waitpid(-1, &status, WNOHANG), pid > 0) |
| 141 | fprintf(stderr, "child %d exited\n", pid); |
| 142 | } |
| 143 | |
| 144 | static void |
Pekka Paalanen | 9e30a82 | 2012-01-19 16:40:28 +0200 | [diff] [blame] | 145 | menu_func(struct window *window, int index, void *data) |
| 146 | { |
| 147 | printf("Selected index %d from a panel menu.\n", index); |
| 148 | } |
| 149 | |
| 150 | static void |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 151 | show_menu(struct panel *panel, struct input *input, uint32_t time) |
Kristian Høgsberg | bcee9a4 | 2011-10-12 00:36:16 -0400 | [diff] [blame] | 152 | { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 153 | int32_t x, y; |
| 154 | static const char *entries[] = { |
| 155 | "Roy", "Pris", "Leon", "Zhora" |
| 156 | }; |
Kristian Høgsberg | bcee9a4 | 2011-10-12 00:36:16 -0400 | [diff] [blame] | 157 | |
| 158 | input_get_position(input, &x, &y); |
Pekka Paalanen | 6d174cf | 2012-01-19 15:17:59 +0200 | [diff] [blame] | 159 | window_show_menu(window_get_display(panel->window), |
| 160 | input, time, panel->window, |
Pekka Paalanen | 9e30a82 | 2012-01-19 16:40:28 +0200 | [diff] [blame] | 161 | x - 10, y - 10, menu_func, entries, 4); |
Kristian Høgsberg | bcee9a4 | 2011-10-12 00:36:16 -0400 | [diff] [blame] | 162 | } |
| 163 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 164 | static int |
| 165 | is_desktop_painted(struct desktop *desktop) |
| 166 | { |
| 167 | struct output *output; |
| 168 | |
| 169 | wl_list_for_each(output, &desktop->outputs, link) { |
| 170 | if (output->panel && !output->panel->painted) |
| 171 | return 0; |
| 172 | if (output->background && !output->background->painted) |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | return 1; |
| 177 | } |
| 178 | |
| 179 | static void |
| 180 | check_desktop_ready(struct window *window) |
| 181 | { |
| 182 | struct display *display; |
| 183 | struct desktop *desktop; |
| 184 | |
| 185 | display = window_get_display(window); |
| 186 | desktop = display_get_user_data(display); |
| 187 | |
| 188 | if (!desktop->painted && is_desktop_painted(desktop)) { |
| 189 | desktop->painted = 1; |
| 190 | |
| 191 | if (desktop->interface_version >= 2) |
| 192 | desktop_shell_desktop_ready(desktop->shell); |
| 193 | } |
| 194 | } |
| 195 | |
Kristian Høgsberg | bcee9a4 | 2011-10-12 00:36:16 -0400 | [diff] [blame] | 196 | static void |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 197 | panel_launcher_activate(struct panel_launcher *widget) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 198 | { |
Kristian Høgsberg | d1936b9 | 2012-07-23 22:59:33 -0400 | [diff] [blame] | 199 | char **argv; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 200 | pid_t pid; |
| 201 | |
| 202 | pid = fork(); |
| 203 | if (pid < 0) { |
| 204 | fprintf(stderr, "fork failed: %m\n"); |
| 205 | return; |
| 206 | } |
| 207 | |
| 208 | if (pid) |
| 209 | return; |
Benjamin Franzke | d775971 | 2011-11-22 12:38:48 +0100 | [diff] [blame] | 210 | |
Kristian Høgsberg | d1936b9 | 2012-07-23 22:59:33 -0400 | [diff] [blame] | 211 | argv = widget->argv.data; |
| 212 | if (execve(argv[0], argv, widget->envp.data) < 0) { |
| 213 | fprintf(stderr, "execl '%s' failed: %m\n", argv[0]); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 214 | exit(1); |
| 215 | } |
| 216 | } |
| 217 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 218 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 219 | panel_launcher_redraw_handler(struct widget *widget, void *data) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 220 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 221 | struct panel_launcher *launcher = data; |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 222 | struct rectangle allocation; |
| 223 | cairo_t *cr; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 224 | |
Alexander Larsson | c584fa6 | 2013-05-22 14:41:32 +0200 | [diff] [blame] | 225 | cr = widget_cairo_create(launcher->panel->widget); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 226 | |
| 227 | widget_get_allocation(widget, &allocation); |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 228 | if (launcher->pressed) { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 229 | allocation.x++; |
| 230 | allocation.y++; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 231 | } |
| 232 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 233 | cairo_set_source_surface(cr, launcher->icon, |
| 234 | allocation.x, allocation.y); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 235 | cairo_paint(cr); |
| 236 | |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 237 | if (launcher->focused) { |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 238 | 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] | 239 | cairo_mask_surface(cr, launcher->icon, |
| 240 | allocation.x, allocation.y); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 241 | } |
Kristian Høgsberg | e28d05b | 2011-09-20 21:43:54 -0400 | [diff] [blame] | 242 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 243 | cairo_destroy(cr); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 244 | } |
| 245 | |
Tiago Vignatti | 6150072 | 2012-05-23 22:06:28 +0300 | [diff] [blame] | 246 | static int |
| 247 | panel_launcher_motion_handler(struct widget *widget, struct input *input, |
| 248 | uint32_t time, float x, float y, void *data) |
| 249 | { |
| 250 | struct panel_launcher *launcher = data; |
| 251 | |
| 252 | widget_set_tooltip(widget, basename((char *)launcher->path), x, y); |
| 253 | |
Ander Conselvan de Oliveira | dc8c8fc | 2012-05-25 16:01:41 +0300 | [diff] [blame] | 254 | return CURSOR_LEFT_PTR; |
Tiago Vignatti | 6150072 | 2012-05-23 22:06:28 +0300 | [diff] [blame] | 255 | } |
| 256 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 257 | static void |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 258 | set_hex_color(cairo_t *cr, uint32_t color) |
| 259 | { |
| 260 | cairo_set_source_rgba(cr, |
| 261 | ((color >> 16) & 0xff) / 255.0, |
| 262 | ((color >> 8) & 0xff) / 255.0, |
| 263 | ((color >> 0) & 0xff) / 255.0, |
| 264 | ((color >> 24) & 0xff) / 255.0); |
| 265 | } |
| 266 | |
| 267 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 268 | panel_redraw_handler(struct widget *widget, void *data) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 269 | { |
| 270 | cairo_surface_t *surface; |
| 271 | cairo_t *cr; |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 272 | struct panel *panel = data; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 273 | |
Alexander Larsson | c584fa6 | 2013-05-22 14:41:32 +0200 | [diff] [blame] | 274 | cr = widget_cairo_create(panel->widget); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 275 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 276 | set_hex_color(cr, panel->color); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 277 | cairo_paint(cr); |
| 278 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 279 | cairo_destroy(cr); |
Alexander Larsson | c584fa6 | 2013-05-22 14:41:32 +0200 | [diff] [blame] | 280 | surface = window_get_surface(panel->window); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 281 | cairo_surface_destroy(surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 282 | panel->painted = 1; |
| 283 | check_desktop_ready(panel->window); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 284 | } |
| 285 | |
Kristian Høgsberg | bb901fa | 2012-01-09 11:22:32 -0500 | [diff] [blame] | 286 | static int |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 287 | panel_launcher_enter_handler(struct widget *widget, struct input *input, |
Kristian Høgsberg | 80680c7 | 2012-05-10 12:21:37 -0400 | [diff] [blame] | 288 | float x, float y, void *data) |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 289 | { |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 290 | struct panel_launcher *launcher = data; |
| 291 | |
| 292 | launcher->focused = 1; |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 293 | widget_schedule_redraw(widget); |
Kristian Høgsberg | bb901fa | 2012-01-09 11:22:32 -0500 | [diff] [blame] | 294 | |
Ander Conselvan de Oliveira | dc8c8fc | 2012-05-25 16:01:41 +0300 | [diff] [blame] | 295 | return CURSOR_LEFT_PTR; |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | static void |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 299 | panel_launcher_leave_handler(struct widget *widget, |
| 300 | struct input *input, void *data) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 301 | { |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 302 | struct panel_launcher *launcher = data; |
| 303 | |
| 304 | launcher->focused = 0; |
Tiago Vignatti | 6150072 | 2012-05-23 22:06:28 +0300 | [diff] [blame] | 305 | widget_destroy_tooltip(widget); |
Kristian Høgsberg | 9a13dab | 2012-01-08 15:18:19 -0500 | [diff] [blame] | 306 | widget_schedule_redraw(widget); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | static void |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 310 | panel_launcher_button_handler(struct widget *widget, |
| 311 | struct input *input, uint32_t time, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 312 | uint32_t button, |
| 313 | enum wl_pointer_button_state state, void *data) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 314 | { |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 315 | struct panel_launcher *launcher; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 316 | |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 317 | launcher = widget_get_user_data(widget); |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 318 | widget_schedule_redraw(widget); |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 319 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 320 | panel_launcher_activate(launcher); |
Rusty Lynch | 4384a24 | 2013-08-08 21:28:22 -0700 | [diff] [blame^] | 321 | |
| 322 | } |
| 323 | |
| 324 | static void |
| 325 | panel_launcher_touch_down_handler(struct widget *widget, uint32_t serial, |
| 326 | uint32_t time, int32_t id, |
| 327 | float x, float y, void *data) |
| 328 | { |
| 329 | struct panel_launcher *launcher; |
| 330 | |
| 331 | launcher = widget_get_user_data(widget); |
| 332 | launcher->focused = 1; |
| 333 | widget_schedule_redraw(widget); |
| 334 | } |
| 335 | |
| 336 | static void |
| 337 | panel_launcher_touch_up_handler(struct widget *widget, uint32_t serial, |
| 338 | uint32_t time, int32_t id, void *data) |
| 339 | { |
| 340 | struct panel_launcher *launcher; |
| 341 | |
| 342 | launcher = widget_get_user_data(widget); |
| 343 | launcher->focused = 0; |
| 344 | widget_schedule_redraw(widget); |
| 345 | panel_launcher_activate(launcher); |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 346 | } |
| 347 | |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 348 | static void |
| 349 | clock_func(struct task *task, uint32_t events) |
| 350 | { |
| 351 | struct panel_clock *clock = |
Kristian Høgsberg | bb262cf | 2012-06-11 11:03:03 -0400 | [diff] [blame] | 352 | container_of(task, struct panel_clock, clock_task); |
Kristian Høgsberg | 70226bb | 2012-06-08 16:54:52 -0400 | [diff] [blame] | 353 | uint64_t exp; |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 354 | |
Martin Olsson | 8df662a | 2012-07-08 03:03:47 +0200 | [diff] [blame] | 355 | if (read(clock->clock_fd, &exp, sizeof exp) != sizeof exp) |
| 356 | abort(); |
Kristian Høgsberg | 92a984a | 2012-06-11 11:10:57 -0400 | [diff] [blame] | 357 | widget_schedule_redraw(clock->widget); |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | static void |
| 361 | panel_clock_redraw_handler(struct widget *widget, void *data) |
| 362 | { |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 363 | struct panel_clock *clock = data; |
| 364 | cairo_t *cr; |
| 365 | struct rectangle allocation; |
| 366 | cairo_text_extents_t extents; |
| 367 | cairo_font_extents_t font_extents; |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 368 | time_t rawtime; |
| 369 | struct tm * timeinfo; |
Kristian Høgsberg | 92a984a | 2012-06-11 11:10:57 -0400 | [diff] [blame] | 370 | char string[128]; |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 371 | |
Kristian Høgsberg | bb262cf | 2012-06-11 11:03:03 -0400 | [diff] [blame] | 372 | time(&rawtime); |
| 373 | timeinfo = localtime(&rawtime); |
Kristian Høgsberg | e9f68f6 | 2012-06-11 12:24:12 -0400 | [diff] [blame] | 374 | strftime(string, sizeof string, "%a %b %d, %I:%M %p", timeinfo); |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 375 | |
| 376 | widget_get_allocation(widget, &allocation); |
Kristian Høgsberg | bb262cf | 2012-06-11 11:03:03 -0400 | [diff] [blame] | 377 | if (allocation.width == 0) |
| 378 | return; |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 379 | |
Alexander Larsson | c584fa6 | 2013-05-22 14:41:32 +0200 | [diff] [blame] | 380 | cr = widget_cairo_create(clock->panel->widget); |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 381 | cairo_select_font_face(cr, "sans", |
| 382 | CAIRO_FONT_SLANT_NORMAL, |
| 383 | CAIRO_FONT_WEIGHT_NORMAL); |
| 384 | cairo_set_font_size(cr, 14); |
Kristian Høgsberg | 92a984a | 2012-06-11 11:10:57 -0400 | [diff] [blame] | 385 | cairo_text_extents(cr, string, &extents); |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 386 | cairo_font_extents (cr, &font_extents); |
Kristian Høgsberg | bb262cf | 2012-06-11 11:03:03 -0400 | [diff] [blame] | 387 | cairo_move_to(cr, allocation.x + 5, |
| 388 | allocation.y + 3 * (allocation.height >> 2) + 1); |
| 389 | cairo_set_source_rgb(cr, 0, 0, 0); |
Kristian Høgsberg | 92a984a | 2012-06-11 11:10:57 -0400 | [diff] [blame] | 390 | cairo_show_text(cr, string); |
Kristian Høgsberg | bb262cf | 2012-06-11 11:03:03 -0400 | [diff] [blame] | 391 | cairo_move_to(cr, allocation.x + 4, |
| 392 | allocation.y + 3 * (allocation.height >> 2)); |
| 393 | cairo_set_source_rgb(cr, 1, 1, 1); |
Kristian Høgsberg | 92a984a | 2012-06-11 11:10:57 -0400 | [diff] [blame] | 394 | cairo_show_text(cr, string); |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 395 | cairo_destroy(cr); |
| 396 | } |
| 397 | |
| 398 | static int |
| 399 | clock_timer_reset(struct panel_clock *clock) |
| 400 | { |
| 401 | struct itimerspec its; |
Kristian Høgsberg | bb262cf | 2012-06-11 11:03:03 -0400 | [diff] [blame] | 402 | |
Kristian Høgsberg | e9f68f6 | 2012-06-11 12:24:12 -0400 | [diff] [blame] | 403 | its.it_interval.tv_sec = 60; |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 404 | its.it_interval.tv_nsec = 0; |
Kristian Høgsberg | e9f68f6 | 2012-06-11 12:24:12 -0400 | [diff] [blame] | 405 | its.it_value.tv_sec = 60; |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 406 | its.it_value.tv_nsec = 0; |
| 407 | if (timerfd_settime(clock->clock_fd, 0, &its, NULL) < 0) { |
| 408 | fprintf(stderr, "could not set timerfd\n: %m"); |
| 409 | return -1; |
| 410 | } |
| 411 | |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | static void |
U. Artie Eoff | 44874d9 | 2012-10-02 21:12:35 -0700 | [diff] [blame] | 416 | panel_destroy_clock(struct panel_clock *clock) |
| 417 | { |
| 418 | widget_destroy(clock->widget); |
| 419 | |
| 420 | close(clock->clock_fd); |
| 421 | |
| 422 | free(clock); |
| 423 | } |
| 424 | |
| 425 | static void |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 426 | panel_add_clock(struct panel *panel) |
| 427 | { |
| 428 | struct panel_clock *clock; |
| 429 | int timerfd; |
| 430 | |
| 431 | timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC); |
| 432 | if (timerfd < 0) { |
| 433 | fprintf(stderr, "could not create timerfd\n: %m"); |
| 434 | return; |
| 435 | } |
| 436 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 437 | clock = xzalloc(sizeof *clock); |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 438 | clock->panel = panel; |
| 439 | panel->clock = clock; |
| 440 | clock->clock_fd = timerfd; |
| 441 | |
| 442 | clock->clock_task.run = clock_func; |
Kristian Høgsberg | bb262cf | 2012-06-11 11:03:03 -0400 | [diff] [blame] | 443 | display_watch_fd(window_get_display(panel->window), clock->clock_fd, |
| 444 | EPOLLIN, &clock->clock_task); |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 445 | clock_timer_reset(clock); |
| 446 | |
| 447 | clock->widget = widget_add_widget(panel->widget, clock); |
Kristian Høgsberg | bb262cf | 2012-06-11 11:03:03 -0400 | [diff] [blame] | 448 | widget_set_redraw_handler(clock->widget, panel_clock_redraw_handler); |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 449 | } |
| 450 | |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 451 | static void |
| 452 | panel_button_handler(struct widget *widget, |
| 453 | struct input *input, uint32_t time, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 454 | uint32_t button, |
| 455 | enum wl_pointer_button_state state, void *data) |
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 | struct panel *panel = data; |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 458 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 459 | if (button == BTN_RIGHT && state == WL_POINTER_BUTTON_STATE_PRESSED) |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 460 | show_menu(panel, input, time); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 461 | } |
| 462 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 463 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 464 | panel_resize_handler(struct widget *widget, |
| 465 | int32_t width, int32_t height, void *data) |
| 466 | { |
| 467 | struct panel_launcher *launcher; |
| 468 | struct panel *panel = data; |
| 469 | int x, y, w, h; |
| 470 | |
| 471 | x = 10; |
| 472 | y = 16; |
| 473 | wl_list_for_each(launcher, &panel->launcher_list, link) { |
| 474 | w = cairo_image_surface_get_width(launcher->icon); |
| 475 | h = cairo_image_surface_get_height(launcher->icon); |
| 476 | widget_set_allocation(launcher->widget, |
| 477 | x, y - h / 2, w + 1, h + 1); |
| 478 | x += w + 10; |
| 479 | } |
Martin Minarik | 1e51a87 | 2012-06-08 00:39:11 +0200 | [diff] [blame] | 480 | h=20; |
| 481 | w=170; |
Pekka Paalanen | 01b1725 | 2012-06-12 17:42:26 +0300 | [diff] [blame] | 482 | |
| 483 | if (panel->clock) |
| 484 | widget_set_allocation(panel->clock->widget, |
| 485 | width - w - 8, y - h / 2, w + 1, h + 1); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | static void |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 489 | panel_configure(void *data, |
| 490 | struct desktop_shell *desktop_shell, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 491 | uint32_t edges, struct window *window, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 492 | int32_t width, int32_t height) |
| 493 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 494 | struct surface *surface = window_get_user_data(window); |
| 495 | struct panel *panel = container_of(surface, struct panel, base); |
| 496 | |
| 497 | window_schedule_resize(panel->window, width, 32); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 498 | } |
| 499 | |
U. Artie Eoff | 44874d9 | 2012-10-02 21:12:35 -0700 | [diff] [blame] | 500 | static void |
| 501 | panel_destroy_launcher(struct panel_launcher *launcher) |
| 502 | { |
| 503 | wl_array_release(&launcher->argv); |
| 504 | wl_array_release(&launcher->envp); |
| 505 | |
| 506 | free(launcher->path); |
| 507 | |
| 508 | cairo_surface_destroy(launcher->icon); |
| 509 | |
| 510 | widget_destroy(launcher->widget); |
| 511 | wl_list_remove(&launcher->link); |
| 512 | |
| 513 | free(launcher); |
| 514 | } |
| 515 | |
| 516 | static void |
| 517 | panel_destroy(struct panel *panel) |
| 518 | { |
| 519 | struct panel_launcher *tmp; |
| 520 | struct panel_launcher *launcher; |
| 521 | |
| 522 | panel_destroy_clock(panel->clock); |
| 523 | |
| 524 | wl_list_for_each_safe(launcher, tmp, &panel->launcher_list, link) |
| 525 | panel_destroy_launcher(launcher); |
| 526 | |
| 527 | widget_destroy(panel->widget); |
| 528 | window_destroy(panel->window); |
| 529 | |
| 530 | free(panel); |
| 531 | } |
| 532 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 533 | static struct panel * |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 534 | panel_create(struct desktop *desktop) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 535 | { |
| 536 | struct panel *panel; |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 537 | struct weston_config_section *s; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 538 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 539 | panel = xzalloc(sizeof *panel); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 540 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 541 | panel->base.configure = panel_configure; |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 542 | panel->window = window_create_custom(desktop->display); |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 543 | panel->widget = window_add_widget(panel->window, panel); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 544 | wl_list_init(&panel->launcher_list); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 545 | |
| 546 | window_set_title(panel->window, "panel"); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 547 | window_set_user_data(panel->window, panel); |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 548 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 549 | widget_set_redraw_handler(panel->widget, panel_redraw_handler); |
| 550 | widget_set_resize_handler(panel->widget, panel_resize_handler); |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 551 | widget_set_button_handler(panel->widget, panel_button_handler); |
Rafal Mielniczuk | b9e513c | 2012-06-09 20:33:29 +0200 | [diff] [blame] | 552 | |
| 553 | panel_add_clock(panel); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 554 | |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 555 | s = weston_config_get_section(desktop->config, "shell", NULL, NULL); |
| 556 | weston_config_section_get_uint(s, "panel-color", |
| 557 | &panel->color, 0xaa000000); |
| 558 | |
| 559 | panel_add_launchers(panel, desktop); |
| 560 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 561 | return panel; |
| 562 | } |
| 563 | |
Philipp Brüschweiler | 467668c | 2012-08-29 10:53:36 +0200 | [diff] [blame] | 564 | static cairo_surface_t * |
| 565 | load_icon_or_fallback(const char *icon) |
| 566 | { |
| 567 | cairo_surface_t *surface = cairo_image_surface_create_from_png(icon); |
Philipp Brüschweiler | 96386b8 | 2013-04-15 20:10:40 +0200 | [diff] [blame] | 568 | cairo_status_t status; |
Philipp Brüschweiler | 467668c | 2012-08-29 10:53:36 +0200 | [diff] [blame] | 569 | cairo_t *cr; |
| 570 | |
Philipp Brüschweiler | 96386b8 | 2013-04-15 20:10:40 +0200 | [diff] [blame] | 571 | status = cairo_surface_status(surface); |
| 572 | if (status == CAIRO_STATUS_SUCCESS) |
Philipp Brüschweiler | 467668c | 2012-08-29 10:53:36 +0200 | [diff] [blame] | 573 | return surface; |
| 574 | |
| 575 | cairo_surface_destroy(surface); |
Philipp Brüschweiler | 96386b8 | 2013-04-15 20:10:40 +0200 | [diff] [blame] | 576 | fprintf(stderr, "ERROR loading icon from file '%s', error: '%s'\n", |
| 577 | icon, cairo_status_to_string(status)); |
Philipp Brüschweiler | 467668c | 2012-08-29 10:53:36 +0200 | [diff] [blame] | 578 | |
| 579 | /* draw fallback icon */ |
| 580 | surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 581 | 20, 20); |
| 582 | cr = cairo_create(surface); |
| 583 | |
| 584 | cairo_set_source_rgba(cr, 0.8, 0.8, 0.8, 1); |
| 585 | cairo_paint(cr); |
| 586 | |
| 587 | cairo_set_source_rgba(cr, 0, 0, 0, 1); |
| 588 | cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); |
| 589 | cairo_rectangle(cr, 0, 0, 20, 20); |
| 590 | cairo_move_to(cr, 4, 4); |
| 591 | cairo_line_to(cr, 16, 16); |
| 592 | cairo_move_to(cr, 4, 16); |
| 593 | cairo_line_to(cr, 16, 4); |
| 594 | cairo_stroke(cr); |
| 595 | |
| 596 | cairo_destroy(cr); |
| 597 | |
| 598 | return surface; |
| 599 | } |
| 600 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 601 | static void |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 602 | 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] | 603 | { |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 604 | struct panel_launcher *launcher; |
Kristian Høgsberg | d1936b9 | 2012-07-23 22:59:33 -0400 | [diff] [blame] | 605 | char *start, *p, *eq, **ps; |
| 606 | int i, j, k; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 607 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 608 | launcher = xzalloc(sizeof *launcher); |
Philipp Brüschweiler | 467668c | 2012-08-29 10:53:36 +0200 | [diff] [blame] | 609 | launcher->icon = load_icon_or_fallback(icon); |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 610 | launcher->path = strdup(path); |
Kristian Høgsberg | d1936b9 | 2012-07-23 22:59:33 -0400 | [diff] [blame] | 611 | |
| 612 | wl_array_init(&launcher->envp); |
| 613 | wl_array_init(&launcher->argv); |
Pekka Paalanen | b6df4f7 | 2012-08-03 14:39:15 +0300 | [diff] [blame] | 614 | for (i = 0; environ[i]; i++) { |
Kristian Høgsberg | d1936b9 | 2012-07-23 22:59:33 -0400 | [diff] [blame] | 615 | ps = wl_array_add(&launcher->envp, sizeof *ps); |
Pekka Paalanen | b6df4f7 | 2012-08-03 14:39:15 +0300 | [diff] [blame] | 616 | *ps = environ[i]; |
Kristian Høgsberg | d1936b9 | 2012-07-23 22:59:33 -0400 | [diff] [blame] | 617 | } |
| 618 | j = 0; |
| 619 | |
| 620 | start = launcher->path; |
| 621 | while (*start) { |
| 622 | for (p = start, eq = NULL; *p && !isspace(*p); p++) |
| 623 | if (*p == '=') |
| 624 | eq = p; |
| 625 | |
| 626 | if (eq && j == 0) { |
| 627 | ps = launcher->envp.data; |
| 628 | for (k = 0; k < i; k++) |
| 629 | if (strncmp(ps[k], start, eq - start) == 0) { |
| 630 | ps[k] = start; |
| 631 | break; |
| 632 | } |
| 633 | if (k == i) { |
| 634 | ps = wl_array_add(&launcher->envp, sizeof *ps); |
| 635 | *ps = start; |
| 636 | i++; |
| 637 | } |
| 638 | } else { |
| 639 | ps = wl_array_add(&launcher->argv, sizeof *ps); |
| 640 | *ps = start; |
| 641 | j++; |
| 642 | } |
| 643 | |
| 644 | while (*p && isspace(*p)) |
| 645 | *p++ = '\0'; |
| 646 | |
| 647 | start = p; |
| 648 | } |
| 649 | |
| 650 | ps = wl_array_add(&launcher->envp, sizeof *ps); |
| 651 | *ps = NULL; |
| 652 | ps = wl_array_add(&launcher->argv, sizeof *ps); |
| 653 | *ps = NULL; |
| 654 | |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 655 | launcher->panel = panel; |
Kristian Høgsberg | 75bc667 | 2012-01-10 09:43:58 -0500 | [diff] [blame] | 656 | wl_list_insert(panel->launcher_list.prev, &launcher->link); |
| 657 | |
Kristian Høgsberg | 441338c | 2012-01-10 13:52:34 -0500 | [diff] [blame] | 658 | launcher->widget = widget_add_widget(panel->widget, launcher); |
Kristian Høgsberg | 5388080 | 2012-01-09 11:16:50 -0500 | [diff] [blame] | 659 | widget_set_enter_handler(launcher->widget, |
| 660 | panel_launcher_enter_handler); |
| 661 | widget_set_leave_handler(launcher->widget, |
| 662 | panel_launcher_leave_handler); |
| 663 | widget_set_button_handler(launcher->widget, |
| 664 | panel_launcher_button_handler); |
Rusty Lynch | 4384a24 | 2013-08-08 21:28:22 -0700 | [diff] [blame^] | 665 | widget_set_touch_down_handler(launcher->widget, |
| 666 | panel_launcher_touch_down_handler); |
| 667 | widget_set_touch_up_handler(launcher->widget, |
| 668 | panel_launcher_touch_up_handler); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 669 | widget_set_redraw_handler(launcher->widget, |
| 670 | panel_launcher_redraw_handler); |
Tiago Vignatti | 6150072 | 2012-05-23 22:06:28 +0300 | [diff] [blame] | 671 | widget_set_motion_handler(launcher->widget, |
| 672 | panel_launcher_motion_handler); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 673 | } |
| 674 | |
Kristian Høgsberg | 07f7294 | 2012-01-25 16:34:36 -0500 | [diff] [blame] | 675 | enum { |
| 676 | BACKGROUND_SCALE, |
Pekka Paalanen | a402b05 | 2013-05-22 18:03:10 +0300 | [diff] [blame] | 677 | BACKGROUND_SCALE_CROP, |
Kristian Høgsberg | 07f7294 | 2012-01-25 16:34:36 -0500 | [diff] [blame] | 678 | BACKGROUND_TILE |
| 679 | }; |
| 680 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 681 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 682 | background_draw(struct widget *widget, void *data) |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 683 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 684 | struct background *background = data; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 685 | cairo_surface_t *surface, *image; |
Kristian Høgsberg | 7e69000 | 2011-09-08 18:18:02 -0400 | [diff] [blame] | 686 | cairo_pattern_t *pattern; |
| 687 | cairo_matrix_t matrix; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 688 | cairo_t *cr; |
Pekka Paalanen | a402b05 | 2013-05-22 18:03:10 +0300 | [diff] [blame] | 689 | double im_w, im_h; |
| 690 | double sx, sy, s; |
| 691 | double tx, ty; |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 692 | struct rectangle allocation; |
Pekka Paalanen | 9564c75 | 2012-10-24 09:43:08 +0300 | [diff] [blame] | 693 | struct display *display; |
| 694 | struct wl_region *opaque; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 695 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 696 | surface = window_get_surface(background->window); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 697 | |
Alexander Larsson | c584fa6 | 2013-05-22 14:41:32 +0200 | [diff] [blame] | 698 | cr = widget_cairo_create(background->widget); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 699 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
| 700 | cairo_set_source_rgba(cr, 0.0, 0.0, 0.2, 1.0); |
| 701 | cairo_paint(cr); |
| 702 | |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 703 | widget_get_allocation(widget, &allocation); |
Kristian Høgsberg | 8129bc0 | 2012-01-25 14:55:33 -0500 | [diff] [blame] | 704 | image = NULL; |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 705 | if (background->image) |
| 706 | image = load_cairo_surface(background->image); |
Kristian Høgsberg | 07f7294 | 2012-01-25 16:34:36 -0500 | [diff] [blame] | 707 | |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 708 | if (image && background->type != -1) { |
Pekka Paalanen | a402b05 | 2013-05-22 18:03:10 +0300 | [diff] [blame] | 709 | im_w = cairo_image_surface_get_width(image); |
| 710 | im_h = cairo_image_surface_get_height(image); |
| 711 | sx = im_w / allocation.width; |
| 712 | sy = im_h / allocation.height; |
| 713 | |
Kristian Høgsberg | 7e69000 | 2011-09-08 18:18:02 -0400 | [diff] [blame] | 714 | pattern = cairo_pattern_create_for_surface(image); |
Pekka Paalanen | a402b05 | 2013-05-22 18:03:10 +0300 | [diff] [blame] | 715 | |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 716 | switch (background->type) { |
Kristian Høgsberg | 07f7294 | 2012-01-25 16:34:36 -0500 | [diff] [blame] | 717 | case BACKGROUND_SCALE: |
Kristian Høgsberg | 07f7294 | 2012-01-25 16:34:36 -0500 | [diff] [blame] | 718 | cairo_matrix_init_scale(&matrix, sx, sy); |
| 719 | cairo_pattern_set_matrix(pattern, &matrix); |
| 720 | break; |
Pekka Paalanen | a402b05 | 2013-05-22 18:03:10 +0300 | [diff] [blame] | 721 | case BACKGROUND_SCALE_CROP: |
| 722 | s = (sx < sy) ? sx : sy; |
| 723 | /* align center */ |
| 724 | tx = (im_w - s * allocation.width) * 0.5; |
| 725 | ty = (im_h - s * allocation.height) * 0.5; |
| 726 | cairo_matrix_init_translate(&matrix, tx, ty); |
| 727 | cairo_matrix_scale(&matrix, s, s); |
| 728 | cairo_pattern_set_matrix(pattern, &matrix); |
| 729 | break; |
Kristian Høgsberg | 07f7294 | 2012-01-25 16:34:36 -0500 | [diff] [blame] | 730 | case BACKGROUND_TILE: |
| 731 | cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); |
| 732 | break; |
| 733 | } |
Pekka Paalanen | a402b05 | 2013-05-22 18:03:10 +0300 | [diff] [blame] | 734 | |
Kristian Høgsberg | 7e69000 | 2011-09-08 18:18:02 -0400 | [diff] [blame] | 735 | cairo_set_source(cr, pattern); |
| 736 | cairo_pattern_destroy (pattern); |
Kristian Høgsberg | 27d3866 | 2011-10-20 13:11:12 -0400 | [diff] [blame] | 737 | cairo_surface_destroy(image); |
Kristian Høgsberg | 8129bc0 | 2012-01-25 14:55:33 -0500 | [diff] [blame] | 738 | } else { |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 739 | set_hex_color(cr, background->color); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 740 | } |
| 741 | |
Kristian Høgsberg | 8129bc0 | 2012-01-25 14:55:33 -0500 | [diff] [blame] | 742 | cairo_paint(cr); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 743 | cairo_destroy(cr); |
| 744 | cairo_surface_destroy(surface); |
Pekka Paalanen | 9564c75 | 2012-10-24 09:43:08 +0300 | [diff] [blame] | 745 | |
| 746 | display = window_get_display(background->window); |
| 747 | opaque = wl_compositor_create_region(display_get_compositor(display)); |
| 748 | wl_region_add(opaque, allocation.x, allocation.y, |
| 749 | allocation.width, allocation.height); |
| 750 | wl_surface_set_opaque_region(window_get_wl_surface(background->window), opaque); |
| 751 | wl_region_destroy(opaque); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 752 | |
| 753 | background->painted = 1; |
| 754 | check_desktop_ready(background->window); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | static void |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 758 | background_configure(void *data, |
| 759 | struct desktop_shell *desktop_shell, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 760 | uint32_t edges, struct window *window, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 761 | int32_t width, int32_t height) |
| 762 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 763 | struct background *background = |
| 764 | (struct background *) window_get_user_data(window); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 765 | |
Kristian Høgsberg | bb97700 | 2012-01-10 19:11:42 -0500 | [diff] [blame] | 766 | widget_schedule_resize(background->widget, width, height); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | static void |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 770 | unlock_dialog_redraw_handler(struct widget *widget, void *data) |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 771 | { |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 772 | struct unlock_dialog *dialog = data; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 773 | struct rectangle allocation; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 774 | cairo_surface_t *surface; |
Alexander Larsson | c584fa6 | 2013-05-22 14:41:32 +0200 | [diff] [blame] | 775 | cairo_t *cr; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 776 | cairo_pattern_t *pat; |
| 777 | double cx, cy, r, f; |
| 778 | |
Alexander Larsson | c584fa6 | 2013-05-22 14:41:32 +0200 | [diff] [blame] | 779 | cr = widget_cairo_create(widget); |
Kristian Høgsberg | 41c5c4e | 2012-03-05 20:37:51 -0500 | [diff] [blame] | 780 | |
Kristian Høgsberg | bb97700 | 2012-01-10 19:11:42 -0500 | [diff] [blame] | 781 | widget_get_allocation(dialog->widget, &allocation); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 782 | cairo_rectangle(cr, allocation.x, allocation.y, |
| 783 | allocation.width, allocation.height); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 784 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
| 785 | cairo_set_source_rgba(cr, 0, 0, 0, 0.6); |
Kristian Høgsberg | 41c5c4e | 2012-03-05 20:37:51 -0500 | [diff] [blame] | 786 | cairo_fill(cr); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 787 | |
Kristian Høgsberg | 41c5c4e | 2012-03-05 20:37:51 -0500 | [diff] [blame] | 788 | cairo_translate(cr, allocation.x, allocation.y); |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 789 | if (dialog->button_focused) |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 790 | f = 1.0; |
| 791 | else |
| 792 | f = 0.7; |
| 793 | |
| 794 | cx = allocation.width / 2.0; |
| 795 | cy = allocation.height / 2.0; |
| 796 | r = (cx < cy ? cx : cy) * 0.4; |
| 797 | pat = cairo_pattern_create_radial(cx, cy, r * 0.7, cx, cy, r); |
| 798 | cairo_pattern_add_color_stop_rgb(pat, 0.0, 0, 0.86 * f, 0); |
| 799 | cairo_pattern_add_color_stop_rgb(pat, 0.85, 0.2 * f, f, 0.2 * f); |
| 800 | cairo_pattern_add_color_stop_rgb(pat, 1.0, 0, 0.86 * f, 0); |
| 801 | cairo_set_source(cr, pat); |
Kristian Høgsberg | 41c5c4e | 2012-03-05 20:37:51 -0500 | [diff] [blame] | 802 | cairo_pattern_destroy(pat); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 803 | cairo_arc(cr, cx, cy, r, 0.0, 2.0 * M_PI); |
| 804 | cairo_fill(cr); |
| 805 | |
Kristian Høgsberg | c51f799 | 2012-01-08 15:09:53 -0500 | [diff] [blame] | 806 | widget_set_allocation(dialog->button, |
Kristian Høgsberg | 41c5c4e | 2012-03-05 20:37:51 -0500 | [diff] [blame] | 807 | allocation.x + cx - r, |
| 808 | allocation.y + cy - r, 2 * r, 2 * r); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 809 | |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 810 | cairo_destroy(cr); |
| 811 | |
Alexander Larsson | c584fa6 | 2013-05-22 14:41:32 +0200 | [diff] [blame] | 812 | surface = window_get_surface(dialog->window); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 813 | cairo_surface_destroy(surface); |
| 814 | } |
| 815 | |
| 816 | static void |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 817 | unlock_dialog_button_handler(struct widget *widget, |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 818 | struct input *input, uint32_t time, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 819 | uint32_t button, |
| 820 | enum wl_pointer_button_state state, void *data) |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 821 | { |
| 822 | struct unlock_dialog *dialog = data; |
| 823 | struct desktop *desktop = dialog->desktop; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 824 | |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 825 | if (button == BTN_LEFT) { |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 826 | if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
| 827 | !dialog->closing) { |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 828 | display_defer(desktop->display, &desktop->unlock_task); |
| 829 | dialog->closing = 1; |
| 830 | } |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | static void |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 835 | unlock_dialog_keyboard_focus_handler(struct window *window, |
| 836 | struct input *device, void *data) |
| 837 | { |
| 838 | window_schedule_redraw(window); |
| 839 | } |
| 840 | |
Kristian Høgsberg | bb901fa | 2012-01-09 11:22:32 -0500 | [diff] [blame] | 841 | static int |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 842 | unlock_dialog_widget_enter_handler(struct widget *widget, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 843 | struct input *input, |
Kristian Høgsberg | 80680c7 | 2012-05-10 12:21:37 -0400 | [diff] [blame] | 844 | float x, float y, void *data) |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 845 | { |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 846 | struct unlock_dialog *dialog = data; |
| 847 | |
| 848 | dialog->button_focused = 1; |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 849 | widget_schedule_redraw(widget); |
Kristian Høgsberg | bb901fa | 2012-01-09 11:22:32 -0500 | [diff] [blame] | 850 | |
Ander Conselvan de Oliveira | dc8c8fc | 2012-05-25 16:01:41 +0300 | [diff] [blame] | 851 | return CURSOR_LEFT_PTR; |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | static void |
| 855 | unlock_dialog_widget_leave_handler(struct widget *widget, |
| 856 | struct input *input, void *data) |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 857 | { |
Kristian Høgsberg | b632351 | 2012-01-11 00:04:42 -0500 | [diff] [blame] | 858 | struct unlock_dialog *dialog = data; |
| 859 | |
| 860 | dialog->button_focused = 0; |
Kristian Høgsberg | 9a13dab | 2012-01-08 15:18:19 -0500 | [diff] [blame] | 861 | widget_schedule_redraw(widget); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | static struct unlock_dialog * |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 865 | unlock_dialog_create(struct desktop *desktop) |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 866 | { |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 867 | struct display *display = desktop->display; |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 868 | struct unlock_dialog *dialog; |
| 869 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 870 | dialog = xzalloc(sizeof *dialog); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 871 | |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 872 | dialog->window = window_create_custom(display); |
Kristian Høgsberg | 29af3eb | 2012-01-10 22:41:05 -0500 | [diff] [blame] | 873 | dialog->widget = frame_create(dialog->window, dialog); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 874 | window_set_title(dialog->window, "Unlock your desktop"); |
| 875 | |
| 876 | window_set_user_data(dialog->window, dialog); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 877 | window_set_keyboard_focus_handler(dialog->window, |
| 878 | unlock_dialog_keyboard_focus_handler); |
Kristian Høgsberg | 441338c | 2012-01-10 13:52:34 -0500 | [diff] [blame] | 879 | dialog->button = widget_add_widget(dialog->widget, dialog); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 880 | widget_set_redraw_handler(dialog->widget, |
| 881 | unlock_dialog_redraw_handler); |
Kristian Høgsberg | ee14323 | 2012-01-09 08:42:24 -0500 | [diff] [blame] | 882 | widget_set_enter_handler(dialog->button, |
| 883 | unlock_dialog_widget_enter_handler); |
| 884 | widget_set_leave_handler(dialog->button, |
| 885 | unlock_dialog_widget_leave_handler); |
Kristian Høgsberg | a8a0db3 | 2012-01-09 11:12:05 -0500 | [diff] [blame] | 886 | widget_set_button_handler(dialog->button, |
| 887 | unlock_dialog_button_handler); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 888 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 889 | desktop_shell_set_lock_surface(desktop->shell, |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 890 | window_get_wl_surface(dialog->window)); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 891 | |
Pekka Paalanen | 40e49ac | 2012-01-18 16:51:30 +0200 | [diff] [blame] | 892 | window_schedule_resize(dialog->window, 260, 230); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 893 | |
| 894 | return dialog; |
| 895 | } |
| 896 | |
| 897 | static void |
| 898 | unlock_dialog_destroy(struct unlock_dialog *dialog) |
| 899 | { |
| 900 | window_destroy(dialog->window); |
| 901 | free(dialog); |
| 902 | } |
| 903 | |
| 904 | static void |
| 905 | unlock_dialog_finish(struct task *task, uint32_t events) |
| 906 | { |
| 907 | struct desktop *desktop = |
Benjamin Franzke | d775971 | 2011-11-22 12:38:48 +0100 | [diff] [blame] | 908 | container_of(task, struct desktop, unlock_task); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 909 | |
| 910 | desktop_shell_unlock(desktop->shell); |
| 911 | unlock_dialog_destroy(desktop->unlock_dialog); |
| 912 | desktop->unlock_dialog = NULL; |
| 913 | } |
| 914 | |
| 915 | static void |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 916 | desktop_shell_configure(void *data, |
| 917 | struct desktop_shell *desktop_shell, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 918 | uint32_t edges, |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 919 | struct wl_surface *surface, |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 920 | int32_t width, int32_t height) |
| 921 | { |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 922 | struct window *window = wl_surface_get_user_data(surface); |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 923 | struct surface *s = window_get_user_data(window); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 924 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 925 | s->configure(data, desktop_shell, edges, window, width, height); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 926 | } |
| 927 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 928 | static void |
| 929 | desktop_shell_prepare_lock_surface(void *data, |
| 930 | struct desktop_shell *desktop_shell) |
| 931 | { |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 932 | struct desktop *desktop = data; |
| 933 | |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 934 | if (!desktop->locking) { |
Pekka Paalanen | fd83b6d | 2011-12-08 10:06:53 +0200 | [diff] [blame] | 935 | desktop_shell_unlock(desktop->shell); |
| 936 | return; |
| 937 | } |
| 938 | |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 939 | if (!desktop->unlock_dialog) { |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 940 | desktop->unlock_dialog = unlock_dialog_create(desktop); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 941 | desktop->unlock_dialog->desktop = desktop; |
| 942 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 943 | } |
| 944 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 945 | static void |
| 946 | desktop_shell_grab_cursor(void *data, |
| 947 | struct desktop_shell *desktop_shell, |
| 948 | uint32_t cursor) |
| 949 | { |
| 950 | struct desktop *desktop = data; |
| 951 | |
| 952 | switch (cursor) { |
Philipp Brüschweiler | 16d59d7 | 2012-08-24 15:43:55 +0200 | [diff] [blame] | 953 | case DESKTOP_SHELL_CURSOR_NONE: |
| 954 | desktop->grab_cursor = CURSOR_BLANK; |
| 955 | break; |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 956 | case DESKTOP_SHELL_CURSOR_BUSY: |
| 957 | desktop->grab_cursor = CURSOR_WATCH; |
| 958 | break; |
| 959 | case DESKTOP_SHELL_CURSOR_MOVE: |
| 960 | desktop->grab_cursor = CURSOR_DRAGGING; |
| 961 | break; |
| 962 | case DESKTOP_SHELL_CURSOR_RESIZE_TOP: |
| 963 | desktop->grab_cursor = CURSOR_TOP; |
| 964 | break; |
| 965 | case DESKTOP_SHELL_CURSOR_RESIZE_BOTTOM: |
| 966 | desktop->grab_cursor = CURSOR_BOTTOM; |
| 967 | break; |
| 968 | case DESKTOP_SHELL_CURSOR_RESIZE_LEFT: |
| 969 | desktop->grab_cursor = CURSOR_LEFT; |
| 970 | break; |
| 971 | case DESKTOP_SHELL_CURSOR_RESIZE_RIGHT: |
| 972 | desktop->grab_cursor = CURSOR_RIGHT; |
| 973 | break; |
| 974 | case DESKTOP_SHELL_CURSOR_RESIZE_TOP_LEFT: |
| 975 | desktop->grab_cursor = CURSOR_TOP_LEFT; |
| 976 | break; |
| 977 | case DESKTOP_SHELL_CURSOR_RESIZE_TOP_RIGHT: |
| 978 | desktop->grab_cursor = CURSOR_TOP_RIGHT; |
| 979 | break; |
| 980 | case DESKTOP_SHELL_CURSOR_RESIZE_BOTTOM_LEFT: |
| 981 | desktop->grab_cursor = CURSOR_BOTTOM_LEFT; |
| 982 | break; |
| 983 | case DESKTOP_SHELL_CURSOR_RESIZE_BOTTOM_RIGHT: |
| 984 | desktop->grab_cursor = CURSOR_BOTTOM_RIGHT; |
| 985 | break; |
| 986 | case DESKTOP_SHELL_CURSOR_ARROW: |
| 987 | default: |
| 988 | desktop->grab_cursor = CURSOR_LEFT_PTR; |
| 989 | } |
| 990 | } |
| 991 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 992 | static const struct desktop_shell_listener listener = { |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 993 | desktop_shell_configure, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 994 | desktop_shell_prepare_lock_surface, |
| 995 | desktop_shell_grab_cursor |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 996 | }; |
| 997 | |
U. Artie Eoff | 44874d9 | 2012-10-02 21:12:35 -0700 | [diff] [blame] | 998 | static void |
| 999 | background_destroy(struct background *background) |
| 1000 | { |
| 1001 | widget_destroy(background->widget); |
| 1002 | window_destroy(background->window); |
| 1003 | |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 1004 | free(background->image); |
U. Artie Eoff | 44874d9 | 2012-10-02 21:12:35 -0700 | [diff] [blame] | 1005 | free(background); |
| 1006 | } |
| 1007 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1008 | static struct background * |
| 1009 | background_create(struct desktop *desktop) |
| 1010 | { |
| 1011 | struct background *background; |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 1012 | struct weston_config_section *s; |
| 1013 | char *type; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1014 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 1015 | background = xzalloc(sizeof *background); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1016 | background->base.configure = background_configure; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1017 | background->window = window_create_custom(desktop->display); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 1018 | background->widget = window_add_widget(background->window, background); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1019 | window_set_user_data(background->window, background); |
Kristian Høgsberg | b67e94b | 2012-01-10 12:23:19 -0500 | [diff] [blame] | 1020 | widget_set_redraw_handler(background->widget, background_draw); |
Tomeu Vizoso | bee45a1 | 2013-08-06 20:05:54 +0200 | [diff] [blame] | 1021 | window_set_preferred_format(background->window, |
| 1022 | WINDOW_PREFERRED_FORMAT_RGB565); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1023 | |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 1024 | s = weston_config_get_section(desktop->config, "shell", NULL, NULL); |
| 1025 | weston_config_section_get_string(s, "background-image", |
| 1026 | &background->image, |
| 1027 | DATADIR "/weston/pattern.png"); |
| 1028 | weston_config_section_get_uint(s, "background-color", |
| 1029 | &background->color, 0xff002244); |
| 1030 | |
| 1031 | weston_config_section_get_string(s, "background-type", |
| 1032 | &type, "tile"); |
| 1033 | if (strcmp(type, "scale") == 0) { |
| 1034 | background->type = BACKGROUND_SCALE; |
| 1035 | } else if (strcmp(type, "scale-crop") == 0) { |
| 1036 | background->type = BACKGROUND_SCALE_CROP; |
| 1037 | } else if (strcmp(type, "tile") == 0) { |
| 1038 | background->type = BACKGROUND_TILE; |
| 1039 | } else { |
| 1040 | background->type = -1; |
| 1041 | fprintf(stderr, "invalid background-type: %s\n", |
| 1042 | type); |
| 1043 | } |
| 1044 | |
| 1045 | free(type); |
| 1046 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1047 | return background; |
| 1048 | } |
| 1049 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1050 | static int |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1051 | grab_surface_enter_handler(struct widget *widget, struct input *input, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1052 | float x, float y, void *data) |
| 1053 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1054 | struct desktop *desktop = data; |
| 1055 | |
| 1056 | return desktop->grab_cursor; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | static void |
U. Artie Eoff | 44874d9 | 2012-10-02 21:12:35 -0700 | [diff] [blame] | 1060 | grab_surface_destroy(struct desktop *desktop) |
| 1061 | { |
| 1062 | widget_destroy(desktop->grab_widget); |
| 1063 | window_destroy(desktop->grab_window); |
| 1064 | } |
| 1065 | |
| 1066 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1067 | grab_surface_create(struct desktop *desktop) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1068 | { |
| 1069 | struct wl_surface *s; |
| 1070 | |
Ander Conselvan de Oliveira | 07a91cd | 2012-07-16 14:15:50 +0300 | [diff] [blame] | 1071 | desktop->grab_window = window_create_custom(desktop->display); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1072 | window_set_user_data(desktop->grab_window, desktop); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1073 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1074 | s = window_get_wl_surface(desktop->grab_window); |
| 1075 | desktop_shell_set_grab_surface(desktop->shell, s); |
| 1076 | |
| 1077 | desktop->grab_widget = |
| 1078 | window_add_widget(desktop->grab_window, desktop); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1079 | /* We set the allocation to 1x1 at 0,0 so the fake enter event |
| 1080 | * at 0,0 will go to this widget. */ |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1081 | widget_set_allocation(desktop->grab_widget, 0, 0, 1, 1); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1082 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1083 | widget_set_enter_handler(desktop->grab_widget, |
| 1084 | grab_surface_enter_handler); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1085 | } |
| 1086 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1087 | static void |
U. Artie Eoff | 44874d9 | 2012-10-02 21:12:35 -0700 | [diff] [blame] | 1088 | output_destroy(struct output *output) |
| 1089 | { |
| 1090 | background_destroy(output->background); |
| 1091 | panel_destroy(output->panel); |
| 1092 | wl_output_destroy(output->output); |
| 1093 | wl_list_remove(&output->link); |
| 1094 | |
| 1095 | free(output); |
| 1096 | } |
| 1097 | |
| 1098 | static void |
| 1099 | desktop_destroy_outputs(struct desktop *desktop) |
| 1100 | { |
| 1101 | struct output *tmp; |
| 1102 | struct output *output; |
| 1103 | |
| 1104 | wl_list_for_each_safe(output, tmp, &desktop->outputs, link) |
| 1105 | output_destroy(output); |
| 1106 | } |
| 1107 | |
| 1108 | static void |
Alexander Larsson | c584fa6 | 2013-05-22 14:41:32 +0200 | [diff] [blame] | 1109 | output_handle_geometry(void *data, |
| 1110 | struct wl_output *wl_output, |
| 1111 | int x, int y, |
| 1112 | int physical_width, |
| 1113 | int physical_height, |
| 1114 | int subpixel, |
| 1115 | const char *make, |
| 1116 | const char *model, |
| 1117 | int transform) |
| 1118 | { |
| 1119 | struct output *output = data; |
| 1120 | |
| 1121 | window_set_buffer_transform(output->panel->window, transform); |
| 1122 | window_set_buffer_transform(output->background->window, transform); |
| 1123 | } |
| 1124 | |
| 1125 | static void |
| 1126 | output_handle_mode(void *data, |
| 1127 | struct wl_output *wl_output, |
| 1128 | uint32_t flags, |
| 1129 | int width, |
| 1130 | int height, |
| 1131 | int refresh) |
| 1132 | { |
| 1133 | } |
| 1134 | |
| 1135 | static void |
| 1136 | output_handle_done(void *data, |
| 1137 | struct wl_output *wl_output) |
| 1138 | { |
| 1139 | } |
| 1140 | |
| 1141 | static void |
| 1142 | output_handle_scale(void *data, |
| 1143 | struct wl_output *wl_output, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 1144 | int32_t scale) |
Alexander Larsson | c584fa6 | 2013-05-22 14:41:32 +0200 | [diff] [blame] | 1145 | { |
| 1146 | struct output *output = data; |
| 1147 | |
| 1148 | window_set_buffer_scale(output->panel->window, scale); |
| 1149 | window_set_buffer_scale(output->background->window, scale); |
| 1150 | } |
| 1151 | |
| 1152 | static const struct wl_output_listener output_listener = { |
| 1153 | output_handle_geometry, |
| 1154 | output_handle_mode, |
| 1155 | output_handle_done, |
| 1156 | output_handle_scale |
| 1157 | }; |
| 1158 | |
| 1159 | static void |
Ander Conselvan de Oliveira | e492549 | 2013-07-05 16:05:28 +0300 | [diff] [blame] | 1160 | output_init(struct output *output, struct desktop *desktop) |
| 1161 | { |
| 1162 | struct wl_surface *surface; |
| 1163 | |
| 1164 | output->panel = panel_create(desktop); |
| 1165 | surface = window_get_wl_surface(output->panel->window); |
| 1166 | desktop_shell_set_panel(desktop->shell, |
| 1167 | output->output, surface); |
| 1168 | |
| 1169 | output->background = background_create(desktop); |
| 1170 | surface = window_get_wl_surface(output->background->window); |
| 1171 | desktop_shell_set_background(desktop->shell, |
| 1172 | output->output, surface); |
| 1173 | } |
| 1174 | |
| 1175 | static void |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1176 | create_output(struct desktop *desktop, uint32_t id) |
| 1177 | { |
| 1178 | struct output *output; |
| 1179 | |
| 1180 | output = calloc(1, sizeof *output); |
| 1181 | if (!output) |
| 1182 | return; |
| 1183 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 1184 | output->output = |
Alexander Larsson | c584fa6 | 2013-05-22 14:41:32 +0200 | [diff] [blame] | 1185 | display_bind(desktop->display, id, &wl_output_interface, 2); |
| 1186 | |
| 1187 | wl_output_add_listener(output->output, &output_listener, output); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1188 | |
| 1189 | wl_list_insert(&desktop->outputs, &output->link); |
Ander Conselvan de Oliveira | e492549 | 2013-07-05 16:05:28 +0300 | [diff] [blame] | 1190 | |
| 1191 | /* On start up we may process an output global before the shell global |
| 1192 | * in which case we can't create the panel and background just yet */ |
| 1193 | if (desktop->shell) |
| 1194 | output_init(output, desktop); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1195 | } |
| 1196 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 1197 | static void |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 1198 | global_handler(struct display *display, uint32_t id, |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 1199 | const char *interface, uint32_t version, void *data) |
| 1200 | { |
| 1201 | struct desktop *desktop = data; |
| 1202 | |
| 1203 | if (!strcmp(interface, "desktop_shell")) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 1204 | desktop->interface_version = (version < 2) ? version : 2; |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 1205 | desktop->shell = display_bind(desktop->display, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 1206 | id, &desktop_shell_interface, |
| 1207 | desktop->interface_version); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 1208 | desktop_shell_add_listener(desktop->shell, &listener, desktop); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1209 | } else if (!strcmp(interface, "wl_output")) { |
| 1210 | create_output(desktop, id); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 1211 | } |
| 1212 | } |
| 1213 | |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 1214 | static void |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 1215 | panel_add_launchers(struct panel *panel, struct desktop *desktop) |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 1216 | { |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 1217 | struct weston_config_section *s; |
| 1218 | char *icon, *path; |
| 1219 | const char *name; |
| 1220 | int count; |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 1221 | |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 1222 | count = 0; |
| 1223 | s = NULL; |
| 1224 | while (weston_config_next_section(desktop->config, &s, &name)) { |
| 1225 | if (strcmp(name, "launcher") != 0) |
| 1226 | continue; |
| 1227 | |
| 1228 | weston_config_section_get_string(s, "icon", &icon, NULL); |
| 1229 | weston_config_section_get_string(s, "path", &path, NULL); |
| 1230 | |
| 1231 | if (icon != NULL && path != NULL) { |
| 1232 | panel_add_launcher(panel, icon, path); |
Rob Bradford | 09252d4 | 2013-07-26 16:29:45 +0100 | [diff] [blame] | 1233 | count++; |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 1234 | } else { |
| 1235 | fprintf(stderr, "invalid launcher section\n"); |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | free(icon); |
| 1239 | free(path); |
Kristian Høgsberg | ac3a59a | 2011-11-14 22:43:37 -0500 | [diff] [blame] | 1240 | } |
| 1241 | |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 1242 | if (count == 0) { |
| 1243 | /* add default launcher */ |
| 1244 | panel_add_launcher(panel, |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 1245 | DATADIR "/weston/terminal.png", |
Rodney Lorrimar | 99ff01b | 2012-02-29 17:31:03 +0100 | [diff] [blame] | 1246 | BINDIR "/weston-terminal"); |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 1247 | } |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 1248 | } |
| 1249 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 1250 | int main(int argc, char *argv[]) |
| 1251 | { |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 1252 | struct desktop desktop = { 0 }; |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 1253 | int config_fd; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1254 | struct output *output; |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 1255 | struct weston_config_section *s; |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 1256 | |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 1257 | desktop.unlock_task.run = unlock_dialog_finish; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1258 | wl_list_init(&desktop.outputs); |
Pekka Paalanen | bfbb26b | 2011-11-15 13:34:56 +0200 | [diff] [blame] | 1259 | |
Ander Conselvan de Oliveira | 6d75da7 | 2013-07-05 16:05:27 +0300 | [diff] [blame] | 1260 | config_fd = open_config_file("weston.ini"); |
| 1261 | desktop.config = weston_config_parse(config_fd); |
| 1262 | close(config_fd); |
| 1263 | |
| 1264 | s = weston_config_get_section(desktop.config, "shell", NULL, NULL); |
| 1265 | weston_config_section_get_bool(s, "locking", &desktop.locking, 1); |
| 1266 | |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 1267 | desktop.display = display_create(&argc, argv); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 1268 | if (desktop.display == NULL) { |
| 1269 | fprintf(stderr, "failed to create display: %m\n"); |
| 1270 | return -1; |
| 1271 | } |
| 1272 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1273 | display_set_user_data(desktop.display, &desktop); |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 1274 | display_set_global_handler(desktop.display, global_handler); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 1275 | |
Ander Conselvan de Oliveira | e492549 | 2013-07-05 16:05:28 +0300 | [diff] [blame] | 1276 | /* Create panel and background for outputs processed before the shell |
| 1277 | * global interface was processed */ |
| 1278 | wl_list_for_each(output, &desktop.outputs, link) |
| 1279 | if (!output->panel) |
| 1280 | output_init(output, &desktop); |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 1281 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1282 | grab_surface_create(&desktop); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1283 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 1284 | signal(SIGCHLD, sigchild_handler); |
| 1285 | |
| 1286 | display_run(desktop.display); |
| 1287 | |
U. Artie Eoff | 44874d9 | 2012-10-02 21:12:35 -0700 | [diff] [blame] | 1288 | /* Cleanup */ |
| 1289 | grab_surface_destroy(&desktop); |
| 1290 | desktop_destroy_outputs(&desktop); |
| 1291 | if (desktop.unlock_dialog) |
| 1292 | unlock_dialog_destroy(desktop.unlock_dialog); |
| 1293 | desktop_shell_destroy(desktop.shell); |
| 1294 | display_destroy(desktop.display); |
| 1295 | |
Kristian Høgsberg | 0c29eb2 | 2011-09-06 18:02:34 -0400 | [diff] [blame] | 1296 | return 0; |
| 1297 | } |