1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include <stdio.h>
#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;
}
|