blob: 777a50a7416fa91399641aab78b78c286430af84 [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 *
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting documentation, and
9 * that the name of the copyright holders not be used in advertising or
10 * publicity pertaining to distribution of the software without specific,
11 * written prior permission. The copyright holders make no representations
12 * about the suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
14 *
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 * OF THIS SOFTWARE.
22 */
23
U. Artie Eoff3c946772014-01-15 10:59:50 -080024#include "config.h"
25
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040026#include <stdint.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30#include <fcntl.h>
31#include <unistd.h>
U. Artie Eoff3c946772014-01-15 10:59:50 -080032#include <errno.h>
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040033#include <math.h>
34#include <cairo.h>
35#include <sys/wait.h>
Martin Minarik1e51a872012-06-08 00:39:11 +020036#include <sys/timerfd.h>
Michael Vetter2a18a522015-05-15 17:17:47 +020037#include <sys/epoll.h>
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040038#include <linux/input.h>
Tiago Vignatti61500722012-05-23 22:06:28 +030039#include <libgen.h>
Kristian Høgsbergd1936b92012-07-23 22:59:33 -040040#include <ctype.h>
Martin Minarik1e51a872012-06-08 00:39:11 +020041#include <time.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"
Kristian Høgsberg5a315bc2012-05-15 22:33:43 -040045#include "../shared/cairo-util.h"
Kristian Høgsberg9b935c82011-12-08 12:44:27 -050046#include "../shared/config-parser.h"
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040047
Pekka Paalanen50719bc2011-11-22 14:18:50 +020048#include "desktop-shell-client-protocol.h"
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040049
Pekka Paalanenb6df4f72012-08-03 14:39:15 +030050extern char **environ; /* defined by libc */
51
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040052struct desktop {
53 struct display *display;
54 struct desktop_shell *shell;
Pekka Paalanen79346ab2013-05-22 18:03:09 +030055 uint32_t interface_version;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +020056 struct unlock_dialog *unlock_dialog;
57 struct task unlock_task;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010058 struct wl_list outputs;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -040059
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +030060 struct window *grab_window;
61 struct widget *grab_widget;
62
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +030063 struct weston_config *config;
64 int locking;
65
Scott Moreauec116022012-07-22 18:23:52 -060066 enum cursor_type grab_cursor;
Pekka Paalanen79346ab2013-05-22 18:03:09 +030067
68 int painted;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010069};
70
71struct surface {
72 void (*configure)(void *data,
73 struct desktop_shell *desktop_shell,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -040074 uint32_t edges, struct window *window,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010075 int32_t width, int32_t height);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040076};
77
78struct panel {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010079 struct surface base;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040080 struct window *window;
Kristian Høgsberg75bc6672012-01-10 09:43:58 -050081 struct widget *widget;
Kristian Høgsberg75bc6672012-01-10 09:43:58 -050082 struct wl_list launcher_list;
Martin Minarik1e51a872012-06-08 00:39:11 +020083 struct panel_clock *clock;
Pekka Paalanen79346ab2013-05-22 18:03:09 +030084 int painted;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +030085 uint32_t color;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040086};
87
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010088struct background {
89 struct surface base;
90 struct window *window;
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -050091 struct widget *widget;
Pekka Paalanen79346ab2013-05-22 18:03:09 +030092 int painted;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +030093
94 char *image;
95 int type;
96 uint32_t color;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010097};
98
99struct output {
100 struct wl_output *output;
Xiong Zhang83d8ee72013-10-23 13:58:35 +0800101 uint32_t server_output_id;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100102 struct wl_list link;
103
104 struct panel *panel;
105 struct background *background;
106};
107
Kristian Høgsberg53880802012-01-09 11:16:50 -0500108struct panel_launcher {
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500109 struct widget *widget;
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400110 struct panel *panel;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400111 cairo_surface_t *icon;
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500112 int focused, pressed;
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400113 char *path;
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500114 struct wl_list link;
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400115 struct wl_array envp;
116 struct wl_array argv;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400117};
118
Martin Minarik1e51a872012-06-08 00:39:11 +0200119struct panel_clock {
120 struct widget *widget;
121 struct panel *panel;
Martin Minarik1e51a872012-06-08 00:39:11 +0200122 struct task clock_task;
123 int clock_fd;
124};
125
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200126struct unlock_dialog {
127 struct window *window;
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500128 struct widget *widget;
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500129 struct widget *button;
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500130 int button_focused;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200131 int closing;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200132 struct desktop *desktop;
133};
134
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300135static void
136panel_add_launchers(struct panel *panel, struct desktop *desktop);
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -0500137
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400138static void
139sigchild_handler(int s)
140{
141 int status;
142 pid_t pid;
143
144 while (pid = waitpid(-1, &status, WNOHANG), pid > 0)
145 fprintf(stderr, "child %d exited\n", pid);
146}
147
Pekka Paalanen79346ab2013-05-22 18:03:09 +0300148static int
149is_desktop_painted(struct desktop *desktop)
150{
151 struct output *output;
152
153 wl_list_for_each(output, &desktop->outputs, link) {
154 if (output->panel && !output->panel->painted)
155 return 0;
156 if (output->background && !output->background->painted)
157 return 0;
158 }
159
160 return 1;
161}
162
163static void
164check_desktop_ready(struct window *window)
165{
166 struct display *display;
167 struct desktop *desktop;
168
169 display = window_get_display(window);
170 desktop = display_get_user_data(display);
171
172 if (!desktop->painted && is_desktop_painted(desktop)) {
173 desktop->painted = 1;
174
175 if (desktop->interface_version >= 2)
176 desktop_shell_desktop_ready(desktop->shell);
177 }
178}
179
Kristian Høgsbergbcee9a42011-10-12 00:36:16 -0400180static void
Kristian Høgsberg53880802012-01-09 11:16:50 -0500181panel_launcher_activate(struct panel_launcher *widget)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400182{
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400183 char **argv;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400184 pid_t pid;
185
186 pid = fork();
187 if (pid < 0) {
188 fprintf(stderr, "fork failed: %m\n");
189 return;
190 }
191
192 if (pid)
193 return;
Benjamin Franzked7759712011-11-22 12:38:48 +0100194
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400195 argv = widget->argv.data;
196 if (execve(argv[0], argv, widget->envp.data) < 0) {
197 fprintf(stderr, "execl '%s' failed: %m\n", argv[0]);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400198 exit(1);
199 }
200}
201
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400202static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500203panel_launcher_redraw_handler(struct widget *widget, void *data)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400204{
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500205 struct panel_launcher *launcher = data;
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500206 struct rectangle allocation;
207 cairo_t *cr;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400208
Alexander Larssonc584fa62013-05-22 14:41:32 +0200209 cr = widget_cairo_create(launcher->panel->widget);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500210
211 widget_get_allocation(widget, &allocation);
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500212 if (launcher->pressed) {
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500213 allocation.x++;
214 allocation.y++;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400215 }
216
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500217 cairo_set_source_surface(cr, launcher->icon,
218 allocation.x, allocation.y);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400219 cairo_paint(cr);
220
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500221 if (launcher->focused) {
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400222 cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.4);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500223 cairo_mask_surface(cr, launcher->icon,
224 allocation.x, allocation.y);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400225 }
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400226
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500227 cairo_destroy(cr);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400228}
229
Tiago Vignatti61500722012-05-23 22:06:28 +0300230static int
231panel_launcher_motion_handler(struct widget *widget, struct input *input,
232 uint32_t time, float x, float y, void *data)
233{
234 struct panel_launcher *launcher = data;
235
236 widget_set_tooltip(widget, basename((char *)launcher->path), x, y);
237
Ander Conselvan de Oliveiradc8c8fc2012-05-25 16:01:41 +0300238 return CURSOR_LEFT_PTR;
Tiago Vignatti61500722012-05-23 22:06:28 +0300239}
240
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400241static void
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -0500242set_hex_color(cairo_t *cr, uint32_t color)
243{
Michael Vetter2a18a522015-05-15 17:17:47 +0200244 cairo_set_source_rgba(cr,
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -0500245 ((color >> 16) & 0xff) / 255.0,
246 ((color >> 8) & 0xff) / 255.0,
247 ((color >> 0) & 0xff) / 255.0,
248 ((color >> 24) & 0xff) / 255.0);
249}
250
251static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500252panel_redraw_handler(struct widget *widget, void *data)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400253{
254 cairo_surface_t *surface;
255 cairo_t *cr;
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500256 struct panel *panel = data;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400257
Alexander Larssonc584fa62013-05-22 14:41:32 +0200258 cr = widget_cairo_create(panel->widget);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400259 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300260 set_hex_color(cr, panel->color);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400261 cairo_paint(cr);
262
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400263 cairo_destroy(cr);
Alexander Larssonc584fa62013-05-22 14:41:32 +0200264 surface = window_get_surface(panel->window);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400265 cairo_surface_destroy(surface);
Pekka Paalanen79346ab2013-05-22 18:03:09 +0300266 panel->painted = 1;
267 check_desktop_ready(panel->window);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400268}
269
Kristian Høgsbergbb901fa2012-01-09 11:22:32 -0500270static int
Kristian Høgsberg53880802012-01-09 11:16:50 -0500271panel_launcher_enter_handler(struct widget *widget, struct input *input,
Kristian Høgsberg80680c72012-05-10 12:21:37 -0400272 float x, float y, void *data)
Kristian Høgsbergee143232012-01-09 08:42:24 -0500273{
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500274 struct panel_launcher *launcher = data;
275
276 launcher->focused = 1;
Kristian Høgsbergee143232012-01-09 08:42:24 -0500277 widget_schedule_redraw(widget);
Kristian Høgsbergbb901fa2012-01-09 11:22:32 -0500278
Ander Conselvan de Oliveiradc8c8fc2012-05-25 16:01:41 +0300279 return CURSOR_LEFT_PTR;
Kristian Høgsbergee143232012-01-09 08:42:24 -0500280}
281
282static void
Kristian Høgsberg53880802012-01-09 11:16:50 -0500283panel_launcher_leave_handler(struct widget *widget,
284 struct input *input, void *data)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400285{
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500286 struct panel_launcher *launcher = data;
287
288 launcher->focused = 0;
Tiago Vignatti61500722012-05-23 22:06:28 +0300289 widget_destroy_tooltip(widget);
Kristian Høgsberg9a13dab2012-01-08 15:18:19 -0500290 widget_schedule_redraw(widget);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400291}
292
293static void
Kristian Høgsberg53880802012-01-09 11:16:50 -0500294panel_launcher_button_handler(struct widget *widget,
295 struct input *input, uint32_t time,
Daniel Stone4dbadb12012-05-30 16:31:51 +0100296 uint32_t button,
297 enum wl_pointer_button_state state, void *data)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400298{
Kristian Høgsberg53880802012-01-09 11:16:50 -0500299 struct panel_launcher *launcher;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400300
Kristian Høgsberg53880802012-01-09 11:16:50 -0500301 launcher = widget_get_user_data(widget);
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500302 widget_schedule_redraw(widget);
Daniel Stone4dbadb12012-05-30 16:31:51 +0100303 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
Kristian Høgsberg53880802012-01-09 11:16:50 -0500304 panel_launcher_activate(launcher);
Rusty Lynch4384a242013-08-08 21:28:22 -0700305
306}
307
308static void
Rusty Lynch1084da52013-08-15 09:10:08 -0700309panel_launcher_touch_down_handler(struct widget *widget, struct input *input,
310 uint32_t serial, uint32_t time, int32_t id,
Rusty Lynch4384a242013-08-08 21:28:22 -0700311 float x, float y, void *data)
312{
313 struct panel_launcher *launcher;
314
315 launcher = widget_get_user_data(widget);
316 launcher->focused = 1;
317 widget_schedule_redraw(widget);
318}
319
320static void
Rusty Lynch1084da52013-08-15 09:10:08 -0700321panel_launcher_touch_up_handler(struct widget *widget, struct input *input,
Michael Vetter2a18a522015-05-15 17:17:47 +0200322 uint32_t serial, uint32_t time, int32_t id,
Rusty Lynch1084da52013-08-15 09:10:08 -0700323 void *data)
Rusty Lynch4384a242013-08-08 21:28:22 -0700324{
325 struct panel_launcher *launcher;
326
327 launcher = widget_get_user_data(widget);
328 launcher->focused = 0;
329 widget_schedule_redraw(widget);
330 panel_launcher_activate(launcher);
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500331}
332
Martin Minarik1e51a872012-06-08 00:39:11 +0200333static void
334clock_func(struct task *task, uint32_t events)
335{
336 struct panel_clock *clock =
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400337 container_of(task, struct panel_clock, clock_task);
Kristian Høgsberg70226bb2012-06-08 16:54:52 -0400338 uint64_t exp;
Martin Minarik1e51a872012-06-08 00:39:11 +0200339
Martin Olsson8df662a2012-07-08 03:03:47 +0200340 if (read(clock->clock_fd, &exp, sizeof exp) != sizeof exp)
341 abort();
Kristian Høgsberg92a984a2012-06-11 11:10:57 -0400342 widget_schedule_redraw(clock->widget);
Martin Minarik1e51a872012-06-08 00:39:11 +0200343}
344
345static void
346panel_clock_redraw_handler(struct widget *widget, void *data)
347{
Martin Minarik1e51a872012-06-08 00:39:11 +0200348 struct panel_clock *clock = data;
349 cairo_t *cr;
350 struct rectangle allocation;
351 cairo_text_extents_t extents;
352 cairo_font_extents_t font_extents;
Martin Minarik1e51a872012-06-08 00:39:11 +0200353 time_t rawtime;
354 struct tm * timeinfo;
Kristian Høgsberg92a984a2012-06-11 11:10:57 -0400355 char string[128];
Martin Minarik1e51a872012-06-08 00:39:11 +0200356
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400357 time(&rawtime);
358 timeinfo = localtime(&rawtime);
Kristian Høgsberge9f68f62012-06-11 12:24:12 -0400359 strftime(string, sizeof string, "%a %b %d, %I:%M %p", timeinfo);
Martin Minarik1e51a872012-06-08 00:39:11 +0200360
361 widget_get_allocation(widget, &allocation);
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400362 if (allocation.width == 0)
363 return;
Martin Minarik1e51a872012-06-08 00:39:11 +0200364
Alexander Larssonc584fa62013-05-22 14:41:32 +0200365 cr = widget_cairo_create(clock->panel->widget);
Martin Minarik1e51a872012-06-08 00:39:11 +0200366 cairo_select_font_face(cr, "sans",
367 CAIRO_FONT_SLANT_NORMAL,
368 CAIRO_FONT_WEIGHT_NORMAL);
369 cairo_set_font_size(cr, 14);
Kristian Høgsberg92a984a2012-06-11 11:10:57 -0400370 cairo_text_extents(cr, string, &extents);
Martin Minarik1e51a872012-06-08 00:39:11 +0200371 cairo_font_extents (cr, &font_extents);
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400372 cairo_move_to(cr, allocation.x + 5,
373 allocation.y + 3 * (allocation.height >> 2) + 1);
374 cairo_set_source_rgb(cr, 0, 0, 0);
Kristian Høgsberg92a984a2012-06-11 11:10:57 -0400375 cairo_show_text(cr, string);
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400376 cairo_move_to(cr, allocation.x + 4,
377 allocation.y + 3 * (allocation.height >> 2));
378 cairo_set_source_rgb(cr, 1, 1, 1);
Kristian Høgsberg92a984a2012-06-11 11:10:57 -0400379 cairo_show_text(cr, string);
Martin Minarik1e51a872012-06-08 00:39:11 +0200380 cairo_destroy(cr);
381}
382
383static int
384clock_timer_reset(struct panel_clock *clock)
385{
386 struct itimerspec its;
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400387
Kristian Høgsberge9f68f62012-06-11 12:24:12 -0400388 its.it_interval.tv_sec = 60;
Martin Minarik1e51a872012-06-08 00:39:11 +0200389 its.it_interval.tv_nsec = 0;
Kristian Høgsberge9f68f62012-06-11 12:24:12 -0400390 its.it_value.tv_sec = 60;
Martin Minarik1e51a872012-06-08 00:39:11 +0200391 its.it_value.tv_nsec = 0;
392 if (timerfd_settime(clock->clock_fd, 0, &its, NULL) < 0) {
393 fprintf(stderr, "could not set timerfd\n: %m");
394 return -1;
395 }
396
397 return 0;
398}
399
400static void
U. Artie Eoff44874d92012-10-02 21:12:35 -0700401panel_destroy_clock(struct panel_clock *clock)
402{
403 widget_destroy(clock->widget);
404
405 close(clock->clock_fd);
406
407 free(clock);
408}
409
410static void
Martin Minarik1e51a872012-06-08 00:39:11 +0200411panel_add_clock(struct panel *panel)
412{
413 struct panel_clock *clock;
414 int timerfd;
415
416 timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
417 if (timerfd < 0) {
418 fprintf(stderr, "could not create timerfd\n: %m");
419 return;
420 }
421
Peter Huttererf3d62272013-08-08 11:57:05 +1000422 clock = xzalloc(sizeof *clock);
Martin Minarik1e51a872012-06-08 00:39:11 +0200423 clock->panel = panel;
424 panel->clock = clock;
425 clock->clock_fd = timerfd;
426
427 clock->clock_task.run = clock_func;
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400428 display_watch_fd(window_get_display(panel->window), clock->clock_fd,
429 EPOLLIN, &clock->clock_task);
Martin Minarik1e51a872012-06-08 00:39:11 +0200430 clock_timer_reset(clock);
431
432 clock->widget = widget_add_widget(panel->widget, clock);
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400433 widget_set_redraw_handler(clock->widget, panel_clock_redraw_handler);
Martin Minarik1e51a872012-06-08 00:39:11 +0200434}
435
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500436static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500437panel_resize_handler(struct widget *widget,
438 int32_t width, int32_t height, void *data)
439{
440 struct panel_launcher *launcher;
441 struct panel *panel = data;
442 int x, y, w, h;
Michael Vetter2a18a522015-05-15 17:17:47 +0200443
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500444 x = 10;
445 y = 16;
446 wl_list_for_each(launcher, &panel->launcher_list, link) {
447 w = cairo_image_surface_get_width(launcher->icon);
448 h = cairo_image_surface_get_height(launcher->icon);
449 widget_set_allocation(launcher->widget,
450 x, y - h / 2, w + 1, h + 1);
451 x += w + 10;
452 }
Martin Minarik1e51a872012-06-08 00:39:11 +0200453 h=20;
454 w=170;
Pekka Paalanen01b17252012-06-12 17:42:26 +0300455
456 if (panel->clock)
457 widget_set_allocation(panel->clock->widget,
458 width - w - 8, y - h / 2, w + 1, h + 1);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500459}
460
461static void
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100462panel_configure(void *data,
463 struct desktop_shell *desktop_shell,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400464 uint32_t edges, struct window *window,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100465 int32_t width, int32_t height)
466{
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500467 struct surface *surface = window_get_user_data(window);
468 struct panel *panel = container_of(surface, struct panel, base);
469
470 window_schedule_resize(panel->window, width, 32);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100471}
472
U. Artie Eoff44874d92012-10-02 21:12:35 -0700473static void
474panel_destroy_launcher(struct panel_launcher *launcher)
475{
476 wl_array_release(&launcher->argv);
477 wl_array_release(&launcher->envp);
478
479 free(launcher->path);
480
481 cairo_surface_destroy(launcher->icon);
482
483 widget_destroy(launcher->widget);
484 wl_list_remove(&launcher->link);
485
486 free(launcher);
487}
488
489static void
490panel_destroy(struct panel *panel)
491{
492 struct panel_launcher *tmp;
493 struct panel_launcher *launcher;
494
495 panel_destroy_clock(panel->clock);
496
497 wl_list_for_each_safe(launcher, tmp, &panel->launcher_list, link)
498 panel_destroy_launcher(launcher);
499
500 widget_destroy(panel->widget);
501 window_destroy(panel->window);
502
503 free(panel);
504}
505
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400506static struct panel *
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300507panel_create(struct desktop *desktop)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400508{
509 struct panel *panel;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300510 struct weston_config_section *s;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400511
Peter Huttererf3d62272013-08-08 11:57:05 +1000512 panel = xzalloc(sizeof *panel);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400513
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100514 panel->base.configure = panel_configure;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300515 panel->window = window_create_custom(desktop->display);
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500516 panel->widget = window_add_widget(panel->window, panel);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500517 wl_list_init(&panel->launcher_list);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400518
519 window_set_title(panel->window, "panel");
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400520 window_set_user_data(panel->window, panel);
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500521
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500522 widget_set_redraw_handler(panel->widget, panel_redraw_handler);
523 widget_set_resize_handler(panel->widget, panel_resize_handler);
Michael Vetter2a18a522015-05-15 17:17:47 +0200524
Rafal Mielniczukb9e513c2012-06-09 20:33:29 +0200525 panel_add_clock(panel);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400526
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300527 s = weston_config_get_section(desktop->config, "shell", NULL, NULL);
528 weston_config_section_get_uint(s, "panel-color",
529 &panel->color, 0xaa000000);
530
531 panel_add_launchers(panel, desktop);
532
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400533 return panel;
534}
535
Philipp Brüschweiler467668c2012-08-29 10:53:36 +0200536static cairo_surface_t *
537load_icon_or_fallback(const char *icon)
538{
539 cairo_surface_t *surface = cairo_image_surface_create_from_png(icon);
Philipp Brüschweiler96386b82013-04-15 20:10:40 +0200540 cairo_status_t status;
Philipp Brüschweiler467668c2012-08-29 10:53:36 +0200541 cairo_t *cr;
542
Philipp Brüschweiler96386b82013-04-15 20:10:40 +0200543 status = cairo_surface_status(surface);
544 if (status == CAIRO_STATUS_SUCCESS)
Philipp Brüschweiler467668c2012-08-29 10:53:36 +0200545 return surface;
546
547 cairo_surface_destroy(surface);
Philipp Brüschweiler96386b82013-04-15 20:10:40 +0200548 fprintf(stderr, "ERROR loading icon from file '%s', error: '%s'\n",
549 icon, cairo_status_to_string(status));
Philipp Brüschweiler467668c2012-08-29 10:53:36 +0200550
551 /* draw fallback icon */
552 surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
553 20, 20);
554 cr = cairo_create(surface);
555
556 cairo_set_source_rgba(cr, 0.8, 0.8, 0.8, 1);
557 cairo_paint(cr);
558
559 cairo_set_source_rgba(cr, 0, 0, 0, 1);
560 cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
561 cairo_rectangle(cr, 0, 0, 20, 20);
562 cairo_move_to(cr, 4, 4);
563 cairo_line_to(cr, 16, 16);
564 cairo_move_to(cr, 4, 16);
565 cairo_line_to(cr, 16, 4);
566 cairo_stroke(cr);
567
568 cairo_destroy(cr);
569
570 return surface;
571}
572
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400573static void
Kristian Høgsberg53880802012-01-09 11:16:50 -0500574panel_add_launcher(struct panel *panel, const char *icon, const char *path)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400575{
Kristian Høgsberg53880802012-01-09 11:16:50 -0500576 struct panel_launcher *launcher;
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400577 char *start, *p, *eq, **ps;
578 int i, j, k;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400579
Peter Huttererf3d62272013-08-08 11:57:05 +1000580 launcher = xzalloc(sizeof *launcher);
Philipp Brüschweiler467668c2012-08-29 10:53:36 +0200581 launcher->icon = load_icon_or_fallback(icon);
U. Artie Eoff3c946772014-01-15 10:59:50 -0800582 launcher->path = xstrdup(path);
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400583
584 wl_array_init(&launcher->envp);
585 wl_array_init(&launcher->argv);
Pekka Paalanenb6df4f72012-08-03 14:39:15 +0300586 for (i = 0; environ[i]; i++) {
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400587 ps = wl_array_add(&launcher->envp, sizeof *ps);
Pekka Paalanenb6df4f72012-08-03 14:39:15 +0300588 *ps = environ[i];
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400589 }
590 j = 0;
591
592 start = launcher->path;
593 while (*start) {
594 for (p = start, eq = NULL; *p && !isspace(*p); p++)
595 if (*p == '=')
596 eq = p;
597
598 if (eq && j == 0) {
599 ps = launcher->envp.data;
600 for (k = 0; k < i; k++)
601 if (strncmp(ps[k], start, eq - start) == 0) {
602 ps[k] = start;
603 break;
604 }
605 if (k == i) {
606 ps = wl_array_add(&launcher->envp, sizeof *ps);
607 *ps = start;
608 i++;
609 }
610 } else {
611 ps = wl_array_add(&launcher->argv, sizeof *ps);
612 *ps = start;
613 j++;
614 }
615
616 while (*p && isspace(*p))
617 *p++ = '\0';
618
619 start = p;
620 }
621
622 ps = wl_array_add(&launcher->envp, sizeof *ps);
623 *ps = NULL;
624 ps = wl_array_add(&launcher->argv, sizeof *ps);
625 *ps = NULL;
626
Kristian Høgsberg53880802012-01-09 11:16:50 -0500627 launcher->panel = panel;
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500628 wl_list_insert(panel->launcher_list.prev, &launcher->link);
629
Kristian Høgsberg441338c2012-01-10 13:52:34 -0500630 launcher->widget = widget_add_widget(panel->widget, launcher);
Kristian Høgsberg53880802012-01-09 11:16:50 -0500631 widget_set_enter_handler(launcher->widget,
632 panel_launcher_enter_handler);
633 widget_set_leave_handler(launcher->widget,
634 panel_launcher_leave_handler);
635 widget_set_button_handler(launcher->widget,
636 panel_launcher_button_handler);
Rusty Lynch4384a242013-08-08 21:28:22 -0700637 widget_set_touch_down_handler(launcher->widget,
638 panel_launcher_touch_down_handler);
639 widget_set_touch_up_handler(launcher->widget,
640 panel_launcher_touch_up_handler);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500641 widget_set_redraw_handler(launcher->widget,
642 panel_launcher_redraw_handler);
Tiago Vignatti61500722012-05-23 22:06:28 +0300643 widget_set_motion_handler(launcher->widget,
644 panel_launcher_motion_handler);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400645}
646
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500647enum {
648 BACKGROUND_SCALE,
Pekka Paalanena402b052013-05-22 18:03:10 +0300649 BACKGROUND_SCALE_CROP,
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500650 BACKGROUND_TILE
651};
652
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400653static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500654background_draw(struct widget *widget, void *data)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400655{
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500656 struct background *background = data;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400657 cairo_surface_t *surface, *image;
Kristian Høgsberg7e690002011-09-08 18:18:02 -0400658 cairo_pattern_t *pattern;
659 cairo_matrix_t matrix;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400660 cairo_t *cr;
Pekka Paalanena402b052013-05-22 18:03:10 +0300661 double im_w, im_h;
662 double sx, sy, s;
663 double tx, ty;
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500664 struct rectangle allocation;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400665
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500666 surface = window_get_surface(background->window);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400667
Alexander Larssonc584fa62013-05-22 14:41:32 +0200668 cr = widget_cairo_create(background->widget);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400669 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
670 cairo_set_source_rgba(cr, 0.0, 0.0, 0.2, 1.0);
671 cairo_paint(cr);
672
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500673 widget_get_allocation(widget, &allocation);
Kristian Høgsberg8129bc02012-01-25 14:55:33 -0500674 image = NULL;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300675 if (background->image)
676 image = load_cairo_surface(background->image);
Kristian Høgsberg4c3661f2014-04-21 22:54:37 -0700677 else if (background->color == 0)
678 image = load_cairo_surface(DATADIR "/weston/pattern.png");
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500679
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300680 if (image && background->type != -1) {
Pekka Paalanena402b052013-05-22 18:03:10 +0300681 im_w = cairo_image_surface_get_width(image);
682 im_h = cairo_image_surface_get_height(image);
683 sx = im_w / allocation.width;
684 sy = im_h / allocation.height;
685
Kristian Høgsberg7e690002011-09-08 18:18:02 -0400686 pattern = cairo_pattern_create_for_surface(image);
Pekka Paalanena402b052013-05-22 18:03:10 +0300687
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300688 switch (background->type) {
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500689 case BACKGROUND_SCALE:
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500690 cairo_matrix_init_scale(&matrix, sx, sy);
691 cairo_pattern_set_matrix(pattern, &matrix);
Bill Spitzak79b7cb32014-05-08 20:00:35 -0700692 cairo_pattern_set_extend(pattern, CAIRO_EXTEND_PAD);
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500693 break;
Pekka Paalanena402b052013-05-22 18:03:10 +0300694 case BACKGROUND_SCALE_CROP:
695 s = (sx < sy) ? sx : sy;
696 /* align center */
697 tx = (im_w - s * allocation.width) * 0.5;
698 ty = (im_h - s * allocation.height) * 0.5;
699 cairo_matrix_init_translate(&matrix, tx, ty);
700 cairo_matrix_scale(&matrix, s, s);
701 cairo_pattern_set_matrix(pattern, &matrix);
Bill Spitzak79b7cb32014-05-08 20:00:35 -0700702 cairo_pattern_set_extend(pattern, CAIRO_EXTEND_PAD);
Pekka Paalanena402b052013-05-22 18:03:10 +0300703 break;
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500704 case BACKGROUND_TILE:
705 cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
706 break;
707 }
Pekka Paalanena402b052013-05-22 18:03:10 +0300708
Kristian Høgsberg7e690002011-09-08 18:18:02 -0400709 cairo_set_source(cr, pattern);
710 cairo_pattern_destroy (pattern);
Kristian Høgsberg27d38662011-10-20 13:11:12 -0400711 cairo_surface_destroy(image);
Kristian Høgsberg8129bc02012-01-25 14:55:33 -0500712 } else {
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300713 set_hex_color(cr, background->color);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400714 }
715
Kristian Høgsberg8129bc02012-01-25 14:55:33 -0500716 cairo_paint(cr);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400717 cairo_destroy(cr);
718 cairo_surface_destroy(surface);
Pekka Paalanen9564c752012-10-24 09:43:08 +0300719
Pekka Paalanen79346ab2013-05-22 18:03:09 +0300720 background->painted = 1;
721 check_desktop_ready(background->window);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400722}
723
724static void
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100725background_configure(void *data,
726 struct desktop_shell *desktop_shell,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400727 uint32_t edges, struct window *window,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100728 int32_t width, int32_t height)
729{
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500730 struct background *background =
731 (struct background *) window_get_user_data(window);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100732
Kristian Høgsberg4598f962014-01-01 16:32:09 -0800733 widget_schedule_resize(background->widget, width, height);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100734}
735
736static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500737unlock_dialog_redraw_handler(struct widget *widget, void *data)
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200738{
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500739 struct unlock_dialog *dialog = data;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200740 struct rectangle allocation;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200741 cairo_surface_t *surface;
Alexander Larssonc584fa62013-05-22 14:41:32 +0200742 cairo_t *cr;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200743 cairo_pattern_t *pat;
744 double cx, cy, r, f;
745
Alexander Larssonc584fa62013-05-22 14:41:32 +0200746 cr = widget_cairo_create(widget);
Kristian Høgsberg41c5c4e2012-03-05 20:37:51 -0500747
Kristian Høgsbergbb977002012-01-10 19:11:42 -0500748 widget_get_allocation(dialog->widget, &allocation);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200749 cairo_rectangle(cr, allocation.x, allocation.y,
750 allocation.width, allocation.height);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200751 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
752 cairo_set_source_rgba(cr, 0, 0, 0, 0.6);
Kristian Høgsberg41c5c4e2012-03-05 20:37:51 -0500753 cairo_fill(cr);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200754
Kristian Høgsberg41c5c4e2012-03-05 20:37:51 -0500755 cairo_translate(cr, allocation.x, allocation.y);
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500756 if (dialog->button_focused)
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200757 f = 1.0;
758 else
759 f = 0.7;
760
761 cx = allocation.width / 2.0;
762 cy = allocation.height / 2.0;
763 r = (cx < cy ? cx : cy) * 0.4;
764 pat = cairo_pattern_create_radial(cx, cy, r * 0.7, cx, cy, r);
765 cairo_pattern_add_color_stop_rgb(pat, 0.0, 0, 0.86 * f, 0);
766 cairo_pattern_add_color_stop_rgb(pat, 0.85, 0.2 * f, f, 0.2 * f);
767 cairo_pattern_add_color_stop_rgb(pat, 1.0, 0, 0.86 * f, 0);
768 cairo_set_source(cr, pat);
Kristian Høgsberg41c5c4e2012-03-05 20:37:51 -0500769 cairo_pattern_destroy(pat);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200770 cairo_arc(cr, cx, cy, r, 0.0, 2.0 * M_PI);
771 cairo_fill(cr);
772
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500773 widget_set_allocation(dialog->button,
Kristian Høgsberg41c5c4e2012-03-05 20:37:51 -0500774 allocation.x + cx - r,
775 allocation.y + cy - r, 2 * r, 2 * r);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200776
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200777 cairo_destroy(cr);
778
Alexander Larssonc584fa62013-05-22 14:41:32 +0200779 surface = window_get_surface(dialog->window);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200780 cairo_surface_destroy(surface);
781}
782
783static void
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500784unlock_dialog_button_handler(struct widget *widget,
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200785 struct input *input, uint32_t time,
Daniel Stone4dbadb12012-05-30 16:31:51 +0100786 uint32_t button,
787 enum wl_pointer_button_state state, void *data)
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200788{
789 struct unlock_dialog *dialog = data;
790 struct desktop *desktop = dialog->desktop;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200791
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500792 if (button == BTN_LEFT) {
Daniel Stone4dbadb12012-05-30 16:31:51 +0100793 if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
794 !dialog->closing) {
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200795 display_defer(desktop->display, &desktop->unlock_task);
796 dialog->closing = 1;
797 }
798 }
799}
800
801static void
Brian J Lovinc4df4082013-08-26 15:58:22 -0700802unlock_dialog_touch_down_handler(struct widget *widget, struct input *input,
803 uint32_t serial, uint32_t time, int32_t id,
804 float x, float y, void *data)
805{
806 struct unlock_dialog *dialog = data;
807
808 dialog->button_focused = 1;
809 widget_schedule_redraw(widget);
810}
811
812static void
813unlock_dialog_touch_up_handler(struct widget *widget, struct input *input,
814 uint32_t serial, uint32_t time, int32_t id,
815 void *data)
816{
817 struct unlock_dialog *dialog = data;
818 struct desktop *desktop = dialog->desktop;
819
820 dialog->button_focused = 0;
821 widget_schedule_redraw(widget);
822 display_defer(desktop->display, &desktop->unlock_task);
823 dialog->closing = 1;
824}
825
826static void
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200827unlock_dialog_keyboard_focus_handler(struct window *window,
828 struct input *device, void *data)
829{
830 window_schedule_redraw(window);
831}
832
Kristian Høgsbergbb901fa2012-01-09 11:22:32 -0500833static int
Kristian Høgsbergee143232012-01-09 08:42:24 -0500834unlock_dialog_widget_enter_handler(struct widget *widget,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400835 struct input *input,
Kristian Høgsberg80680c72012-05-10 12:21:37 -0400836 float x, float y, void *data)
Kristian Høgsbergee143232012-01-09 08:42:24 -0500837{
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500838 struct unlock_dialog *dialog = data;
839
840 dialog->button_focused = 1;
Kristian Høgsbergee143232012-01-09 08:42:24 -0500841 widget_schedule_redraw(widget);
Kristian Høgsbergbb901fa2012-01-09 11:22:32 -0500842
Ander Conselvan de Oliveiradc8c8fc2012-05-25 16:01:41 +0300843 return CURSOR_LEFT_PTR;
Kristian Høgsbergee143232012-01-09 08:42:24 -0500844}
845
846static void
847unlock_dialog_widget_leave_handler(struct widget *widget,
848 struct input *input, void *data)
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200849{
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500850 struct unlock_dialog *dialog = data;
851
852 dialog->button_focused = 0;
Kristian Høgsberg9a13dab2012-01-08 15:18:19 -0500853 widget_schedule_redraw(widget);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200854}
855
856static struct unlock_dialog *
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500857unlock_dialog_create(struct desktop *desktop)
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200858{
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500859 struct display *display = desktop->display;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200860 struct unlock_dialog *dialog;
861
Peter Huttererf3d62272013-08-08 11:57:05 +1000862 dialog = xzalloc(sizeof *dialog);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200863
Kristian Høgsberg730c94d2012-06-26 21:44:35 -0400864 dialog->window = window_create_custom(display);
Jason Ekstrandee7fefc2013-10-13 19:08:38 -0500865 dialog->widget = window_frame_create(dialog->window, dialog);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200866 window_set_title(dialog->window, "Unlock your desktop");
867
868 window_set_user_data(dialog->window, dialog);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200869 window_set_keyboard_focus_handler(dialog->window,
870 unlock_dialog_keyboard_focus_handler);
Kristian Høgsberg441338c2012-01-10 13:52:34 -0500871 dialog->button = widget_add_widget(dialog->widget, dialog);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500872 widget_set_redraw_handler(dialog->widget,
873 unlock_dialog_redraw_handler);
Kristian Høgsbergee143232012-01-09 08:42:24 -0500874 widget_set_enter_handler(dialog->button,
875 unlock_dialog_widget_enter_handler);
876 widget_set_leave_handler(dialog->button,
877 unlock_dialog_widget_leave_handler);
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500878 widget_set_button_handler(dialog->button,
879 unlock_dialog_button_handler);
Brian J Lovinc4df4082013-08-26 15:58:22 -0700880 widget_set_touch_down_handler(dialog->button,
881 unlock_dialog_touch_down_handler);
882 widget_set_touch_up_handler(dialog->button,
883 unlock_dialog_touch_up_handler);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200884
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500885 desktop_shell_set_lock_surface(desktop->shell,
Kristian Høgsberg730c94d2012-06-26 21:44:35 -0400886 window_get_wl_surface(dialog->window));
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500887
Pekka Paalanen40e49ac2012-01-18 16:51:30 +0200888 window_schedule_resize(dialog->window, 260, 230);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200889
890 return dialog;
891}
892
893static void
894unlock_dialog_destroy(struct unlock_dialog *dialog)
895{
896 window_destroy(dialog->window);
897 free(dialog);
898}
899
900static void
901unlock_dialog_finish(struct task *task, uint32_t events)
902{
903 struct desktop *desktop =
Benjamin Franzked7759712011-11-22 12:38:48 +0100904 container_of(task, struct desktop, unlock_task);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200905
906 desktop_shell_unlock(desktop->shell);
907 unlock_dialog_destroy(desktop->unlock_dialog);
908 desktop->unlock_dialog = NULL;
909}
910
911static void
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400912desktop_shell_configure(void *data,
913 struct desktop_shell *desktop_shell,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400914 uint32_t edges,
Kristian Høgsberg962342c2012-06-26 16:29:50 -0400915 struct wl_surface *surface,
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400916 int32_t width, int32_t height)
917{
Kristian Høgsberg962342c2012-06-26 16:29:50 -0400918 struct window *window = wl_surface_get_user_data(surface);
Pekka Paalanen068ae942011-11-28 14:11:15 +0200919 struct surface *s = window_get_user_data(window);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400920
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400921 s->configure(data, desktop_shell, edges, window, width, height);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400922}
923
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200924static void
925desktop_shell_prepare_lock_surface(void *data,
926 struct desktop_shell *desktop_shell)
927{
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200928 struct desktop *desktop = data;
929
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300930 if (!desktop->locking) {
Pekka Paalanenfd83b6d2011-12-08 10:06:53 +0200931 desktop_shell_unlock(desktop->shell);
932 return;
933 }
934
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200935 if (!desktop->unlock_dialog) {
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500936 desktop->unlock_dialog = unlock_dialog_create(desktop);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200937 desktop->unlock_dialog->desktop = desktop;
938 }
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200939}
940
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300941static void
942desktop_shell_grab_cursor(void *data,
943 struct desktop_shell *desktop_shell,
944 uint32_t cursor)
945{
946 struct desktop *desktop = data;
947
948 switch (cursor) {
Philipp Brüschweiler16d59d72012-08-24 15:43:55 +0200949 case DESKTOP_SHELL_CURSOR_NONE:
950 desktop->grab_cursor = CURSOR_BLANK;
951 break;
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300952 case DESKTOP_SHELL_CURSOR_BUSY:
953 desktop->grab_cursor = CURSOR_WATCH;
954 break;
955 case DESKTOP_SHELL_CURSOR_MOVE:
956 desktop->grab_cursor = CURSOR_DRAGGING;
957 break;
958 case DESKTOP_SHELL_CURSOR_RESIZE_TOP:
959 desktop->grab_cursor = CURSOR_TOP;
960 break;
961 case DESKTOP_SHELL_CURSOR_RESIZE_BOTTOM:
962 desktop->grab_cursor = CURSOR_BOTTOM;
963 break;
964 case DESKTOP_SHELL_CURSOR_RESIZE_LEFT:
965 desktop->grab_cursor = CURSOR_LEFT;
966 break;
967 case DESKTOP_SHELL_CURSOR_RESIZE_RIGHT:
968 desktop->grab_cursor = CURSOR_RIGHT;
969 break;
970 case DESKTOP_SHELL_CURSOR_RESIZE_TOP_LEFT:
971 desktop->grab_cursor = CURSOR_TOP_LEFT;
972 break;
973 case DESKTOP_SHELL_CURSOR_RESIZE_TOP_RIGHT:
974 desktop->grab_cursor = CURSOR_TOP_RIGHT;
975 break;
976 case DESKTOP_SHELL_CURSOR_RESIZE_BOTTOM_LEFT:
977 desktop->grab_cursor = CURSOR_BOTTOM_LEFT;
978 break;
979 case DESKTOP_SHELL_CURSOR_RESIZE_BOTTOM_RIGHT:
980 desktop->grab_cursor = CURSOR_BOTTOM_RIGHT;
981 break;
982 case DESKTOP_SHELL_CURSOR_ARROW:
983 default:
984 desktop->grab_cursor = CURSOR_LEFT_PTR;
985 }
986}
987
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400988static const struct desktop_shell_listener listener = {
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200989 desktop_shell_configure,
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300990 desktop_shell_prepare_lock_surface,
991 desktop_shell_grab_cursor
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400992};
993
U. Artie Eoff44874d92012-10-02 21:12:35 -0700994static void
995background_destroy(struct background *background)
996{
997 widget_destroy(background->widget);
998 window_destroy(background->window);
999
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001000 free(background->image);
U. Artie Eoff44874d92012-10-02 21:12:35 -07001001 free(background);
1002}
1003
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001004static struct background *
1005background_create(struct desktop *desktop)
1006{
1007 struct background *background;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001008 struct weston_config_section *s;
1009 char *type;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001010
Peter Huttererf3d62272013-08-08 11:57:05 +10001011 background = xzalloc(sizeof *background);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001012 background->base.configure = background_configure;
Kristian Høgsberg962342c2012-06-26 16:29:50 -04001013 background->window = window_create_custom(desktop->display);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -05001014 background->widget = window_add_widget(background->window, background);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001015 window_set_user_data(background->window, background);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -05001016 widget_set_redraw_handler(background->widget, background_draw);
Arnaud Vracfb754a02014-08-25 20:56:49 +02001017 widget_set_transparent(background->widget, 0);
Tomeu Vizosobee45a12013-08-06 20:05:54 +02001018 window_set_preferred_format(background->window,
1019 WINDOW_PREFERRED_FORMAT_RGB565);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001020
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001021 s = weston_config_get_section(desktop->config, "shell", NULL, NULL);
1022 weston_config_section_get_string(s, "background-image",
Kristian Høgsberg4c3661f2014-04-21 22:54:37 -07001023 &background->image, NULL);
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001024 weston_config_section_get_uint(s, "background-color",
Kristian Høgsberg4c3661f2014-04-21 22:54:37 -07001025 &background->color, 0);
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001026
1027 weston_config_section_get_string(s, "background-type",
1028 &type, "tile");
U. Artie Eoff3c946772014-01-15 10:59:50 -08001029 if (type == NULL) {
1030 fprintf(stderr, "%s: out of memory\n", program_invocation_short_name);
1031 exit(EXIT_FAILURE);
1032 }
1033
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001034 if (strcmp(type, "scale") == 0) {
1035 background->type = BACKGROUND_SCALE;
1036 } else if (strcmp(type, "scale-crop") == 0) {
1037 background->type = BACKGROUND_SCALE_CROP;
1038 } else if (strcmp(type, "tile") == 0) {
1039 background->type = BACKGROUND_TILE;
1040 } else {
1041 background->type = -1;
1042 fprintf(stderr, "invalid background-type: %s\n",
1043 type);
1044 }
1045
1046 free(type);
1047
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001048 return background;
1049}
1050
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001051static int
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001052grab_surface_enter_handler(struct widget *widget, struct input *input,
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001053 float x, float y, void *data)
1054{
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001055 struct desktop *desktop = data;
1056
1057 return desktop->grab_cursor;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001058}
1059
1060static void
U. Artie Eoff44874d92012-10-02 21:12:35 -07001061grab_surface_destroy(struct desktop *desktop)
1062{
1063 widget_destroy(desktop->grab_widget);
1064 window_destroy(desktop->grab_window);
1065}
1066
1067static void
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001068grab_surface_create(struct desktop *desktop)
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001069{
1070 struct wl_surface *s;
1071
Ander Conselvan de Oliveira07a91cd2012-07-16 14:15:50 +03001072 desktop->grab_window = window_create_custom(desktop->display);
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001073 window_set_user_data(desktop->grab_window, desktop);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001074
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001075 s = window_get_wl_surface(desktop->grab_window);
1076 desktop_shell_set_grab_surface(desktop->shell, s);
1077
1078 desktop->grab_widget =
1079 window_add_widget(desktop->grab_window, desktop);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001080 /* We set the allocation to 1x1 at 0,0 so the fake enter event
1081 * at 0,0 will go to this widget. */
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001082 widget_set_allocation(desktop->grab_widget, 0, 0, 1, 1);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001083
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001084 widget_set_enter_handler(desktop->grab_widget,
1085 grab_surface_enter_handler);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001086}
1087
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001088static void
U. Artie Eoff44874d92012-10-02 21:12:35 -07001089output_destroy(struct output *output)
1090{
1091 background_destroy(output->background);
Jonny Lambe67118c2014-08-12 15:07:51 +02001092 if (output->panel)
1093 panel_destroy(output->panel);
U. Artie Eoff44874d92012-10-02 21:12:35 -07001094 wl_output_destroy(output->output);
1095 wl_list_remove(&output->link);
1096
1097 free(output);
1098}
1099
1100static void
1101desktop_destroy_outputs(struct desktop *desktop)
1102{
1103 struct output *tmp;
1104 struct output *output;
1105
1106 wl_list_for_each_safe(output, tmp, &desktop->outputs, link)
1107 output_destroy(output);
1108}
1109
1110static void
Alexander Larssonc584fa62013-05-22 14:41:32 +02001111output_handle_geometry(void *data,
1112 struct wl_output *wl_output,
1113 int x, int y,
1114 int physical_width,
1115 int physical_height,
1116 int subpixel,
1117 const char *make,
1118 const char *model,
1119 int transform)
1120{
1121 struct output *output = data;
1122
Jonny Lambe67118c2014-08-12 15:07:51 +02001123 if (output->panel)
1124 window_set_buffer_transform(output->panel->window, transform);
Alexander Larssonc584fa62013-05-22 14:41:32 +02001125 window_set_buffer_transform(output->background->window, transform);
1126}
1127
1128static void
1129output_handle_mode(void *data,
1130 struct wl_output *wl_output,
1131 uint32_t flags,
1132 int width,
1133 int height,
1134 int refresh)
1135{
1136}
1137
1138static void
1139output_handle_done(void *data,
1140 struct wl_output *wl_output)
1141{
1142}
1143
1144static void
1145output_handle_scale(void *data,
1146 struct wl_output *wl_output,
Alexander Larssonedddbd12013-05-24 13:09:43 +02001147 int32_t scale)
Alexander Larssonc584fa62013-05-22 14:41:32 +02001148{
1149 struct output *output = data;
1150
Jonny Lambe67118c2014-08-12 15:07:51 +02001151 if (output->panel)
1152 window_set_buffer_scale(output->panel->window, scale);
Alexander Larssonc584fa62013-05-22 14:41:32 +02001153 window_set_buffer_scale(output->background->window, scale);
1154}
1155
1156static const struct wl_output_listener output_listener = {
1157 output_handle_geometry,
1158 output_handle_mode,
1159 output_handle_done,
1160 output_handle_scale
1161};
1162
Jonny Lambe67118c2014-08-12 15:07:51 +02001163static int
1164want_panel(struct desktop *desktop)
1165{
1166 struct weston_config_section *s;
1167 char *location = NULL;
1168 int ret = 1;
1169
1170 s = weston_config_get_section(desktop->config, "shell", NULL, NULL);
1171 weston_config_section_get_string(s, "panel-location",
1172 &location, "top");
1173
1174 if (strcmp(location, "top") != 0)
1175 ret = 0;
1176
1177 free(location);
1178
1179 return ret;
1180}
1181
Alexander Larssonc584fa62013-05-22 14:41:32 +02001182static void
Ander Conselvan de Oliveirae4925492013-07-05 16:05:28 +03001183output_init(struct output *output, struct desktop *desktop)
1184{
1185 struct wl_surface *surface;
1186
Jonny Lambe67118c2014-08-12 15:07:51 +02001187 if (want_panel(desktop)) {
1188 output->panel = panel_create(desktop);
1189 surface = window_get_wl_surface(output->panel->window);
1190 desktop_shell_set_panel(desktop->shell,
1191 output->output, surface);
1192 }
Ander Conselvan de Oliveirae4925492013-07-05 16:05:28 +03001193
1194 output->background = background_create(desktop);
1195 surface = window_get_wl_surface(output->background->window);
1196 desktop_shell_set_background(desktop->shell,
1197 output->output, surface);
1198}
1199
1200static void
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001201create_output(struct desktop *desktop, uint32_t id)
1202{
1203 struct output *output;
1204
1205 output = calloc(1, sizeof *output);
1206 if (!output)
1207 return;
1208
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001209 output->output =
Alexander Larssonc584fa62013-05-22 14:41:32 +02001210 display_bind(desktop->display, id, &wl_output_interface, 2);
Xiong Zhang83d8ee72013-10-23 13:58:35 +08001211 output->server_output_id = id;
Alexander Larssonc584fa62013-05-22 14:41:32 +02001212
1213 wl_output_add_listener(output->output, &output_listener, output);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001214
1215 wl_list_insert(&desktop->outputs, &output->link);
Ander Conselvan de Oliveirae4925492013-07-05 16:05:28 +03001216
1217 /* On start up we may process an output global before the shell global
1218 * in which case we can't create the panel and background just yet */
1219 if (desktop->shell)
1220 output_init(output, desktop);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001221}
1222
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001223static void
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001224global_handler(struct display *display, uint32_t id,
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001225 const char *interface, uint32_t version, void *data)
1226{
1227 struct desktop *desktop = data;
1228
1229 if (!strcmp(interface, "desktop_shell")) {
Pekka Paalanen79346ab2013-05-22 18:03:09 +03001230 desktop->interface_version = (version < 2) ? version : 2;
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001231 desktop->shell = display_bind(desktop->display,
Pekka Paalanen79346ab2013-05-22 18:03:09 +03001232 id, &desktop_shell_interface,
1233 desktop->interface_version);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001234 desktop_shell_add_listener(desktop->shell, &listener, desktop);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001235 } else if (!strcmp(interface, "wl_output")) {
1236 create_output(desktop, id);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001237 }
1238}
1239
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -05001240static void
Xiong Zhang83d8ee72013-10-23 13:58:35 +08001241global_handler_remove(struct display *display, uint32_t id,
1242 const char *interface, uint32_t version, void *data)
1243{
1244 struct desktop *desktop = data;
1245 struct output *output;
1246
1247 if (!strcmp(interface, "wl_output")) {
1248 wl_list_for_each(output, &desktop->outputs, link) {
1249 if (output->server_output_id == id) {
1250 output_destroy(output);
1251 break;
1252 }
1253 }
1254 }
1255}
1256
1257static void
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001258panel_add_launchers(struct panel *panel, struct desktop *desktop)
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -05001259{
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001260 struct weston_config_section *s;
1261 char *icon, *path;
1262 const char *name;
1263 int count;
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -05001264
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001265 count = 0;
1266 s = NULL;
1267 while (weston_config_next_section(desktop->config, &s, &name)) {
1268 if (strcmp(name, "launcher") != 0)
1269 continue;
1270
1271 weston_config_section_get_string(s, "icon", &icon, NULL);
1272 weston_config_section_get_string(s, "path", &path, NULL);
1273
1274 if (icon != NULL && path != NULL) {
1275 panel_add_launcher(panel, icon, path);
Rob Bradford09252d42013-07-26 16:29:45 +01001276 count++;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001277 } else {
1278 fprintf(stderr, "invalid launcher section\n");
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001279 }
1280
1281 free(icon);
1282 free(path);
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -05001283 }
1284
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001285 if (count == 0) {
1286 /* add default launcher */
1287 panel_add_launcher(panel,
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -05001288 DATADIR "/weston/terminal.png",
Rodney Lorrimar99ff01b2012-02-29 17:31:03 +01001289 BINDIR "/weston-terminal");
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001290 }
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -05001291}
1292
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001293int main(int argc, char *argv[])
1294{
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001295 struct desktop desktop = { 0 };
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001296 struct output *output;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001297 struct weston_config_section *s;
Pekka Paalanen6c71aae2015-03-24 15:56:19 +02001298 const char *config_file;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001299
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001300 desktop.unlock_task.run = unlock_dialog_finish;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001301 wl_list_init(&desktop.outputs);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001302
Pekka Paalanen6c71aae2015-03-24 15:56:19 +02001303 config_file = weston_config_get_name_from_env();
1304 desktop.config = weston_config_parse(config_file);
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001305 s = weston_config_get_section(desktop.config, "shell", NULL, NULL);
1306 weston_config_section_get_bool(s, "locking", &desktop.locking, 1);
1307
Kristian Høgsberg4172f662013-02-20 15:27:49 -05001308 desktop.display = display_create(&argc, argv);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001309 if (desktop.display == NULL) {
1310 fprintf(stderr, "failed to create display: %m\n");
1311 return -1;
1312 }
1313
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001314 display_set_user_data(desktop.display, &desktop);
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001315 display_set_global_handler(desktop.display, global_handler);
Xiong Zhang83d8ee72013-10-23 13:58:35 +08001316 display_set_global_handler_remove(desktop.display, global_handler_remove);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001317
Ander Conselvan de Oliveirae4925492013-07-05 16:05:28 +03001318 /* Create panel and background for outputs processed before the shell
1319 * global interface was processed */
1320 wl_list_for_each(output, &desktop.outputs, link)
1321 if (!output->panel)
1322 output_init(output, &desktop);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001323
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001324 grab_surface_create(&desktop);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001325
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001326 signal(SIGCHLD, sigchild_handler);
1327
1328 display_run(desktop.display);
1329
U. Artie Eoff44874d92012-10-02 21:12:35 -07001330 /* Cleanup */
1331 grab_surface_destroy(&desktop);
1332 desktop_destroy_outputs(&desktop);
1333 if (desktop.unlock_dialog)
1334 unlock_dialog_destroy(desktop.unlock_dialog);
1335 desktop_shell_destroy(desktop.shell);
1336 display_destroy(desktop.display);
1337
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001338 return 0;
1339}