blob: 591a626d52133c515848029c280d7ce497909867 [file] [log] [blame]
Quentin Glidic642bcaf2017-01-27 17:30:23 +01001/*
2 * Copyright © 2010-2012 Intel Corporation
3 * Copyright © 2011-2012 Collabora, Ltd.
4 * Copyright © 2013 Raspberry Pi Foundation
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26#include "config.h"
27
28#include <stdlib.h>
29#include <stdint.h>
30#include <stdio.h>
31#include <string.h>
32#include <unistd.h>
33#include <linux/input.h>
34#include <assert.h>
35#include <signal.h>
36#include <math.h>
37#include <sys/types.h>
38
39#include "compositor/weston.h"
40#include "shared/config-parser.h"
41#include "shared/helpers.h"
42#include "libweston-desktop/libweston-desktop.h"
43
44#ifndef static_assert
45#define static_assert(cond, msg)
46#endif
47
48static struct weston_desktop *desktop = NULL;
49static struct weston_layer background_layer;
50static struct weston_surface *background_surface = NULL;
51static struct weston_view *background_view = NULL;
52static struct weston_layer layer;
53static struct weston_view *view = NULL;
54/*
55 * libweston-desktop
56 */
57
58static void
59desktop_surface_added(struct weston_desktop_surface *desktop_surface,
60 void *shell)
61{
62
63 assert(!view);
64
65 view = weston_desktop_surface_create_view(desktop_surface);
66
67 assert(view);
68}
69
70static void
71desktop_surface_removed(struct weston_desktop_surface *desktop_surface,
72 void *shell)
73{
74 assert(view);
75
76 weston_desktop_surface_unlink_view(view);
77 weston_view_destroy(view);
78 view = NULL;
79}
80
81static void
82desktop_surface_committed(struct weston_desktop_surface *desktop_surface,
83 int32_t sx, int32_t sy, void *data)
84{
85 struct weston_surface *surface =
86 weston_desktop_surface_get_surface(desktop_surface);
87 struct weston_geometry geometry =
88 weston_desktop_surface_get_geometry(desktop_surface);
89
90 assert(view);
91
92 if (weston_surface_is_mapped(surface))
93 return;
94
95 surface->is_mapped = true;
96 weston_layer_entry_insert(&layer.view_list, &view->layer_link);
97 weston_view_set_position(view, 0 - geometry.x, 0 - geometry.y);
98 weston_view_update_transform(view);
99 view->is_mapped = true;
100}
101
102static void
103desktop_surface_move(struct weston_desktop_surface *desktop_surface,
104 struct weston_seat *seat, uint32_t serial, void *shell)
105{
106}
107
108static void
109desktop_surface_resize(struct weston_desktop_surface *desktop_surface,
110 struct weston_seat *seat, uint32_t serial,
111 enum weston_desktop_surface_edge edges, void *shell)
112{
113}
114
115static void
116desktop_surface_fullscreen_requested(struct weston_desktop_surface *desktop_surface,
117 bool fullscreen,
118 struct weston_output *output, void *shell)
119{
120}
121
122static void
123desktop_surface_maximized_requested(struct weston_desktop_surface *desktop_surface,
124 bool maximized, void *shell)
125{
126}
127
128static void
129desktop_surface_minimized_requested(struct weston_desktop_surface *desktop_surface,
130 void *shell)
131{
132}
133
134static void
135desktop_surface_ping_timeout(struct weston_desktop_client *desktop_client,
136 void *shell)
137{
138}
139
140static void
141desktop_surface_pong(struct weston_desktop_client *desktop_client,
142 void *shell)
143{
144}
145
146static const struct weston_desktop_api shell_desktop_api = {
147 .struct_size = sizeof(struct weston_desktop_api),
148 .surface_added = desktop_surface_added,
149 .surface_removed = desktop_surface_removed,
150 .committed = desktop_surface_committed,
151 .move = desktop_surface_move,
152 .resize = desktop_surface_resize,
153 .fullscreen_requested = desktop_surface_fullscreen_requested,
154 .maximized_requested = desktop_surface_maximized_requested,
155 .minimized_requested = desktop_surface_minimized_requested,
156 .ping_timeout = desktop_surface_ping_timeout,
157 .pong = desktop_surface_pong,
158};
159
160/* ************************ *
161 * end of libweston-desktop *
162 * ************************ */
163
164WL_EXPORT int
165wet_shell_init(struct weston_compositor *ec,
166 int *argc, char *argv[])
167{
168 weston_layer_init(&layer, ec);
169 weston_layer_init(&background_layer, ec);
170
171 weston_layer_set_position(&layer,
172 WESTON_LAYER_POSITION_NORMAL);
173 weston_layer_set_position(&background_layer,
174 WESTON_LAYER_POSITION_BACKGROUND);
175
176 background_surface = weston_surface_create(ec);
177 if (background_surface == NULL)
178 return -1;
179 background_view = weston_view_create(background_surface);
180 if (background_view == NULL) {
181 weston_surface_destroy(background_surface);
182 return -1;
183 }
184
185 weston_surface_set_color(background_surface, 0.0, 0.0, 0.0, 1);
186 pixman_region32_fini(&background_surface->opaque);
187 pixman_region32_init_rect(&background_surface->opaque, 0, 0, 2000, 2000);
188 pixman_region32_fini(&background_surface->input);
189 pixman_region32_init_rect(&background_surface->input, 0, 0, 2000, 2000);
190
191 weston_surface_set_size(background_surface, 2000, 2000);
192 weston_view_set_position(background_view, 0, 0);
193 weston_layer_entry_insert(&background_layer.view_list, &background_view->layer_link);
194 weston_view_update_transform(background_view);
195
196 desktop = weston_desktop_create(ec, &shell_desktop_api, NULL);
197 return desktop ? 0 : -1;
198}