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