diff --git a/src/libeis-client.h b/src/libeis-client.h new file mode 100644 index 0000000..c400a9e --- /dev/null +++ b/src/libeis-client.h @@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2020 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#include "libeis.h" + +#include "util-object.h" +#include "util-list.h" + +enum eis_client_state { + EIS_CLIENT_STATE_NEW, /* just connected */ + EIS_CLIENT_STATE_CONNECTING, /* client requested connect */ + EIS_CLIENT_STATE_CONNECTED, /* server has sent connect */ + EIS_CLIENT_STATE_DISCONNECTED, +}; + +struct eis_client { + struct object object; + void *user_data; + struct list link; + struct source *source; + uint32_t version; + uint32_t configure_version; + uint32_t id; + enum eis_client_state state; + char *name; + bool is_sender; + + struct list seats; + struct list seats_pending; + + struct { + uint32_t cap_allow_mask; + } restrictions; +}; + +struct eis_client * +eis_client_new(struct eis *eis, int fd); + +struct eis* +eis_client_get_context(struct eis_client *client); + +struct eis_client * +eis_client_get_client(struct eis_client *client); + +void +eis_add_client(struct eis *eis, struct eis_client *client); + +void +eis_client_add_seat(struct eis_client *client, struct eis_seat *seat); +void +eis_client_remove_seat(struct eis_client *client, struct eis_seat *seat); + +void +eis_client_add_device(struct eis_client *client, struct eis_device *device); +void +eis_client_remove_device(struct eis_client *client, struct eis_device *device); + +void +eis_client_resume_device(struct eis_client *client, + struct eis_device *device); +void +eis_client_pause_device(struct eis_client *client, + struct eis_device *device); + +void +eis_client_keyboard_modifiers(struct eis_client *client, struct eis_device *device, + uint32_t depressed, uint32_t latched, uint32_t locked, + uint32_t group); + diff --git a/src/libeis-device.h b/src/libeis-device.h new file mode 100644 index 0000000..2580fa8 --- /dev/null +++ b/src/libeis-device.h @@ -0,0 +1,157 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2020 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#include "libeis.h" + +#include "util-object.h" +#include "util-list.h" + +enum eis_device_state { + EIS_DEVICE_STATE_NEW, + EIS_DEVICE_STATE_PAUSED, + EIS_DEVICE_STATE_RESUMED, + EIS_DEVICE_STATE_EMULATING, + EIS_DEVICE_STATE_CLOSED_BY_CLIENT, + EIS_DEVICE_STATE_DEAD, +}; + +struct eis_device { + struct object object; /* parent is ei_seat, and we have a ref to it */ + struct list link; + uint32_t id; + char *name; + enum eis_device_state state; + uint32_t capabilities; + void *user_data; + enum eis_device_type type; + + uint32_t width, height; + + struct list regions; + struct list regions_new; /* not yet added */ + + struct eis_keymap *keymap; + + struct list pending_event_queue; /* incoming events waiting for a frame */ + + bool send_frame_event; + + struct { + bool x_is_stopped, y_is_stopped; + bool x_is_cancelled, y_is_cancelled; + } scroll; + +}; + +struct eis_touch { + struct object object; + struct eis_device *device; + void *user_data; + uint32_t tracking_id; + enum { + TOUCH_IS_NEW, + TOUCH_IS_DOWN, + TOUCH_IS_UP, + } state; + + double x, y; +}; + +struct eis_keymap { + struct object object; + struct eis_device *device; + void *user_data; + enum eis_keymap_type type; + int fd; + size_t size; + bool assigned; +}; + +struct eis_xkb_modifiers { + uint32_t depressed; + uint32_t locked; + uint32_t latched; + uint32_t group; +}; + +struct eis * +eis_device_get_context(struct eis_device *device); + +void +eis_device_set_client_keymap(struct eis_device *device, + enum eis_keymap_type type, + int keymap_fd, size_t size); +int +eis_device_event_frame(struct eis_device *device, uint64_t time); + +int +eis_device_event_pointer_rel(struct eis_device *device, + double x, double y); + +int +eis_device_event_pointer_abs(struct eis_device *device, + double x, double y); + +int +eis_device_event_pointer_button(struct eis_device *device, + uint32_t button, bool state); + +int +eis_device_event_pointer_scroll(struct eis_device *device, + double x, double y); + +int +eis_device_event_pointer_scroll_discrete(struct eis_device *device, + int32_t x, int32_t y); +int +eis_device_event_pointer_scroll_stop(struct eis_device *device, bool x, bool y); + +int +eis_device_event_pointer_scroll_cancel(struct eis_device *device, bool x, bool y); + +int +eis_device_event_keyboard_key(struct eis_device *device, + uint32_t key, bool state); +int +eis_device_event_touch_down(struct eis_device *device, uint32_t touchid, + double x, double y); + +int +eis_device_event_touch_motion(struct eis_device *device, uint32_t touchid, + double x, double y); + +int +eis_device_event_touch_up(struct eis_device *device, uint32_t touchid); + +void +eis_device_event_start_emulating(struct eis_device *device, uint32_t sequence); + +void +eis_device_event_stop_emulating(struct eis_device *device); + +void +eis_device_closed_by_client(struct eis_device *device); + diff --git a/src/libeis-event.h b/src/libeis-event.h new file mode 100644 index 0000000..2a928d1 --- /dev/null +++ b/src/libeis-event.h @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2020 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#include "libeis.h" +#include "util-object.h" +#include "util-list.h" + +struct eis_event { + struct object object; + enum eis_event_type type; + struct list link; + struct eis_client *client; + struct eis_seat *seat; + struct eis_device *device; + + uint64_t timestamp; + + union { + struct { + uint32_t capabilities; + } bind; + struct { + double dx, dy; /* relative motion */ + double absx, absy; /* absolute motion */ + double sx, sy; /* scroll */ + int32_t sdx, sdy; /* discrete scroll */ + bool stop_x, stop_y; /* scroll stop */ + uint32_t button; + bool button_is_press; + } pointer; + struct { + uint32_t key; + bool key_is_press; + } keyboard; + struct { + uint32_t touchid; + double x, y; + } touch; + struct { + uint32_t sequence; + } start_emulating; + }; +}; + +struct eis_event * +eis_event_new_for_client(struct eis_client *client); + +struct eis_event * +eis_event_new_for_seat(struct eis_seat *seat); + +struct eis_event * +eis_event_new_for_device(struct eis_device *device); + +struct eis * +eis_event_get_context(struct eis_event *event); + +struct eis_event* +eis_event_ref(struct eis_event *event); + diff --git a/src/libeis-private.h b/src/libeis-private.h index 5541158..af7ef63 100644 --- a/src/libeis-private.h +++ b/src/libeis-private.h @@ -34,6 +34,12 @@ #include "util-sources.h" #include "util-structs.h" +#include "libeis-client.h" +#include "libeis-device.h" +#include "libeis-event.h" +#include "libeis-region.h" +#include "libeis-seat.h" + struct eis_backend_interface { void (*destroy)(struct eis *eis, void *backend); }; @@ -56,171 +62,6 @@ struct eis { const struct eis_proto_requests *requests; }; -enum eis_client_state { - EIS_CLIENT_STATE_NEW, /* just connected */ - EIS_CLIENT_STATE_CONNECTING, /* client requested connect */ - EIS_CLIENT_STATE_CONNECTED, /* server has sent connect */ - EIS_CLIENT_STATE_DISCONNECTED, -}; - -struct eis_client { - struct object object; - void *user_data; - struct list link; - struct source *source; - uint32_t version; - uint32_t configure_version; - uint32_t id; - enum eis_client_state state; - char *name; - bool is_sender; - - struct list seats; - struct list seats_pending; - - struct { - uint32_t cap_allow_mask; - } restrictions; -}; - -enum eis_seat_state { - EIS_SEAT_STATE_PENDING, - EIS_SEAT_STATE_ADDED, - EIS_SEAT_STATE_BOUND, - EIS_SEAT_STATE_REMOVED_INTERNALLY, /* Removed internally but eis_seat_remove() may be called */ - EIS_SEAT_STATE_REMOVED, /* Removed but still waiting for some devices to be removed */ - EIS_SEAT_STATE_DEAD, /* Removed from our list */ -}; - -struct eis_seat { - struct object object; /* parent is ei_client */ - struct list link; - void *user_data; - uint32_t id; - - enum eis_seat_state state; - char *name; - uint32_t capabilities_mask; - - struct list devices; -}; - -enum eis_device_state { - EIS_DEVICE_STATE_NEW, - EIS_DEVICE_STATE_PAUSED, - EIS_DEVICE_STATE_RESUMED, - EIS_DEVICE_STATE_EMULATING, - EIS_DEVICE_STATE_CLOSED_BY_CLIENT, - EIS_DEVICE_STATE_DEAD, -}; - -struct eis_region { - struct object object; - struct eis_device *device; - void *user_data; - bool added_to_device; - struct list link; - uint32_t x, y; - uint32_t width, height; - double physical_scale; -}; - -struct eis_device { - struct object object; /* parent is ei_seat, and we have a ref to it */ - struct list link; - uint32_t id; - char *name; - enum eis_device_state state; - uint32_t capabilities; - void *user_data; - enum eis_device_type type; - - uint32_t width, height; - - struct list regions; - struct list regions_new; /* not yet added */ - - struct eis_keymap *keymap; - - struct list pending_event_queue; /* incoming events waiting for a frame */ - - bool send_frame_event; - - struct { - bool x_is_stopped, y_is_stopped; - bool x_is_cancelled, y_is_cancelled; - } scroll; - -}; - -struct eis_touch { - struct object object; - struct eis_device *device; - void *user_data; - uint32_t tracking_id; - enum { - TOUCH_IS_NEW, - TOUCH_IS_DOWN, - TOUCH_IS_UP, - } state; - - double x, y; -}; - -struct eis_event { - struct object object; - enum eis_event_type type; - struct list link; - struct eis_client *client; - struct eis_seat *seat; - struct eis_device *device; - - uint64_t timestamp; - - union { - struct { - uint32_t capabilities; - } bind; - struct { - double dx, dy; /* relative motion */ - double absx, absy; /* absolute motion */ - double sx, sy; /* scroll */ - int32_t sdx, sdy; /* discrete scroll */ - bool stop_x, stop_y; /* scroll stop */ - uint32_t button; - bool button_is_press; - } pointer; - struct { - uint32_t key; - bool key_is_press; - } keyboard; - struct { - uint32_t touchid; - double x, y; - } touch; - struct { - uint32_t sequence; - } start_emulating; - }; -}; - -struct eis_keymap { - struct object object; - struct eis_device *device; - void *user_data; - enum eis_keymap_type type; - int fd; - size_t size; - bool assigned; -}; - -struct eis_xkb_modifiers { - uint32_t depressed; - uint32_t locked; - uint32_t latched; - uint32_t group; -}; - void eis_init_object(struct eis *eis, struct object *parent); @@ -230,122 +71,6 @@ eis_init(struct eis *eis); struct eis * eis_get_context(struct eis *eis); -struct eis_client * -eis_client_new(struct eis *eis, int fd); - -struct eis* -eis_client_get_context(struct eis_client *client); - -struct eis_client * -eis_client_get_client(struct eis_client *client); - -void -eis_add_client(struct eis *eis, struct eis_client *client); - -void -eis_client_add_seat(struct eis_client *client, struct eis_seat *seat); -void -eis_client_remove_seat(struct eis_client *client, struct eis_seat *seat); - -void -eis_client_add_device(struct eis_client *client, struct eis_device *device); -void -eis_client_remove_device(struct eis_client *client, struct eis_device *device); - -void -eis_client_resume_device(struct eis_client *client, - struct eis_device *device); -void -eis_client_pause_device(struct eis_client *client, - struct eis_device *device); - -void -eis_client_keyboard_modifiers(struct eis_client *client, struct eis_device *device, - uint32_t depressed, uint32_t latched, uint32_t locked, - uint32_t group); - -void -eis_seat_bind(struct eis_seat *seat, uint32_t cap); - -void -eis_seat_drop(struct eis_seat *seat); - -struct eis * -eis_device_get_context(struct eis_device *device); - -void -eis_device_set_client_keymap(struct eis_device *device, - enum eis_keymap_type type, - int keymap_fd, size_t size); -int -eis_device_event_frame(struct eis_device *device, uint64_t time); - -int -eis_device_event_pointer_rel(struct eis_device *device, - double x, double y); - -int -eis_device_event_pointer_abs(struct eis_device *device, - double x, double y); - -int -eis_device_event_pointer_button(struct eis_device *device, - uint32_t button, bool state); - -int -eis_device_event_pointer_scroll(struct eis_device *device, - double x, double y); - -int -eis_device_event_pointer_scroll_discrete(struct eis_device *device, - int32_t x, int32_t y); -int -eis_device_event_pointer_scroll_stop(struct eis_device *device, bool x, bool y); - -int -eis_device_event_pointer_scroll_cancel(struct eis_device *device, bool x, bool y); - -int -eis_device_event_keyboard_key(struct eis_device *device, - uint32_t key, bool state); -int -eis_device_event_touch_down(struct eis_device *device, uint32_t touchid, - double x, double y); - -int -eis_device_event_touch_motion(struct eis_device *device, uint32_t touchid, - double x, double y); - -int -eis_device_event_touch_up(struct eis_device *device, uint32_t touchid); - -void -eis_device_event_start_emulating(struct eis_device *device, uint32_t sequence); - -void -eis_device_event_stop_emulating(struct eis_device *device); - -void -eis_device_closed_by_client(struct eis_device *device); - -bool -eis_region_contains(struct eis_region *r, double x, double y); - -struct eis_event * -eis_event_new_for_client(struct eis_client *client); - -struct eis_event * -eis_event_new_for_seat(struct eis_seat *seat); - -struct eis_event * -eis_event_new_for_device(struct eis_device *device); - -struct eis * -eis_event_get_context(struct eis_event *event); - -struct eis_event* -eis_event_ref(struct eis_event *event); - void eis_queue_connect_event(struct eis_client *client); diff --git a/src/libeis-region.h b/src/libeis-region.h new file mode 100644 index 0000000..69a7a07 --- /dev/null +++ b/src/libeis-region.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2020 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#include "libeis.h" + +#include "util-object.h" +#include "util-list.h" + +struct eis_region { + struct object object; + struct eis_device *device; + void *user_data; + bool added_to_device; + struct list link; + uint32_t x, y; + uint32_t width, height; + double physical_scale; +}; + +bool +eis_region_contains(struct eis_region *r, double x, double y); diff --git a/src/libeis-seat.h b/src/libeis-seat.h new file mode 100644 index 0000000..d0fd100 --- /dev/null +++ b/src/libeis-seat.h @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2020 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#include +#include "util-object.h" +#include "util-list.h" + +enum eis_seat_state { + EIS_SEAT_STATE_PENDING, + EIS_SEAT_STATE_ADDED, + EIS_SEAT_STATE_BOUND, + EIS_SEAT_STATE_REMOVED_INTERNALLY, /* Removed internally but eis_seat_remove() may be called */ + EIS_SEAT_STATE_REMOVED, /* Removed but still waiting for some devices to be removed */ + EIS_SEAT_STATE_DEAD, /* Removed from our list */ +}; + +struct eis_seat { + struct object object; /* parent is ei_client */ + struct list link; + void *user_data; + uint32_t id; + + enum eis_seat_state state; + char *name; + uint32_t capabilities_mask; + + struct list devices; +}; + +void +eis_seat_bind(struct eis_seat *seat, uint32_t cap); + +void +eis_seat_drop(struct eis_seat *seat); +