2011-10-21 05:28:59 +08:00
|
|
|
/**
|
2012-10-09 11:02:04 +08:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-10-21 05:28:59 +08:00
|
|
|
* X11 Graphical Objects
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2016-04-05 23:07:45 +08:00
|
|
|
* Copyright 2016 Thincast Technologies GmbH
|
|
|
|
* Copyright 2016 Armin Novak <armin.novak@thincast.com>
|
2011-10-21 05:28:59 +08:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 18:20:38 +08:00
|
|
|
#include <freerdp/config.h>
|
2012-08-15 05:20:53 +08:00
|
|
|
|
2011-10-21 06:18:45 +08:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
|
|
|
|
#ifdef WITH_XCURSOR
|
|
|
|
#include <X11/Xcursor/Xcursor.h>
|
|
|
|
#endif
|
|
|
|
|
2022-06-29 20:18:36 +08:00
|
|
|
#include <float.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2012-11-20 12:49:08 +08:00
|
|
|
#include <winpr/crt.h>
|
2022-01-19 16:27:39 +08:00
|
|
|
#include <winpr/assert.h>
|
2012-11-20 12:49:08 +08:00
|
|
|
|
2011-10-21 05:28:59 +08:00
|
|
|
#include <freerdp/codec/bitmap.h>
|
2012-07-25 03:05:22 +08:00
|
|
|
#include <freerdp/codec/rfx.h>
|
2011-10-21 05:28:59 +08:00
|
|
|
|
|
|
|
#include "xf_graphics.h"
|
2021-03-08 20:52:29 +08:00
|
|
|
#include "xf_event.h"
|
2011-10-21 05:28:59 +08:00
|
|
|
|
2014-09-12 23:13:01 +08:00
|
|
|
#include <freerdp/log.h>
|
|
|
|
#define TAG CLIENT_TAG("x11")
|
|
|
|
|
2022-07-04 14:52:17 +08:00
|
|
|
static BOOL xf_Pointer_Set(rdpContext* context, rdpPointer* pointer);
|
|
|
|
|
2017-01-25 15:33:36 +08:00
|
|
|
BOOL xf_decode_color(xfContext* xfc, const UINT32 srcColor, XColor* color)
|
2016-08-03 16:54:50 +08:00
|
|
|
{
|
2023-06-05 18:16:57 +08:00
|
|
|
UINT32 SrcFormat = 0;
|
2024-01-23 23:49:54 +08:00
|
|
|
BYTE r = 0;
|
|
|
|
BYTE g = 0;
|
|
|
|
BYTE b = 0;
|
|
|
|
BYTE a = 0;
|
2017-01-25 15:33:36 +08:00
|
|
|
|
|
|
|
if (!xfc || !color)
|
|
|
|
return FALSE;
|
|
|
|
|
2023-06-05 18:16:57 +08:00
|
|
|
rdpGdi* gdi = xfc->common.context.gdi;
|
2016-08-03 16:54:50 +08:00
|
|
|
|
2017-01-25 15:33:36 +08:00
|
|
|
if (!gdi)
|
2016-08-03 16:54:50 +08:00
|
|
|
return FALSE;
|
|
|
|
|
2023-06-05 18:16:57 +08:00
|
|
|
rdpSettings* settings = xfc->common.context.settings;
|
2016-08-03 16:54:50 +08:00
|
|
|
|
2017-01-25 15:33:36 +08:00
|
|
|
if (!settings)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-06-22 18:42:48 +08:00
|
|
|
switch (freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth))
|
2017-02-01 18:00:24 +08:00
|
|
|
{
|
|
|
|
case 32:
|
|
|
|
case 24:
|
|
|
|
SrcFormat = PIXEL_FORMAT_BGR24;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 16:
|
|
|
|
SrcFormat = PIXEL_FORMAT_RGB16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 15:
|
|
|
|
SrcFormat = PIXEL_FORMAT_RGB15;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
SrcFormat = PIXEL_FORMAT_RGB8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2022-04-28 11:43:31 +08:00
|
|
|
FreeRDPSplitColor(srcColor, SrcFormat, &r, &g, &b, &a, &gdi->palette);
|
2017-01-25 15:33:36 +08:00
|
|
|
color->blue = (unsigned short)(b << 8);
|
|
|
|
color->green = (unsigned short)(g << 8);
|
|
|
|
color->red = (unsigned short)(r << 8);
|
|
|
|
color->flags = DoRed | DoGreen | DoBlue;
|
|
|
|
|
|
|
|
if (XAllocColor(xfc->display, xfc->colormap, color) == 0)
|
|
|
|
return FALSE;
|
2016-08-03 16:54:50 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2022-07-04 14:52:17 +08:00
|
|
|
static BOOL xf_Pointer_GetCursorForCurrentScale(rdpContext* context, rdpPointer* pointer,
|
|
|
|
Cursor* cursor)
|
2020-09-08 23:12:27 +08:00
|
|
|
{
|
2023-05-31 14:29:24 +08:00
|
|
|
#if defined(WITH_XCURSOR) && defined(WITH_XRENDER)
|
2020-09-08 23:12:27 +08:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2022-04-29 20:21:31 +08:00
|
|
|
xfPointer* xpointer = (xfPointer*)pointer;
|
2020-10-05 15:45:45 +08:00
|
|
|
XcursorImage ci = { 0 };
|
2020-11-10 15:14:56 +08:00
|
|
|
int cursorIndex = -1;
|
2020-09-08 23:12:27 +08:00
|
|
|
|
|
|
|
if (!context || !pointer || !context->gdi)
|
|
|
|
return FALSE;
|
|
|
|
|
2023-06-05 18:16:57 +08:00
|
|
|
rdpSettings* settings = xfc->common.context.settings;
|
2020-09-08 23:12:27 +08:00
|
|
|
|
|
|
|
if (!settings)
|
|
|
|
return FALSE;
|
|
|
|
|
2024-09-02 20:57:55 +08:00
|
|
|
const double dw = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
|
|
|
|
const double xscale =
|
|
|
|
(freerdp_settings_get_bool(settings, FreeRDP_SmartSizing) ? 1.0 * xfc->scaledWidth / dw
|
|
|
|
: 1);
|
|
|
|
const double dh = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
|
|
|
|
const double yscale =
|
|
|
|
(freerdp_settings_get_bool(settings, FreeRDP_SmartSizing) ? 1.0 * xfc->scaledHeight / dh
|
|
|
|
: 1);
|
|
|
|
const UINT32 xTargetSize = MAX(1, (UINT32)lround(1.0 * pointer->width * xscale));
|
|
|
|
const UINT32 yTargetSize = MAX(1, (UINT32)lround(1.0 * pointer->height * yscale));
|
2020-09-08 23:12:27 +08:00
|
|
|
|
2023-01-23 19:03:18 +08:00
|
|
|
WLog_DBG(TAG, "scaled: %" PRIu32 "x%" PRIu32 ", desktop: %" PRIu32 "x%" PRIu32,
|
2023-10-13 15:48:44 +08:00
|
|
|
xfc->scaledWidth, xfc->scaledHeight,
|
|
|
|
freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
|
|
|
|
freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight));
|
2023-06-05 18:16:57 +08:00
|
|
|
for (UINT32 i = 0; i < xpointer->nCursors; i++)
|
2020-09-08 23:12:27 +08:00
|
|
|
{
|
2022-07-04 14:52:17 +08:00
|
|
|
if ((xpointer->cursorWidths[i] == xTargetSize) &&
|
|
|
|
(xpointer->cursorHeights[i] == yTargetSize))
|
2020-09-08 23:12:27 +08:00
|
|
|
{
|
|
|
|
cursorIndex = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cursorIndex == -1)
|
|
|
|
{
|
2023-06-05 18:16:57 +08:00
|
|
|
UINT32 CursorFormat = 0;
|
2020-09-08 23:12:27 +08:00
|
|
|
xf_lock_x11(xfc);
|
|
|
|
|
|
|
|
if (!xfc->invert)
|
|
|
|
CursorFormat = (!xfc->big_endian) ? PIXEL_FORMAT_RGBA32 : PIXEL_FORMAT_ABGR32;
|
|
|
|
else
|
|
|
|
CursorFormat = (!xfc->big_endian) ? PIXEL_FORMAT_BGRA32 : PIXEL_FORMAT_ARGB32;
|
|
|
|
|
|
|
|
if (xpointer->nCursors == xpointer->mCursors)
|
|
|
|
{
|
2024-01-23 23:49:54 +08:00
|
|
|
void* tmp2 = NULL;
|
2020-09-08 23:12:27 +08:00
|
|
|
xpointer->mCursors = (xpointer->mCursors == 0 ? 1 : xpointer->mCursors * 2);
|
|
|
|
|
2020-10-05 15:45:45 +08:00
|
|
|
tmp2 = realloc(xpointer->cursorWidths, sizeof(UINT32) * xpointer->mCursors);
|
|
|
|
if (!tmp2)
|
2020-09-08 23:12:27 +08:00
|
|
|
{
|
|
|
|
xf_unlock_x11(xfc);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-10-05 15:45:45 +08:00
|
|
|
xpointer->cursorWidths = tmp2;
|
|
|
|
|
|
|
|
tmp2 = realloc(xpointer->cursorHeights, sizeof(UINT32) * xpointer->mCursors);
|
|
|
|
if (!tmp2)
|
2020-09-08 23:12:27 +08:00
|
|
|
{
|
|
|
|
xf_unlock_x11(xfc);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-10-05 15:45:45 +08:00
|
|
|
xpointer->cursorHeights = (UINT32*)tmp2;
|
|
|
|
|
|
|
|
tmp2 = realloc(xpointer->cursors, sizeof(Cursor) * xpointer->mCursors);
|
|
|
|
if (!tmp2)
|
2020-09-08 23:12:27 +08:00
|
|
|
{
|
|
|
|
xf_unlock_x11(xfc);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-10-05 15:45:45 +08:00
|
|
|
xpointer->cursors = (Cursor*)tmp2;
|
2020-09-08 23:12:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ci.version = XCURSOR_IMAGE_VERSION;
|
|
|
|
ci.size = sizeof(ci);
|
|
|
|
ci.width = xTargetSize;
|
|
|
|
ci.height = yTargetSize;
|
2024-09-02 20:57:55 +08:00
|
|
|
ci.xhot = (XcursorDim)lround(1.0 * pointer->xPos * xscale);
|
|
|
|
ci.yhot = (XcursorDim)lround(1.0 * pointer->yPos * yscale);
|
2023-08-22 15:41:28 +08:00
|
|
|
const size_t size = 1ull * ci.height * ci.width * FreeRDPGetBytesPerPixel(CursorFormat);
|
2020-09-08 23:12:27 +08:00
|
|
|
|
2023-06-05 18:16:57 +08:00
|
|
|
void* tmp = winpr_aligned_malloc(size, 16);
|
2020-10-05 15:45:45 +08:00
|
|
|
if (!tmp)
|
2020-09-08 23:12:27 +08:00
|
|
|
{
|
|
|
|
xf_unlock_x11(xfc);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-10-05 15:45:45 +08:00
|
|
|
ci.pixels = (XcursorPixel*)tmp;
|
2020-09-08 23:12:27 +08:00
|
|
|
|
2022-07-04 15:53:41 +08:00
|
|
|
const double xs = fabs(fabs(xscale) - 1.0);
|
|
|
|
const double ys = fabs(fabs(yscale) - 1.0);
|
2022-07-04 18:13:20 +08:00
|
|
|
|
|
|
|
WLog_DBG(TAG,
|
2023-01-23 19:03:18 +08:00
|
|
|
"cursorIndex %" PRId32 " scaling pointer %" PRIu32 "x%" PRIu32 " --> %" PRIu32
|
2022-07-04 18:13:20 +08:00
|
|
|
"x%" PRIu32 " [%lfx%lf]",
|
2023-01-23 19:03:18 +08:00
|
|
|
cursorIndex, pointer->width, pointer->height, ci.width, ci.height, xscale, yscale);
|
2022-07-04 15:53:41 +08:00
|
|
|
if ((xs > DBL_EPSILON) || (ys > DBL_EPSILON))
|
2020-09-08 23:12:27 +08:00
|
|
|
{
|
|
|
|
if (!freerdp_image_scale((BYTE*)ci.pixels, CursorFormat, 0, 0, 0, ci.width, ci.height,
|
|
|
|
(BYTE*)xpointer->cursorPixels, CursorFormat, 0, 0, 0,
|
|
|
|
pointer->width, pointer->height))
|
|
|
|
{
|
2022-05-11 17:28:55 +08:00
|
|
|
winpr_aligned_free(tmp);
|
2020-09-08 23:12:27 +08:00
|
|
|
xf_unlock_x11(xfc);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ci.pixels = xpointer->cursorPixels;
|
|
|
|
}
|
|
|
|
|
|
|
|
cursorIndex = xpointer->nCursors;
|
|
|
|
xpointer->cursorWidths[cursorIndex] = ci.width;
|
|
|
|
xpointer->cursorHeights[cursorIndex] = ci.height;
|
|
|
|
xpointer->cursors[cursorIndex] = XcursorImageLoadCursor(xfc->display, &ci);
|
|
|
|
xpointer->nCursors += 1;
|
2020-10-05 15:45:45 +08:00
|
|
|
|
2022-05-11 17:28:55 +08:00
|
|
|
winpr_aligned_free(tmp);
|
2020-09-08 23:12:27 +08:00
|
|
|
|
|
|
|
xf_unlock_x11(xfc);
|
|
|
|
}
|
2022-07-04 18:13:20 +08:00
|
|
|
else
|
|
|
|
{
|
2023-01-23 19:03:18 +08:00
|
|
|
WLog_DBG(TAG, "using cached cursor %" PRId32, cursorIndex);
|
2022-07-04 18:13:20 +08:00
|
|
|
}
|
2020-09-08 23:12:27 +08:00
|
|
|
|
|
|
|
cursor[0] = xpointer->cursors[cursorIndex];
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-10-21 06:18:45 +08:00
|
|
|
/* Pointer Class */
|
2020-12-03 21:09:16 +08:00
|
|
|
static Window xf_Pointer_get_window(xfContext* xfc)
|
|
|
|
{
|
|
|
|
if (!xfc)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "xf_Pointer: Invalid context");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (xfc->remote_app)
|
|
|
|
{
|
|
|
|
if (!xfc->appWindow)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "xf_Pointer: Invalid appWindow");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return xfc->appWindow->handle;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!xfc->window)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "xf_Pointer: Invalid window");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return xfc->window->handle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-04 14:52:17 +08:00
|
|
|
BOOL xf_pointer_update_scale(xfContext* xfc)
|
|
|
|
{
|
2024-01-23 23:49:54 +08:00
|
|
|
xfPointer* pointer = NULL;
|
2022-07-04 14:52:17 +08:00
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
|
|
|
|
pointer = xfc->pointer;
|
|
|
|
if (!pointer)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return xf_Pointer_Set(&xfc->common.context, &xfc->pointer->pointer);
|
|
|
|
}
|
|
|
|
|
2016-04-05 23:07:45 +08:00
|
|
|
static BOOL xf_Pointer_New(rdpContext* context, rdpPointer* pointer)
|
2011-10-21 06:18:45 +08:00
|
|
|
{
|
2022-07-04 18:13:20 +08:00
|
|
|
BOOL rc = FALSE;
|
|
|
|
|
2016-09-09 14:58:26 +08:00
|
|
|
#ifdef WITH_XCURSOR
|
2024-01-23 23:49:54 +08:00
|
|
|
UINT32 CursorFormat = 0;
|
|
|
|
size_t size = 0;
|
2019-11-06 22:24:51 +08:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2016-09-09 14:58:26 +08:00
|
|
|
xfPointer* xpointer = (xfPointer*)pointer;
|
2016-08-03 20:16:20 +08:00
|
|
|
|
|
|
|
if (!context || !pointer || !context->gdi)
|
2022-07-04 18:13:20 +08:00
|
|
|
goto fail;
|
2016-08-03 20:16:20 +08:00
|
|
|
|
2016-10-10 15:19:43 +08:00
|
|
|
if (!xfc->invert)
|
2017-09-18 16:47:56 +08:00
|
|
|
CursorFormat = (!xfc->big_endian) ? PIXEL_FORMAT_RGBA32 : PIXEL_FORMAT_ABGR32;
|
2016-10-10 15:19:43 +08:00
|
|
|
else
|
2017-09-18 16:47:56 +08:00
|
|
|
CursorFormat = (!xfc->big_endian) ? PIXEL_FORMAT_BGRA32 : PIXEL_FORMAT_ARGB32;
|
2016-10-10 15:19:43 +08:00
|
|
|
|
2020-09-08 23:12:27 +08:00
|
|
|
xpointer->nCursors = 0;
|
|
|
|
xpointer->mCursors = 0;
|
|
|
|
|
2023-08-22 15:41:28 +08:00
|
|
|
size = 1ull * pointer->height * pointer->width * FreeRDPGetBytesPerPixel(CursorFormat);
|
2020-09-08 23:12:27 +08:00
|
|
|
|
2022-05-11 17:28:55 +08:00
|
|
|
if (!(xpointer->cursorPixels = (XcursorPixel*)winpr_aligned_malloc(size, 16)))
|
2022-07-04 18:13:20 +08:00
|
|
|
goto fail;
|
2011-10-21 06:18:45 +08:00
|
|
|
|
2016-10-04 20:14:39 +08:00
|
|
|
if (!freerdp_image_copy_from_pointer_data(
|
2020-09-08 23:12:27 +08:00
|
|
|
(BYTE*)xpointer->cursorPixels, CursorFormat, 0, 0, 0, pointer->width, pointer->height,
|
2019-11-06 22:24:51 +08:00
|
|
|
pointer->xorMaskData, pointer->lengthXorMask, pointer->andMaskData,
|
|
|
|
pointer->lengthAndMask, pointer->xorBpp, &context->gdi->palette))
|
2015-08-05 23:32:46 +08:00
|
|
|
{
|
2022-05-11 17:28:55 +08:00
|
|
|
winpr_aligned_free(xpointer->cursorPixels);
|
2022-07-04 18:13:20 +08:00
|
|
|
goto fail;
|
2011-10-21 06:18:45 +08:00
|
|
|
}
|
|
|
|
|
2012-10-28 03:01:22 +08:00
|
|
|
#endif
|
2022-07-04 18:13:20 +08:00
|
|
|
|
2022-09-05 15:48:30 +08:00
|
|
|
rc = TRUE;
|
|
|
|
|
2022-07-04 18:13:20 +08:00
|
|
|
fail:
|
2023-01-23 19:03:18 +08:00
|
|
|
WLog_DBG(TAG, "%p", rc ? pointer : NULL);
|
2022-07-04 18:13:20 +08:00
|
|
|
return rc;
|
2011-10-21 06:18:45 +08:00
|
|
|
}
|
|
|
|
|
2016-04-05 23:07:45 +08:00
|
|
|
static void xf_Pointer_Free(rdpContext* context, rdpPointer* pointer)
|
2011-10-21 06:18:45 +08:00
|
|
|
{
|
2023-01-23 19:03:18 +08:00
|
|
|
WLog_DBG(TAG, "%p", pointer);
|
2022-07-04 18:13:20 +08:00
|
|
|
|
2012-10-28 03:01:22 +08:00
|
|
|
#ifdef WITH_XCURSOR
|
2019-11-06 22:24:51 +08:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2020-09-08 23:12:27 +08:00
|
|
|
xfPointer* xpointer = (xfPointer*)pointer;
|
|
|
|
|
2020-03-04 18:33:06 +08:00
|
|
|
xf_lock_x11(xfc);
|
2013-02-07 10:57:49 +08:00
|
|
|
|
2022-05-11 17:28:55 +08:00
|
|
|
winpr_aligned_free(xpointer->cursorPixels);
|
2020-09-08 23:12:27 +08:00
|
|
|
free(xpointer->cursorWidths);
|
|
|
|
free(xpointer->cursorHeights);
|
|
|
|
|
2024-01-30 17:25:38 +08:00
|
|
|
for (UINT32 i = 0; i < xpointer->nCursors; i++)
|
2020-09-08 23:12:27 +08:00
|
|
|
{
|
|
|
|
XFreeCursor(xfc->display, xpointer->cursors[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(xpointer->cursors);
|
|
|
|
xpointer->nCursors = 0;
|
|
|
|
xpointer->mCursors = 0;
|
2013-02-07 10:57:49 +08:00
|
|
|
|
2020-03-04 18:33:06 +08:00
|
|
|
xf_unlock_x11(xfc);
|
2012-10-28 03:01:22 +08:00
|
|
|
#endif
|
2011-10-21 06:18:45 +08:00
|
|
|
}
|
|
|
|
|
2022-04-28 03:31:14 +08:00
|
|
|
static BOOL xf_Pointer_Set(rdpContext* context, rdpPointer* pointer)
|
2011-10-21 06:18:45 +08:00
|
|
|
{
|
2023-01-23 19:03:18 +08:00
|
|
|
WLog_DBG(TAG, "%p", pointer);
|
2012-10-28 03:01:22 +08:00
|
|
|
#ifdef WITH_XCURSOR
|
2019-11-06 22:24:51 +08:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2020-12-03 21:09:16 +08:00
|
|
|
Window handle = xf_Pointer_get_window(xfc);
|
2022-04-28 03:02:18 +08:00
|
|
|
|
2022-07-04 14:52:17 +08:00
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
WINPR_ASSERT(pointer);
|
|
|
|
|
2022-04-29 20:21:31 +08:00
|
|
|
xfc->pointer = (xfPointer*)pointer;
|
2013-08-04 04:13:39 +08:00
|
|
|
|
2011-11-25 02:01:34 +08:00
|
|
|
/* in RemoteApp mode, window can be null if none has had focus */
|
|
|
|
|
2020-12-03 21:09:16 +08:00
|
|
|
if (handle)
|
2020-09-08 23:12:27 +08:00
|
|
|
{
|
2022-07-04 14:52:17 +08:00
|
|
|
if (!xf_Pointer_GetCursorForCurrentScale(context, pointer, &(xfc->pointer->cursor)))
|
2020-09-08 23:12:27 +08:00
|
|
|
return FALSE;
|
|
|
|
xf_lock_x11(xfc);
|
2020-12-03 21:09:16 +08:00
|
|
|
XDefineCursor(xfc->display, handle, xfc->pointer->cursor);
|
2020-09-08 23:12:27 +08:00
|
|
|
xf_unlock_x11(xfc);
|
|
|
|
}
|
2022-07-04 18:13:20 +08:00
|
|
|
else
|
|
|
|
{
|
2023-01-23 19:03:18 +08:00
|
|
|
WLog_WARN(TAG, "handle=%ld", handle);
|
2022-07-04 18:13:20 +08:00
|
|
|
}
|
2012-10-28 03:01:22 +08:00
|
|
|
#endif
|
2015-04-14 16:14:23 +08:00
|
|
|
return TRUE;
|
2011-10-21 06:18:45 +08:00
|
|
|
}
|
2012-02-24 20:44:23 +08:00
|
|
|
|
2016-04-05 23:07:45 +08:00
|
|
|
static BOOL xf_Pointer_SetNull(rdpContext* context)
|
2012-02-24 20:44:23 +08:00
|
|
|
{
|
2023-01-23 19:03:18 +08:00
|
|
|
WLog_DBG(TAG, "called");
|
2012-10-28 03:01:22 +08:00
|
|
|
#ifdef WITH_XCURSOR
|
2019-11-06 22:24:51 +08:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2012-02-24 20:44:23 +08:00
|
|
|
static Cursor nullcursor = None;
|
2020-12-03 21:09:16 +08:00
|
|
|
Window handle = xf_Pointer_get_window(xfc);
|
2020-03-04 18:33:06 +08:00
|
|
|
xf_lock_x11(xfc);
|
2013-02-07 10:57:49 +08:00
|
|
|
|
2012-02-24 20:44:23 +08:00
|
|
|
if (nullcursor == None)
|
|
|
|
{
|
2022-10-13 22:25:36 +08:00
|
|
|
XcursorImage ci = { 0 };
|
2012-02-24 20:44:23 +08:00
|
|
|
XcursorPixel xp = 0;
|
2022-10-13 22:25:36 +08:00
|
|
|
|
2012-02-24 20:44:23 +08:00
|
|
|
ci.version = XCURSOR_IMAGE_VERSION;
|
|
|
|
ci.size = sizeof(ci);
|
|
|
|
ci.width = ci.height = 1;
|
|
|
|
ci.xhot = ci.yhot = 0;
|
|
|
|
ci.pixels = &xp;
|
2013-06-13 06:57:25 +08:00
|
|
|
nullcursor = XcursorImageLoadCursor(xfc->display, &ci);
|
2012-02-24 20:44:23 +08:00
|
|
|
}
|
2012-10-28 03:01:22 +08:00
|
|
|
|
2013-08-04 04:13:39 +08:00
|
|
|
xfc->pointer = NULL;
|
|
|
|
|
2020-12-03 21:09:16 +08:00
|
|
|
if ((handle) && (nullcursor != None))
|
|
|
|
XDefineCursor(xfc->display, handle, nullcursor);
|
2013-02-07 10:57:49 +08:00
|
|
|
|
2020-03-04 18:33:06 +08:00
|
|
|
xf_unlock_x11(xfc);
|
2012-10-28 03:01:22 +08:00
|
|
|
#endif
|
2015-04-14 16:14:23 +08:00
|
|
|
return TRUE;
|
2012-02-24 20:44:23 +08:00
|
|
|
}
|
|
|
|
|
2016-04-05 23:07:45 +08:00
|
|
|
static BOOL xf_Pointer_SetDefault(rdpContext* context)
|
2012-02-24 20:44:23 +08:00
|
|
|
{
|
2023-01-23 19:03:18 +08:00
|
|
|
WLog_DBG(TAG, "called");
|
2012-10-28 03:01:22 +08:00
|
|
|
#ifdef WITH_XCURSOR
|
2019-11-06 22:24:51 +08:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2020-12-03 21:09:16 +08:00
|
|
|
Window handle = xf_Pointer_get_window(xfc);
|
2020-03-04 18:33:06 +08:00
|
|
|
xf_lock_x11(xfc);
|
2013-08-04 04:13:39 +08:00
|
|
|
xfc->pointer = NULL;
|
|
|
|
|
2020-12-03 21:09:16 +08:00
|
|
|
if (handle)
|
|
|
|
XUndefineCursor(xfc->display, handle);
|
2013-02-07 10:57:49 +08:00
|
|
|
|
2020-03-04 18:33:06 +08:00
|
|
|
xf_unlock_x11(xfc);
|
2012-10-28 03:01:22 +08:00
|
|
|
#endif
|
2015-04-14 16:14:23 +08:00
|
|
|
return TRUE;
|
2012-02-24 20:44:23 +08:00
|
|
|
}
|
|
|
|
|
2016-04-05 23:07:45 +08:00
|
|
|
static BOOL xf_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y)
|
2015-02-02 22:32:49 +08:00
|
|
|
{
|
2019-11-06 22:24:51 +08:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2023-06-05 18:16:57 +08:00
|
|
|
XWindowAttributes current = { 0 };
|
|
|
|
XSetWindowAttributes tmp = { 0 };
|
2015-04-14 16:14:23 +08:00
|
|
|
BOOL ret = FALSE;
|
2023-06-05 18:16:57 +08:00
|
|
|
Status rc = 0;
|
2020-12-03 21:09:16 +08:00
|
|
|
Window handle = xf_Pointer_get_window(xfc);
|
2015-02-02 22:32:49 +08:00
|
|
|
|
2020-12-03 21:09:16 +08:00
|
|
|
if (!handle)
|
|
|
|
{
|
2023-01-23 19:03:18 +08:00
|
|
|
WLog_WARN(TAG, "focus %d, handle%lu", xfc->focused, handle);
|
2020-12-03 21:09:16 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-01-23 19:03:18 +08:00
|
|
|
WLog_DBG(TAG, "%" PRIu32 "x%" PRIu32, x, y);
|
2023-06-26 21:59:21 +08:00
|
|
|
if (!xfc->focused)
|
2015-04-14 16:14:23 +08:00
|
|
|
return TRUE;
|
2015-02-02 22:32:49 +08:00
|
|
|
|
2021-03-08 20:52:29 +08:00
|
|
|
xf_adjust_coordinates_to_screen(xfc, &x, &y);
|
|
|
|
|
2020-03-04 18:33:06 +08:00
|
|
|
xf_lock_x11(xfc);
|
2015-02-02 22:32:49 +08:00
|
|
|
|
2020-12-03 21:09:16 +08:00
|
|
|
rc = XGetWindowAttributes(xfc->display, handle, ¤t);
|
|
|
|
if (rc == 0)
|
|
|
|
{
|
2023-01-23 19:03:18 +08:00
|
|
|
WLog_WARN(TAG, "XGetWindowAttributes==%d", rc);
|
2015-02-04 05:08:34 +08:00
|
|
|
goto out;
|
2020-12-03 21:09:16 +08:00
|
|
|
}
|
2015-02-04 05:08:34 +08:00
|
|
|
|
|
|
|
tmp.event_mask = (current.your_event_mask & ~(PointerMotionMask));
|
2016-07-14 22:08:06 +08:00
|
|
|
|
2020-12-03 21:09:16 +08:00
|
|
|
rc = XChangeWindowAttributes(xfc->display, handle, CWEventMask, &tmp);
|
|
|
|
if (rc == 0)
|
|
|
|
{
|
2023-01-23 19:03:18 +08:00
|
|
|
WLog_WARN(TAG, "XChangeWindowAttributes==%d", rc);
|
2015-02-04 05:08:34 +08:00
|
|
|
goto out;
|
2020-12-03 21:09:16 +08:00
|
|
|
}
|
2015-02-04 05:08:34 +08:00
|
|
|
|
2023-06-26 21:59:21 +08:00
|
|
|
rc = XWarpPointer(xfc->display, handle, handle, 0, 0, 0, 0, x, y);
|
2020-12-03 21:09:16 +08:00
|
|
|
if (rc == 0)
|
2023-01-23 19:03:18 +08:00
|
|
|
WLog_WARN(TAG, "XWarpPointer==%d", rc);
|
2015-02-04 05:08:34 +08:00
|
|
|
tmp.event_mask = current.your_event_mask;
|
2020-12-03 21:09:16 +08:00
|
|
|
rc = XChangeWindowAttributes(xfc->display, handle, CWEventMask, &tmp);
|
|
|
|
if (rc == 0)
|
2023-01-23 19:03:18 +08:00
|
|
|
WLog_WARN(TAG, "2.try XChangeWindowAttributes==%d", rc);
|
2015-04-14 16:14:23 +08:00
|
|
|
ret = TRUE;
|
2015-02-04 05:08:34 +08:00
|
|
|
out:
|
2020-03-04 18:33:06 +08:00
|
|
|
xf_unlock_x11(xfc);
|
2015-04-14 16:14:23 +08:00
|
|
|
return ret;
|
2015-02-02 22:32:49 +08:00
|
|
|
}
|
|
|
|
|
2011-10-21 06:18:45 +08:00
|
|
|
/* Graphics Module */
|
2016-07-18 20:16:13 +08:00
|
|
|
BOOL xf_register_pointer(rdpGraphics* graphics)
|
|
|
|
{
|
2023-06-26 21:39:27 +08:00
|
|
|
rdpPointer pointer = { 0 };
|
|
|
|
|
|
|
|
pointer.size = sizeof(xfPointer);
|
|
|
|
pointer.New = xf_Pointer_New;
|
|
|
|
pointer.Free = xf_Pointer_Free;
|
|
|
|
pointer.Set = xf_Pointer_Set;
|
|
|
|
pointer.SetNull = xf_Pointer_SetNull;
|
|
|
|
pointer.SetDefault = xf_Pointer_SetDefault;
|
|
|
|
pointer.SetPosition = xf_Pointer_SetPosition;
|
|
|
|
graphics_register_pointer(graphics, &pointer);
|
2016-07-18 20:16:13 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
2011-10-21 06:18:45 +08:00
|
|
|
|
2016-08-03 20:16:20 +08:00
|
|
|
UINT32 xf_get_local_color_format(xfContext* xfc, BOOL aligned)
|
|
|
|
{
|
2024-01-23 23:49:54 +08:00
|
|
|
UINT32 DstFormat = 0;
|
2017-01-26 17:44:19 +08:00
|
|
|
BOOL invert = FALSE;
|
2016-08-03 20:16:20 +08:00
|
|
|
|
|
|
|
if (!xfc)
|
|
|
|
return 0;
|
|
|
|
|
2017-01-26 17:44:19 +08:00
|
|
|
invert = xfc->invert;
|
|
|
|
|
2022-11-28 14:31:19 +08:00
|
|
|
WINPR_ASSERT(xfc->depth != 0);
|
2016-08-03 20:16:20 +08:00
|
|
|
if (xfc->depth == 32)
|
2016-08-04 03:22:06 +08:00
|
|
|
DstFormat = (!invert) ? PIXEL_FORMAT_RGBA32 : PIXEL_FORMAT_BGRA32;
|
2022-03-19 20:19:41 +08:00
|
|
|
else if (xfc->depth == 30)
|
|
|
|
DstFormat = (!invert) ? PIXEL_FORMAT_RGBX32_DEPTH30 : PIXEL_FORMAT_BGRX32_DEPTH30;
|
2016-08-03 20:16:20 +08:00
|
|
|
else if (xfc->depth == 24)
|
|
|
|
{
|
|
|
|
if (aligned)
|
2016-08-04 03:22:06 +08:00
|
|
|
DstFormat = (!invert) ? PIXEL_FORMAT_RGBX32 : PIXEL_FORMAT_BGRX32;
|
2016-08-03 20:16:20 +08:00
|
|
|
else
|
2016-08-04 03:22:06 +08:00
|
|
|
DstFormat = (!invert) ? PIXEL_FORMAT_RGB24 : PIXEL_FORMAT_BGR24;
|
2016-08-03 20:16:20 +08:00
|
|
|
}
|
|
|
|
else if (xfc->depth == 16)
|
2017-01-20 00:14:16 +08:00
|
|
|
DstFormat = PIXEL_FORMAT_RGB16;
|
2016-08-03 20:16:20 +08:00
|
|
|
else if (xfc->depth == 15)
|
2017-01-20 00:14:16 +08:00
|
|
|
DstFormat = PIXEL_FORMAT_RGB15;
|
2016-08-03 20:16:20 +08:00
|
|
|
else
|
2016-08-04 03:22:06 +08:00
|
|
|
DstFormat = (!invert) ? PIXEL_FORMAT_RGBX32 : PIXEL_FORMAT_BGRX32;
|
2016-08-03 20:16:20 +08:00
|
|
|
|
|
|
|
return DstFormat;
|
|
|
|
}
|