1 /* 2 * Copyright (c) 2020 Andri Yngvason 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 * PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #pragma once 18 19 #include <wayland-client.h> 20 21 struct wl_cursor_theme; 22 23 enum pointer_cursor_type { 24 POINTER_CURSOR_NONE = 0, 25 POINTER_CURSOR_LEFT_PTR, 26 }; 27 28 enum pointer_button_mask { 29 POINTER_BUTTON_LEFT = 1 << 0, 30 POINTER_BUTTON_MIDDLE = 1 << 1, 31 POINTER_BUTTON_RIGHT = 1 << 2, 32 // TODO: More buttons 33 POINTER_SCROLL_UP = 1 << 3, 34 POINTER_SCROLL_DOWN = 1 << 4, 35 POINTER_SCROLL_LEFT = 1 << 5, 36 POINTER_SCROLL_RIGHT = 1 << 6, 37 }; 38 39 struct pointer { 40 struct wl_pointer* wl_pointer; 41 struct wl_list link; 42 43 uint32_t serial; 44 enum pointer_button_mask pressed; 45 wl_fixed_t x, y; 46 47 int vertical_scroll_steps; 48 int horizontal_scroll_steps; 49 50 double vertical_axis_value; 51 double horizontal_axis_value; 52 53 struct wl_cursor_theme* cursor_theme; 54 struct wl_surface* cursor_surface; 55 56 enum pointer_cursor_type cursor_type; 57 }; 58 59 struct pointer_collection { 60 struct wl_list pointers; 61 void (*on_frame)(struct pointer_collection*, struct pointer*); 62 enum pointer_cursor_type cursor_type; 63 void* userdata; 64 }; 65 66 struct pointer_collection* pointer_collection_new(enum pointer_cursor_type); 67 void pointer_collection_destroy(struct pointer_collection*); 68 69 int pointer_collection_add_wl_pointer(struct pointer_collection* self, 70 struct wl_pointer* wl_pointer); 71 void pointer_collection_remove_wl_pointer(struct pointer_collection* self, 72 struct wl_pointer* wl_pointer); 73