28 static int enableResizable = 1, viewOnly, listenLoop, buttonMask;
36 static int rightAltKeyDown, leftAltKeyDown;
50 SDL_Surface*
sdl=SDL_CreateRGBSurface(0,
56 rfbClientErr(
"resize: error creating surface: %s\n", SDL_GetError());
74 SDL_WINDOWPOS_UNDEFINED,
75 SDL_WINDOWPOS_UNDEFINED,
80 rfbClientErr(
"resize: error creating window: %s\n", SDL_GetError());
89 rfbClientErr(
"resize: error creating renderer: %s\n", SDL_GetError());
90 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY,
"linear");
98 SDL_PIXELFORMAT_ARGB8888,
99 SDL_TEXTUREACCESS_STREAMING,
102 rfbClientErr(
"resize: error creating texture: %s\n", SDL_GetError());
106 static rfbKeySym SDL_key2rfbKeySym(SDL_KeyboardEvent* e) {
108 SDL_Keycode sym = e->keysym.sym;
112 case SDLK_TAB: k =
XK_Tab;
break;
113 case SDLK_CLEAR: k =
XK_Clear;
break;
115 case SDLK_PAUSE: k =
XK_Pause;
break;
118 case SDLK_KP_0: k =
XK_KP_0;
break;
119 case SDLK_KP_1: k =
XK_KP_1;
break;
120 case SDLK_KP_2: k =
XK_KP_2;
break;
121 case SDLK_KP_3: k =
XK_KP_3;
break;
122 case SDLK_KP_4: k =
XK_KP_4;
break;
123 case SDLK_KP_5: k =
XK_KP_5;
break;
124 case SDLK_KP_6: k =
XK_KP_6;
break;
125 case SDLK_KP_7: k =
XK_KP_7;
break;
126 case SDLK_KP_8: k =
XK_KP_8;
break;
127 case SDLK_KP_9: k =
XK_KP_9;
break;
135 case SDLK_UP: k =
XK_Up;
break;
136 case SDLK_DOWN: k =
XK_Down;
break;
137 case SDLK_RIGHT: k =
XK_Right;
break;
138 case SDLK_LEFT: k =
XK_Left;
break;
140 case SDLK_HOME: k =
XK_Home;
break;
141 case SDLK_END: k =
XK_End;
break;
144 case SDLK_F1: k =
XK_F1;
break;
145 case SDLK_F2: k =
XK_F2;
break;
146 case SDLK_F3: k =
XK_F3;
break;
147 case SDLK_F4: k =
XK_F4;
break;
148 case SDLK_F5: k =
XK_F5;
break;
149 case SDLK_F6: k =
XK_F6;
break;
150 case SDLK_F7: k =
XK_F7;
break;
151 case SDLK_F8: k =
XK_F8;
break;
152 case SDLK_F9: k =
XK_F9;
break;
153 case SDLK_F10: k =
XK_F10;
break;
154 case SDLK_F11: k =
XK_F11;
break;
155 case SDLK_F12: k =
XK_F12;
break;
156 case SDLK_F13: k =
XK_F13;
break;
157 case SDLK_F14: k =
XK_F14;
break;
158 case SDLK_F15: k =
XK_F15;
break;
166 case SDLK_RALT: k =
XK_Alt_R;
break;
167 case SDLK_LALT: k =
XK_Alt_L;
break;
171 case SDLK_COMPOSE: k = XK_Compose;
break;
174 case SDLK_HELP: k =
XK_Help;
break;
175 case SDLK_PRINTSCREEN: k =
XK_Print;
break;
180 if (k == 0 && sym > 0x0 && sym < 0x100 && e->keysym.mod & KMOD_CTRL)
187 static rfbKeySym utf8char2rfbKeySym(
const char chr[4]) {
188 int bytes = strlen(chr);
189 int shift =
utf8Mapping[0].bits_stored * (bytes - 1);
192 for(i = 1; i < bytes; ++i, ++chr) {
199 static void update(
rfbClient* cl,
int x,
int y,
int w,
int h) {
202 SDL_Rect r = {
x,
y,w,h};
204 rfbClientErr(
"update: failed to update texture: %s\n", SDL_GetError());
207 rfbClientErr(
"update: failed to clear renderer: %s\n", SDL_GetError());
209 rfbClientErr(
"update: failed to copy texture to renderer: %s\n", SDL_GetError());
213 static void kbd_leds(
rfbClient* cl,
int value,
int pad) {
215 fprintf(stderr,
"Led State= 0x%02X\n", value);
220 static void text_chat(
rfbClient* cl,
int value,
char *text) {
223 fprintf(stderr,
"TextChat: We should open a textchat window!\n");
227 fprintf(stderr,
"TextChat: We should close our window!\n");
230 fprintf(stderr,
"TextChat: We should close our window!\n");
233 fprintf(stderr,
"TextChat: Received \"%s\"\n", text);
246 log_to_file(
const char *format, ...)
249 static char* logfile_str=0;
258 logfile_str=getenv(
"VNCLOG");
260 logfile_str=
"vnc.log";
263 logfile=fopen(logfile_str,
"a");
265 va_start(args, format);
268 strftime(buf, 255,
"%d/%m/%Y %X ", localtime(&log_clock));
269 fprintf(logfile,buf);
271 vfprintf(logfile, format, args);
286 SDL_QuitSubSystem(SDL_INIT_VIDEO);
287 SDL_InitSubSystem(SDL_INIT_VIDEO);
296 case SDL_WINDOWEVENT:
297 switch (e->window.event) {
298 case SDL_WINDOWEVENT_EXPOSED:
302 case SDL_WINDOWEVENT_RESIZED:
305 case SDL_WINDOWEVENT_FOCUS_GAINED:
306 if (SDL_HasClipboardText()) {
307 char *text = SDL_GetClipboardText();
315 case SDL_WINDOWEVENT_FOCUS_LOST:
316 if (rightAltKeyDown) {
318 rightAltKeyDown =
FALSE;
321 if (leftAltKeyDown) {
323 leftAltKeyDown =
FALSE;
336 for(steps = 0; steps < e->wheel.y; ++steps) {
341 for(steps = 0; steps > e->wheel.y; --steps) {
346 for(steps = 0; steps < e->wheel.x; ++steps) {
351 for(steps = 0; steps > e->wheel.x; --steps) {
357 case SDL_MOUSEBUTTONUP:
358 case SDL_MOUSEBUTTONDOWN:
359 case SDL_MOUSEMOTION:
365 if (e->type == SDL_MOUSEMOTION) {
368 state = e->motion.state;
373 state = e->button.button;
377 if (e->type == SDL_MOUSEBUTTONDOWN)
380 buttonMask &= ~state;
394 if (e->key.keysym.sym == SDLK_RALT)
395 rightAltKeyDown = e->type == SDL_KEYDOWN;
396 if (e->key.keysym.sym == SDLK_LALT)
397 leftAltKeyDown = e->type == SDL_KEYDOWN;
402 rfbKeySym sym = utf8char2rfbKeySym(e->text.text);
423 static void got_selection(
rfbClient *cl,
const char *text,
int len)
426 if(SDL_SetClipboardText(text) != 0)
427 rfbClientErr(
"could not set received clipboard text: %s\n", SDL_GetError());
437 rfbClientErr(
"something else than username and password required for authentication\n");
441 rfbClientLog(
"username and password required for authentication!\n");
459 int main(
int argc,
char** argv) {
468 for (i = 1, j = 1; i < argc; i++)
469 if (!strcmp(argv[i],
"-viewonly"))
471 else if (!strcmp(argv[i],
"-resizable"))
473 else if (!strcmp(argv[i],
"-no-resizable"))
475 else if (!strcmp(argv[i],
"-listen")) {
477 argv[i] =
"-listennofork";
487 SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
489 signal(SIGINT, exit);
511 if(SDL_PollEvent(&e)) {
516 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 string on the server's clipboard.
rfbClient * rfbGetClient(int bitsPerSample, int samplesPerPixel, int bytesPerPixel)
Allocates and returns a pointer to an rfbClient structure.
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
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 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
GetCredentialProc GetCredential
To support security types that requires user input (except VNC password authentication),...
HandleKeyboardLedStateProc HandleKeyboardLedState
struct rfbClient::@4 updateRect
MallocFrameBufferProc MallocFrameBuffer
For GetCredentialProc callback function to return.
struct rfbCredential::@3 userCredential
Plain (VeNCrypt), MSLogon (UltraVNC)