swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

xdg_decoration.c (3872B)


      1 /* swc: libswc/xdg_decoration.c
      2  *
      3  * Copyright (c) 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 "xdg_decoration.h"
     25 #include "util.h"
     26 
     27 #include <wayland-server.h>
     28 #include "xdg-decoration-unstable-v1-server-protocol.h"
     29 
     30 struct xdg_toplevel_decoration {
     31 	struct wl_resource *resource;
     32 	struct wl_listener toplevel_destroy_listener;
     33 };
     34 
     35 static void
     36 set_mode(struct wl_client *client, struct wl_resource *resource, uint32_t mode)
     37 {
     38 }
     39 
     40 static void
     41 unset_mode(struct wl_client *client, struct wl_resource *resource)
     42 {
     43 }
     44 
     45 static const struct zxdg_toplevel_decoration_v1_interface decoration_impl = {
     46 	.destroy = destroy_resource,
     47 	.set_mode = set_mode,
     48 	.unset_mode = unset_mode,
     49 };
     50 
     51 static void
     52 handle_toplevel_destroy(struct wl_listener *listener, void *data)
     53 {
     54 	struct xdg_toplevel_decoration *decoration = wl_container_of(listener, decoration, toplevel_destroy_listener);
     55 
     56 	wl_resource_destroy(decoration->resource);
     57 }
     58 
     59 static void
     60 decoration_destroy(struct wl_resource *resource)
     61 {
     62 	struct xdg_toplevel_decoration *decoration = wl_resource_get_user_data(resource);
     63 
     64 	wl_list_remove(&decoration->toplevel_destroy_listener.link);
     65 	free(decoration);
     66 }
     67 
     68 static void
     69 get_toplevel_decoration(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *toplevel_resource)
     70 {
     71 	struct xdg_toplevel_decoration *decoration;
     72 
     73 	decoration = malloc(sizeof(*decoration));
     74 	if (!decoration)
     75 		goto error0;
     76 	decoration->resource = wl_resource_create(client, &zxdg_toplevel_decoration_v1_interface, wl_resource_get_version(resource), id);
     77 	if (!decoration->resource)
     78 		goto error1;
     79 	decoration->toplevel_destroy_listener.notify = &handle_toplevel_destroy;
     80 	wl_resource_add_destroy_listener(toplevel_resource, &decoration->toplevel_destroy_listener);
     81 	wl_resource_set_implementation(decoration->resource, &decoration_impl, decoration, decoration_destroy);
     82 	zxdg_toplevel_decoration_v1_send_configure(decoration->resource, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
     83 	return;
     84 
     85 error1:
     86 	free(decoration);
     87 error0:
     88 	wl_resource_post_no_memory(resource);
     89 }
     90 
     91 static const struct zxdg_decoration_manager_v1_interface decoration_manager_impl = {
     92 	.destroy = destroy_resource,
     93 	.get_toplevel_decoration = get_toplevel_decoration,
     94 };
     95 
     96 static void
     97 bind_decoration_manager(struct wl_client *client, void *data, uint32_t version, uint32_t id)
     98 {
     99 	struct wl_resource *resource;
    100 
    101 	resource = wl_resource_create(client, &zxdg_decoration_manager_v1_interface, version, id);
    102 	if (!resource) {
    103 		wl_client_post_no_memory(client);
    104 		return;
    105 	}
    106 	wl_resource_set_implementation(resource, &decoration_manager_impl, NULL, NULL);
    107 }
    108 
    109 struct wl_global *
    110 xdg_decoration_manager_create(struct wl_display *display)
    111 {
    112 	return wl_global_create(display, &zxdg_decoration_manager_v1_interface, 1, NULL, &bind_decoration_manager);
    113 }