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 <stdbool.h> 20 #include <unistd.h> 21 #include <pixman.h> 22 #include <wayland-client.h> 23 #include <rfb/rfbclient.h> 24 25 struct vnc_client { 26 rfbClient* client; 27 28 int (*alloc_fb)(struct vnc_client*); 29 void (*update_fb)(struct vnc_client*); 30 void (*cut_text)(struct vnc_client*, const char*, size_t); 31 32 void* userdata; 33 struct pixman_region16 damage; 34 }; 35 36 struct vnc_client* vnc_client_create(void); 37 void vnc_client_destroy(struct vnc_client* self); 38 39 int vnc_client_connect(struct vnc_client* self, const char* address, int port); 40 41 int vnc_client_set_pixel_format(struct vnc_client* self, 42 enum wl_shm_format format); 43 44 int vnc_client_get_fd(const struct vnc_client* self); 45 int vnc_client_get_width(const struct vnc_client* self); 46 int vnc_client_get_height(const struct vnc_client* self); 47 int vnc_client_get_stride(const struct vnc_client* self); 48 void* vnc_client_get_fb(const struct vnc_client* self); 49 void vnc_client_set_fb(struct vnc_client* self, void* fb); 50 const char* vnc_client_get_desktop_name(const struct vnc_client* self); 51 int vnc_client_process(struct vnc_client* self); 52 void vnc_client_send_pointer_event(struct vnc_client* self, int x, int y, 53 uint32_t button_mask); 54 void vnc_client_send_keyboard_event(struct vnc_client* self, uint32_t symbol, 55 uint32_t code, bool is_pressed); 56 void vnc_client_set_encodings(struct vnc_client* self, const char* encodings); 57 void vnc_client_set_quality_level(struct vnc_client* self, int value); 58 void vnc_client_set_compression_level(struct vnc_client* self, int value); 59 void vnc_client_send_cut_text(struct vnc_client* self, const char* text, 60 size_t len); 61