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