blob: 319382db0d04a9cbd7637ac74c54393aabce9187 [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
24#include <stdint.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <fcntl.h>
29#include <unistd.h>
30#include <math.h>
31#include <cairo.h>
32#include <sys/wait.h>
Martin Minarik1e51a872012-06-08 00:39:11 +020033#include <sys/timerfd.h>
34#include <sys/epoll.h>
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040035#include <linux/input.h>
Tiago Vignatti61500722012-05-23 22:06:28 +030036#include <libgen.h>
Kristian Høgsbergd1936b92012-07-23 22:59:33 -040037#include <ctype.h>
Martin Minarik1e51a872012-06-08 00:39:11 +020038#include <time.h>
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040039
Pekka Paalanen50719bc2011-11-22 14:18:50 +020040#include <wayland-client.h>
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040041#include "window.h"
Kristian Høgsberg5a315bc2012-05-15 22:33:43 -040042#include "../shared/cairo-util.h"
Kristian Høgsberg9b935c82011-12-08 12:44:27 -050043#include "../shared/config-parser.h"
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040044
Pekka Paalanen50719bc2011-11-22 14:18:50 +020045#include "desktop-shell-client-protocol.h"
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040046
Pekka Paalanenb6df4f72012-08-03 14:39:15 +030047extern char **environ; /* defined by libc */
48
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040049struct desktop {
50 struct display *display;
51 struct desktop_shell *shell;
Pekka Paalanen79346ab2013-05-22 18:03:09 +030052 uint32_t interface_version;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +020053 struct unlock_dialog *unlock_dialog;
54 struct task unlock_task;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010055 struct wl_list outputs;
Kristian Høgsbergd56bd902012-06-05 09:58:51 -040056
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +030057 struct window *grab_window;
58 struct widget *grab_widget;
59
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +030060 struct weston_config *config;
61 int locking;
62
Scott Moreauec116022012-07-22 18:23:52 -060063 enum cursor_type grab_cursor;
Pekka Paalanen79346ab2013-05-22 18:03:09 +030064
65 int painted;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010066};
67
68struct surface {
69 void (*configure)(void *data,
70 struct desktop_shell *desktop_shell,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -040071 uint32_t edges, struct window *window,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010072 int32_t width, int32_t height);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040073};
74
75struct panel {
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010076 struct surface base;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040077 struct window *window;
Kristian Høgsberg75bc6672012-01-10 09:43:58 -050078 struct widget *widget;
Kristian Høgsberg75bc6672012-01-10 09:43:58 -050079 struct wl_list launcher_list;
Martin Minarik1e51a872012-06-08 00:39:11 +020080 struct panel_clock *clock;
Pekka Paalanen79346ab2013-05-22 18:03:09 +030081 int painted;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +030082 uint32_t color;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -040083};
84
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010085struct background {
86 struct surface base;
87 struct window *window;
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -050088 struct widget *widget;
Pekka Paalanen79346ab2013-05-22 18:03:09 +030089 int painted;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +030090
91 char *image;
92 int type;
93 uint32_t color;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +010094};
95
96struct output {
97 struct wl_output *output;
98 struct wl_list link;
99
100 struct panel *panel;
101 struct background *background;
102};
103
Kristian Høgsberg53880802012-01-09 11:16:50 -0500104struct panel_launcher {
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500105 struct widget *widget;
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400106 struct panel *panel;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400107 cairo_surface_t *icon;
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500108 int focused, pressed;
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400109 char *path;
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500110 struct wl_list link;
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400111 struct wl_array envp;
112 struct wl_array argv;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400113};
114
Martin Minarik1e51a872012-06-08 00:39:11 +0200115struct panel_clock {
116 struct widget *widget;
117 struct panel *panel;
Martin Minarik1e51a872012-06-08 00:39:11 +0200118 struct task clock_task;
119 int clock_fd;
120};
121
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200122struct unlock_dialog {
123 struct window *window;
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500124 struct widget *widget;
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500125 struct widget *button;
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500126 int button_focused;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200127 int closing;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200128 struct desktop *desktop;
129};
130
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300131static void
132panel_add_launchers(struct panel *panel, struct desktop *desktop);
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -0500133
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400134static void
135sigchild_handler(int s)
136{
137 int status;
138 pid_t pid;
139
140 while (pid = waitpid(-1, &status, WNOHANG), pid > 0)
141 fprintf(stderr, "child %d exited\n", pid);
142}
143
144static void
Pekka Paalanen9e30a822012-01-19 16:40:28 +0200145menu_func(struct window *window, int index, void *data)
146{
147 printf("Selected index %d from a panel menu.\n", index);
148}
149
150static void
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500151show_menu(struct panel *panel, struct input *input, uint32_t time)
Kristian Høgsbergbcee9a42011-10-12 00:36:16 -0400152{
Kristian Høgsbergb3cca0a2012-01-04 22:19:14 -0500153 int32_t x, y;
154 static const char *entries[] = {
155 "Roy", "Pris", "Leon", "Zhora"
156 };
Kristian Høgsbergbcee9a42011-10-12 00:36:16 -0400157
158 input_get_position(input, &x, &y);
Pekka Paalanen6d174cf2012-01-19 15:17:59 +0200159 window_show_menu(window_get_display(panel->window),
160 input, time, panel->window,
Pekka Paalanen9e30a822012-01-19 16:40:28 +0200161 x - 10, y - 10, menu_func, entries, 4);
Kristian Høgsbergbcee9a42011-10-12 00:36:16 -0400162}
163
Pekka Paalanen79346ab2013-05-22 18:03:09 +0300164static int
165is_desktop_painted(struct desktop *desktop)
166{
167 struct output *output;
168
169 wl_list_for_each(output, &desktop->outputs, link) {
170 if (output->panel && !output->panel->painted)
171 return 0;
172 if (output->background && !output->background->painted)
173 return 0;
174 }
175
176 return 1;
177}
178
179static void
180check_desktop_ready(struct window *window)
181{
182 struct display *display;
183 struct desktop *desktop;
184
185 display = window_get_display(window);
186 desktop = display_get_user_data(display);
187
188 if (!desktop->painted && is_desktop_painted(desktop)) {
189 desktop->painted = 1;
190
191 if (desktop->interface_version >= 2)
192 desktop_shell_desktop_ready(desktop->shell);
193 }
194}
195
Kristian Høgsbergbcee9a42011-10-12 00:36:16 -0400196static void
Kristian Høgsberg53880802012-01-09 11:16:50 -0500197panel_launcher_activate(struct panel_launcher *widget)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400198{
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400199 char **argv;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400200 pid_t pid;
201
202 pid = fork();
203 if (pid < 0) {
204 fprintf(stderr, "fork failed: %m\n");
205 return;
206 }
207
208 if (pid)
209 return;
Benjamin Franzked7759712011-11-22 12:38:48 +0100210
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400211 argv = widget->argv.data;
212 if (execve(argv[0], argv, widget->envp.data) < 0) {
213 fprintf(stderr, "execl '%s' failed: %m\n", argv[0]);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400214 exit(1);
215 }
216}
217
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400218static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500219panel_launcher_redraw_handler(struct widget *widget, void *data)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400220{
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500221 struct panel_launcher *launcher = data;
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500222 struct rectangle allocation;
223 cairo_t *cr;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400224
Alexander Larssonc584fa62013-05-22 14:41:32 +0200225 cr = widget_cairo_create(launcher->panel->widget);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500226
227 widget_get_allocation(widget, &allocation);
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500228 if (launcher->pressed) {
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500229 allocation.x++;
230 allocation.y++;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400231 }
232
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500233 cairo_set_source_surface(cr, launcher->icon,
234 allocation.x, allocation.y);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400235 cairo_paint(cr);
236
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500237 if (launcher->focused) {
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400238 cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.4);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500239 cairo_mask_surface(cr, launcher->icon,
240 allocation.x, allocation.y);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400241 }
Kristian Høgsberge28d05b2011-09-20 21:43:54 -0400242
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500243 cairo_destroy(cr);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400244}
245
Tiago Vignatti61500722012-05-23 22:06:28 +0300246static int
247panel_launcher_motion_handler(struct widget *widget, struct input *input,
248 uint32_t time, float x, float y, void *data)
249{
250 struct panel_launcher *launcher = data;
251
252 widget_set_tooltip(widget, basename((char *)launcher->path), x, y);
253
Ander Conselvan de Oliveiradc8c8fc2012-05-25 16:01:41 +0300254 return CURSOR_LEFT_PTR;
Tiago Vignatti61500722012-05-23 22:06:28 +0300255}
256
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400257static void
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -0500258set_hex_color(cairo_t *cr, uint32_t color)
259{
260 cairo_set_source_rgba(cr,
261 ((color >> 16) & 0xff) / 255.0,
262 ((color >> 8) & 0xff) / 255.0,
263 ((color >> 0) & 0xff) / 255.0,
264 ((color >> 24) & 0xff) / 255.0);
265}
266
267static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500268panel_redraw_handler(struct widget *widget, void *data)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400269{
270 cairo_surface_t *surface;
271 cairo_t *cr;
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500272 struct panel *panel = data;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400273
Alexander Larssonc584fa62013-05-22 14:41:32 +0200274 cr = widget_cairo_create(panel->widget);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400275 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300276 set_hex_color(cr, panel->color);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400277 cairo_paint(cr);
278
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400279 cairo_destroy(cr);
Alexander Larssonc584fa62013-05-22 14:41:32 +0200280 surface = window_get_surface(panel->window);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400281 cairo_surface_destroy(surface);
Pekka Paalanen79346ab2013-05-22 18:03:09 +0300282 panel->painted = 1;
283 check_desktop_ready(panel->window);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400284}
285
Kristian Høgsbergbb901fa2012-01-09 11:22:32 -0500286static int
Kristian Høgsberg53880802012-01-09 11:16:50 -0500287panel_launcher_enter_handler(struct widget *widget, struct input *input,
Kristian Høgsberg80680c72012-05-10 12:21:37 -0400288 float x, float y, void *data)
Kristian Høgsbergee143232012-01-09 08:42:24 -0500289{
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500290 struct panel_launcher *launcher = data;
291
292 launcher->focused = 1;
Kristian Høgsbergee143232012-01-09 08:42:24 -0500293 widget_schedule_redraw(widget);
Kristian Høgsbergbb901fa2012-01-09 11:22:32 -0500294
Ander Conselvan de Oliveiradc8c8fc2012-05-25 16:01:41 +0300295 return CURSOR_LEFT_PTR;
Kristian Høgsbergee143232012-01-09 08:42:24 -0500296}
297
298static void
Kristian Høgsberg53880802012-01-09 11:16:50 -0500299panel_launcher_leave_handler(struct widget *widget,
300 struct input *input, void *data)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400301{
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500302 struct panel_launcher *launcher = data;
303
304 launcher->focused = 0;
Tiago Vignatti61500722012-05-23 22:06:28 +0300305 widget_destroy_tooltip(widget);
Kristian Høgsberg9a13dab2012-01-08 15:18:19 -0500306 widget_schedule_redraw(widget);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400307}
308
309static void
Kristian Høgsberg53880802012-01-09 11:16:50 -0500310panel_launcher_button_handler(struct widget *widget,
311 struct input *input, uint32_t time,
Daniel Stone4dbadb12012-05-30 16:31:51 +0100312 uint32_t button,
313 enum wl_pointer_button_state state, void *data)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400314{
Kristian Høgsberg53880802012-01-09 11:16:50 -0500315 struct panel_launcher *launcher;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400316
Kristian Høgsberg53880802012-01-09 11:16:50 -0500317 launcher = widget_get_user_data(widget);
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500318 widget_schedule_redraw(widget);
Daniel Stone4dbadb12012-05-30 16:31:51 +0100319 if (state == WL_POINTER_BUTTON_STATE_RELEASED)
Kristian Høgsberg53880802012-01-09 11:16:50 -0500320 panel_launcher_activate(launcher);
Rusty Lynch4384a242013-08-08 21:28:22 -0700321
322}
323
324static void
Rusty Lynch1084da52013-08-15 09:10:08 -0700325panel_launcher_touch_down_handler(struct widget *widget, struct input *input,
326 uint32_t serial, uint32_t time, int32_t id,
Rusty Lynch4384a242013-08-08 21:28:22 -0700327 float x, float y, void *data)
328{
329 struct panel_launcher *launcher;
330
331 launcher = widget_get_user_data(widget);
332 launcher->focused = 1;
333 widget_schedule_redraw(widget);
334}
335
336static void
Rusty Lynch1084da52013-08-15 09:10:08 -0700337panel_launcher_touch_up_handler(struct widget *widget, struct input *input,
338 uint32_t serial, uint32_t time, int32_t id,
339 void *data)
Rusty Lynch4384a242013-08-08 21:28:22 -0700340{
341 struct panel_launcher *launcher;
342
343 launcher = widget_get_user_data(widget);
344 launcher->focused = 0;
345 widget_schedule_redraw(widget);
346 panel_launcher_activate(launcher);
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500347}
348
Martin Minarik1e51a872012-06-08 00:39:11 +0200349static void
350clock_func(struct task *task, uint32_t events)
351{
352 struct panel_clock *clock =
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400353 container_of(task, struct panel_clock, clock_task);
Kristian Høgsberg70226bb2012-06-08 16:54:52 -0400354 uint64_t exp;
Martin Minarik1e51a872012-06-08 00:39:11 +0200355
Martin Olsson8df662a2012-07-08 03:03:47 +0200356 if (read(clock->clock_fd, &exp, sizeof exp) != sizeof exp)
357 abort();
Kristian Høgsberg92a984a2012-06-11 11:10:57 -0400358 widget_schedule_redraw(clock->widget);
Martin Minarik1e51a872012-06-08 00:39:11 +0200359}
360
361static void
362panel_clock_redraw_handler(struct widget *widget, void *data)
363{
Martin Minarik1e51a872012-06-08 00:39:11 +0200364 struct panel_clock *clock = data;
365 cairo_t *cr;
366 struct rectangle allocation;
367 cairo_text_extents_t extents;
368 cairo_font_extents_t font_extents;
Martin Minarik1e51a872012-06-08 00:39:11 +0200369 time_t rawtime;
370 struct tm * timeinfo;
Kristian Høgsberg92a984a2012-06-11 11:10:57 -0400371 char string[128];
Martin Minarik1e51a872012-06-08 00:39:11 +0200372
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400373 time(&rawtime);
374 timeinfo = localtime(&rawtime);
Kristian Høgsberge9f68f62012-06-11 12:24:12 -0400375 strftime(string, sizeof string, "%a %b %d, %I:%M %p", timeinfo);
Martin Minarik1e51a872012-06-08 00:39:11 +0200376
377 widget_get_allocation(widget, &allocation);
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400378 if (allocation.width == 0)
379 return;
Martin Minarik1e51a872012-06-08 00:39:11 +0200380
Alexander Larssonc584fa62013-05-22 14:41:32 +0200381 cr = widget_cairo_create(clock->panel->widget);
Martin Minarik1e51a872012-06-08 00:39:11 +0200382 cairo_select_font_face(cr, "sans",
383 CAIRO_FONT_SLANT_NORMAL,
384 CAIRO_FONT_WEIGHT_NORMAL);
385 cairo_set_font_size(cr, 14);
Kristian Høgsberg92a984a2012-06-11 11:10:57 -0400386 cairo_text_extents(cr, string, &extents);
Martin Minarik1e51a872012-06-08 00:39:11 +0200387 cairo_font_extents (cr, &font_extents);
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400388 cairo_move_to(cr, allocation.x + 5,
389 allocation.y + 3 * (allocation.height >> 2) + 1);
390 cairo_set_source_rgb(cr, 0, 0, 0);
Kristian Høgsberg92a984a2012-06-11 11:10:57 -0400391 cairo_show_text(cr, string);
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400392 cairo_move_to(cr, allocation.x + 4,
393 allocation.y + 3 * (allocation.height >> 2));
394 cairo_set_source_rgb(cr, 1, 1, 1);
Kristian Høgsberg92a984a2012-06-11 11:10:57 -0400395 cairo_show_text(cr, string);
Martin Minarik1e51a872012-06-08 00:39:11 +0200396 cairo_destroy(cr);
397}
398
399static int
400clock_timer_reset(struct panel_clock *clock)
401{
402 struct itimerspec its;
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400403
Kristian Høgsberge9f68f62012-06-11 12:24:12 -0400404 its.it_interval.tv_sec = 60;
Martin Minarik1e51a872012-06-08 00:39:11 +0200405 its.it_interval.tv_nsec = 0;
Kristian Høgsberge9f68f62012-06-11 12:24:12 -0400406 its.it_value.tv_sec = 60;
Martin Minarik1e51a872012-06-08 00:39:11 +0200407 its.it_value.tv_nsec = 0;
408 if (timerfd_settime(clock->clock_fd, 0, &its, NULL) < 0) {
409 fprintf(stderr, "could not set timerfd\n: %m");
410 return -1;
411 }
412
413 return 0;
414}
415
416static void
U. Artie Eoff44874d92012-10-02 21:12:35 -0700417panel_destroy_clock(struct panel_clock *clock)
418{
419 widget_destroy(clock->widget);
420
421 close(clock->clock_fd);
422
423 free(clock);
424}
425
426static void
Martin Minarik1e51a872012-06-08 00:39:11 +0200427panel_add_clock(struct panel *panel)
428{
429 struct panel_clock *clock;
430 int timerfd;
431
432 timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
433 if (timerfd < 0) {
434 fprintf(stderr, "could not create timerfd\n: %m");
435 return;
436 }
437
Peter Huttererf3d62272013-08-08 11:57:05 +1000438 clock = xzalloc(sizeof *clock);
Martin Minarik1e51a872012-06-08 00:39:11 +0200439 clock->panel = panel;
440 panel->clock = clock;
441 clock->clock_fd = timerfd;
442
443 clock->clock_task.run = clock_func;
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400444 display_watch_fd(window_get_display(panel->window), clock->clock_fd,
445 EPOLLIN, &clock->clock_task);
Martin Minarik1e51a872012-06-08 00:39:11 +0200446 clock_timer_reset(clock);
447
448 clock->widget = widget_add_widget(panel->widget, clock);
Kristian Høgsbergbb262cf2012-06-11 11:03:03 -0400449 widget_set_redraw_handler(clock->widget, panel_clock_redraw_handler);
Martin Minarik1e51a872012-06-08 00:39:11 +0200450}
451
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500452static void
453panel_button_handler(struct widget *widget,
454 struct input *input, uint32_t time,
Daniel Stone4dbadb12012-05-30 16:31:51 +0100455 uint32_t button,
456 enum wl_pointer_button_state state, void *data)
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500457{
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500458 struct panel *panel = data;
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500459
Daniel Stone4dbadb12012-05-30 16:31:51 +0100460 if (button == BTN_RIGHT && state == WL_POINTER_BUTTON_STATE_PRESSED)
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500461 show_menu(panel, input, time);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400462}
463
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100464static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500465panel_resize_handler(struct widget *widget,
466 int32_t width, int32_t height, void *data)
467{
468 struct panel_launcher *launcher;
469 struct panel *panel = data;
470 int x, y, w, h;
471
472 x = 10;
473 y = 16;
474 wl_list_for_each(launcher, &panel->launcher_list, link) {
475 w = cairo_image_surface_get_width(launcher->icon);
476 h = cairo_image_surface_get_height(launcher->icon);
477 widget_set_allocation(launcher->widget,
478 x, y - h / 2, w + 1, h + 1);
479 x += w + 10;
480 }
Martin Minarik1e51a872012-06-08 00:39:11 +0200481 h=20;
482 w=170;
Pekka Paalanen01b17252012-06-12 17:42:26 +0300483
484 if (panel->clock)
485 widget_set_allocation(panel->clock->widget,
486 width - w - 8, y - h / 2, w + 1, h + 1);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500487}
488
489static void
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100490panel_configure(void *data,
491 struct desktop_shell *desktop_shell,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400492 uint32_t edges, struct window *window,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100493 int32_t width, int32_t height)
494{
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500495 struct surface *surface = window_get_user_data(window);
496 struct panel *panel = container_of(surface, struct panel, base);
497
498 window_schedule_resize(panel->window, width, 32);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100499}
500
U. Artie Eoff44874d92012-10-02 21:12:35 -0700501static void
502panel_destroy_launcher(struct panel_launcher *launcher)
503{
504 wl_array_release(&launcher->argv);
505 wl_array_release(&launcher->envp);
506
507 free(launcher->path);
508
509 cairo_surface_destroy(launcher->icon);
510
511 widget_destroy(launcher->widget);
512 wl_list_remove(&launcher->link);
513
514 free(launcher);
515}
516
517static void
518panel_destroy(struct panel *panel)
519{
520 struct panel_launcher *tmp;
521 struct panel_launcher *launcher;
522
523 panel_destroy_clock(panel->clock);
524
525 wl_list_for_each_safe(launcher, tmp, &panel->launcher_list, link)
526 panel_destroy_launcher(launcher);
527
528 widget_destroy(panel->widget);
529 window_destroy(panel->window);
530
531 free(panel);
532}
533
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400534static struct panel *
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300535panel_create(struct desktop *desktop)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400536{
537 struct panel *panel;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300538 struct weston_config_section *s;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400539
Peter Huttererf3d62272013-08-08 11:57:05 +1000540 panel = xzalloc(sizeof *panel);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400541
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100542 panel->base.configure = panel_configure;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300543 panel->window = window_create_custom(desktop->display);
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500544 panel->widget = window_add_widget(panel->window, panel);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500545 wl_list_init(&panel->launcher_list);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400546
547 window_set_title(panel->window, "panel");
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400548 window_set_user_data(panel->window, panel);
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500549
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500550 widget_set_redraw_handler(panel->widget, panel_redraw_handler);
551 widget_set_resize_handler(panel->widget, panel_resize_handler);
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500552 widget_set_button_handler(panel->widget, panel_button_handler);
Rafal Mielniczukb9e513c2012-06-09 20:33:29 +0200553
554 panel_add_clock(panel);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400555
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300556 s = weston_config_get_section(desktop->config, "shell", NULL, NULL);
557 weston_config_section_get_uint(s, "panel-color",
558 &panel->color, 0xaa000000);
559
560 panel_add_launchers(panel, desktop);
561
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400562 return panel;
563}
564
Philipp Brüschweiler467668c2012-08-29 10:53:36 +0200565static cairo_surface_t *
566load_icon_or_fallback(const char *icon)
567{
568 cairo_surface_t *surface = cairo_image_surface_create_from_png(icon);
Philipp Brüschweiler96386b82013-04-15 20:10:40 +0200569 cairo_status_t status;
Philipp Brüschweiler467668c2012-08-29 10:53:36 +0200570 cairo_t *cr;
571
Philipp Brüschweiler96386b82013-04-15 20:10:40 +0200572 status = cairo_surface_status(surface);
573 if (status == CAIRO_STATUS_SUCCESS)
Philipp Brüschweiler467668c2012-08-29 10:53:36 +0200574 return surface;
575
576 cairo_surface_destroy(surface);
Philipp Brüschweiler96386b82013-04-15 20:10:40 +0200577 fprintf(stderr, "ERROR loading icon from file '%s', error: '%s'\n",
578 icon, cairo_status_to_string(status));
Philipp Brüschweiler467668c2012-08-29 10:53:36 +0200579
580 /* draw fallback icon */
581 surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
582 20, 20);
583 cr = cairo_create(surface);
584
585 cairo_set_source_rgba(cr, 0.8, 0.8, 0.8, 1);
586 cairo_paint(cr);
587
588 cairo_set_source_rgba(cr, 0, 0, 0, 1);
589 cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
590 cairo_rectangle(cr, 0, 0, 20, 20);
591 cairo_move_to(cr, 4, 4);
592 cairo_line_to(cr, 16, 16);
593 cairo_move_to(cr, 4, 16);
594 cairo_line_to(cr, 16, 4);
595 cairo_stroke(cr);
596
597 cairo_destroy(cr);
598
599 return surface;
600}
601
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400602static void
Kristian Høgsberg53880802012-01-09 11:16:50 -0500603panel_add_launcher(struct panel *panel, const char *icon, const char *path)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400604{
Kristian Høgsberg53880802012-01-09 11:16:50 -0500605 struct panel_launcher *launcher;
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400606 char *start, *p, *eq, **ps;
607 int i, j, k;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400608
Peter Huttererf3d62272013-08-08 11:57:05 +1000609 launcher = xzalloc(sizeof *launcher);
Philipp Brüschweiler467668c2012-08-29 10:53:36 +0200610 launcher->icon = load_icon_or_fallback(icon);
Kristian Høgsberg53880802012-01-09 11:16:50 -0500611 launcher->path = strdup(path);
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400612
613 wl_array_init(&launcher->envp);
614 wl_array_init(&launcher->argv);
Pekka Paalanenb6df4f72012-08-03 14:39:15 +0300615 for (i = 0; environ[i]; i++) {
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400616 ps = wl_array_add(&launcher->envp, sizeof *ps);
Pekka Paalanenb6df4f72012-08-03 14:39:15 +0300617 *ps = environ[i];
Kristian Høgsbergd1936b92012-07-23 22:59:33 -0400618 }
619 j = 0;
620
621 start = launcher->path;
622 while (*start) {
623 for (p = start, eq = NULL; *p && !isspace(*p); p++)
624 if (*p == '=')
625 eq = p;
626
627 if (eq && j == 0) {
628 ps = launcher->envp.data;
629 for (k = 0; k < i; k++)
630 if (strncmp(ps[k], start, eq - start) == 0) {
631 ps[k] = start;
632 break;
633 }
634 if (k == i) {
635 ps = wl_array_add(&launcher->envp, sizeof *ps);
636 *ps = start;
637 i++;
638 }
639 } else {
640 ps = wl_array_add(&launcher->argv, sizeof *ps);
641 *ps = start;
642 j++;
643 }
644
645 while (*p && isspace(*p))
646 *p++ = '\0';
647
648 start = p;
649 }
650
651 ps = wl_array_add(&launcher->envp, sizeof *ps);
652 *ps = NULL;
653 ps = wl_array_add(&launcher->argv, sizeof *ps);
654 *ps = NULL;
655
Kristian Høgsberg53880802012-01-09 11:16:50 -0500656 launcher->panel = panel;
Kristian Høgsberg75bc6672012-01-10 09:43:58 -0500657 wl_list_insert(panel->launcher_list.prev, &launcher->link);
658
Kristian Høgsberg441338c2012-01-10 13:52:34 -0500659 launcher->widget = widget_add_widget(panel->widget, launcher);
Kristian Høgsberg53880802012-01-09 11:16:50 -0500660 widget_set_enter_handler(launcher->widget,
661 panel_launcher_enter_handler);
662 widget_set_leave_handler(launcher->widget,
663 panel_launcher_leave_handler);
664 widget_set_button_handler(launcher->widget,
665 panel_launcher_button_handler);
Rusty Lynch4384a242013-08-08 21:28:22 -0700666 widget_set_touch_down_handler(launcher->widget,
667 panel_launcher_touch_down_handler);
668 widget_set_touch_up_handler(launcher->widget,
669 panel_launcher_touch_up_handler);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500670 widget_set_redraw_handler(launcher->widget,
671 panel_launcher_redraw_handler);
Tiago Vignatti61500722012-05-23 22:06:28 +0300672 widget_set_motion_handler(launcher->widget,
673 panel_launcher_motion_handler);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400674}
675
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500676enum {
677 BACKGROUND_SCALE,
Pekka Paalanena402b052013-05-22 18:03:10 +0300678 BACKGROUND_SCALE_CROP,
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500679 BACKGROUND_TILE
680};
681
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400682static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500683background_draw(struct widget *widget, void *data)
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400684{
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500685 struct background *background = data;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400686 cairo_surface_t *surface, *image;
Kristian Høgsberg7e690002011-09-08 18:18:02 -0400687 cairo_pattern_t *pattern;
688 cairo_matrix_t matrix;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400689 cairo_t *cr;
Pekka Paalanena402b052013-05-22 18:03:10 +0300690 double im_w, im_h;
691 double sx, sy, s;
692 double tx, ty;
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500693 struct rectangle allocation;
Pekka Paalanen9564c752012-10-24 09:43:08 +0300694 struct display *display;
695 struct wl_region *opaque;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400696
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500697 surface = window_get_surface(background->window);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400698
Alexander Larssonc584fa62013-05-22 14:41:32 +0200699 cr = widget_cairo_create(background->widget);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400700 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
701 cairo_set_source_rgba(cr, 0.0, 0.0, 0.2, 1.0);
702 cairo_paint(cr);
703
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500704 widget_get_allocation(widget, &allocation);
Kristian Høgsberg8129bc02012-01-25 14:55:33 -0500705 image = NULL;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300706 if (background->image)
707 image = load_cairo_surface(background->image);
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500708
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300709 if (image && background->type != -1) {
Pekka Paalanena402b052013-05-22 18:03:10 +0300710 im_w = cairo_image_surface_get_width(image);
711 im_h = cairo_image_surface_get_height(image);
712 sx = im_w / allocation.width;
713 sy = im_h / allocation.height;
714
Kristian Høgsberg7e690002011-09-08 18:18:02 -0400715 pattern = cairo_pattern_create_for_surface(image);
Pekka Paalanena402b052013-05-22 18:03:10 +0300716
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300717 switch (background->type) {
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500718 case BACKGROUND_SCALE:
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500719 cairo_matrix_init_scale(&matrix, sx, sy);
720 cairo_pattern_set_matrix(pattern, &matrix);
721 break;
Pekka Paalanena402b052013-05-22 18:03:10 +0300722 case BACKGROUND_SCALE_CROP:
723 s = (sx < sy) ? sx : sy;
724 /* align center */
725 tx = (im_w - s * allocation.width) * 0.5;
726 ty = (im_h - s * allocation.height) * 0.5;
727 cairo_matrix_init_translate(&matrix, tx, ty);
728 cairo_matrix_scale(&matrix, s, s);
729 cairo_pattern_set_matrix(pattern, &matrix);
730 break;
Kristian Høgsberg07f72942012-01-25 16:34:36 -0500731 case BACKGROUND_TILE:
732 cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
733 break;
734 }
Pekka Paalanena402b052013-05-22 18:03:10 +0300735
Kristian Høgsberg7e690002011-09-08 18:18:02 -0400736 cairo_set_source(cr, pattern);
737 cairo_pattern_destroy (pattern);
Kristian Høgsberg27d38662011-10-20 13:11:12 -0400738 cairo_surface_destroy(image);
Kristian Høgsberg8129bc02012-01-25 14:55:33 -0500739 } else {
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300740 set_hex_color(cr, background->color);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400741 }
742
Kristian Høgsberg8129bc02012-01-25 14:55:33 -0500743 cairo_paint(cr);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400744 cairo_destroy(cr);
745 cairo_surface_destroy(surface);
Pekka Paalanen9564c752012-10-24 09:43:08 +0300746
747 display = window_get_display(background->window);
748 opaque = wl_compositor_create_region(display_get_compositor(display));
749 wl_region_add(opaque, allocation.x, allocation.y,
750 allocation.width, allocation.height);
751 wl_surface_set_opaque_region(window_get_wl_surface(background->window), opaque);
752 wl_region_destroy(opaque);
Pekka Paalanen79346ab2013-05-22 18:03:09 +0300753
754 background->painted = 1;
755 check_desktop_ready(background->window);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400756}
757
758static void
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100759background_configure(void *data,
760 struct desktop_shell *desktop_shell,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400761 uint32_t edges, struct window *window,
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100762 int32_t width, int32_t height)
763{
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500764 struct background *background =
765 (struct background *) window_get_user_data(window);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100766
Kristian Høgsbergbb977002012-01-10 19:11:42 -0500767 widget_schedule_resize(background->widget, width, height);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +0100768}
769
770static void
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500771unlock_dialog_redraw_handler(struct widget *widget, void *data)
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200772{
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500773 struct unlock_dialog *dialog = data;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200774 struct rectangle allocation;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200775 cairo_surface_t *surface;
Alexander Larssonc584fa62013-05-22 14:41:32 +0200776 cairo_t *cr;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200777 cairo_pattern_t *pat;
778 double cx, cy, r, f;
779
Alexander Larssonc584fa62013-05-22 14:41:32 +0200780 cr = widget_cairo_create(widget);
Kristian Høgsberg41c5c4e2012-03-05 20:37:51 -0500781
Kristian Høgsbergbb977002012-01-10 19:11:42 -0500782 widget_get_allocation(dialog->widget, &allocation);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200783 cairo_rectangle(cr, allocation.x, allocation.y,
784 allocation.width, allocation.height);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200785 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
786 cairo_set_source_rgba(cr, 0, 0, 0, 0.6);
Kristian Høgsberg41c5c4e2012-03-05 20:37:51 -0500787 cairo_fill(cr);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200788
Kristian Høgsberg41c5c4e2012-03-05 20:37:51 -0500789 cairo_translate(cr, allocation.x, allocation.y);
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500790 if (dialog->button_focused)
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200791 f = 1.0;
792 else
793 f = 0.7;
794
795 cx = allocation.width / 2.0;
796 cy = allocation.height / 2.0;
797 r = (cx < cy ? cx : cy) * 0.4;
798 pat = cairo_pattern_create_radial(cx, cy, r * 0.7, cx, cy, r);
799 cairo_pattern_add_color_stop_rgb(pat, 0.0, 0, 0.86 * f, 0);
800 cairo_pattern_add_color_stop_rgb(pat, 0.85, 0.2 * f, f, 0.2 * f);
801 cairo_pattern_add_color_stop_rgb(pat, 1.0, 0, 0.86 * f, 0);
802 cairo_set_source(cr, pat);
Kristian Høgsberg41c5c4e2012-03-05 20:37:51 -0500803 cairo_pattern_destroy(pat);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200804 cairo_arc(cr, cx, cy, r, 0.0, 2.0 * M_PI);
805 cairo_fill(cr);
806
Kristian Høgsbergc51f7992012-01-08 15:09:53 -0500807 widget_set_allocation(dialog->button,
Kristian Høgsberg41c5c4e2012-03-05 20:37:51 -0500808 allocation.x + cx - r,
809 allocation.y + cy - r, 2 * r, 2 * r);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200810
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200811 cairo_destroy(cr);
812
Alexander Larssonc584fa62013-05-22 14:41:32 +0200813 surface = window_get_surface(dialog->window);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200814 cairo_surface_destroy(surface);
815}
816
817static void
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500818unlock_dialog_button_handler(struct widget *widget,
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200819 struct input *input, uint32_t time,
Daniel Stone4dbadb12012-05-30 16:31:51 +0100820 uint32_t button,
821 enum wl_pointer_button_state state, void *data)
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200822{
823 struct unlock_dialog *dialog = data;
824 struct desktop *desktop = dialog->desktop;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200825
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500826 if (button == BTN_LEFT) {
Daniel Stone4dbadb12012-05-30 16:31:51 +0100827 if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
828 !dialog->closing) {
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200829 display_defer(desktop->display, &desktop->unlock_task);
830 dialog->closing = 1;
831 }
832 }
833}
834
835static void
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200836unlock_dialog_keyboard_focus_handler(struct window *window,
837 struct input *device, void *data)
838{
839 window_schedule_redraw(window);
840}
841
Kristian Høgsbergbb901fa2012-01-09 11:22:32 -0500842static int
Kristian Høgsbergee143232012-01-09 08:42:24 -0500843unlock_dialog_widget_enter_handler(struct widget *widget,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400844 struct input *input,
Kristian Høgsberg80680c72012-05-10 12:21:37 -0400845 float x, float y, void *data)
Kristian Høgsbergee143232012-01-09 08:42:24 -0500846{
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500847 struct unlock_dialog *dialog = data;
848
849 dialog->button_focused = 1;
Kristian Høgsbergee143232012-01-09 08:42:24 -0500850 widget_schedule_redraw(widget);
Kristian Høgsbergbb901fa2012-01-09 11:22:32 -0500851
Ander Conselvan de Oliveiradc8c8fc2012-05-25 16:01:41 +0300852 return CURSOR_LEFT_PTR;
Kristian Høgsbergee143232012-01-09 08:42:24 -0500853}
854
855static void
856unlock_dialog_widget_leave_handler(struct widget *widget,
857 struct input *input, void *data)
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200858{
Kristian Høgsbergb6323512012-01-11 00:04:42 -0500859 struct unlock_dialog *dialog = data;
860
861 dialog->button_focused = 0;
Kristian Høgsberg9a13dab2012-01-08 15:18:19 -0500862 widget_schedule_redraw(widget);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200863}
864
865static struct unlock_dialog *
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500866unlock_dialog_create(struct desktop *desktop)
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200867{
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500868 struct display *display = desktop->display;
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200869 struct unlock_dialog *dialog;
870
Peter Huttererf3d62272013-08-08 11:57:05 +1000871 dialog = xzalloc(sizeof *dialog);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200872
Kristian Høgsberg730c94d2012-06-26 21:44:35 -0400873 dialog->window = window_create_custom(display);
Kristian Høgsberg29af3eb2012-01-10 22:41:05 -0500874 dialog->widget = frame_create(dialog->window, dialog);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200875 window_set_title(dialog->window, "Unlock your desktop");
876
877 window_set_user_data(dialog->window, dialog);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200878 window_set_keyboard_focus_handler(dialog->window,
879 unlock_dialog_keyboard_focus_handler);
Kristian Høgsberg441338c2012-01-10 13:52:34 -0500880 dialog->button = widget_add_widget(dialog->widget, dialog);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -0500881 widget_set_redraw_handler(dialog->widget,
882 unlock_dialog_redraw_handler);
Kristian Høgsbergee143232012-01-09 08:42:24 -0500883 widget_set_enter_handler(dialog->button,
884 unlock_dialog_widget_enter_handler);
885 widget_set_leave_handler(dialog->button,
886 unlock_dialog_widget_leave_handler);
Kristian Høgsberga8a0db32012-01-09 11:12:05 -0500887 widget_set_button_handler(dialog->button,
888 unlock_dialog_button_handler);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200889
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500890 desktop_shell_set_lock_surface(desktop->shell,
Kristian Høgsberg730c94d2012-06-26 21:44:35 -0400891 window_get_wl_surface(dialog->window));
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500892
Pekka Paalanen40e49ac2012-01-18 16:51:30 +0200893 window_schedule_resize(dialog->window, 260, 230);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200894
895 return dialog;
896}
897
898static void
899unlock_dialog_destroy(struct unlock_dialog *dialog)
900{
901 window_destroy(dialog->window);
902 free(dialog);
903}
904
905static void
906unlock_dialog_finish(struct task *task, uint32_t events)
907{
908 struct desktop *desktop =
Benjamin Franzked7759712011-11-22 12:38:48 +0100909 container_of(task, struct desktop, unlock_task);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200910
911 desktop_shell_unlock(desktop->shell);
912 unlock_dialog_destroy(desktop->unlock_dialog);
913 desktop->unlock_dialog = NULL;
914}
915
916static void
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400917desktop_shell_configure(void *data,
918 struct desktop_shell *desktop_shell,
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400919 uint32_t edges,
Kristian Høgsberg962342c2012-06-26 16:29:50 -0400920 struct wl_surface *surface,
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400921 int32_t width, int32_t height)
922{
Kristian Høgsberg962342c2012-06-26 16:29:50 -0400923 struct window *window = wl_surface_get_user_data(surface);
Pekka Paalanen068ae942011-11-28 14:11:15 +0200924 struct surface *s = window_get_user_data(window);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400925
Kristian Høgsbergeae5de72012-04-11 22:42:15 -0400926 s->configure(data, desktop_shell, edges, window, width, height);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400927}
928
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200929static void
930desktop_shell_prepare_lock_surface(void *data,
931 struct desktop_shell *desktop_shell)
932{
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200933 struct desktop *desktop = data;
934
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +0300935 if (!desktop->locking) {
Pekka Paalanenfd83b6d2011-12-08 10:06:53 +0200936 desktop_shell_unlock(desktop->shell);
937 return;
938 }
939
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200940 if (!desktop->unlock_dialog) {
Kristian Høgsberg1ec0c312011-11-15 16:39:55 -0500941 desktop->unlock_dialog = unlock_dialog_create(desktop);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +0200942 desktop->unlock_dialog->desktop = desktop;
943 }
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200944}
945
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300946static void
947desktop_shell_grab_cursor(void *data,
948 struct desktop_shell *desktop_shell,
949 uint32_t cursor)
950{
951 struct desktop *desktop = data;
952
953 switch (cursor) {
Philipp Brüschweiler16d59d72012-08-24 15:43:55 +0200954 case DESKTOP_SHELL_CURSOR_NONE:
955 desktop->grab_cursor = CURSOR_BLANK;
956 break;
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300957 case DESKTOP_SHELL_CURSOR_BUSY:
958 desktop->grab_cursor = CURSOR_WATCH;
959 break;
960 case DESKTOP_SHELL_CURSOR_MOVE:
961 desktop->grab_cursor = CURSOR_DRAGGING;
962 break;
963 case DESKTOP_SHELL_CURSOR_RESIZE_TOP:
964 desktop->grab_cursor = CURSOR_TOP;
965 break;
966 case DESKTOP_SHELL_CURSOR_RESIZE_BOTTOM:
967 desktop->grab_cursor = CURSOR_BOTTOM;
968 break;
969 case DESKTOP_SHELL_CURSOR_RESIZE_LEFT:
970 desktop->grab_cursor = CURSOR_LEFT;
971 break;
972 case DESKTOP_SHELL_CURSOR_RESIZE_RIGHT:
973 desktop->grab_cursor = CURSOR_RIGHT;
974 break;
975 case DESKTOP_SHELL_CURSOR_RESIZE_TOP_LEFT:
976 desktop->grab_cursor = CURSOR_TOP_LEFT;
977 break;
978 case DESKTOP_SHELL_CURSOR_RESIZE_TOP_RIGHT:
979 desktop->grab_cursor = CURSOR_TOP_RIGHT;
980 break;
981 case DESKTOP_SHELL_CURSOR_RESIZE_BOTTOM_LEFT:
982 desktop->grab_cursor = CURSOR_BOTTOM_LEFT;
983 break;
984 case DESKTOP_SHELL_CURSOR_RESIZE_BOTTOM_RIGHT:
985 desktop->grab_cursor = CURSOR_BOTTOM_RIGHT;
986 break;
987 case DESKTOP_SHELL_CURSOR_ARROW:
988 default:
989 desktop->grab_cursor = CURSOR_LEFT_PTR;
990 }
991}
992
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400993static const struct desktop_shell_listener listener = {
Pekka Paalanen9ef3e012011-11-15 13:34:48 +0200994 desktop_shell_configure,
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +0300995 desktop_shell_prepare_lock_surface,
996 desktop_shell_grab_cursor
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -0400997};
998
U. Artie Eoff44874d92012-10-02 21:12:35 -0700999static void
1000background_destroy(struct background *background)
1001{
1002 widget_destroy(background->widget);
1003 window_destroy(background->window);
1004
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001005 free(background->image);
U. Artie Eoff44874d92012-10-02 21:12:35 -07001006 free(background);
1007}
1008
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001009static struct background *
1010background_create(struct desktop *desktop)
1011{
1012 struct background *background;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001013 struct weston_config_section *s;
1014 char *type;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001015
Peter Huttererf3d62272013-08-08 11:57:05 +10001016 background = xzalloc(sizeof *background);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001017 background->base.configure = background_configure;
Kristian Høgsberg962342c2012-06-26 16:29:50 -04001018 background->window = window_create_custom(desktop->display);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -05001019 background->widget = window_add_widget(background->window, background);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001020 window_set_user_data(background->window, background);
Kristian Høgsbergb67e94b2012-01-10 12:23:19 -05001021 widget_set_redraw_handler(background->widget, background_draw);
Tomeu Vizosobee45a12013-08-06 20:05:54 +02001022 window_set_preferred_format(background->window,
1023 WINDOW_PREFERRED_FORMAT_RGB565);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001024
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001025 s = weston_config_get_section(desktop->config, "shell", NULL, NULL);
1026 weston_config_section_get_string(s, "background-image",
1027 &background->image,
1028 DATADIR "/weston/pattern.png");
1029 weston_config_section_get_uint(s, "background-color",
1030 &background->color, 0xff002244);
1031
1032 weston_config_section_get_string(s, "background-type",
1033 &type, "tile");
1034 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);
1092 panel_destroy(output->panel);
1093 wl_output_destroy(output->output);
1094 wl_list_remove(&output->link);
1095
1096 free(output);
1097}
1098
1099static void
1100desktop_destroy_outputs(struct desktop *desktop)
1101{
1102 struct output *tmp;
1103 struct output *output;
1104
1105 wl_list_for_each_safe(output, tmp, &desktop->outputs, link)
1106 output_destroy(output);
1107}
1108
1109static void
Alexander Larssonc584fa62013-05-22 14:41:32 +02001110output_handle_geometry(void *data,
1111 struct wl_output *wl_output,
1112 int x, int y,
1113 int physical_width,
1114 int physical_height,
1115 int subpixel,
1116 const char *make,
1117 const char *model,
1118 int transform)
1119{
1120 struct output *output = data;
1121
1122 window_set_buffer_transform(output->panel->window, transform);
1123 window_set_buffer_transform(output->background->window, transform);
1124}
1125
1126static void
1127output_handle_mode(void *data,
1128 struct wl_output *wl_output,
1129 uint32_t flags,
1130 int width,
1131 int height,
1132 int refresh)
1133{
1134}
1135
1136static void
1137output_handle_done(void *data,
1138 struct wl_output *wl_output)
1139{
1140}
1141
1142static void
1143output_handle_scale(void *data,
1144 struct wl_output *wl_output,
Alexander Larssonedddbd12013-05-24 13:09:43 +02001145 int32_t scale)
Alexander Larssonc584fa62013-05-22 14:41:32 +02001146{
1147 struct output *output = data;
1148
1149 window_set_buffer_scale(output->panel->window, scale);
1150 window_set_buffer_scale(output->background->window, scale);
1151}
1152
1153static const struct wl_output_listener output_listener = {
1154 output_handle_geometry,
1155 output_handle_mode,
1156 output_handle_done,
1157 output_handle_scale
1158};
1159
1160static void
Ander Conselvan de Oliveirae4925492013-07-05 16:05:28 +03001161output_init(struct output *output, struct desktop *desktop)
1162{
1163 struct wl_surface *surface;
1164
1165 output->panel = panel_create(desktop);
1166 surface = window_get_wl_surface(output->panel->window);
1167 desktop_shell_set_panel(desktop->shell,
1168 output->output, surface);
1169
1170 output->background = background_create(desktop);
1171 surface = window_get_wl_surface(output->background->window);
1172 desktop_shell_set_background(desktop->shell,
1173 output->output, surface);
1174}
1175
1176static void
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001177create_output(struct desktop *desktop, uint32_t id)
1178{
1179 struct output *output;
1180
1181 output = calloc(1, sizeof *output);
1182 if (!output)
1183 return;
1184
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001185 output->output =
Alexander Larssonc584fa62013-05-22 14:41:32 +02001186 display_bind(desktop->display, id, &wl_output_interface, 2);
1187
1188 wl_output_add_listener(output->output, &output_listener, output);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001189
1190 wl_list_insert(&desktop->outputs, &output->link);
Ander Conselvan de Oliveirae4925492013-07-05 16:05:28 +03001191
1192 /* On start up we may process an output global before the shell global
1193 * in which case we can't create the panel and background just yet */
1194 if (desktop->shell)
1195 output_init(output, desktop);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001196}
1197
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001198static void
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001199global_handler(struct display *display, uint32_t id,
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001200 const char *interface, uint32_t version, void *data)
1201{
1202 struct desktop *desktop = data;
1203
1204 if (!strcmp(interface, "desktop_shell")) {
Pekka Paalanen79346ab2013-05-22 18:03:09 +03001205 desktop->interface_version = (version < 2) ? version : 2;
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001206 desktop->shell = display_bind(desktop->display,
Pekka Paalanen79346ab2013-05-22 18:03:09 +03001207 id, &desktop_shell_interface,
1208 desktop->interface_version);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001209 desktop_shell_add_listener(desktop->shell, &listener, desktop);
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001210 } else if (!strcmp(interface, "wl_output")) {
1211 create_output(desktop, id);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001212 }
1213}
1214
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -05001215static void
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001216panel_add_launchers(struct panel *panel, struct desktop *desktop)
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -05001217{
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001218 struct weston_config_section *s;
1219 char *icon, *path;
1220 const char *name;
1221 int count;
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -05001222
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001223 count = 0;
1224 s = NULL;
1225 while (weston_config_next_section(desktop->config, &s, &name)) {
1226 if (strcmp(name, "launcher") != 0)
1227 continue;
1228
1229 weston_config_section_get_string(s, "icon", &icon, NULL);
1230 weston_config_section_get_string(s, "path", &path, NULL);
1231
1232 if (icon != NULL && path != NULL) {
1233 panel_add_launcher(panel, icon, path);
Rob Bradford09252d42013-07-26 16:29:45 +01001234 count++;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001235 } else {
1236 fprintf(stderr, "invalid launcher section\n");
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001237 }
1238
1239 free(icon);
1240 free(path);
Kristian Høgsbergac3a59a2011-11-14 22:43:37 -05001241 }
1242
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001243 if (count == 0) {
1244 /* add default launcher */
1245 panel_add_launcher(panel,
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -05001246 DATADIR "/weston/terminal.png",
Rodney Lorrimar99ff01b2012-02-29 17:31:03 +01001247 BINDIR "/weston-terminal");
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001248 }
Kristian Høgsberg6af8eb92012-01-25 16:57:11 -05001249}
1250
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001251int main(int argc, char *argv[])
1252{
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001253 struct desktop desktop = { 0 };
Ossama Othmana50e6e42013-05-14 09:48:26 -07001254 int config_fd;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001255 struct output *output;
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001256 struct weston_config_section *s;
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001257
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001258 desktop.unlock_task.run = unlock_dialog_finish;
Benjamin Franzked0f79ab2011-11-22 12:43:52 +01001259 wl_list_init(&desktop.outputs);
Pekka Paalanenbfbb26b2011-11-15 13:34:56 +02001260
Ander Conselvan de Oliveira6d75da72013-07-05 16:05:27 +03001261 config_fd = open_config_file("weston.ini");
1262 desktop.config = weston_config_parse(config_fd);
1263 close(config_fd);
1264
1265 s = weston_config_get_section(desktop.config, "shell", NULL, NULL);
1266 weston_config_section_get_bool(s, "locking", &desktop.locking, 1);
1267
Kristian Høgsberg4172f662013-02-20 15:27:49 -05001268 desktop.display = display_create(&argc, argv);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001269 if (desktop.display == NULL) {
1270 fprintf(stderr, "failed to create display: %m\n");
1271 return -1;
1272 }
1273
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001274 display_set_user_data(desktop.display, &desktop);
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001275 display_set_global_handler(desktop.display, global_handler);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001276
Ander Conselvan de Oliveirae4925492013-07-05 16:05:28 +03001277 /* Create panel and background for outputs processed before the shell
1278 * global interface was processed */
1279 wl_list_for_each(output, &desktop.outputs, link)
1280 if (!output->panel)
1281 output_init(output, &desktop);
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001282
Ander Conselvan de Oliveirab9d2a0f2012-06-28 18:08:05 +03001283 grab_surface_create(&desktop);
Kristian Høgsbergd56bd902012-06-05 09:58:51 -04001284
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001285 signal(SIGCHLD, sigchild_handler);
1286
1287 display_run(desktop.display);
1288
U. Artie Eoff44874d92012-10-02 21:12:35 -07001289 /* Cleanup */
1290 grab_surface_destroy(&desktop);
1291 desktop_destroy_outputs(&desktop);
1292 if (desktop.unlock_dialog)
1293 unlock_dialog_destroy(desktop.unlock_dialog);
1294 desktop_shell_destroy(desktop.shell);
1295 display_destroy(desktop.display);
1296
Kristian Høgsberg0c29eb22011-09-06 18:02:34 -04001297 return 0;
1298}