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