29#include <sys/select.h>
30#include <sys/signal.h>
34#include <X11/XKBlib.h>
36#include <winpr/endian.h>
38#include <winpr/assert.h>
39#include <winpr/cast.h>
40#include <winpr/path.h>
41#include <winpr/synch.h>
42#include <winpr/image.h>
43#include <winpr/sysinfo.h>
45#include <freerdp/log.h>
46#include <freerdp/codec/color.h>
47#include <freerdp/codec/region.h>
49#include "x11_shadow.h"
51#define TAG SERVER_TAG("shadow.x11")
55static UINT32 x11_shadow_enum_monitors(
MONITOR_DEF* monitors, UINT32 maxMonitors);
59#include <security/pam_appl.h>
66} SHADOW_PAM_AUTH_DATA;
73 SHADOW_PAM_AUTH_DATA appdata;
74} SHADOW_PAM_AUTH_INFO;
77static int x11_shadow_pam_conv(
int num_msg,
const struct pam_message** msg,
78 struct pam_response** resp,
void* appdata_ptr)
80 int pam_status = PAM_CONV_ERR;
81 SHADOW_PAM_AUTH_DATA* appdata =
nullptr;
82 struct pam_response* response =
nullptr;
83 WINPR_ASSERT(num_msg >= 0);
84 appdata = (SHADOW_PAM_AUTH_DATA*)appdata_ptr;
85 WINPR_ASSERT(appdata);
87 if (!(response = (
struct pam_response*)calloc((
size_t)num_msg,
sizeof(
struct pam_response))))
90 for (
int index = 0; index < num_msg; index++)
92 switch (msg[index]->msg_style)
94 case PAM_PROMPT_ECHO_ON:
95 response[index].resp = _strdup(appdata->user);
97 if (!response[index].resp)
100 response[index].resp_retcode = PAM_SUCCESS;
103 case PAM_PROMPT_ECHO_OFF:
104 response[index].resp = _strdup(appdata->password);
106 if (!response[index].resp)
109 response[index].resp_retcode = PAM_SUCCESS;
113 pam_status = PAM_CONV_ERR;
122 for (
int index = 0; index < num_msg; ++index)
124 if (response[index].resp)
126 memset(response[index].resp, 0, strlen(response[index].resp));
127 free(response[index].resp);
131 memset(response, 0,
sizeof(
struct pam_response) * (
size_t)num_msg);
138static BOOL x11_shadow_pam_get_service_name(SHADOW_PAM_AUTH_INFO* info)
140 const char* base =
"/etc/pam.d";
141 const char* hints[] = {
"lightdm",
"gdm",
"xdm",
"login",
"sshd" };
143 for (
size_t x = 0; x < ARRAYSIZE(hints); x++)
145 char path[MAX_PATH] = WINPR_C_ARRAY_INIT;
146 const char* hint = hints[x];
148 (void)_snprintf(path,
sizeof(path),
"%s/%s", base, hint);
149 if (winpr_PathFileExists(path))
152 info->service_name = _strdup(hint);
153 return info->service_name !=
nullptr;
156 WLog_WARN(TAG,
"Could not determine PAM service name");
161static int x11_shadow_pam_authenticate(rdpShadowSubsystem* subsystem, rdpShadowClient* client,
162 const char* user,
const char* domain,
const char* password)
166 SHADOW_PAM_AUTH_INFO info = WINPR_C_ARRAY_INIT;
167 WINPR_UNUSED(subsystem);
168 WINPR_UNUSED(client);
170 if (!x11_shadow_pam_get_service_name(&info))
173 info.appdata.user = user;
174 info.appdata.domain = domain;
175 info.appdata.password = password;
176 info.pamc.conv = &x11_shadow_pam_conv;
177 info.pamc.appdata_ptr = &info.appdata;
178 pam_status = pam_start(info.service_name,
nullptr, &info.pamc, &info.handle);
180 if (pam_status != PAM_SUCCESS)
182 WLog_ERR(TAG,
"pam_start failure: %s", pam_strerror(info.handle, pam_status));
186 pam_status = pam_authenticate(info.handle, 0);
188 if (pam_status != PAM_SUCCESS)
190 WLog_ERR(TAG,
"pam_authenticate failure: %s", pam_strerror(info.handle, pam_status));
194 pam_status = pam_acct_mgmt(info.handle, 0);
196 if (pam_status != PAM_SUCCESS)
198 WLog_ERR(TAG,
"pam_acct_mgmt failure: %s", pam_strerror(info.handle, pam_status));
206 const int res = pam_end(info.handle, pam_status);
207 if (res != PAM_SUCCESS)
208 WLog_WARN(TAG,
"pam_end failure: %s", pam_strerror(info.handle, pam_status));
210 free(info.service_name);
216#if defined(WITH_XTEST)
218static BOOL isKeyPressed(Display* display, KeyCode code)
220 char keys[32] = WINPR_C_ARRAY_INIT;
221 if (XQueryKeymap(display, keys) != 1)
224 return (keys[code >> 3] >> (code & 7)) & 1;
227static BOOL pressKey(Display* display, KeySym sym)
229 WINPR_ASSERT(display);
231 KeyCode key = XKeysymToKeycode(display, sym);
234 WLog_WARN(TAG,
"No KeyCode mapped for KeySym=%lu", sym);
239 const int rc1 = XTestFakeKeyEvent(display, key, True, CurrentTime);
241 const int rc2 = XTestFakeKeyEvent(display, key, False, CurrentTime);
243 if ((rc1 == 0) || (rc2 == 0))
245 WLog_WARN(TAG,
"Failed to synghesize KeyCode=%u event", key);
251WINPR_ATTR_MALLOC(XFree, 1)
252static
char* nameForIndicator(Display* display,
unsigned int pos)
254 WINPR_ASSERT(display);
256 XkbDescPtr xkb = XkbAllocKeyboard();
259 WLog_WARN(TAG,
"Failed to allocate XkbDescPtr");
263 if (XkbGetNames(display, XkbIndicatorNamesMask, xkb) != Success)
265 WLog_WARN(TAG,
"Failed to get XkbGetNames");
266 XkbFreeKeyboard(xkb, 0, True);
270 char* name =
nullptr;
271 if (pos >= XkbNumIndicators)
272 WLog_WARN(TAG,
"invalid indicator bit position %u", pos);
275 Atom atom = xkb->names->indicators[pos];
277 name = XGetAtomName(display, atom);
279 WLog_WARN(TAG,
"Failed to map indicator position %u to atom", pos);
281 XkbFreeKeyboard(xkb, 0, True);
286static unsigned int utf16_to_utf32(WCHAR lehigh, WCHAR lelow)
288 const WCHAR high = winpr_Data_Get_UINT16(&lehigh);
289 const WCHAR low = winpr_Data_Get_UINT16(&lelow);
290 unsigned int u32 = high;
291 if ((high >= 0xD800u) && (high <= 0xDBFFu) && (low >= 0xDC00u) && (low <= 0xDFFFu))
292 u32 = ((high - 0xD800u) << 10u) + (low - 0xDC00u) + 0x10000u;
298static BOOL x11_shadow_input_synchronize_event(WINPR_ATTR_UNUSED rdpShadowSubsystem* subsystem,
299 WINPR_ATTR_UNUSED rdpShadowClient* client,
300 WINPR_ATTR_UNUSED UINT32 flags)
303 x11ShadowSubsystem* x11 = (x11ShadowSubsystem*)subsystem;
305 if (!client || !subsystem)
308 XLockDisplay(x11->display);
309 XTestGrabControl(x11->display, True);
312 for (KeyCode x = 0; x < 255; x++)
314 if (!isKeyPressed(x11->display, x))
317 XTestFakeKeyEvent(x11->display, x, False, CurrentTime);
321 unsigned int state = WINPR_C_ARRAY_INIT;
322 const Status rc = XkbGetIndicatorState(x11->display, XkbUseCoreKbd, &state);
325 WLog_WARN(TAG,
"XkbGetIndicatorState failed, not syncing modifiers");
330 for (
unsigned x = 0; x < XkbNumIndicators; x++)
332 unsigned bit = 1 << x;
333 if ((state & bit) == 0)
335 char* name = nameForIndicator(x11->display, x);
339 if (_stricmp(name,
"Scroll Lock") == 0)
341 pressKey(x11->display, XK_Scroll_Lock);
343 else if (_stricmp(name,
"Num Lock") == 0)
345 pressKey(x11->display, XK_Num_Lock);
347 else if (_stricmp(name,
"Caps Lock") == 0)
349 pressKey(x11->display, XK_Caps_Lock);
351 else if (_stricmp(name,
"Kana Lock") == 0)
353 pressKey(x11->display, XK_Kana_Lock);
359 const Status rc2 = XkbGetIndicatorState(x11->display, XkbUseCoreKbd, &state2);
362 WLog_WARN(TAG,
"XkbGetIndicatorState failed, can not check modifiers were cleared");
364 else if (state2 != 0)
366 WLog_WARN(TAG,
"XkbGetIndicatorState clear check returned 0x%08u, should be 0x00000000",
371 if ((flags & KBD_SYNC_SCROLL_LOCK) != 0)
373 pressKey(x11->display, XK_Scroll_Lock);
375 if ((flags & KBD_SYNC_NUM_LOCK) != 0)
377 pressKey(x11->display, XK_Num_Lock);
379 if ((flags & KBD_SYNC_CAPS_LOCK) != 0)
381 pressKey(x11->display, XK_Caps_Lock);
383 if ((flags & KBD_SYNC_KANA_LOCK) != 0)
385 pressKey(x11->display, XK_Kana_Lock);
389 const Status rc3 = XkbGetIndicatorState(x11->display, XkbUseCoreKbd, &state2);
392 WLog_WARN(TAG,
"XkbGetIndicatorState failed, can not check modifiers were applied");
394 else if (state3 != 0)
396 WLog_DBG(TAG,
"XkbGetIndicatorState apply check returned 0x%08u", state3);
400 XTestGrabControl(x11->display, False);
401 XFlush(x11->display);
402 XUnlockDisplay(x11->display);
404 WLog_WARN(TAG,
"SynchronizeEvent not supported by backend, ignoring");
410static BOOL x11_shadow_input_keyboard_event(rdpShadowSubsystem* subsystem, rdpShadowClient* client,
411 UINT16 flags, UINT8 code)
414 x11ShadowSubsystem* x11 = (x11ShadowSubsystem*)subsystem;
415 BOOL extended = FALSE;
417 if (!client || !subsystem)
420 if (flags & KBD_FLAGS_EXTENDED)
423 DWORD scancode = code;
427 DWORD vkcode = GetVirtualKeyCodeFromVirtualScanCode(scancode, WINPR_KBD_TYPE_IBM_ENHANCED);
432 const DWORD keycode = GetKeycodeFromVirtualKeyCode(vkcode, WINPR_KEYCODE_TYPE_XKB);
436 XLockDisplay(x11->display);
437 XTestGrabControl(x11->display, True);
441 const Bool down = ((flags & KBD_FLAGS_RELEASE) == 0);
442 XTestFakeKeyEvent(x11->display, keycode, down, CurrentTime);
444 XTestGrabControl(x11->display, False);
445 XFlush(x11->display);
446 XUnlockDisplay(x11->display);
449 WLog_WARN(TAG,
"KeyboardEvent not supported by backend, ignoring");
455static BOOL x11_shadow_input_unicode_keyboard_event(WINPR_ATTR_UNUSED rdpShadowSubsystem* subsystem,
456 WINPR_ATTR_UNUSED rdpShadowClient* client,
457 WINPR_ATTR_UNUSED UINT16 flags,
458 WINPR_ATTR_UNUSED UINT16 lecode)
461 x11ShadowSubsystem* x11 = (x11ShadowSubsystem*)subsystem;
464 if (!client || !subsystem)
467 if ((flags & KBD_FLAGS_RELEASE) == 0)
471 const WCHAR becode = winpr_Data_Get_UINT16(&lecode);
472 const WCHAR surrogate = x11->surrogate;
473 if ((becode >= 0xD800) && (becode <= 0xDBFF))
477 if (surrogate != becode)
479 "Invalid high surrogate: mismatch between key down and key up, ignoring");
482 x11->surrogate = lecode;
488 BOOL isSurrogate = FALSE;
491 if ((becode >= 0xDC00) && (becode <= 0xDFFF))
494 WLog_WARN(TAG,
"Received invalid surrogate sequence, discarding.");
497 XLockDisplay(x11->display);
499 KeySym unicode_keysym = NoSymbol;
500 KeyCode keycode = AnyKey;
502 if (!isSurrogate && ((becode < 0x20) || (becode == 0x7f)))
507 unicode_keysym = XK_Delete;
510 unicode_keysym = XK_BackSpace;
513 unicode_keysym = XK_Tab;
516 unicode_keysym = XK_Linefeed;
519 unicode_keysym = XK_Return;
522 unicode_keysym = XK_Cancel;
525 unicode_keysym = XK_Escape;
529 WLog_WARN(TAG,
"ASCII control 0x%02x unmapped, ignoring", becode);
561 if (unicode_keysym != NoSymbol)
563 keycode = XKeysymToKeycode(x11->display, unicode_keysym);
564 if (keycode == AnyKey)
567 XChangeKeyboardMapping(x11->display, keycode, 1, &unicode_keysym, 1);
568 XSync(x11->display, False);
575 unicode_keysym = utf16_to_utf32(surrogate, lecode) | 0x01000000u;
578 char buffer[32] = WINPR_C_ARRAY_INIT;
579 (void)ConvertWCharNToUtf8(&lecode, 1, buffer,
sizeof(buffer));
580 unicode_keysym = XStringToKeysym(buffer);
583 if (unicode_keysym != NoSymbol)
584 keycode = XKeysymToKeycode(x11->display, unicode_keysym);
586 if (keycode == AnyKey)
590 XChangeKeyboardMapping(x11->display, keycode, 1, &unicode_keysym, 1);
591 XSync(x11->display, False);
595 if (keycode != AnyKey)
597 XTestGrabControl(x11->display, True);
599 XTestFakeKeyEvent(x11->display, keycode, down, CurrentTime);
600 XTestGrabControl(x11->display, False);
601 XSync(x11->display, False);
602 XFlush(x11->display);
604 XUnlockDisplay(x11->display);
606 WLog_WARN(TAG,
"UnicodeKeyboardEvent not supported by backend, ignoring");
612static BOOL x11_shadow_input_mouse_event(rdpShadowSubsystem* subsystem, rdpShadowClient* client,
613 UINT16 flags, UINT16 x, UINT16 y)
616 x11ShadowSubsystem* x11 = (x11ShadowSubsystem*)subsystem;
617 unsigned int button = 0;
620 if (!subsystem || !client)
623 rdpShadowServer* server = subsystem->server;
628 rdpShadowSurface* surface = server->surface;
633 EnterCriticalSection(&surface->lock);
634 x11->lastMouseClient = client;
637 XLockDisplay(x11->display);
638 XTestGrabControl(x11->display, True);
640 if (flags & PTR_FLAGS_WHEEL)
642 BOOL negative = FALSE;
644 if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
647 button = (negative) ? 5 : 4;
648 XTestFakeButtonEvent(x11->display, button, True, (
unsigned long)CurrentTime);
649 XTestFakeButtonEvent(x11->display, button, False, (
unsigned long)CurrentTime);
651 else if (flags & PTR_FLAGS_HWHEEL)
653 BOOL negative = FALSE;
655 if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
658 button = (negative) ? 7 : 6;
659 XTestFakeButtonEvent(x11->display, button, True, (
unsigned long)CurrentTime);
660 XTestFakeButtonEvent(x11->display, button, False, (
unsigned long)CurrentTime);
664 if (flags & PTR_FLAGS_MOVE)
665 XTestFakeMotionEvent(x11->display, 0, x, y, CurrentTime);
667 if (flags & PTR_FLAGS_BUTTON1)
669 else if (flags & PTR_FLAGS_BUTTON2)
671 else if (flags & PTR_FLAGS_BUTTON3)
674 if (flags & PTR_FLAGS_DOWN)
678 XTestFakeButtonEvent(x11->display, button, down, CurrentTime);
681 XTestGrabControl(x11->display, False);
682 XFlush(x11->display);
683 XUnlockDisplay(x11->display);
684 LeaveCriticalSection(&surface->lock);
686 WLog_WARN(TAG,
"MouseEvent not supported by backend, ignoring");
692static BOOL x11_shadow_input_rel_mouse_event(rdpShadowSubsystem* subsystem, rdpShadowClient* client,
693 UINT16 flags, INT16 xDelta, INT16 yDelta)
696 x11ShadowSubsystem* x11 = (x11ShadowSubsystem*)subsystem;
699 unsigned int button = 0;
702 if (!subsystem || !client)
705 rdpShadowServer* server = subsystem->server;
710 rdpShadowSurface* surface = server->surface;
715 EnterCriticalSection(&surface->lock);
716 x11->lastMouseClient = client;
718 XLockDisplay(x11->display);
719 XTestGrabControl(x11->display, True);
721 if (flags & PTR_FLAGS_MOVE)
722 XTestFakeRelativeMotionEvent(x11->display, xDelta, yDelta, 0);
724 if (flags & PTR_FLAGS_BUTTON1)
726 else if (flags & PTR_FLAGS_BUTTON2)
728 else if (flags & PTR_FLAGS_BUTTON3)
730 else if (flags & PTR_XFLAGS_BUTTON1)
732 else if (flags & PTR_XFLAGS_BUTTON2)
735 if (flags & PTR_FLAGS_DOWN)
739 XTestFakeButtonEvent(x11->display, button, down, CurrentTime);
741 XTestGrabControl(x11->display, False);
742 XFlush(x11->display);
743 XUnlockDisplay(x11->display);
744 LeaveCriticalSection(&surface->lock);
746 WLog_WARN(TAG,
"RelMouseEvent not supported by backend, ignoring");
752static BOOL x11_shadow_input_extended_mouse_event(rdpShadowSubsystem* subsystem,
753 rdpShadowClient* client, UINT16 flags, UINT16 x,
757 x11ShadowSubsystem* x11 = (x11ShadowSubsystem*)subsystem;
761 if (!subsystem || !client)
764 rdpShadowServer* server = subsystem->server;
769 rdpShadowSurface* surface = server->surface;
774 EnterCriticalSection(&surface->lock);
775 x11->lastMouseClient = client;
778 XLockDisplay(x11->display);
779 XTestGrabControl(x11->display, True);
780 XTestFakeMotionEvent(x11->display, 0, x, y, CurrentTime);
782 if (flags & PTR_XFLAGS_BUTTON1)
784 else if (flags & PTR_XFLAGS_BUTTON2)
787 if (flags & PTR_XFLAGS_DOWN)
791 XTestFakeButtonEvent(x11->display, button, down, CurrentTime);
793 XTestGrabControl(x11->display, False);
794 XFlush(x11->display);
795 XUnlockDisplay(x11->display);
796 LeaveCriticalSection(&surface->lock);
798 WLog_WARN(TAG,
"ExtendedMouseEvent not supported by backend, ignoring");
803static void x11_shadow_message_free(UINT32
id, SHADOW_MSG_OUT* msg)
807 case SHADOW_MSG_OUT_POINTER_POSITION_UPDATE_ID:
811 case SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE_ID:
818 WLog_ERR(TAG,
"Unknown message id: %" PRIu32
"",
id);
825static int x11_shadow_pointer_position_update(x11ShadowSubsystem* subsystem)
827 UINT32 msgId = SHADOW_MSG_OUT_POINTER_POSITION_UPDATE_ID;
828 rdpShadowServer* server =
nullptr;
832 if (!subsystem || !subsystem->common.server || !subsystem->common.server->clients)
835 templateMsg.xPos = subsystem->common.pointerX;
836 templateMsg.yPos = subsystem->common.pointerY;
837 templateMsg.common.Free = x11_shadow_message_free;
838 server = subsystem->common.server;
839 ArrayList_Lock(server->clients);
841 for (
size_t index = 0; index < ArrayList_Count(server->clients); index++)
844 rdpShadowClient* client = (rdpShadowClient*)ArrayList_GetItem(server->clients, index);
847 if (client == subsystem->lastMouseClient)
850 msg = malloc(
sizeof(templateMsg));
858 memcpy(msg, &templateMsg,
sizeof(templateMsg));
860 if (shadow_client_post_msg(client,
nullptr, msgId, (SHADOW_MSG_OUT*)msg,
nullptr))
864 ArrayList_Unlock(server->clients);
869static int x11_shadow_pointer_alpha_update(x11ShadowSubsystem* subsystem)
871 UINT32 msgId = SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE_ID;
878 msg->xHot = subsystem->cursorHotX;
879 msg->yHot = subsystem->cursorHotY;
880 msg->width = subsystem->cursorWidth;
881 msg->height = subsystem->cursorHeight;
883 if (shadow_subsystem_pointer_convert_alpha_pointer_data_to_format(
884 subsystem->cursorPixels, subsystem->format, TRUE, msg->width, msg->height, msg) < 0)
890 msg->common.Free = x11_shadow_message_free;
891 const int count = shadow_client_boardcast_msg(subsystem->common.server,
nullptr, msgId,
892 (SHADOW_MSG_OUT*)msg,
nullptr);
899static int x11_shadow_query_cursor(x11ShadowSubsystem* subsystem, BOOL getImage)
904 rdpShadowServer* server = subsystem->common.server;
905 rdpShadowSurface* surface = server->surface;
910 UINT32* pDstPixel =
nullptr;
911 XFixesCursorImage* ci =
nullptr;
912 XLockDisplay(subsystem->display);
913 ci = XFixesGetCursorImage(subsystem->display);
914 XUnlockDisplay(subsystem->display);
922 if (ci->width > subsystem->cursorMaxWidth)
925 if (ci->height > subsystem->cursorMaxHeight)
928 subsystem->cursorHotX = ci->xhot;
929 subsystem->cursorHotY = ci->yhot;
930 subsystem->cursorWidth = ci->width;
931 subsystem->cursorHeight = ci->height;
932 subsystem->cursorId = ci->cursor_serial;
933 n = ci->width * ci->height;
934 pDstPixel = WINPR_PACKED_ALIGN_CAST(UINT32*, subsystem->cursorPixels);
936 for (
int k = 0; k < n; k++)
939 *pDstPixel++ = (UINT32)ci->pixels[k];
943 const int rc = x11_shadow_pointer_alpha_update(subsystem);
957 XLockDisplay(subsystem->display);
959 if (!XQueryPointer(subsystem->display, subsystem->root_window, &root, &child, &root_x,
960 &root_y, &win_x, &win_y, &mask))
962 XUnlockDisplay(subsystem->display);
966 XUnlockDisplay(subsystem->display);
974 EnterCriticalSection(&surface->lock);
977 LeaveCriticalSection(&surface->lock);
980 if ((x != (INT64)subsystem->common.pointerX) || (y != (INT64)subsystem->common.pointerY))
982 subsystem->common.pointerX = (UINT32)MAX(0, x);
983 subsystem->common.pointerY = (UINT32)MAX(0, y);
984 return x11_shadow_pointer_position_update(subsystem);
991static int x11_shadow_handle_xevent(x11ShadowSubsystem* subsystem, XEvent* xevent)
993 if (xevent->type == MotionNotify)
998 else if (xevent->type == subsystem->xfixes_cursor_notify_event)
1000 return x11_shadow_query_cursor(subsystem, TRUE);
1011#if defined(USE_SHADOW_BLEND_CURSOR)
1013static int x11_shadow_blend_cursor(x11ShadowSubsystem* subsystem)
1018 rdpShadowSurface* surface = subsystem->common.server->surface;
1021 UINT32 nWidth = subsystem->cursorWidth;
1022 UINT32 nHeight = subsystem->cursorHeight;
1023 INT64 nXDst = subsystem->common.pointerX - subsystem->cursorHotX;
1024 INT64 nYDst = subsystem->common.pointerY - subsystem->cursorHotY;
1026 if (nXDst >= surface->width)
1033 if (nXDst >= nWidth)
1036 nXSrc = (UINT32)nXDst;
1041 if (nYDst >= surface->height)
1048 if (nYDst >= nHeight)
1051 nYSrc = (UINT32)nYDst;
1056 if ((nXDst + nWidth) > surface->width)
1057 nWidth = (nXDst > surface->width) ? 0 : (UINT32)(surface->width - nXDst);
1059 if ((nYDst + nHeight) > surface->height)
1060 nHeight = (nYDst > surface->height) ? 0 : (UINT32)(surface->height - nYDst);
1062 const BYTE* pSrcData = subsystem->cursorPixels;
1063 const UINT32 nSrcStep = subsystem->cursorWidth * 4;
1064 BYTE* pDstData = surface->data;
1065 const UINT32 nDstStep = surface->scanline;
1067 for (
size_t y = 0; y < nHeight; y++)
1069 const BYTE* pSrcPixel = &pSrcData[((nYSrc + y) * nSrcStep) + (4ULL * nXSrc)];
1070 BYTE* pDstPixel = &pDstData[((WINPR_ASSERTING_INT_CAST(uint32_t, nYDst) + y) * nDstStep) +
1071 (4ULL * WINPR_ASSERTING_INT_CAST(uint32_t, nXDst))];
1073 for (
size_t x = 0; x < nWidth; x++)
1075 const BYTE B = *pSrcPixel++;
1076 const BYTE G = *pSrcPixel++;
1077 const BYTE R = *pSrcPixel++;
1078 const BYTE A = *pSrcPixel++;
1088 pDstPixel[0] = B + (pDstPixel[0] * (0xFF - A) + (0xFF / 2)) / 0xFF;
1089 pDstPixel[1] = G + (pDstPixel[1] * (0xFF - A) + (0xFF / 2)) / 0xFF;
1090 pDstPixel[2] = R + (pDstPixel[2] * (0xFF - A) + (0xFF / 2)) / 0xFF;
1093 pDstPixel[3] = 0xFF;
1103static BOOL x11_shadow_check_resize(x11ShadowSubsystem* subsystem)
1105 XWindowAttributes attr;
1106 XLockDisplay(subsystem->display);
1107 XGetWindowAttributes(subsystem->display, subsystem->root_window, &attr);
1108 XUnlockDisplay(subsystem->display);
1110 if (attr.width != (INT64)subsystem->width || attr.height != (INT64)subsystem->height)
1112 MONITOR_DEF* virtualScreen = &(subsystem->common.virtualScreen);
1115 subsystem->common.numMonitors = x11_shadow_enum_monitors(subsystem->common.monitors, 16);
1116 if (!shadow_screen_resize(subsystem->common.server->screen))
1119 WINPR_ASSERT(attr.width > 0);
1120 WINPR_ASSERT(attr.height > 0);
1122 subsystem->width = (UINT32)attr.width;
1123 subsystem->height = (UINT32)attr.height;
1125 virtualScreen->left = 0;
1126 virtualScreen->top = 0;
1127 virtualScreen->right = attr.width - 1;
1128 virtualScreen->bottom = attr.height - 1;
1129 virtualScreen->flags = 1;
1137static int x11_shadow_error_handler_for_capture(Display* display, XErrorEvent* event)
1140 XGetErrorText(display, event->error_code, (
char*)&msg,
sizeof(msg));
1141 WLog_ERR(TAG,
"X11 error: %s Error code: %x, request code: %x, minor code: %x", msg,
1142 event->error_code, event->request_code, event->minor_code);
1145 if (event->error_code != BadMatch)
1154static int x11_shadow_screen_grab_disp_locked(x11ShadowSubsystem* subsystem, XImage** ppimage,
1157 WINPR_ASSERT(subsystem);
1158 WINPR_ASSERT(ppimage);
1159 WINPR_ASSERT(invalidRect);
1161 rdpShadowServer* server = subsystem->common.server;
1162 WINPR_ASSERT(server);
1164 rdpShadowSurface* surface = server->surface;
1165 WINPR_ASSERT(surface);
1169#if defined(WITH_XDAMAGE)
1170 if (subsystem->use_xshm)
1172 XImage* image = subsystem->fb_image;
1175 XCopyArea(subsystem->display, subsystem->root_window, subsystem->fb_pixmap,
1176 subsystem->xshm_gc, 0, 0, subsystem->width, subsystem->height, 0, 0);
1178 EnterCriticalSection(&surface->lock);
1179 status = shadow_capture_compare_with_format(
1180 surface->data, surface->format, surface->scanline, surface->width, surface->height,
1181 (BYTE*)&(image->data[surface->width * 4ull]), subsystem->format,
1182 WINPR_ASSERTING_INT_CAST(UINT32, image->bytes_per_line), invalidRect);
1183 LeaveCriticalSection(&surface->lock);
1188 EnterCriticalSection(&surface->lock);
1189 XImage* image = XGetImage(subsystem->display, subsystem->root_window, surface->x,
1190 surface->y, surface->width, surface->height, AllPlanes, ZPixmap);
1194 status = shadow_capture_compare_with_format(
1195 surface->data, surface->format, surface->scanline, surface->width, surface->height,
1196 (BYTE*)image->data, subsystem->format,
1197 WINPR_ASSERTING_INT_CAST(UINT32, image->bytes_per_line), invalidRect);
1200 LeaveCriticalSection(&surface->lock);
1207static BOOL x11_shadow_surface_update_invalid(rdpShadowSurface* surface,
1211 WINPR_ASSERT(surface);
1212 WINPR_ASSERT(invalidRect);
1213 WINPR_ASSERT(surfaceRect);
1215 EnterCriticalSection(&surface->lock);
1217 region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), invalidRect);
1219 region16_intersect_rect(&(surface->invalidRegion), &(surface->invalidRegion), surfaceRect);
1220 const BOOL empty = region16_is_empty(&(surface->invalidRegion));
1221 LeaveCriticalSection(&surface->lock);
1222 return !rc1 || !rc2 || empty;
1226static BOOL x11_shadow_surface_update_contents(rdpShadowSurface* surface, UINT32 format,
1227 const XImage* image)
1229 WINPR_ASSERT(surface);
1230 WINPR_ASSERT(image);
1232 EnterCriticalSection(&surface->lock);
1233 const RECTANGLE_16* extents = region16_extents(&(surface->invalidRegion));
1234 const UINT16 x = extents->left;
1235 const UINT16 y = extents->top;
1236 const UINT16 width = extents->right - extents->left;
1237 const UINT16 height = extents->bottom - extents->top;
1238 WINPR_ASSERT(image);
1239 WINPR_ASSERT(image->bytes_per_line >= 0);
1240 WINPR_ASSERT(width >= 0);
1241 WINPR_ASSERT(height >= 0);
1242 const BOOL success = freerdp_image_copy_no_overlap(
1243 surface->data, surface->format, surface->scanline, WINPR_ASSERTING_INT_CAST(uint32_t, x),
1244 WINPR_ASSERTING_INT_CAST(uint32_t, y), WINPR_ASSERTING_INT_CAST(uint32_t, width),
1245 WINPR_ASSERTING_INT_CAST(uint32_t, height), (BYTE*)image->data, format,
1246 WINPR_ASSERTING_INT_CAST(uint32_t, image->bytes_per_line),
1247 WINPR_ASSERTING_INT_CAST(UINT32, x), WINPR_ASSERTING_INT_CAST(UINT32, y),
nullptr,
1249 LeaveCriticalSection(&surface->lock);
1254static int x11_shadow_screen_grab(x11ShadowSubsystem* subsystem)
1258 WINPR_ASSERT(subsystem);
1261 rdpShadowServer* server = subsystem->common.server;
1262 WINPR_ASSERT(server);
1264 rdpShadowSurface* surface = server->surface;
1265 WINPR_ASSERT(surface);
1267 size_t count = ArrayList_Count(server->clients);
1273 EnterCriticalSection(&surface->lock);
1274 surfaceRect.right = WINPR_ASSERTING_INT_CAST(UINT16, surface->width);
1275 surfaceRect.bottom = WINPR_ASSERTING_INT_CAST(UINT16, surface->height);
1276 LeaveCriticalSection(&surface->lock);
1279 XImage* image =
nullptr;
1283 XLockDisplay(subsystem->display);
1288 XSetErrorHandler(x11_shadow_error_handler_for_capture);
1290 status = x11_shadow_screen_grab_disp_locked(subsystem, &image, &invalidRect);
1295 XSetErrorHandler(
nullptr);
1296 XSync(subsystem->display, False);
1297 XUnlockDisplay(subsystem->display);
1302 const BOOL empty = x11_shadow_surface_update_invalid(surface, &invalidRect, &surfaceRect);
1306 const BOOL success =
1307 x11_shadow_surface_update_contents(surface, subsystem->format, image);
1311#if defined(USE_SHADOW_BLEND_CURSOR)
1312 if (x11_shadow_blend_cursor(subsystem) < 0)
1315 count = ArrayList_Count(server->clients);
1316 shadow_subsystem_frame_update(&subsystem->common);
1320 rdpShadowClient* client =
nullptr;
1321 client = (rdpShadowClient*)ArrayList_GetItem(server->clients, 0);
1324 subsystem->common.captureFrameRate =
1325 shadow_encoder_preferred_fps(client->encoder);
1329 EnterCriticalSection(&surface->lock);
1330 region16_clear(&(surface->invalidRegion));
1331 LeaveCriticalSection(&surface->lock);
1338 if (!subsystem->use_xshm && image)
1339 XDestroyImage(image);
1345static int x11_shadow_subsystem_process_message(x11ShadowSubsystem* subsystem, wMessage* message)
1347 switch (message->id)
1349 case SHADOW_MSG_IN_REFRESH_REQUEST_ID:
1350 shadow_subsystem_frame_update((rdpShadowSubsystem*)subsystem);
1354 WLog_ERR(TAG,
"Unknown message id: %" PRIu32
"", message->id);
1359 message->Free(message);
1365static DWORD WINAPI x11_shadow_subsystem_thread(LPVOID arg)
1367 x11ShadowSubsystem* subsystem = (x11ShadowSubsystem*)arg;
1371 DWORD dwInterval = 0;
1372 UINT64 frameTime = 0;
1376 MsgPipe = subsystem->common.MsgPipe;
1378 events[nCount++] = subsystem->common.event;
1379 events[nCount++] = MessageQueue_Event(MsgPipe->In);
1380 subsystem->common.captureFrameRate = 16;
1381 dwInterval = 1000 / subsystem->common.captureFrameRate;
1382 frameTime = GetTickCount64() + dwInterval;
1386 const UINT64 cTime = GetTickCount64();
1387 const DWORD dwTimeout =
1388 (DWORD)((cTime > frameTime) ? 0 : MIN(UINT32_MAX, frameTime - cTime));
1389 status = WaitForMultipleObjects(nCount, events, FALSE, dwTimeout);
1391 if (WaitForSingleObject(MessageQueue_Event(MsgPipe->In), 0) == WAIT_OBJECT_0)
1393 if (MessageQueue_Peek(MsgPipe->In, &message, TRUE))
1395 if (message.id == WMQ_QUIT)
1398 const int rc = x11_shadow_subsystem_process_message(subsystem, &message);
1404 if (WaitForSingleObject(subsystem->common.event, 0) == WAIT_OBJECT_0)
1407 XLockDisplay(subsystem->display);
1409 if (XEventsQueued(subsystem->display, QueuedAlready))
1411 XNextEvent(subsystem->display, &xevent);
1412 rc = x11_shadow_handle_xevent(subsystem, &xevent);
1415 XUnlockDisplay(subsystem->display);
1420 if ((status == WAIT_TIMEOUT) || (GetTickCount64() > frameTime))
1422 const int rc1 = x11_shadow_check_resize(subsystem);
1425 const int rc2 = x11_shadow_screen_grab(subsystem);
1428 const int rc3 = x11_shadow_query_cursor(subsystem, FALSE);
1431 dwInterval = 1000 / subsystem->common.captureFrameRate;
1432 frameTime += dwInterval;
1441static int x11_shadow_subsystem_base_init(x11ShadowSubsystem* subsystem)
1443 if (subsystem->display)
1447 if (!getenv(
"DISPLAY"))
1450 setenv(
"DISPLAY",
":0", 1);
1453 if (!XInitThreads())
1456 subsystem->display = XOpenDisplay(
nullptr);
1458 if (!subsystem->display)
1460 WLog_ERR(TAG,
"failed to open display: %s", XDisplayName(
nullptr));
1464 subsystem->xfds = ConnectionNumber(subsystem->display);
1465 subsystem->number = DefaultScreen(subsystem->display);
1466 subsystem->screen = ScreenOfDisplay(subsystem->display, subsystem->number);
1467 subsystem->depth = WINPR_ASSERTING_INT_CAST(UINT32, DefaultDepthOfScreen(subsystem->screen));
1468 subsystem->width = WINPR_ASSERTING_INT_CAST(UINT32, WidthOfScreen(subsystem->screen));
1469 subsystem->height = WINPR_ASSERTING_INT_CAST(UINT32, HeightOfScreen(subsystem->screen));
1470 subsystem->root_window = RootWindow(subsystem->display, subsystem->number);
1475static int x11_shadow_xfixes_init(x11ShadowSubsystem* subsystem)
1478 int xfixes_event = 0;
1479 int xfixes_error = 0;
1483 if (!XFixesQueryExtension(subsystem->display, &xfixes_event, &xfixes_error))
1486 if (!XFixesQueryVersion(subsystem->display, &major, &minor))
1489 subsystem->xfixes_cursor_notify_event = xfixes_event + XFixesCursorNotify;
1490 XFixesSelectCursorInput(subsystem->display, subsystem->root_window,
1491 XFixesDisplayCursorNotifyMask);
1499static int x11_shadow_xinerama_init(x11ShadowSubsystem* subsystem)
1502 int xinerama_event = 0;
1503 int xinerama_error = 0;
1505 const int rc = x11_shadow_subsystem_base_init(subsystem);
1509 if (!XineramaQueryExtension(subsystem->display, &xinerama_event, &xinerama_error))
1512#if defined(WITH_XDAMAGE)
1515 if (!XDamageQueryVersion(subsystem->display, &major, &minor))
1519 if (!XineramaIsActive(subsystem->display))
1529static int x11_shadow_xdamage_init(x11ShadowSubsystem* subsystem)
1534 int damage_event = 0;
1535 int damage_error = 0;
1537 if (!subsystem->use_xfixes)
1540 if (!XDamageQueryExtension(subsystem->display, &damage_event, &damage_error))
1543 if (!XDamageQueryVersion(subsystem->display, &major, &minor))
1549 subsystem->xdamage_notify_event = damage_event + XDamageNotify;
1550 subsystem->xdamage =
1551 XDamageCreate(subsystem->display, subsystem->root_window, XDamageReportDeltaRectangles);
1553 if (!subsystem->xdamage)
1557 subsystem->xdamage_region = XFixesCreateRegion(subsystem->display,
nullptr, 0);
1559 if (!subsystem->xdamage_region)
1570static int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem)
1577 if (!XShmQueryExtension(subsystem->display))
1580 if (!XShmQueryVersion(subsystem->display, &major, &minor, &pixmaps))
1586 subsystem->fb_shm_info.shmid = -1;
1587 subsystem->fb_shm_info.shmaddr = (
char*)-1;
1588 subsystem->fb_shm_info.readOnly = False;
1589 subsystem->fb_image =
1590 XShmCreateImage(subsystem->display, subsystem->visual, subsystem->depth, ZPixmap,
nullptr,
1591 &(subsystem->fb_shm_info), subsystem->width, subsystem->height);
1593 if (!subsystem->fb_image)
1595 WLog_ERR(TAG,
"XShmCreateImage failed");
1599 subsystem->fb_shm_info.shmid =
1601 1ull * WINPR_ASSERTING_INT_CAST(uint32_t, subsystem->fb_image->bytes_per_line) *
1602 WINPR_ASSERTING_INT_CAST(uint32_t, subsystem->fb_image->height),
1605 if (subsystem->fb_shm_info.shmid == -1)
1607 WLog_ERR(TAG,
"shmget failed");
1611 subsystem->fb_shm_info.shmaddr = shmat(subsystem->fb_shm_info.shmid,
nullptr, 0);
1612 subsystem->fb_image->data = subsystem->fb_shm_info.shmaddr;
1614 if (subsystem->fb_shm_info.shmaddr == ((
char*)-1))
1616 WLog_ERR(TAG,
"shmat failed");
1620 if (!XShmAttach(subsystem->display, &(subsystem->fb_shm_info)))
1623 XSync(subsystem->display, False);
1624 shmctl(subsystem->fb_shm_info.shmid, IPC_RMID,
nullptr);
1625 subsystem->fb_pixmap = XShmCreatePixmap(
1626 subsystem->display, subsystem->root_window, subsystem->fb_image->data,
1627 &(subsystem->fb_shm_info), WINPR_ASSERTING_INT_CAST(uint32_t, subsystem->fb_image->width),
1628 WINPR_ASSERTING_INT_CAST(uint32_t, subsystem->fb_image->height),
1629 WINPR_ASSERTING_INT_CAST(uint32_t, subsystem->fb_image->depth));
1630 XSync(subsystem->display, False);
1632 if (!subsystem->fb_pixmap)
1635 values.subwindow_mode = IncludeInferiors;
1636 values.graphics_exposures = False;
1637#if defined(WITH_XDAMAGE)
1638 subsystem->xshm_gc = XCreateGC(subsystem->display, subsystem->root_window,
1639 GCSubwindowMode | GCGraphicsExposures, &values);
1640 XSetFunction(subsystem->display, subsystem->xshm_gc, GXcopy);
1642 XSync(subsystem->display, False);
1646UINT32 x11_shadow_enum_monitors(
MONITOR_DEF* monitors, UINT32 maxMonitors)
1648 Display* display =
nullptr;
1649 int displayWidth = 0;
1650 int displayHeight = 0;
1651 int numMonitors = 0;
1654 if (!getenv(
"DISPLAY"))
1657 setenv(
"DISPLAY",
":0", 1);
1660 display = XOpenDisplay(
nullptr);
1664 WLog_ERR(TAG,
"failed to open display: %s", XDisplayName(
nullptr));
1668 displayWidth = WidthOfScreen(DefaultScreenOfDisplay(display));
1669 displayHeight = HeightOfScreen(DefaultScreenOfDisplay(display));
1672#if defined(WITH_XDAMAGE)
1676 int xinerama_event = 0;
1677 int xinerama_error = 0;
1678 XineramaScreenInfo* screens =
nullptr;
1680 const Bool xinerama = XineramaQueryExtension(display, &xinerama_event, &xinerama_error);
1682#if defined(WITH_XDAMAGE)
1683 XDamageQueryVersion(display, &major, &minor);
1688 if (xinerama && damage && XineramaIsActive(display))
1690 screens = XineramaQueryScreens(display, &numMonitors);
1692 if (numMonitors > (INT64)maxMonitors)
1693 numMonitors = (int)maxMonitors;
1695 if (screens && (numMonitors > 0))
1697 for (
int index = 0; index < numMonitors; index++)
1700 const XineramaScreenInfo* screen = &screens[index];
1702 monitor->left = screen->x_org;
1703 monitor->top = screen->y_org;
1704 monitor->right = monitor->left + screen->width - 1;
1705 monitor->bottom = monitor->top + screen->height - 1;
1706 monitor->flags = (index == 0) ? 1 : 0;
1714 XCloseDisplay(display);
1716 if (numMonitors < 1)
1723 monitor->right = displayWidth - 1;
1724 monitor->bottom = displayHeight - 1;
1729 return WINPR_ASSERTING_INT_CAST(uint32_t, numMonitors);
1733static int x11_shadow_subsystem_init(rdpShadowSubsystem* sub)
1737 int nextensions = 0;
1738 XVisualInfo xtemplate = WINPR_C_ARRAY_INIT;
1739 XPixmapFormatValues* pf =
nullptr;
1741 x11ShadowSubsystem* subsystem = (x11ShadowSubsystem*)sub;
1746 subsystem->common.numMonitors = x11_shadow_enum_monitors(subsystem->common.monitors, 16);
1747 const int rc = x11_shadow_subsystem_base_init(subsystem);
1751 subsystem->format = (ImageByteOrder(subsystem->display) == LSBFirst) ? PIXEL_FORMAT_BGRA32
1752 : PIXEL_FORMAT_ARGB32;
1754 if ((subsystem->depth != 24) && (subsystem->depth != 32))
1756 WLog_ERR(TAG,
"unsupported X11 server color depth: %" PRIu32, subsystem->depth);
1761 char** extensions = XListExtensions(subsystem->display, &nextensions);
1763 if (!extensions || (nextensions < 0))
1766 for (
int i = 0; i < nextensions; i++)
1768 if (strcmp(extensions[i],
"Composite") == 0)
1769 subsystem->composite = TRUE;
1772 XFreeExtensionList(extensions);
1775 if (subsystem->composite)
1776 subsystem->use_xdamage = FALSE;
1779 XPixmapFormatValues* pfs = XListPixmapFormats(subsystem->display, &pf_count);
1783 WLog_ERR(TAG,
"XListPixmapFormats failed");
1787 for (
int i = 0; i < pf_count; i++)
1791 if (pf->depth == (INT64)subsystem->depth)
1793 subsystem->bpp = WINPR_ASSERTING_INT_CAST(uint32_t, pf->bits_per_pixel);
1794 subsystem->scanline_pad = WINPR_ASSERTING_INT_CAST(uint32_t, pf->scanline_pad);
1802 xtemplate.class = TrueColor;
1803 xtemplate.screen = subsystem->number;
1806 XVisualInfo* vis = XGetVisualInfo(subsystem->display, VisualClassMask | VisualScreenMask,
1807 &xtemplate, &vi_count);
1811 WLog_ERR(TAG,
"XGetVisualInfo failed");
1815 for (
int i = 0; i < vi_count; i++)
1817 XVisualInfo* vi = vis + i;
1819 if (vi->depth == (INT64)subsystem->depth)
1821 subsystem->visual = vi->visual;
1829 XSelectInput(subsystem->display, subsystem->root_window, SubstructureNotifyMask);
1830 subsystem->cursorMaxWidth = 256;
1831 subsystem->cursorMaxHeight = 256;
1832 subsystem->cursorPixels =
1833 winpr_aligned_calloc(4ULL * subsystem->cursorMaxWidth, subsystem->cursorMaxHeight, 16);
1835 if (!subsystem->cursorPixels)
1838 const int rc1 = x11_shadow_query_cursor(subsystem, TRUE);
1842 if (subsystem->use_xfixes)
1844 if (x11_shadow_xfixes_init(subsystem) < 0)
1845 subsystem->use_xfixes = FALSE;
1848 if (subsystem->use_xinerama)
1850 if (x11_shadow_xinerama_init(subsystem) < 0)
1851 subsystem->use_xinerama = FALSE;
1854 if (subsystem->use_xshm)
1856 if (x11_shadow_xshm_init(subsystem) < 0)
1857 subsystem->use_xshm = FALSE;
1860 if (subsystem->use_xdamage)
1862 if (x11_shadow_xdamage_init(subsystem) < 0)
1863 subsystem->use_xdamage = FALSE;
1866 if (!(subsystem->common.event =
1867 CreateFileDescriptorEvent(
nullptr, FALSE, FALSE, subsystem->xfds, WINPR_FD_READ)))
1871 MONITOR_DEF* virtualScreen = &(subsystem->common.virtualScreen);
1872 virtualScreen->left = 0;
1873 virtualScreen->top = 0;
1874 WINPR_ASSERT(subsystem->width <= INT32_MAX);
1875 WINPR_ASSERT(subsystem->height <= INT32_MAX);
1876 virtualScreen->right = (INT32)subsystem->width - 1;
1877 virtualScreen->bottom = (INT32)subsystem->height - 1;
1878 virtualScreen->flags = 1;
1880 "X11 Extensions: XFixes: %" PRId32
" Xinerama: %" PRId32
" XDamage: %" PRId32
1881 " XShm: %" PRId32
"",
1882 subsystem->use_xfixes, subsystem->use_xinerama, subsystem->use_xdamage,
1883 subsystem->use_xshm);
1889static int x11_shadow_subsystem_uninit(rdpShadowSubsystem* sub)
1891 x11ShadowSubsystem* subsystem = (x11ShadowSubsystem*)sub;
1896 if (subsystem->display)
1898 XCloseDisplay(subsystem->display);
1899 subsystem->display =
nullptr;
1902 if (subsystem->common.event)
1904 (void)CloseHandle(subsystem->common.event);
1905 subsystem->common.event =
nullptr;
1908 if (subsystem->cursorPixels)
1910 winpr_aligned_free(subsystem->cursorPixels);
1911 subsystem->cursorPixels =
nullptr;
1918static int x11_shadow_subsystem_start(rdpShadowSubsystem* sub)
1920 x11ShadowSubsystem* subsystem = (x11ShadowSubsystem*)sub;
1925 if (!(subsystem->thread =
1926 CreateThread(
nullptr, 0, x11_shadow_subsystem_thread, (
void*)subsystem, 0,
nullptr)))
1928 WLog_ERR(TAG,
"Failed to create thread");
1936static int x11_shadow_subsystem_stop(rdpShadowSubsystem* sub)
1938 x11ShadowSubsystem* subsystem = (x11ShadowSubsystem*)sub;
1943 if (subsystem->thread)
1945 if (MessageQueue_PostQuit(subsystem->common.MsgPipe->In, 0))
1946 (void)WaitForSingleObject(subsystem->thread, INFINITE);
1948 (void)CloseHandle(subsystem->thread);
1949 subsystem->thread =
nullptr;
1956static rdpShadowSubsystem* x11_shadow_subsystem_new(
void)
1958 x11ShadowSubsystem* subsystem = (x11ShadowSubsystem*)calloc(1,
sizeof(x11ShadowSubsystem));
1964 subsystem->common.Authenticate = x11_shadow_pam_authenticate;
1966 subsystem->common.SynchronizeEvent = x11_shadow_input_synchronize_event;
1967 subsystem->common.KeyboardEvent = x11_shadow_input_keyboard_event;
1968 subsystem->common.UnicodeKeyboardEvent = x11_shadow_input_unicode_keyboard_event;
1969 subsystem->common.MouseEvent = x11_shadow_input_mouse_event;
1970 subsystem->common.RelMouseEvent = x11_shadow_input_rel_mouse_event;
1971 subsystem->common.ExtendedMouseEvent = x11_shadow_input_extended_mouse_event;
1972 subsystem->composite = FALSE;
1973 subsystem->use_xshm = FALSE;
1974 subsystem->use_xfixes = TRUE;
1975 subsystem->use_xdamage = FALSE;
1976 subsystem->use_xinerama = TRUE;
1977 return &subsystem->common;
1980static void x11_shadow_subsystem_free(rdpShadowSubsystem* subsystem)
1985 x11_shadow_subsystem_uninit(subsystem);
1989FREERDP_ENTRY_POINT(FREERDP_API WINPR_ATTR_NODISCARD
const char* ShadowSubsystemName(
void))
1994FREERDP_ENTRY_POINT(FREERDP_API WINPR_ATTR_NODISCARD
int ShadowSubsystemEntry(
1995 RDP_SHADOW_ENTRY_POINTS* pEntryPoints))
2000 pEntryPoints->New = x11_shadow_subsystem_new;
2001 pEntryPoints->Free = x11_shadow_subsystem_free;
2002 pEntryPoints->Init = x11_shadow_subsystem_init;
2003 pEntryPoints->Uninit = x11_shadow_subsystem_uninit;
2004 pEntryPoints->Start = x11_shadow_subsystem_start;
2005 pEntryPoints->Stop = x11_shadow_subsystem_stop;
2006 pEntryPoints->EnumMonitors = x11_shadow_enum_monitors;