2011-10-21 01:28:59 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-10-21 01:28:59 +04:00
|
|
|
* X11 Graphical Objects
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2016-04-05 18:07:45 +03:00
|
|
|
* Copyright 2016 Thincast Technologies GmbH
|
|
|
|
* Copyright 2016 Armin Novak <armin.novak@thincast.com>
|
2011-10-21 01:28:59 +04: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 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2012-08-15 01:20:53 +04:00
|
|
|
|
2011-10-21 02:18:45 +04:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
|
|
|
|
#ifdef WITH_XCURSOR
|
|
|
|
#include <X11/Xcursor/Xcursor.h>
|
|
|
|
#endif
|
|
|
|
|
2022-06-29 15:18:36 +03:00
|
|
|
#include <float.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
#include <winpr/crt.h>
|
2022-01-19 11:27:39 +03:00
|
|
|
#include <winpr/assert.h>
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2011-10-21 01:28:59 +04:00
|
|
|
#include <freerdp/codec/bitmap.h>
|
2012-07-24 23:05:22 +04:00
|
|
|
#include <freerdp/codec/rfx.h>
|
2011-10-21 01:28:59 +04:00
|
|
|
|
|
|
|
#include "xf_graphics.h"
|
2014-12-15 18:34:09 +03:00
|
|
|
#include "xf_gdi.h"
|
2021-03-08 15:52:29 +03:00
|
|
|
#include "xf_event.h"
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2014-09-12 19:13:01 +04:00
|
|
|
#include <freerdp/log.h>
|
|
|
|
#define TAG CLIENT_TAG("x11")
|
|
|
|
|
2022-07-04 09:52:17 +03:00
|
|
|
static BOOL xf_Pointer_Set(rdpContext* context, rdpPointer* pointer);
|
|
|
|
|
2017-01-25 10:33:36 +03:00
|
|
|
BOOL xf_decode_color(xfContext* xfc, const UINT32 srcColor, XColor* color)
|
2016-08-03 11:54:50 +03:00
|
|
|
{
|
2017-01-25 10:33:36 +03:00
|
|
|
rdpGdi* gdi;
|
|
|
|
rdpSettings* settings;
|
2016-08-03 11:54:50 +03:00
|
|
|
UINT32 SrcFormat;
|
2017-01-25 10:33:36 +03:00
|
|
|
BYTE r, g, b, a;
|
|
|
|
|
|
|
|
if (!xfc || !color)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
gdi = xfc->common.context.gdi;
|
2016-08-03 11:54:50 +03:00
|
|
|
|
2017-01-25 10:33:36 +03:00
|
|
|
if (!gdi)
|
2016-08-03 11:54:50 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
settings = xfc->common.context.settings;
|
2016-08-03 11:54:50 +03:00
|
|
|
|
2017-01-25 10:33:36 +03:00
|
|
|
if (!settings)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-06-22 13:42:48 +03:00
|
|
|
switch (freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth))
|
2017-02-01 13:00:24 +03: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 06:43:31 +03:00
|
|
|
FreeRDPSplitColor(srcColor, SrcFormat, &r, &g, &b, &a, &gdi->palette);
|
2017-01-25 10:33:36 +03: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 11:54:50 +03:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-10-21 02:18:45 +04:00
|
|
|
/* Bitmap Class */
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL xf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2017-02-20 20:31:58 +03:00
|
|
|
BOOL rc = FALSE;
|
|
|
|
UINT32 depth;
|
2014-09-17 20:17:41 +04:00
|
|
|
BYTE* data;
|
2016-08-03 15:16:20 +03:00
|
|
|
rdpGdi* gdi;
|
2017-03-28 12:49:47 +03:00
|
|
|
xfBitmap* xbitmap = (xfBitmap*)bitmap;
|
2019-11-06 17:24:51 +03:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
|
|
|
if (!context || !bitmap || !context->gdi)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-08-03 15:16:20 +03:00
|
|
|
gdi = context->gdi;
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_lock_x11(xfc);
|
2022-04-28 06:43:31 +03:00
|
|
|
depth = FreeRDPGetBitsPerPixel(bitmap->format);
|
2022-11-28 09:31:19 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(xfc->depth != 0);
|
2019-11-06 17:24:51 +03:00
|
|
|
xbitmap->pixmap =
|
|
|
|
XCreatePixmap(xfc->display, xfc->drawable, bitmap->width, bitmap->height, xfc->depth);
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2017-03-28 12:49:47 +03:00
|
|
|
if (!xbitmap->pixmap)
|
2017-02-20 20:31:58 +03:00
|
|
|
goto unlock;
|
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
if (bitmap->data)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2014-09-12 09:03:19 +04:00
|
|
|
XSetFunction(xfc->display, xfc->gc, GXcopy);
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2019-02-07 16:40:36 +03:00
|
|
|
if ((INT64)depth != xfc->depth)
|
2014-09-17 20:17:41 +04:00
|
|
|
{
|
2022-05-11 12:28:55 +03:00
|
|
|
if (!(data = winpr_aligned_malloc(bitmap->width * bitmap->height * 4ULL, 16)))
|
2017-02-20 20:31:58 +03:00
|
|
|
goto unlock;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!freerdp_image_copy(data, gdi->dstFormat, 0, 0, 0, bitmap->width, bitmap->height,
|
|
|
|
bitmap->data, bitmap->format, 0, 0, 0, &context->gdi->palette,
|
|
|
|
FREERDP_FLIP_NONE))
|
2015-04-28 18:00:41 +03:00
|
|
|
{
|
2022-05-11 12:28:55 +03:00
|
|
|
winpr_aligned_free(data);
|
2017-02-20 20:31:58 +03:00
|
|
|
goto unlock;
|
2015-04-28 18:00:41 +03:00
|
|
|
}
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2022-05-11 12:28:55 +03:00
|
|
|
winpr_aligned_free(bitmap->data);
|
2014-09-17 20:17:41 +04:00
|
|
|
bitmap->data = data;
|
2016-08-03 15:16:20 +03:00
|
|
|
bitmap->format = gdi->dstFormat;
|
2014-09-17 20:17:41 +04:00
|
|
|
}
|
|
|
|
|
2022-11-28 09:31:19 +03:00
|
|
|
WINPR_ASSERT(xfc->depth != 0);
|
2019-11-06 17:24:51 +03:00
|
|
|
xbitmap->image =
|
|
|
|
XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0, (char*)bitmap->data,
|
|
|
|
bitmap->width, bitmap->height, xfc->scanline_pad, 0);
|
2018-10-19 18:02:33 +03:00
|
|
|
|
2017-03-28 12:49:47 +03:00
|
|
|
if (!xbitmap->image)
|
2017-02-20 20:31:58 +03:00
|
|
|
goto unlock;
|
|
|
|
|
2017-09-18 11:47:56 +03:00
|
|
|
xbitmap->image->byte_order = LSBFirst;
|
|
|
|
xbitmap->image->bitmap_bit_order = LSBFirst;
|
2017-03-28 12:49:47 +03:00
|
|
|
XPutImage(xfc->display, xbitmap->pixmap, xfc->gc, xbitmap->image, 0, 0, 0, 0, bitmap->width,
|
2016-10-04 10:00:00 +03:00
|
|
|
bitmap->height);
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
rc = TRUE;
|
|
|
|
unlock:
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_unlock_x11(xfc);
|
2017-02-20 20:31:58 +03:00
|
|
|
return rc;
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static void xf_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2017-03-28 12:49:47 +03:00
|
|
|
xfBitmap* xbitmap = (xfBitmap*)bitmap;
|
|
|
|
|
|
|
|
if (!xfc || !xbitmap)
|
|
|
|
return;
|
|
|
|
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_lock_x11(xfc);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2018-04-04 11:46:14 +03:00
|
|
|
if (xbitmap->pixmap != 0)
|
2018-02-12 13:14:54 +03:00
|
|
|
{
|
2017-03-28 12:49:47 +03:00
|
|
|
XFreePixmap(xfc->display, xbitmap->pixmap);
|
2018-04-04 11:46:14 +03:00
|
|
|
xbitmap->pixmap = 0;
|
2018-02-12 13:14:54 +03:00
|
|
|
}
|
2017-03-28 12:49:47 +03:00
|
|
|
|
|
|
|
if (xbitmap->image)
|
2018-02-12 13:14:54 +03:00
|
|
|
{
|
2018-02-13 12:18:43 +03:00
|
|
|
xbitmap->image->data = NULL;
|
2018-02-12 12:02:35 +03:00
|
|
|
XDestroyImage(xbitmap->image);
|
2018-02-12 13:14:54 +03:00
|
|
|
xbitmap->image = NULL;
|
|
|
|
}
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_unlock_x11(xfc);
|
2022-05-11 12:28:55 +03:00
|
|
|
winpr_aligned_free(bitmap->data);
|
2018-02-13 12:18:43 +03:00
|
|
|
free(xbitmap);
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL xf_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2011-10-21 05:34:55 +04:00
|
|
|
int width, height;
|
2019-11-06 17:24:51 +03:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2017-03-28 12:49:47 +03:00
|
|
|
xfBitmap* xbitmap = (xfBitmap*)bitmap;
|
2017-02-20 20:31:58 +03:00
|
|
|
BOOL ret;
|
2017-03-28 12:49:47 +03:00
|
|
|
|
|
|
|
if (!context || !xbitmap)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-10-21 05:34:55 +04:00
|
|
|
width = bitmap->right - bitmap->left + 1;
|
|
|
|
height = bitmap->bottom - bitmap->top + 1;
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_lock_x11(xfc);
|
2013-06-13 02:57:25 +04:00
|
|
|
XSetFunction(xfc->display, xfc->gc, GXcopy);
|
2019-11-06 17:24:51 +03:00
|
|
|
XPutImage(xfc->display, xfc->primary, xfc->gc, xbitmap->image, 0, 0, bitmap->left, bitmap->top,
|
|
|
|
width, height);
|
2015-04-17 17:21:55 +03:00
|
|
|
ret = gdi_InvalidateRegion(xfc->hdc, bitmap->left, bitmap->top, width, height);
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_unlock_x11(xfc);
|
2017-02-20 20:31:58 +03:00
|
|
|
return ret;
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL xf_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, BOOL primary)
|
2011-10-21 02:18:45 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2017-09-04 19:22:49 +03:00
|
|
|
|
|
|
|
if (!context || (!bitmap && !primary))
|
|
|
|
return FALSE;
|
|
|
|
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_lock_x11(xfc);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2011-10-21 02:18:45 +04:00
|
|
|
if (primary)
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->drawing = xfc->primary;
|
2011-10-21 02:18:45 +04:00
|
|
|
else
|
2019-11-06 17:24:51 +03:00
|
|
|
xfc->drawing = ((xfBitmap*)bitmap)->pixmap;
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_unlock_x11(xfc);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-10-21 02:18:45 +04:00
|
|
|
}
|
|
|
|
|
2022-07-04 09:52:17 +03:00
|
|
|
static BOOL xf_Pointer_GetCursorForCurrentScale(rdpContext* context, rdpPointer* pointer,
|
|
|
|
Cursor* cursor)
|
2020-09-08 18:12:27 +03:00
|
|
|
{
|
2023-05-31 09:29:24 +03:00
|
|
|
#if defined(WITH_XCURSOR) && defined(WITH_XRENDER)
|
2020-09-08 18:12:27 +03:00
|
|
|
UINT32 CursorFormat;
|
|
|
|
xfContext* xfc = (xfContext*)context;
|
2022-04-29 15:21:31 +03:00
|
|
|
xfPointer* xpointer = (xfPointer*)pointer;
|
2020-10-05 10:45:45 +03:00
|
|
|
XcursorImage ci = { 0 };
|
2020-09-08 18:12:27 +03:00
|
|
|
rdpSettings* settings;
|
|
|
|
UINT32 xTargetSize;
|
|
|
|
UINT32 yTargetSize;
|
|
|
|
double xscale;
|
|
|
|
double yscale;
|
|
|
|
size_t size;
|
2020-11-10 10:14:56 +03:00
|
|
|
int cursorIndex = -1;
|
|
|
|
UINT32 i;
|
2020-10-05 10:45:45 +03:00
|
|
|
void* tmp;
|
2020-09-08 18:12:27 +03:00
|
|
|
|
|
|
|
if (!context || !pointer || !context->gdi)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
settings = xfc->common.context.settings;
|
2020-09-08 18:12:27 +03:00
|
|
|
|
|
|
|
if (!settings)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
xscale = (settings->SmartSizing ? xfc->scaledWidth / (double)settings->DesktopWidth : 1);
|
|
|
|
yscale = (settings->SmartSizing ? xfc->scaledHeight / (double)settings->DesktopHeight : 1);
|
2022-11-16 13:58:02 +03:00
|
|
|
xTargetSize = MAX(1, pointer->width * xscale);
|
|
|
|
yTargetSize = MAX(1, pointer->height * yscale);
|
2020-09-08 18:12:27 +03:00
|
|
|
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_DBG(TAG, "scaled: %" PRIu32 "x%" PRIu32 ", desktop: %" PRIu32 "x%" PRIu32,
|
2022-08-22 10:42:15 +03:00
|
|
|
xfc->scaledWidth, xfc->scaledHeight, settings->DesktopWidth, settings->DesktopHeight);
|
2020-09-22 08:43:56 +03:00
|
|
|
for (i = 0; i < xpointer->nCursors; i++)
|
2020-09-08 18:12:27 +03:00
|
|
|
{
|
2022-07-04 09:52:17 +03:00
|
|
|
if ((xpointer->cursorWidths[i] == xTargetSize) &&
|
|
|
|
(xpointer->cursorHeights[i] == yTargetSize))
|
2020-09-08 18:12:27 +03:00
|
|
|
{
|
|
|
|
cursorIndex = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cursorIndex == -1)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2020-10-05 10:45:45 +03:00
|
|
|
void* tmp2;
|
2020-09-08 18:12:27 +03:00
|
|
|
xpointer->mCursors = (xpointer->mCursors == 0 ? 1 : xpointer->mCursors * 2);
|
|
|
|
|
2020-10-05 10:45:45 +03:00
|
|
|
tmp2 = realloc(xpointer->cursorWidths, sizeof(UINT32) * xpointer->mCursors);
|
|
|
|
if (!tmp2)
|
2020-09-08 18:12:27 +03:00
|
|
|
{
|
|
|
|
xf_unlock_x11(xfc);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-10-05 10:45:45 +03:00
|
|
|
xpointer->cursorWidths = tmp2;
|
|
|
|
|
|
|
|
tmp2 = realloc(xpointer->cursorHeights, sizeof(UINT32) * xpointer->mCursors);
|
|
|
|
if (!tmp2)
|
2020-09-08 18:12:27 +03:00
|
|
|
{
|
|
|
|
xf_unlock_x11(xfc);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-10-05 10:45:45 +03:00
|
|
|
xpointer->cursorHeights = (UINT32*)tmp2;
|
|
|
|
|
|
|
|
tmp2 = realloc(xpointer->cursors, sizeof(Cursor) * xpointer->mCursors);
|
|
|
|
if (!tmp2)
|
2020-09-08 18:12:27 +03:00
|
|
|
{
|
|
|
|
xf_unlock_x11(xfc);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-10-05 10:45:45 +03:00
|
|
|
xpointer->cursors = (Cursor*)tmp2;
|
2020-09-08 18:12:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ci.version = XCURSOR_IMAGE_VERSION;
|
|
|
|
ci.size = sizeof(ci);
|
|
|
|
ci.width = xTargetSize;
|
|
|
|
ci.height = yTargetSize;
|
|
|
|
ci.xhot = pointer->xPos * xscale;
|
|
|
|
ci.yhot = pointer->yPos * yscale;
|
2022-04-28 06:43:31 +03:00
|
|
|
size = ci.height * ci.width * FreeRDPGetBytesPerPixel(CursorFormat) * 1ULL;
|
2020-09-08 18:12:27 +03:00
|
|
|
|
2022-05-11 12:28:55 +03:00
|
|
|
tmp = winpr_aligned_malloc(size, 16);
|
2020-10-05 10:45:45 +03:00
|
|
|
if (!tmp)
|
2020-09-08 18:12:27 +03:00
|
|
|
{
|
|
|
|
xf_unlock_x11(xfc);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-10-05 10:45:45 +03:00
|
|
|
ci.pixels = (XcursorPixel*)tmp;
|
2020-09-08 18:12:27 +03:00
|
|
|
|
2022-07-04 10:53:41 +03:00
|
|
|
const double xs = fabs(fabs(xscale) - 1.0);
|
|
|
|
const double ys = fabs(fabs(yscale) - 1.0);
|
2022-07-04 13:13:20 +03:00
|
|
|
|
|
|
|
WLog_DBG(TAG,
|
2023-01-23 14:03:18 +03:00
|
|
|
"cursorIndex %" PRId32 " scaling pointer %" PRIu32 "x%" PRIu32 " --> %" PRIu32
|
2022-07-04 13:13:20 +03:00
|
|
|
"x%" PRIu32 " [%lfx%lf]",
|
2023-01-23 14:03:18 +03:00
|
|
|
cursorIndex, pointer->width, pointer->height, ci.width, ci.height, xscale, yscale);
|
2022-07-04 10:53:41 +03:00
|
|
|
if ((xs > DBL_EPSILON) || (ys > DBL_EPSILON))
|
2020-09-08 18:12:27 +03: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 12:28:55 +03:00
|
|
|
winpr_aligned_free(tmp);
|
2020-09-08 18:12:27 +03: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 10:45:45 +03:00
|
|
|
|
2022-05-11 12:28:55 +03:00
|
|
|
winpr_aligned_free(tmp);
|
2020-09-08 18:12:27 +03:00
|
|
|
|
|
|
|
xf_unlock_x11(xfc);
|
|
|
|
}
|
2022-07-04 13:13:20 +03:00
|
|
|
else
|
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_DBG(TAG, "using cached cursor %" PRId32, cursorIndex);
|
2022-07-04 13:13:20 +03:00
|
|
|
}
|
2020-09-08 18:12:27 +03:00
|
|
|
|
|
|
|
cursor[0] = xpointer->cursors[cursorIndex];
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-10-21 02:18:45 +04:00
|
|
|
/* Pointer Class */
|
2020-12-03 16:09:16 +03: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 09:52:17 +03:00
|
|
|
BOOL xf_pointer_update_scale(xfContext* xfc)
|
|
|
|
{
|
|
|
|
xfPointer* pointer;
|
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
|
|
|
|
pointer = xfc->pointer;
|
|
|
|
if (!pointer)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return xf_Pointer_Set(&xfc->common.context, &xfc->pointer->pointer);
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL xf_Pointer_New(rdpContext* context, rdpPointer* pointer)
|
2011-10-21 02:18:45 +04:00
|
|
|
{
|
2022-07-04 13:13:20 +03:00
|
|
|
BOOL rc = FALSE;
|
|
|
|
|
2016-09-09 09:58:26 +03:00
|
|
|
#ifdef WITH_XCURSOR
|
2016-10-10 10:19:43 +03:00
|
|
|
UINT32 CursorFormat;
|
2016-09-09 09:58:26 +03:00
|
|
|
size_t size;
|
2019-11-06 17:24:51 +03:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2016-09-09 09:58:26 +03:00
|
|
|
xfPointer* xpointer = (xfPointer*)pointer;
|
2016-08-03 15:16:20 +03:00
|
|
|
|
|
|
|
if (!context || !pointer || !context->gdi)
|
2022-07-04 13:13:20 +03:00
|
|
|
goto fail;
|
2016-08-03 15:16:20 +03:00
|
|
|
|
2016-10-10 10:19:43 +03:00
|
|
|
if (!xfc->invert)
|
2017-09-18 11:47:56 +03:00
|
|
|
CursorFormat = (!xfc->big_endian) ? PIXEL_FORMAT_RGBA32 : PIXEL_FORMAT_ABGR32;
|
2016-10-10 10:19:43 +03:00
|
|
|
else
|
2017-09-18 11:47:56 +03:00
|
|
|
CursorFormat = (!xfc->big_endian) ? PIXEL_FORMAT_BGRA32 : PIXEL_FORMAT_ARGB32;
|
2016-10-10 10:19:43 +03:00
|
|
|
|
2020-09-08 18:12:27 +03:00
|
|
|
xpointer->nCursors = 0;
|
|
|
|
xpointer->mCursors = 0;
|
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
size = pointer->height * pointer->width * FreeRDPGetBytesPerPixel(CursorFormat) * 1ULL;
|
2020-09-08 18:12:27 +03:00
|
|
|
|
2022-05-11 12:28:55 +03:00
|
|
|
if (!(xpointer->cursorPixels = (XcursorPixel*)winpr_aligned_malloc(size, 16)))
|
2022-07-04 13:13:20 +03:00
|
|
|
goto fail;
|
2011-10-21 02:18:45 +04:00
|
|
|
|
2016-10-04 15:14:39 +03:00
|
|
|
if (!freerdp_image_copy_from_pointer_data(
|
2020-09-08 18:12:27 +03:00
|
|
|
(BYTE*)xpointer->cursorPixels, CursorFormat, 0, 0, 0, pointer->width, pointer->height,
|
2019-11-06 17:24:51 +03:00
|
|
|
pointer->xorMaskData, pointer->lengthXorMask, pointer->andMaskData,
|
|
|
|
pointer->lengthAndMask, pointer->xorBpp, &context->gdi->palette))
|
2015-08-05 18:32:46 +03:00
|
|
|
{
|
2022-05-11 12:28:55 +03:00
|
|
|
winpr_aligned_free(xpointer->cursorPixels);
|
2022-07-04 13:13:20 +03:00
|
|
|
goto fail;
|
2011-10-21 02:18:45 +04:00
|
|
|
}
|
|
|
|
|
2012-10-27 23:01:22 +04:00
|
|
|
#endif
|
2022-07-04 13:13:20 +03:00
|
|
|
|
2022-09-05 10:48:30 +03:00
|
|
|
rc = TRUE;
|
|
|
|
|
2022-07-04 13:13:20 +03:00
|
|
|
fail:
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_DBG(TAG, "%p", rc ? pointer : NULL);
|
2022-07-04 13:13:20 +03:00
|
|
|
return rc;
|
2011-10-21 02:18:45 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static void xf_Pointer_Free(rdpContext* context, rdpPointer* pointer)
|
2011-10-21 02:18:45 +04:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_DBG(TAG, "%p", pointer);
|
2022-07-04 13:13:20 +03:00
|
|
|
|
2012-10-27 23:01:22 +04:00
|
|
|
#ifdef WITH_XCURSOR
|
2020-09-16 10:30:37 +03:00
|
|
|
UINT32 i;
|
2019-11-06 17:24:51 +03:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2020-09-08 18:12:27 +03:00
|
|
|
xfPointer* xpointer = (xfPointer*)pointer;
|
|
|
|
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_lock_x11(xfc);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2022-05-11 12:28:55 +03:00
|
|
|
winpr_aligned_free(xpointer->cursorPixels);
|
2020-09-08 18:12:27 +03:00
|
|
|
free(xpointer->cursorWidths);
|
|
|
|
free(xpointer->cursorHeights);
|
|
|
|
|
2020-09-16 10:30:37 +03:00
|
|
|
for (i = 0; i < xpointer->nCursors; i++)
|
2020-09-08 18:12:27 +03:00
|
|
|
{
|
|
|
|
XFreeCursor(xfc->display, xpointer->cursors[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(xpointer->cursors);
|
|
|
|
xpointer->nCursors = 0;
|
|
|
|
xpointer->mCursors = 0;
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_unlock_x11(xfc);
|
2012-10-27 23:01:22 +04:00
|
|
|
#endif
|
2011-10-21 02:18:45 +04:00
|
|
|
}
|
|
|
|
|
2022-04-27 22:31:14 +03:00
|
|
|
static BOOL xf_Pointer_Set(rdpContext* context, rdpPointer* pointer)
|
2011-10-21 02:18:45 +04:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_DBG(TAG, "%p", pointer);
|
2012-10-27 23:01:22 +04:00
|
|
|
#ifdef WITH_XCURSOR
|
2019-11-06 17:24:51 +03:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2020-12-03 16:09:16 +03:00
|
|
|
Window handle = xf_Pointer_get_window(xfc);
|
2022-04-27 22:02:18 +03:00
|
|
|
|
2022-07-04 09:52:17 +03:00
|
|
|
WINPR_ASSERT(xfc);
|
|
|
|
WINPR_ASSERT(pointer);
|
|
|
|
|
2022-04-29 15:21:31 +03:00
|
|
|
xfc->pointer = (xfPointer*)pointer;
|
2013-08-04 00:13:39 +04:00
|
|
|
|
2011-11-24 22:01:34 +04:00
|
|
|
/* in RemoteApp mode, window can be null if none has had focus */
|
|
|
|
|
2020-12-03 16:09:16 +03:00
|
|
|
if (handle)
|
2020-09-08 18:12:27 +03:00
|
|
|
{
|
2022-07-04 09:52:17 +03:00
|
|
|
if (!xf_Pointer_GetCursorForCurrentScale(context, pointer, &(xfc->pointer->cursor)))
|
2020-09-08 18:12:27 +03:00
|
|
|
return FALSE;
|
|
|
|
xf_lock_x11(xfc);
|
2020-12-03 16:09:16 +03:00
|
|
|
XDefineCursor(xfc->display, handle, xfc->pointer->cursor);
|
2020-09-08 18:12:27 +03:00
|
|
|
xf_unlock_x11(xfc);
|
|
|
|
}
|
2022-07-04 13:13:20 +03:00
|
|
|
else
|
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_WARN(TAG, "handle=%ld", handle);
|
2022-07-04 13:13:20 +03:00
|
|
|
}
|
2012-10-27 23:01:22 +04:00
|
|
|
#endif
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-10-21 02:18:45 +04:00
|
|
|
}
|
2012-02-24 16:44:23 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL xf_Pointer_SetNull(rdpContext* context)
|
2012-02-24 16:44:23 +04:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_DBG(TAG, "called");
|
2012-10-27 23:01:22 +04:00
|
|
|
#ifdef WITH_XCURSOR
|
2019-11-06 17:24:51 +03:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2012-02-24 16:44:23 +04:00
|
|
|
static Cursor nullcursor = None;
|
2020-12-03 16:09:16 +03:00
|
|
|
Window handle = xf_Pointer_get_window(xfc);
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_lock_x11(xfc);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2012-02-24 16:44:23 +04:00
|
|
|
if (nullcursor == None)
|
|
|
|
{
|
2022-10-13 17:25:36 +03:00
|
|
|
XcursorImage ci = { 0 };
|
2012-02-24 16:44:23 +04:00
|
|
|
XcursorPixel xp = 0;
|
2022-10-13 17:25:36 +03:00
|
|
|
|
2012-02-24 16:44:23 +04: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 02:57:25 +04:00
|
|
|
nullcursor = XcursorImageLoadCursor(xfc->display, &ci);
|
2012-02-24 16:44:23 +04:00
|
|
|
}
|
2012-10-27 23:01:22 +04:00
|
|
|
|
2013-08-04 00:13:39 +04:00
|
|
|
xfc->pointer = NULL;
|
|
|
|
|
2020-12-03 16:09:16 +03:00
|
|
|
if ((handle) && (nullcursor != None))
|
|
|
|
XDefineCursor(xfc->display, handle, nullcursor);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_unlock_x11(xfc);
|
2012-10-27 23:01:22 +04:00
|
|
|
#endif
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2012-02-24 16:44:23 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL xf_Pointer_SetDefault(rdpContext* context)
|
2012-02-24 16:44:23 +04:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_DBG(TAG, "called");
|
2012-10-27 23:01:22 +04:00
|
|
|
#ifdef WITH_XCURSOR
|
2019-11-06 17:24:51 +03:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2020-12-03 16:09:16 +03:00
|
|
|
Window handle = xf_Pointer_get_window(xfc);
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_lock_x11(xfc);
|
2013-08-04 00:13:39 +04:00
|
|
|
xfc->pointer = NULL;
|
|
|
|
|
2020-12-03 16:09:16 +03:00
|
|
|
if (handle)
|
|
|
|
XUndefineCursor(xfc->display, handle);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_unlock_x11(xfc);
|
2012-10-27 23:01:22 +04:00
|
|
|
#endif
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2012-02-24 16:44:23 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL xf_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y)
|
2015-02-02 17:32:49 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2015-02-04 00:08:34 +03:00
|
|
|
XWindowAttributes current;
|
|
|
|
XSetWindowAttributes tmp;
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL ret = FALSE;
|
2020-12-03 16:09:16 +03:00
|
|
|
Status rc;
|
|
|
|
Window handle = xf_Pointer_get_window(xfc);
|
2015-02-02 17:32:49 +03:00
|
|
|
|
2020-12-03 16:09:16 +03:00
|
|
|
if (!handle)
|
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_WARN(TAG, "focus %d, handle%lu", xfc->focused, handle);
|
2020-12-03 16:09:16 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_DBG(TAG, "%" PRIu32 "x%" PRIu32, x, y);
|
2020-12-03 16:09:16 +03:00
|
|
|
if (xfc->remote_app && !xfc->focused)
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2015-02-02 17:32:49 +03:00
|
|
|
|
2021-03-08 15:52:29 +03:00
|
|
|
xf_adjust_coordinates_to_screen(xfc, &x, &y);
|
|
|
|
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_lock_x11(xfc);
|
2015-02-02 17:32:49 +03:00
|
|
|
|
2020-12-03 16:09:16 +03:00
|
|
|
rc = XGetWindowAttributes(xfc->display, handle, ¤t);
|
|
|
|
if (rc == 0)
|
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_WARN(TAG, "XGetWindowAttributes==%d", rc);
|
2015-02-04 00:08:34 +03:00
|
|
|
goto out;
|
2020-12-03 16:09:16 +03:00
|
|
|
}
|
2015-02-04 00:08:34 +03:00
|
|
|
|
|
|
|
tmp.event_mask = (current.your_event_mask & ~(PointerMotionMask));
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2020-12-03 16:09:16 +03:00
|
|
|
rc = XChangeWindowAttributes(xfc->display, handle, CWEventMask, &tmp);
|
|
|
|
if (rc == 0)
|
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_WARN(TAG, "XChangeWindowAttributes==%d", rc);
|
2015-02-04 00:08:34 +03:00
|
|
|
goto out;
|
2020-12-03 16:09:16 +03:00
|
|
|
}
|
2015-02-04 00:08:34 +03:00
|
|
|
|
2020-12-03 16:09:16 +03:00
|
|
|
rc = XWarpPointer(xfc->display, None, handle, 0, 0, 0, 0, x, y);
|
|
|
|
if (rc == 0)
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_WARN(TAG, "XWarpPointer==%d", rc);
|
2015-02-04 00:08:34 +03:00
|
|
|
tmp.event_mask = current.your_event_mask;
|
2020-12-03 16:09:16 +03:00
|
|
|
rc = XChangeWindowAttributes(xfc->display, handle, CWEventMask, &tmp);
|
|
|
|
if (rc == 0)
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_WARN(TAG, "2.try XChangeWindowAttributes==%d", rc);
|
2015-04-14 11:14:23 +03:00
|
|
|
ret = TRUE;
|
2015-02-04 00:08:34 +03:00
|
|
|
out:
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_unlock_x11(xfc);
|
2015-04-14 11:14:23 +03:00
|
|
|
return ret;
|
2015-02-02 17:32:49 +03:00
|
|
|
}
|
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
/* Glyph Class */
|
2021-08-02 13:13:34 +03:00
|
|
|
static BOOL xf_Glyph_New(rdpContext* context, rdpGlyph* glyph)
|
2011-11-09 21:16:09 +04:00
|
|
|
{
|
|
|
|
int scanline;
|
|
|
|
XImage* image;
|
2021-08-02 13:13:34 +03:00
|
|
|
xfGlyph* xf_glyph = (xfGlyph*)glyph;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_lock_x11(xfc);
|
2011-11-09 21:16:09 +04:00
|
|
|
scanline = (glyph->cx + 7) / 8;
|
2019-11-06 17:24:51 +03:00
|
|
|
xf_glyph->pixmap = XCreatePixmap(xfc->display, xfc->drawing, glyph->cx, glyph->cy, 1);
|
|
|
|
image = XCreateImage(xfc->display, xfc->visual, 1, ZPixmap, 0, (char*)glyph->aj, glyph->cx,
|
|
|
|
glyph->cy, 8, scanline);
|
2011-11-09 21:16:09 +04:00
|
|
|
image->byte_order = MSBFirst;
|
|
|
|
image->bitmap_bit_order = MSBFirst;
|
|
|
|
XInitImage(image);
|
2019-11-06 17:24:51 +03:00
|
|
|
XPutImage(xfc->display, xf_glyph->pixmap, xfc->gc_mono, image, 0, 0, 0, 0, glyph->cx,
|
|
|
|
glyph->cy);
|
2018-02-12 13:14:54 +03:00
|
|
|
image->data = NULL;
|
2018-02-12 12:02:35 +03:00
|
|
|
XDestroyImage(image);
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_unlock_x11(xfc);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-11-09 21:16:09 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static void xf_Glyph_Free(rdpContext* context, rdpGlyph* glyph)
|
2011-11-09 21:16:09 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_lock_x11(xfc);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (((xfGlyph*)glyph)->pixmap != 0)
|
|
|
|
XFreePixmap(xfc->display, ((xfGlyph*)glyph)->pixmap);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_unlock_x11(xfc);
|
2016-07-20 11:06:45 +03:00
|
|
|
free(glyph->aj);
|
|
|
|
free(glyph);
|
2011-11-09 21:16:09 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL xf_Glyph_Draw(rdpContext* context, const rdpGlyph* glyph, INT32 x, INT32 y, INT32 w,
|
|
|
|
INT32 h, INT32 sx, INT32 sy, BOOL fOpRedundant)
|
2011-11-09 21:16:09 +04:00
|
|
|
{
|
2021-08-02 13:13:34 +03:00
|
|
|
const xfGlyph* xf_glyph = (const xfGlyph*)glyph;
|
2019-11-06 17:24:51 +03:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2021-08-02 13:13:34 +03:00
|
|
|
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_lock_x11(xfc);
|
2016-08-17 10:26:59 +03:00
|
|
|
|
|
|
|
if (!fOpRedundant)
|
|
|
|
{
|
|
|
|
XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled);
|
|
|
|
XFillRectangle(xfc->display, xfc->drawable, xfc->gc, x, y, w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
XSetFillStyle(xfc->display, xfc->gc, FillStippled);
|
2013-06-13 02:57:25 +04:00
|
|
|
XSetStipple(xfc->display, xfc->gc, xf_glyph->pixmap);
|
2016-08-17 10:26:59 +03:00
|
|
|
|
|
|
|
if (sx || sy)
|
|
|
|
WLog_ERR(TAG, "");
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
// XSetClipOrigin(xfc->display, xfc->gc, sx, sy);
|
2013-06-13 02:57:25 +04:00
|
|
|
XSetTSOrigin(xfc->display, xfc->gc, x, y);
|
2016-08-17 10:26:59 +03:00
|
|
|
XFillRectangle(xfc->display, xfc->drawing, xfc->gc, x, y, w, h);
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_unlock_x11(xfc);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-11-09 21:16:09 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL xf_Glyph_BeginDraw(rdpContext* context, INT32 x, INT32 y, INT32 width, INT32 height,
|
|
|
|
UINT32 bgcolor, UINT32 fgcolor, BOOL fOpRedundant)
|
2011-11-09 21:16:09 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2017-01-25 10:33:36 +03:00
|
|
|
XColor xbgcolor, xfgcolor;
|
2016-07-18 13:36:22 +03:00
|
|
|
|
2017-01-25 10:33:36 +03:00
|
|
|
if (!xf_decode_color(xfc, bgcolor, &xbgcolor))
|
2016-07-18 13:36:22 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2017-01-25 10:33:36 +03:00
|
|
|
if (!xf_decode_color(xfc, fgcolor, &xfgcolor))
|
2016-07-18 13:36:22 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_lock_x11(xfc);
|
2016-08-17 10:26:59 +03:00
|
|
|
|
|
|
|
if (!fOpRedundant)
|
|
|
|
{
|
2017-01-25 10:33:36 +03:00
|
|
|
XSetForeground(xfc->display, xfc->gc, xfgcolor.pixel);
|
|
|
|
XSetBackground(xfc->display, xfc->gc, xfgcolor.pixel);
|
2016-08-17 10:26:59 +03:00
|
|
|
XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled);
|
|
|
|
XFillRectangle(xfc->display, xfc->drawable, xfc->gc, x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2017-01-25 10:33:36 +03:00
|
|
|
XSetForeground(xfc->display, xfc->gc, xbgcolor.pixel);
|
|
|
|
XSetBackground(xfc->display, xfc->gc, xfgcolor.pixel);
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_unlock_x11(xfc);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-11-09 21:16:09 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL xf_Glyph_EndDraw(rdpContext* context, INT32 x, INT32 y, INT32 width, INT32 height,
|
2016-10-04 10:00:00 +03:00
|
|
|
UINT32 bgcolor, UINT32 fgcolor)
|
2011-11-09 21:16:09 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
xfContext* xfc = (xfContext*)context;
|
2015-04-17 17:21:55 +03:00
|
|
|
BOOL ret = TRUE;
|
2017-01-25 10:33:36 +03:00
|
|
|
XColor xfgcolor, xbgcolor;
|
2016-08-10 18:01:54 +03:00
|
|
|
|
2017-01-25 10:33:36 +03:00
|
|
|
if (!xf_decode_color(xfc, bgcolor, &xbgcolor))
|
2016-08-10 18:01:54 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2017-01-25 10:33:36 +03:00
|
|
|
if (!xf_decode_color(xfc, fgcolor, &xfgcolor))
|
2016-08-10 18:01:54 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->drawing == xfc->primary)
|
2015-04-17 17:21:55 +03:00
|
|
|
ret = gdi_InvalidateRegion(xfc->hdc, x, y, width, height);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2015-04-17 17:21:55 +03:00
|
|
|
return ret;
|
2011-11-09 21:16:09 +04:00
|
|
|
}
|
|
|
|
|
2011-10-21 02:18:45 +04:00
|
|
|
/* Graphics Module */
|
2016-07-18 15:16:13 +03:00
|
|
|
BOOL xf_register_pointer(rdpGraphics* graphics)
|
|
|
|
{
|
|
|
|
rdpPointer* pointer = NULL;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!(pointer = (rdpPointer*)calloc(1, sizeof(rdpPointer))))
|
2016-07-18 15:16:13 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
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);
|
|
|
|
free(pointer);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2011-10-21 02:18:45 +04:00
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
BOOL xf_register_graphics(rdpGraphics* graphics)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2016-07-21 11:07:42 +03:00
|
|
|
rdpBitmap bitmap;
|
|
|
|
rdpGlyph glyph;
|
2011-11-09 21:16:09 +04:00
|
|
|
|
2016-07-21 11:07:42 +03:00
|
|
|
if (!graphics || !graphics->Bitmap_Prototype || !graphics->Glyph_Prototype)
|
|
|
|
return FALSE;
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2016-07-21 11:07:42 +03:00
|
|
|
bitmap = *graphics->Bitmap_Prototype;
|
|
|
|
glyph = *graphics->Glyph_Prototype;
|
|
|
|
bitmap.size = sizeof(xfBitmap);
|
|
|
|
bitmap.New = xf_Bitmap_New;
|
|
|
|
bitmap.Free = xf_Bitmap_Free;
|
|
|
|
bitmap.Paint = xf_Bitmap_Paint;
|
|
|
|
bitmap.SetSurface = xf_Bitmap_SetSurface;
|
|
|
|
graphics_register_bitmap(graphics, &bitmap);
|
|
|
|
glyph.size = sizeof(xfGlyph);
|
|
|
|
glyph.New = xf_Glyph_New;
|
|
|
|
glyph.Free = xf_Glyph_Free;
|
|
|
|
glyph.Draw = xf_Glyph_Draw;
|
|
|
|
glyph.BeginDraw = xf_Glyph_BeginDraw;
|
|
|
|
glyph.EndDraw = xf_Glyph_EndDraw;
|
|
|
|
graphics_register_glyph(graphics, &glyph);
|
|
|
|
return TRUE;
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
2016-08-03 15:16:20 +03:00
|
|
|
|
|
|
|
UINT32 xf_get_local_color_format(xfContext* xfc, BOOL aligned)
|
|
|
|
{
|
|
|
|
UINT32 DstFormat;
|
2017-01-26 12:44:19 +03:00
|
|
|
BOOL invert = FALSE;
|
2016-08-03 15:16:20 +03:00
|
|
|
|
|
|
|
if (!xfc)
|
|
|
|
return 0;
|
|
|
|
|
2017-01-26 12:44:19 +03:00
|
|
|
invert = xfc->invert;
|
|
|
|
|
2022-11-28 09:31:19 +03:00
|
|
|
WINPR_ASSERT(xfc->depth != 0);
|
2016-08-03 15:16:20 +03:00
|
|
|
if (xfc->depth == 32)
|
2016-08-03 22:22:06 +03:00
|
|
|
DstFormat = (!invert) ? PIXEL_FORMAT_RGBA32 : PIXEL_FORMAT_BGRA32;
|
2022-03-19 15:19:41 +03:00
|
|
|
else if (xfc->depth == 30)
|
|
|
|
DstFormat = (!invert) ? PIXEL_FORMAT_RGBX32_DEPTH30 : PIXEL_FORMAT_BGRX32_DEPTH30;
|
2016-08-03 15:16:20 +03:00
|
|
|
else if (xfc->depth == 24)
|
|
|
|
{
|
|
|
|
if (aligned)
|
2016-08-03 22:22:06 +03:00
|
|
|
DstFormat = (!invert) ? PIXEL_FORMAT_RGBX32 : PIXEL_FORMAT_BGRX32;
|
2016-08-03 15:16:20 +03:00
|
|
|
else
|
2016-08-03 22:22:06 +03:00
|
|
|
DstFormat = (!invert) ? PIXEL_FORMAT_RGB24 : PIXEL_FORMAT_BGR24;
|
2016-08-03 15:16:20 +03:00
|
|
|
}
|
|
|
|
else if (xfc->depth == 16)
|
2017-01-19 19:14:16 +03:00
|
|
|
DstFormat = PIXEL_FORMAT_RGB16;
|
2016-08-03 15:16:20 +03:00
|
|
|
else if (xfc->depth == 15)
|
2017-01-19 19:14:16 +03:00
|
|
|
DstFormat = PIXEL_FORMAT_RGB15;
|
2016-08-03 15:16:20 +03:00
|
|
|
else
|
2016-08-03 22:22:06 +03:00
|
|
|
DstFormat = (!invert) ? PIXEL_FORMAT_RGBX32 : PIXEL_FORMAT_BGRX32;
|
2016-08-03 15:16:20 +03:00
|
|
|
|
|
|
|
return DstFormat;
|
|
|
|
}
|