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>
|
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>
|
|
|
|
#endif
|
|
|
|
|
2013-04-26 02:30:39 +04:00
|
|
|
#ifdef WITH_XI
|
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
|
|
|
|
|
|
|
|
#ifdef WITH_XRENDER
|
|
|
|
#include <X11/extensions/Xrender.h>
|
|
|
|
#endif
|
|
|
|
|
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/event.h>
|
|
|
|
#include <freerdp/utils/signal.h>
|
|
|
|
#include <freerdp/utils/passphrase.h>
|
|
|
|
#include <freerdp/client/cliprdr.h>
|
|
|
|
#include <freerdp/client/channels.h>
|
|
|
|
|
|
|
|
#include <freerdp/rail.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>
|
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"
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
static long xv_port = 0;
|
|
|
|
static const size_t password_size = 512;
|
|
|
|
|
2013-06-26 04:41:32 +04:00
|
|
|
void xf_transform_window(xfContext* xfc)
|
2013-05-15 00:18:57 +04:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
long supplied;
|
|
|
|
Atom hints_atom;
|
|
|
|
XSizeHints* size_hints = NULL;
|
|
|
|
|
2013-06-26 04:41:32 +04:00
|
|
|
hints_atom = XInternAtom(xfc->display, "WM_SIZE_HINTS", 1);
|
2013-05-15 00:18:57 +04:00
|
|
|
|
2013-06-26 04:41:32 +04:00
|
|
|
ret = XGetWMSizeHints(xfc->display, xfc->window->handle, size_hints, &supplied, hints_atom);
|
2013-05-15 00:18:57 +04:00
|
|
|
|
|
|
|
if(ret == 0)
|
|
|
|
size_hints = XAllocSizeHints();
|
|
|
|
|
2013-06-27 22:24:46 +04:00
|
|
|
w = (xfc->originalWidth * xfc->settings->ScalingFactor) + xfc->offset_x;
|
|
|
|
h = (xfc->originalHeight * xfc->settings->ScalingFactor) + xfc->offset_y;
|
2013-05-15 00:18:57 +04:00
|
|
|
|
2013-06-04 01:53:06 +04:00
|
|
|
if(w < 1)
|
|
|
|
w = 1;
|
|
|
|
|
|
|
|
if(h < 1)
|
|
|
|
h = 1;
|
|
|
|
|
2013-05-15 00:18:57 +04:00
|
|
|
if (size_hints)
|
|
|
|
{
|
|
|
|
size_hints->flags |= PMinSize | PMaxSize;
|
|
|
|
size_hints->min_width = size_hints->max_width = w;
|
|
|
|
size_hints->min_height = size_hints->max_height = h;
|
2013-06-26 04:41:32 +04:00
|
|
|
XSetWMNormalHints(xfc->display, xfc->window->handle, size_hints);
|
|
|
|
XResizeWindow(xfc->display, xfc->window->handle, w, h);
|
2013-05-15 00:18:57 +04:00
|
|
|
|
|
|
|
XFree(size_hints);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-26 04:41:32 +04:00
|
|
|
void xf_draw_screen_scaled(xfContext* xfc, int x, int y, int w, int h, BOOL scale)
|
2013-05-05 05:23:24 +04:00
|
|
|
{
|
2013-05-25 02:38:02 +04:00
|
|
|
#ifdef WITH_XRENDER
|
2013-05-09 05:51:16 +04:00
|
|
|
XTransform transform;
|
|
|
|
Picture windowPicture;
|
|
|
|
Picture primaryPicture;
|
2013-05-05 05:23:24 +04:00
|
|
|
XRenderPictureAttributes pa;
|
|
|
|
XRenderPictFormat* picFormat;
|
2013-05-16 23:15:19 +04:00
|
|
|
XRectangle xr;
|
2013-05-09 05:51:16 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
picFormat = XRenderFindStandardFormat(xfc->display, PictStandardRGB24);
|
2013-05-09 05:51:16 +04:00
|
|
|
pa.subwindow_mode = IncludeInferiors;
|
2013-06-13 02:57:25 +04:00
|
|
|
primaryPicture = XRenderCreatePicture(xfc->display, xfc->primary, picFormat, CPSubwindowMode, &pa);
|
|
|
|
windowPicture = XRenderCreatePicture(xfc->display, xfc->window->handle, picFormat, CPSubwindowMode, &pa);
|
2013-05-05 05:23:24 +04:00
|
|
|
|
|
|
|
transform.matrix[0][0] = XDoubleToFixed(1);
|
|
|
|
transform.matrix[0][1] = XDoubleToFixed(0);
|
|
|
|
transform.matrix[0][2] = XDoubleToFixed(0);
|
2013-05-09 05:51:16 +04:00
|
|
|
|
2013-05-05 05:23:24 +04:00
|
|
|
transform.matrix[1][0] = XDoubleToFixed(0);
|
|
|
|
transform.matrix[1][1] = XDoubleToFixed(1);
|
|
|
|
transform.matrix[1][2] = XDoubleToFixed(0);
|
2013-05-09 05:51:16 +04:00
|
|
|
|
2013-05-05 05:23:24 +04:00
|
|
|
transform.matrix[2][0] = XDoubleToFixed(0);
|
|
|
|
transform.matrix[2][1] = XDoubleToFixed(0);
|
2013-06-27 22:24:46 +04:00
|
|
|
transform.matrix[2][2] = XDoubleToFixed(xfc->settings->ScalingFactor);
|
2013-05-09 05:51:16 +04:00
|
|
|
|
2013-05-16 23:15:19 +04:00
|
|
|
if( (w != 0) && (h != 0) )
|
|
|
|
{
|
2013-05-17 00:20:25 +04:00
|
|
|
|
|
|
|
if(scale == TRUE)
|
|
|
|
{
|
2013-06-27 22:24:46 +04:00
|
|
|
xr.x = x * xfc->settings->ScalingFactor;
|
|
|
|
xr.y = y * xfc->settings->ScalingFactor;
|
|
|
|
xr.width = (w+1) * xfc->settings->ScalingFactor;
|
|
|
|
xr.height = (h+1) * xfc->settings->ScalingFactor;
|
2013-05-17 00:20:25 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xr.x = x;
|
|
|
|
xr.y = y;
|
|
|
|
xr.width = w;
|
|
|
|
xr.height = h;
|
|
|
|
}
|
2013-05-16 23:15:19 +04:00
|
|
|
|
2013-06-26 04:41:32 +04:00
|
|
|
XRenderSetPictureClipRectangles(xfc->display, primaryPicture, 0, 0, &xr, 1);
|
2013-05-16 23:15:19 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XRenderSetPictureTransform(xfc->display, primaryPicture, &transform);
|
2013-06-05 22:59:24 +04:00
|
|
|
|
2013-06-26 04:41:32 +04:00
|
|
|
XRenderComposite(xfc->display, PictOpSrc, primaryPicture, 0, windowPicture, 0, 0, 0, 0, xfc->offset_x, xfc->offset_y, xfc->currentWidth, xfc->currentHeight);
|
2013-05-14 02:29:55 +04:00
|
|
|
|
2013-06-26 04:41:32 +04:00
|
|
|
XRenderFreePicture(xfc->display, primaryPicture);
|
|
|
|
XRenderFreePicture(xfc->display, windowPicture);
|
2013-05-16 23:15:19 +04:00
|
|
|
|
2013-05-25 02:38:02 +04:00
|
|
|
#endif
|
2013-06-05 22:59:24 +04:00
|
|
|
|
2013-05-05 05:23:24 +04:00
|
|
|
}
|
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
void xf_sw_begin_paint(rdpContext* context)
|
|
|
|
{
|
|
|
|
rdpGdi* gdi = context->gdi;
|
|
|
|
gdi->primary->hdc->hwnd->invalid->null = 1;
|
|
|
|
gdi->primary->hdc->hwnd->ninvalid = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void xf_sw_end_paint(rdpContext* context)
|
|
|
|
{
|
|
|
|
rdpGdi* gdi;
|
|
|
|
INT32 x, y;
|
|
|
|
UINT32 w, h;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
gdi = context->gdi;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (!xfc->remote_app)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
if (!xfc->complex_regions)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
if (gdi->primary->hdc->hwnd->invalid->null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XPutImage(xfc->display, xfc->primary, xfc->gc, xfc->image, x, y, x, y, w, h);
|
2013-05-09 05:51:16 +04:00
|
|
|
|
2013-06-27 22:24:46 +04:00
|
|
|
if ( (xfc->settings->ScalingFactor != 1.0) || (xfc->offset_x) || (xfc->offset_y) )
|
2013-05-09 05:51:16 +04:00
|
|
|
{
|
2013-06-26 04:41:32 +04:00
|
|
|
xf_draw_screen_scaled(xfc, x, y, w, h, TRUE);
|
2013-05-09 05:51:16 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
XCopyArea(xfc->display, xfc->primary, xfc->window->handle, xfc->gc, x, y, w, h, x, y);
|
2013-05-09 05:51:16 +04:00
|
|
|
}
|
2013-04-02 21:22:59 +04:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (gdi->primary->hdc->hwnd->ninvalid < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ninvalid = gdi->primary->hdc->hwnd->ninvalid;
|
|
|
|
cinvalid = gdi->primary->hdc->hwnd->cinvalid;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
for (i = 0; i < ninvalid; i++)
|
|
|
|
{
|
|
|
|
x = cinvalid[i].x;
|
|
|
|
y = cinvalid[i].y;
|
|
|
|
w = cinvalid[i].w;
|
|
|
|
h = cinvalid[i].h;
|
2013-04-22 06:49:24 +04:00
|
|
|
|
2013-06-26 04:41:32 +04:00
|
|
|
//combine xfc->primary with xfc->image
|
2013-06-13 02:57:25 +04:00
|
|
|
XPutImage(xfc->display, xfc->primary, xfc->gc, xfc->image, x, y, x, y, w, h);
|
2013-05-03 04:31:22 +04:00
|
|
|
|
2013-06-27 22:24:46 +04:00
|
|
|
if ( (xfc->settings->ScalingFactor != 1.0) || (xfc->offset_x) || (xfc->offset_y) )
|
2013-05-03 04:31:22 +04:00
|
|
|
{
|
2013-06-26 04:41:32 +04:00
|
|
|
xf_draw_screen_scaled(xfc, x, y, w, h, TRUE);
|
2013-05-05 05:23:24 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
XCopyArea(xfc->display, xfc->primary, xfc->window->handle, xfc->gc, x, y, w, h, x, y);
|
2013-05-03 04:31:22 +04:00
|
|
|
}
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XFlush(xfc->display);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gdi->primary->hdc->hwnd->invalid->null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_rail_paint(xfc, context->rail, x, y, x + w - 1, y + h - 1);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void xf_sw_desktop_resize(rdpContext* context)
|
|
|
|
{
|
|
|
|
rdpSettings* settings;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
settings = xfc->instance->settings;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, TRUE);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (!xfc->fullscreen)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
rdpGdi* gdi = context->gdi;
|
2013-06-13 02:57:25 +04:00
|
|
|
gdi_resize(gdi, xfc->width, xfc->height);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->image)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->image->data = NULL;
|
|
|
|
XDestroyImage(xfc->image);
|
|
|
|
xfc->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0,
|
|
|
|
(char*) gdi->primary_buffer, gdi->width, gdi->height, xfc->scanline_pad, 0);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, TRUE);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void xf_hw_begin_paint(rdpContext* context)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->hdc->hwnd->invalid->null = 1;
|
|
|
|
xfc->hdc->hwnd->ninvalid = 0;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void xf_hw_end_paint(rdpContext* context)
|
|
|
|
{
|
|
|
|
INT32 x, y;
|
|
|
|
UINT32 w, h;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (!xfc->remote_app)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
if (!xfc->complex_regions)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->hdc->hwnd->invalid->null)
|
2013-04-02 21:22:59 +04:00
|
|
|
return;
|
|
|
|
|
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;
|
2013-04-22 06:49:24 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-27 22:24:46 +04:00
|
|
|
if ( (xfc->settings->ScalingFactor != 1.0) || (xfc->offset_x) || (xfc->offset_y) )
|
2013-05-05 05:48:50 +04:00
|
|
|
{
|
2013-06-26 04:41:32 +04:00
|
|
|
xf_draw_screen_scaled(xfc, x, y, w, h, TRUE);
|
2013-05-05 05:48:50 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
XCopyArea(xfc->display, xfc->primary, xfc->drawable, xfc->gc, x, y, w, h, x, y);
|
2013-05-05 05:48:50 +04:00
|
|
|
}
|
2013-04-30 04:21:59 +04:00
|
|
|
|
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;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->hdc->hwnd->ninvalid < 1)
|
2013-04-02 21:22:59 +04:00
|
|
|
return;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
ninvalid = xfc->hdc->hwnd->ninvalid;
|
|
|
|
cinvalid = xfc->hdc->hwnd->cinvalid;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
for (i = 0; i < ninvalid; i++)
|
|
|
|
{
|
|
|
|
x = cinvalid[i].x;
|
|
|
|
y = cinvalid[i].y;
|
|
|
|
w = cinvalid[i].w;
|
|
|
|
h = cinvalid[i].h;
|
2013-04-22 06:49:24 +04:00
|
|
|
|
2013-06-27 22:24:46 +04:00
|
|
|
if ( (xfc->settings->ScalingFactor != 1.0) || (xfc->offset_x) || (xfc->offset_y) )
|
2013-05-05 05:59:31 +04:00
|
|
|
{
|
2013-06-26 04:41:32 +04:00
|
|
|
xf_draw_screen_scaled(xfc, x, y, w, h, TRUE);
|
2013-05-09 05:51:16 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
XCopyArea(xfc->display, xfc->primary, xfc->drawable, xfc->gc, x, y, w, h, x, y);
|
2013-05-09 05:51:16 +04:00
|
|
|
}
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XFlush(xfc->display);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->hdc->hwnd->invalid->null)
|
2013-04-02 21:22:59 +04:00
|
|
|
return;
|
|
|
|
|
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;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_rail_paint(xfc, context->rail, x, y, x + w - 1, y + h - 1);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void xf_hw_desktop_resize(rdpContext* context)
|
|
|
|
{
|
|
|
|
BOOL same;
|
|
|
|
rdpSettings* settings;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
settings = xfc->instance->settings;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, TRUE);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (!xfc->fullscreen)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->width = settings->DesktopWidth;
|
|
|
|
xfc->height = settings->DesktopHeight;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->window)
|
|
|
|
xf_ResizeDesktopWindow(xfc, xfc->window, settings->DesktopWidth, settings->DesktopHeight);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->primary)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
same = (xfc->primary == xfc->drawing) ? TRUE : FALSE;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XFreePixmap(xfc->display, xfc->primary);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->primary = XCreatePixmap(xfc->display, xfc->drawable,
|
|
|
|
xfc->width, xfc->height, xfc->depth);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
if (same)
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->drawing = xfc->primary;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
XSetFunction(xfc->display, xfc->gc, GXcopy);
|
|
|
|
XSetFillStyle(xfc->display, xfc->gc, FillSolid);
|
|
|
|
XSetForeground(xfc->display, xfc->gc, 0);
|
|
|
|
XFillRectangle(xfc->display, xfc->drawable, xfc->gc, 0, 0, xfc->width, xfc->height);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, TRUE);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL xf_get_fds(freerdp* instance, void** rfds, int* rcount, void** wfds, int* wcount)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) instance->context;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
rfds[*rcount] = (void*)(long)(xfc->xfds);
|
2013-04-02 21:22:59 +04:00
|
|
|
(*rcount)++;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL xf_process_x_events(freerdp* instance)
|
|
|
|
{
|
|
|
|
BOOL status;
|
|
|
|
XEvent xevent;
|
|
|
|
int pending_status;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) instance->context;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
status = TRUE;
|
|
|
|
pending_status = TRUE;
|
|
|
|
|
|
|
|
while (pending_status)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
pending_status = XPending(xfc->display);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
if (pending_status)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
void xf_create_window(xfContext* xfc)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
XEvent xevent;
|
|
|
|
int width, height;
|
2013-04-09 01:03:21 +04:00
|
|
|
char* windowTitle;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
ZeroMemory(&xevent, sizeof(xevent));
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
width = xfc->width;
|
|
|
|
height = xfc->height;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04: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;
|
|
|
|
xfc->attribs.override_redirect = xfc->grab_keyboard ? xfc->fullscreen : False;
|
|
|
|
xfc->attribs.colormap = xfc->colormap;
|
|
|
|
xfc->attribs.bit_gravity = NorthWestGravity;
|
|
|
|
xfc->attribs.win_gravity = NorthWestGravity;
|
|
|
|
|
|
|
|
if (xfc->instance->settings->WindowTitle)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
windowTitle = _strdup(xfc->instance->settings->WindowTitle);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2013-06-13 02:57:25 +04:00
|
|
|
else if (xfc->instance->settings->ServerPort == 3389)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
windowTitle = malloc(1 + sizeof("FreeRDP: ") + strlen(xfc->instance->settings->ServerHostname));
|
|
|
|
sprintf(windowTitle, "FreeRDP: %s", xfc->instance->settings->ServerHostname);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
windowTitle = malloc(1 + sizeof("FreeRDP: ") + strlen(xfc->instance->settings->ServerHostname) + sizeof(":00000"));
|
|
|
|
sprintf(windowTitle, "FreeRDP: %s:%i", xfc->instance->settings->ServerHostname, xfc->instance->settings->ServerPort);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->window = xf_CreateDesktopWindow(xfc, windowTitle, width, height, xfc->settings->Decorations);
|
2013-04-09 01:03:21 +04:00
|
|
|
free(windowTitle);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->fullscreen)
|
|
|
|
xf_SetWindowFullscreen(xfc, xfc->window, xfc->fullscreen);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->unobscured = (xevent.xvisibility.state == VisibilityUnobscured);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
void xf_toggle_fullscreen(xfContext* xfc)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
Pixmap contents = 0;
|
2013-06-16 01:01:10 +04:00
|
|
|
WindowStateChangeEventArgs e;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, TRUE);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
contents = XCreatePixmap(xfc->display, xfc->window->handle, xfc->width, xfc->height, xfc->depth);
|
|
|
|
XCopyArea(xfc->display, xfc->primary, contents, xfc->gc, 0, 0, xfc->width, xfc->height, 0, 0);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XDestroyWindow(xfc->display, xfc->window->handle);
|
|
|
|
xfc->fullscreen = (xfc->fullscreen) ? FALSE : TRUE;
|
|
|
|
xf_create_window(xfc);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XCopyArea(xfc->display, contents, xfc->primary, xfc->gc, 0, 0, xfc->width, xfc->height, 0, 0);
|
|
|
|
XFreePixmap(xfc->display, contents);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, TRUE);
|
2013-04-28 09:11:29 +04:00
|
|
|
|
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;
|
2013-06-18 08:39:48 +04:00
|
|
|
PubSub_OnWindowStateChange(((rdpContext*) xfc)->pubSub, xfc, &e);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
void xf_lock_x11(xfContext* xfc, BOOL display)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04: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
|
|
|
|
{
|
|
|
|
if (display)
|
2013-06-13 02:57:25 +04:00
|
|
|
XLockDisplay(xfc->display);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
void xf_unlock_x11(xfContext* xfc, BOOL display)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04: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
|
|
|
|
{
|
|
|
|
if (display)
|
2013-06-13 02:57:25 +04:00
|
|
|
XUnlockDisplay(xfc->display);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
BOOL xf_get_pixmap_info(xfContext* xfc)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int vi_count;
|
|
|
|
int pf_count;
|
|
|
|
XVisualInfo* vi;
|
|
|
|
XVisualInfo* vis;
|
|
|
|
XVisualInfo template;
|
|
|
|
XPixmapFormatValues* pf;
|
|
|
|
XPixmapFormatValues* pfs;
|
|
|
|
XWindowAttributes window_attributes;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
pfs = XListPixmapFormats(xfc->display, &pf_count);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
if (pfs == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "xf_get_pixmap_info: XListPixmapFormats failed\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pf_count; i++)
|
|
|
|
{
|
|
|
|
pf = pfs + i;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (pf->depth == xfc->depth)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->bpp = pf->bits_per_pixel;
|
|
|
|
xfc->scanline_pad = pf->scanline_pad;
|
2013-04-02 21:22:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XFree(pfs);
|
|
|
|
|
|
|
|
ZeroMemory(&template, sizeof(template));
|
|
|
|
template.class = TrueColor;
|
2013-06-13 02:57:25 +04:00
|
|
|
template.screen = xfc->screen_number;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (XGetWindowAttributes(xfc->display, RootWindowOfScreen(xfc->screen), &window_attributes) == 0)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
fprintf(stderr, "xf_get_pixmap_info: XGetWindowAttributes failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
vis = XGetVisualInfo(xfc->display, VisualClassMask | VisualScreenMask, &template, &vi_count);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
if (vis == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "xf_get_pixmap_info: XGetVisualInfo failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
vi = NULL;
|
|
|
|
for (i = 0; i < vi_count; i++)
|
|
|
|
{
|
|
|
|
vi = vis + i;
|
|
|
|
|
|
|
|
if (vi->visual == window_attributes.visual)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->visual = vi->visual;
|
2013-04-02 21:22:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vi)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Detect if the server visual has an inverted colormap
|
|
|
|
* (BGR vs RGB, or red being the least significant byte)
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (vi->red_mask & 0xFF)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->clrconv->invert = TRUE;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(vis);
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if ((xfc->visual == NULL) || (xfc->scanline_pad == 0))
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int (*_def_error_handler)(Display*, XErrorEvent*);
|
|
|
|
|
|
|
|
int xf_error_handler(Display* d, XErrorEvent* ev)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
int do_abort = TRUE;
|
|
|
|
|
|
|
|
XGetErrorText(d, ev->error_code, buf, sizeof(buf));
|
|
|
|
fprintf(stderr, "%s", buf);
|
|
|
|
|
|
|
|
if (do_abort)
|
|
|
|
abort();
|
|
|
|
|
|
|
|
_def_error_handler(d, ev);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int _xf_error_handler(Display* d, XErrorEvent* ev)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* ungrab the keyboard, in case a debugger is running in
|
|
|
|
* another window. This make xf_error_handler() a potential
|
|
|
|
* debugger breakpoint.
|
|
|
|
*/
|
|
|
|
XUngrabKeyboard(d, CurrentTime);
|
|
|
|
return xf_error_handler(d, ev);
|
|
|
|
}
|
|
|
|
|
2013-08-19 19:44:52 +04:00
|
|
|
static void xf_post_disconnect(freerdp *instance)
|
|
|
|
{
|
|
|
|
xfContext* xfc = (xfContext*) instance->context;
|
|
|
|
|
|
|
|
assert(NULL != instance);
|
|
|
|
assert(NULL != xfc);
|
|
|
|
assert(NULL != instance->settings);
|
|
|
|
|
|
|
|
WaitForSingleObject(xfc->mutex, INFINITE);
|
|
|
|
CloseHandle(xfc->mutex);
|
|
|
|
|
|
|
|
xf_monitors_free(xfc, instance->settings);
|
|
|
|
}
|
|
|
|
|
2013-04-02 21:22:59 +04: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.
|
|
|
|
*/
|
|
|
|
BOOL xf_pre_connect(freerdp* instance)
|
|
|
|
{
|
2013-05-14 01:39:53 +04:00
|
|
|
rdpChannels* channels;
|
2013-04-02 21:22:59 +04:00
|
|
|
rdpSettings* settings;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) instance->context;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->mutex = CreateMutex(NULL, FALSE, NULL);
|
|
|
|
xfc->settings = instance->settings;
|
|
|
|
xfc->instance = instance;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
settings = instance->settings;
|
2013-05-14 01:39:53 +04:00
|
|
|
channels = instance->context->channels;
|
|
|
|
|
2013-07-11 19:53:15 +04:00
|
|
|
PubSub_SubscribeChannelConnected(instance->context->pubSub,
|
|
|
|
(pChannelConnectedEventHandler) xf_OnChannelConnectedEventHandler);
|
|
|
|
|
|
|
|
PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
|
|
|
|
(pChannelDisconnectedEventHandler) xf_OnChannelDisconnectedEventHandler);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-05-14 01:39:53 +04:00
|
|
|
freerdp_client_load_addins(channels, instance->settings);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-05-14 01:39:53 +04:00
|
|
|
freerdp_channels_pre_connect(channels, instance);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
if (settings->AuthenticationOnly)
|
|
|
|
{
|
|
|
|
/* Check --authonly has a username and password. */
|
|
|
|
if (settings->Username == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "--authonly, but no -u username. Please provide one.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (settings->Password == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "--authonly, but no -p password. Please provide one.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "%s:%d: Authentication only. Don't connect to X.\n", __FILE__, __LINE__);
|
|
|
|
/* Avoid XWindows initialization and configuration below. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->UseXThreads = TRUE;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->UseXThreads)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
if (!XInitThreads())
|
|
|
|
{
|
|
|
|
fprintf(stderr, "warning: XInitThreads() failure\n");
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->UseXThreads = FALSE;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->display = XOpenDisplay(NULL);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (!xfc->display)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
fprintf(stderr, "xf_pre_connect: failed to open display: %s\n", XDisplayName(NULL));
|
|
|
|
fprintf(stderr, "Please check that the $DISPLAY environment variable is properly set.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->debug)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Enabling X11 debug mode.\n");
|
2013-06-13 02:57:25 +04:00
|
|
|
XSynchronize(xfc->display, TRUE);
|
2013-04-02 21:22:59 +04:00
|
|
|
_def_error_handler = XSetErrorHandler(_xf_error_handler);
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->_NET_WM_ICON = XInternAtom(xfc->display, "_NET_WM_ICON", False);
|
|
|
|
xfc->_MOTIF_WM_HINTS = XInternAtom(xfc->display, "_MOTIF_WM_HINTS", False);
|
|
|
|
xfc->_NET_CURRENT_DESKTOP = XInternAtom(xfc->display, "_NET_CURRENT_DESKTOP", False);
|
|
|
|
xfc->_NET_WORKAREA = XInternAtom(xfc->display, "_NET_WORKAREA", False);
|
|
|
|
xfc->_NET_WM_STATE = XInternAtom(xfc->display, "_NET_WM_STATE", False);
|
|
|
|
xfc->_NET_WM_STATE_FULLSCREEN = XInternAtom(xfc->display, "_NET_WM_STATE_FULLSCREEN", False);
|
|
|
|
xfc->_NET_WM_WINDOW_TYPE = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE", False);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->_NET_WM_WINDOW_TYPE_NORMAL = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE_NORMAL", False);
|
|
|
|
xfc->_NET_WM_WINDOW_TYPE_DIALOG = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE_DIALOG", False);
|
|
|
|
xfc->_NET_WM_WINDOW_TYPE_POPUP = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE_POPUP", False);
|
|
|
|
xfc->_NET_WM_WINDOW_TYPE_UTILITY = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE_UTILITY", False);
|
|
|
|
xfc->_NET_WM_WINDOW_TYPE_DROPDOWN_MENU = XInternAtom(xfc->display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", False);
|
|
|
|
xfc->_NET_WM_STATE_SKIP_TASKBAR = XInternAtom(xfc->display, "_NET_WM_STATE_SKIP_TASKBAR", False);
|
|
|
|
xfc->_NET_WM_STATE_SKIP_PAGER = XInternAtom(xfc->display, "_NET_WM_STATE_SKIP_PAGER", False);
|
|
|
|
xfc->_NET_WM_MOVERESIZE = XInternAtom(xfc->display, "_NET_WM_MOVERESIZE", False);
|
|
|
|
xfc->_NET_MOVERESIZE_WINDOW = XInternAtom(xfc->display, "_NET_MOVERESIZE_WINDOW", False);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04: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);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_kbd_init(xfc);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->clrconv = freerdp_clrconv_new(CLRCONV_ALPHA);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
instance->context->cache = cache_new(instance->settings);
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
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);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->complex_regions = TRUE;
|
|
|
|
xfc->fullscreen = settings->Fullscreen;
|
|
|
|
xfc->grab_keyboard = settings->GrabKeyboard;
|
|
|
|
xfc->fullscreen_toggle = settings->ToggleFullscreen;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_detect_monitors(xfc, settings);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
BOOL xf_post_connect(freerdp* instance)
|
|
|
|
{
|
|
|
|
XGCValues gcv;
|
|
|
|
rdpCache* cache;
|
|
|
|
rdpChannels* channels;
|
|
|
|
rdpSettings* settings;
|
2013-06-16 01:01:10 +04:00
|
|
|
ResizeWindowEventArgs e;
|
2013-04-02 21:22:59 +04:00
|
|
|
RFX_CONTEXT* rfx_context = NULL;
|
|
|
|
NSC_CONTEXT* nsc_context = NULL;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) instance->context;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
cache = instance->context->cache;
|
2013-06-13 02:57:25 +04:00
|
|
|
channels = instance->context->channels;
|
2013-04-02 21:22:59 +04:00
|
|
|
settings = instance->settings;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (!xf_get_pixmap_info(xfc))
|
2013-04-02 21:22:59 +04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
xf_register_graphics(instance->context->graphics);
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->settings->SoftwareGdi)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
rdpGdi* gdi;
|
|
|
|
UINT32 flags;
|
|
|
|
|
|
|
|
flags = CLRCONV_ALPHA;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->bpp > 16)
|
2013-04-02 21:22:59 +04:00
|
|
|
flags |= CLRBUF_32BPP;
|
|
|
|
else
|
|
|
|
flags |= CLRBUF_16BPP;
|
|
|
|
|
|
|
|
gdi_init(instance, flags, NULL);
|
|
|
|
gdi = instance->context->gdi;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->primary_buffer = gdi->primary_buffer;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
rfx_context = gdi->rfx_context;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->srcBpp = instance->settings->ColorDepth;
|
2013-04-02 21:22:59 +04:00
|
|
|
xf_gdi_register_update_callbacks(instance->update);
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->hdc = gdi_CreateDC(xfc->clrconv, xfc->bpp);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
if (instance->settings->RemoteFxCodec)
|
|
|
|
{
|
|
|
|
rfx_context = (void*) rfx_context_new();
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->rfx_context = rfx_context;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (instance->settings->NSCodec)
|
|
|
|
{
|
|
|
|
nsc_context = (void*) nsc_context_new();
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->nsc_context = nsc_context;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->originalWidth = settings->DesktopWidth;
|
|
|
|
xfc->originalHeight = settings->DesktopHeight;
|
|
|
|
xfc->currentWidth = xfc->originalWidth;
|
|
|
|
xfc->currentHeight = xfc->originalWidth;
|
2013-06-27 22:24:46 +04:00
|
|
|
xfc->settings->ScalingFactor = 1.0;
|
2013-05-04 04:00:26 +04:00
|
|
|
|
2013-06-26 04:41:32 +04:00
|
|
|
xfc->offset_x = 0;
|
|
|
|
xfc->offset_y = 0;
|
2013-05-14 02:29:55 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->width = settings->DesktopWidth;
|
|
|
|
xfc->height = settings->DesktopHeight;
|
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
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_create_window(xfc);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
ZeroMemory(&gcv, sizeof(gcv));
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->modifier_map = XGetModifierMapping(xfc->display);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->gc = XCreateGC(xfc->display, xfc->drawable, GCGraphicsExposures, &gcv);
|
|
|
|
xfc->primary = XCreatePixmap(xfc->display, xfc->drawable, xfc->width, xfc->height, xfc->depth);
|
|
|
|
xfc->drawing = xfc->primary;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->bitmap_mono = XCreatePixmap(xfc->display, xfc->drawable, 8, 8, 1);
|
|
|
|
xfc->gc_mono = XCreateGC(xfc->display, xfc->bitmap_mono, GCGraphicsExposures, &gcv);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XSetFunction(xfc->display, xfc->gc, GXcopy);
|
|
|
|
XSetFillStyle(xfc->display, xfc->gc, FillSolid);
|
|
|
|
XSetForeground(xfc->display, xfc->gc, BlackPixelOfScreen(xfc->screen));
|
|
|
|
XFillRectangle(xfc->display, xfc->primary, xfc->gc, 0, 0, xfc->width, xfc->height);
|
|
|
|
XFlush(xfc->display);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0,
|
|
|
|
(char*) xfc->primary_buffer, xfc->width, xfc->height, xfc->scanline_pad, 0);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->bmp_codec_none = (BYTE*) malloc(64 * 64 * 4);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->settings->SoftwareGdi)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
instance->update->BeginPaint = xf_sw_begin_paint;
|
|
|
|
instance->update->EndPaint = xf_sw_end_paint;
|
|
|
|
instance->update->DesktopResize = xf_sw_desktop_resize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
instance->update->BeginPaint = xf_hw_begin_paint;
|
|
|
|
instance->update->EndPaint = xf_hw_end_paint;
|
|
|
|
instance->update->DesktopResize = xf_hw_desktop_resize;
|
|
|
|
}
|
|
|
|
|
|
|
|
pointer_cache_register_callbacks(instance->update);
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (!xfc->settings->SoftwareGdi)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
glyph_cache_register_callbacks(instance->update);
|
|
|
|
brush_cache_register_callbacks(instance->update);
|
|
|
|
bitmap_cache_register_callbacks(instance->update);
|
|
|
|
offscreen_cache_register_callbacks(instance->update);
|
|
|
|
palette_cache_register_callbacks(instance->update);
|
|
|
|
}
|
|
|
|
|
|
|
|
instance->context->rail = rail_new(instance->settings);
|
|
|
|
rail_register_update_callbacks(instance->context->rail, instance->update);
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_rail_register_callbacks(xfc, instance->context->rail);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
freerdp_channels_post_connect(channels, instance);
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_tsmf_init(xfc, xv_port);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_init(xfc, channels);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
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;
|
2013-06-18 08:39:48 +04:00
|
|
|
PubSub_OnResizeWindow(((rdpContext*) xfc)->pubSub, xfc, &e);
|
2013-04-06 03:08:37 +04:00
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Callback set in the rdp_freerdp structure, and used to get the user's password,
|
|
|
|
* if required to establish the connection.
|
|
|
|
* This function is actually called in credssp_ntlmssp_client_init()
|
|
|
|
* @see rdp_server_accept_nego() and rdp_check_fds()
|
|
|
|
* @param instance - pointer to the rdp_freerdp structure that contains the connection settings
|
|
|
|
* @param username - unused
|
|
|
|
* @param password - on return: pointer to a character string that will be filled by the password entered by the user.
|
|
|
|
* Note that this character string will be allocated inside the function, and needs to be deallocated by the caller
|
|
|
|
* using free(), even in case this function fails.
|
|
|
|
* @param domain - unused
|
|
|
|
* @return TRUE if a password was successfully entered. See freerdp_passphrase_read() for more details.
|
|
|
|
*/
|
|
|
|
BOOL xf_authenticate(freerdp* instance, char** username, char** password, char** domain)
|
|
|
|
{
|
|
|
|
// FIXME: seems this callback may be called when 'username' is not known.
|
|
|
|
// But it doesn't do anything to fix it...
|
|
|
|
*password = malloc(password_size * sizeof(char));
|
|
|
|
|
|
|
|
if (freerdp_passphrase_read("Password: ", *password, password_size, instance->settings->CredentialsFromStdin) == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Callback set in the rdp_freerdp structure, and used to make a certificate validation
|
|
|
|
* when the connection requires it.
|
|
|
|
* This function will actually be called by tls_verify_certificate().
|
|
|
|
* @see rdp_client_connect() and tls_connect()
|
|
|
|
* @param instance - pointer to the rdp_freerdp structure that contains the connection settings
|
|
|
|
* @param subject
|
|
|
|
* @param issuer
|
|
|
|
* @param fingerprint
|
|
|
|
* @return TRUE if the certificate is trusted. FALSE otherwise.
|
|
|
|
*/
|
|
|
|
BOOL xf_verify_certificate(freerdp* instance, char* subject, char* issuer, char* fingerprint)
|
|
|
|
{
|
|
|
|
char answer;
|
|
|
|
|
|
|
|
printf("Certificate details:\n");
|
|
|
|
printf("\tSubject: %s\n", subject);
|
|
|
|
printf("\tIssuer: %s\n", issuer);
|
|
|
|
printf("\tThumbprint: %s\n", fingerprint);
|
|
|
|
printf("The above X.509 certificate could not be verified, possibly because you do not have "
|
|
|
|
"the CA certificate in your certificate store, or the certificate has expired. "
|
|
|
|
"Please look at the documentation on how to create local certificate store for a private CA.\n");
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
printf("Do you trust the above certificate? (Y/N) ");
|
|
|
|
answer = fgetc(stdin);
|
|
|
|
|
|
|
|
if (feof(stdin))
|
|
|
|
{
|
|
|
|
printf("\nError: Could not read answer from stdin.");
|
|
|
|
if (instance->settings->CredentialsFromStdin)
|
|
|
|
printf(" - Run without parameter \"--from-stdin\" to set trust.");
|
|
|
|
printf("\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (answer == 'y' || answer == 'Y')
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (answer == 'n' || answer == 'N')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xf_logon_error_info(freerdp* instance, UINT32 data, UINT32 type)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc = (xfContext*) instance->context;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_rail_disable_remoteapp_mode(xfc);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xf_receive_channel_data(freerdp* instance, int channelId, BYTE* data, int size, int flags, int total_size)
|
|
|
|
{
|
|
|
|
return freerdp_channels_data(instance, channelId, data, size, flags, total_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void xf_process_channel_event(rdpChannels* channels, freerdp* instance)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc;
|
2013-04-02 21:22:59 +04:00
|
|
|
wMessage* event;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc = (xfContext*) instance->context;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
event = freerdp_channels_pop_event(channels);
|
|
|
|
|
|
|
|
if (event)
|
|
|
|
{
|
|
|
|
switch (GetMessageClass(event->id))
|
|
|
|
{
|
|
|
|
case RailChannel_Class:
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_process_rail_event(xfc, channels, event);
|
2013-04-02 21:22:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TsmfChannel_Class:
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_process_tsmf_event(xfc, event);
|
2013-04-02 21:22:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CliprdrChannel_Class:
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_process_cliprdr_event(xfc, event);
|
2013-04-02 21:22:59 +04:00
|
|
|
break;
|
|
|
|
|
2013-05-09 08:52:37 +04:00
|
|
|
case RdpeiChannel_Class:
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_process_rdpei_event(xfc, event);
|
2013-05-09 08:52:37 +04:00
|
|
|
break;
|
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
freerdp_event_free(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
void xf_window_free(xfContext* xfc)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-14 05:34:46 +04:00
|
|
|
rdpContext* context = (rdpContext*) xfc;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-14 05:34:46 +04:00
|
|
|
if (xfc->modifier_map)
|
|
|
|
{
|
|
|
|
XFreeModifiermap(xfc->modifier_map);
|
2013-06-14 06:11:23 +04:00
|
|
|
xfc->modifier_map = NULL;
|
2013-06-14 05:34:46 +04:00
|
|
|
}
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->gc)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
XFreeGC(xfc->display, xfc->gc);
|
|
|
|
xfc->gc = 0;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->gc_mono)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
XFreeGC(xfc->display, xfc->gc_mono);
|
|
|
|
xfc->gc_mono = 0;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->window)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_DestroyWindow(xfc, xfc->window);
|
|
|
|
xfc->window = NULL;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->primary)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
XFreePixmap(xfc->display, xfc->primary);
|
|
|
|
xfc->primary = 0;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->bitmap_mono)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
XFreePixmap(xfc->display, xfc->bitmap_mono);
|
|
|
|
xfc->bitmap_mono = 0;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->image)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->image->data = NULL;
|
|
|
|
XDestroyImage(xfc->image);
|
|
|
|
xfc->image = NULL;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2013-06-14 05:34:46 +04:00
|
|
|
if (context->cache)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
cache_free(context->cache);
|
|
|
|
context->cache = NULL;
|
2013-06-14 05:34:46 +04:00
|
|
|
}
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-14 05:34:46 +04:00
|
|
|
if (context->rail)
|
|
|
|
{
|
2013-04-02 21:22:59 +04:00
|
|
|
rail_free(context->rail);
|
|
|
|
context->rail = NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->rfx_context)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
rfx_context_free(xfc->rfx_context);
|
|
|
|
xfc->rfx_context = NULL;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->nsc_context)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
nsc_context_free(xfc->nsc_context);
|
|
|
|
xfc->nsc_context = NULL;
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
2013-06-14 05:34:46 +04:00
|
|
|
if (xfc->clrconv)
|
|
|
|
{
|
|
|
|
freerdp_clrconv_free(xfc->clrconv);
|
|
|
|
xfc->clrconv = NULL;
|
|
|
|
}
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xfc->hdc)
|
|
|
|
gdi_DeleteDC(xfc->hdc);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-14 05:34:46 +04:00
|
|
|
if (xfc->xv_context)
|
|
|
|
{
|
|
|
|
xf_tsmf_uninit(xfc);
|
|
|
|
xfc->xv_context = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xfc->clipboard_context)
|
|
|
|
{
|
|
|
|
xf_cliprdr_uninit(xfc);
|
|
|
|
xfc->clipboard_context = NULL;
|
|
|
|
}
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void* xf_update_thread(void* arg)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
wMessage message;
|
|
|
|
wMessageQueue* queue;
|
|
|
|
freerdp* instance = (freerdp*) arg;
|
|
|
|
|
|
|
|
status = 1;
|
|
|
|
queue = freerdp_get_message_queue(instance, FREERDP_UPDATE_MESSAGE_QUEUE);
|
|
|
|
|
|
|
|
while (MessageQueue_Wait(queue))
|
|
|
|
{
|
|
|
|
while (MessageQueue_Peek(queue, &message, TRUE))
|
|
|
|
{
|
|
|
|
status = freerdp_message_queue_process_message(instance, FREERDP_UPDATE_MESSAGE_QUEUE, &message);
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* xf_input_thread(void* arg)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc;
|
2013-04-02 21:22:59 +04:00
|
|
|
HANDLE event;
|
|
|
|
XEvent xevent;
|
|
|
|
wMessageQueue* queue;
|
|
|
|
int pending_status = 1;
|
|
|
|
int process_status = 1;
|
|
|
|
freerdp* instance = (freerdp*) arg;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc = (xfContext*) instance->context;
|
2013-04-25 22:46:12 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
event = CreateFileDescriptorEvent(NULL, FALSE, FALSE, xfc->xfds);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
while (WaitForSingleObject(event, INFINITE) == WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
pending_status = XPending(xfc->display);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
if (pending_status)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_lock_x11(xfc, FALSE);
|
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
|
|
|
process_status = xf_event_process(instance, &xevent);
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_unlock_x11(xfc, FALSE);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
if (!process_status)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (pending_status);
|
|
|
|
|
|
|
|
if (!process_status)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
queue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE);
|
|
|
|
MessageQueue_PostQuit(queue, 0);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* xf_channels_thread(void* arg)
|
|
|
|
{
|
|
|
|
int status;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc;
|
2013-04-02 21:22:59 +04:00
|
|
|
HANDLE event;
|
|
|
|
rdpChannels* channels;
|
|
|
|
freerdp* instance = (freerdp*) arg;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc = (xfContext*) instance->context;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
channels = instance->context->channels;
|
|
|
|
event = freerdp_channels_get_event_handle(instance);
|
|
|
|
|
|
|
|
while (WaitForSingleObject(event, INFINITE) == WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
status = freerdp_channels_process_pending_messages(instance);
|
|
|
|
xf_process_channel_event(channels, instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Main loop for the rdp connection.
|
|
|
|
* 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)
|
|
|
|
*/
|
2013-04-02 22:51:12 +04:00
|
|
|
void* xf_thread(void* param)
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int fds;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc;
|
2013-04-02 21:22:59 +04:00
|
|
|
int max_fds;
|
|
|
|
int rcount;
|
|
|
|
int wcount;
|
|
|
|
BOOL status;
|
2013-04-02 22:51:12 +04:00
|
|
|
int exit_code;
|
2013-04-02 21:22:59 +04:00
|
|
|
void* rfds[32];
|
|
|
|
void* wfds[32];
|
|
|
|
fd_set rfds_set;
|
|
|
|
fd_set wfds_set;
|
2013-04-02 22:51:12 +04:00
|
|
|
freerdp* instance;
|
2013-04-02 21:22:59 +04:00
|
|
|
int fd_input_event;
|
2013-04-02 22:51:12 +04:00
|
|
|
HANDLE input_event;
|
2013-04-02 21:22:59 +04:00
|
|
|
int select_status;
|
|
|
|
BOOL async_update;
|
|
|
|
BOOL async_input;
|
|
|
|
BOOL async_channels;
|
|
|
|
BOOL async_transport;
|
|
|
|
HANDLE update_thread;
|
|
|
|
HANDLE input_thread;
|
|
|
|
HANDLE channels_thread;
|
|
|
|
rdpChannels* channels;
|
|
|
|
rdpSettings* settings;
|
|
|
|
struct timeval timeout;
|
|
|
|
|
2013-04-02 22:51:12 +04:00
|
|
|
exit_code = 0;
|
|
|
|
input_event = NULL;
|
|
|
|
|
|
|
|
instance = (freerdp*) param;
|
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
ZeroMemory(rfds, sizeof(rfds));
|
|
|
|
ZeroMemory(wfds, sizeof(wfds));
|
|
|
|
ZeroMemory(&timeout, sizeof(struct timeval));
|
|
|
|
|
|
|
|
status = freerdp_connect(instance);
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc = (xfContext*) instance->context;
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
/* Connection succeeded. --authonly ? */
|
|
|
|
if (instance->settings->AuthenticationOnly)
|
|
|
|
{
|
|
|
|
freerdp_disconnect(instance);
|
|
|
|
fprintf(stderr, "%s:%d: Authentication only, exit status %d\n", __FILE__, __LINE__, !status);
|
2013-08-19 19:44:52 +04:00
|
|
|
ExitThread(exit_code);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
{
|
2013-04-02 22:51:12 +04:00
|
|
|
exit_code = XF_EXIT_CONN_FAILED;
|
|
|
|
ExitThread(exit_code);
|
2013-04-02 21:22:59 +04:00
|
|
|
}
|
2013-06-14 04:25:50 +04:00
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
channels = instance->context->channels;
|
|
|
|
settings = instance->context->settings;
|
|
|
|
|
|
|
|
async_update = settings->AsyncUpdate;
|
|
|
|
async_input = settings->AsyncInput;
|
|
|
|
async_channels = settings->AsyncChannels;
|
|
|
|
async_transport = settings->AsyncTransport;
|
|
|
|
|
|
|
|
if (async_update)
|
|
|
|
{
|
|
|
|
update_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) xf_update_thread, instance, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (async_input)
|
|
|
|
{
|
|
|
|
input_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) xf_input_thread, instance, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (async_channels)
|
|
|
|
{
|
|
|
|
channels_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) xf_channels_thread, instance, 0, NULL);
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
while (!xfc->disconnect && !freerdp_shall_disconnect(instance))
|
2013-04-02 21:22:59 +04:00
|
|
|
{
|
|
|
|
rcount = 0;
|
|
|
|
wcount = 0;
|
|
|
|
|
2013-04-15 14:14:09 +04:00
|
|
|
if (freerdp_focus_required(instance))
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_kbd_focus_in(xfc);
|
2013-04-15 14:14:09 +04:00
|
|
|
}
|
|
|
|
|
2013-04-02 21:22:59 +04:00
|
|
|
if (!async_transport)
|
|
|
|
{
|
|
|
|
if (freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to get FreeRDP file descriptor\n");
|
2013-04-02 22:51:12 +04:00
|
|
|
exit_code = XF_EXIT_CONN_FAILED;
|
2013-04-02 21:22:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!async_channels)
|
|
|
|
{
|
|
|
|
if (freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount) != TRUE)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to get channel manager file descriptor\n");
|
2013-04-02 22:51:12 +04:00
|
|
|
exit_code = XF_EXIT_CONN_FAILED;
|
2013-04-02 21:22:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!async_input)
|
|
|
|
{
|
|
|
|
if (xf_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to get xfreerdp file descriptor\n");
|
2013-04-02 22:51:12 +04:00
|
|
|
exit_code = XF_EXIT_CONN_FAILED;
|
2013-04-02 21:22:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
input_event = freerdp_get_message_queue_event_handle(instance, FREERDP_INPUT_MESSAGE_QUEUE);
|
|
|
|
fd_input_event = GetEventFileDescriptor(input_event);
|
|
|
|
rfds[rcount++] = (void*) (long) fd_input_event;
|
|
|
|
}
|
|
|
|
|
|
|
|
max_fds = 0;
|
|
|
|
FD_ZERO(&rfds_set);
|
|
|
|
FD_ZERO(&wfds_set);
|
|
|
|
|
|
|
|
for (i = 0; i < rcount; i++)
|
|
|
|
{
|
|
|
|
fds = (int)(long)(rfds[i]);
|
|
|
|
|
|
|
|
if (fds > max_fds)
|
|
|
|
max_fds = fds;
|
|
|
|
|
|
|
|
FD_SET(fds, &rfds_set);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max_fds == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
timeout.tv_sec = 1;
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
|
|
|
|
select_status = select(max_fds + 1, &rfds_set, NULL, NULL, &timeout);
|
|
|
|
|
|
|
|
if (select_status == 0)
|
|
|
|
{
|
|
|
|
continue; /* select timeout */
|
|
|
|
}
|
|
|
|
else if (select_status == -1)
|
|
|
|
{
|
|
|
|
/* these are not really errors */
|
|
|
|
if (!((errno == EAGAIN) || (errno == EWOULDBLOCK) ||
|
|
|
|
(errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */
|
|
|
|
{
|
|
|
|
fprintf(stderr, "xfreerdp_run: select failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!async_transport)
|
|
|
|
{
|
|
|
|
if (freerdp_check_fds(instance) != TRUE)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to check FreeRDP file descriptor\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!async_channels)
|
|
|
|
{
|
|
|
|
if (freerdp_channels_check_fds(channels, instance) != TRUE)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to check channel manager file descriptor\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
xf_process_channel_event(channels, instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!async_input)
|
|
|
|
{
|
|
|
|
if (xf_process_x_events(instance) != TRUE)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Closed from X11\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (WaitForSingleObject(input_event, 0) == WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
if (!freerdp_message_queue_process_pending_messages(instance, FREERDP_INPUT_MESSAGE_QUEUE))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "User Disconnect\n");
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->disconnect = TRUE;
|
2013-04-02 21:22:59 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (async_update)
|
|
|
|
{
|
|
|
|
wMessageQueue* update_queue = freerdp_get_message_queue(instance, FREERDP_UPDATE_MESSAGE_QUEUE);
|
|
|
|
MessageQueue_PostQuit(update_queue, 0);
|
|
|
|
WaitForSingleObject(update_thread, INFINITE);
|
|
|
|
CloseHandle(update_thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE* fin = fopen("/tmp/tsmf.tid", "rt");
|
|
|
|
|
|
|
|
if (fin)
|
|
|
|
{
|
|
|
|
FILE* fin1;
|
|
|
|
int thid = 0;
|
|
|
|
int timeout;
|
|
|
|
|
|
|
|
fscanf(fin, "%d", &thid);
|
|
|
|
fclose(fin);
|
|
|
|
|
|
|
|
pthread_kill((pthread_t) (size_t) thid, SIGUSR1);
|
|
|
|
|
|
|
|
fin1 = fopen("/tmp/tsmf.tid", "rt");
|
|
|
|
timeout = 5;
|
|
|
|
|
|
|
|
while (fin1)
|
|
|
|
{
|
|
|
|
fclose(fin1);
|
|
|
|
sleep(1);
|
|
|
|
timeout--;
|
|
|
|
|
|
|
|
if (timeout <= 0)
|
|
|
|
{
|
|
|
|
unlink("/tmp/tsmf.tid");
|
|
|
|
pthread_kill((pthread_t) (size_t) thid, SIGKILL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fin1 = fopen("/tmp/tsmf.tid", "rt");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-02 22:51:12 +04:00
|
|
|
if (!exit_code)
|
|
|
|
exit_code = freerdp_error_info(instance);
|
2013-04-02 21:22:59 +04:00
|
|
|
|
|
|
|
freerdp_channels_close(channels, instance);
|
|
|
|
freerdp_channels_free(channels);
|
|
|
|
freerdp_disconnect(instance);
|
|
|
|
gdi_free(instance);
|
2013-04-03 00:22:30 +04:00
|
|
|
|
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
|
|
|
{
|
2013-04-02 22:51:12 +04:00
|
|
|
if (reason == 0 || (reason >= XF_EXIT_PARSE_ARGUMENTS && reason <= XF_EXIT_CONN_FAILED))
|
2013-04-02 21:22:59 +04:00
|
|
|
return reason;
|
|
|
|
|
|
|
|
/* License error set */
|
|
|
|
else if (reason >= 0x100 && reason <= 0x10A)
|
|
|
|
reason -= 0x100 + XF_EXIT_LICENSE_INTERNAL;
|
|
|
|
|
|
|
|
/* RDP protocol error set */
|
|
|
|
else if (reason >= 0x10c9 && reason <= 0x1193)
|
|
|
|
reason = XF_EXIT_RDP;
|
|
|
|
|
|
|
|
/* There's no need to test protocol-independent codes: they match */
|
|
|
|
else if (!(reason <= 0xB))
|
|
|
|
reason = XF_EXIT_UNKNOWN;
|
|
|
|
|
|
|
|
return reason;
|
|
|
|
}
|
2013-04-02 23:13:10 +04:00
|
|
|
|
2013-06-19 00:55:23 +04:00
|
|
|
void xf_TerminateEventHandler(rdpContext* context, TerminateEventArgs* e)
|
|
|
|
{
|
|
|
|
wMessageQueue* queue;
|
|
|
|
xfContext* xfc = (xfContext*) context;
|
|
|
|
|
|
|
|
if (context->settings->AsyncInput)
|
|
|
|
{
|
|
|
|
queue = freerdp_get_message_queue(context->instance, FREERDP_INPUT_MESSAGE_QUEUE);
|
|
|
|
|
|
|
|
if (queue)
|
|
|
|
MessageQueue_PostQuit(queue, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xfc->disconnect = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-27 05:56:37 +04:00
|
|
|
void xf_ParamChangeEventHandler(rdpContext* context, ParamChangeEventArgs* e)
|
|
|
|
{
|
2013-06-27 11:59:49 +04:00
|
|
|
|
|
|
|
xfContext* xfc = (xfContext*) context;
|
|
|
|
|
2013-06-27 05:56:37 +04:00
|
|
|
switch (e->id)
|
|
|
|
{
|
2013-06-27 23:07:40 +04:00
|
|
|
case FreeRDP_ScalingFactor:
|
2013-06-27 11:59:49 +04:00
|
|
|
|
|
|
|
xfc->currentWidth = xfc->originalWidth * xfc->settings->ScalingFactor;
|
|
|
|
xfc->currentHeight = xfc->originalHeight * xfc->settings->ScalingFactor;
|
|
|
|
|
|
|
|
xf_transform_window(xfc);
|
|
|
|
|
|
|
|
{
|
|
|
|
ResizeWindowEventArgs e;
|
|
|
|
|
|
|
|
EventArgsInit(&e, "xfreerdp");
|
|
|
|
e.width = (int) xfc->originalWidth * xfc->settings->ScalingFactor;
|
|
|
|
e.height = (int) xfc->originalHeight * xfc->settings->ScalingFactor;
|
|
|
|
PubSub_OnResizeWindow(((rdpContext*) xfc)->pubSub, xfc, &e);
|
|
|
|
}
|
|
|
|
xf_draw_screen_scaled(xfc, 0, 0, 0, 0, FALSE);
|
|
|
|
|
2013-06-27 23:07:40 +04:00
|
|
|
break;
|
2013-06-27 05:56:37 +04:00
|
|
|
|
2013-06-27 23:07:40 +04:00
|
|
|
default:
|
|
|
|
break;
|
2013-06-27 05:56:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-27 23:07:40 +04:00
|
|
|
void xf_ScalingFactorChangeEventHandler(rdpContext* context, ScalingFactorChangeEventArgs* e)
|
|
|
|
{
|
|
|
|
xfContext* xfc = (xfContext*) context;
|
|
|
|
|
|
|
|
xfc->settings->ScalingFactor += e->ScalingFactor;
|
|
|
|
|
|
|
|
if (xfc->settings->ScalingFactor > 1.2)
|
|
|
|
xfc->settings->ScalingFactor = 1.2;
|
|
|
|
if (xfc->settings->ScalingFactor < 0.8)
|
|
|
|
xfc->settings->ScalingFactor = 0.8;
|
|
|
|
|
|
|
|
|
|
|
|
xfc->currentWidth = xfc->originalWidth * xfc->settings->ScalingFactor;
|
|
|
|
xfc->currentHeight = xfc->originalHeight * xfc->settings->ScalingFactor;
|
|
|
|
|
|
|
|
xf_transform_window(xfc);
|
|
|
|
|
|
|
|
{
|
|
|
|
ResizeWindowEventArgs e;
|
|
|
|
|
|
|
|
EventArgsInit(&e, "xfreerdp");
|
|
|
|
e.width = (int) xfc->originalWidth * xfc->settings->ScalingFactor;
|
|
|
|
e.height = (int) xfc->originalHeight * xfc->settings->ScalingFactor;
|
|
|
|
PubSub_OnResizeWindow(((rdpContext*) xfc)->pubSub, xfc, &e);
|
|
|
|
}
|
|
|
|
xf_draw_screen_scaled(xfc, 0, 0, 0, 0, FALSE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-04-02 23:13:10 +04:00
|
|
|
/**
|
|
|
|
* Client Interface
|
|
|
|
*/
|
|
|
|
|
2013-06-14 06:11:23 +04:00
|
|
|
void xfreerdp_client_global_init()
|
2013-04-02 23:13:10 +04:00
|
|
|
{
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
freerdp_handle_signals();
|
|
|
|
freerdp_channels_global_init();
|
|
|
|
}
|
|
|
|
|
2013-06-14 06:11:23 +04:00
|
|
|
void xfreerdp_client_global_uninit()
|
2013-04-02 23:13:10 +04:00
|
|
|
{
|
|
|
|
freerdp_channels_global_uninit();
|
|
|
|
}
|
|
|
|
|
2013-06-14 06:11:23 +04:00
|
|
|
int xfreerdp_client_start(rdpContext* context)
|
2013-04-02 23:13:10 +04:00
|
|
|
{
|
2013-06-14 01:52:24 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
|
|
|
|
|
|
|
rdpSettings* settings = context->settings;
|
2013-04-22 16:33:41 +04:00
|
|
|
|
|
|
|
if (!settings->ServerHostname)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "error: server hostname was not specified with /v:<server>[:port]\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-06-14 04:25:50 +04:00
|
|
|
xfc->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) xf_thread, context->instance, 0, NULL);
|
2013-04-02 23:45:48 +04:00
|
|
|
|
2013-04-02 23:13:10 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-14 06:11:23 +04:00
|
|
|
int xfreerdp_client_stop(rdpContext* context)
|
2013-04-02 23:13:10 +04:00
|
|
|
{
|
2013-06-14 01:52:24 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
|
|
|
|
2013-06-14 04:25:50 +04:00
|
|
|
if (context->settings->AsyncInput)
|
2013-04-08 01:46:57 +04:00
|
|
|
{
|
|
|
|
wMessageQueue* queue;
|
2013-06-14 01:52:24 +04:00
|
|
|
queue = freerdp_get_message_queue(context->instance, FREERDP_INPUT_MESSAGE_QUEUE);
|
2013-06-19 00:55:23 +04:00
|
|
|
|
|
|
|
if (queue)
|
|
|
|
MessageQueue_PostQuit(queue, 0);
|
2013-04-08 01:46:57 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->disconnect = TRUE;
|
2013-04-08 01:46:57 +04:00
|
|
|
}
|
|
|
|
|
2013-08-19 19:44:52 +04:00
|
|
|
WaitForSingleObject(xfc->thread, INFINITE);
|
|
|
|
CloseHandle(xfc->thread);
|
|
|
|
|
2013-04-02 23:13:10 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-14 06:11:23 +04:00
|
|
|
int xfreerdp_client_new(freerdp* instance, rdpContext* context)
|
2013-04-02 23:13:10 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xfContext* xfc;
|
2013-04-07 01:43:27 +04:00
|
|
|
rdpSettings* settings;
|
2013-04-02 23:45:48 +04:00
|
|
|
|
2013-06-14 04:25:50 +04:00
|
|
|
xfc = (xfContext*) instance->context;
|
|
|
|
|
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;
|
2013-04-02 23:45:48 +04:00
|
|
|
instance->Authenticate = xf_authenticate;
|
|
|
|
instance->VerifyCertificate = xf_verify_certificate;
|
|
|
|
instance->LogonErrorInfo = xf_logon_error_info;
|
|
|
|
instance->ReceiveChannelData = xf_receive_channel_data;
|
|
|
|
|
2013-06-14 05:34:46 +04:00
|
|
|
context->channels = freerdp_channels_new();
|
2013-04-08 23:37:56 +04:00
|
|
|
|
2013-04-07 01:43:27 +04:00
|
|
|
settings = instance->settings;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->settings = instance->context->settings;
|
2013-04-07 01:43:27 +04:00
|
|
|
|
|
|
|
settings->OsMajorType = OSMAJORTYPE_UNIX;
|
|
|
|
settings->OsMinorType = OSMINORTYPE_NATIVE_XSERVER;
|
|
|
|
|
|
|
|
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;
|
|
|
|
settings->OrderSupport[NEG_MEM3BLT_INDEX] = (settings->SoftwareGdi) ? TRUE : FALSE;
|
|
|
|
settings->OrderSupport[NEG_MEMBLT_V2_INDEX] = settings->BitmapCacheEnabled;
|
|
|
|
settings->OrderSupport[NEG_MEM3BLT_V2_INDEX] = FALSE;
|
|
|
|
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;
|
|
|
|
settings->OrderSupport[NEG_POLYGON_SC_INDEX] = (settings->SoftwareGdi) ? FALSE : TRUE;
|
|
|
|
settings->OrderSupport[NEG_POLYGON_CB_INDEX] = (settings->SoftwareGdi) ? FALSE : TRUE;
|
|
|
|
settings->OrderSupport[NEG_ELLIPSE_SC_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_ELLIPSE_CB_INDEX] = FALSE;
|
2013-04-02 23:45:48 +04:00
|
|
|
|
2013-06-19 00:55:23 +04:00
|
|
|
PubSub_SubscribeTerminate(context->pubSub, (pTerminateEventHandler) xf_TerminateEventHandler);
|
2013-06-27 05:56:37 +04:00
|
|
|
PubSub_SubscribeParamChange(context->pubSub, (pParamChangeEventHandler) xf_ParamChangeEventHandler);
|
2013-06-27 23:07:40 +04:00
|
|
|
PubSub_SubscribeScalingFactorChange(context->pubSub, (pScalingFactorChangeEventHandler) xf_ScalingFactorChangeEventHandler);
|
2013-06-27 05:56:37 +04:00
|
|
|
|
2013-04-29 01:10:43 +04:00
|
|
|
|
2013-06-14 04:25:50 +04:00
|
|
|
return 0;
|
2013-04-02 23:13:10 +04:00
|
|
|
}
|
|
|
|
|
2013-06-14 06:11:23 +04:00
|
|
|
void xfreerdp_client_free(freerdp* instance, rdpContext* context)
|
2013-04-02 23:13:10 +04:00
|
|
|
{
|
2013-06-14 01:52:24 +04:00
|
|
|
xfContext* xfc = (xfContext*) context;
|
2013-04-12 21:44:23 +04:00
|
|
|
|
2013-06-14 01:52:24 +04:00
|
|
|
if (context)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_window_free(xfc);
|
2013-04-02 23:13:10 +04:00
|
|
|
|
2013-06-14 05:34:46 +04:00
|
|
|
if (xfc->bmp_codec_none)
|
|
|
|
free(xfc->bmp_codec_none);
|
2013-04-02 23:13:10 +04:00
|
|
|
|
2013-06-14 05:34:46 +04:00
|
|
|
if (xfc->display)
|
|
|
|
XCloseDisplay(xfc->display);
|
2013-04-02 23:45:48 +04:00
|
|
|
}
|
2013-04-02 23:13:10 +04:00
|
|
|
}
|
|
|
|
|
2013-06-14 04:25:50 +04:00
|
|
|
int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
|
|
|
|
{
|
|
|
|
pEntryPoints->Version = 1;
|
|
|
|
pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
|
2013-04-12 21:44:23 +04:00
|
|
|
|
2013-06-14 06:11:23 +04:00
|
|
|
pEntryPoints->GlobalInit = xfreerdp_client_global_init;
|
|
|
|
pEntryPoints->GlobalUninit = xfreerdp_client_global_uninit;
|
2013-04-12 21:44:23 +04:00
|
|
|
|
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;
|
2013-04-12 21:44:23 +04:00
|
|
|
|
2013-06-14 06:11:23 +04:00
|
|
|
pEntryPoints->ClientStart = xfreerdp_client_start;
|
|
|
|
pEntryPoints->ClientStop = xfreerdp_client_stop;
|
2013-04-12 21:44:23 +04:00
|
|
|
|
2013-06-14 04:25:50 +04:00
|
|
|
return 0;
|
2013-04-02 23:13:10 +04:00
|
|
|
}
|