main neuswc / libswc / panel_manager.c
 1/* swc: libswc/panel_manager.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 "panel_manager.h"
25#include "internal.h"
26#include "panel.h"
27
28#include "swc-server-protocol.h"
29#include <wayland-server.h>
30
31static void
32create_panel(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
37	if (!panel_new(client, wl_resource_get_version(resource), id, surface)) {
38		wl_client_post_no_memory(client);
39	}
40}
41
42static const struct swc_panel_manager_interface panel_manager_impl = {
43    .create_panel = create_panel,
44};
45
46static void
47bind_panel_manager(struct wl_client *client, void *data, uint32_t version,
48                   uint32_t id)
49{
50	struct wl_resource *resource;
51
52	resource =
53	    wl_resource_create(client, &swc_panel_manager_interface, version, id);
54	if (!resource) {
55		wl_client_post_no_memory(client);
56		return;
57	}
58	wl_resource_set_implementation(resource, &panel_manager_impl, NULL, NULL);
59}
60
61struct wl_global *
62panel_manager_create(struct wl_display *display)
63{
64	return wl_global_create(display, &swc_panel_manager_interface, 1, NULL,
65	                        &bind_panel_manager);
66}