25#include <freerdp/config.h>
28#include <winpr/cast.h>
29#include <winpr/assert.h>
30#include <winpr/sspicli.h>
39#include <X11/extensions/Xrender.h>
43#include <X11/extensions/XInput.h>
44#include <X11/extensions/XInput2.h>
48#include <X11/Xcursor/Xcursor.h>
52#include <X11/extensions/Xinerama.h>
55#include <X11/XKBlib.h>
67#include <sys/select.h>
71#include <freerdp/freerdp.h>
72#include <freerdp/constants.h>
73#include <freerdp/codec/nsc.h>
74#include <freerdp/codec/rfx.h>
75#include <freerdp/codec/color.h>
76#include <freerdp/codec/bitmap.h>
78#include <freerdp/utils/signal.h>
79#include <freerdp/utils/passphrase.h>
80#include <freerdp/client/cliprdr.h>
81#include <freerdp/client/channels.h>
83#include <freerdp/client/file.h>
84#include <freerdp/client/cmdline.h>
87#include <winpr/synch.h>
88#include <winpr/file.h>
89#include <winpr/print.h>
90#include <winpr/sysinfo.h>
93#if defined(CHANNEL_TSMF_CLIENT)
98#include "xf_cliprdr.h"
101#include "xf_monitor.h"
102#include "xf_graphics.h"
103#include "xf_keyboard.h"
104#include "xf_channels.h"
105#include "xf_client.h"
109#include <freerdp/log.h>
110#define TAG CLIENT_TAG("x11")
112#define MIN_PIXEL_DIFF 0.001
114struct xf_exit_code_map_t
119static const struct xf_exit_code_map_t xf_exit_code_map[] = {
120 { FREERDP_ERROR_SUCCESS, XF_EXIT_SUCCESS },
121 { FREERDP_ERROR_AUTHENTICATION_FAILED, XF_EXIT_AUTH_FAILURE },
122 { FREERDP_ERROR_SECURITY_NEGO_CONNECT_FAILED, XF_EXIT_NEGO_FAILURE },
123 { FREERDP_ERROR_CONNECT_LOGON_FAILURE, XF_EXIT_LOGON_FAILURE },
124 { FREERDP_ERROR_CONNECT_ACCOUNT_LOCKED_OUT, XF_EXIT_ACCOUNT_LOCKED_OUT },
125 { FREERDP_ERROR_PRE_CONNECT_FAILED, XF_EXIT_PRE_CONNECT_FAILED },
126 { FREERDP_ERROR_CONNECT_UNDEFINED, XF_EXIT_CONNECT_UNDEFINED },
127 { FREERDP_ERROR_POST_CONNECT_FAILED, XF_EXIT_POST_CONNECT_FAILED },
128 { FREERDP_ERROR_DNS_ERROR, XF_EXIT_DNS_ERROR },
129 { FREERDP_ERROR_DNS_NAME_NOT_FOUND, XF_EXIT_DNS_NAME_NOT_FOUND },
130 { FREERDP_ERROR_CONNECT_FAILED, XF_EXIT_CONNECT_FAILED },
131 { FREERDP_ERROR_MCS_CONNECT_INITIAL_ERROR, XF_EXIT_MCS_CONNECT_INITIAL_ERROR },
132 { FREERDP_ERROR_TLS_CONNECT_FAILED, XF_EXIT_TLS_CONNECT_FAILED },
133 { FREERDP_ERROR_INSUFFICIENT_PRIVILEGES, XF_EXIT_INSUFFICIENT_PRIVILEGES },
134 { FREERDP_ERROR_CONNECT_CANCELLED, XF_EXIT_CONNECT_CANCELLED },
135 { FREERDP_ERROR_CONNECT_TRANSPORT_FAILED, XF_EXIT_CONNECT_TRANSPORT_FAILED },
136 { FREERDP_ERROR_CONNECT_PASSWORD_EXPIRED, XF_EXIT_CONNECT_PASSWORD_EXPIRED },
137 { FREERDP_ERROR_CONNECT_PASSWORD_MUST_CHANGE, XF_EXIT_CONNECT_PASSWORD_MUST_CHANGE },
138 { FREERDP_ERROR_CONNECT_KDC_UNREACHABLE, XF_EXIT_CONNECT_KDC_UNREACHABLE },
139 { FREERDP_ERROR_CONNECT_ACCOUNT_DISABLED, XF_EXIT_CONNECT_ACCOUNT_DISABLED },
140 { FREERDP_ERROR_CONNECT_PASSWORD_CERTAINLY_EXPIRED,
141 XF_EXIT_CONNECT_PASSWORD_CERTAINLY_EXPIRED },
142 { FREERDP_ERROR_CONNECT_CLIENT_REVOKED, XF_EXIT_CONNECT_CLIENT_REVOKED },
143 { FREERDP_ERROR_CONNECT_WRONG_PASSWORD, XF_EXIT_CONNECT_WRONG_PASSWORD },
144 { FREERDP_ERROR_CONNECT_ACCESS_DENIED, XF_EXIT_CONNECT_ACCESS_DENIED },
145 { FREERDP_ERROR_CONNECT_ACCOUNT_RESTRICTION, XF_EXIT_CONNECT_ACCOUNT_RESTRICTION },
146 { FREERDP_ERROR_CONNECT_ACCOUNT_EXPIRED, XF_EXIT_CONNECT_ACCOUNT_EXPIRED },
147 { FREERDP_ERROR_CONNECT_LOGON_TYPE_NOT_GRANTED, XF_EXIT_CONNECT_LOGON_TYPE_NOT_GRANTED },
148 { FREERDP_ERROR_CONNECT_NO_OR_MISSING_CREDENTIALS, XF_EXIT_CONNECT_NO_OR_MISSING_CREDENTIALS }
151static BOOL xf_setup_x11(xfContext* xfc);
152static void xf_teardown_x11(xfContext* xfc);
154static int xf_map_error_to_exit_code(DWORD error)
156 for (
size_t x = 0; x < ARRAYSIZE(xf_exit_code_map); x++)
158 const struct xf_exit_code_map_t* cur = &xf_exit_code_map[x];
159 if (cur->error == error)
163 return XF_EXIT_CONN_FAILED;
166static int (*def_error_handler)(Display*, XErrorEvent*);
167static int xf_error_handler_ex(Display* d, XErrorEvent* ev);
168static void xf_check_extensions(xfContext* context);
169static void xf_window_free(xfContext* xfc);
170static BOOL xf_get_pixmap_info(xfContext* xfc);
173static void xf_draw_screen_scaled(xfContext* xfc,
int x,
int y,
int w,
int h)
175 XTransform transform = { 0 };
176 Picture windowPicture = 0;
177 Picture primaryPicture = 0;
178 XRenderPictureAttributes pa;
179 XRenderPictFormat* picFormat = NULL;
182 const char* filter = NULL;
185 rdpSettings* settings = xfc->common.context.settings;
186 WINPR_ASSERT(settings);
188 if (xfc->scaledWidth <= 0 || xfc->scaledHeight <= 0)
190 WLog_ERR(TAG,
"the current window dimensions are invalid");
197 WLog_ERR(TAG,
"the window dimensions are invalid");
201 const double xScalingFactor = 1.0 *
203 (double)xfc->scaledWidth;
204 const double yScalingFactor = 1.0 *
206 (double)xfc->scaledHeight;
207 LogDynAndXSetFillStyle(xfc->log, xfc->display, xfc->gc, FillSolid);
208 LogDynAndXSetForeground(xfc->log, xfc->display, xfc->gc, 0);
211 XRectangle box1 = { 0, 0, WINPR_ASSERTING_INT_CAST(UINT16, xfc->window->width),
212 WINPR_ASSERTING_INT_CAST(UINT16, xfc->window->height) };
213 XRectangle box2 = { WINPR_ASSERTING_INT_CAST(INT16, xfc->offset_x),
214 WINPR_ASSERTING_INT_CAST(INT16, xfc->offset_y),
215 WINPR_ASSERTING_INT_CAST(UINT16, xfc->scaledWidth),
216 WINPR_ASSERTING_INT_CAST(UINT16, xfc->scaledHeight) };
217 Region reg1 = XCreateRegion();
218 Region reg2 = XCreateRegion();
219 XUnionRectWithRegion(&box1, reg1, reg1);
220 XUnionRectWithRegion(&box2, reg2, reg2);
222 if (XSubtractRegion(reg1, reg2, reg1) && !XEmptyRegion(reg1))
224 LogDynAndXSetRegion(xfc->log, xfc->display, xfc->gc, reg1);
225 LogDynAndXFillRectangle(xfc->log, xfc->display, xfc->window->handle, xfc->gc, 0, 0,
226 WINPR_ASSERTING_INT_CAST(UINT16, xfc->window->width),
227 WINPR_ASSERTING_INT_CAST(UINT16, xfc->window->height));
228 LogDynAndXSetClipMask(xfc->log, xfc->display, xfc->gc, None);
231 XDestroyRegion(reg1);
232 XDestroyRegion(reg2);
234 picFormat = XRenderFindVisualFormat(xfc->display, xfc->visual);
235 pa.subwindow_mode = IncludeInferiors;
237 XRenderCreatePicture(xfc->display, xfc->primary, picFormat, CPSubwindowMode, &pa);
239 XRenderCreatePicture(xfc->display, xfc->window->handle, picFormat, CPSubwindowMode, &pa);
242 filter = FilterBilinear;
243 if (fabs(xScalingFactor - yScalingFactor) < MIN_PIXEL_DIFF)
245 const double inverseX = 1.0 / xScalingFactor;
246 const double inverseRoundedX = round(inverseX);
247 const double absInverse = fabs(inverseX - inverseRoundedX);
249 if (absInverse < MIN_PIXEL_DIFF)
250 filter = FilterNearest;
252 XRenderSetPictureFilter(xfc->display, primaryPicture, filter, 0, 0);
253 transform.matrix[0][0] = XDoubleToFixed(xScalingFactor);
254 transform.matrix[0][1] = XDoubleToFixed(0.0);
255 transform.matrix[0][2] = XDoubleToFixed(0.0);
256 transform.matrix[1][0] = XDoubleToFixed(0.0);
257 transform.matrix[1][1] = XDoubleToFixed(yScalingFactor);
258 transform.matrix[1][2] = XDoubleToFixed(0.0);
259 transform.matrix[2][0] = XDoubleToFixed(0.0);
260 transform.matrix[2][1] = XDoubleToFixed(0.0);
261 transform.matrix[2][2] = XDoubleToFixed(1.0);
266 const double dx1 = floor(x / xScalingFactor);
267 const double dy1 = floor(y / yScalingFactor);
268 const double dx2 = ceil(x2 / xScalingFactor);
269 const double dy2 = ceil(y2 / yScalingFactor);
272 w = ((int)dx2) + 1 - x;
273 h = ((int)dy2) + 1 - y;
274 XRenderSetPictureTransform(xfc->display, primaryPicture, &transform);
275 XRenderComposite(xfc->display, PictOpSrc, primaryPicture, 0, windowPicture, x, y, 0, 0,
276 xfc->offset_x + x, xfc->offset_y + y, WINPR_ASSERTING_INT_CAST(uint32_t, w),
277 WINPR_ASSERTING_INT_CAST(uint32_t, h));
278 XRenderFreePicture(xfc->display, primaryPicture);
279 XRenderFreePicture(xfc->display, windowPicture);
282BOOL xf_picture_transform_required(xfContext* xfc)
284 rdpSettings* settings = NULL;
288 settings = xfc->common.context.settings;
289 WINPR_ASSERT(settings);
291 if ((xfc->offset_x != 0) || (xfc->offset_y != 0) ||
302void xf_draw_screen_(xfContext* xfc,
int x,
int y,
int w,
int h,
const char* fkt,
303 WINPR_ATTR_UNUSED
const char* file, WINPR_ATTR_UNUSED
int line)
307 WLog_DBG(TAG,
"called from [%s] xfc=%p", fkt, xfc);
311 if (w == 0 || h == 0)
313 WLog_WARN(TAG,
"invalid width and/or height specified: w=%d h=%d", w, h);
319 WLog_WARN(TAG,
"invalid xfc->window=%p", xfc->window);
325 if (xf_picture_transform_required(xfc))
327 xf_draw_screen_scaled(xfc, x, y, w, h);
332 LogDynAndXCopyArea(xfc->log, xfc->display, xfc->primary, xfc->window->handle, xfc->gc, x, y,
333 WINPR_ASSERTING_INT_CAST(uint32_t, w), WINPR_ASSERTING_INT_CAST(uint32_t, h),
337static BOOL xf_desktop_resize(rdpContext* context)
339 xfContext* xfc = (xfContext*)context;
343 rdpSettings* settings = context->settings;
344 WINPR_ASSERT(settings);
348 BOOL same = (xfc->primary == xfc->drawing) ? TRUE : FALSE;
349 LogDynAndXFreePixmap(xfc->log, xfc->display, xfc->primary);
351 WINPR_ASSERT(xfc->depth != 0);
352 if (!(xfc->primary = LogDynAndXCreatePixmap(
353 xfc->log, xfc->display, xfc->drawable,
356 WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth))))
360 xfc->drawing = xfc->primary;
367 xfc->scaledWidth = WINPR_ASSERTING_INT_CAST(
369 xfc->scaledHeight = WINPR_ASSERTING_INT_CAST(
375 if (!xfc->fullscreen)
377 xf_ResizeDesktopWindow(
379 WINPR_ASSERTING_INT_CAST(
int,
381 WINPR_ASSERTING_INT_CAST(
int,
393 xfc->savedWidth = WINPR_ASSERTING_INT_CAST(
395 xfc->savedHeight = WINPR_ASSERTING_INT_CAST(
399 LogDynAndXSetFunction(xfc->log, xfc->display, xfc->gc, GXcopy);
400 LogDynAndXSetFillStyle(xfc->log, xfc->display, xfc->gc, FillSolid);
401 LogDynAndXSetForeground(xfc->log, xfc->display, xfc->gc, 0);
402 LogDynAndXFillRectangle(xfc->log, xfc->display, xfc->drawable, xfc->gc, 0, 0,
410static BOOL xf_paint(xfContext* xfc,
const GDI_RGN* region)
413 WINPR_ASSERT(region);
417 const RECTANGLE_16 rect = { .left = WINPR_ASSERTING_INT_CAST(UINT16, region->x),
418 .top = WINPR_ASSERTING_INT_CAST(UINT16, region->y),
420 WINPR_ASSERTING_INT_CAST(UINT16, region->x + region->w),
422 WINPR_ASSERTING_INT_CAST(UINT16, region->y + region->h) };
423 xf_rail_paint(xfc, &rect);
427 LogDynAndXPutImage(xfc->log, xfc->display, xfc->primary, xfc->gc, xfc->image, region->x,
428 region->y, region->x, region->y,
429 WINPR_ASSERTING_INT_CAST(UINT16, region->w),
430 WINPR_ASSERTING_INT_CAST(UINT16, region->h));
431 xf_draw_screen(xfc, region->x, region->y, region->w, region->h);
436static BOOL xf_end_paint(rdpContext* context)
438 xfContext* xfc = (xfContext*)context;
441 rdpGdi* gdi = context->gdi;
444 if (gdi->suppressOutput)
447 HGDI_DC hdc = gdi->primary->hdc;
452 if (!xfc->complex_regions)
454 const GDI_RGN* rgn = hwnd->invalid;
458 if (!xf_paint(xfc, rgn))
464 const INT32 ninvalid = hwnd->ninvalid;
465 const GDI_RGN* cinvalid = hwnd->cinvalid;
467 if (hwnd->ninvalid < 1)
472 for (INT32 i = 0; i < ninvalid; i++)
474 const GDI_RGN* rgn = &cinvalid[i];
475 if (!xf_paint(xfc, rgn))
479 LogDynAndXFlush(xfc->log, xfc->display);
483 hwnd->invalid->null = TRUE;
488static BOOL xf_sw_desktop_resize(rdpContext* context)
490 WINPR_ASSERT(context);
492 rdpGdi* gdi = context->gdi;
495 xfContext* xfc = (xfContext*)context;
496 rdpSettings* settings = context->settings;
497 WINPR_ASSERT(settings);
504 const BOOL suppress = gdi->suppressOutput;
505 gdi->suppressOutput = TRUE;
514 xfc->image->data = NULL;
515 XDestroyImage(xfc->image);
518 WINPR_ASSERT(xfc->depth != 0);
519 if (!(xfc->image = LogDynAndXCreateImage(
520 xfc->log, xfc->display, xfc->visual, WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth),
521 ZPixmap, 0, (
char*)gdi->primary_buffer,
522 WINPR_ASSERTING_INT_CAST(uint32_t, gdi->width),
523 WINPR_ASSERTING_INT_CAST(uint32_t, gdi->height), xfc->scanline_pad,
524 WINPR_ASSERTING_INT_CAST(
int, gdi->stride))))
529 xfc->image->byte_order = LSBFirst;
530 xfc->image->bitmap_bit_order = LSBFirst;
531 ret = xf_desktop_resize(context);
534 gdi->suppressOutput = suppress;
538static BOOL xf_process_x_events(freerdp* instance)
541 int pending_status = 1;
542 xfContext* xfc = (xfContext*)instance->context;
544 while (pending_status)
547 pending_status = XPending(xfc->display);
551 XEvent xevent = { 0 };
553 XNextEvent(xfc->display, &xevent);
554 status = xf_event_process(instance, &xevent);
564static char* xf_window_get_title(rdpSettings* settings)
567 char* windowTitle = NULL;
569 const char* prefix =
"FreeRDP:";
578 return _strdup(title);
582 size = strnlen(name, MAX_PATH) + 16;
583 windowTitle = calloc(size,
sizeof(
char));
589 (void)sprintf_s(windowTitle, size,
"%s %s", prefix, name);
591 (
void)sprintf_s(windowTitle, size,
"%s %s:%" PRIu32, prefix, name,
597BOOL xf_create_window(xfContext* xfc)
599 XGCValues gcv = { 0 };
600 XEvent xevent = { 0 };
601 char* windowTitle = NULL;
604 rdpSettings* settings = xfc->common.context.settings;
605 WINPR_ASSERT(settings);
612 const XSetWindowAttributes empty = { 0 };
613 xfc->attribs = empty;
618 xfc->depth = DefaultDepthOfScreen(xfc->screen);
620 XVisualInfo vinfo = { 0 };
621 if (XMatchVisualInfo(xfc->display, xfc->screen_number, xfc->depth, TrueColor, &vinfo))
623 Window root = XDefaultRootWindow(xfc->display);
624 xfc->visual = vinfo.visual;
625 xfc->attribs.colormap = xfc->colormap =
626 XCreateColormap(xfc->display, root, vinfo.visual, AllocNone);
632 WLog_WARN(TAG,
"running in remote app mode, but XServer does not support transparency");
633 WLog_WARN(TAG,
"display of remote applications might be distorted (black frames, ...)");
635 xfc->depth = DefaultDepthOfScreen(xfc->screen);
636 xfc->visual = DefaultVisual(xfc->display, xfc->screen_number);
637 xfc->attribs.colormap = xfc->colormap = DefaultColormap(xfc->display, xfc->screen_number);
644 if (vinfo.red_mask & 0xFF)
649 if (!xfc->remote_app)
651 xfc->attribs.background_pixel = BlackPixelOfScreen(xfc->screen);
652 xfc->attribs.border_pixel = WhitePixelOfScreen(xfc->screen);
653 xfc->attribs.backing_store = xfc->primary ? NotUseful : Always;
654 xfc->attribs.override_redirect = False;
656 xfc->attribs.bit_gravity = NorthWestGravity;
657 xfc->attribs.win_gravity = NorthWestGravity;
658 xfc->attribs_mask = CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap |
659 CWBorderPixel | CWWinGravity | CWBitGravity;
665 windowTitle = xf_window_get_title(settings);
675 width = WINPR_ASSERTING_INT_CAST(
679 height = WINPR_ASSERTING_INT_CAST(
682 xfc->scaledWidth = width;
683 xfc->scaledHeight = height;
687 xfc->window = xf_CreateDesktopWindow(xfc, windowTitle, width, height);
691 xf_SetWindowFullscreen(xfc, xfc->window, xfc->fullscreen);
693 xfc->unobscured = (xevent.xvisibility.state == VisibilityUnobscured);
694 XSetWMProtocols(xfc->display, xfc->window->handle, &(xfc->WM_DELETE_WINDOW), 1);
695 xfc->drawable = xfc->window->handle;
699 xfc->attribs.border_pixel = 0;
700 xfc->attribs.background_pixel = 0;
701 xfc->attribs.backing_store = xfc->primary ? NotUseful : Always;
702 xfc->attribs.override_redirect = False;
704 xfc->attribs.bit_gravity = NorthWestGravity;
705 xfc->attribs.win_gravity = NorthWestGravity;
706 xfc->attribs_mask = CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap |
707 CWBorderPixel | CWWinGravity | CWBitGravity;
709 xfc->drawable = xf_CreateDummyWindow(xfc);
714 LogDynAndXCreateGC(xfc->log, xfc->display, xfc->drawable, GCGraphicsExposures, &gcv);
716 WINPR_ASSERT(xfc->depth != 0);
719 LogDynAndXCreatePixmap(xfc->log, xfc->display, xfc->drawable,
722 WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth));
724 xfc->drawing = xfc->primary;
726 if (!xfc->bitmap_mono)
727 xfc->bitmap_mono = LogDynAndXCreatePixmap(xfc->log, xfc->display, xfc->drawable, 8, 8, 1);
731 LogDynAndXCreateGC(xfc->log, xfc->display, xfc->bitmap_mono, GCGraphicsExposures, &gcv);
733 LogDynAndXSetFunction(xfc->log, xfc->display, xfc->gc, GXcopy);
734 LogDynAndXSetFillStyle(xfc->log, xfc->display, xfc->gc, FillSolid);
735 LogDynAndXSetForeground(xfc->log, xfc->display, xfc->gc, BlackPixelOfScreen(xfc->screen));
736 LogDynAndXFillRectangle(xfc->log, xfc->display, xfc->primary, xfc->gc, 0, 0,
739 LogDynAndXFlush(xfc->log, xfc->display);
744BOOL xf_create_image(xfContext* xfc)
749 const rdpSettings* settings = xfc->common.context.settings;
750 rdpGdi* cgdi = xfc->common.context.gdi;
753 WINPR_ASSERT(xfc->depth != 0);
754 xfc->image = LogDynAndXCreateImage(
755 xfc->log, xfc->display, xfc->visual, WINPR_ASSERTING_INT_CAST(uint32_t, xfc->depth),
756 ZPixmap, 0, (
char*)cgdi->primary_buffer,
759 WINPR_ASSERTING_INT_CAST(
int, cgdi->stride));
760 xfc->image->byte_order = LSBFirst;
761 xfc->image->bitmap_bit_order = LSBFirst;
766static void xf_window_free(xfContext* xfc)
770 xf_DestroyDesktopWindow(xfc, xfc->window);
774#if defined(CHANNEL_TSMF_CLIENT)
777 xf_tsmf_uninit(xfc, NULL);
778 xfc->xv_context = NULL;
784 xfc->image->data = NULL;
785 XDestroyImage(xfc->image);
789 if (xfc->bitmap_mono)
791 LogDynAndXFreePixmap(xfc->log, xfc->display, xfc->bitmap_mono);
792 xfc->bitmap_mono = 0;
797 LogDynAndXFreeGC(xfc->log, xfc->display, xfc->gc_mono);
803 LogDynAndXFreePixmap(xfc->log, xfc->display, xfc->primary);
809 LogDynAndXFreeGC(xfc->log, xfc->display, xfc->gc);
814void xf_toggle_fullscreen(xfContext* xfc)
816 WindowStateChangeEventArgs e = { 0 };
817 rdpContext* context = (rdpContext*)xfc;
818 rdpSettings* settings = context->settings;
827 xfc->fullscreen = (xfc->fullscreen) ? FALSE : TRUE;
830 xf_SetWindowFullscreen(xfc, xfc->window, xfc->fullscreen);
831 EventArgsInit(&e,
"xfreerdp");
832 e.state = xfc->fullscreen ? FREERDP_WINDOW_STATE_FULLSCREEN : 0;
833 PubSub_OnWindowStateChange(context->pubSub, context, &e);
836void xf_minimize(xfContext* xfc)
838 WindowStateChangeEventArgs e = { 0 };
839 rdpContext* context = (rdpContext*)xfc;
840 WINPR_ASSERT(context);
849 xf_SetWindowMinimized(xfc, xfc->window);
851 e.state = xfc->fullscreen ? FREERDP_WINDOW_STATE_FULLSCREEN : 0;
852 PubSub_OnWindowStateChange(context->pubSub, context, &e);
855void xf_lock_x11_(xfContext* xfc, WINPR_ATTR_UNUSED
const char* fkt)
857 if (!xfc->UseXThreads)
858 (void)WaitForSingleObject(xfc->mutex, INFINITE);
860 XLockDisplay(xfc->display);
865void xf_unlock_x11_(xfContext* xfc, WINPR_ATTR_UNUSED
const char* fkt)
867 if (xfc->locked == 0)
868 WLog_WARN(TAG,
"X11: trying to unlock although not locked!");
872 if (!xfc->UseXThreads)
873 (void)ReleaseMutex(xfc->mutex);
875 XUnlockDisplay(xfc->display);
878static BOOL xf_get_pixmap_info(xfContext* xfc)
881 XPixmapFormatValues* pfs = NULL;
883 WINPR_ASSERT(xfc->display);
884 pfs = XListPixmapFormats(xfc->display, &pf_count);
888 WLog_ERR(TAG,
"XListPixmapFormats failed");
892 WINPR_ASSERT(xfc->depth != 0);
893 for (
int i = 0; i < pf_count; i++)
895 const XPixmapFormatValues* pf = &pfs[i];
897 if (pf->depth == xfc->depth)
899 xfc->scanline_pad = pf->scanline_pad;
905 if ((xfc->visual == NULL) || (xfc->scanline_pad == 0))
911static int xf_error_handler(Display* d, XErrorEvent* ev)
913 char buf[256] = { 0 };
914 XGetErrorText(d, ev->error_code, buf,
sizeof(buf));
915 WLog_ERR(TAG,
"%s", buf);
916 winpr_log_backtrace(TAG, WLOG_ERROR, 20);
918 if (def_error_handler)
919 return def_error_handler(d, ev);
924static int xf_error_handler_ex(Display* d, XErrorEvent* ev)
932 XUngrabKeyboard(d, CurrentTime);
933 XUngrabPointer(d, CurrentTime);
934 return xf_error_handler(d, ev);
937static BOOL xf_play_sound(rdpContext* context,
const PLAY_SOUND_UPDATE* play_sound)
939 xfContext* xfc = (xfContext*)context;
940 WINPR_UNUSED(play_sound);
941 XkbBell(xfc->display, None, 100, 0);
945static void xf_check_extensions(xfContext* context)
950 int xkb_major = XkbMajorVersion;
951 int xkb_minor = XkbMinorVersion;
953 if (XkbLibraryVersion(&xkb_major, &xkb_minor) &&
954 XkbQueryExtension(context->display, &xkb_opcode, &xkb_event, &xkb_error, &xkb_major,
957 context->xkbAvailable = TRUE;
962 int xrender_event_base = 0;
963 int xrender_error_base = 0;
965 if (XRenderQueryExtension(context->display, &xrender_event_base, &xrender_error_base))
967 context->xrenderAvailable = TRUE;
976static const char TEST_PTR_STR[] =
"Virtual core XTEST pointer";
977static const size_t TEST_PTR_LEN =
sizeof(TEST_PTR_STR) /
sizeof(
char);
980static void xf_get_x11_button_map(xfContext* xfc,
unsigned char* x11_map)
986 XDevice* ptr_dev = NULL;
987 XExtensionVersion* version = NULL;
988 XDeviceInfo* devices1 = NULL;
989 XIDeviceInfo* devices2 = NULL;
992 if (XQueryExtension(xfc->display,
"XInputExtension", &opcode, &event, &error))
994 WLog_DBG(TAG,
"Searching for XInput pointer device");
997 version = XGetExtensionVersion(xfc->display, INAME);
999 if (version->major_version >= 2)
1002 devices2 = XIQueryDevice(xfc->display, XIAllDevices, &num_devices);
1006 for (
int i = 0; i < num_devices; ++i)
1008 XIDeviceInfo* dev = &devices2[i];
1009 if ((dev->use == XISlavePointer) &&
1010 (strncmp(dev->name, TEST_PTR_STR, TEST_PTR_LEN) != 0))
1012 ptr_dev = XOpenDevice(xfc->display,
1013 WINPR_ASSERTING_INT_CAST(uint32_t, dev->deviceid));
1019 XIFreeDeviceInfo(devices2);
1025 devices1 = XListInputDevices(xfc->display, &num_devices);
1029 for (
int i = 0; i < num_devices; ++i)
1031 if ((devices1[i].use == IsXExtensionPointer) &&
1032 (strncmp(devices1[i].name, TEST_PTR_STR, TEST_PTR_LEN) != 0))
1034 ptr_dev = XOpenDevice(xfc->display, devices1[i].id);
1040 XFreeDeviceList(devices1);
1050 WLog_DBG(TAG,
"Pointer device: %d", ptr_dev->device_id);
1051 XGetDeviceButtonMapping(xfc->display, ptr_dev, x11_map, NUM_BUTTONS_MAPPED);
1052 XCloseDevice(xfc->display, ptr_dev);
1056 WLog_DBG(TAG,
"No pointer device found!");
1062 WLog_DBG(TAG,
"Get global pointer mapping (no XInput)");
1063 XGetPointerMapping(xfc->display, x11_map, NUM_BUTTONS_MAPPED);
1069static const button_map xf_button_flags[NUM_BUTTONS_MAPPED] = {
1070 { Button1, PTR_FLAGS_BUTTON1 },
1071 { Button2, PTR_FLAGS_BUTTON3 },
1072 { Button3, PTR_FLAGS_BUTTON2 },
1073 { Button4, PTR_FLAGS_WHEEL | 0x78 },
1075 { Button5, PTR_FLAGS_WHEEL | PTR_FLAGS_WHEEL_NEGATIVE | (0x100 - 0x78) },
1076 { 6, PTR_FLAGS_HWHEEL | PTR_FLAGS_WHEEL_NEGATIVE | (0x100 - 0x78) },
1077 { 7, PTR_FLAGS_HWHEEL | 0x78 },
1078 { 8, PTR_XFLAGS_BUTTON1 },
1079 { 9, PTR_XFLAGS_BUTTON2 },
1080 { 97, PTR_XFLAGS_BUTTON1 },
1081 { 112, PTR_XFLAGS_BUTTON2 }
1084static UINT16 get_flags_for_button(
size_t button)
1086 for (
size_t x = 0; x < ARRAYSIZE(xf_button_flags); x++)
1090 if (map->button == button)
1097void xf_button_map_init(xfContext* xfc)
1104 unsigned char x11_map[112] = { 0 };
1107 WINPR_ASSERT(xfc->common.context.settings);
1109 x11_map[0] = Button1;
1110 x11_map[1] = Button2;
1111 x11_map[2] = Button3;
1112 x11_map[3] = Button4;
1113 x11_map[4] = Button5;
1124 xf_get_x11_button_map(xfc, x11_map);
1130 for (
size_t physical = 0; physical < ARRAYSIZE(x11_map); ++physical)
1132 const unsigned char logical = x11_map[physical];
1133 const UINT16 flags = get_flags_for_button(logical);
1135 if ((logical != 0) && (flags != 0))
1137 if (pos >= NUM_BUTTONS_MAPPED)
1139 WLog_ERR(TAG,
"Failed to map mouse button to RDP button, no space");
1144 map->button = logical;
1145 map->flags = get_flags_for_button(physical + Button1);
1162static BOOL xf_pre_connect(freerdp* instance)
1164 UINT32 maxWidth = 0;
1165 UINT32 maxHeight = 0;
1167 WINPR_ASSERT(instance);
1169 rdpContext* context = instance->context;
1170 WINPR_ASSERT(context);
1171 xfContext* xfc = (xfContext*)context;
1173 rdpSettings* settings = context->settings;
1174 WINPR_ASSERT(settings);
1181 if (!xf_setup_x11(xfc))
1189 PubSub_SubscribeChannelConnected(context->pubSub, xf_OnChannelConnectedEventHandler);
1190 PubSub_SubscribeChannelDisconnected(context->pubSub, xf_OnChannelDisconnectedEventHandler);
1196 char login_name[MAX_PATH] = { 0 };
1197 ULONG size =
sizeof(login_name) - 1;
1199 if (GetUserNameExA(NameSamCompatible, login_name, &size))
1204 WLog_INFO(TAG,
"No user name set. - Using login name: %s",
1214 WLog_INFO(TAG,
"auth-only, but no password set. Please provide one.");
1218 WLog_INFO(TAG,
"Authentication only. Don't connect to X.");
1224 xfc->common.context.settings, FreeRDP_KeyboardRemappingList);
1226 xfc->remap_table = freerdp_keyboard_remap_string_to_list(KeyboardRemappingList);
1227 if (!xfc->remap_table)
1229 if (!xf_keyboard_init(xfc))
1231 if (!xf_keyboard_action_script_init(xfc))
1233 if (!xf_detect_monitors(xfc, &maxWidth, &maxHeight))
1257 settings, FreeRDP_DesktopWidth,
1261 settings, FreeRDP_DesktopHeight,
1272 xf_button_map_init(xfc);
1276static BOOL xf_inject_keypress(rdpContext* context,
const char* buffer,
size_t size)
1278 WCHAR wbuffer[64] = { 0 };
1279 const SSIZE_T len = ConvertUtf8NToWChar(buffer, size, wbuffer, ARRAYSIZE(wbuffer));
1283 rdpInput* input = context->input;
1284 WINPR_ASSERT(input);
1286 for (SSIZE_T x = 0; x < len; x++)
1288 const WCHAR code = wbuffer[x];
1289 freerdp_input_send_unicode_keyboard_event(input, 0, code);
1291 freerdp_input_send_unicode_keyboard_event(input, KBD_FLAGS_RELEASE, code);
1297static BOOL xf_process_pipe(rdpContext* context,
const char* pipe)
1299 int fd = open(pipe, O_NONBLOCK | O_RDONLY);
1302 char ebuffer[256] = { 0 };
1303 WLog_ERR(TAG,
"pipe '%s' open returned %s [%d]", pipe,
1304 winpr_strerror(errno, ebuffer,
sizeof(ebuffer)), errno);
1307 while (!freerdp_shall_disconnect_context(context))
1309 char buffer[64] = { 0 };
1310 ssize_t rd = read(fd, buffer,
sizeof(buffer) - 1);
1313 char ebuffer[256] = { 0 };
1314 if ((errno == EAGAIN) || (errno == 0))
1321 WLog_ERR(TAG,
"pipe '%s' read returned %s [%d]", pipe,
1322 winpr_strerror(errno, ebuffer,
sizeof(ebuffer)), errno);
1327 char ebuffer[256] = { 0 };
1328 WLog_ERR(TAG,
"pipe '%s' read returned %s [%d]", pipe,
1329 winpr_strerror(errno, ebuffer,
sizeof(ebuffer)), errno);
1334 if (!xf_inject_keypress(context, buffer, WINPR_ASSERTING_INT_CAST(
size_t, rd)))
1342static void cleanup_pipe(WINPR_ATTR_UNUSED
int signum, WINPR_ATTR_UNUSED
const char* signame,
1345 const char* pipe = context;
1351static DWORD WINAPI xf_handle_pipe(
void* arg)
1353 xfContext* xfc = arg;
1356 rdpContext* context = &xfc->common.context;
1357 WINPR_ASSERT(context);
1359 rdpSettings* settings = context->settings;
1360 WINPR_ASSERT(settings);
1365 const int rc = mkfifo(pipe, S_IWUSR | S_IRUSR);
1368 char ebuffer[256] = { 0 };
1369 WLog_ERR(TAG,
"Failed to create named pipe '%s': %s [%d]", pipe,
1370 winpr_strerror(errno, ebuffer,
sizeof(ebuffer)), errno);
1374 void* ctx = WINPR_CAST_CONST_PTR_AWAY(pipe,
void*);
1375 freerdp_add_signal_cleanup_handler(ctx, cleanup_pipe);
1377 xf_process_pipe(context, pipe);
1379 freerdp_del_signal_cleanup_handler(ctx, cleanup_pipe);
1390static BOOL xf_post_connect(freerdp* instance)
1392 ResizeWindowEventArgs e = { 0 };
1394 WINPR_ASSERT(instance);
1395 xfContext* xfc = (xfContext*)instance->context;
1396 rdpContext* context = instance->context;
1397 WINPR_ASSERT(context);
1399 rdpSettings* settings = context->settings;
1400 WINPR_ASSERT(settings);
1402 rdpUpdate* update = context->update;
1403 WINPR_ASSERT(update);
1406 xfc->remote_app = TRUE;
1408 if (!xf_create_window(xfc))
1411 if (!xf_get_pixmap_info(xfc))
1414 if (!gdi_init(instance, xf_get_local_color_format(xfc, TRUE)))
1417 if (!xf_create_image(xfc))
1420 if (!xf_register_pointer(context->graphics))
1432 if (!xfc->xrenderAvailable)
1436 WLog_ERR(TAG,
"XRender not available: disabling smart-sizing");
1443 WLog_ERR(TAG,
"XRender not available: disabling local multi-touch gestures");
1449 update->DesktopResize = xf_sw_desktop_resize;
1450 update->EndPaint = xf_end_paint;
1451 update->PlaySound = xf_play_sound;
1452 update->SetKeyboardIndicators = xf_keyboard_set_indicators;
1453 update->SetKeyboardImeStatus = xf_keyboard_set_ime_status;
1455 const BOOL serverIsWindowsPlatform =
1458 !(xfc->clipboard = xf_clipboard_new(xfc, !serverIsWindowsPlatform)))
1461 if (!(xfc->xfDisp = xf_disp_new(xfc)))
1467 xfc->pipethread = CreateThread(NULL, 0, xf_handle_pipe, xfc, 0, NULL);
1468 if (!xfc->pipethread)
1472 EventArgsInit(&e,
"xfreerdp");
1477 PubSub_OnResizeWindow(context->pubSub, xfc, &e);
1481static void xf_post_disconnect(freerdp* instance)
1483 xfContext* xfc = NULL;
1484 rdpContext* context = NULL;
1486 if (!instance || !instance->context)
1489 context = instance->context;
1490 xfc = (xfContext*)context;
1491 PubSub_UnsubscribeChannelConnected(instance->context->pubSub,
1492 xf_OnChannelConnectedEventHandler);
1493 PubSub_UnsubscribeChannelDisconnected(instance->context->pubSub,
1494 xf_OnChannelDisconnectedEventHandler);
1497 if (xfc->pipethread)
1499 (void)WaitForSingleObject(xfc->pipethread, INFINITE);
1500 (void)CloseHandle(xfc->pipethread);
1501 xfc->pipethread = NULL;
1505 xf_clipboard_free(xfc->clipboard);
1506 xfc->clipboard = NULL;
1511 xf_disp_free(xfc->xfDisp);
1515 if ((xfc->window != NULL) && (xfc->drawable == xfc->window->handle))
1518 xf_DestroyDummyWindow(xfc, xfc->drawable);
1520 freerdp_keyboard_remap_free(xfc->remap_table);
1521 xfc->remap_table = NULL;
1523 xf_window_free(xfc);
1526static void xf_post_final_disconnect(freerdp* instance)
1528 xfContext* xfc = NULL;
1529 rdpContext* context = NULL;
1531 if (!instance || !instance->context)
1534 context = instance->context;
1535 xfc = (xfContext*)context;
1537 xf_keyboard_free(xfc);
1538 xf_teardown_x11(xfc);
1541static int xf_logon_error_info(freerdp* instance, UINT32 data, UINT32 type)
1543 xfContext* xfc = (xfContext*)instance->context;
1544 const char* str_data = freerdp_get_logon_error_info_data(data);
1545 const char* str_type = freerdp_get_logon_error_info_type(type);
1546 WLog_INFO(TAG,
"Logon Error Info %s [%s]", str_data, str_type);
1547 if (type != LOGON_MSG_SESSION_CONTINUE)
1549 xf_rail_disable_remoteapp_mode(xfc);
1554static BOOL handle_window_events(freerdp* instance)
1556 if (!xf_process_x_events(instance))
1558 WLog_DBG(TAG,
"Closed from X11");
1573static DWORD WINAPI xf_client_thread(LPVOID param)
1575 DWORD exit_code = 0;
1576 DWORD waitStatus = 0;
1577 HANDLE inputEvent = NULL;
1579 freerdp* instance = (freerdp*)param;
1580 WINPR_ASSERT(instance);
1582 const BOOL status = freerdp_connect(instance);
1583 rdpContext* context = instance->context;
1584 WINPR_ASSERT(context);
1585 xfContext* xfc = (xfContext*)instance->context;
1588 rdpSettings* settings = context->settings;
1589 WINPR_ASSERT(settings);
1593 UINT32 error = freerdp_get_last_error(instance->context);
1594 exit_code = (uint32_t)xf_map_error_to_exit_code(error);
1597 exit_code = XF_EXIT_SUCCESS;
1605 WLog_ERR(TAG,
"Authentication only, exit status %" PRId32
"", !status);
1611 WLog_ERR(TAG,
"Freerdp connect error exit status %" PRId32
"", !status);
1612 exit_code = freerdp_error_info(instance);
1614 if (freerdp_get_last_error(instance->context) == FREERDP_ERROR_AUTHENTICATION_FAILED)
1615 exit_code = XF_EXIT_AUTH_FAILURE;
1616 else if (exit_code == ERRINFO_SUCCESS)
1617 exit_code = XF_EXIT_CONN_FAILED;
1622 inputEvent = xfc->x11event;
1624 while (!freerdp_shall_disconnect_context(instance->context))
1626 HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
1628 handles[nCount++] = inputEvent;
1635 if (freerdp_focus_required(instance))
1637 xf_keyboard_focus_in(xfc);
1638 xf_keyboard_focus_in(xfc);
1643 freerdp_get_event_handles(context, &handles[nCount], ARRAYSIZE(handles) - nCount);
1647 WLog_ERR(TAG,
"freerdp_get_event_handles failed");
1655 xf_floatbar_hide_and_show(xfc->window->floatbar);
1657 waitStatus = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
1659 if (waitStatus == WAIT_FAILED)
1663 if (!freerdp_check_event_handles(context))
1665 if (client_auto_reconnect_ex(instance, handle_window_events))
1673 const UINT32 error = freerdp_get_last_error(instance->context);
1675 if (freerdp_error_info(instance) == 0)
1676 exit_code = (uint32_t)xf_map_error_to_exit_code(error);
1679 if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
1680 WLog_ERR(TAG,
"Failed to check FreeRDP file descriptor");
1686 if (!handle_window_events(instance))
1692 exit_code = freerdp_error_info(instance);
1694 if (exit_code == XF_EXIT_DISCONNECT &&
1695 freerdp_get_disconnect_ultimatum(context) == Disconnect_Ultimatum_user_requested)
1698 WLog_INFO(TAG,
"Error info says user did not initiate but disconnect ultimatum says "
1699 "they did; treat this as a user logoff");
1700 exit_code = XF_EXIT_LOGOFF;
1706 freerdp_disconnect(instance);
1708 ExitThread(exit_code);
1712int xf_exit_code_from_disconnect_reason(DWORD reason)
1715 (reason >= XF_EXIT_PARSE_ARGUMENTS && reason <= XF_EXIT_CONNECT_NO_OR_MISSING_CREDENTIALS))
1716 return WINPR_ASSERTING_INT_CAST(
int, reason);
1718 else if (reason >= 0x100 && reason <= 0x10A)
1719 reason -= 0x100 + XF_EXIT_LICENSE_INTERNAL;
1721 else if (reason >= 0x10c9 && reason <= 0x1193)
1722 reason = XF_EXIT_RDP;
1724 else if (!(reason <= 0xC))
1725 reason = XF_EXIT_UNKNOWN;
1727 return WINPR_ASSERTING_INT_CAST(
int, reason);
1730static void xf_TerminateEventHandler(
void* context,
const TerminateEventArgs* e)
1732 rdpContext* ctx = (rdpContext*)context;
1734 freerdp_abort_connect_context(ctx);
1738static void xf_ZoomingChangeEventHandler(
void* context,
const ZoomingChangeEventArgs* e)
1742 rdpSettings* settings = NULL;
1743 xfContext* xfc = (xfContext*)context;
1747 settings = xfc->common.context.settings;
1748 WINPR_ASSERT(settings);
1750 w = xfc->scaledWidth + e->dx;
1751 h = xfc->scaledHeight + e->dy;
1753 if (e->dx == 0 && e->dy == 0)
1762 if (w == xfc->scaledWidth && h == xfc->scaledHeight)
1765 xfc->scaledWidth = w;
1766 xfc->scaledHeight = h;
1767 xf_draw_screen(xfc, 0, 0,
1768 WINPR_ASSERTING_INT_CAST(
1770 WINPR_ASSERTING_INT_CAST(
1774static void xf_PanningChangeEventHandler(
void* context,
const PanningChangeEventArgs* e)
1776 xfContext* xfc = (xfContext*)context;
1777 rdpSettings* settings = NULL;
1782 settings = xfc->common.context.settings;
1783 WINPR_ASSERT(settings);
1785 if (e->dx == 0 && e->dy == 0)
1788 xfc->offset_x += e->dx;
1789 xfc->offset_y += e->dy;
1790 xf_draw_screen(xfc, 0, 0,
1791 WINPR_ASSERTING_INT_CAST(
1793 WINPR_ASSERTING_INT_CAST(
1802static BOOL xfreerdp_client_global_init(
void)
1805 (void)setlocale(LC_ALL,
"");
1807 if (freerdp_handle_signals() != 0)
1813static void xfreerdp_client_global_uninit(
void)
1817static int xfreerdp_client_start(rdpContext* context)
1819 xfContext* xfc = (xfContext*)context;
1820 rdpSettings* settings = context->settings;
1824 WLog_ERR(TAG,
"error: server hostname was not specified with /v:<server>[:port]");
1828 if (!(xfc->common.thread = CreateThread(NULL, 0, xf_client_thread, context->instance, 0, NULL)))
1830 WLog_ERR(TAG,
"failed to create client thread");
1837static Atom get_supported_atom(xfContext* xfc,
const char* atomName)
1839 const Atom atom = Logging_XInternAtom(xfc->log, xfc->display, atomName, False);
1841 for (
unsigned long i = 0; i < xfc->supportedAtomCount; i++)
1843 if (xfc->supportedAtoms[i] == atom)
1850void xf_teardown_x11(xfContext* xfc)
1856 LogDynAndXCloseDisplay(xfc->log, xfc->display);
1857 xfc->display = NULL;
1862 (void)CloseHandle(xfc->x11event);
1863 xfc->x11event = NULL;
1868 (void)CloseHandle(xfc->mutex);
1872 if (xfc->vscreen.monitors)
1874 free(xfc->vscreen.monitors);
1875 xfc->vscreen.monitors = NULL;
1877 xfc->vscreen.nmonitors = 0;
1879 free(xfc->supportedAtoms);
1880 xfc->supportedAtoms = NULL;
1881 xfc->supportedAtomCount = 0;
1884BOOL xf_setup_x11(xfContext* xfc)
1888 xfc->UseXThreads = TRUE;
1895 if (xfc->UseXThreads)
1897 if (!XInitThreads())
1899 WLog_WARN(TAG,
"XInitThreads() failure");
1900 xfc->UseXThreads = FALSE;
1904 xfc->display = XOpenDisplay(NULL);
1908 WLog_ERR(TAG,
"failed to open display: %s", XDisplayName(NULL));
1909 WLog_ERR(TAG,
"Please check that the $DISPLAY environment variable is properly set.");
1914 WLog_INFO(TAG,
"Enabling X11 debug mode.");
1915 XSynchronize(xfc->display, TRUE);
1917 def_error_handler = XSetErrorHandler(xf_error_handler_ex);
1919 xfc->mutex = CreateMutex(NULL, FALSE, NULL);
1923 WLog_ERR(TAG,
"Could not create mutex!");
1927 xfc->xfds = ConnectionNumber(xfc->display);
1928 xfc->screen_number = DefaultScreen(xfc->display);
1929 xfc->screen = ScreenOfDisplay(xfc->display, xfc->screen_number);
1930 xfc->big_endian = (ImageByteOrder(xfc->display) == MSBFirst);
1932 xfc->complex_regions = TRUE;
1933 xfc->NET_SUPPORTED = Logging_XInternAtom(xfc->log, xfc->display,
"_NET_SUPPORTED", True);
1934 xfc->NET_SUPPORTING_WM_CHECK =
1935 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_SUPPORTING_WM_CHECK", True);
1937 if ((xfc->NET_SUPPORTED != None) && (xfc->NET_SUPPORTING_WM_CHECK != None))
1939 Atom actual_type = 0;
1940 int actual_format = 0;
1941 unsigned long nitems = 0;
1942 unsigned long after = 0;
1943 unsigned char* data = NULL;
1944 int status = LogDynAndXGetWindowProperty(
1945 xfc->log, xfc->display, RootWindowOfScreen(xfc->screen), xfc->NET_SUPPORTED, 0, 1024,
1946 False, XA_ATOM, &actual_type, &actual_format, &nitems, &after, &data);
1948 if ((status == Success) && (actual_type == XA_ATOM) && (actual_format == 32))
1950 xfc->supportedAtomCount = nitems;
1951 xfc->supportedAtoms = calloc(xfc->supportedAtomCount,
sizeof(Atom));
1952 WINPR_ASSERT(xfc->supportedAtoms);
1953 memcpy(xfc->supportedAtoms, data, nitems *
sizeof(Atom));
1960 xfc->XWAYLAND_MAY_GRAB_KEYBOARD =
1961 Logging_XInternAtom(xfc->log, xfc->display,
"_XWAYLAND_MAY_GRAB_KEYBOARD", False);
1962 xfc->NET_WM_ICON = Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_ICON", False);
1963 xfc->MOTIF_WM_HINTS = Logging_XInternAtom(xfc->log, xfc->display,
"_MOTIF_WM_HINTS", False);
1964 xfc->NET_NUMBER_OF_DESKTOPS =
1965 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_NUMBER_OF_DESKTOPS", False);
1966 xfc->NET_CURRENT_DESKTOP =
1967 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_CURRENT_DESKTOP", False);
1968 xfc->NET_WORKAREA = Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WORKAREA", False);
1969 xfc->NET_WM_STATE = get_supported_atom(xfc,
"_NET_WM_STATE");
1970 xfc->NET_WM_STATE_MODAL = get_supported_atom(xfc,
"_NET_WM_STATE_MODAL");
1971 xfc->NET_WM_STATE_STICKY = get_supported_atom(xfc,
"_NET_WM_STATE_STICKY");
1972 xfc->NET_WM_STATE_MAXIMIZED_HORZ =
1973 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_STATE_MAXIMIZED_HORZ", False);
1974 xfc->NET_WM_STATE_MAXIMIZED_VERT =
1975 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_STATE_MAXIMIZED_VERT", False);
1976 xfc->NET_WM_STATE_SHADED = get_supported_atom(xfc,
"_NET_WM_STATE_SHADED");
1977 xfc->NET_WM_STATE_SKIP_TASKBAR = get_supported_atom(xfc,
"_NET_WM_STATE_SKIP_TASKBAR");
1978 xfc->NET_WM_STATE_SKIP_PAGER = get_supported_atom(xfc,
"_NET_WM_STATE_SKIP_PAGER");
1979 xfc->NET_WM_STATE_HIDDEN = get_supported_atom(xfc,
"_NET_WM_STATE_HIDDEN");
1980 xfc->NET_WM_STATE_FULLSCREEN = get_supported_atom(xfc,
"_NET_WM_STATE_FULLSCREEN");
1981 xfc->NET_WM_STATE_ABOVE = get_supported_atom(xfc,
"_NET_WM_STATE_ABOVE");
1982 xfc->NET_WM_STATE_BELOW = get_supported_atom(xfc,
"_NET_WM_STATE_BELOW");
1983 xfc->NET_WM_STATE_DEMANDS_ATTENTION =
1984 get_supported_atom(xfc,
"_NET_WM_STATE_DEMANDS_ATTENTION");
1985 xfc->NET_WM_FULLSCREEN_MONITORS = get_supported_atom(xfc,
"_NET_WM_FULLSCREEN_MONITORS");
1986 xfc->NET_WM_NAME = Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_NAME", False);
1987 xfc->NET_WM_PID = Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_PID", False);
1988 xfc->NET_WM_WINDOW_TYPE =
1989 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_WINDOW_TYPE", False);
1990 xfc->NET_WM_WINDOW_TYPE_NORMAL =
1991 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_WINDOW_TYPE_NORMAL", False);
1992 xfc->NET_WM_WINDOW_TYPE_DIALOG =
1993 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_WINDOW_TYPE_DIALOG", False);
1994 xfc->NET_WM_WINDOW_TYPE_POPUP =
1995 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_WINDOW_TYPE_POPUP", False);
1996 xfc->NET_WM_WINDOW_TYPE_POPUP_MENU =
1997 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_WINDOW_TYPE_POPUP_MENU", False);
1998 xfc->NET_WM_WINDOW_TYPE_UTILITY =
1999 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_WINDOW_TYPE_UTILITY", False);
2000 xfc->NET_WM_WINDOW_TYPE_DROPDOWN_MENU =
2001 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", False);
2002 xfc->NET_WM_STATE_SKIP_TASKBAR =
2003 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_STATE_SKIP_TASKBAR", False);
2004 xfc->NET_WM_STATE_SKIP_PAGER =
2005 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_STATE_SKIP_PAGER", False);
2006 xfc->NET_WM_MOVERESIZE =
2007 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_MOVERESIZE", False);
2008 xfc->NET_MOVERESIZE_WINDOW =
2009 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_MOVERESIZE_WINDOW", False);
2010 xfc->UTF8_STRING = Logging_XInternAtom(xfc->log, xfc->display,
"UTF8_STRING", FALSE);
2011 xfc->WM_PROTOCOLS = Logging_XInternAtom(xfc->log, xfc->display,
"WM_PROTOCOLS", False);
2012 xfc->WM_DELETE_WINDOW = Logging_XInternAtom(xfc->log, xfc->display,
"WM_DELETE_WINDOW", False);
2013 xfc->WM_STATE = Logging_XInternAtom(xfc->log, xfc->display,
"WM_STATE", False);
2014 xfc->x11event = CreateFileDescriptorEvent(NULL, FALSE, FALSE, xfc->xfds, WINPR_FD_READ);
2016 xfc->NET_WM_ALLOWED_ACTIONS =
2017 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_ALLOWED_ACTIONS", False);
2019 xfc->NET_WM_ACTION_CLOSE =
2020 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_ACTION_CLOSE", False);
2021 xfc->NET_WM_ACTION_MINIMIZE =
2022 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_ACTION_MINIMIZE", False);
2023 xfc->NET_WM_ACTION_MOVE =
2024 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_ACTION_MOVE", False);
2025 xfc->NET_WM_ACTION_RESIZE =
2026 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_ACTION_RESIZE", False);
2027 xfc->NET_WM_ACTION_MAXIMIZE_HORZ =
2028 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_ACTION_MAXIMIZE_HORZ", False);
2029 xfc->NET_WM_ACTION_MAXIMIZE_VERT =
2030 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_ACTION_MAXIMIZE_VERT", False);
2031 xfc->NET_WM_ACTION_FULLSCREEN =
2032 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_ACTION_FULLSCREEN", False);
2033 xfc->NET_WM_ACTION_CHANGE_DESKTOP =
2034 Logging_XInternAtom(xfc->log, xfc->display,
"_NET_WM_ACTION_CHANGE_DESKTOP", False);
2038 WLog_ERR(TAG,
"Could not create xfds event");
2042 xf_check_extensions(xfc);
2044 xfc->vscreen.monitors = calloc(16,
sizeof(MONITOR_INFO));
2046 if (!xfc->vscreen.monitors)
2051 xf_teardown_x11(xfc);
2055static BOOL xfreerdp_client_new(freerdp* instance, rdpContext* context)
2057 xfContext* xfc = (xfContext*)instance->context;
2058 WINPR_ASSERT(context);
2060 WINPR_ASSERT(!xfc->display);
2061 WINPR_ASSERT(!xfc->mutex);
2062 WINPR_ASSERT(!xfc->x11event);
2063 instance->PreConnect = xf_pre_connect;
2064 instance->PostConnect = xf_post_connect;
2065 instance->PostDisconnect = xf_post_disconnect;
2066 instance->PostFinalDisconnect = xf_post_final_disconnect;
2067 instance->LogonErrorInfo = xf_logon_error_info;
2068 instance->GetAccessToken = client_cli_get_access_token;
2069 PubSub_SubscribeTerminate(context->pubSub, xf_TerminateEventHandler);
2071 PubSub_SubscribeZoomingChange(context->pubSub, xf_ZoomingChangeEventHandler);
2072 PubSub_SubscribePanningChange(context->pubSub, xf_PanningChangeEventHandler);
2074 xfc->log = WLog_Get(TAG);
2079static void xfreerdp_client_free(WINPR_ATTR_UNUSED freerdp* instance, rdpContext* context)
2084 if (context->pubSub)
2086 PubSub_UnsubscribeTerminate(context->pubSub, xf_TerminateEventHandler);
2088 PubSub_UnsubscribeZoomingChange(context->pubSub, xf_ZoomingChangeEventHandler);
2089 PubSub_UnsubscribePanningChange(context->pubSub, xf_PanningChangeEventHandler);
2094int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
2096 pEntryPoints->Version = 1;
2097 pEntryPoints->Size =
sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
2098 pEntryPoints->GlobalInit = xfreerdp_client_global_init;
2099 pEntryPoints->GlobalUninit = xfreerdp_client_global_uninit;
2100 pEntryPoints->ContextSize =
sizeof(xfContext);
2101 pEntryPoints->ClientNew = xfreerdp_client_new;
2102 pEntryPoints->ClientFree = xfreerdp_client_free;
2103 pEntryPoints->ClientStart = xfreerdp_client_start;
2104 pEntryPoints->ClientStop = freerdp_client_common_stop;
FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
FREERDP_API BOOL freerdp_settings_set_string(rdpSettings *settings, FreeRDP_Settings_Keys_String id, const char *param)
Sets a string settings value. The param is copied.
FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.
FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 param)
Sets a UINT32 settings value.
FREERDP_API const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string settings value.
FREERDP_API BOOL freerdp_settings_set_bool(rdpSettings *settings, FreeRDP_Settings_Keys_Bool id, BOOL param)
Sets a BOOL settings value.