28static int enableResizable = 1, viewOnly, listenLoop, buttonMask;
36static int rightAltKeyDown, leftAltKeyDown;
47 SDL_Surface*
sdl=SDL_CreateRGBSurface(0,
53 rfbClientErr(
"resize: error creating surface: %s\n", SDL_GetError());
71 SDL_WINDOWPOS_UNDEFINED,
72 SDL_WINDOWPOS_UNDEFINED,
77 rfbClientErr(
"resize: error creating window: %s\n", SDL_GetError());
86 rfbClientErr(
"resize: error creating renderer: %s\n", SDL_GetError());
87 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY,
"linear");
95 SDL_PIXELFORMAT_ARGB8888,
96 SDL_TEXTUREACCESS_STREAMING,
99 rfbClientErr(
"resize: error creating texture: %s\n", SDL_GetError());
103static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) {
105 SDL_Keycode sym = e->keysym.sym;
109 case SDLK_TAB: k =
XK_Tab;
break;
110 case SDLK_CLEAR: k =
XK_Clear;
break;
112 case SDLK_PAUSE: k =
XK_Pause;
break;
115 case SDLK_KP_0: k =
XK_KP_0;
break;
116 case SDLK_KP_1: k =
XK_KP_1;
break;
117 case SDLK_KP_2: k =
XK_KP_2;
break;
118 case SDLK_KP_3: k =
XK_KP_3;
break;
119 case SDLK_KP_4: k =
XK_KP_4;
break;
120 case SDLK_KP_5: k =
XK_KP_5;
break;
121 case SDLK_KP_6: k =
XK_KP_6;
break;
122 case SDLK_KP_7: k =
XK_KP_7;
break;
123 case SDLK_KP_8: k =
XK_KP_8;
break;
124 case SDLK_KP_9: k =
XK_KP_9;
break;
132 case SDLK_UP: k =
XK_Up;
break;
133 case SDLK_DOWN: k =
XK_Down;
break;
134 case SDLK_RIGHT: k =
XK_Right;
break;
135 case SDLK_LEFT: k =
XK_Left;
break;
137 case SDLK_HOME: k =
XK_Home;
break;
138 case SDLK_END: k =
XK_End;
break;
141 case SDLK_F1: k =
XK_F1;
break;
142 case SDLK_F2: k =
XK_F2;
break;
143 case SDLK_F3: k =
XK_F3;
break;
144 case SDLK_F4: k =
XK_F4;
break;
145 case SDLK_F5: k =
XK_F5;
break;
146 case SDLK_F6: k =
XK_F6;
break;
147 case SDLK_F7: k =
XK_F7;
break;
148 case SDLK_F8: k =
XK_F8;
break;
149 case SDLK_F9: k =
XK_F9;
break;
150 case SDLK_F10: k =
XK_F10;
break;
151 case SDLK_F11: k =
XK_F11;
break;
152 case SDLK_F12: k =
XK_F12;
break;
153 case SDLK_F13: k =
XK_F13;
break;
154 case SDLK_F14: k =
XK_F14;
break;
155 case SDLK_F15: k =
XK_F15;
break;
163 case SDLK_RALT: k =
XK_Alt_R;
break;
164 case SDLK_LALT: k =
XK_Alt_L;
break;
168 case SDLK_COMPOSE: k = XK_Compose;
break;
171 case SDLK_HELP: k =
XK_Help;
break;
172 case SDLK_PRINTSCREEN: k =
XK_Print;
break;
177 if (k == 0 && sym > 0x0 && sym < 0x100 && e->keysym.mod & KMOD_CTRL)
184static rfbKeySym utf8char2rfbKeySym(
const char chr[4]) {
185 int bytes = strlen(chr);
186 int shift =
utf8Mapping[0].bits_stored * (bytes - 1);
189 for(i = 1; i < bytes; ++i, ++chr) {
196static void update(
rfbClient* cl,
int x,
int y,
int w,
int h) {
199 SDL_Rect r = {
x,
y,w,h};
201 rfbClientErr(
"update: failed to update texture: %s\n", SDL_GetError());
204 rfbClientErr(
"update: failed to clear renderer: %s\n", SDL_GetError());
206 rfbClientErr(
"update: failed to copy texture to renderer: %s\n", SDL_GetError());
210static void kbd_leds(
rfbClient* cl,
int value,
int pad) {
212 fprintf(stderr,
"Led State= 0x%02X\n", value);
217static void text_chat(
rfbClient* cl,
int value,
char *text) {
220 fprintf(stderr,
"TextChat: We should open a textchat window!\n");
224 fprintf(stderr,
"TextChat: We should close our window!\n");
227 fprintf(stderr,
"TextChat: We should close our window!\n");
230 fprintf(stderr,
"TextChat: Received \"%s\"\n", text);
243log_to_file(
const char *format, ...)
246 static char* logfile_str=0;
255 logfile_str=getenv(
"VNCLOG");
257 logfile_str=
"vnc.log";
260 logfile=fopen(logfile_str,
"a");
262 va_start(args, format);
265 strftime(buf, 255,
"%d/%m/%Y %X ", localtime(&log_clock));
266 fprintf(logfile,buf);
268 vfprintf(logfile, format, args);
283 SDL_QuitSubSystem(SDL_INIT_VIDEO);
284 SDL_InitSubSystem(SDL_INIT_VIDEO);
293 case SDL_WINDOWEVENT:
294 switch (e->window.event) {
295 case SDL_WINDOWEVENT_EXPOSED:
299 case SDL_WINDOWEVENT_RESIZED:
302 case SDL_WINDOWEVENT_FOCUS_GAINED:
303 if (SDL_HasClipboardText()) {
304 char *text = SDL_GetClipboardText();
313 case SDL_WINDOWEVENT_FOCUS_LOST:
314 if (rightAltKeyDown) {
316 rightAltKeyDown =
FALSE;
319 if (leftAltKeyDown) {
321 leftAltKeyDown =
FALSE;
334 for(steps = 0; steps < e->wheel.y; ++steps) {
339 for(steps = 0; steps > e->wheel.y; --steps) {
344 for(steps = 0; steps < e->wheel.x; ++steps) {
349 for(steps = 0; steps > e->wheel.x; --steps) {
355 case SDL_MOUSEBUTTONUP:
356 case SDL_MOUSEBUTTONDOWN:
357 case SDL_MOUSEMOTION:
363 if (e->type == SDL_MOUSEMOTION) {
366 state = e->motion.state;
371 state = e->button.button;
375 if (e->type == SDL_MOUSEBUTTONDOWN)
378 buttonMask &= ~state;
392 if (e->key.keysym.sym == SDLK_RALT)
393 rightAltKeyDown = e->type == SDL_KEYDOWN;
394 if (e->key.keysym.sym == SDLK_LALT)
395 leftAltKeyDown = e->type == SDL_KEYDOWN;
400 rfbKeySym sym = utf8char2rfbKeySym(e->text.text);
421static void got_selection_latin1(
rfbClient *cl,
const char *text,
int len)
423 rfbClientLog(
"received latin1 clipboard text '%s'\n", text);
424 if(SDL_SetClipboardText(text) != 0)
425 rfbClientErr(
"could not set received latin1 clipboard text: %s\n", SDL_GetError());
428static void got_selection_utf8(
rfbClient *cl,
const char *buf,
int len)
430 rfbClientLog(
"received utf8 clipboard text '%s'\n", buf);
431 if(SDL_SetClipboardText(buf) != 0)
432 rfbClientErr(
"could not set received utf8 clipboard text: %s\n", SDL_GetError());
454 rfbClientErr(
"something else than username and password required for authentication\n");
458 rfbClientLog(
"username and password required for authentication!\n");
476int main(
int argc,
char** argv) {
485 for (i = 1, j = 1; i < argc; i++)
486 if (!strcmp(argv[i],
"-viewonly"))
488 else if (!strcmp(argv[i],
"-resizable"))
490 else if (!strcmp(argv[i],
"-no-resizable"))
492 else if (!strcmp(argv[i],
"-listen")) {
494 argv[i] =
"-listennofork";
504 SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
506 signal(SIGINT, exit);
532 if(SDL_PollEvent(&e)) {
537 if(!handleSDLEvent(cl, &e))
int main(int argc, char **argv)
struct @5 buttonMapping[]
SDL_Renderer * sdlRenderer
rfbBool SendClientCutText(rfbClient *client, char *str, int len)
Places a Latin-1-encoded string on the server's clipboard.
int WaitForMessage(rfbClient *client, unsigned int usecs)
Waits for an RFB message to arrive from the server.
rfbBool TextChatOpen(rfbClient *client)
Opens a text chat window on the server.
rfbClientLogProc rfbClientLog
rfbClient * rfbGetClient(int bitsPerSample, int samplesPerPixel, int bytesPerPixel)
Allocates and returns a pointer to an rfbClient structure.
void rfbClientCleanup(rfbClient *client)
Cleans up the client structure and releases the memory allocated for it.
rfbBool SendExtDesktopSize(rfbClient *client, uint16_t width, uint16_t height)
Sends a SetDesktopSize event to the server.
rfbBool HandleRFBServerMessage(rfbClient *client)
Handles messages from the RFB server.
rfbBool SendPointerEvent(rfbClient *client, int x, int y, int buttonMask)
Sends a pointer event to the server.
rfbBool rfbInitClient(rfbClient *client, int *argc, char **argv)
Initializes the client.
rfbBool SendKeyEvent(rfbClient *client, uint32_t key, rfbBool down)
Sends a key event to the server.
rfbBool SendClientCutTextUTF8(rfbClient *client, char *str, int len)
Places a UTF-8-encoded string on the server's clipboard if the server supports it.
rfbBool SendFramebufferUpdateRequest(rfbClient *client, int x, int y, int w, int h, rfbBool incremental)
Sends a framebuffer update request to the server.
#define rfbCredentialTypeUser
#define LISTEN_PORT_OFFSET
void * rfbClientGetClientData(rfbClient *client, void *tag)
Returns a pointer to the client data associated with the given tag.
rfbClientLogProc rfbClientErr
void rfbClientSetClientData(rfbClient *client, void *tag, void *data)
Associates a client data tag with the given pointer.
rfbBool rfbEnableClientLogging
rfbBool SetFormatAndEncodings(rfbClient *client)
Sends format and encoding parameters to the server.
#define rfbTextChatFinished
GotFrameBufferUpdateProc GotFrameBufferUpdate
GotXCutTextProc GotXCutText
HandleTextChatProc HandleTextChat
GotXCutTextUTF8Proc GotXCutTextUTF8
Callback fired when "Extended Clipboard" UTF-8 text data is received.
GetCredentialProc GetCredential
To support security types that requires user input (except VNC password authentication),...
HandleKeyboardLedStateProc HandleKeyboardLedState
MallocFrameBufferProc MallocFrameBuffer
For GetCredentialProc callback function to return.
struct rfbCredential::@3 userCredential
Plain (VeNCrypt), MSLogon (UltraVNC)