swc

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

data_device_manager.c (2552B)


      1 /* swc: data_device_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 "data_device_manager.h"
     25 #include "data.h"
     26 #include "data_device.h"
     27 #include "internal.h"
     28 #include "seat.h"
     29 
     30 static void
     31 create_data_source(struct wl_client *client, struct wl_resource *resource, uint32_t id)
     32 {
     33 	if (!data_source_new(client, wl_resource_get_version(resource), id))
     34 		wl_resource_post_no_memory(resource);
     35 }
     36 
     37 static void
     38 get_data_device(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *seat_resource)
     39 {
     40 	struct swc_seat *seat = wl_resource_get_user_data(seat_resource);
     41 
     42 	if (!data_device_bind(seat->data_device, client, wl_resource_get_version(resource), id))
     43 		wl_resource_post_no_memory(resource);
     44 }
     45 
     46 static const struct wl_data_device_manager_interface data_device_manager_impl = {
     47 	.create_data_source = create_data_source,
     48 	.get_data_device = get_data_device,
     49 };
     50 
     51 static void
     52 bind_data_device_manager(struct wl_client *client, void *data, uint32_t version, uint32_t id)
     53 {
     54 	struct wl_resource *resource;
     55 
     56 	resource = wl_resource_create(client, &wl_data_device_manager_interface, version, id);
     57 	if (!resource) {
     58 		wl_client_post_no_memory(client);
     59 		return;
     60 	}
     61 	wl_resource_set_implementation(resource, &data_device_manager_impl, NULL, NULL);
     62 }
     63 
     64 struct wl_global *
     65 data_device_manager_create(struct wl_display *display)
     66 {
     67 	return wl_global_create(display, &wl_data_device_manager_interface, 2, NULL, &bind_data_device_manager);
     68 }