2013-04-02 21:22:59 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* X11 Client Interface
|
|
|
|
*
|
|
|
|
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2013-04-26 02:30:39 +04:00
|
|
|
* Copyright 2013 Corey Clayton <can.of.tuna@gmail.com>
|
2014-12-01 13:17:16 +03:00
|
|
|
* Copyright 2014 Thincast Technologies GmbH
|
|
|
|
* Copyright 2014 Norbert Federa <norbert.federa@thincast.com>
|
2016-04-05 18:07:45 +03:00
|
|
|
* Copyright 2016 Armin Novak <armin.novak@thincast.com>
|
|
|
|
* Copyright 2016 Thincast Technologies GmbH
|
2013-04-02 21:22: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-08-19 19:44:52 +04:00
|
|
|
#include <assert.h>
|
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
2013-04-26 02:30:39 +04:00
|
|
|
|
2013-05-03 04:31:22 +04:00
|
|
|
#ifdef WITH_XRENDER
|
|
|
|
#include <X11/extensions/Xrender.h>
|
2014-12-01 13:56:44 +03:00
|
|
|
#include <math.h>
|
2013-05-03 04:31:22 +04:00
|
|
|
#endif
|
|
|
|
|
2013-04-26 02:30:39 +04:00
|
|
|
#ifdef WITH_XI
|
2015-07-14 01:31:12 +03:00
|
|
|
#include <X11/extensions/XInput.h>
|
2013-04-24 05:28:05 +04:00
|
|
|
#include <X11/extensions/XInput2.h>
|
2013-04-26 02:30:39 +04:00
|
|
|
#endif
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
#ifdef WITH_XCURSOR
|
|
|
|
#include <X11/Xcursor/Xcursor.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WITH_XINERAMA
|
|
|
|
#include <X11/extensions/Xinerama.h>
|
|
|
|
#endif
|
|
|
|
|
2013-05-09 05:51:16 +04:00
|
|
|
#ifdef WITH_XI
|
|
|
|
#include <X11/extensions/XInput2.h>
|
|
|
|
#endif
|
|
|
|
|
2014-10-06 12:37:37 +04:00
|
|
|
#include <X11/XKBlib.h>
|
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
|
2013-05-14 01:39:53 +04:00
|
|
|
#include <freerdp/freerdp.h>
|
2013-04-02 21:22:59 +04:00
|
|
|
#include <freerdp/constants.h>
|
|
|
|
#include <freerdp/codec/nsc.h>
|
|
|
|
#include <freerdp/codec/rfx.h>
|
|
|
|
#include <freerdp/codec/color.h>
|
|
|
|
#include <freerdp/codec/bitmap.h>
|
|
|
|
|
|
|
|
#include <freerdp/utils/signal.h>
|
|
|
|
#include <freerdp/utils/passphrase.h>
|
|
|
|
#include <freerdp/client/cliprdr.h>
|
|
|
|
#include <freerdp/client/channels.h>
|
|
|
|
|
|
|
|
#include <freerdp/client/file.h>
|
|
|
|
#include <freerdp/client/cmdline.h>
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/synch.h>
|
|
|
|
#include <winpr/file.h>
|
2013-05-02 22:30:43 +04:00
|
|
|
#include <winpr/print.h>
|
2014-10-03 18:04:15 +04:00
|
|
|
#include <X11/XKBlib.h>
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
#include "xf_gdi.h"
|
|
|
|
#include "xf_rail.h"
|
|
|
|
#include "xf_tsmf.h"
|
|
|
|
#include "xf_event.h"
|
2013-05-09 08:52:37 +04:00
|
|
|
#include "xf_input.h"
|
2013-04-02 21:22:59 +04:00
|
|
|
#include "xf_cliprdr.h"
|
|
|
|
#include "xf_monitor.h"
|
|
|
|
#include "xf_graphics.h"
|
|
|
|
#include "xf_keyboard.h"
|
2013-04-26 02:57:41 +04:00
|
|
|
#include "xf_input.h"
|
2013-05-14 03:17:25 +04:00
|
|
|
#include "xf_channels.h"
|
2013-04-28 08:23:36 +04:00
|
|
|
#include "xfreerdp.h"
|
2014-11-12 02:32:18 +03:00
|
|
|
|
2014-09-12 19:13:01 +04:00
|
|
|
#include <freerdp/log.h>
|
|
|
|
#define TAG CLIENT_TAG("x11")
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2015-02-09 19:33:55 +03:00
|
|
|
static int (*_def_error_handler)(Display*, XErrorEvent*);
|
|
|
|
static int _xf_error_handler(Display* d, XErrorEvent* ev);
|
|
|
|
static void xf_check_extensions(xfContext* context);
|
|
|
|
static void xf_window_free(xfContext* xfc);
|
|
|
|
static BOOL xf_get_pixmap_info(xfContext* xfc);
|
|
|
|
|
2013-05-25 02:38:02 +04:00
|
|
|
#ifdef WITH_XRENDER
|
2014-12-01 13:56:44 +03:00
|
|
|
static void xf_draw_screen_scaled(xfContext* xfc, int x, int y, int w, int h)
|
|
|
|
{
|
2013-05-09 05:51:16 +04:00
|
|
|
XTransform transform;
|
|
|
|
Picture windowPicture;
|
|
|
|
Picture primaryPicture;
|
2013-05-05 05:23:24 +04:00
|
|
|
XRenderPictureAttributes pa;
|
2015-02-09 19:33:55 +03:00
|
|
|
XRenderPictFormat* picFormat;
|
2014-12-01 13:17:16 +03:00
|
|
|
double xScalingFactor;
|
|
|
|
double yScalingFactor;
|
2014-12-01 13:56:44 +03:00
|
|
|
int x2;
|
|
|
|
int y2;
|
2016-07-19 17:15:38 +03:00
|
|
|
rdpSettings* settings = xfc->context.settings;
|
2014-12-01 13:17:16 +03:00
|
|
|
|
2014-12-01 13:56:44 +03:00
|
|
|
if (xfc->scaledWidth <= 0 || xfc->scaledHeight <= 0)
|
|
|
|
{
|
2015-01-30 17:47:02 +03:00
|
|
|
WLog_ERR(TAG, "the current window dimensions are invalid");
|
2014-12-01 13:17:16 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-19 17:15:38 +03:00
|
|
|
if (settings->DesktopWidth <= 0 || settings->DesktopHeight <= 0)
|
2014-12-01 13:56:44 +03:00
|
|
|
{
|
2015-01-30 17:47:02 +03:00
|
|
|
WLog_ERR(TAG, "the window dimensions are invalid");
|
2014-12-01 13:56:44 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-19 17:15:38 +03:00
|
|
|
xScalingFactor = settings->DesktopWidth / (double)xfc->scaledWidth;
|
|
|
|
yScalingFactor = settings->DesktopHeight / (double)xfc->scaledHeight;
|
2014-12-01 13:56:44 +03:00
|
|
|
XSetFillStyle(xfc->display, xfc->gc, FillSolid);
|
|
|
|
XSetForeground(xfc->display, xfc->gc, 0);
|
|
|
|
/* Black out possible space between desktop and window borders */
|
|
|
|
{
|
|
|
|
XRectangle box1 = { 0, 0, xfc->window->width, xfc->window->height };
|
|
|
|
XRectangle box2 = { xfc->offset_x, xfc->offset_y, xfc->scaledWidth, xfc->scaledHeight };
|
|
|
|
Region reg1 = XCreateRegion();
|
|
|
|
Region reg2 = XCreateRegion();
|
2015-02-09 19:33:55 +03:00
|
|
|
XUnionRectWithRegion(&box1, reg1, reg1);
|
|
|
|
XUnionRectWithRegion(&box2, reg2, reg2);
|
2014-12-01 13:56:44 +03:00
|
|
|
|
|
|
|
if (XSubtractRegion(reg1, reg2, reg1) && !XEmptyRegion(reg1))
|
|
|
|
{
|
2015-02-09 19:33:55 +03:00
|
|
|
XSetRegion(xfc->display, xfc->gc, reg1);
|
2016-04-05 18:07:45 +03:00
|
|
|
XFillRectangle(xfc->display, xfc->window->handle, xfc->gc, 0, 0,
|
2016-10-04 10:00:00 +03:00
|
|
|
xfc->window->width, xfc->window->height);
|
2014-12-01 13:56:44 +03:00
|
|
|
XSetClipMask(xfc->display, xfc->gc, None);
|
|
|
|
}
|
|
|
|
|
|
|
|
XDestroyRegion(reg1);
|
|
|
|
XDestroyRegion(reg2);
|
|
|
|
}
|
2014-12-04 19:52:54 +03:00
|
|
|
picFormat = XRenderFindVisualFormat(xfc->display, xfc->visual);
|
2013-05-09 05:51:16 +04:00
|
|
|
pa.subwindow_mode = IncludeInferiors;
|
2016-04-05 18:07:45 +03:00
|
|
|
primaryPicture = XRenderCreatePicture(xfc->display, xfc->primary, picFormat,
|
2016-10-04 10:00:00 +03:00
|
|
|
CPSubwindowMode, &pa);
|
2016-04-05 18:07:45 +03:00
|
|
|
windowPicture = XRenderCreatePicture(xfc->display, xfc->window->handle,
|
2016-10-04 10:00:00 +03:00
|
|
|
picFormat, CPSubwindowMode, &pa);
|
2014-12-01 13:17:16 +03:00
|
|
|
XRenderSetPictureFilter(xfc->display, primaryPicture, FilterBilinear, 0, 0);
|
|
|
|
transform.matrix[0][0] = XDoubleToFixed(xScalingFactor);
|
|
|
|
transform.matrix[0][1] = XDoubleToFixed(0.0);
|
|
|
|
transform.matrix[0][2] = XDoubleToFixed(0.0);
|
|
|
|
transform.matrix[1][0] = XDoubleToFixed(0.0);
|
|
|
|
transform.matrix[1][1] = XDoubleToFixed(yScalingFactor);
|
|
|
|
transform.matrix[1][2] = XDoubleToFixed(0.0);
|
|
|
|
transform.matrix[2][0] = XDoubleToFixed(0.0);
|
|
|
|
transform.matrix[2][1] = XDoubleToFixed(0.0);
|
|
|
|
transform.matrix[2][2] = XDoubleToFixed(1.0);
|
2014-12-01 13:56:44 +03:00
|
|
|
/* calculate and fix up scaled coordinates */
|
|
|
|
x2 = x + w;
|
|
|
|
y2 = y + h;
|
|
|
|
x = floor(x / xScalingFactor) - 1;
|
|
|
|
y = floor(y / yScalingFactor) - 1;
|
|
|
|
w = ceil(x2 / xScalingFactor) + 1 - x;
|
|
|
|
h = ceil(y2 / yScalingFactor) + 1 - y;
|
2013-06-13 02:57:25 +04:00
|
|
|
XRenderSetPictureTransform(xfc->display, primaryPicture, &transform);
|
2016-04-05 18:07:45 +03:00
|
|
|
XRenderComposite(xfc->display, PictOpSrc, primaryPicture, 0, windowPicture, x,
|
2016-10-04 10:00:00 +03:00
|
|
|
y, 0, 0, xfc->offset_x + x, xfc->offset_y + y, w, h);
|
2013-06-26 04:41:32 +04:00
|
|
|
XRenderFreePicture(xfc->display, primaryPicture);
|
|
|
|
XRenderFreePicture(xfc->display, windowPicture);
|
2014-12-01 13:56:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL xf_picture_transform_required(xfContext* xfc)
|
|
|
|
{
|
2016-07-19 17:15:38 +03:00
|
|
|
rdpSettings* settings = xfc->context.settings;
|
|
|
|
|
2014-12-01 13:56:44 +03:00
|
|
|
if (xfc->offset_x || xfc->offset_y ||
|
2016-07-19 17:15:38 +03:00
|
|
|
xfc->scaledWidth != settings->DesktopWidth ||
|
|
|
|
xfc->scaledHeight != settings->DesktopHeight)
|
2014-12-01 13:56:44 +03:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
2015-02-09 19:33:55 +03:00
|
|
|
|
2014-12-01 13:56:44 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-12-03 17:41:10 +03:00
|
|
|
#endif /* WITH_XRENDER defined */
|
2014-12-01 13:56:44 +03:00
|
|
|
|
|
|
|
void xf_draw_screen(xfContext* xfc, int x, int y, int w, int h)
|
|
|
|
{
|
2014-12-05 21:40:40 +03:00
|
|
|
if (w == 0 || h == 0)
|
|
|
|
{
|
2015-02-06 01:01:56 +03:00
|
|
|
WLog_WARN(TAG, "invalid width and/or height specified: w=%d h=%d", w, h);
|
2014-12-05 21:40:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-01 13:56:44 +03:00
|
|
|
#ifdef WITH_XRENDER
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
if (xf_picture_transform_required(xfc))
|
|
|
|
{
|
2014-12-01 13:56:44 +03:00
|
|
|
xf_draw_screen_scaled(xfc, x, y, w, h);
|
|
|
|
return;
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2013-05-25 02:38:02 +04:00
|
|
|
#endif
|
2016-04-05 18:07:45 +03:00
|
|
|
XCopyArea(xfc->display, xfc->primary, xfc->window->handle, xfc->gc, x, y, w, h,
|
2016-10-04 10:00:00 +03:00
|
|
|
x, y);
|
2013-05-05 05:23:24 +04:00
|
|
|
}
|
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
static BOOL xf_desktop_resize(rdpContext* context)
|
2014-12-03 17:41:10 +03:00
|
|
|
{
|
|
|
|
rdpSettings* settings;
|
|
|
|
xfContext* xfc = (xfContext*) context;
|
2016-08-03 15:16:20 +03:00
|
|
|
settings = context->settings;
|
2014-12-03 17:41:10 +03:00
|
|
|
|
|
|
|
if (xfc->primary)
|
|
|
|
{
|
|
|
|
BOOL same = (xfc->primary == xfc->drawing) ? TRUE : FALSE;
|
|
|
|
XFreePixmap(xfc->display, xfc->primary);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
if (!(xfc->primary = XCreatePixmap(
|
2016-10-04 10:00:00 +03:00
|
|
|
xfc->display, xfc->drawable,
|
|
|
|
settings->DesktopWidth,
|
|
|
|
settings->DesktopHeight, xfc->depth)))
|
2015-05-08 22:39:23 +03:00
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2014-12-03 17:41:10 +03:00
|
|
|
if (same)
|
2015-02-09 19:33:55 +03:00
|
|
|
xfc->drawing = xfc->primary;
|
2014-12-03 17:41:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WITH_XRENDER
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-08-03 15:16:20 +03:00
|
|
|
if (!xfc->context.settings->SmartSizing)
|
2014-12-03 20:23:20 +03:00
|
|
|
{
|
2016-07-19 17:15:38 +03:00
|
|
|
xfc->scaledWidth = settings->DesktopWidth;
|
|
|
|
xfc->scaledHeight = settings->DesktopHeight;
|
2014-12-03 20:23:20 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2014-12-03 17:41:10 +03:00
|
|
|
#endif
|
2014-12-03 20:08:01 +03:00
|
|
|
|
2014-12-03 17:41:10 +03:00
|
|
|
if (!xfc->fullscreen)
|
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
xf_ResizeDesktopWindow(xfc, xfc->window, settings->DesktopWidth,
|
2016-10-04 10:00:00 +03:00
|
|
|
settings->DesktopHeight);
|
2014-12-03 17:41:10 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-16 18:29:52 +03:00
|
|
|
#ifdef WITH_XRENDER
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-08-03 15:16:20 +03:00
|
|
|
if (!xfc->context.settings->SmartSizing)
|
2015-04-16 18:29:52 +03:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* Update the saved width and height values the window will be
|
|
|
|
* resized to when toggling out of fullscreen */
|
2016-07-19 17:15:38 +03:00
|
|
|
xfc->savedWidth = settings->DesktopWidth;
|
|
|
|
xfc->savedHeight = settings->DesktopHeight;
|
2015-04-16 18:29:52 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2014-12-03 17:41:10 +03:00
|
|
|
XSetFunction(xfc->display, xfc->gc, GXcopy);
|
|
|
|
XSetFillStyle(xfc->display, xfc->gc, FillSolid);
|
|
|
|
XSetForeground(xfc->display, xfc->gc, 0);
|
2016-04-05 18:07:45 +03:00
|
|
|
XFillRectangle(xfc->display, xfc->drawable, xfc->gc, 0, 0, xfc->window->width,
|
2016-10-04 10:00:00 +03:00
|
|
|
xfc->window->height);
|
2014-12-03 17:41:10 +03:00
|
|
|
}
|
2015-05-08 22:39:23 +03:00
|
|
|
|
|
|
|
return TRUE;
|
2014-12-03 17:41:10 +03:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL xf_sw_begin_paint(rdpContext* context)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-09-06 00:06:19 +04:00
|
|
|
rdpGdi* gdi = context->gdi;
|
2016-10-06 14:41:52 +03:00
|
|
|
gdi->primary->hdc->hwnd->invalid->null = TRUE;
|
2013-04-02 21:22:59 +04:00
|
|
|
gdi->primary->hdc->hwnd->ninvalid = 0;
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL xf_sw_end_paint(rdpContext* context)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-09-06 00:06:19 +04:00
|
|
|
int i;
|
2013-04-02 21:22:59 +04:00
|
|
|
INT32 x, y;
|
|
|
|
UINT32 w, h;
|
2014-09-06 00:06:19 +04:00
|
|
|
int ninvalid;
|
|
|
|
HGDI_RGN cinvalid;
|
|
|
|
xfContext* xfc = (xfContext*) context;
|
|
|
|
rdpGdi* gdi = context->gdi;
|
|
|
|
x = gdi->primary->hdc->hwnd->invalid->x;
|
|
|
|
y = gdi->primary->hdc->hwnd->invalid->y;
|
|
|
|
w = gdi->primary->hdc->hwnd->invalid->w;
|
|
|
|
h = gdi->primary->hdc->hwnd->invalid->h;
|
|
|
|
ninvalid = gdi->primary->hdc->hwnd->ninvalid;
|
|
|
|
cinvalid = gdi->primary->hdc->hwnd->cinvalid;
|
|
|
|
|
|
|
|
if (!xfc->remote_app)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-09-06 00:06:19 +04:00
|
|
|
if (!xfc->complex_regions)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-09-06 00:06:19 +04:00
|
|
|
if (gdi->primary->hdc->hwnd->invalid->null)
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2014-09-06 00:06:19 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2016-04-05 18:07:45 +03:00
|
|
|
XPutImage(xfc->display, xfc->primary, xfc->gc, xfc->image,
|
2016-10-04 10:00:00 +03:00
|
|
|
x, y, x, y, w, h);
|
2014-12-01 13:56:44 +03:00
|
|
|
xf_draw_screen(xfc, x, y, w, h);
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-06 00:06:19 +04:00
|
|
|
if (gdi->primary->hdc->hwnd->ninvalid < 1)
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2014-09-06 00:06:19 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2014-09-06 00:06:19 +04:00
|
|
|
|
|
|
|
for (i = 0; i < ninvalid; i++)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
x = cinvalid[i].x;
|
|
|
|
y = cinvalid[i].y;
|
|
|
|
w = cinvalid[i].w;
|
|
|
|
h = cinvalid[i].h;
|
2016-04-05 18:07:45 +03:00
|
|
|
XPutImage(xfc->display, xfc->primary, xfc->gc,
|
2016-10-04 10:00:00 +03:00
|
|
|
xfc->image, x, y, x, y, w, h);
|
2014-12-01 13:56:44 +03:00
|
|
|
xf_draw_screen(xfc, x, y, w, h);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2014-09-06 00:06:19 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XFlush(xfc->display);
|
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-06 00:06:19 +04:00
|
|
|
if (gdi->primary->hdc->hwnd->invalid->null)
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2014-09-06 00:06:19 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2015-10-15 22:29:48 +03:00
|
|
|
xf_rail_paint(xfc, x, y, x + w, y + h);
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL xf_sw_desktop_resize(rdpContext* context)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-09-17 03:12:26 +04:00
|
|
|
rdpGdi* gdi = context->gdi;
|
|
|
|
xfContext* xfc = (xfContext*) context;
|
2016-07-19 17:15:38 +03:00
|
|
|
rdpSettings* settings = context->settings;
|
2015-05-08 22:39:23 +03:00
|
|
|
BOOL ret = FALSE;
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, TRUE);
|
2014-09-06 00:06:19 +04:00
|
|
|
|
2016-07-19 17:15:38 +03:00
|
|
|
if (!gdi_resize(gdi, settings->DesktopWidth, settings->DesktopHeight))
|
2015-05-08 22:39:23 +03:00
|
|
|
goto out;
|
2014-09-17 03:12:26 +04:00
|
|
|
|
2014-12-03 17:41:10 +03:00
|
|
|
if (xfc->image)
|
|
|
|
{
|
|
|
|
xfc->image->data = NULL;
|
|
|
|
XDestroyImage(xfc->image);
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2014-12-03 17:41:10 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!(xfc->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap,
|
2017-01-25 10:33:04 +03:00
|
|
|
0, gdi->primary_buffer, gdi->width,
|
|
|
|
gdi->height, xfc->scanline_pad, gdi->stride)))
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
|
|
|
goto out;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2014-09-06 00:06:19 +04:00
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
ret = xf_desktop_resize(context);
|
|
|
|
out:
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, TRUE);
|
2015-05-08 22:39:23 +03:00
|
|
|
return ret;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL xf_hw_begin_paint(rdpContext* context)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-09-17 03:12:26 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2016-10-06 14:41:52 +03:00
|
|
|
xfc->hdc->hwnd->invalid->null = TRUE;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->hdc->hwnd->ninvalid = 0;
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL xf_hw_end_paint(rdpContext* context)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
INT32 x, y;
|
|
|
|
UINT32 w, h;
|
2014-09-17 03:12:26 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
|
|
|
|
|
|
|
if (!xfc->remote_app)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-09-17 03:12:26 +04:00
|
|
|
if (!xfc->complex_regions)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-09-17 03:12:26 +04:00
|
|
|
if (xfc->hdc->hwnd->invalid->null)
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2014-09-17 03:12:26 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
x = xfc->hdc->hwnd->invalid->x;
|
|
|
|
y = xfc->hdc->hwnd->invalid->y;
|
|
|
|
w = xfc->hdc->hwnd->invalid->w;
|
|
|
|
h = xfc->hdc->hwnd->invalid->h;
|
|
|
|
xf_lock_x11(xfc, FALSE);
|
2014-12-01 13:56:44 +03:00
|
|
|
xf_draw_screen(xfc, x, y, w, h);
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int ninvalid;
|
|
|
|
HGDI_RGN cinvalid;
|
2014-09-17 03:12:26 +04:00
|
|
|
|
|
|
|
if (xfc->hdc->hwnd->ninvalid < 1)
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2014-09-17 03:12:26 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
ninvalid = xfc->hdc->hwnd->ninvalid;
|
|
|
|
cinvalid = xfc->hdc->hwnd->cinvalid;
|
|
|
|
xf_lock_x11(xfc, FALSE);
|
2014-09-17 03:12:26 +04:00
|
|
|
|
|
|
|
for (i = 0; i < ninvalid; i++)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
x = cinvalid[i].x;
|
|
|
|
y = cinvalid[i].y;
|
|
|
|
w = cinvalid[i].w;
|
|
|
|
h = cinvalid[i].h;
|
2014-12-01 13:56:44 +03:00
|
|
|
xf_draw_screen(xfc, x, y, w, h);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2014-09-17 03:12:26 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XFlush(xfc->display);
|
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-17 03:12:26 +04:00
|
|
|
if (xfc->hdc->hwnd->invalid->null)
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2014-09-17 03:12:26 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
x = xfc->hdc->hwnd->invalid->x;
|
|
|
|
y = xfc->hdc->hwnd->invalid->y;
|
|
|
|
w = xfc->hdc->hwnd->invalid->w;
|
|
|
|
h = xfc->hdc->hwnd->invalid->h;
|
|
|
|
xf_lock_x11(xfc, FALSE);
|
2015-10-15 22:29:48 +03:00
|
|
|
xf_rail_paint(xfc, x, y, x + w, y + h);
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL xf_hw_desktop_resize(rdpContext* context)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2016-11-17 09:36:02 +03:00
|
|
|
rdpGdi* gdi = context->gdi;
|
2014-11-12 06:27:33 +03:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2016-11-17 09:36:02 +03:00
|
|
|
rdpSettings* settings = context->settings;
|
|
|
|
BOOL ret = FALSE;
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, TRUE);
|
2016-11-17 09:36:02 +03:00
|
|
|
|
|
|
|
if (!gdi_resize(gdi, settings->DesktopWidth, settings->DesktopHeight))
|
|
|
|
goto out;
|
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
ret = xf_desktop_resize(context);
|
2016-11-17 09:36:02 +03:00
|
|
|
out:
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, TRUE);
|
2015-05-08 22:39:23 +03:00
|
|
|
return ret;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
static BOOL xf_process_x_events(freerdp* instance)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
BOOL status;
|
|
|
|
XEvent xevent;
|
|
|
|
int pending_status;
|
2014-11-12 06:27:33 +03:00
|
|
|
xfContext* xfc = (xfContext*) instance->context;
|
2013-04-02 21:22:59 +04:00
|
|
|
status = TRUE;
|
|
|
|
pending_status = TRUE;
|
2014-11-12 06:27:33 +03:00
|
|
|
|
|
|
|
while (pending_status)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
|
|
|
pending_status = XPending(xfc->display);
|
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2014-11-12 01:49:29 +03:00
|
|
|
if (pending_status)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
ZeroMemory(&xevent, sizeof(xevent));
|
2013-06-13 02:57:25 +04:00
|
|
|
XNextEvent(xfc->display, &xevent);
|
2013-04-02 21:22:59 +04:00
|
|
|
status = xf_event_process(instance, &xevent);
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2014-11-12 01:49:29 +03:00
|
|
|
if (!status)
|
2013-04-02 21:22:59 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-02-09 19:33:55 +03:00
|
|
|
BOOL xf_create_window(xfContext* xfc)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2015-02-10 23:15:30 +03:00
|
|
|
XGCValues gcv;
|
2013-04-02 21:22:59 +04:00
|
|
|
XEvent xevent;
|
|
|
|
int width, height;
|
2014-11-12 06:27:33 +03:00
|
|
|
char* windowTitle;
|
2016-08-03 15:16:20 +03:00
|
|
|
rdpGdi* gdi;
|
|
|
|
rdpSettings* settings;
|
|
|
|
settings = xfc->context.settings;
|
|
|
|
gdi = xfc->context.gdi;
|
2015-02-09 19:33:55 +03:00
|
|
|
ZeroMemory(&xevent, sizeof(xevent));
|
2016-07-19 17:15:38 +03:00
|
|
|
width = settings->DesktopWidth;
|
|
|
|
height = settings->DesktopHeight;
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
if (!xfc->hdc)
|
2016-08-03 15:16:20 +03:00
|
|
|
if (!(xfc->hdc = gdi_CreateDC(gdi->dstFormat)))
|
2015-05-08 22:39:23 +03:00
|
|
|
return FALSE;
|
2015-02-10 23:15:30 +03:00
|
|
|
|
2014-11-12 01:49:29 +03:00
|
|
|
if (!xfc->remote_app)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->attribs.background_pixel = BlackPixelOfScreen(xfc->screen);
|
|
|
|
xfc->attribs.border_pixel = WhitePixelOfScreen(xfc->screen);
|
|
|
|
xfc->attribs.backing_store = xfc->primary ? NotUseful : Always;
|
2015-02-23 20:22:28 +03:00
|
|
|
xfc->attribs.override_redirect = False;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->attribs.colormap = xfc->colormap;
|
|
|
|
xfc->attribs.bit_gravity = NorthWestGravity;
|
|
|
|
xfc->attribs.win_gravity = NorthWestGravity;
|
2014-12-01 13:56:44 +03:00
|
|
|
#ifdef WITH_XRENDER
|
|
|
|
xfc->offset_x = 0;
|
|
|
|
xfc->offset_y = 0;
|
|
|
|
#endif
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
if (settings->WindowTitle)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2015-02-10 23:15:30 +03:00
|
|
|
windowTitle = _strdup(settings->WindowTitle);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!windowTitle)
|
|
|
|
return FALSE;
|
2014-11-12 06:27:33 +03:00
|
|
|
}
|
2015-02-10 23:15:30 +03:00
|
|
|
else if (settings->ServerPort == 3389)
|
2014-11-12 06:27:33 +03:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
windowTitle = malloc(1 + sizeof("FreeRDP: ") + strlen(
|
2016-10-04 10:00:00 +03:00
|
|
|
settings->ServerHostname));
|
2015-02-10 23:15:30 +03:00
|
|
|
sprintf(windowTitle, "FreeRDP: %s", settings->ServerHostname);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
else
|
2014-11-12 06:27:33 +03:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
windowTitle = malloc(1 + sizeof("FreeRDP: ") + strlen(settings->ServerHostname)
|
2016-10-04 10:00:00 +03:00
|
|
|
+ sizeof(":00000"));
|
2016-04-05 18:07:45 +03:00
|
|
|
sprintf(windowTitle, "FreeRDP: %s:%i", settings->ServerHostname,
|
2016-10-04 10:00:00 +03:00
|
|
|
settings->ServerPort);
|
2014-11-12 06:27:33 +03:00
|
|
|
}
|
|
|
|
|
2014-12-01 13:56:44 +03:00
|
|
|
#ifdef WITH_XRENDER
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-04-16 18:29:52 +03:00
|
|
|
if (settings->SmartSizing && !xfc->fullscreen)
|
2014-12-01 13:56:44 +03:00
|
|
|
{
|
2015-04-16 18:29:52 +03:00
|
|
|
if (settings->SmartSizingWidth)
|
|
|
|
width = settings->SmartSizingWidth;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-04-16 18:29:52 +03:00
|
|
|
if (settings->SmartSizingHeight)
|
|
|
|
height = settings->SmartSizingHeight;
|
2015-04-17 00:54:56 +03:00
|
|
|
|
|
|
|
xfc->scaledWidth = width;
|
|
|
|
xfc->scaledHeight = height;
|
2014-12-01 13:56:44 +03:00
|
|
|
}
|
2015-02-10 23:15:30 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
#endif
|
2015-02-23 20:22:28 +03:00
|
|
|
xfc->window = xf_CreateDesktopWindow(xfc, windowTitle, width, height);
|
2013-04-09 01:03:21 +04:00
|
|
|
free(windowTitle);
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2014-11-12 01:49:29 +03:00
|
|
|
if (xfc->fullscreen)
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_SetWindowFullscreen(xfc, xfc->window, xfc->fullscreen);
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->unobscured = (xevent.xvisibility.state == VisibilityUnobscured);
|
|
|
|
XSetWMProtocols(xfc->display, xfc->window->handle, &(xfc->WM_DELETE_WINDOW), 1);
|
|
|
|
xfc->drawable = xfc->window->handle;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->drawable = DefaultRootWindow(xfc->display);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2015-02-09 19:33:55 +03:00
|
|
|
|
|
|
|
ZeroMemory(&gcv, sizeof(gcv));
|
|
|
|
|
|
|
|
if (xfc->modifierMap)
|
|
|
|
XFreeModifiermap(xfc->modifierMap);
|
|
|
|
|
|
|
|
xfc->modifierMap = XGetModifierMapping(xfc->display);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-05-17 19:24:11 +03:00
|
|
|
if (!xfc->gc)
|
2015-05-07 15:36:07 +03:00
|
|
|
xfc->gc = XCreateGC(xfc->display, xfc->drawable, GCGraphicsExposures, &gcv);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-05-17 19:24:11 +03:00
|
|
|
if (!xfc->primary)
|
2016-07-19 17:15:38 +03:00
|
|
|
xfc->primary = XCreatePixmap(xfc->display, xfc->drawable,
|
2016-10-04 10:00:00 +03:00
|
|
|
settings->DesktopWidth,
|
|
|
|
settings->DesktopHeight, xfc->depth);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-02-09 19:33:55 +03:00
|
|
|
xfc->drawing = xfc->primary;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-05-17 19:24:11 +03:00
|
|
|
if (!xfc->bitmap_mono)
|
2015-05-07 15:36:07 +03:00
|
|
|
xfc->bitmap_mono = XCreatePixmap(xfc->display, xfc->drawable, 8, 8, 1);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-05-17 19:24:11 +03:00
|
|
|
if (!xfc->gc_mono)
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->gc_mono = XCreateGC(xfc->display, xfc->bitmap_mono, GCGraphicsExposures,
|
2016-10-04 10:00:00 +03:00
|
|
|
&gcv);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-02-09 19:33:55 +03:00
|
|
|
XSetFunction(xfc->display, xfc->gc, GXcopy);
|
|
|
|
XSetFillStyle(xfc->display, xfc->gc, FillSolid);
|
|
|
|
XSetForeground(xfc->display, xfc->gc, BlackPixelOfScreen(xfc->screen));
|
2016-07-19 17:15:38 +03:00
|
|
|
XFillRectangle(xfc->display, xfc->primary, xfc->gc, 0, 0,
|
2016-10-04 10:00:00 +03:00
|
|
|
settings->DesktopWidth,
|
|
|
|
settings->DesktopHeight);
|
2015-02-09 19:33:55 +03:00
|
|
|
XFlush(xfc->display);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-05-17 19:24:11 +03:00
|
|
|
if (!xfc->image)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
|
|
|
rdpGdi* gdi = xfc->context.gdi;
|
|
|
|
xfc->image = XCreateImage(xfc->display, xfc->visual,
|
2016-10-04 10:00:00 +03:00
|
|
|
xfc->depth,
|
|
|
|
ZPixmap, 0, (char*) gdi->primary_buffer,
|
|
|
|
settings->DesktopWidth, settings->DesktopHeight,
|
2017-01-25 10:33:04 +03:00
|
|
|
xfc->scanline_pad, gdi->stride);
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2015-02-10 23:15:30 +03:00
|
|
|
|
2015-02-09 19:33:55 +03:00
|
|
|
return TRUE;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
static void xf_window_free(xfContext* xfc)
|
2015-02-10 23:15:30 +03:00
|
|
|
{
|
|
|
|
if (xfc->gc_mono)
|
|
|
|
{
|
|
|
|
XFreeGC(xfc->display, xfc->gc_mono);
|
|
|
|
xfc->gc_mono = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xfc->window)
|
|
|
|
{
|
|
|
|
xf_DestroyDesktopWindow(xfc, xfc->window);
|
|
|
|
xfc->window = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xfc->hdc)
|
|
|
|
{
|
|
|
|
gdi_DeleteDC(xfc->hdc);
|
|
|
|
xfc->hdc = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xfc->xv_context)
|
|
|
|
{
|
|
|
|
xf_tsmf_uninit(xfc, NULL);
|
|
|
|
xfc->xv_context = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xfc->image)
|
|
|
|
{
|
|
|
|
xfc->image->data = NULL;
|
|
|
|
XDestroyImage(xfc->image);
|
|
|
|
xfc->image = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xfc->bitmap_mono)
|
|
|
|
{
|
|
|
|
XFreePixmap(xfc->display, xfc->bitmap_mono);
|
|
|
|
xfc->bitmap_mono = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xfc->primary)
|
|
|
|
{
|
|
|
|
XFreePixmap(xfc->display, xfc->primary);
|
|
|
|
xfc->primary = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xfc->gc)
|
|
|
|
{
|
|
|
|
XFreeGC(xfc->display, xfc->gc);
|
|
|
|
xfc->gc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xfc->modifierMap)
|
|
|
|
{
|
|
|
|
XFreeModifiermap(xfc->modifierMap);
|
|
|
|
xfc->modifierMap = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 01:17:06 +04:00
|
|
|
void xf_toggle_fullscreen(xfContext* xfc)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-16 01:01:10 +04:00
|
|
|
WindowStateChangeEventArgs e;
|
2015-02-10 23:15:30 +03:00
|
|
|
rdpContext* context = (rdpContext*) xfc;
|
|
|
|
rdpSettings* settings = context->settings;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->fullscreen = (xfc->fullscreen) ? FALSE : TRUE;
|
2015-02-10 23:15:30 +03:00
|
|
|
xfc->decorations = (xfc->fullscreen) ? FALSE : settings->Decorations;
|
2015-02-23 20:22:28 +03:00
|
|
|
xf_SetWindowFullscreen(xfc, xfc->window, xfc->fullscreen);
|
2013-06-18 08:39:48 +04:00
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2013-06-16 01:01:10 +04:00
|
|
|
e.state = xfc->fullscreen ? FREERDP_WINDOW_STATE_FULLSCREEN : 0;
|
2015-02-10 23:15:30 +03:00
|
|
|
PubSub_OnWindowStateChange(context->pubSub, context, &e);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2014-07-01 01:17:06 +04:00
|
|
|
void xf_toggle_control(xfContext* xfc)
|
|
|
|
{
|
|
|
|
EncomspClientContext* encomsp;
|
|
|
|
ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU pdu;
|
|
|
|
encomsp = xfc->encomsp;
|
|
|
|
|
|
|
|
if (!encomsp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pdu.ParticipantId = 0;
|
|
|
|
pdu.Flags = ENCOMSP_REQUEST_VIEW;
|
|
|
|
|
|
|
|
if (!xfc->controlToggle)
|
|
|
|
pdu.Flags |= ENCOMSP_REQUEST_INTERACT;
|
|
|
|
|
|
|
|
encomsp->ChangeParticipantControlLevel(encomsp, &pdu);
|
|
|
|
xfc->controlToggle = !xfc->controlToggle;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2016-07-14 17:08:06 +03:00
|
|
|
static UINT xf_encomsp_participant_created(EncomspClientContext* context,
|
2016-10-04 10:00:00 +03:00
|
|
|
ENCOMSP_PARTICIPANT_CREATED_PDU* participantCreated)
|
2014-07-01 01:17:06 +04:00
|
|
|
{
|
2015-06-08 15:44:10 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2014-07-01 01:17:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void xf_encomsp_init(xfContext* xfc, EncomspClientContext* encomsp)
|
|
|
|
{
|
|
|
|
xfc->encomsp = encomsp;
|
|
|
|
encomsp->custom = (void*) xfc;
|
|
|
|
encomsp->ParticipantCreated = xf_encomsp_participant_created;
|
|
|
|
}
|
|
|
|
|
|
|
|
void xf_encomsp_uninit(xfContext* xfc, EncomspClientContext* encomsp)
|
|
|
|
{
|
|
|
|
xfc->encomsp = NULL;
|
|
|
|
}
|
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
void xf_lock_x11(xfContext* xfc, BOOL display)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-11-12 01:49:29 +03:00
|
|
|
if (!xfc->UseXThreads)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
WaitForSingleObject(xfc->mutex, INFINITE);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-12 01:49:29 +03:00
|
|
|
if (display)
|
2013-06-13 02:57:25 +04:00
|
|
|
XLockDisplay(xfc->display);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
void xf_unlock_x11(xfContext* xfc, BOOL display)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-11-12 01:49:29 +03:00
|
|
|
if (!xfc->UseXThreads)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
ReleaseMutex(xfc->mutex);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-12 01:49:29 +03:00
|
|
|
if (display)
|
2013-06-13 02:57:25 +04:00
|
|
|
XUnlockDisplay(xfc->display);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-15 18:34:09 +03:00
|
|
|
static void xf_calculate_color_shifts(UINT32 mask, UINT8* rsh, UINT8* lsh)
|
|
|
|
{
|
2015-02-09 19:33:55 +03:00
|
|
|
for (*lsh = 0; !(mask & 1); mask >>= 1)
|
|
|
|
(*lsh)++;
|
|
|
|
|
|
|
|
for (*rsh = 8; mask; mask >>= 1)
|
|
|
|
(*rsh)--;
|
2014-12-15 18:34:09 +03:00
|
|
|
}
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
static BOOL xf_get_pixmap_info(xfContext* xfc)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int vi_count;
|
|
|
|
int pf_count;
|
2015-02-09 19:33:55 +03:00
|
|
|
XVisualInfo* vi;
|
|
|
|
XVisualInfo* vis;
|
2016-08-03 11:54:50 +03:00
|
|
|
XVisualInfo tpl;
|
2015-02-09 19:33:55 +03:00
|
|
|
XPixmapFormatValues* pf;
|
|
|
|
XPixmapFormatValues* pfs;
|
2013-04-02 21:22:59 +04:00
|
|
|
XWindowAttributes window_attributes;
|
2015-02-09 19:33:55 +03:00
|
|
|
assert(xfc->display);
|
2013-06-13 02:57:25 +04:00
|
|
|
pfs = XListPixmapFormats(xfc->display, &pf_count);
|
2014-10-22 06:19:11 +04:00
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
if (!pfs)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2015-01-30 17:47:02 +03:00
|
|
|
WLog_ERR(TAG, "XListPixmapFormats failed");
|
2013-04-02 21:22:59 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2014-10-22 06:19:11 +04:00
|
|
|
|
|
|
|
for (i = 0; i < pf_count; i++)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
pf = pfs + i;
|
2014-10-22 06:19:11 +04:00
|
|
|
|
|
|
|
if (pf->depth == xfc->depth)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->scanline_pad = pf->scanline_pad;
|
2013-04-02 21:22:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-10-22 06:19:11 +04:00
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
XFree(pfs);
|
2016-08-03 11:54:50 +03:00
|
|
|
ZeroMemory(&tpl, sizeof(tpl));
|
|
|
|
tpl.class = TrueColor;
|
|
|
|
tpl.screen = xfc->screen_number;
|
2014-10-22 06:19:11 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (XGetWindowAttributes(xfc->display, RootWindowOfScreen(xfc->screen),
|
2016-10-04 10:00:00 +03:00
|
|
|
&window_attributes) == 0)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2015-01-30 17:47:02 +03:00
|
|
|
WLog_ERR(TAG, "XGetWindowAttributes failed");
|
2013-04-02 21:22:59 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-10-22 06:19:11 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
vis = XGetVisualInfo(xfc->display, VisualClassMask | VisualScreenMask,
|
2016-10-04 10:00:00 +03:00
|
|
|
&tpl, &vi_count);
|
2014-10-22 06:19:11 +04:00
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
if (!vis)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2015-01-30 17:47:02 +03:00
|
|
|
WLog_ERR(TAG, "XGetVisualInfo failed");
|
2013-04-02 21:22:59 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-10-22 06:19:11 +04:00
|
|
|
|
2015-01-13 14:43:27 +03:00
|
|
|
vi = vis;
|
2014-10-22 06:19:11 +04:00
|
|
|
|
|
|
|
for (i = 0; i < vi_count; i++)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
vi = vis + i;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2014-11-12 01:49:29 +03:00
|
|
|
if (vi->visual == window_attributes.visual)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->visual = vi->visual;
|
2013-04-02 21:22:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-10-22 06:19:11 +04:00
|
|
|
|
2014-12-15 18:34:09 +03:00
|
|
|
if (xfc->visual)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
/*
|
2016-07-18 15:16:13 +03:00
|
|
|
* Detect if the server visual has an inverted colormap
|
|
|
|
* (BGR vs RGB, or red being the least significant byte)
|
|
|
|
*/
|
2014-10-22 06:19:11 +04:00
|
|
|
if (vi->red_mask & 0xFF)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-10-22 06:19:11 +04:00
|
|
|
xfc->invert = TRUE;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2014-12-15 18:34:09 +03:00
|
|
|
|
|
|
|
/* calculate color shifts required for rdp order color conversion */
|
|
|
|
xf_calculate_color_shifts(vi->red_mask, &xfc->red_shift_r, &xfc->red_shift_l);
|
2016-04-05 18:07:45 +03:00
|
|
|
xf_calculate_color_shifts(vi->green_mask, &xfc->green_shift_r,
|
2016-10-04 10:00:00 +03:00
|
|
|
&xfc->green_shift_l);
|
2016-04-05 18:07:45 +03:00
|
|
|
xf_calculate_color_shifts(vi->blue_mask, &xfc->blue_shift_r,
|
2016-10-04 10:00:00 +03:00
|
|
|
&xfc->blue_shift_l);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2014-10-22 06:19:11 +04:00
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
XFree(vis);
|
2014-10-22 06:19:11 +04:00
|
|
|
|
|
|
|
if ((xfc->visual == NULL) || (xfc->scanline_pad == 0))
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-10-22 06:19:11 +04:00
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
static int xf_error_handler(Display* d, XErrorEvent* ev)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
int do_abort = TRUE;
|
|
|
|
XGetErrorText(d, ev->error_code, buf, sizeof(buf));
|
2014-11-12 06:27:33 +03:00
|
|
|
WLog_ERR(TAG, "%s", buf);
|
|
|
|
|
2014-11-12 01:49:29 +03:00
|
|
|
if (do_abort)
|
2013-04-02 21:22:59 +04:00
|
|
|
abort();
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
_def_error_handler(d, ev);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
static int _xf_error_handler(Display* d, XErrorEvent* ev)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
/*
|
2014-05-23 15:08:22 +04:00
|
|
|
* ungrab the keyboard, in case a debugger is running in
|
|
|
|
* another window. This make xf_error_handler() a potential
|
|
|
|
* debugger breakpoint.
|
|
|
|
*/
|
2013-04-02 21:22:59 +04:00
|
|
|
XUngrabKeyboard(d, CurrentTime);
|
|
|
|
return xf_error_handler(d, ev);
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static BOOL xf_play_sound(rdpContext* context,
|
2016-10-04 10:00:00 +03:00
|
|
|
const PLAY_SOUND_UPDATE* play_sound)
|
2014-10-03 18:04:15 +04:00
|
|
|
{
|
|
|
|
xfContext* xfc = (xfContext*) context;
|
|
|
|
XkbBell(xfc->display, None, 100, 0);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2014-10-03 18:04:15 +04:00
|
|
|
}
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
static void xf_check_extensions(xfContext* context)
|
2014-10-06 12:37:37 +04:00
|
|
|
{
|
|
|
|
int xkb_opcode, xkb_event, xkb_error;
|
|
|
|
int xkb_major = XkbMajorVersion;
|
|
|
|
int xkb_minor = XkbMinorVersion;
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (XkbLibraryVersion(&xkb_major, &xkb_minor)
|
2016-07-14 17:08:06 +03:00
|
|
|
&& XkbQueryExtension(context->display, &xkb_opcode, &xkb_event,
|
2016-10-04 10:00:00 +03:00
|
|
|
&xkb_error, &xkb_major, &xkb_minor))
|
2014-10-06 12:37:37 +04:00
|
|
|
{
|
|
|
|
context->xkbAvailable = TRUE;
|
|
|
|
}
|
2014-12-03 17:41:10 +03:00
|
|
|
|
|
|
|
#ifdef WITH_XRENDER
|
|
|
|
{
|
|
|
|
int xrender_event_base;
|
|
|
|
int xrender_error_base;
|
2015-02-09 19:33:55 +03:00
|
|
|
|
|
|
|
if (XRenderQueryExtension(context->display, &xrender_event_base,
|
2016-10-04 10:00:00 +03:00
|
|
|
&xrender_error_base))
|
2014-12-03 17:41:10 +03:00
|
|
|
{
|
|
|
|
context->xrenderAvailable = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2014-10-06 12:37:37 +04:00
|
|
|
}
|
|
|
|
|
2015-07-14 01:31:12 +03:00
|
|
|
#ifdef WITH_XI
|
|
|
|
/* Input device which does NOT have the correct mapping. We must disregard */
|
|
|
|
/* this device when trying to find the input device which is the pointer. */
|
|
|
|
static const char TEST_PTR_STR [] = "Virtual core XTEST pointer";
|
2016-04-05 18:07:45 +03:00
|
|
|
static const size_t TEST_PTR_LEN = sizeof(TEST_PTR_STR) / sizeof(char);
|
2015-07-14 01:31:12 +03:00
|
|
|
|
|
|
|
/* Invalid device identifier which indicate failure. */
|
|
|
|
static const int INVALID_XID = -1;
|
|
|
|
#endif /* WITH_XI */
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static void xf_get_x11_button_map(xfContext* xfc, unsigned char* x11_map)
|
2015-07-14 01:31:12 +03:00
|
|
|
{
|
|
|
|
#ifdef WITH_XI
|
|
|
|
int opcode, event, error;
|
|
|
|
int xid;
|
|
|
|
XDevice* ptr_dev;
|
|
|
|
XExtensionVersion* version;
|
|
|
|
XDeviceInfo* devices1;
|
|
|
|
XIDeviceInfo* devices2;
|
|
|
|
int i, num_devices;
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (XQueryExtension(xfc->display, "XInputExtension", &opcode, &event, &error))
|
2015-07-14 01:31:12 +03:00
|
|
|
{
|
|
|
|
WLog_DBG(TAG, "Searching for XInput pointer device");
|
|
|
|
xid = INVALID_XID;
|
|
|
|
/* loop through every device, looking for a pointer */
|
2016-04-05 18:07:45 +03:00
|
|
|
version = XGetExtensionVersion(xfc->display, INAME);
|
|
|
|
|
2015-07-14 01:31:12 +03:00
|
|
|
if (version->major_version >= 2)
|
|
|
|
{
|
|
|
|
/* XID of pointer device using XInput version 2 */
|
2016-04-05 18:07:45 +03:00
|
|
|
devices2 = XIQueryDevice(xfc->display, XIAllDevices, &num_devices);
|
|
|
|
|
2015-07-14 01:31:12 +03:00
|
|
|
if (devices2)
|
|
|
|
{
|
|
|
|
for (i = 0; i < num_devices; ++i)
|
|
|
|
{
|
|
|
|
if ((devices2[i].use == XISlavePointer) &&
|
2016-07-14 17:08:06 +03:00
|
|
|
(strncmp(devices2[i].name, TEST_PTR_STR, TEST_PTR_LEN) != 0))
|
2015-07-14 01:31:12 +03:00
|
|
|
{
|
|
|
|
xid = devices2[i].deviceid;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
XIFreeDeviceInfo(devices2);
|
2015-07-14 01:31:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* XID of pointer device using XInput version 1 */
|
2016-04-05 18:07:45 +03:00
|
|
|
devices1 = XListInputDevices(xfc->display, &num_devices);
|
|
|
|
|
2015-07-14 01:31:12 +03:00
|
|
|
if (devices1)
|
|
|
|
{
|
|
|
|
for (i = 0; i < num_devices; ++i)
|
|
|
|
{
|
|
|
|
if ((devices1[i].use == IsXExtensionPointer) &&
|
2016-07-14 17:08:06 +03:00
|
|
|
(strncmp(devices1[i].name, TEST_PTR_STR, TEST_PTR_LEN) != 0))
|
2015-07-14 01:31:12 +03:00
|
|
|
{
|
|
|
|
xid = devices1[i].id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
XFreeDeviceList(devices1);
|
2015-07-14 01:31:12 +03:00
|
|
|
}
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
XFree(version);
|
|
|
|
|
2015-07-14 01:31:12 +03:00
|
|
|
/* get button mapping from input extension if there is a pointer device; */
|
|
|
|
/* otherwise leave unchanged. */
|
|
|
|
if (xid != INVALID_XID)
|
|
|
|
{
|
|
|
|
WLog_DBG(TAG, "Pointer device: %d", xid);
|
2016-04-05 18:07:45 +03:00
|
|
|
ptr_dev = XOpenDevice(xfc->display, xid);
|
|
|
|
XGetDeviceButtonMapping(xfc->display, ptr_dev, x11_map, NUM_BUTTONS_MAPPED);
|
|
|
|
XCloseDevice(xfc->display, ptr_dev);
|
2015-07-14 01:31:12 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_DBG(TAG, "No pointer device found!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif /* WITH_XI */
|
|
|
|
{
|
|
|
|
WLog_DBG(TAG, "Get global pointer mapping (no XInput)");
|
2016-04-05 18:07:45 +03:00
|
|
|
XGetPointerMapping(xfc->display, x11_map, NUM_BUTTONS_MAPPED);
|
2015-07-14 01:31:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 23:59:18 +03:00
|
|
|
/* Assignment of physical (not logical) mouse buttons to wire flags. */
|
|
|
|
/* Notice that the middle button is 2 in X11, but 3 in RDP. */
|
2016-04-05 18:07:45 +03:00
|
|
|
static const int xf_button_flags[NUM_BUTTONS_MAPPED] =
|
|
|
|
{
|
2015-07-13 23:59:18 +03:00
|
|
|
PTR_FLAGS_BUTTON1,
|
|
|
|
PTR_FLAGS_BUTTON3,
|
|
|
|
PTR_FLAGS_BUTTON2
|
|
|
|
};
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static void xf_button_map_init(xfContext* xfc)
|
2015-07-13 23:59:18 +03:00
|
|
|
{
|
|
|
|
/* loop counter for array initialization */
|
|
|
|
int physical;
|
|
|
|
int logical;
|
|
|
|
/* logical mouse button which is used for each physical mouse */
|
|
|
|
/* button (indexed from zero). This is the default map. */
|
2016-04-05 18:07:45 +03:00
|
|
|
unsigned char x11_map[NUM_BUTTONS_MAPPED] =
|
|
|
|
{
|
2015-07-13 23:59:18 +03:00
|
|
|
Button1,
|
|
|
|
Button2,
|
|
|
|
Button3
|
|
|
|
};
|
|
|
|
|
2015-07-14 01:31:12 +03:00
|
|
|
/* query system for actual remapping */
|
2016-08-03 15:16:20 +03:00
|
|
|
if (!xfc->context.settings->UnmapButtons)
|
2015-07-14 02:03:33 +03:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
xf_get_x11_button_map(xfc, x11_map);
|
2015-07-14 02:03:33 +03:00
|
|
|
}
|
2015-07-14 01:31:12 +03:00
|
|
|
|
2015-07-13 23:59:18 +03:00
|
|
|
/* iterate over all (mapped) physical buttons; for each of them */
|
|
|
|
/* find the logical button in X11, and assign to this the */
|
|
|
|
/* appropriate value to send over the RDP wire. */
|
|
|
|
for (physical = 0; physical < NUM_BUTTONS_MAPPED; ++physical)
|
|
|
|
{
|
|
|
|
logical = x11_map[physical];
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-07-13 23:59:18 +03:00
|
|
|
if (Button1 <= logical && logical <= Button3)
|
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->button_map[logical - BUTTON_BASE] = xf_button_flags[physical];
|
2015-07-13 23:59:18 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
WLog_ERR(TAG, "Mouse physical button %d is mapped to logical button %d",
|
2016-10-04 10:00:00 +03:00
|
|
|
physical, logical);
|
2015-07-13 23:59:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
/**
|
2016-07-18 15:16:13 +03:00
|
|
|
* Callback given to freerdp_connect() to process the pre-connect operations.
|
|
|
|
* It will fill the rdp_freerdp structure (instance) with the appropriate options to use for the connection.
|
|
|
|
*
|
|
|
|
* @param instance - pointer to the rdp_freerdp structure that contains the connection's parameters, and will
|
|
|
|
* be filled with the appropriate informations.
|
|
|
|
*
|
|
|
|
* @return TRUE if successful. FALSE otherwise.
|
|
|
|
* Can exit with error code XF_EXIT_PARSE_ARGUMENTS if there is an error in the parameters.
|
|
|
|
*/
|
2016-07-14 17:08:06 +03:00
|
|
|
static BOOL xf_pre_connect(freerdp* instance)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-09-10 08:42:41 +04:00
|
|
|
rdpChannels* channels;
|
|
|
|
rdpSettings* settings;
|
2015-02-10 23:15:30 +03:00
|
|
|
rdpContext* context = instance->context;
|
2014-09-10 08:42:41 +04:00
|
|
|
xfContext* xfc = (xfContext*) instance->context;
|
2015-04-16 18:29:52 +03:00
|
|
|
UINT32 maxWidth = 0;
|
|
|
|
UINT32 maxHeight = 0;
|
2013-04-02 21:22:59 +04:00
|
|
|
settings = instance->settings;
|
2015-02-10 23:15:30 +03:00
|
|
|
channels = context->channels;
|
2013-12-10 21:30:25 +04:00
|
|
|
settings->OsMajorType = OSMAJORTYPE_UNIX;
|
|
|
|
settings->OsMinorType = OSMINORTYPE_NATIVE_XSERVER;
|
|
|
|
ZeroMemory(settings->OrderSupport, 32);
|
|
|
|
settings->OrderSupport[NEG_DSTBLT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_PATBLT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_SCRBLT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_OPAQUE_RECT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_DRAWNINEGRID_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_MULTIDSTBLT_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_MULTIPATBLT_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_MULTISCRBLT_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_MULTIOPAQUERECT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_MULTI_DRAWNINEGRID_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_LINETO_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_POLYLINE_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_MEMBLT_INDEX] = settings->BitmapCacheEnabled;
|
2016-08-10 18:01:54 +03:00
|
|
|
settings->OrderSupport[NEG_MEM3BLT_INDEX] = settings->BitmapCacheEnabled;
|
2013-12-10 21:30:25 +04:00
|
|
|
settings->OrderSupport[NEG_MEMBLT_V2_INDEX] = settings->BitmapCacheEnabled;
|
2016-08-10 18:01:54 +03:00
|
|
|
settings->OrderSupport[NEG_MEM3BLT_V2_INDEX] = settings->BitmapCacheEnabled;
|
2013-12-10 21:30:25 +04:00
|
|
|
settings->OrderSupport[NEG_SAVEBITMAP_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_GLYPH_INDEX_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_FAST_INDEX_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_FAST_GLYPH_INDEX] = TRUE;
|
2016-10-16 16:08:47 +03:00
|
|
|
settings->OrderSupport[NEG_POLYGON_SC_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_POLYGON_CB_INDEX] = FALSE;
|
2013-12-10 21:30:25 +04:00
|
|
|
settings->OrderSupport[NEG_ELLIPSE_SC_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_ELLIPSE_CB_INDEX] = FALSE;
|
2013-07-11 19:53:15 +04:00
|
|
|
PubSub_SubscribeChannelConnected(instance->context->pubSub,
|
2016-10-04 10:00:00 +03:00
|
|
|
(pChannelConnectedEventHandler) xf_OnChannelConnectedEventHandler);
|
2013-07-11 19:53:15 +04:00
|
|
|
PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
|
2016-10-04 10:00:00 +03:00
|
|
|
(pChannelDisconnectedEventHandler) xf_OnChannelDisconnectedEventHandler);
|
2015-02-10 23:15:30 +03:00
|
|
|
|
2016-03-07 14:54:49 +03:00
|
|
|
if (!freerdp_client_load_addins(channels, instance->settings))
|
|
|
|
return FALSE;
|
|
|
|
|
2015-06-23 15:59:54 +03:00
|
|
|
if (!settings->Username && !settings->CredentialsFromStdin)
|
2014-12-08 20:07:05 +03:00
|
|
|
{
|
2015-02-09 19:33:55 +03:00
|
|
|
char* login_name = getlogin();
|
|
|
|
|
2014-12-08 20:07:05 +03:00
|
|
|
if (login_name)
|
|
|
|
{
|
|
|
|
settings->Username = _strdup(login_name);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!settings->Username)
|
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2014-12-08 20:07:05 +03:00
|
|
|
WLog_INFO(TAG, "No user name set. - Using login name: %s", settings->Username);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-17 03:12:26 +04:00
|
|
|
if (settings->AuthenticationOnly)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-12-08 20:13:54 +03:00
|
|
|
/* Check +auth-only has a username and password. */
|
2014-09-17 03:12:26 +04:00
|
|
|
if (!settings->Password)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-12-08 20:13:54 +03:00
|
|
|
WLog_INFO(TAG, "auth-only, but no password set. Please provide one.");
|
2013-09-05 16:27:34 +04:00
|
|
|
return FALSE;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2014-09-17 03:12:26 +04:00
|
|
|
|
2014-09-18 03:09:56 +04:00
|
|
|
WLog_INFO(TAG, "Authentication only. Don't connect to X.");
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2014-09-17 03:12:26 +04:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!xf_keyboard_init(xfc))
|
|
|
|
return FALSE;
|
2015-02-10 23:15:30 +03:00
|
|
|
|
2015-04-16 18:29:52 +03:00
|
|
|
xf_detect_monitors(xfc, &maxWidth, &maxHeight);
|
|
|
|
|
|
|
|
if (maxWidth && maxHeight)
|
|
|
|
{
|
|
|
|
settings->DesktopWidth = maxWidth;
|
|
|
|
settings->DesktopHeight = maxHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WITH_XRENDER
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-04-16 18:29:52 +03:00
|
|
|
/**
|
|
|
|
* If /f is specified in combination with /smart-sizing:widthxheight then
|
|
|
|
* we run the session in the /smart-sizing dimensions scaled to full screen
|
|
|
|
*/
|
|
|
|
if (settings->Fullscreen && settings->SmartSizing &&
|
2016-07-14 17:08:06 +03:00
|
|
|
settings->SmartSizingWidth && settings->SmartSizingHeight)
|
2015-04-16 18:29:52 +03:00
|
|
|
{
|
|
|
|
settings->DesktopWidth = settings->SmartSizingWidth;
|
|
|
|
settings->DesktopHeight = settings->SmartSizingHeight;
|
|
|
|
}
|
2015-02-10 23:15:30 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
#endif
|
2015-02-10 23:15:30 +03:00
|
|
|
xfc->fullscreen = settings->Fullscreen;
|
|
|
|
xfc->decorations = settings->Decorations;
|
|
|
|
xfc->grab_keyboard = settings->GrabKeyboard;
|
|
|
|
xfc->fullscreen_toggle = settings->ToggleFullscreen;
|
2016-04-05 18:07:45 +03:00
|
|
|
xf_button_map_init(xfc);
|
2013-04-02 21:22:59 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-18 15:16:13 +03:00
|
|
|
* Callback given to freerdp_connect() to perform post-connection operations.
|
|
|
|
* It will be called only if the connection was initialized properly, and will continue the initialization based on the
|
|
|
|
* newly created connection.
|
|
|
|
*/
|
2016-07-14 17:08:06 +03:00
|
|
|
static BOOL xf_post_connect(freerdp* instance)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2015-02-10 23:15:30 +03:00
|
|
|
rdpUpdate* update;
|
|
|
|
rdpContext* context;
|
2014-07-08 23:07:19 +04:00
|
|
|
rdpChannels* channels;
|
|
|
|
rdpSettings* settings;
|
2013-06-16 01:01:10 +04:00
|
|
|
ResizeWindowEventArgs e;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) instance->context;
|
2015-02-10 23:15:30 +03:00
|
|
|
context = instance->context;
|
|
|
|
channels = context->channels;
|
2013-04-02 21:22:59 +04:00
|
|
|
settings = instance->settings;
|
2015-02-10 23:15:30 +03:00
|
|
|
update = context->update;
|
|
|
|
|
2016-08-03 15:16:20 +03:00
|
|
|
if (!gdi_init(instance, xf_get_local_color_format(xfc, TRUE)))
|
2015-05-08 22:39:23 +03:00
|
|
|
return FALSE;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2016-07-18 15:16:13 +03:00
|
|
|
if (!xf_register_pointer(context->graphics))
|
2016-04-05 18:07:45 +03:00
|
|
|
return FALSE;
|
2014-10-22 06:19:11 +04:00
|
|
|
|
2016-07-15 17:45:36 +03:00
|
|
|
if (!settings->SoftwareGdi)
|
2016-07-18 15:16:13 +03:00
|
|
|
{
|
|
|
|
if (!xf_register_graphics(context->graphics))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "failed to register graphics");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
xf_gdi_register_update_callbacks(update);
|
2016-07-21 14:00:57 +03:00
|
|
|
brush_cache_register_callbacks(instance->update);
|
|
|
|
glyph_cache_register_callbacks(instance->update);
|
|
|
|
bitmap_cache_register_callbacks(instance->update);
|
|
|
|
offscreen_cache_register_callbacks(instance->update);
|
|
|
|
palette_cache_register_callbacks(instance->update);
|
2016-07-18 15:16:13 +03:00
|
|
|
}
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2014-12-01 13:56:44 +03:00
|
|
|
#ifdef WITH_XRENDER
|
2016-07-19 17:15:38 +03:00
|
|
|
xfc->scaledWidth = settings->DesktopWidth;
|
|
|
|
xfc->scaledHeight = settings->DesktopHeight;
|
2014-12-01 13:56:44 +03:00
|
|
|
xfc->offset_x = 0;
|
|
|
|
xfc->offset_y = 0;
|
|
|
|
#endif
|
|
|
|
|
2014-12-03 17:41:10 +03:00
|
|
|
if (!xfc->xrenderAvailable)
|
|
|
|
{
|
|
|
|
if (settings->SmartSizing)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "XRender not available: disabling smart-sizing");
|
|
|
|
settings->SmartSizing = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings->MultiTouchGestures)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "XRender not available: disabling local multi-touch gestures");
|
|
|
|
settings->MultiTouchGestures = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
if (settings->RemoteApplicationMode)
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->remote_app = TRUE;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!xf_create_window(xfc))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "xf_create_window failed");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2014-09-12 06:29:09 +04:00
|
|
|
if (settings->SoftwareGdi)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2015-02-10 23:15:30 +03:00
|
|
|
update->BeginPaint = xf_sw_begin_paint;
|
|
|
|
update->EndPaint = xf_sw_end_paint;
|
|
|
|
update->DesktopResize = xf_sw_desktop_resize;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-10 23:15:30 +03:00
|
|
|
update->BeginPaint = xf_hw_begin_paint;
|
|
|
|
update->EndPaint = xf_hw_end_paint;
|
|
|
|
update->DesktopResize = xf_hw_desktop_resize;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
pointer_cache_register_callbacks(update);
|
|
|
|
update->PlaySound = xf_play_sound;
|
|
|
|
update->SetKeyboardIndicators = xf_keyboard_set_indicators;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2015-10-20 22:28:29 +03:00
|
|
|
if (!(xfc->clipboard = xf_clipboard_new(xfc)))
|
|
|
|
return FALSE;
|
|
|
|
|
2013-06-18 08:39:48 +04:00
|
|
|
EventArgsInit(&e, "xfreerdp");
|
2013-06-16 01:01:10 +04:00
|
|
|
e.width = settings->DesktopWidth;
|
|
|
|
e.height = settings->DesktopHeight;
|
2015-02-10 23:15:30 +03:00
|
|
|
PubSub_OnResizeWindow(context->pubSub, xfc, &e);
|
2013-04-02 21:22:59 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
static void xf_post_disconnect(freerdp* instance)
|
|
|
|
{
|
|
|
|
xfContext* xfc;
|
|
|
|
rdpContext* context;
|
|
|
|
|
|
|
|
if (!instance || !instance->context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
context = instance->context;
|
|
|
|
xfc = (xfContext*) context;
|
|
|
|
gdi_free(instance);
|
|
|
|
|
|
|
|
if (xfc->clipboard)
|
|
|
|
{
|
|
|
|
xf_clipboard_free(xfc->clipboard);
|
|
|
|
xfc->clipboard = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
xf_window_free(xfc);
|
|
|
|
xf_keyboard_free(xfc);
|
|
|
|
}
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
static int xf_logon_error_info(freerdp* instance, UINT32 data, UINT32 type)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-11-12 06:27:33 +03:00
|
|
|
xfContext* xfc = (xfContext*) instance->context;
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_rail_disable_remoteapp_mode(xfc);
|
2013-04-02 21:22:59 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
static void* xf_input_thread(void* arg)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-12-05 23:48:24 +03:00
|
|
|
DWORD status;
|
2014-12-15 17:42:04 +03:00
|
|
|
DWORD nCount;
|
2016-09-13 10:53:16 +03:00
|
|
|
HANDLE events[3];
|
2013-04-02 21:22:59 +04:00
|
|
|
XEvent xevent;
|
2014-12-05 23:48:24 +03:00
|
|
|
wMessage msg;
|
2015-01-30 17:47:02 +03:00
|
|
|
wMessageQueue* queue;
|
2013-04-02 21:22:59 +04:00
|
|
|
int pending_status = 1;
|
|
|
|
int process_status = 1;
|
2014-12-15 17:42:04 +03:00
|
|
|
freerdp* instance = (freerdp*) arg;
|
|
|
|
xfContext* xfc = (xfContext*) instance->context;
|
2013-09-06 11:02:46 +04:00
|
|
|
queue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE);
|
2014-12-15 17:42:04 +03:00
|
|
|
nCount = 0;
|
|
|
|
events[nCount++] = MessageQueue_Event(queue);
|
2015-01-30 17:47:02 +03:00
|
|
|
events[nCount++] = xfc->x11event;
|
2016-09-13 10:53:16 +03:00
|
|
|
events[nCount++] = instance->context->abortEvent;
|
2014-10-15 06:24:07 +04:00
|
|
|
|
2015-02-09 19:33:55 +03:00
|
|
|
while (1)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-12-15 17:42:04 +03:00
|
|
|
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
|
2015-02-09 19:33:55 +03:00
|
|
|
|
2014-12-15 17:42:04 +03:00
|
|
|
if (WaitForSingleObject(events[0], 0) == WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
if (MessageQueue_Peek(queue, &msg, FALSE))
|
|
|
|
{
|
|
|
|
if (msg.id == WMQ_QUIT)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WaitForSingleObject(events[1], 0) == WAIT_OBJECT_0)
|
2014-05-27 00:54:34 +04:00
|
|
|
{
|
2014-12-05 23:48:24 +03:00
|
|
|
do
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2014-12-05 23:48:24 +03:00
|
|
|
pending_status = XPending(xfc->display);
|
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2014-12-05 23:48:24 +03:00
|
|
|
if (pending_status)
|
|
|
|
{
|
|
|
|
xf_lock_x11(xfc, FALSE);
|
|
|
|
ZeroMemory(&xevent, sizeof(xevent));
|
|
|
|
XNextEvent(xfc->display, &xevent);
|
|
|
|
process_status = xf_event_process(instance, &xevent);
|
|
|
|
xf_unlock_x11(xfc, FALSE);
|
|
|
|
|
|
|
|
if (!process_status)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (pending_status);
|
|
|
|
|
|
|
|
if (!process_status)
|
|
|
|
break;
|
|
|
|
}
|
2016-09-13 10:53:16 +03:00
|
|
|
|
|
|
|
if (WaitForSingleObject(events[2], 0) == WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2014-10-15 06:24:07 +04:00
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
MessageQueue_PostQuit(queue, 0);
|
2013-09-05 16:27:34 +04:00
|
|
|
ExitThread(0);
|
2013-04-02 21:22:59 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
static BOOL xf_auto_reconnect(freerdp* instance)
|
2014-01-17 02:38:56 +04:00
|
|
|
{
|
2015-02-06 01:01:56 +03:00
|
|
|
UINT32 maxRetries;
|
|
|
|
UINT32 numRetries = 0;
|
2016-08-03 15:16:20 +03:00
|
|
|
rdpSettings* settings = instance->settings;
|
2015-02-06 01:01:56 +03:00
|
|
|
maxRetries = settings->AutoReconnectMaxRetries;
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2014-01-17 02:38:56 +04:00
|
|
|
/* Only auto reconnect on network disconnects. */
|
2014-11-12 01:49:29 +03:00
|
|
|
if (freerdp_error_info(instance) != 0)
|
2014-02-28 01:55:07 +04:00
|
|
|
return FALSE;
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2014-01-17 02:38:56 +04:00
|
|
|
/* A network disconnect was detected */
|
2015-02-06 01:01:56 +03:00
|
|
|
WLog_INFO(TAG, "Network disconnect!");
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2015-02-06 01:01:56 +03:00
|
|
|
if (!settings->AutoReconnectionEnabled)
|
2014-01-17 02:38:56 +04:00
|
|
|
{
|
|
|
|
/* No auto-reconnect - just quit */
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2014-01-17 02:38:56 +04:00
|
|
|
/* Perform an auto-reconnect. */
|
2015-02-06 01:01:56 +03:00
|
|
|
while (TRUE)
|
2014-01-17 02:38:56 +04:00
|
|
|
{
|
|
|
|
/* Quit retrying if max retries has been exceeded */
|
2017-01-09 14:34:09 +03:00
|
|
|
if ((maxRetries > 0) && (numRetries++ >= maxRetries))
|
2014-01-17 02:38:56 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2014-01-17 02:38:56 +04:00
|
|
|
/* Attempt the next reconnect */
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_INFO(TAG, "Attempting reconnect (%"PRIu32" of %"PRIu32")", numRetries, maxRetries);
|
2015-02-06 01:01:56 +03:00
|
|
|
|
2014-11-12 01:49:29 +03:00
|
|
|
if (freerdp_reconnect(instance))
|
2014-01-17 02:38:56 +04:00
|
|
|
return TRUE;
|
2015-02-06 01:01:56 +03:00
|
|
|
|
2014-01-17 02:38:56 +04:00
|
|
|
sleep(5);
|
|
|
|
}
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2015-01-30 17:47:02 +03:00
|
|
|
WLog_ERR(TAG, "Maximum reconnect retries exceeded");
|
2014-01-17 02:38:56 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
/** Main loop for the rdp connection.
|
2016-07-18 15:16:13 +03:00
|
|
|
* It will be run from the thread's entry point (thread_func()).
|
|
|
|
* It initiates the connection, and will continue to run until the session ends,
|
|
|
|
* processing events as they are received.
|
|
|
|
* @param instance - pointer to the rdp_freerdp structure that contains the session's settings
|
|
|
|
* @return A code from the enum XF_EXIT_CODE (0 if successful)
|
|
|
|
*/
|
2016-07-14 17:08:06 +03:00
|
|
|
static void* xf_client_thread(void* param)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
BOOL status;
|
2013-04-02 22:51:12 +04:00
|
|
|
int exit_code;
|
2015-01-30 17:47:02 +03:00
|
|
|
DWORD nCount;
|
|
|
|
DWORD waitStatus;
|
|
|
|
HANDLE handles[64];
|
|
|
|
xfContext* xfc;
|
|
|
|
freerdp* instance;
|
|
|
|
rdpContext* context;
|
2015-06-02 16:04:34 +03:00
|
|
|
HANDLE inputEvent = NULL;
|
|
|
|
HANDLE inputThread = NULL;
|
2015-01-30 17:47:02 +03:00
|
|
|
rdpChannels* channels;
|
|
|
|
rdpSettings* settings;
|
2013-04-02 22:51:12 +04:00
|
|
|
exit_code = 0;
|
2015-01-30 17:47:02 +03:00
|
|
|
instance = (freerdp*) param;
|
|
|
|
context = instance->context;
|
2013-04-02 21:22:59 +04:00
|
|
|
status = freerdp_connect(instance);
|
2014-11-12 06:27:33 +03:00
|
|
|
xfc = (xfContext*) instance->context;
|
|
|
|
|
2015-09-03 22:45:40 +03:00
|
|
|
/* --authonly ? */
|
|
|
|
if (instance->settings->AuthenticationOnly)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "Authentication only, exit status %"PRId32"", !status);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-09-03 22:45:40 +03:00
|
|
|
if (!status)
|
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
if (freerdp_get_last_error(instance->context) ==
|
2016-07-14 17:08:06 +03:00
|
|
|
FREERDP_ERROR_AUTHENTICATION_FAILED)
|
2015-09-03 22:45:40 +03:00
|
|
|
exit_code = XF_EXIT_AUTH_FAILURE;
|
|
|
|
else
|
|
|
|
exit_code = XF_EXIT_CONN_FAILED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
exit_code = XF_EXIT_SUCCESS;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-09-03 22:45:40 +03:00
|
|
|
goto disconnect;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "Freerdp connect error exit status %"PRId32"", !status);
|
2015-09-03 22:45:40 +03:00
|
|
|
exit_code = freerdp_error_info(instance);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
if (freerdp_get_last_error(instance->context) ==
|
2016-07-14 17:08:06 +03:00
|
|
|
FREERDP_ERROR_AUTHENTICATION_FAILED)
|
2015-09-03 22:45:40 +03:00
|
|
|
exit_code = XF_EXIT_AUTH_FAILURE;
|
2015-08-05 00:52:44 +03:00
|
|
|
else
|
|
|
|
exit_code = XF_EXIT_CONN_FAILED;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-05-05 14:55:48 +03:00
|
|
|
goto disconnect;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
channels = context->channels;
|
|
|
|
settings = context->settings;
|
2014-07-14 21:27:50 +04:00
|
|
|
|
2015-01-30 17:47:02 +03:00
|
|
|
if (!settings->AsyncInput)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2015-01-30 17:47:02 +03:00
|
|
|
inputEvent = xfc->x11event;
|
2016-09-13 10:53:16 +03:00
|
|
|
handles[0] = inputEvent;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2015-01-30 17:47:02 +03:00
|
|
|
else
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!(inputThread = CreateThread(NULL, 0,
|
2016-10-04 10:00:00 +03:00
|
|
|
(LPTHREAD_START_ROUTINE) xf_input_thread, instance, 0, NULL)))
|
2015-05-05 14:55:48 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "async input: failed to create input thread");
|
|
|
|
exit_code = XF_EXIT_UNKNOWN;
|
|
|
|
goto disconnect;
|
|
|
|
}
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2016-09-13 10:53:16 +03:00
|
|
|
while (!freerdp_shall_disconnect(instance))
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-09-09 20:41:57 +04:00
|
|
|
/*
|
2016-12-15 14:09:05 +03:00
|
|
|
* win8 and server 2k12 seem to have some timing issue/race condition
|
|
|
|
* when a initial sync request is send to sync the keyboard indicators
|
|
|
|
* sending the sync event twice fixed this problem
|
|
|
|
*/
|
2014-11-12 01:49:29 +03:00
|
|
|
if (freerdp_focus_required(instance))
|
2013-04-15 14:14:09 +04:00
|
|
|
{
|
2014-03-14 05:10:22 +04:00
|
|
|
xf_keyboard_focus_in(xfc);
|
|
|
|
xf_keyboard_focus_in(xfc);
|
2013-04-15 14:14:09 +04:00
|
|
|
}
|
2014-11-12 01:49:29 +03:00
|
|
|
|
2016-09-13 10:53:16 +03:00
|
|
|
nCount = (settings->AsyncInput) ? 0 : 1;
|
2014-11-12 01:49:29 +03:00
|
|
|
|
2015-01-30 17:47:02 +03:00
|
|
|
if (!settings->AsyncTransport)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2015-04-21 13:24:50 +03:00
|
|
|
DWORD tmp = freerdp_get_event_handles(context, &handles[nCount], 64 - nCount);
|
|
|
|
|
|
|
|
if (tmp == 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "freerdp_get_event_handles failed");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nCount += tmp;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2014-11-12 01:49:29 +03:00
|
|
|
|
2015-02-06 01:01:56 +03:00
|
|
|
waitStatus = WaitForMultipleObjects(nCount, handles, FALSE, 100);
|
2014-11-12 01:49:29 +03:00
|
|
|
|
2015-01-30 17:47:02 +03:00
|
|
|
if (!settings->AsyncTransport)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2015-01-30 17:47:02 +03:00
|
|
|
if (!freerdp_check_event_handles(context))
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-11-12 01:49:29 +03:00
|
|
|
if (xf_auto_reconnect(instance))
|
2014-02-28 01:55:07 +04:00
|
|
|
continue;
|
2014-11-12 01:49:29 +03:00
|
|
|
|
2015-01-30 17:47:02 +03:00
|
|
|
WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
|
2013-04-02 21:22:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-11-12 01:49:29 +03:00
|
|
|
|
2015-01-30 17:47:02 +03:00
|
|
|
if (!settings->AsyncInput)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2014-11-12 01:49:29 +03:00
|
|
|
if (!xf_process_x_events(instance))
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2015-01-30 17:47:02 +03:00
|
|
|
WLog_INFO(TAG, "Closed from X11");
|
2013-04-02 21:22:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-14 21:27:50 +04:00
|
|
|
|
2015-01-30 17:47:02 +03:00
|
|
|
if (settings->AsyncInput)
|
2013-09-05 16:27:34 +04:00
|
|
|
{
|
2016-09-13 10:53:16 +03:00
|
|
|
WaitForSingleObject(inputThread, INFINITE);
|
2015-01-30 17:47:02 +03:00
|
|
|
CloseHandle(inputThread);
|
2013-09-05 16:27:34 +04:00
|
|
|
}
|
2014-11-12 01:49:29 +03:00
|
|
|
|
|
|
|
if (!exit_code)
|
2013-04-02 22:51:12 +04:00
|
|
|
exit_code = freerdp_error_info(instance);
|
2014-11-12 01:49:29 +03:00
|
|
|
|
2015-05-05 14:55:48 +03:00
|
|
|
disconnect:
|
2013-04-02 21:22:59 +04:00
|
|
|
freerdp_disconnect(instance);
|
2013-04-02 22:51:12 +04:00
|
|
|
ExitThread(exit_code);
|
2013-05-15 20:12:47 +04:00
|
|
|
return NULL;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2013-04-02 22:51:12 +04:00
|
|
|
DWORD xf_exit_code_from_disconnect_reason(DWORD reason)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
if (reason == 0 || (reason >= XF_EXIT_PARSE_ARGUMENTS
|
2016-10-04 10:00:00 +03:00
|
|
|
&& reason <= XF_EXIT_AUTH_FAILURE))
|
2016-08-03 11:54:50 +03:00
|
|
|
return reason;
|
2013-04-02 21:22:59 +04:00
|
|
|
/* License error set */
|
2014-11-12 06:27:33 +03:00
|
|
|
else if (reason >= 0x100 && reason <= 0x10A)
|
2016-08-03 11:54:50 +03:00
|
|
|
reason -= 0x100 + XF_EXIT_LICENSE_INTERNAL;
|
2013-04-02 21:22:59 +04:00
|
|
|
/* RDP protocol error set */
|
2014-11-12 06:27:33 +03:00
|
|
|
else if (reason >= 0x10c9 && reason <= 0x1193)
|
2016-08-03 11:54:50 +03:00
|
|
|
reason = XF_EXIT_RDP;
|
2013-04-02 21:22:59 +04:00
|
|
|
/* There's no need to test protocol-independent codes: they match */
|
2015-02-10 02:15:07 +03:00
|
|
|
else if (!(reason <= 0xC))
|
2016-08-03 11:54:50 +03:00
|
|
|
reason = XF_EXIT_UNKNOWN;
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
return reason;
|
|
|
|
}
|
2013-04-02 23:13:10 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
static void xf_TerminateEventHandler(rdpContext* context, TerminateEventArgs* e)
|
2013-06-19 00:55:23 +04:00
|
|
|
{
|
2016-09-13 10:53:16 +03:00
|
|
|
freerdp_abort_connect(context->instance);
|
2013-06-19 00:55:23 +04:00
|
|
|
}
|
|
|
|
|
2014-12-03 17:41:10 +03:00
|
|
|
#ifdef WITH_XRENDER
|
2016-04-05 18:07:45 +03:00
|
|
|
static void xf_ZoomingChangeEventHandler(rdpContext* context,
|
2016-10-04 10:00:00 +03:00
|
|
|
ZoomingChangeEventArgs* e)
|
2013-06-27 23:07:40 +04:00
|
|
|
{
|
2014-09-12 06:29:09 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2016-07-19 17:15:38 +03:00
|
|
|
rdpSettings* settings = context->settings;
|
2014-12-01 13:56:44 +03:00
|
|
|
int w = xfc->scaledWidth + e->dx;
|
|
|
|
int h = xfc->scaledHeight + e->dy;
|
2014-09-12 06:29:09 +04:00
|
|
|
|
2014-12-01 13:56:44 +03:00
|
|
|
if (e->dx == 0 && e->dy == 0)
|
|
|
|
return;
|
2014-09-12 06:29:09 +04:00
|
|
|
|
2014-12-01 13:56:44 +03:00
|
|
|
if (w < 10)
|
2016-08-03 11:54:50 +03:00
|
|
|
w = 10;
|
2014-09-12 06:29:09 +04:00
|
|
|
|
2014-12-01 13:56:44 +03:00
|
|
|
if (h < 10)
|
2016-08-03 11:54:50 +03:00
|
|
|
h = 10;
|
2014-09-12 06:29:09 +04:00
|
|
|
|
2014-12-01 13:56:44 +03:00
|
|
|
if (w == xfc->scaledWidth && h == xfc->scaledHeight)
|
|
|
|
return;
|
2014-09-12 06:29:09 +04:00
|
|
|
|
2014-12-01 13:56:44 +03:00
|
|
|
xfc->scaledWidth = w;
|
|
|
|
xfc->scaledHeight = h;
|
2016-07-19 17:15:38 +03:00
|
|
|
xf_draw_screen(xfc, 0, 0, settings->DesktopWidth, settings->DesktopHeight);
|
2014-12-01 13:56:44 +03:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static void xf_PanningChangeEventHandler(rdpContext* context,
|
2016-10-04 10:00:00 +03:00
|
|
|
PanningChangeEventArgs* e)
|
2014-12-01 13:56:44 +03:00
|
|
|
{
|
|
|
|
xfContext* xfc = (xfContext*) context;
|
2016-07-19 17:15:38 +03:00
|
|
|
rdpSettings* settings = context->settings;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
|
|
|
if (e->dx == 0 && e->dy == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
xfc->offset_x += e->dx;
|
|
|
|
xfc->offset_y += e->dy;
|
2016-07-19 17:15:38 +03:00
|
|
|
xf_draw_screen(xfc, 0, 0, settings->DesktopWidth, settings->DesktopHeight);
|
2013-06-27 23:07:40 +04:00
|
|
|
}
|
2014-12-03 17:41:10 +03:00
|
|
|
#endif
|
2013-06-27 23:07:40 +04:00
|
|
|
|
2013-04-02 23:13:10 +04:00
|
|
|
/**
|
2016-07-18 15:16:13 +03:00
|
|
|
* Client Interface
|
|
|
|
*/
|
2013-04-02 23:13:10 +04:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
static BOOL xfreerdp_client_global_init()
|
2013-04-02 23:13:10 +04:00
|
|
|
{
|
|
|
|
setlocale(LC_ALL, "");
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
if (freerdp_handle_signals() != 0)
|
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-04-02 23:13:10 +04:00
|
|
|
}
|
|
|
|
|
2013-08-30 16:19:50 +04:00
|
|
|
static void xfreerdp_client_global_uninit()
|
2013-04-02 23:13:10 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
static int xfreerdp_client_start(rdpContext* context)
|
2013-04-02 23:13:10 +04:00
|
|
|
{
|
2015-02-09 19:33:55 +03:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2014-09-12 06:29:09 +04:00
|
|
|
rdpSettings* settings = context->settings;
|
|
|
|
|
|
|
|
if (!settings->ServerHostname)
|
2013-04-22 16:33:41 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
WLog_ERR(TAG,
|
2016-10-04 10:00:00 +03:00
|
|
|
"error: server hostname was not specified with /v:<server>[:port]");
|
2013-04-22 16:33:41 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2015-02-06 01:01:56 +03:00
|
|
|
|
2015-05-05 14:55:48 +03:00
|
|
|
if (!(xfc->thread = CreateThread(NULL, 0,
|
2016-10-04 10:00:00 +03:00
|
|
|
(LPTHREAD_START_ROUTINE) xf_client_thread,
|
|
|
|
context->instance, 0, NULL)))
|
2015-05-05 14:55:48 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "failed to create client thread");
|
|
|
|
return -1;
|
|
|
|
}
|
2015-02-06 01:01:56 +03:00
|
|
|
|
2013-04-02 23:13:10 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-12 06:29:09 +04:00
|
|
|
static int xfreerdp_client_stop(rdpContext* context)
|
2013-04-02 23:13:10 +04:00
|
|
|
{
|
2014-09-12 06:29:09 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2016-09-13 10:53:16 +03:00
|
|
|
freerdp_abort_connect(context->instance);
|
2014-09-12 06:29:09 +04:00
|
|
|
|
|
|
|
if (xfc->thread)
|
2013-09-05 16:44:35 +04:00
|
|
|
{
|
2015-02-06 01:01:56 +03:00
|
|
|
WaitForSingleObject(xfc->thread, INFINITE);
|
2013-09-05 16:44:35 +04:00
|
|
|
CloseHandle(xfc->thread);
|
|
|
|
xfc->thread = NULL;
|
|
|
|
}
|
2014-09-12 06:29:09 +04:00
|
|
|
|
2013-04-02 23:13:10 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
static BOOL xfreerdp_client_new(freerdp* instance, rdpContext* context)
|
2013-04-02 23:13:10 +04:00
|
|
|
{
|
2014-09-12 06:29:09 +04:00
|
|
|
rdpSettings* settings;
|
2015-02-10 23:15:30 +03:00
|
|
|
xfContext* xfc = (xfContext*) instance->context;
|
2015-04-28 18:00:41 +03:00
|
|
|
assert(context);
|
|
|
|
assert(xfc);
|
|
|
|
assert(!xfc->display);
|
|
|
|
assert(!xfc->mutex);
|
|
|
|
assert(!xfc->x11event);
|
2013-04-02 23:45:48 +04:00
|
|
|
instance->PreConnect = xf_pre_connect;
|
|
|
|
instance->PostConnect = xf_post_connect;
|
2013-08-19 19:44:52 +04:00
|
|
|
instance->PostDisconnect = xf_post_disconnect;
|
2015-12-17 18:43:55 +03:00
|
|
|
instance->Authenticate = client_cli_authenticate;
|
|
|
|
instance->GatewayAuthenticate = client_cli_gw_authenticate;
|
|
|
|
instance->VerifyCertificate = client_cli_verify_certificate;
|
|
|
|
instance->VerifyChangedCertificate = client_cli_verify_changed_certificate;
|
2013-04-02 23:45:48 +04:00
|
|
|
instance->LogonErrorInfo = xf_logon_error_info;
|
2013-04-07 01:43:27 +04:00
|
|
|
settings = instance->settings;
|
2016-04-05 18:07:45 +03:00
|
|
|
PubSub_SubscribeTerminate(context->pubSub,
|
2016-10-04 10:00:00 +03:00
|
|
|
(pTerminateEventHandler) xf_TerminateEventHandler);
|
2014-12-03 17:41:10 +03:00
|
|
|
#ifdef WITH_XRENDER
|
2016-04-05 18:07:45 +03:00
|
|
|
PubSub_SubscribeZoomingChange(context->pubSub,
|
2016-10-04 10:00:00 +03:00
|
|
|
(pZoomingChangeEventHandler) xf_ZoomingChangeEventHandler);
|
2016-04-05 18:07:45 +03:00
|
|
|
PubSub_SubscribePanningChange(context->pubSub,
|
2016-10-04 10:00:00 +03:00
|
|
|
(pPanningChangeEventHandler) xf_PanningChangeEventHandler);
|
2014-12-03 17:41:10 +03:00
|
|
|
#endif
|
2015-02-09 19:33:55 +03:00
|
|
|
xfc->UseXThreads = TRUE;
|
2016-04-05 18:07:45 +03:00
|
|
|
//xfc->debug = TRUE;
|
2015-02-09 19:33:55 +03:00
|
|
|
|
|
|
|
if (xfc->UseXThreads)
|
|
|
|
{
|
|
|
|
if (!XInitThreads())
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "XInitThreads() failure");
|
|
|
|
xfc->UseXThreads = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xfc->display = XOpenDisplay(NULL);
|
|
|
|
|
|
|
|
if (!xfc->display)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "failed to open display: %s", XDisplayName(NULL));
|
2016-04-05 18:07:45 +03:00
|
|
|
WLog_ERR(TAG,
|
2016-10-04 10:00:00 +03:00
|
|
|
"Please check that the $DISPLAY environment variable is properly set.");
|
2015-04-28 18:00:41 +03:00
|
|
|
goto fail_open_display;
|
2015-02-09 19:33:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
xfc->mutex = CreateMutex(NULL, FALSE, NULL);
|
|
|
|
|
|
|
|
if (!xfc->mutex)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Could not create mutex!");
|
2015-04-28 18:00:41 +03:00
|
|
|
goto fail_create_mutex;
|
2015-02-09 19:33:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
xfc->_NET_WM_ICON = XInternAtom(xfc->display, "_NET_WM_ICON", False);
|
|
|
|
xfc->_MOTIF_WM_HINTS = XInternAtom(xfc->display, "_MOTIF_WM_HINTS", False);
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->_NET_CURRENT_DESKTOP = XInternAtom(xfc->display, "_NET_CURRENT_DESKTOP",
|
2016-10-04 10:00:00 +03:00
|
|
|
False);
|
2015-02-09 19:33:55 +03:00
|
|
|
xfc->_NET_WORKAREA = XInternAtom(xfc->display, "_NET_WORKAREA", False);
|
|
|
|
xfc->_NET_WM_STATE = XInternAtom(xfc->display, "_NET_WM_STATE", False);
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->_NET_WM_STATE_FULLSCREEN = XInternAtom(xfc->display,
|
2016-10-04 10:00:00 +03:00
|
|
|
"_NET_WM_STATE_FULLSCREEN", False);
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->_NET_WM_STATE_MAXIMIZED_HORZ = XInternAtom(xfc->display,
|
2016-10-04 10:00:00 +03:00
|
|
|
"_NET_WM_STATE_MAXIMIZED_HORZ", False);
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->_NET_WM_STATE_MAXIMIZED_VERT = XInternAtom(xfc->display,
|
2016-10-04 10:00:00 +03:00
|
|
|
"_NET_WM_STATE_MAXIMIZED_VERT", False);
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->_NET_WM_FULLSCREEN_MONITORS = XInternAtom(xfc->display,
|
2016-10-04 10:00:00 +03:00
|
|
|
"_NET_WM_FULLSCREEN_MONITORS", False);
|
2015-10-15 22:59:53 +03:00
|
|
|
xfc->_NET_WM_NAME = XInternAtom(xfc->display, "_NET_WM_NAME", False);
|
|
|
|
xfc->_NET_WM_PID = XInternAtom(xfc->display, "_NET_WM_PID", False);
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->_NET_WM_WINDOW_TYPE = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE",
|
2016-10-04 10:00:00 +03:00
|
|
|
False);
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->_NET_WM_WINDOW_TYPE_NORMAL = XInternAtom(xfc->display,
|
2016-10-04 10:00:00 +03:00
|
|
|
"_NET_WM_WINDOW_TYPE_NORMAL", False);
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->_NET_WM_WINDOW_TYPE_DIALOG = XInternAtom(xfc->display,
|
2016-10-04 10:00:00 +03:00
|
|
|
"_NET_WM_WINDOW_TYPE_DIALOG", False);
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->_NET_WM_WINDOW_TYPE_POPUP = XInternAtom(xfc->display,
|
2016-10-04 10:00:00 +03:00
|
|
|
"_NET_WM_WINDOW_TYPE_POPUP", False);
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->_NET_WM_WINDOW_TYPE_UTILITY = XInternAtom(xfc->display,
|
2016-10-04 10:00:00 +03:00
|
|
|
"_NET_WM_WINDOW_TYPE_UTILITY", False);
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->_NET_WM_WINDOW_TYPE_DROPDOWN_MENU = XInternAtom(xfc->display,
|
2016-10-04 10:00:00 +03:00
|
|
|
"_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", False);
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->_NET_WM_STATE_SKIP_TASKBAR = XInternAtom(xfc->display,
|
2016-10-04 10:00:00 +03:00
|
|
|
"_NET_WM_STATE_SKIP_TASKBAR", False);
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->_NET_WM_STATE_SKIP_PAGER = XInternAtom(xfc->display,
|
2016-10-04 10:00:00 +03:00
|
|
|
"_NET_WM_STATE_SKIP_PAGER", False);
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->_NET_WM_MOVERESIZE = XInternAtom(xfc->display, "_NET_WM_MOVERESIZE",
|
2016-10-04 10:00:00 +03:00
|
|
|
False);
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->_NET_MOVERESIZE_WINDOW = XInternAtom(xfc->display,
|
2016-10-04 10:00:00 +03:00
|
|
|
"_NET_MOVERESIZE_WINDOW", False);
|
2015-10-16 02:41:55 +03:00
|
|
|
xfc->UTF8_STRING = XInternAtom(xfc->display, "UTF8_STRING", FALSE);
|
2015-02-09 19:33:55 +03:00
|
|
|
xfc->WM_PROTOCOLS = XInternAtom(xfc->display, "WM_PROTOCOLS", False);
|
|
|
|
xfc->WM_DELETE_WINDOW = XInternAtom(xfc->display, "WM_DELETE_WINDOW", False);
|
|
|
|
xfc->WM_STATE = XInternAtom(xfc->display, "WM_STATE", False);
|
|
|
|
xfc->xfds = ConnectionNumber(xfc->display);
|
|
|
|
xfc->screen_number = DefaultScreen(xfc->display);
|
|
|
|
xfc->screen = ScreenOfDisplay(xfc->display, xfc->screen_number);
|
|
|
|
xfc->depth = DefaultDepthOfScreen(xfc->screen);
|
|
|
|
xfc->big_endian = (ImageByteOrder(xfc->display) == MSBFirst);
|
2016-08-03 15:16:20 +03:00
|
|
|
xfc->invert = (ImageByteOrder(xfc->display) == MSBFirst) ? FALSE : TRUE;
|
2015-02-09 19:33:55 +03:00
|
|
|
xfc->complex_regions = TRUE;
|
2016-04-05 18:07:45 +03:00
|
|
|
xfc->x11event = CreateFileDescriptorEvent(NULL, FALSE, FALSE, xfc->xfds,
|
2016-10-04 10:00:00 +03:00
|
|
|
WINPR_FD_READ);
|
2015-02-09 19:33:55 +03:00
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!xfc->x11event)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Could not create xfds event");
|
|
|
|
goto fail_xfds_event;
|
|
|
|
}
|
|
|
|
|
2015-02-09 19:33:55 +03:00
|
|
|
xfc->colormap = DefaultColormap(xfc->display, xfc->screen_number);
|
|
|
|
|
|
|
|
if (xfc->debug)
|
|
|
|
{
|
|
|
|
WLog_INFO(TAG, "Enabling X11 debug mode.");
|
|
|
|
XSynchronize(xfc->display, TRUE);
|
|
|
|
_def_error_handler = XSetErrorHandler(_xf_error_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
xf_check_extensions(xfc);
|
|
|
|
|
|
|
|
if (!xf_get_pixmap_info(xfc))
|
2015-04-28 18:00:41 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to get pixmap info");
|
|
|
|
goto fail_pixmap_info;
|
|
|
|
}
|
2015-02-10 23:15:30 +03:00
|
|
|
|
|
|
|
xfc->vscreen.monitors = calloc(16, sizeof(MONITOR_INFO));
|
|
|
|
|
|
|
|
if (!xfc->vscreen.monitors)
|
2015-04-28 18:00:41 +03:00
|
|
|
goto fail_vscreen_monitors;
|
2015-02-09 19:33:55 +03:00
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
return TRUE;
|
|
|
|
fail_vscreen_monitors:
|
|
|
|
fail_pixmap_info:
|
|
|
|
CloseHandle(xfc->x11event);
|
|
|
|
xfc->x11event = NULL;
|
|
|
|
fail_xfds_event:
|
|
|
|
CloseHandle(xfc->mutex);
|
|
|
|
xfc->mutex = NULL;
|
|
|
|
fail_create_mutex:
|
|
|
|
XCloseDisplay(xfc->display);
|
|
|
|
xfc->display = NULL;
|
|
|
|
fail_open_display:
|
|
|
|
return FALSE;
|
2013-04-02 23:13:10 +04:00
|
|
|
}
|
|
|
|
|
2014-09-12 06:29:09 +04:00
|
|
|
static void xfreerdp_client_free(freerdp* instance, rdpContext* context)
|
2013-04-02 23:13:10 +04:00
|
|
|
{
|
2015-02-09 19:33:55 +03:00
|
|
|
xfContext* xfc = (xfContext*) instance->context;
|
2014-09-12 06:29:09 +04:00
|
|
|
|
2015-02-06 01:01:56 +03:00
|
|
|
if (!context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (xfc->display)
|
|
|
|
{
|
|
|
|
XCloseDisplay(xfc->display);
|
|
|
|
xfc->display = NULL;
|
|
|
|
}
|
2014-09-12 06:29:09 +04:00
|
|
|
|
2015-02-06 01:01:56 +03:00
|
|
|
if (xfc->x11event)
|
|
|
|
{
|
|
|
|
CloseHandle(xfc->x11event);
|
|
|
|
xfc->x11event = NULL;
|
|
|
|
}
|
2014-12-03 19:48:27 +03:00
|
|
|
|
2015-02-06 01:01:56 +03:00
|
|
|
if (xfc->mutex)
|
|
|
|
{
|
|
|
|
CloseHandle(xfc->mutex);
|
|
|
|
xfc->mutex = NULL;
|
2013-04-02 23:45:48 +04:00
|
|
|
}
|
2015-02-10 23:15:30 +03:00
|
|
|
|
|
|
|
if (xfc->vscreen.monitors)
|
|
|
|
{
|
|
|
|
free(xfc->vscreen.monitors);
|
|
|
|
xfc->vscreen.monitors = NULL;
|
|
|
|
}
|
2013-04-02 23:13:10 +04:00
|
|
|
}
|
|
|
|
|
2014-09-12 06:29:09 +04:00
|
|
|
int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
|
2013-06-14 04:25:50 +04:00
|
|
|
{
|
|
|
|
pEntryPoints->Version = 1;
|
|
|
|
pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
|
2013-06-14 06:11:23 +04:00
|
|
|
pEntryPoints->GlobalInit = xfreerdp_client_global_init;
|
|
|
|
pEntryPoints->GlobalUninit = xfreerdp_client_global_uninit;
|
2013-06-14 05:34:46 +04:00
|
|
|
pEntryPoints->ContextSize = sizeof(xfContext);
|
2013-06-14 06:11:23 +04:00
|
|
|
pEntryPoints->ClientNew = xfreerdp_client_new;
|
|
|
|
pEntryPoints->ClientFree = xfreerdp_client_free;
|
|
|
|
pEntryPoints->ClientStart = xfreerdp_client_start;
|
|
|
|
pEntryPoints->ClientStop = xfreerdp_client_stop;
|
2013-06-14 04:25:50 +04:00
|
|
|
return 0;
|
2013-04-02 23:13:10 +04:00
|
|
|
}
|