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