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>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:20:53 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
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>
|
2012-06-27 03:57:18 +04:00
|
|
|
#include <freerdp/codec/jpeg.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"
|
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")
|
|
|
|
|
2011-10-21 02:18:45 +04:00
|
|
|
/* Bitmap Class */
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL xf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2014-09-17 20:17:41 +04:00
|
|
|
int depth;
|
|
|
|
BYTE* data;
|
2011-10-21 01:28:59 +04:00
|
|
|
Pixmap pixmap;
|
|
|
|
XImage* image;
|
2014-09-17 20:17:41 +04:00
|
|
|
UINT32 SrcFormat;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2014-09-17 20:17:41 +04:00
|
|
|
data = bitmap->data;
|
|
|
|
depth = (bitmap->bpp >= 24) ? 24 : bitmap->bpp;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
pixmap = XCreatePixmap(xfc->display, xfc->drawable, bitmap->width, bitmap->height, xfc->depth);
|
2011-10-21 01:28:59 +04:00
|
|
|
|
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
|
|
|
|
2014-09-17 20:17:41 +04:00
|
|
|
if (depth != xfc->depth)
|
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(data = _aligned_malloc(bitmap->width * bitmap->height * 4, 16)))
|
|
|
|
{
|
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2015-04-14 11:14:23 +03:00
|
|
|
return FALSE;
|
2015-04-28 18:00:41 +03:00
|
|
|
}
|
2014-09-17 20:17:41 +04:00
|
|
|
|
|
|
|
SrcFormat = gdi_get_pixel_format(bitmap->bpp, TRUE);
|
|
|
|
|
|
|
|
freerdp_image_copy(data, xfc->format, -1, 0, 0,
|
2014-09-18 02:30:09 +04:00
|
|
|
bitmap->width, bitmap->height, bitmap->data, SrcFormat, -1, 0, 0, xfc->palette);
|
2014-09-17 20:17:41 +04:00
|
|
|
|
|
|
|
_aligned_free(bitmap->data);
|
|
|
|
bitmap->data = data;
|
|
|
|
|
|
|
|
bitmap->bpp = (xfc->depth >= 24) ? 32 : xfc->depth;
|
|
|
|
}
|
|
|
|
|
2014-09-12 09:03:19 +04:00
|
|
|
image = XCreateImage(xfc->display, xfc->visual, xfc->depth,
|
|
|
|
ZPixmap, 0, (char*) bitmap->data, bitmap->width, bitmap->height, xfc->scanline_pad, 0);
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2014-09-12 09:03:19 +04:00
|
|
|
XPutImage(xfc->display, pixmap, xfc->gc, image, 0, 0, 0, 0, bitmap->width, bitmap->height);
|
2012-07-25 02:10:45 +04:00
|
|
|
|
2014-09-12 09:03:19 +04:00
|
|
|
XFree(image);
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
((xfBitmap*) bitmap)->pixmap = pixmap;
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void xf_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2011-10-21 01:28:59 +04:00
|
|
|
if (((xfBitmap*) bitmap)->pixmap != 0)
|
2013-06-13 02:57:25 +04:00
|
|
|
XFreePixmap(xfc->display, ((xfBitmap*) bitmap)->pixmap);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL xf_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2011-10-21 05:34:55 +04:00
|
|
|
XImage* image;
|
|
|
|
int width, height;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2015-04-17 17:21:55 +03:00
|
|
|
BOOL ret = TRUE;
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2011-10-21 05:34:55 +04:00
|
|
|
width = bitmap->right - bitmap->left + 1;
|
|
|
|
height = bitmap->bottom - bitmap->top + 1;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XSetFunction(xfc->display, xfc->gc, GXcopy);
|
2011-10-21 05:34:55 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
image = XCreateImage(xfc->display, xfc->visual, xfc->depth,
|
|
|
|
ZPixmap, 0, (char*) bitmap->data, bitmap->width, bitmap->height, xfc->scanline_pad, 0);
|
2011-10-21 05:34:55 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XPutImage(xfc->display, xfc->primary, xfc->gc,
|
2011-10-21 05:34:55 +04:00
|
|
|
image, 0, 0, bitmap->left, bitmap->top, width, height);
|
|
|
|
|
|
|
|
XFree(image);
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2015-04-17 17:21:55 +03:00
|
|
|
ret = gdi_InvalidateRegion(xfc->hdc, bitmap->left, bitmap->top, width, height);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL xf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* data, int width, int height, int bpp, int length,
|
2014-09-10 08:42:41 +04:00
|
|
|
BOOL compressed, int codecId)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2014-09-10 08:42:41 +04:00
|
|
|
int status;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 size;
|
2014-09-12 09:03:19 +04:00
|
|
|
BYTE* pSrcData;
|
|
|
|
BYTE* pDstData;
|
|
|
|
UINT32 SrcSize;
|
|
|
|
UINT32 SrcFormat;
|
|
|
|
UINT32 bytesPerPixel;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2014-09-12 09:03:19 +04:00
|
|
|
bytesPerPixel = (bpp + 7) / 8;
|
|
|
|
size = width * height * 4;
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2014-09-17 20:17:41 +04:00
|
|
|
bitmap->data = (BYTE*) _aligned_malloc(size, 16);
|
2015-04-14 11:14:23 +03:00
|
|
|
if (!bitmap->data)
|
|
|
|
return FALSE;
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2014-09-12 09:03:19 +04:00
|
|
|
pSrcData = data;
|
|
|
|
SrcSize = (UINT32) length;
|
|
|
|
pDstData = bitmap->data;
|
|
|
|
|
|
|
|
if (compressed)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2014-09-12 09:03:19 +04:00
|
|
|
if (bpp < 32)
|
|
|
|
{
|
2016-05-28 21:13:47 +03:00
|
|
|
if (!freerdp_client_codecs_prepare(xfc->codecs, FREERDP_CODEC_INTERLEAVED,
|
|
|
|
xfc->settings->DesktopWidth,
|
|
|
|
xfc->settings->DesktopHeight))
|
2015-04-28 18:00:41 +03:00
|
|
|
return FALSE;
|
2014-09-12 09:03:19 +04:00
|
|
|
|
|
|
|
status = interleaved_decompress(xfc->codecs->interleaved, pSrcData, SrcSize, bpp,
|
2014-09-18 02:30:09 +04:00
|
|
|
&pDstData, xfc->format, -1, 0, 0, width, height, xfc->palette);
|
2014-09-12 09:03:19 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-28 21:13:47 +03:00
|
|
|
if (!freerdp_client_codecs_prepare(xfc->codecs, FREERDP_CODEC_PLANAR,
|
|
|
|
xfc->settings->DesktopWidth,
|
|
|
|
xfc->settings->DesktopHeight))
|
2015-04-28 18:00:41 +03:00
|
|
|
return FALSE;
|
2014-09-12 09:03:19 +04:00
|
|
|
|
2014-09-17 03:12:26 +04:00
|
|
|
status = planar_decompress(xfc->codecs->planar, pSrcData, SrcSize,
|
|
|
|
&pDstData, xfc->format, -1, 0, 0, width, height, TRUE);
|
2014-09-12 09:03:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "Bitmap Decompression Failed");
|
2015-04-14 11:14:23 +03:00
|
|
|
return FALSE;
|
2014-09-12 09:03:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SrcFormat = gdi_get_pixel_format(bpp, TRUE);
|
|
|
|
|
2014-09-17 03:12:26 +04:00
|
|
|
status = freerdp_image_copy(pDstData, xfc->format, -1, 0, 0,
|
2014-09-18 02:30:09 +04:00
|
|
|
width, height, pSrcData, SrcFormat, -1, 0, 0, xfc->palette);
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
bitmap->compressed = FALSE;
|
2011-10-21 01:28:59 +04:00
|
|
|
bitmap->length = size;
|
2014-09-17 03:12:26 +04:00
|
|
|
bitmap->bpp = (xfc->depth >= 24) ? 32 : xfc->depth;
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL xf_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, BOOL primary)
|
2011-10-21 02:18:45 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2011-10-21 02:18:45 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
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
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->drawing = ((xfBitmap*) bitmap)->pixmap;
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-10-21 02:18:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Pointer Class */
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL xf_Pointer_New(rdpContext* context, rdpPointer* pointer)
|
2011-10-21 02:18:45 +04:00
|
|
|
{
|
2012-10-27 23:01:22 +04:00
|
|
|
#ifdef WITH_XCURSOR
|
2011-10-21 02:18:45 +04:00
|
|
|
XcursorImage ci;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2011-10-21 02:18:45 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
|
|
|
ZeroMemory(&ci, sizeof(ci));
|
2011-10-21 02:18:45 +04:00
|
|
|
ci.version = XCURSOR_IMAGE_VERSION;
|
|
|
|
ci.size = sizeof(ci);
|
|
|
|
ci.width = pointer->width;
|
|
|
|
ci.height = pointer->height;
|
|
|
|
ci.xhot = pointer->xPos;
|
|
|
|
ci.yhot = pointer->yPos;
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(ci.pixels = (XcursorPixel*) calloc(1, ci.width * ci.height * 4)))
|
|
|
|
{
|
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2015-04-14 11:14:23 +03:00
|
|
|
return FALSE;
|
2015-04-28 18:00:41 +03:00
|
|
|
}
|
2011-10-21 02:18:45 +04:00
|
|
|
|
2015-08-06 12:24:42 +03:00
|
|
|
if (freerdp_image_copy_from_pointer_data(
|
|
|
|
(BYTE*) ci.pixels, PIXEL_FORMAT_ARGB32,
|
|
|
|
pointer->width * 4, 0, 0, pointer->width, pointer->height,
|
|
|
|
pointer->xorMaskData, pointer->lengthXorMask,
|
|
|
|
pointer->andMaskData, pointer->lengthAndMask,
|
|
|
|
pointer->xorBpp, xfc->palette) < 0)
|
2015-08-05 18:32:46 +03:00
|
|
|
{
|
|
|
|
free(ci.pixels);
|
|
|
|
xf_unlock_x11(xfc, FALSE);
|
|
|
|
return FALSE;
|
2011-10-21 02:18:45 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
((xfPointer*) pointer)->cursor = XcursorImageLoadCursor(xfc->display, &ci);
|
2012-10-27 23:01:22 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(ci.pixels);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void xf_Pointer_Free(rdpContext* context, rdpPointer* pointer)
|
|
|
|
{
|
2012-10-27 23:01:22 +04:00
|
|
|
#ifdef WITH_XCURSOR
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2011-10-21 02:18:45 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-08-04 00:13:39 +04:00
|
|
|
if (((xfPointer*) pointer)->cursor)
|
2013-06-13 02:57:25 +04:00
|
|
|
XFreeCursor(xfc->display, ((xfPointer*) pointer)->cursor);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2012-10-27 23:01:22 +04:00
|
|
|
#endif
|
2011-10-21 02:18:45 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL xf_Pointer_Set(rdpContext* context, rdpPointer* pointer)
|
2011-10-21 02:18:45 +04:00
|
|
|
{
|
2012-10-27 23:01:22 +04:00
|
|
|
#ifdef WITH_XCURSOR
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2011-10-21 02:18:45 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-08-04 00:13:39 +04:00
|
|
|
xfc->pointer = (xfPointer*) pointer;
|
|
|
|
|
2011-11-24 22:01:34 +04:00
|
|
|
/* in RemoteApp mode, window can be null if none has had focus */
|
|
|
|
|
2013-08-04 00:13:39 +04:00
|
|
|
if (xfc->window)
|
|
|
|
XDefineCursor(xfc->display, xfc->window->handle, xfc->pointer->cursor);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
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
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL xf_Pointer_SetNull(rdpContext* context)
|
2012-02-24 16:44:23 +04:00
|
|
|
{
|
2012-10-27 23:01:22 +04:00
|
|
|
#ifdef WITH_XCURSOR
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2012-02-24 16:44:23 +04:00
|
|
|
static Cursor nullcursor = None;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2012-02-24 16:44:23 +04:00
|
|
|
if (nullcursor == None)
|
|
|
|
{
|
|
|
|
XcursorImage ci;
|
|
|
|
XcursorPixel xp = 0;
|
2013-02-07 06:57:49 +04:00
|
|
|
ZeroMemory(&ci, sizeof(ci));
|
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;
|
|
|
|
|
|
|
|
if ((xfc->window) && (nullcursor != None))
|
2013-06-13 02:57:25 +04:00
|
|
|
XDefineCursor(xfc->display, xfc->window->handle, nullcursor);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
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
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL xf_Pointer_SetDefault(rdpContext* context)
|
2012-02-24 16:44:23 +04:00
|
|
|
{
|
2012-10-27 23:01:22 +04:00
|
|
|
#ifdef WITH_XCURSOR
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2012-02-24 16:44:23 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-08-04 00:13:39 +04:00
|
|
|
xfc->pointer = NULL;
|
|
|
|
|
|
|
|
if (xfc->window)
|
2013-06-13 02:57:25 +04:00
|
|
|
XUndefineCursor(xfc->display, xfc->window->handle);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
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
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL xf_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y)
|
2015-02-02 17:32:49 +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;
|
2015-02-02 17:32:49 +03:00
|
|
|
|
2015-02-04 00:08:34 +03:00
|
|
|
if (!xfc->focused || !xfc->window)
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2015-02-02 17:32:49 +03:00
|
|
|
|
|
|
|
xf_lock_x11(xfc, FALSE);
|
|
|
|
|
2015-02-04 00:08:34 +03:00
|
|
|
if (XGetWindowAttributes(xfc->display, xfc->window->handle, ¤t) == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
tmp.event_mask = (current.your_event_mask & ~(PointerMotionMask));
|
|
|
|
if (XChangeWindowAttributes(xfc->display, xfc->window->handle, CWEventMask, &tmp) == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
XWarpPointer(xfc->display, None, xfc->window->handle, 0, 0, 0, 0, x, y);
|
|
|
|
|
|
|
|
tmp.event_mask = current.your_event_mask;
|
|
|
|
XChangeWindowAttributes(xfc->display, xfc->window->handle, CWEventMask, &tmp);
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
ret = TRUE;
|
2015-02-04 00:08:34 +03:00
|
|
|
out:
|
2015-04-14 11:14:23 +03:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
|
|
|
return ret;
|
2015-02-02 17:32:49 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
/* Glyph Class */
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL xf_Glyph_New(rdpContext* context, rdpGlyph* glyph)
|
2011-11-09 21:16:09 +04:00
|
|
|
{
|
|
|
|
int scanline;
|
|
|
|
XImage* image;
|
|
|
|
xfGlyph* xf_glyph;
|
|
|
|
|
|
|
|
xf_glyph = (xfGlyph*) glyph;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2011-11-09 21:16:09 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
scanline = (glyph->cx + 7) / 8;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_glyph->pixmap = XCreatePixmap(xfc->display, xfc->drawing, glyph->cx, glyph->cy, 1);
|
2011-11-09 21:16:09 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
image = XCreateImage(xfc->display, xfc->visual, 1,
|
2011-11-09 21:16:09 +04:00
|
|
|
ZPixmap, 0, (char*) glyph->aj, glyph->cx, glyph->cy, 8, scanline);
|
|
|
|
|
|
|
|
image->byte_order = MSBFirst;
|
|
|
|
image->bitmap_bit_order = MSBFirst;
|
|
|
|
|
|
|
|
XInitImage(image);
|
2013-06-13 02:57:25 +04:00
|
|
|
XPutImage(xfc->display, xf_glyph->pixmap, xfc->gc_mono, image, 0, 0, 0, 0, glyph->cx, glyph->cy);
|
2011-11-09 21:16:09 +04:00
|
|
|
XFree(image);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-11-09 21:16:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void xf_Glyph_Free(rdpContext* context, rdpGlyph* glyph)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2011-11-09 21:16:09 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2011-11-24 22:01:34 +04:00
|
|
|
if (((xfGlyph*) glyph)->pixmap != 0)
|
2013-06-13 02:57:25 +04:00
|
|
|
XFreePixmap(xfc->display, ((xfGlyph*) glyph)->pixmap);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2011-11-09 21:16:09 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL xf_Glyph_Draw(rdpContext* context, rdpGlyph* glyph, int x, int y)
|
2011-11-09 21:16:09 +04:00
|
|
|
{
|
2011-11-24 22:01:34 +04:00
|
|
|
xfGlyph* xf_glyph;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2011-11-24 22:01:34 +04:00
|
|
|
|
|
|
|
xf_glyph = (xfGlyph*) glyph;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XSetStipple(xfc->display, xfc->gc, xf_glyph->pixmap);
|
|
|
|
XSetTSOrigin(xfc->display, xfc->gc, x, y);
|
|
|
|
XFillRectangle(xfc->display, xfc->drawing, xfc->gc, x, y, glyph->cx, glyph->cy);
|
|
|
|
XSetStipple(xfc->display, xfc->gc, xfc->bitmap_mono);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-11-09 21:16:09 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL xf_Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor, BOOL fOpRedundant)
|
2011-11-09 21:16:09 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2011-11-24 22:01:34 +04:00
|
|
|
|
2014-12-15 18:34:09 +03:00
|
|
|
bgcolor = xf_convert_rdp_order_color(xfc, bgcolor);
|
|
|
|
fgcolor = xf_convert_rdp_order_color(xfc, fgcolor);
|
2011-11-09 21:16:09 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XSetFunction(xfc->display, xfc->gc, GXcopy);
|
2014-10-29 22:56:26 +03:00
|
|
|
|
|
|
|
if (width && height)
|
|
|
|
{
|
|
|
|
XSetFillStyle(xfc->display, xfc->gc, FillSolid);
|
|
|
|
XSetForeground(xfc->display, xfc->gc, fgcolor);
|
|
|
|
XFillRectangle(xfc->display, xfc->drawing, xfc->gc, x, y, width, height);
|
|
|
|
}
|
2011-12-13 21:18:11 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XSetForeground(xfc->display, xfc->gc, bgcolor);
|
|
|
|
XSetBackground(xfc->display, xfc->gc, fgcolor);
|
2014-10-29 22:56:26 +03:00
|
|
|
|
|
|
|
XSetFillStyle(xfc->display, xfc->gc, fOpRedundant ? FillOpaqueStippled : FillStippled);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-11-09 21:16:09 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL xf_Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor)
|
2011-11-09 21:16:09 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2015-04-17 17:21:55 +03:00
|
|
|
BOOL ret = TRUE;
|
2011-11-24 22:01:34 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-02-07 06:57:49 +04:00
|
|
|
|
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
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
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 */
|
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
BOOL xf_register_graphics(rdpGraphics* graphics)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2015-05-08 22:39:23 +03:00
|
|
|
rdpBitmap* bitmap = NULL;
|
|
|
|
rdpPointer* pointer = NULL;
|
|
|
|
rdpGlyph* glyph = NULL;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if (!(bitmap = (rdpBitmap*) calloc(1, sizeof(rdpBitmap))))
|
|
|
|
goto out;
|
2011-11-09 21:16:09 +04:00
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!(pointer = (rdpPointer*) calloc(1, sizeof(rdpPointer))))
|
|
|
|
goto out;
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!(glyph = (rdpGlyph*) calloc(1, sizeof(rdpGlyph))))
|
|
|
|
goto out;
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
bitmap->size = sizeof(xfBitmap);
|
|
|
|
bitmap->New = xf_Bitmap_New;
|
|
|
|
bitmap->Free = xf_Bitmap_Free;
|
|
|
|
bitmap->Paint = xf_Bitmap_Paint;
|
|
|
|
bitmap->Decompress = xf_Bitmap_Decompress;
|
|
|
|
bitmap->SetSurface = xf_Bitmap_SetSurface;
|
|
|
|
|
|
|
|
graphics_register_bitmap(graphics, bitmap);
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
pointer->size = sizeof(xfPointer);
|
|
|
|
pointer->New = xf_Pointer_New;
|
|
|
|
pointer->Free = xf_Pointer_Free;
|
|
|
|
pointer->Set = xf_Pointer_Set;
|
2012-02-24 16:44:23 +04:00
|
|
|
pointer->SetNull = xf_Pointer_SetNull;
|
|
|
|
pointer->SetDefault = xf_Pointer_SetDefault;
|
2015-02-02 17:32:49 +03:00
|
|
|
pointer->SetPosition = xf_Pointer_SetPosition;
|
2011-11-09 21:16:09 +04:00
|
|
|
|
|
|
|
graphics_register_pointer(graphics, pointer);
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
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);
|
2015-05-08 22:39:23 +03:00
|
|
|
|
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
out:
|
|
|
|
free(bitmap);
|
|
|
|
free(pointer);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(glyph);
|
2015-05-08 22:39:23 +03:00
|
|
|
|
|
|
|
return ret;
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|