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