data_device_manager.c (2751B)
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, 32 uint32_t id) 33 { 34 if (!data_source_new(client, wl_resource_get_version(resource), id)) { 35 wl_resource_post_no_memory(resource); 36 } 37 } 38 39 static void 40 get_data_device(struct wl_client *client, struct wl_resource *resource, 41 uint32_t id, struct wl_resource *seat_resource) 42 { 43 struct swc_seat *seat = wl_resource_get_user_data(seat_resource); 44 45 if (!data_device_bind(seat->data_device, client, 46 wl_resource_get_version(resource), id)) { 47 wl_resource_post_no_memory(resource); 48 } 49 } 50 51 static const struct wl_data_device_manager_interface data_device_manager_impl = 52 { 53 .create_data_source = create_data_source, 54 .get_data_device = get_data_device, 55 }; 56 57 static void 58 bind_data_device_manager(struct wl_client *client, void *data, uint32_t version, 59 uint32_t id) 60 { 61 struct wl_resource *resource; 62 63 resource = wl_resource_create(client, &wl_data_device_manager_interface, 64 version, id); 65 if (!resource) { 66 wl_client_post_no_memory(client); 67 return; 68 } 69 wl_resource_set_implementation(resource, &data_device_manager_impl, NULL, 70 NULL); 71 } 72 73 struct wl_global * 74 data_device_manager_create(struct wl_display *display) 75 { 76 return wl_global_create(display, &wl_data_device_manager_interface, 3, 77 NULL, &bind_data_device_manager); 78 }