From c9110cd30d6efd42de07b357ff144d5ccacb2541 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Thu, 4 Nov 2021 11:23:12 +0000 Subject: Have library control window creation This allows for the library to create a window of the correct size, and will also allow for future updates that have the client automatically resize the window (perhaps when receiving a desktop-size pseudoencoding). --- SDL2_vnc.c | 11 +++++++++++ SDL2_vnc.h | 4 ++++ vncc.c | 18 ++++++------------ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/SDL2_vnc.c b/SDL2_vnc.c index 6afedfc..4988aa6 100644 --- a/SDL2_vnc.c +++ b/SDL2_vnc.c @@ -955,3 +955,14 @@ int key_event(SDL_vnc *vnc, bool pressed, SDL_Keysym sym) { to_server(vnc->socket, buf, 8); } + +SDL_Window *create_window_for_connection(SDL_vnc *vnc, char *title, int x, + int y, Uint32 flags) { + + vnc->window = SDL_CreateWindow(title, x, y, vnc->server_details.w, + vnc->server_details.h, flags); + + SDL_ShowCursor(SDL_DISABLE); + + return vnc->window; +} diff --git a/SDL2_vnc.h b/SDL2_vnc.h index c6d4234..df9574a 100644 --- a/SDL2_vnc.h +++ b/SDL2_vnc.h @@ -55,6 +55,7 @@ typedef struct { SDL_Thread *thread; unsigned int fps; vnc_colour_map colour_map; + SDL_Window *window; } SDL_vnc; typedef enum { @@ -74,6 +75,9 @@ SDL_vnc_result init_vnc_connection(SDL_vnc *vnc, char *host, unsigned int port, int wait_on_vnc_connection(SDL_vnc *vnc); +SDL_Window *create_window_for_connection(SDL_vnc *vnc, char *title, int x, + int y, Uint32 flags); + int key_event(SDL_vnc *vnc, bool pressed, SDL_Keysym key); int pointer_event(SDL_vnc *vnc, uint32_t button_mask, uint16_t x, uint16_t y, int32_t mw_x, int32_t mw_y); diff --git a/vncc.c b/vncc.c index c2914cb..98ccc9e 100644 --- a/vncc.c +++ b/vncc.c @@ -6,22 +6,16 @@ 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"); + SDL_Window *wind = create_window_for_connection(&vnc, NULL, + SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 0); + + SDL_Renderer *rend = SDL_CreateRenderer(wind, -1, 0); + bool running = true; while (running) { @@ -62,7 +56,7 @@ int main(int argc, char **argv) { } SDL_Texture *text = SDL_CreateTextureFromSurface(rend, vnc.surface); - SDL_RenderCopy(rend, text, &window_size, NULL); + SDL_RenderCopy(rend, text, NULL, NULL); SDL_DestroyTexture(text); SDL_RenderPresent(rend); -- cgit v1.2.1