291
290
xfp = (xfPeerContext*) client->context;
293
xfp->pipe_fd[0] = -1;
294
xfp->pipe_fd[1] = -1;
296
if (pipe(xfp->pipe_fd) < 0)
297
printf("xf_peer_init: pipe failed\n");
300
294
xfp->activations = 0;
302
xfp->stopwatch = stopwatch_create();
304
xfp->hdc = gdi_GetDC();
306
xfp->hdc->hwnd = (HGDI_WND) malloc(sizeof(GDI_WND));
307
xfp->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0);
308
xfp->hdc->hwnd->invalid->null = 1;
310
xfp->hdc->hwnd->count = 32;
311
xfp->hdc->hwnd->cinvalid = (HGDI_RGN) malloc(sizeof(GDI_RGN) * xfp->hdc->hwnd->count);
312
xfp->hdc->hwnd->ninvalid = 0;
295
xfp->event_queue = xf_event_queue_new();
298
xfp->hdc = gdi_CreateDC(xfi->clrconv, xfi->bpp);
314
300
pthread_mutex_init(&(xfp->mutex), NULL);
321
307
return context->s;
324
int xf_is_event_set(xfPeerContext* xfp)
331
FD_SET(xfp->pipe_fd[0], &rfds);
332
memset(&time, 0, sizeof(time));
333
num_set = select(xfp->pipe_fd[0] + 1, &rfds, 0, 0, &time);
335
return (num_set == 1);
338
void xf_signal_event(xfPeerContext* xfp)
342
length = write(xfp->pipe_fd[1], "sig", 4);
345
printf("xf_signal_event: error\n");
348
void xf_clear_event(xfPeerContext* xfp)
352
while (xf_is_event_set(xfp))
354
length = read(xfp->pipe_fd[0], &length, 4);
357
printf("xf_clear_event: error\n");
361
void* xf_monitor_graphics(void* param)
368
freerdp_peer* client;
369
int x, y, width, height;
370
XDamageNotifyEvent* notify;
372
client = (freerdp_peer*) param;
373
xfp = (xfPeerContext*) client->context;
376
xfp->capture_buffer = (uint8*) xmalloc(xfi->width * xfi->height * xfi->bytesPerPixel);
378
pthread_detach(pthread_self());
380
stopwatch_start(xfp->stopwatch);
384
pthread_mutex_lock(&(xfp->mutex));
386
while (XPending(xfi->display))
388
memset(&xevent, 0, sizeof(xevent));
389
XNextEvent(xfi->display, &xevent);
391
if (xevent.type == xfi->xdamage_notify_event)
393
notify = (XDamageNotifyEvent*) &xevent;
397
width = notify->area.width;
398
height = notify->area.height;
402
region.width = width;
403
region.height = height;
406
XFixesSetRegion(xfi->display, xfi->xdamage_region, ®ion, 1);
407
XDamageSubtract(xfi->display, xfi->xdamage, xfi->xdamage_region, None);
410
gdi_InvalidateRegion(xfp->hdc, x, y, width, height);
412
stopwatch_stop(xfp->stopwatch);
413
stopwatch_get_elapsed_time_in_useconds(xfp->stopwatch, &sec, &usec);
415
if ((sec > 0) || (usec > 30))
420
stopwatch_stop(xfp->stopwatch);
421
stopwatch_get_elapsed_time_in_useconds(xfp->stopwatch, &sec, &usec);
423
if ((sec > 0) || (usec > 30))
427
stopwatch_reset(xfp->stopwatch);
428
stopwatch_start(xfp->stopwatch);
430
region = xfp->hdc->hwnd->invalid;
431
pthread_mutex_unlock(&(xfp->mutex));
433
xf_signal_event(xfp);
437
pthread_mutex_unlock(&(xfp->mutex));
446
310
void xf_peer_live_rfx(freerdp_peer* client)
448
312
xfPeerContext* xfp = (xfPeerContext*) client->context;
450
314
if (xfp->activations == 1)
451
pthread_create(&(xfp->thread), 0, xf_monitor_graphics, (void*) client);
315
pthread_create(&(xfp->thread), 0, xf_monitor_updates, (void*) client);
454
318
static boolean xf_peer_sleep_tsdiff(uint32 *old_sec, uint32 *old_usec, uint32 new_sec, uint32 new_usec)
547
412
s = xf_peer_stream_init(xfp);
549
image = xf_snapshot(xfp, x, y, width, height);
551
414
if (xfi->use_xshm)
555
423
rect.width = width;
556
424
rect.height = height;
558
rfx_compose_message(xfp->rfx_context, s, &rect, 1,
559
(uint8*) image->data, width, height, image->bytes_per_line);
426
image = xf_snapshot(xfp, x, y, width, height);
428
data = (uint8*) image->data;
429
data = &data[(y * image->bytes_per_line) + (x * image->bits_per_pixel)];
431
rfx_compose_message(xfp->rfx_context, s, &rect, 1, data,
432
width, height, image->bytes_per_line);
561
434
cmd->destLeft = x;
562
435
cmd->destTop = y;
570
443
rect.width = width;
571
444
rect.height = height;
573
freerdp_image_convert((uint8*) image->data, xfp->capture_buffer,
574
width, height, 32, 24, xfi->clrconv);
446
image = xf_snapshot(xfp, x, y, width, height);
576
448
rfx_compose_message(xfp->rfx_context, s, &rect, 1,
577
xfp->capture_buffer, width, height, width * xfi->bytesPerPixel);
449
(uint8*) image->data, width, height, width * xfi->bytesPerPixel);
579
451
cmd->destLeft = x;
580
452
cmd->destTop = y;
581
453
cmd->destRight = x + width;
582
454
cmd->destBottom = y + height;
456
XDestroyImage(image);
608
482
boolean xf_peer_check_fds(freerdp_peer* client)
611
486
xfPeerContext* xfp;
487
HGDI_RGN invalid_region;
613
489
xfp = (xfPeerContext*) client->context;
616
if (xfp->pipe_fd[0] == -1)
619
492
if (xfp->activated == false)
622
if (xf_is_event_set(xfp))
495
event = xf_event_peek(xfp->event_queue);
628
region = xfp->hdc->hwnd->invalid;
633
xf_peer_rfx_update(client, region->x, region->y, region->w, region->h);
499
if (event->type == XF_EVENT_TYPE_REGION)
501
xfEventRegion* region = (xfEventRegion*) xf_event_pop(xfp->event_queue);
502
gdi_InvalidateRegion(xfp->hdc, region->x, region->y, region->width, region->height);
503
xf_event_region_free(region);
505
else if (event->type == XF_EVENT_TYPE_FRAME_TICK)
507
event = xf_event_pop(xfp->event_queue);
508
invalid_region = xfp->hdc->hwnd->invalid;
510
if (invalid_region->null == false)
512
xf_peer_rfx_update(client, invalid_region->x, invalid_region->y,
513
invalid_region->w, invalid_region->h);
516
invalid_region->null = 1;
517
xfp->hdc->hwnd->ninvalid = 0;
519
xf_event_free(event);
706
void xf_peer_synchronize_event(rdpInput* input, uint32 flags)
708
printf("Client sent a synchronize event (flags:0x%X)\n", flags);
711
void xf_peer_keyboard_event(rdpInput* input, uint16 flags, uint16 code)
713
unsigned int keycode;
714
boolean extended = false;
715
xfPeerContext* xfp = (xfPeerContext*) input->context;
716
xfInfo* xfi = xfp->info;
718
if (flags & KBD_FLAGS_EXTENDED)
721
keycode = freerdp_kbd_get_keycode_by_scancode(code, extended);
726
pthread_mutex_lock(&(xfp->mutex));
728
if (flags & KBD_FLAGS_DOWN)
729
XTestFakeKeyEvent(xfi->display, keycode, True, 0);
730
else if (flags & KBD_FLAGS_RELEASE)
731
XTestFakeKeyEvent(xfi->display, keycode, False, 0);
733
pthread_mutex_unlock(&(xfp->mutex));
738
void xf_peer_unicode_keyboard_event(rdpInput* input, uint16 code)
740
printf("Client sent a unicode keyboard event (code:0x%X)\n", code);
743
void xf_peer_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
746
boolean down = false;
747
xfPeerContext* xfp = (xfPeerContext*) input->context;
748
xfInfo* xfi = xfp->info;
750
pthread_mutex_lock(&(xfp->mutex));
753
if (flags & PTR_FLAGS_WHEEL)
755
boolean negative = false;
757
if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
760
button = (negative) ? 5 : 4;
762
XTestFakeButtonEvent(xfi->display, button, True, 0);
763
XTestFakeButtonEvent(xfi->display, button, False, 0);
767
if (flags & PTR_FLAGS_MOVE)
768
XTestFakeMotionEvent(xfi->display, 0, x, y, 0);
770
if (flags & PTR_FLAGS_BUTTON1)
772
else if (flags & PTR_FLAGS_BUTTON2)
774
else if (flags & PTR_FLAGS_BUTTON3)
777
if (flags & PTR_FLAGS_DOWN)
781
XTestFakeButtonEvent(xfi->display, button, down, 0);
784
pthread_mutex_unlock(&(xfp->mutex));
787
void xf_peer_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y)
789
xfPeerContext* xfp = (xfPeerContext*) input->context;
790
xfInfo* xfi = xfp->info;
792
pthread_mutex_lock(&(xfp->mutex));
794
XTestFakeMotionEvent(xfi->display, 0, x, y, CurrentTime);
796
pthread_mutex_unlock(&(xfp->mutex));
799
592
void* xf_peer_main_loop(void* arg)
811
606
printf("We've got a client %s\n", client->hostname);
813
608
xf_peer_init(client);
609
settings = client->settings;
815
611
/* Initialize the real server settings here */
816
client->settings->cert_file = xstrdup("server.crt");
817
client->settings->privatekey_file = xstrdup("server.key");
818
client->settings->nla_security = false;
819
client->settings->rfx_codec = true;
613
if (settings->development_mode)
615
server_file_path = freerdp_construct_path(settings->development_path, "server/X11");
619
server_file_path = freerdp_construct_path(settings->config_path, "server");
621
if (!freerdp_check_file_exists(server_file_path))
622
freerdp_mkdir(server_file_path);
625
settings->cert_file = freerdp_construct_path(server_file_path, "server.crt");
626
settings->privatekey_file = freerdp_construct_path(server_file_path, "server.key");
628
settings->nla_security = false;
629
settings->rfx_codec = true;
821
631
client->Capabilities = xf_peer_capabilities;
822
632
client->PostConnect = xf_peer_post_connect;
823
633
client->Activate = xf_peer_activate;
825
client->input->SynchronizeEvent = xf_peer_synchronize_event;
826
client->input->KeyboardEvent = xf_peer_keyboard_event;
827
client->input->UnicodeKeyboardEvent = xf_peer_unicode_keyboard_event;
828
client->input->MouseEvent = xf_peer_mouse_event;
829
client->input->ExtendedMouseEvent = xf_peer_extended_mouse_event;
635
xf_input_register_callbacks(client->input);
831
637
client->Initialize(client);