From 841052f7731c05e0f03d58284bfe8d249f91c109 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Thu, 4 Nov 2021 10:22:52 +0000 Subject: Initial commit --- vncc.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 vncc.c (limited to 'vncc.c') diff --git a/vncc.c b/vncc.c new file mode 100644 index 0000000..c2914cb --- /dev/null +++ b/vncc.c @@ -0,0 +1,74 @@ +#include + +#include "SDL2_vnc.h" + +int main(int argc, char **argv) { + + SDL_Init(SDL_INIT_VIDEO); + + SDL_Renderer *rend; + SDL_Window *wind; + SDL_CreateWindowAndRenderer(800, 600, 0, &wind, &rend); + SDL_Rect window_size; + window_size.x = 0; + window_size.y = 0; + window_size.w = 800; + window_size.h = 600; + + SDL_ShowCursor(SDL_DISABLE); + + SDL_vnc vnc; + printf("trying to make connection\n"); + init_vnc_connection(&vnc, "127.0.0.1", 5905, 60); + printf("connection succeeded!\n"); + + bool running = true; + + while (running) { + SDL_Event e; + while (SDL_PollEvent(&e)) { + switch (e.type) { + case SDL_QUIT: + running = false; + break; + + case SDL_KEYUP: + case SDL_KEYDOWN: + key_event(&vnc, e.key.state == SDL_PRESSED, e.key.keysym); + break; + + case SDL_MOUSEBUTTONUP: + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEMOTION: { + int x; + int y; + uint32_t buttons = SDL_GetMouseState(&x, &y); + pointer_event(&vnc, buttons, x, y, 0, 0); + break; + } + + case SDL_MOUSEWHEEL: { + int x; + int y; + uint32_t buttons = SDL_GetMouseState(&x, &y); + pointer_event(&vnc, buttons, x, y, e.wheel.x, e.wheel.y); + pointer_event(&vnc, buttons, x, y, 0, 0); + break; + } + + default: + break; + } + } + + SDL_Texture *text = SDL_CreateTextureFromSurface(rend, vnc.surface); + SDL_RenderCopy(rend, text, &window_size, NULL); + SDL_DestroyTexture(text); + + SDL_RenderPresent(rend); + + SDL_Delay(1000/60); + } + + return 0; +} -- cgit v1.2.1