1/* swc: libswc/shell.c
2 *
3 * Copyright (c) 2013-2020 Michael Forney
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24#include "shell.h"
25#include "internal.h"
26#include "surface.h"
27#include "shell_surface.h"
28
29#include <wayland-server.h>
30
31static void
32get_shell_surface(struct wl_client *client, struct wl_resource *resource,
33 uint32_t id, struct wl_resource *surface_resource)
34{
35 struct surface *surface = wl_resource_get_user_data(surface_resource);
36 struct shell_surface *shell_surface;
37
38 if (surface->role) {
39 wl_resource_post_error(resource, WL_SHELL_ERROR_ROLE,
40 "surface already has a role");
41 return;
42 }
43
44 shell_surface = shell_surface_new(client, wl_resource_get_version(resource),
45 id, surface);
46
47 if (!shell_surface) {
48 wl_resource_post_no_memory(resource);
49 }
50}
51
52static const struct wl_shell_interface shell_implementation = {
53 .get_shell_surface = get_shell_surface,
54};
55
56static void
57bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
58{
59 struct wl_resource *resource;
60
61 resource = wl_resource_create(client, &wl_shell_interface, version, id);
62 if (!resource) {
63 wl_client_post_no_memory(client);
64 return;
65 }
66 wl_resource_set_implementation(resource, &shell_implementation, NULL, NULL);
67}
68
69struct wl_global *
70shell_create(struct wl_display *display)
71{
72 return wl_global_create(display, &wl_shell_interface, 1, NULL, &bind_shell);
73}