blob: b7755dce9e4348d3c9c3dcf7e70d58d6cd872f4c [file] [log] [blame]
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001/*
2 * Copyright © 2011 Kristian Høgsberg
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02003 * Copyright © 2011 Collabora, Ltd.
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04004 *
Bryce Harrington1f6b0d12015-06-10 22:48:59 -07005 * 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øgsberg0c29eb22011-09-06 18:02:34 -040011 *
Bryce Harrington1f6b0d12015-06-10 22:48:59 -070012 * 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øgsberg0c29eb22011-09-06 18:02:34 -040023 */
24
U. Artie Eoff3c946772014-01-15 10:59:50 -080025#include "config.h"
26
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040027#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 Eoff3c946772014-01-15 10:59:50 -080033#include <errno.h>
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040034#include <math.h>
35#include <cairo.h>
36#include <sys/wait.h>
37#include <linux/input.h>
Tiago Vignatti61500722012-05-23 22:06:28 +030038#include <libgen.h>
Kristian Høgsbergd1936b92012-07-23 22:59:33 -040039#include <ctype.h>
Martin Minarik1e51a872012-06-08 00:39:11 +020040#include <time.h>
Quentin Glidicf9574f22016-06-23 18:55:21 +020041#include <assert.h>
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040042
Pekka Paalanen50719bc2011-11-22 14:18:50 +020043#include <wayland-client.h>
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040044#include "window.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070045#include "shared/cairo-util.h"
Pekka Paalanen91b10102019-04-04 14:27:31 +030046#include <libweston/config-parser.h>
Jon Cruz867d50e2015-06-15 15:37:10 -070047#include "shared/helpers.h"
Bryce Harringtone99e4bf2016-03-16 14:15:18 -070048#include "shared/xalloc.h"
Pekka Paalanenecbdcfd2019-04-04 14:46:00 +030049#include <libweston/zalloc.h>
Derek Foremane2772762018-02-06 15:18:38 -060050#include "shared/file-util.h"
Veeresh Kadasanied4a0e92020-12-21 15:24:51 +053051#include "shared/timespec-util.h"
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040052
Jonas Ådahl6d6fb612015-11-17 16:00:33 +080053#include "weston-desktop-shell-client-protocol.h"
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040054
Armin Krezovićc6a55db2016-03-10 18:02:34 +010055#define DEFAULT_CLOCK_FORMAT CLOCK_FORMAT_MINUTES
-c505af82019-06-26 21:00:43 +000056#define DEFAULT_SPACING 10
Armin Krezovićc6a55db2016-03-10 18:02:34 +010057
Pekka Paalanenb6df4f72012-08-03 14:39:15 +030058extern char **environ; /* defined by libc */
59
Quentin Glidicf9574f22016-06-23 18:55:21 +020060enum clock_format {
61 CLOCK_FORMAT_MINUTES,
62 CLOCK_FORMAT_SECONDS,
Nicholas Niroa11bc632020-10-30 15:09:23 -040063 CLOCK_FORMAT_MINUTES_24H,
64 CLOCK_FORMAT_SECONDS_24H,
Quentin Glidicf9574f22016-06-23 18:55:21 +020065 CLOCK_FORMAT_NONE
66};
67
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040068struct desktop {
69 struct display *display;
Jonas Ådahl6d6fb612015-11-17 16:00:33 +080070 struct weston_desktop_shell *shell;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +020071 struct unlock_dialog *unlock_dialog;
72 struct task unlock_task;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010073 struct wl_list outputs;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -040074
Quentin Glidic55d57012016-06-23 18:55:18 +020075 int want_panel;
76 enum weston_desktop_shell_panel_position panel_position;
Quentin Glidic3e37b342016-06-23 18:55:22 +020077 enum clock_format clock_format;
Quentin Glidic55d57012016-06-23 18:55:18 +020078
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +030079 struct window *grab_window;
80 struct widget *grab_widget;
81
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +030082 struct weston_config *config;
Daniel Stone51d995a2019-11-26 00:14:24 +000083 bool locking;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +030084
Scott Moreauec116022012-07-22 18:23:52 -060085 enum cursor_type grab_cursor;
Pekka Paalanen79346ab2013-05-22 18:03:09 +030086
87 int painted;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010088};
89
90struct surface {
91 void (*configure)(void *data,
Jonas Ådahl6d6fb612015-11-17 16:00:33 +080092 struct weston_desktop_shell *desktop_shell,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -040093 uint32_t edges, struct window *window,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010094 int32_t width, int32_t height);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040095};
96
Pekka Paalanencb115382017-12-07 12:15:01 +020097struct output;
98
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040099struct panel {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100100 struct surface base;
Pekka Paalanen1cbfcf42017-12-07 12:39:15 +0200101
102 struct output *owner;
103
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400104 struct window *window;
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500105 struct widget *widget;
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500106 struct wl_list launcher_list;
Martin Minarik1e51a872012-06-08 00:39:11 +0200107 struct panel_clock *clock;
Pekka Paalanen79346ab2013-05-22 18:03:09 +0300108 int painted;
Quentin Glidice7ed60f2016-06-23 18:55:24 +0200109 enum weston_desktop_shell_panel_position panel_position;
Quentin Glidicf9574f22016-06-23 18:55:21 +0200110 enum clock_format clock_format;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300111 uint32_t color;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400112};
113
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100114struct background {
115 struct surface base;
Pekka Paalanencb115382017-12-07 12:15:01 +0200116
117 struct output *owner;
118
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100119 struct window *window;
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500120 struct widget *widget;
Pekka Paalanen79346ab2013-05-22 18:03:09 +0300121 int painted;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300122
123 char *image;
124 int type;
125 uint32_t color;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100126};
127
128struct output {
129 struct wl_output *output;
Xiong Zhang83d8ee72013-10-23 13:58:35 +0800130 uint32_t server_output_id;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100131 struct wl_list link;
132
Pekka Paalanenc1bcce62017-12-07 15:30:18 +0200133 int x;
134 int y;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100135 struct panel *panel;
136 struct background *background;
137};
138
Kristian Høgsberg53880802012-01-09 11:16:50 -0500139struct panel_launcher {
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500140 struct widget *widget;
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400141 struct panel *panel;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400142 cairo_surface_t *icon;
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500143 int focused, pressed;
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400144 char *path;
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500145 struct wl_list link;
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400146 struct wl_array envp;
147 struct wl_array argv;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400148};
149
Martin Minarik1e51a872012-06-08 00:39:11 +0200150struct panel_clock {
151 struct widget *widget;
152 struct panel *panel;
Pekka Paalanen64a26bc2018-03-09 13:17:26 +0200153 struct toytimer timer;
Armin Krezovićc6a55db2016-03-10 18:02:34 +0100154 char *format_string;
155 time_t refresh_timer;
Martin Minarik1e51a872012-06-08 00:39:11 +0200156};
157
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200158struct unlock_dialog {
159 struct window *window;
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500160 struct widget *widget;
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500161 struct widget *button;
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500162 int button_focused;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200163 int closing;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200164 struct desktop *desktop;
165};
166
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300167static void
168panel_add_launchers(struct panel *panel, struct desktop *desktop);
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -0500169
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400170static void
171sigchild_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 Paalanen79346ab2013-05-22 18:03:09 +0300180static int
181is_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
195static void
196check_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 Ådahl6d6fb612015-11-17 16:00:33 +0800207 weston_desktop_shell_desktop_ready(desktop->shell);
Pekka Paalanen79346ab2013-05-22 18:03:09 +0300208 }
209}
210
Kristian Høgsbergbcee9a42011-10-12 00:36:16 -0400211static void
Kristian Høgsberg53880802012-01-09 11:16:50 -0500212panel_launcher_activate(struct panel_launcher *widget)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400213{
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400214 char **argv;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400215 pid_t pid;
216
217 pid = fork();
218 if (pid < 0) {
Antonio Borneo39578632019-04-26 23:57:31 +0200219 fprintf(stderr, "fork failed: %s\n", strerror(errno));
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400220 return;
221 }
222
223 if (pid)
224 return;
Benjamin Franzked7759712011-11-22 12:38:48 +0100225
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400226 argv = widget->argv.data;
Derek Foreman091c8012017-03-24 09:41:13 -0500227
228 if (setsid() == -1)
229 exit(EXIT_FAILURE);
230
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400231 if (execve(argv[0], argv, widget->envp.data) < 0) {
Antonio Borneo39578632019-04-26 23:57:31 +0200232 fprintf(stderr, "execl '%s' failed: %s\n", argv[0],
233 strerror(errno));
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400234 exit(1);
235 }
236}
237
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400238static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500239panel_launcher_redraw_handler(struct widget *widget, void *data)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400240{
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500241 struct panel_launcher *launcher = data;
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500242 struct rectangle allocation;
243 cairo_t *cr;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400244
Alexander Larssonc584fa62013-05-22 14:41:32 +0200245 cr = widget_cairo_create(launcher->panel->widget);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500246
247 widget_get_allocation(widget, &allocation);
-c505af82019-06-26 21:00:43 +0000248 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øgsberg75bc6672012-01-10 09:43:58 -0500256 if (launcher->pressed) {
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500257 allocation.x++;
258 allocation.y++;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400259 }
260
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500261 cairo_set_source_surface(cr, launcher->icon,
262 allocation.x, allocation.y);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400263 cairo_paint(cr);
264
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500265 if (launcher->focused) {
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400266 cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.4);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500267 cairo_mask_surface(cr, launcher->icon,
268 allocation.x, allocation.y);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400269 }
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400270
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500271 cairo_destroy(cr);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400272}
273
Tiago Vignatti61500722012-05-23 22:06:28 +0300274static int
275panel_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 Oliveiradc8c8fc2012-05-25 16:01:41 +0300282 return CURSOR_LEFT_PTR;
Tiago Vignatti61500722012-05-23 22:06:28 +0300283}
284
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400285static void
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -0500286set_hex_color(cairo_t *cr, uint32_t color)
287{
Michael Vetter2a18a522015-05-15 17:17:47 +0200288 cairo_set_source_rgba(cr,
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -0500289 ((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
295static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500296panel_redraw_handler(struct widget *widget, void *data)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400297{
298 cairo_surface_t *surface;
299 cairo_t *cr;
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500300 struct panel *panel = data;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400301
Alexander Larssonc584fa62013-05-22 14:41:32 +0200302 cr = widget_cairo_create(panel->widget);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400303 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300304 set_hex_color(cr, panel->color);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400305 cairo_paint(cr);
306
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400307 cairo_destroy(cr);
Alexander Larssonc584fa62013-05-22 14:41:32 +0200308 surface = window_get_surface(panel->window);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400309 cairo_surface_destroy(surface);
Pekka Paalanen79346ab2013-05-22 18:03:09 +0300310 panel->painted = 1;
311 check_desktop_ready(panel->window);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400312}
313
Kristian Høgsbergbb901fa2012-01-09 11:22:32 -0500314static int
Kristian Høgsberg53880802012-01-09 11:16:50 -0500315panel_launcher_enter_handler(struct widget *widget, struct input *input,
Kristian Høgsberg80680c72012-05-10 12:21:37 -0400316 float x, float y, void *data)
Kristian Høgsbergee143232012-01-09 08:42:24 -0500317{
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500318 struct panel_launcher *launcher = data;
319
320 launcher->focused = 1;
Kristian Høgsbergee143232012-01-09 08:42:24 -0500321 widget_schedule_redraw(widget);
Kristian Høgsbergbb901fa2012-01-09 11:22:32 -0500322
Ander Conselvan de Oliveiradc8c8fc2012-05-25 16:01:41 +0300323 return CURSOR_LEFT_PTR;
Kristian Høgsbergee143232012-01-09 08:42:24 -0500324}
325
326static void
Kristian Høgsberg53880802012-01-09 11:16:50 -0500327panel_launcher_leave_handler(struct widget *widget,
328 struct input *input, void *data)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400329{
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500330 struct panel_launcher *launcher = data;
331
332 launcher->focused = 0;
Tiago Vignatti61500722012-05-23 22:06:28 +0300333 widget_destroy_tooltip(widget);
Kristian Høgsberg9a13dab2012-01-08 15:18:19 -0500334 widget_schedule_redraw(widget);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400335}
336
337static void
Kristian Høgsberg53880802012-01-09 11:16:50 -0500338panel_launcher_button_handler(struct widget *widget,
339 struct input *input, uint32_t time,
Daniel Stone4dbadb12012-05-30 16:31:51 +0100340 uint32_t button,
341 enum wl_pointer_button_state state, void *data)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400342{
Kristian Høgsberg53880802012-01-09 11:16:50 -0500343 struct panel_launcher *launcher;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400344
Kristian Høgsberg53880802012-01-09 11:16:50 -0500345 launcher = widget_get_user_data(widget);
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500346 widget_schedule_redraw(widget);
Daniel Stone4dbadb12012-05-30 16:31:51 +0100347 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
Kristian Høgsberg53880802012-01-09 11:16:50 -0500348 panel_launcher_activate(launcher);
Rusty Lynch4384a242013-08-08 21:28:22 -0700349
350}
351
352static void
Rusty Lynch1084da52013-08-15 09:10:08 -0700353panel_launcher_touch_down_handler(struct widget *widget, struct input *input,
354 uint32_t serial, uint32_t time, int32_t id,
Rusty Lynch4384a242013-08-08 21:28:22 -0700355 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
364static void
Rusty Lynch1084da52013-08-15 09:10:08 -0700365panel_launcher_touch_up_handler(struct widget *widget, struct input *input,
Michael Vetter2a18a522015-05-15 17:17:47 +0200366 uint32_t serial, uint32_t time, int32_t id,
Rusty Lynch1084da52013-08-15 09:10:08 -0700367 void *data)
Rusty Lynch4384a242013-08-08 21:28:22 -0700368{
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øgsberga8a0db32012-01-09 11:12:05 -0500375}
376
Martin Minarik1e51a872012-06-08 00:39:11 +0200377static void
Pekka Paalanen64a26bc2018-03-09 13:17:26 +0200378clock_func(struct toytimer *tt)
Martin Minarik1e51a872012-06-08 00:39:11 +0200379{
Pekka Paalanen64a26bc2018-03-09 13:17:26 +0200380 struct panel_clock *clock = container_of(tt, struct panel_clock, timer);
Martin Minarik1e51a872012-06-08 00:39:11 +0200381
Kristian Høgsberg92a984a2012-06-11 11:10:57 -0400382 widget_schedule_redraw(clock->widget);
Martin Minarik1e51a872012-06-08 00:39:11 +0200383}
384
385static void
386panel_clock_redraw_handler(struct widget *widget, void *data)
387{
Martin Minarik1e51a872012-06-08 00:39:11 +0200388 struct panel_clock *clock = data;
389 cairo_t *cr;
390 struct rectangle allocation;
391 cairo_text_extents_t extents;
Martin Minarik1e51a872012-06-08 00:39:11 +0200392 time_t rawtime;
393 struct tm * timeinfo;
Kristian Høgsberg92a984a2012-06-11 11:10:57 -0400394 char string[128];
Martin Minarik1e51a872012-06-08 00:39:11 +0200395
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400396 time(&rawtime);
397 timeinfo = localtime(&rawtime);
Armin Krezovićc6a55db2016-03-10 18:02:34 +0100398 strftime(string, sizeof string, clock->format_string, timeinfo);
Martin Minarik1e51a872012-06-08 00:39:11 +0200399
400 widget_get_allocation(widget, &allocation);
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400401 if (allocation.width == 0)
402 return;
Martin Minarik1e51a872012-06-08 00:39:11 +0200403
Alexander Larssonc584fa62013-05-22 14:41:32 +0200404 cr = widget_cairo_create(clock->panel->widget);
Martin Minarik1e51a872012-06-08 00:39:11 +0200405 cairo_set_font_size(cr, 14);
Kristian Høgsberg92a984a2012-06-11 11:10:57 -0400406 cairo_text_extents(cr, string, &extents);
-c505af82019-06-26 21:00:43 +0000407 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øgsberg92a984a2012-06-11 11:10:57 -0400416 cairo_show_text(cr, string);
-c505af82019-06-26 21:00:43 +0000417 cairo_move_to(cr, allocation.x, allocation.y);
418 cairo_set_source_rgba(cr, 1, 1, 1, 0.85);
Kristian Høgsberg92a984a2012-06-11 11:10:57 -0400419 cairo_show_text(cr, string);
Martin Minarik1e51a872012-06-08 00:39:11 +0200420 cairo_destroy(cr);
421}
422
423static int
424clock_timer_reset(struct panel_clock *clock)
425{
426 struct itimerspec its;
Veeresh Kadasanied4a0e92020-12-21 15:24:51 +0530427 struct timespec ts;
428 struct tm *tm;
429
430 clock_gettime(CLOCK_REALTIME, &ts);
431 tm = localtime(&ts.tv_sec);
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400432
Armin Krezovićc6a55db2016-03-10 18:02:34 +0100433 its.it_interval.tv_sec = clock->refresh_timer;
Martin Minarik1e51a872012-06-08 00:39:11 +0200434 its.it_interval.tv_nsec = 0;
Veeresh Kadasanied4a0e92020-12-21 15:24:51 +0530435 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 Minarik1e51a872012-06-08 00:39:11 +0200438
Veeresh Kadasanied4a0e92020-12-21 15:24:51 +0530439 toytimer_arm(&clock->timer, &its);
Martin Minarik1e51a872012-06-08 00:39:11 +0200440 return 0;
441}
442
443static void
U. Artie Eoff44874d92012-10-02 21:12:35 -0700444panel_destroy_clock(struct panel_clock *clock)
445{
446 widget_destroy(clock->widget);
Pekka Paalanen64a26bc2018-03-09 13:17:26 +0200447 toytimer_fini(&clock->timer);
U. Artie Eoff44874d92012-10-02 21:12:35 -0700448 free(clock);
449}
450
451static void
Martin Minarik1e51a872012-06-08 00:39:11 +0200452panel_add_clock(struct panel *panel)
453{
454 struct panel_clock *clock;
Martin Minarik1e51a872012-06-08 00:39:11 +0200455
Peter Huttererf3d62272013-08-08 11:57:05 +1000456 clock = xzalloc(sizeof *clock);
Martin Minarik1e51a872012-06-08 00:39:11 +0200457 clock->panel = panel;
458 panel->clock = clock;
Martin Minarik1e51a872012-06-08 00:39:11 +0200459
Armin Krezovićc6a55db2016-03-10 18:02:34 +0100460 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 Niroa11bc632020-10-30 15:09:23 -0400469 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 Glidicf9574f22016-06-23 18:55:21 +0200477 case CLOCK_FORMAT_NONE:
478 assert(!"not reached");
Armin Krezovićc6a55db2016-03-10 18:02:34 +0100479 }
480
Pekka Paalanen64a26bc2018-03-09 13:17:26 +0200481 toytimer_init(&clock->timer, CLOCK_MONOTONIC,
482 window_get_display(panel->window), clock_func);
Martin Minarik1e51a872012-06-08 00:39:11 +0200483 clock_timer_reset(clock);
484
485 clock->widget = widget_add_widget(panel->widget, clock);
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400486 widget_set_redraw_handler(clock->widget, panel_clock_redraw_handler);
Martin Minarik1e51a872012-06-08 00:39:11 +0200487}
488
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500489static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500490panel_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;
-c505af82019-06-26 21:00:43 +0000495 int x = 0;
496 int y = 0;
497 int w = height > width ? width : height;
498 int h = w;
Quentin Glidice7ed60f2016-06-23 18:55:24 +0200499 int horizontal = panel->panel_position == WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP || panel->panel_position == WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
-c505af82019-06-26 21:00:43 +0000500 int first_pad_h = horizontal ? 0 : DEFAULT_SPACING / 2;
501 int first_pad_w = horizontal ? DEFAULT_SPACING / 2 : 0;
Michael Vetter2a18a522015-05-15 17:17:47 +0200502
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500503 wl_list_for_each(launcher, &panel->launcher_list, link) {
-c505af82019-06-26 21:00:43 +0000504 widget_set_allocation(launcher->widget, x, y,
505 w + first_pad_w + 1, h + first_pad_h + 1);
Quentin Glidice7ed60f2016-06-23 18:55:24 +0200506 if (horizontal)
-c505af82019-06-26 21:00:43 +0000507 x += w + first_pad_w;
Quentin Glidice7ed60f2016-06-23 18:55:24 +0200508 else
-c505af82019-06-26 21:00:43 +0000509 y += h + first_pad_h;
510 first_pad_h = first_pad_w = 0;
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500511 }
Armin Krezovićc6a55db2016-03-10 18:02:34 +0100512
Armin Krezovićc6a55db2016-03-10 18:02:34 +0100513 if (panel->clock_format == CLOCK_FORMAT_SECONDS)
Armin Krezovićc6a55db2016-03-10 18:02:34 +0100514 w = 170;
Nicholas Niroa11bc632020-10-30 15:09:23 -0400515 else /* CLOCK_FORMAT_MINUTES and 24H versions */
-c505af82019-06-26 21:00:43 +0000516 w = 150;
Pekka Paalanen01b17252012-06-12 17:42:26 +0300517
-c505af82019-06-26 21:00:43 +0000518 if (horizontal)
519 x = width - w;
520 else
521 y = height - (h = DEFAULT_SPACING * 3);
Quentin Glidic51c2c372016-06-23 18:55:23 +0200522
Pekka Paalanen01b17252012-06-12 17:42:26 +0300523 if (panel->clock)
524 widget_set_allocation(panel->clock->widget,
Quentin Glidic51c2c372016-06-23 18:55:23 +0200525 x, y, w + 1, h + 1);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500526}
527
528static void
Pekka Paalanen1cbfcf42017-12-07 12:39:15 +0200529panel_destroy(struct panel *panel);
530
531static void
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100532panel_configure(void *data,
Jonas Ådahl6d6fb612015-11-17 16:00:33 +0800533 struct weston_desktop_shell *desktop_shell,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400534 uint32_t edges, struct window *window,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100535 int32_t width, int32_t height)
536{
Quentin Glidice7ed60f2016-06-23 18:55:24 +0200537 struct desktop *desktop = data;
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500538 struct surface *surface = window_get_user_data(window);
539 struct panel *panel = container_of(surface, struct panel, base);
Pekka Paalanen1cbfcf42017-12-07 12:39:15 +0200540 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øgsbergb67e94b2012-01-10 12:23:19 -0500549
Quentin Glidice7ed60f2016-06-23 18:55:24 +0200550 switch (desktop->panel_position) {
551 case WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP:
552 case WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM:
Quentin Glidic51c2c372016-06-23 18:55:23 +0200553 height = 32;
Quentin Glidice7ed60f2016-06-23 18:55:24 +0200554 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 Niroa11bc632020-10-30 15:09:23 -0400562 case CLOCK_FORMAT_MINUTES_24H:
563 case CLOCK_FORMAT_SECONDS_24H:
-c505af82019-06-26 21:00:43 +0000564 width = 150;
Quentin Glidice7ed60f2016-06-23 18:55:24 +0200565 break;
566 case CLOCK_FORMAT_SECONDS:
-c505af82019-06-26 21:00:43 +0000567 width = 170;
Quentin Glidice7ed60f2016-06-23 18:55:24 +0200568 break;
569 }
570 break;
571 }
Quentin Glidic51c2c372016-06-23 18:55:23 +0200572 window_schedule_resize(panel->window, width, height);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100573}
574
U. Artie Eoff44874d92012-10-02 21:12:35 -0700575static void
576panel_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
591static void
592panel_destroy(struct panel *panel)
593{
594 struct panel_launcher *tmp;
595 struct panel_launcher *launcher;
596
Armin Krezovićc6a55db2016-03-10 18:02:34 +0100597 if (panel->clock)
598 panel_destroy_clock(panel->clock);
U. Artie Eoff44874d92012-10-02 21:12:35 -0700599
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øgsberg0c29eb22011-09-06 18:02:34 -0400609static struct panel *
Pekka Paalanen1cbfcf42017-12-07 12:39:15 +0200610panel_create(struct desktop *desktop, struct output *output)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400611{
612 struct panel *panel;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300613 struct weston_config_section *s;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400614
Peter Huttererf3d62272013-08-08 11:57:05 +1000615 panel = xzalloc(sizeof *panel);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400616
Pekka Paalanen1cbfcf42017-12-07 12:39:15 +0200617 panel->owner = output;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100618 panel->base.configure = panel_configure;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300619 panel->window = window_create_custom(desktop->display);
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500620 panel->widget = window_add_widget(panel->window, panel);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500621 wl_list_init(&panel->launcher_list);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400622
623 window_set_title(panel->window, "panel");
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400624 window_set_user_data(panel->window, panel);
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500625
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500626 widget_set_redraw_handler(panel->widget, panel_redraw_handler);
627 widget_set_resize_handler(panel->widget, panel_resize_handler);
Michael Vetter2a18a522015-05-15 17:17:47 +0200628
Quentin Glidice7ed60f2016-06-23 18:55:24 +0200629 panel->panel_position = desktop->panel_position;
Quentin Glidic3e37b342016-06-23 18:55:22 +0200630 panel->clock_format = desktop->clock_format;
Armin Krezovićc6a55db2016-03-10 18:02:34 +0100631 if (panel->clock_format != CLOCK_FORMAT_NONE)
632 panel_add_clock(panel);
633
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300634 s = weston_config_get_section(desktop->config, "shell", NULL, NULL);
Bryce Harringtone776f2a2016-07-14 18:28:03 -0700635 weston_config_section_get_color(s, "panel-color",
636 &panel->color, 0xaa000000);
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300637
638 panel_add_launchers(panel, desktop);
639
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400640 return panel;
641}
642
Philipp Brüschweiler467668c2012-08-29 10:53:36 +0200643static cairo_surface_t *
644load_icon_or_fallback(const char *icon)
645{
646 cairo_surface_t *surface = cairo_image_surface_create_from_png(icon);
Philipp Brüschweiler96386b82013-04-15 20:10:40 +0200647 cairo_status_t status;
Philipp Brüschweiler467668c2012-08-29 10:53:36 +0200648 cairo_t *cr;
649
Philipp Brüschweiler96386b82013-04-15 20:10:40 +0200650 status = cairo_surface_status(surface);
651 if (status == CAIRO_STATUS_SUCCESS)
Philipp Brüschweiler467668c2012-08-29 10:53:36 +0200652 return surface;
653
654 cairo_surface_destroy(surface);
Philipp Brüschweiler96386b82013-04-15 20:10:40 +0200655 fprintf(stderr, "ERROR loading icon from file '%s', error: '%s'\n",
656 icon, cairo_status_to_string(status));
Philipp Brüschweiler467668c2012-08-29 10:53:36 +0200657
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øgsberg0c29eb22011-09-06 18:02:34 -0400680static void
Kristian Høgsberg53880802012-01-09 11:16:50 -0500681panel_add_launcher(struct panel *panel, const char *icon, const char *path)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400682{
Kristian Høgsberg53880802012-01-09 11:16:50 -0500683 struct panel_launcher *launcher;
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400684 char *start, *p, *eq, **ps;
685 int i, j, k;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400686
Peter Huttererf3d62272013-08-08 11:57:05 +1000687 launcher = xzalloc(sizeof *launcher);
Philipp Brüschweiler467668c2012-08-29 10:53:36 +0200688 launcher->icon = load_icon_or_fallback(icon);
U. Artie Eoff3c946772014-01-15 10:59:50 -0800689 launcher->path = xstrdup(path);
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400690
691 wl_array_init(&launcher->envp);
692 wl_array_init(&launcher->argv);
Pekka Paalanenb6df4f72012-08-03 14:39:15 +0300693 for (i = 0; environ[i]; i++) {
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400694 ps = wl_array_add(&launcher->envp, sizeof *ps);
Pekka Paalanenb6df4f72012-08-03 14:39:15 +0300695 *ps = environ[i];
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400696 }
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øgsberg53880802012-01-09 11:16:50 -0500734 launcher->panel = panel;
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500735 wl_list_insert(panel->launcher_list.prev, &launcher->link);
736
Kristian Høgsberg441338c2012-01-10 13:52:34 -0500737 launcher->widget = widget_add_widget(panel->widget, launcher);
Kristian Høgsberg53880802012-01-09 11:16:50 -0500738 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 Lynch4384a242013-08-08 21:28:22 -0700744 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øgsbergb67e94b2012-01-10 12:23:19 -0500748 widget_set_redraw_handler(launcher->widget,
749 panel_launcher_redraw_handler);
Tiago Vignatti61500722012-05-23 22:06:28 +0300750 widget_set_motion_handler(launcher->widget,
751 panel_launcher_motion_handler);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400752}
753
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500754enum {
755 BACKGROUND_SCALE,
Pekka Paalanena402b052013-05-22 18:03:10 +0300756 BACKGROUND_SCALE_CROP,
Stefan Agner20b24162018-08-22 23:56:07 +0200757 BACKGROUND_TILE,
758 BACKGROUND_CENTERED
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500759};
760
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400761static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500762background_draw(struct widget *widget, void *data)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400763{
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500764 struct background *background = data;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400765 cairo_surface_t *surface, *image;
Kristian Høgsberg7e690002011-09-08 18:18:02 -0400766 cairo_pattern_t *pattern;
767 cairo_matrix_t matrix;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400768 cairo_t *cr;
Pekka Paalanena402b052013-05-22 18:03:10 +0300769 double im_w, im_h;
770 double sx, sy, s;
771 double tx, ty;
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500772 struct rectangle allocation;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400773
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500774 surface = window_get_surface(background->window);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400775
Alexander Larssonc584fa62013-05-22 14:41:32 +0200776 cr = widget_cairo_create(background->widget);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400777 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
Stefan Agner1c1e4fd2018-08-22 23:33:10 +0200778 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øgsberg0c29eb22011-09-06 18:02:34 -0400782 cairo_paint(cr);
783
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500784 widget_get_allocation(widget, &allocation);
Kristian Høgsberg8129bc02012-01-25 14:55:33 -0500785 image = NULL;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300786 if (background->image)
787 image = load_cairo_surface(background->image);
Derek Foremane2772762018-02-06 15:18:38 -0600788 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øgsberg07f72942012-01-25 16:34:36 -0500794
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300795 if (image && background->type != -1) {
Pekka Paalanena402b052013-05-22 18:03:10 +0300796 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øgsberg7e690002011-09-08 18:18:02 -0400801 pattern = cairo_pattern_create_for_surface(image);
Pekka Paalanena402b052013-05-22 18:03:10 +0300802
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300803 switch (background->type) {
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500804 case BACKGROUND_SCALE:
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500805 cairo_matrix_init_scale(&matrix, sx, sy);
806 cairo_pattern_set_matrix(pattern, &matrix);
Bill Spitzak79b7cb32014-05-08 20:00:35 -0700807 cairo_pattern_set_extend(pattern, CAIRO_EXTEND_PAD);
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500808 break;
Pekka Paalanena402b052013-05-22 18:03:10 +0300809 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 Spitzak79b7cb32014-05-08 20:00:35 -0700817 cairo_pattern_set_extend(pattern, CAIRO_EXTEND_PAD);
Pekka Paalanena402b052013-05-22 18:03:10 +0300818 break;
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500819 case BACKGROUND_TILE:
820 cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
821 break;
Stefan Agner20b24162018-08-22 23:56:07 +0200822 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øgsberg07f72942012-01-25 16:34:36 -0500835 }
Pekka Paalanena402b052013-05-22 18:03:10 +0300836
Kristian Høgsberg7e690002011-09-08 18:18:02 -0400837 cairo_set_source(cr, pattern);
838 cairo_pattern_destroy (pattern);
Kristian Høgsberg27d38662011-10-20 13:11:12 -0400839 cairo_surface_destroy(image);
Stefan Agner20b24162018-08-22 23:56:07 +0200840 cairo_mask(cr, pattern);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400841 }
842
843 cairo_destroy(cr);
844 cairo_surface_destroy(surface);
Pekka Paalanen9564c752012-10-24 09:43:08 +0300845
Pekka Paalanen79346ab2013-05-22 18:03:09 +0300846 background->painted = 1;
847 check_desktop_ready(background->window);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400848}
849
850static void
Pekka Paalanencb115382017-12-07 12:15:01 +0200851background_destroy(struct background *background);
852
853static void
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100854background_configure(void *data,
Jonas Ådahl6d6fb612015-11-17 16:00:33 +0800855 struct weston_desktop_shell *desktop_shell,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400856 uint32_t edges, struct window *window,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100857 int32_t width, int32_t height)
858{
Pekka Paalanencb115382017-12-07 12:15:01 +0200859 struct output *owner;
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500860 struct background *background =
861 (struct background *) window_get_user_data(window);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100862
Pekka Paalanencb115382017-12-07 12:15:01 +0200863 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 Shah8ef3ce52020-10-16 06:05:45 +0000871 if (!background->image && background->color) {
Harish Krupo3623e462018-12-11 13:59:07 +0530872 widget_set_viewport_destination(background->widget, width, height);
873 width = 1;
874 height = 1;
875 }
876
Kristian Høgsberg4598f962014-01-01 16:32:09 -0800877 widget_schedule_resize(background->widget, width, height);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100878}
879
880static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500881unlock_dialog_redraw_handler(struct widget *widget, void *data)
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200882{
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500883 struct unlock_dialog *dialog = data;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200884 struct rectangle allocation;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200885 cairo_surface_t *surface;
Alexander Larssonc584fa62013-05-22 14:41:32 +0200886 cairo_t *cr;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200887 cairo_pattern_t *pat;
888 double cx, cy, r, f;
889
Alexander Larssonc584fa62013-05-22 14:41:32 +0200890 cr = widget_cairo_create(widget);
Kristian Høgsberg41c5c4e2012-03-05 20:37:51 -0500891
Kristian Høgsbergbb977002012-01-10 19:11:42 -0500892 widget_get_allocation(dialog->widget, &allocation);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200893 cairo_rectangle(cr, allocation.x, allocation.y,
894 allocation.width, allocation.height);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200895 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
896 cairo_set_source_rgba(cr, 0, 0, 0, 0.6);
Kristian Høgsberg41c5c4e2012-03-05 20:37:51 -0500897 cairo_fill(cr);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200898
Kristian Høgsberg41c5c4e2012-03-05 20:37:51 -0500899 cairo_translate(cr, allocation.x, allocation.y);
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500900 if (dialog->button_focused)
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200901 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øgsberg41c5c4e2012-03-05 20:37:51 -0500913 cairo_pattern_destroy(pat);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200914 cairo_arc(cr, cx, cy, r, 0.0, 2.0 * M_PI);
915 cairo_fill(cr);
916
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500917 widget_set_allocation(dialog->button,
Kristian Høgsberg41c5c4e2012-03-05 20:37:51 -0500918 allocation.x + cx - r,
919 allocation.y + cy - r, 2 * r, 2 * r);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200920
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200921 cairo_destroy(cr);
922
Alexander Larssonc584fa62013-05-22 14:41:32 +0200923 surface = window_get_surface(dialog->window);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200924 cairo_surface_destroy(surface);
925}
926
927static void
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500928unlock_dialog_button_handler(struct widget *widget,
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200929 struct input *input, uint32_t time,
Daniel Stone4dbadb12012-05-30 16:31:51 +0100930 uint32_t button,
931 enum wl_pointer_button_state state, void *data)
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200932{
933 struct unlock_dialog *dialog = data;
934 struct desktop *desktop = dialog->desktop;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200935
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500936 if (button == BTN_LEFT) {
Daniel Stone4dbadb12012-05-30 16:31:51 +0100937 if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
938 !dialog->closing) {
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200939 display_defer(desktop->display, &desktop->unlock_task);
940 dialog->closing = 1;
941 }
942 }
943}
944
945static void
Brian J Lovinc4df4082013-08-26 15:58:22 -0700946unlock_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
956static void
957unlock_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
970static void
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200971unlock_dialog_keyboard_focus_handler(struct window *window,
972 struct input *device, void *data)
973{
974 window_schedule_redraw(window);
975}
976
Kristian Høgsbergbb901fa2012-01-09 11:22:32 -0500977static int
Kristian Høgsbergee143232012-01-09 08:42:24 -0500978unlock_dialog_widget_enter_handler(struct widget *widget,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400979 struct input *input,
Kristian Høgsberg80680c72012-05-10 12:21:37 -0400980 float x, float y, void *data)
Kristian Høgsbergee143232012-01-09 08:42:24 -0500981{
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500982 struct unlock_dialog *dialog = data;
983
984 dialog->button_focused = 1;
Kristian Høgsbergee143232012-01-09 08:42:24 -0500985 widget_schedule_redraw(widget);
Kristian Høgsbergbb901fa2012-01-09 11:22:32 -0500986
Ander Conselvan de Oliveiradc8c8fc2012-05-25 16:01:41 +0300987 return CURSOR_LEFT_PTR;
Kristian Høgsbergee143232012-01-09 08:42:24 -0500988}
989
990static void
991unlock_dialog_widget_leave_handler(struct widget *widget,
992 struct input *input, void *data)
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200993{
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500994 struct unlock_dialog *dialog = data;
995
996 dialog->button_focused = 0;
Kristian Høgsberg9a13dab2012-01-08 15:18:19 -0500997 widget_schedule_redraw(widget);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200998}
999
1000static struct unlock_dialog *
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001001unlock_dialog_create(struct desktop *desktop)
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001002{
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001003 struct display *display = desktop->display;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001004 struct unlock_dialog *dialog;
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001005 struct wl_surface *surface;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001006
Peter Huttererf3d62272013-08-08 11:57:05 +10001007 dialog = xzalloc(sizeof *dialog);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001008
Kristian Høgsberg730c94d2012-06-26 21:44:35 -04001009 dialog->window = window_create_custom(display);
Jason Ekstrandee7fefc2013-10-13 19:08:38 -05001010 dialog->widget = window_frame_create(dialog->window, dialog);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001011 window_set_title(dialog->window, "Unlock your desktop");
1012
1013 window_set_user_data(dialog->window, dialog);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001014 window_set_keyboard_focus_handler(dialog->window,
1015 unlock_dialog_keyboard_focus_handler);
Kristian Høgsberg441338c2012-01-10 13:52:34 -05001016 dialog->button = widget_add_widget(dialog->widget, dialog);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -05001017 widget_set_redraw_handler(dialog->widget,
1018 unlock_dialog_redraw_handler);
Kristian Høgsbergee143232012-01-09 08:42:24 -05001019 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øgsberga8a0db32012-01-09 11:12:05 -05001023 widget_set_button_handler(dialog->button,
1024 unlock_dialog_button_handler);
Brian J Lovinc4df4082013-08-26 15:58:22 -07001025 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 Paalanenbfbb26b2011-11-15 13:34:56 +02001029
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001030 surface = window_get_wl_surface(dialog->window);
1031 weston_desktop_shell_set_lock_surface(desktop->shell, surface);
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001032
Pekka Paalanen40e49ac2012-01-18 16:51:30 +02001033 window_schedule_resize(dialog->window, 260, 230);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001034
1035 return dialog;
1036}
1037
1038static void
1039unlock_dialog_destroy(struct unlock_dialog *dialog)
1040{
1041 window_destroy(dialog->window);
1042 free(dialog);
1043}
1044
1045static void
1046unlock_dialog_finish(struct task *task, uint32_t events)
1047{
1048 struct desktop *desktop =
Benjamin Franzked7759712011-11-22 12:38:48 +01001049 container_of(task, struct desktop, unlock_task);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001050
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001051 weston_desktop_shell_unlock(desktop->shell);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001052 unlock_dialog_destroy(desktop->unlock_dialog);
1053 desktop->unlock_dialog = NULL;
1054}
1055
1056static void
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001057desktop_shell_configure(void *data,
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001058 struct weston_desktop_shell *desktop_shell,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001059 uint32_t edges,
Kristian Høgsberg962342c2012-06-26 16:29:50 -04001060 struct wl_surface *surface,
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001061 int32_t width, int32_t height)
1062{
Kristian Høgsberg962342c2012-06-26 16:29:50 -04001063 struct window *window = wl_surface_get_user_data(surface);
Pekka Paalanen068ae942011-11-28 14:11:15 +02001064 struct surface *s = window_get_user_data(window);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001065
Kristian Høgsbergeae5de72012-04-11 22:42:15 -04001066 s->configure(data, desktop_shell, edges, window, width, height);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001067}
1068
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001069static void
1070desktop_shell_prepare_lock_surface(void *data,
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001071 struct weston_desktop_shell *desktop_shell)
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001072{
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001073 struct desktop *desktop = data;
1074
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001075 if (!desktop->locking) {
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001076 weston_desktop_shell_unlock(desktop->shell);
Pekka Paalanenfd83b6d2011-12-08 10:06:53 +02001077 return;
1078 }
1079
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001080 if (!desktop->unlock_dialog) {
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -05001081 desktop->unlock_dialog = unlock_dialog_create(desktop);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001082 desktop->unlock_dialog->desktop = desktop;
1083 }
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001084}
1085
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001086static void
1087desktop_shell_grab_cursor(void *data,
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001088 struct weston_desktop_shell *desktop_shell,
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001089 uint32_t cursor)
1090{
1091 struct desktop *desktop = data;
1092
1093 switch (cursor) {
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001094 case WESTON_DESKTOP_SHELL_CURSOR_NONE:
Philipp Brüschweiler16d59d72012-08-24 15:43:55 +02001095 desktop->grab_cursor = CURSOR_BLANK;
1096 break;
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001097 case WESTON_DESKTOP_SHELL_CURSOR_BUSY:
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001098 desktop->grab_cursor = CURSOR_WATCH;
1099 break;
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001100 case WESTON_DESKTOP_SHELL_CURSOR_MOVE:
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001101 desktop->grab_cursor = CURSOR_DRAGGING;
1102 break;
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001103 case WESTON_DESKTOP_SHELL_CURSOR_RESIZE_TOP:
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001104 desktop->grab_cursor = CURSOR_TOP;
1105 break;
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001106 case WESTON_DESKTOP_SHELL_CURSOR_RESIZE_BOTTOM:
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001107 desktop->grab_cursor = CURSOR_BOTTOM;
1108 break;
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001109 case WESTON_DESKTOP_SHELL_CURSOR_RESIZE_LEFT:
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001110 desktop->grab_cursor = CURSOR_LEFT;
1111 break;
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001112 case WESTON_DESKTOP_SHELL_CURSOR_RESIZE_RIGHT:
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001113 desktop->grab_cursor = CURSOR_RIGHT;
1114 break;
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001115 case WESTON_DESKTOP_SHELL_CURSOR_RESIZE_TOP_LEFT:
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001116 desktop->grab_cursor = CURSOR_TOP_LEFT;
1117 break;
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001118 case WESTON_DESKTOP_SHELL_CURSOR_RESIZE_TOP_RIGHT:
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001119 desktop->grab_cursor = CURSOR_TOP_RIGHT;
1120 break;
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001121 case WESTON_DESKTOP_SHELL_CURSOR_RESIZE_BOTTOM_LEFT:
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001122 desktop->grab_cursor = CURSOR_BOTTOM_LEFT;
1123 break;
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001124 case WESTON_DESKTOP_SHELL_CURSOR_RESIZE_BOTTOM_RIGHT:
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001125 desktop->grab_cursor = CURSOR_BOTTOM_RIGHT;
1126 break;
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001127 case WESTON_DESKTOP_SHELL_CURSOR_ARROW:
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001128 default:
1129 desktop->grab_cursor = CURSOR_LEFT_PTR;
1130 }
1131}
1132
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001133static const struct weston_desktop_shell_listener listener = {
Pekka Paalanen9ef3e012011-11-15 13:34:48 +02001134 desktop_shell_configure,
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001135 desktop_shell_prepare_lock_surface,
1136 desktop_shell_grab_cursor
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001137};
1138
U. Artie Eoff44874d92012-10-02 21:12:35 -07001139static void
1140background_destroy(struct background *background)
1141{
1142 widget_destroy(background->widget);
1143 window_destroy(background->window);
1144
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001145 free(background->image);
U. Artie Eoff44874d92012-10-02 21:12:35 -07001146 free(background);
1147}
1148
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001149static struct background *
Pekka Paalanencb115382017-12-07 12:15:01 +02001150background_create(struct desktop *desktop, struct output *output)
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001151{
1152 struct background *background;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001153 struct weston_config_section *s;
1154 char *type;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001155
Peter Huttererf3d62272013-08-08 11:57:05 +10001156 background = xzalloc(sizeof *background);
Pekka Paalanencb115382017-12-07 12:15:01 +02001157 background->owner = output;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001158 background->base.configure = background_configure;
Kristian Høgsberg962342c2012-06-26 16:29:50 -04001159 background->window = window_create_custom(desktop->display);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -05001160 background->widget = window_add_widget(background->window, background);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001161 window_set_user_data(background->window, background);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -05001162 widget_set_redraw_handler(background->widget, background_draw);
Arnaud Vracfb754a02014-08-25 20:56:49 +02001163 widget_set_transparent(background->widget, 0);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001164
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001165 s = weston_config_get_section(desktop->config, "shell", NULL, NULL);
1166 weston_config_section_get_string(s, "background-image",
Kristian Høgsberg4c3661f2014-04-21 22:54:37 -07001167 &background->image, NULL);
Bryce Harringtone776f2a2016-07-14 18:28:03 -07001168 weston_config_section_get_color(s, "background-color",
1169 &background->color, 0x00000000);
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001170
1171 weston_config_section_get_string(s, "background-type",
1172 &type, "tile");
U. Artie Eoff3c946772014-01-15 10:59:50 -08001173 if (type == NULL) {
1174 fprintf(stderr, "%s: out of memory\n", program_invocation_short_name);
1175 exit(EXIT_FAILURE);
1176 }
1177
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001178 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 Agner20b24162018-08-22 23:56:07 +02001184 } else if (strcmp(type, "centered") == 0) {
1185 background->type = BACKGROUND_CENTERED;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001186 } else {
1187 background->type = -1;
1188 fprintf(stderr, "invalid background-type: %s\n",
1189 type);
1190 }
1191
1192 free(type);
1193
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001194 return background;
1195}
1196
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001197static int
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001198grab_surface_enter_handler(struct widget *widget, struct input *input,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001199 float x, float y, void *data)
1200{
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001201 struct desktop *desktop = data;
1202
1203 return desktop->grab_cursor;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001204}
1205
1206static void
U. Artie Eoff44874d92012-10-02 21:12:35 -07001207grab_surface_destroy(struct desktop *desktop)
1208{
1209 widget_destroy(desktop->grab_widget);
1210 window_destroy(desktop->grab_window);
1211}
1212
1213static void
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001214grab_surface_create(struct desktop *desktop)
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001215{
1216 struct wl_surface *s;
1217
Ander Conselvan de Oliveira07a91cd2012-07-16 14:15:50 +03001218 desktop->grab_window = window_create_custom(desktop->display);
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001219 window_set_user_data(desktop->grab_window, desktop);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001220
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001221 s = window_get_wl_surface(desktop->grab_window);
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001222 weston_desktop_shell_set_grab_surface(desktop->shell, s);
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001223
1224 desktop->grab_widget =
1225 window_add_widget(desktop->grab_window, desktop);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001226 /* 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 Oliveirab9d2a0f2012-06-28 18:08:05 +03001228 widget_set_allocation(desktop->grab_widget, 0, 0, 1, 1);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001229
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001230 widget_set_enter_handler(desktop->grab_widget,
1231 grab_surface_enter_handler);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001232}
1233
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001234static void
U. Artie Eoff44874d92012-10-02 21:12:35 -07001235output_destroy(struct output *output)
1236{
Pekka Paalanencb115382017-12-07 12:15:01 +02001237 if (output->background)
1238 background_destroy(output->background);
Jonny Lambe67118c2014-08-12 15:07:51 +02001239 if (output->panel)
1240 panel_destroy(output->panel);
U. Artie Eoff44874d92012-10-02 21:12:35 -07001241 wl_output_destroy(output->output);
1242 wl_list_remove(&output->link);
1243
1244 free(output);
1245}
1246
1247static void
1248desktop_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
1257static void
Alexander Larssonc584fa62013-05-22 14:41:32 +02001258output_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 Paalanenc1bcce62017-12-07 15:30:18 +02001270 output->x = x;
1271 output->y = y;
1272
Jonny Lambe67118c2014-08-12 15:07:51 +02001273 if (output->panel)
1274 window_set_buffer_transform(output->panel->window, transform);
Pekka Paalanencb115382017-12-07 12:15:01 +02001275 if (output->background)
1276 window_set_buffer_transform(output->background->window, transform);
Alexander Larssonc584fa62013-05-22 14:41:32 +02001277}
1278
1279static void
1280output_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
1289static void
1290output_handle_done(void *data,
1291 struct wl_output *wl_output)
1292{
1293}
1294
1295static void
1296output_handle_scale(void *data,
1297 struct wl_output *wl_output,
Alexander Larssonedddbd12013-05-24 13:09:43 +02001298 int32_t scale)
Alexander Larssonc584fa62013-05-22 14:41:32 +02001299{
1300 struct output *output = data;
1301
Jonny Lambe67118c2014-08-12 15:07:51 +02001302 if (output->panel)
1303 window_set_buffer_scale(output->panel->window, scale);
Pekka Paalanencb115382017-12-07 12:15:01 +02001304 if (output->background)
1305 window_set_buffer_scale(output->background->window, scale);
Alexander Larssonc584fa62013-05-22 14:41:32 +02001306}
1307
1308static 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
1315static void
Ander Conselvan de Oliveirae4925492013-07-05 16:05:28 +03001316output_init(struct output *output, struct desktop *desktop)
1317{
1318 struct wl_surface *surface;
1319
Quentin Glidic55d57012016-06-23 18:55:18 +02001320 if (desktop->want_panel) {
Pekka Paalanen1cbfcf42017-12-07 12:39:15 +02001321 output->panel = panel_create(desktop, output);
Jonny Lambe67118c2014-08-12 15:07:51 +02001322 surface = window_get_wl_surface(output->panel->window);
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001323 weston_desktop_shell_set_panel(desktop->shell,
1324 output->output, surface);
Jonny Lambe67118c2014-08-12 15:07:51 +02001325 }
Ander Conselvan de Oliveirae4925492013-07-05 16:05:28 +03001326
Pekka Paalanencb115382017-12-07 12:15:01 +02001327 output->background = background_create(desktop, output);
Ander Conselvan de Oliveirae4925492013-07-05 16:05:28 +03001328 surface = window_get_wl_surface(output->background->window);
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001329 weston_desktop_shell_set_background(desktop->shell,
1330 output->output, surface);
Ander Conselvan de Oliveirae4925492013-07-05 16:05:28 +03001331}
1332
1333static void
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001334create_output(struct desktop *desktop, uint32_t id)
1335{
1336 struct output *output;
1337
Bryce Harrington0d1a6222016-02-11 16:42:49 -08001338 output = zalloc(sizeof *output);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001339 if (!output)
1340 return;
1341
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001342 output->output =
Alexander Larssonc584fa62013-05-22 14:41:32 +02001343 display_bind(desktop->display, id, &wl_output_interface, 2);
limin.tian3fb40df2025-01-09 07:15:04 +00001344
1345 if (output->output == NULL ) {
1346 fprintf(stderr, "%s output fail, return \n",__FUNCTION__);
1347 return;
1348 }
Xiong Zhang83d8ee72013-10-23 13:58:35 +08001349 output->server_output_id = id;
Alexander Larssonc584fa62013-05-22 14:41:32 +02001350
1351 wl_output_add_listener(output->output, &output_listener, output);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001352
1353 wl_list_insert(&desktop->outputs, &output->link);
Ander Conselvan de Oliveirae4925492013-07-05 16:05:28 +03001354
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 Franzked0f79ab2011-11-22 12:43:52 +01001359}
1360
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001361static void
Pekka Paalanenc1bcce62017-12-07 15:30:18 +02001362output_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 Paalanen82dd54d2018-06-21 15:38:56 +03001386 /* 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 Paalanenc1bcce62017-12-07 15:30:18 +02001397
Pekka Paalanen82dd54d2018-06-21 15:38:56 +03001398 if (!rep->background) {
1399 rep->background = output->background;
1400 output->background = NULL;
1401 rep->background->owner = rep;
1402 }
Pekka Paalanenc1bcce62017-12-07 15:30:18 +02001403
Pekka Paalanen82dd54d2018-06-21 15:38:56 +03001404 if (!rep->panel) {
1405 rep->panel = output->panel;
1406 output->panel = NULL;
1407 if (rep->panel)
1408 rep->panel->owner = rep;
1409 }
Pekka Paalanenc1bcce62017-12-07 15:30:18 +02001410 }
1411
1412 output_destroy(output);
1413}
1414
1415static void
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001416global_handler(struct display *display, uint32_t id,
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001417 const char *interface, uint32_t version, void *data)
1418{
1419 struct desktop *desktop = data;
1420
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001421 if (!strcmp(interface, "weston_desktop_shell")) {
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001422 desktop->shell = display_bind(desktop->display,
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001423 id,
1424 &weston_desktop_shell_interface,
1425 1);
1426 weston_desktop_shell_add_listener(desktop->shell,
1427 &listener,
1428 desktop);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001429 } else if (!strcmp(interface, "wl_output")) {
1430 create_output(desktop, id);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001431 }
1432}
1433
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -05001434static void
Xiong Zhang83d8ee72013-10-23 13:58:35 +08001435global_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 Paalanenc1bcce62017-12-07 15:30:18 +02001444 output_remove(desktop, output);
Xiong Zhang83d8ee72013-10-23 13:58:35 +08001445 break;
1446 }
1447 }
1448 }
1449}
1450
1451static void
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001452panel_add_launchers(struct panel *panel, struct desktop *desktop)
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -05001453{
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001454 struct weston_config_section *s;
1455 char *icon, *path;
1456 const char *name;
1457 int count;
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -05001458
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001459 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 Bradford09252d42013-07-26 16:29:45 +01001470 count++;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001471 } else {
1472 fprintf(stderr, "invalid launcher section\n");
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001473 }
1474
1475 free(icon);
1476 free(path);
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -05001477 }
1478
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001479 if (count == 0) {
Emmanuel Gil Peyroteff793a2021-07-31 17:25:41 +02001480 char *name = file_name_with_datadir("terminal.png");
Derek Foremane2772762018-02-06 15:18:38 -06001481
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001482 /* add default launcher */
1483 panel_add_launcher(panel,
Derek Foremane2772762018-02-06 15:18:38 -06001484 name,
Rodney Lorrimar99ff01b2012-02-29 17:31:03 +01001485 BINDIR "/weston-terminal");
Derek Foremane2772762018-02-06 15:18:38 -06001486 free(name);
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001487 }
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -05001488}
1489
Quentin Glidic55d57012016-06-23 18:55:18 +02001490static void
1491parse_panel_position(struct desktop *desktop, struct weston_config_section *s)
1492{
1493 char *position;
1494
Daniel Stone08cf24b2017-01-16 13:18:21 +00001495 desktop->want_panel = 1;
Quentin Glidic55d57012016-06-23 18:55:18 +02001496
Daniel Stone08cf24b2017-01-16 13:18:21 +00001497 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 Glidic55d57012016-06-23 18:55:18 +02001511 }
Daniel Stone08cf24b2017-01-16 13:18:21 +00001512 free(position);
Quentin Glidic55d57012016-06-23 18:55:18 +02001513}
1514
Quentin Glidic3e37b342016-06-23 18:55:22 +02001515static void
1516parse_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 Niroa11bc632020-10-30 15:09:23 -04001525 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 Glidic3e37b342016-06-23 18:55:22 +02001529 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øgsberg0c29eb22011-09-06 18:02:34 -04001536int main(int argc, char *argv[])
1537{
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001538 struct desktop desktop = { 0 };
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001539 struct output *output;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001540 struct weston_config_section *s;
Pekka Paalanen6c71aae2015-03-24 15:56:19 +02001541 const char *config_file;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001542
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001543 desktop.unlock_task.run = unlock_dialog_finish;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001544 wl_list_init(&desktop.outputs);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001545
Pekka Paalanen6c71aae2015-03-24 15:56:19 +02001546 config_file = weston_config_get_name_from_env();
1547 desktop.config = weston_config_parse(config_file);
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001548 s = weston_config_get_section(desktop.config, "shell", NULL, NULL);
Daniel Stone51d995a2019-11-26 00:14:24 +00001549 weston_config_section_get_bool(s, "locking", &desktop.locking, true);
Quentin Glidic55d57012016-06-23 18:55:18 +02001550 parse_panel_position(&desktop, s);
Quentin Glidic3e37b342016-06-23 18:55:22 +02001551 parse_clock_format(&desktop, s);
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001552
Kristian Høgsberg4172f662013-02-20 15:27:49 -05001553 desktop.display = display_create(&argc, argv);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001554 if (desktop.display == NULL) {
Antonio Borneo39578632019-04-26 23:57:31 +02001555 fprintf(stderr, "failed to create display: %s\n",
1556 strerror(errno));
Anurup Mc640cb62020-11-25 06:35:40 +05301557 weston_config_destroy(desktop.config);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001558 return -1;
1559 }
1560
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001561 display_set_user_data(desktop.display, &desktop);
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001562 display_set_global_handler(desktop.display, global_handler);
Xiong Zhang83d8ee72013-10-23 13:58:35 +08001563 display_set_global_handler_remove(desktop.display, global_handler_remove);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001564
Ander Conselvan de Oliveirae4925492013-07-05 16:05:28 +03001565 /* Create panel and background for outputs processed before the shell
1566 * global interface was processed */
Quentin Glidic55d57012016-06-23 18:55:18 +02001567 if (desktop.want_panel)
1568 weston_desktop_shell_set_panel_position(desktop.shell, desktop.panel_position);
Ander Conselvan de Oliveirae4925492013-07-05 16:05:28 +03001569 wl_list_for_each(output, &desktop.outputs, link)
1570 if (!output->panel)
1571 output_init(output, &desktop);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001572
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001573 grab_surface_create(&desktop);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001574
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001575 signal(SIGCHLD, sigchild_handler);
1576
1577 display_run(desktop.display);
1578
U. Artie Eoff44874d92012-10-02 21:12:35 -07001579 /* Cleanup */
1580 grab_surface_destroy(&desktop);
1581 desktop_destroy_outputs(&desktop);
1582 if (desktop.unlock_dialog)
1583 unlock_dialog_destroy(desktop.unlock_dialog);
Jonas Ådahl6d6fb612015-11-17 16:00:33 +08001584 weston_desktop_shell_destroy(desktop.shell);
U. Artie Eoff44874d92012-10-02 21:12:35 -07001585 display_destroy(desktop.display);
Anurup Mc640cb62020-11-25 06:35:40 +05301586 weston_config_destroy(desktop.config);
U. Artie Eoff44874d92012-10-02 21:12:35 -07001587
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001588 return 0;
1589}