2013-03-19 04:12:51 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Windows Client
|
|
|
|
*
|
|
|
|
* Copyright 2009-2011 Jay Sorg
|
|
|
|
* Copyright 2010-2011 Vic Lee
|
|
|
|
* Copyright 2010-2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
2013-10-07 21:46:13 +04:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-03-19 04:12:51 +04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
|
#include <winpr/windows.h>
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/credui.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <tchar.h>
|
2013-09-19 20:08:20 +04:00
|
|
|
#include <assert.h>
|
2013-03-19 04:12:51 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2014-09-12 19:13:01 +04:00
|
|
|
#include <freerdp/log.h>
|
2014-10-24 18:30:54 +04:00
|
|
|
#include <freerdp/event.h>
|
2013-03-19 04:12:51 +04:00
|
|
|
#include <freerdp/freerdp.h>
|
|
|
|
#include <freerdp/constants.h>
|
|
|
|
|
2014-10-25 03:46:02 +04:00
|
|
|
#include <freerdp/codec/region.h>
|
2013-03-19 04:12:51 +04:00
|
|
|
#include <freerdp/client/cmdline.h>
|
|
|
|
#include <freerdp/client/channels.h>
|
|
|
|
#include <freerdp/channels/channels.h>
|
|
|
|
|
|
|
|
#include "wf_gdi.h"
|
2014-10-25 03:46:02 +04:00
|
|
|
#include "wf_rail.h"
|
2014-09-13 00:30:57 +04:00
|
|
|
#include "wf_channels.h"
|
2013-03-19 04:12:51 +04:00
|
|
|
#include "wf_graphics.h"
|
|
|
|
#include "wf_cliprdr.h"
|
|
|
|
|
2014-09-13 00:30:57 +04:00
|
|
|
#include "wf_client.h"
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2013-03-19 19:11:14 +04:00
|
|
|
#include "resource.h"
|
|
|
|
|
2014-09-12 19:13:01 +04:00
|
|
|
#define TAG CLIENT_TAG("windows")
|
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
int wf_create_console(void)
|
|
|
|
{
|
|
|
|
if (!AllocConsole())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
freopen("CONOUT$", "w", stdout);
|
2013-08-17 20:49:51 +04:00
|
|
|
freopen("CONOUT$", "w", stderr);
|
2014-09-15 21:48:57 +04:00
|
|
|
WLog_INFO(TAG, "Debug console created.");
|
2013-03-19 04:12:51 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL wf_sw_begin_paint(wfContext* wfc)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
rdpGdi* gdi = ((rdpContext*) wfc)->gdi;
|
2013-03-19 04:12:51 +04:00
|
|
|
gdi->primary->hdc->hwnd->invalid->null = 1;
|
|
|
|
gdi->primary->hdc->hwnd->ninvalid = 0;
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL wf_sw_end_paint(wfContext* wfc)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
rdpGdi* gdi;
|
|
|
|
int ninvalid;
|
2014-10-25 03:46:02 +04:00
|
|
|
RECT updateRect;
|
2013-03-19 04:12:51 +04:00
|
|
|
HGDI_RGN cinvalid;
|
2014-10-25 03:46:02 +04:00
|
|
|
REGION16 invalidRegion;
|
|
|
|
RECTANGLE_16 invalidRect;
|
|
|
|
const RECTANGLE_16* extents;
|
|
|
|
rdpContext* context = (rdpContext*) wfc;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2014-10-25 03:46:02 +04:00
|
|
|
gdi = context->gdi;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
|
|
|
ninvalid = gdi->primary->hdc->hwnd->ninvalid;
|
|
|
|
cinvalid = gdi->primary->hdc->hwnd->cinvalid;
|
|
|
|
|
2014-10-25 03:46:02 +04:00
|
|
|
if (ninvalid < 1)
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2014-10-25 03:46:02 +04:00
|
|
|
|
|
|
|
region16_init(&invalidRegion);
|
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
for (i = 0; i < ninvalid; i++)
|
|
|
|
{
|
2014-10-25 03:46:02 +04:00
|
|
|
invalidRect.left = cinvalid[i].x;
|
|
|
|
invalidRect.top = cinvalid[i].y;
|
|
|
|
invalidRect.right = cinvalid[i].x + cinvalid[i].w;
|
|
|
|
invalidRect.bottom = cinvalid[i].y + cinvalid[i].h;
|
|
|
|
|
|
|
|
region16_union_rect(&invalidRegion, &invalidRegion, &invalidRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!region16_is_empty(&invalidRegion))
|
|
|
|
{
|
|
|
|
extents = region16_extents(&invalidRegion);
|
|
|
|
|
|
|
|
updateRect.left = extents->left;
|
|
|
|
updateRect.top = extents->top;
|
|
|
|
updateRect.right = extents->right;
|
|
|
|
updateRect.bottom = extents->bottom;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2014-10-25 03:46:02 +04:00
|
|
|
InvalidateRect(wfc->hwnd, &updateRect, FALSE);
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2014-10-25 03:46:02 +04:00
|
|
|
if (wfc->rail)
|
|
|
|
wf_rail_invalidate_region(wfc, &invalidRegion);
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
2014-10-25 03:46:02 +04:00
|
|
|
|
|
|
|
region16_uninit(&invalidRegion);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL wf_sw_desktop_resize(wfContext* wfc)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
|
|
|
rdpGdi* gdi;
|
2013-06-16 06:57:21 +04:00
|
|
|
rdpContext* context;
|
2013-03-19 04:12:51 +04:00
|
|
|
rdpSettings* settings;
|
2015-05-07 21:20:49 +03:00
|
|
|
freerdp* instance = wfc->instance;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2013-06-16 08:51:48 +04:00
|
|
|
context = (rdpContext*) wfc;
|
2013-06-16 06:57:21 +04:00
|
|
|
settings = wfc->instance->settings;
|
2013-03-19 04:12:51 +04:00
|
|
|
gdi = context->gdi;
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->width = settings->DesktopWidth;
|
|
|
|
wfc->height = settings->DesktopHeight;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2015-05-07 21:20:49 +03:00
|
|
|
gdi->primary->bitmap->data = NULL;
|
2015-03-17 15:02:41 +03:00
|
|
|
gdi_free(instance);
|
2015-05-07 21:20:49 +03:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->primary)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_image_free(wfc->primary);
|
2015-03-17 15:02:41 +03:00
|
|
|
wfc->primary = wf_image_new(wfc, wfc->width, wfc->height, wfc->dstBpp, NULL);
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
2015-05-08 22:39:23 +03:00
|
|
|
|
|
|
|
if (!gdi_init(instance, CLRCONV_ALPHA | CLRBUF_32BPP, wfc->primary->pdata))
|
|
|
|
return FALSE;
|
|
|
|
|
2015-03-17 15:02:41 +03:00
|
|
|
gdi = instance->context->gdi;
|
|
|
|
wfc->hdc = gdi->primary->hdc;
|
2015-05-07 21:20:49 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL wf_hw_begin_paint(wfContext* wfc)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->hdc->hwnd->invalid->null = 1;
|
|
|
|
wfc->hdc->hwnd->ninvalid = 0;
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL wf_hw_end_paint(wfContext* wfc)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL wf_hw_desktop_resize(wfContext* wfc)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
|
|
|
BOOL same;
|
|
|
|
RECT rect;
|
|
|
|
rdpSettings* settings;
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
settings = wfc->instance->settings;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->width = settings->DesktopWidth;
|
|
|
|
wfc->height = settings->DesktopHeight;
|
2013-03-19 05:54:50 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->primary)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
same = (wfc->primary == wfc->drawing) ? TRUE : FALSE;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_image_free(wfc->primary);
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->primary = wf_image_new(wfc, wfc->width, wfc->height, wfc->dstBpp, NULL);
|
2013-03-19 04:12:51 +04:00
|
|
|
|
|
|
|
if (same)
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->drawing = wfc->primary;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
2013-03-19 19:11:14 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->fullscreen != TRUE)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->hwnd)
|
|
|
|
SetWindowPos(wfc->hwnd, HWND_TOP, -1, -1, wfc->width + wfc->diff.x, wfc->height + wfc->diff.y, SWP_NOMOVE);
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_update_offset(wfc);
|
|
|
|
GetWindowRect(wfc->hwnd, &rect);
|
|
|
|
InvalidateRect(wfc->hwnd, &rect, TRUE);
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL wf_pre_connect(freerdp* instance)
|
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wfContext* wfc;
|
|
|
|
int desktopWidth;
|
|
|
|
int desktopHeight;
|
|
|
|
rdpContext* context;
|
2013-03-19 04:12:51 +04:00
|
|
|
rdpSettings* settings;
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
context = instance->context;
|
|
|
|
wfc = (wfContext*) instance->context;
|
|
|
|
wfc->instance = instance;
|
2014-09-10 08:42:41 +04:00
|
|
|
wfc->codecs = instance->context->codecs;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
|
|
|
settings = instance->settings;
|
|
|
|
|
|
|
|
if (settings->ConnectionFile)
|
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->connectionRdpFile)
|
2013-04-23 00:08:47 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
freerdp_client_rdp_file_free(wfc->connectionRdpFile);
|
2013-04-23 00:08:47 +04:00
|
|
|
}
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->connectionRdpFile = freerdp_client_rdp_file_new();
|
2014-09-15 21:48:57 +04:00
|
|
|
WLog_INFO(TAG, "Using connection file: %s", settings->ConnectionFile);
|
2013-06-16 06:57:21 +04:00
|
|
|
freerdp_client_parse_rdp_file(wfc->connectionRdpFile, settings->ConnectionFile);
|
|
|
|
freerdp_client_populate_settings_from_rdp_file(wfc->connectionRdpFile, settings);
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
settings->OsMajorType = OSMAJORTYPE_WINDOWS;
|
|
|
|
settings->OsMinorType = OSMINORTYPE_WINDOWS_NT;
|
|
|
|
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] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_MEM3BLT_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_SAVEBITMAP_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_GLYPH_INDEX_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_FAST_INDEX_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_FAST_GLYPH_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_POLYGON_SC_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_POLYGON_CB_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_ELLIPSE_SC_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_ELLIPSE_CB_INDEX] = FALSE;
|
|
|
|
|
|
|
|
settings->GlyphSupportLevel = GLYPH_SUPPORT_NONE;
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->fullscreen = settings->Fullscreen;
|
2014-09-12 19:34:30 +04:00
|
|
|
|
2014-03-04 09:50:31 +04:00
|
|
|
if (wfc->fullscreen)
|
|
|
|
wfc->fs_toggle = 1;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->clrconv = (HCLRCONV) malloc(sizeof(CLRCONV));
|
|
|
|
ZeroMemory(wfc->clrconv, sizeof(CLRCONV));
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->clrconv->palette = NULL;
|
|
|
|
wfc->clrconv->alpha = FALSE;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
|
|
|
instance->context->cache = cache_new(settings);
|
|
|
|
|
2013-04-25 00:33:43 +04:00
|
|
|
desktopWidth = settings->DesktopWidth;
|
|
|
|
desktopHeight = settings->DesktopHeight;
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->percentscreen > 0)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
desktopWidth = (GetSystemMetrics(SM_CXSCREEN) * wfc->percentscreen) / 100;
|
2013-04-25 18:50:26 +04:00
|
|
|
settings->DesktopWidth = desktopWidth;
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
desktopHeight = (GetSystemMetrics(SM_CYSCREEN) * wfc->percentscreen) / 100;
|
2013-04-25 18:50:26 +04:00
|
|
|
settings->DesktopHeight = desktopHeight;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
2014-03-04 11:35:21 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->fullscreen)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2013-04-25 18:50:26 +04:00
|
|
|
if (settings->UseMultimon)
|
|
|
|
{
|
2014-02-26 07:34:48 +04:00
|
|
|
desktopWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
|
|
|
desktopHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
2013-04-25 18:50:26 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-26 07:34:48 +04:00
|
|
|
desktopWidth = GetSystemMetrics(SM_CXSCREEN);
|
|
|
|
desktopHeight = GetSystemMetrics(SM_CYSCREEN);
|
2013-04-25 18:50:26 +04:00
|
|
|
}
|
2013-04-25 00:33:43 +04:00
|
|
|
}
|
|
|
|
|
2014-03-04 11:35:21 +04:00
|
|
|
/* FIXME: desktopWidth has a limitation that it should be divisible by 4,
|
|
|
|
* otherwise the screen will crash when connecting to an XP desktop.*/
|
|
|
|
desktopWidth = (desktopWidth + 3) & (~3);
|
|
|
|
|
2013-04-25 00:33:43 +04:00
|
|
|
if (desktopWidth != settings->DesktopWidth)
|
|
|
|
{
|
|
|
|
freerdp_set_param_uint32(settings, FreeRDP_DesktopWidth, desktopWidth);
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2013-04-25 00:33:43 +04:00
|
|
|
if (desktopHeight != settings->DesktopHeight)
|
|
|
|
{
|
|
|
|
freerdp_set_param_uint32(settings, FreeRDP_DesktopHeight, desktopHeight);
|
|
|
|
}
|
2013-03-19 04:12:51 +04:00
|
|
|
|
|
|
|
if ((settings->DesktopWidth < 64) || (settings->DesktopHeight < 64) ||
|
|
|
|
(settings->DesktopWidth > 4096) || (settings->DesktopHeight > 4096))
|
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "invalid dimensions %d %d", settings->DesktopWidth, settings->DesktopHeight);
|
2013-03-19 04:12:51 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-04-25 00:33:43 +04:00
|
|
|
freerdp_set_param_uint32(settings, FreeRDP_KeyboardLayout, (int) GetKeyboardLayout(0) & 0x0000FFFF);
|
2014-09-13 00:30:57 +04:00
|
|
|
|
|
|
|
PubSub_SubscribeChannelConnected(instance->context->pubSub,
|
|
|
|
(pChannelConnectedEventHandler) wf_OnChannelConnectedEventHandler);
|
|
|
|
|
|
|
|
PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
|
|
|
|
(pChannelDisconnectedEventHandler) wf_OnChannelDisconnectedEventHandler);
|
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
freerdp_channels_pre_connect(instance->context->channels, instance);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
void wf_add_system_menu(wfContext* wfc)
|
2013-04-30 19:15:04 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
HMENU hMenu = GetSystemMenu(wfc->hwnd, FALSE);
|
2013-04-30 19:15:04 +04:00
|
|
|
|
|
|
|
MENUITEMINFO item_info;
|
|
|
|
ZeroMemory(&item_info, sizeof(MENUITEMINFO));
|
|
|
|
|
|
|
|
item_info.fMask = MIIM_CHECKMARKS | MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_DATA;
|
|
|
|
item_info.cbSize = sizeof(MENUITEMINFO);
|
|
|
|
item_info.wID = SYSCOMMAND_ID_SMARTSIZING;
|
|
|
|
item_info.fType = MFT_STRING;
|
|
|
|
item_info.dwTypeData = _wcsdup(_T("Smart sizing"));
|
2014-02-10 09:34:17 +04:00
|
|
|
item_info.cch = (UINT) _wcslen(_T("Smart sizing"));
|
2013-06-16 06:57:21 +04:00
|
|
|
item_info.dwItemData = (ULONG_PTR) wfc;
|
2013-04-30 19:15:04 +04:00
|
|
|
|
|
|
|
InsertMenuItem(hMenu, 6, TRUE, &item_info);
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->instance->settings->SmartSizing)
|
2013-04-30 19:15:04 +04:00
|
|
|
{
|
|
|
|
CheckMenuItem(hMenu, SYSCOMMAND_ID_SMARTSIZING, MF_CHECKED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
BOOL wf_post_connect(freerdp* instance)
|
|
|
|
{
|
|
|
|
rdpGdi* gdi;
|
2013-04-02 02:32:14 +04:00
|
|
|
DWORD dwStyle;
|
2013-03-19 04:12:51 +04:00
|
|
|
rdpCache* cache;
|
2013-06-16 06:57:21 +04:00
|
|
|
wfContext* wfc;
|
|
|
|
rdpContext* context;
|
2013-03-19 21:17:30 +04:00
|
|
|
WCHAR lpWindowName[64];
|
2013-03-19 04:12:51 +04:00
|
|
|
rdpSettings* settings;
|
2013-10-07 21:46:13 +04:00
|
|
|
EmbedWindowEventArgs e;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
|
|
|
settings = instance->settings;
|
2013-06-16 06:57:21 +04:00
|
|
|
context = instance->context;
|
|
|
|
wfc = (wfContext*) instance->context;
|
2013-03-19 04:12:51 +04:00
|
|
|
cache = instance->context->cache;
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->dstBpp = 32;
|
|
|
|
wfc->width = settings->DesktopWidth;
|
|
|
|
wfc->height = settings->DesktopHeight;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2014-09-12 19:34:30 +04:00
|
|
|
if (settings->SoftwareGdi)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2014-09-11 17:51:44 +04:00
|
|
|
wfc->primary = wf_image_new(wfc, wfc->width, wfc->height, wfc->dstBpp, NULL);
|
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!gdi_init(instance, CLRCONV_ALPHA | CLRBUF_32BPP, wfc->primary->pdata))
|
|
|
|
return FALSE;
|
2014-09-11 17:51:44 +04:00
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
gdi = instance->context->gdi;
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->hdc = gdi->primary->hdc;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wf_gdi_register_update_callbacks(instance->update);
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->srcBpp = instance->settings->ColorDepth;
|
|
|
|
wfc->primary = wf_image_new(wfc, wfc->width, wfc->height, wfc->dstBpp, NULL);
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!(wfc->hdc = gdi_GetDC()))
|
|
|
|
return FALSE;
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->hdc->bitsPerPixel = wfc->dstBpp;
|
|
|
|
wfc->hdc->bytesPerPixel = wfc->dstBpp / 8;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->hdc->alpha = wfc->clrconv->alpha;
|
|
|
|
wfc->hdc->invert = wfc->clrconv->invert;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->hdc->hwnd = (HGDI_WND) malloc(sizeof(GDI_WND));
|
|
|
|
wfc->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0);
|
|
|
|
wfc->hdc->hwnd->invalid->null = 1;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->hdc->hwnd->count = 32;
|
|
|
|
wfc->hdc->hwnd->cinvalid = (HGDI_RGN) malloc(sizeof(GDI_RGN) * wfc->hdc->hwnd->count);
|
|
|
|
wfc->hdc->hwnd->ninvalid = 0;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
|
|
|
if (settings->RemoteFxCodec)
|
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->tile = wf_image_new(wfc, 64, 64, 32, NULL);
|
2013-03-19 21:17:30 +04:00
|
|
|
}
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (settings->WindowTitle != NULL)
|
2013-03-19 21:17:30 +04:00
|
|
|
_snwprintf(lpWindowName, ARRAYSIZE(lpWindowName), L"%S", settings->WindowTitle);
|
2013-03-19 04:12:51 +04:00
|
|
|
else if (settings->ServerPort == 3389)
|
2013-03-19 21:17:30 +04:00
|
|
|
_snwprintf(lpWindowName, ARRAYSIZE(lpWindowName), L"FreeRDP: %S", settings->ServerHostname);
|
2013-03-19 04:12:51 +04:00
|
|
|
else
|
2013-03-19 21:17:30 +04:00
|
|
|
_snwprintf(lpWindowName, ARRAYSIZE(lpWindowName), L"FreeRDP: %S:%d", settings->ServerHostname, settings->ServerPort);
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2013-10-07 21:46:13 +04:00
|
|
|
if (settings->EmbeddedWindow)
|
|
|
|
settings->Decorations = FALSE;
|
2015-03-17 15:02:41 +03:00
|
|
|
|
2014-08-20 00:59:22 +04:00
|
|
|
if (wfc->fullscreen)
|
|
|
|
dwStyle = WS_POPUP;
|
|
|
|
else if (!settings->Decorations)
|
2013-04-02 02:32:14 +04:00
|
|
|
dwStyle = WS_CHILD | WS_BORDER;
|
|
|
|
else
|
2014-08-20 00:59:22 +04:00
|
|
|
dwStyle = WS_CAPTION | WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_SIZEBOX | WS_MAXIMIZEBOX;
|
2013-04-02 02:32:14 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (!wfc->hwnd)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->hwnd = CreateWindowEx((DWORD) NULL, wfc->wndClassName, lpWindowName, dwStyle,
|
|
|
|
0, 0, 0, 0, wfc->hWndParent, NULL, wfc->hInstance, NULL);
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2014-10-25 02:30:04 +04:00
|
|
|
SetWindowLongPtr(wfc->hwnd, GWLP_USERDATA, (LONG_PTR) wfc);
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_resize_window(wfc);
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wf_add_system_menu(wfc);
|
2013-04-30 19:15:04 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
BitBlt(wfc->primary->hdc, 0, 0, wfc->width, wfc->height, NULL, 0, 0, BLACKNESS);
|
|
|
|
wfc->drawing = wfc->primary;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2013-10-07 21:46:13 +04:00
|
|
|
EventArgsInit(&e, "wfreerdp");
|
|
|
|
e.embed = FALSE;
|
|
|
|
e.handle = (void*) wfc->hwnd;
|
2015-03-17 15:02:41 +03:00
|
|
|
PubSub_OnEmbedWindow(context->pubSub, context, &e);
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
ShowWindow(wfc->hwnd, SW_SHOWNORMAL);
|
|
|
|
UpdateWindow(wfc->hwnd);
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2014-09-12 19:34:30 +04:00
|
|
|
if (settings->SoftwareGdi)
|
2015-03-17 15:02:41 +03:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
instance->update->BeginPaint = (pBeginPaint) wf_sw_begin_paint;
|
|
|
|
instance->update->EndPaint = (pEndPaint) wf_sw_end_paint;
|
|
|
|
instance->update->DesktopResize = (pDesktopResize) wf_sw_desktop_resize;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
instance->update->BeginPaint = (pBeginPaint) wf_hw_begin_paint;
|
|
|
|
instance->update->EndPaint = (pEndPaint) wf_hw_end_paint;
|
|
|
|
instance->update->DesktopResize = (pDesktopResize) wf_hw_desktop_resize;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
pointer_cache_register_callbacks(instance->update);
|
2014-09-12 19:34:30 +04:00
|
|
|
wf_register_pointer(context->graphics);
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2014-09-12 19:34:30 +04:00
|
|
|
if (!settings->SoftwareGdi)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
|
|
|
brush_cache_register_callbacks(instance->update);
|
|
|
|
bitmap_cache_register_callbacks(instance->update);
|
|
|
|
offscreen_cache_register_callbacks(instance->update);
|
2014-09-12 19:34:30 +04:00
|
|
|
wf_register_graphics(context->graphics);
|
|
|
|
instance->update->BitmapUpdate = wf_gdi_bitmap_update;
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2014-09-12 19:34:30 +04:00
|
|
|
freerdp_channels_post_connect(context->channels, instance);
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2014-03-04 09:50:31 +04:00
|
|
|
if (wfc->fullscreen)
|
|
|
|
floatbar_window_create(wfc);
|
2013-04-19 18:06:26 +04:00
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CREDUI_INFOA wfUiInfo =
|
|
|
|
{
|
|
|
|
sizeof(CREDUI_INFOA),
|
|
|
|
NULL,
|
|
|
|
"Enter your credentials",
|
|
|
|
"Remote Desktop Security",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
BOOL wf_authenticate(freerdp* instance, char** username, char** password, char** domain)
|
|
|
|
{
|
|
|
|
BOOL fSave;
|
|
|
|
DWORD status;
|
|
|
|
DWORD dwFlags;
|
|
|
|
char UserName[CREDUI_MAX_USERNAME_LENGTH + 1];
|
|
|
|
char Password[CREDUI_MAX_PASSWORD_LENGTH + 1];
|
|
|
|
char User[CREDUI_MAX_USERNAME_LENGTH + 1];
|
|
|
|
char Domain[CREDUI_MAX_DOMAIN_TARGET_LENGTH + 1];
|
|
|
|
|
|
|
|
fSave = FALSE;
|
|
|
|
ZeroMemory(UserName, sizeof(UserName));
|
|
|
|
ZeroMemory(Password, sizeof(Password));
|
|
|
|
dwFlags = CREDUI_FLAGS_DO_NOT_PERSIST | CREDUI_FLAGS_EXCLUDE_CERTIFICATES;
|
|
|
|
|
2015-06-18 17:07:25 +03:00
|
|
|
status = CredUIPromptForCredentialsA(&wfUiInfo,
|
|
|
|
instance->settings->ServerHostname,
|
|
|
|
NULL, 0,
|
2013-03-19 04:12:51 +04:00
|
|
|
UserName, CREDUI_MAX_USERNAME_LENGTH + 1,
|
|
|
|
Password, CREDUI_MAX_PASSWORD_LENGTH + 1, &fSave, dwFlags);
|
|
|
|
|
|
|
|
if (status != NO_ERROR)
|
|
|
|
{
|
2015-01-30 06:57:58 +03:00
|
|
|
WLog_ERR(TAG, "CredUIPromptForCredentials unexpected status: 0x%08X", status);
|
2013-03-19 04:12:51 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZeroMemory(User, sizeof(User));
|
|
|
|
ZeroMemory(Domain, sizeof(Domain));
|
|
|
|
|
|
|
|
status = CredUIParseUserNameA(UserName, User, sizeof(User), Domain, sizeof(Domain));
|
2015-01-30 06:57:58 +03:00
|
|
|
//WLog_ERR(TAG, "User: %s Domain: %s Password: %s", User, Domain, Password);
|
2013-03-19 04:12:51 +04:00
|
|
|
*username = _strdup(User);
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!(*username))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "strdup failed", status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-03-19 04:12:51 +04:00
|
|
|
|
|
|
|
if (strlen(Domain) > 0)
|
|
|
|
*domain = _strdup(Domain);
|
2015-06-18 14:01:28 +03:00
|
|
|
else
|
|
|
|
*domain = _strdup("\0");
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!(*domain))
|
|
|
|
{
|
|
|
|
free(*username);
|
|
|
|
WLog_ERR(TAG, "strdup failed", status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
*password = _strdup(Password);
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!(*password))
|
|
|
|
{
|
|
|
|
free(*username);
|
|
|
|
free(*domain);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-03-19 04:12:51 +04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL wf_verify_certificate(freerdp* instance, char* subject, char* issuer, char* fingerprint)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
DWORD mode;
|
|
|
|
int read_size;
|
|
|
|
DWORD read_count;
|
|
|
|
TCHAR answer[2];
|
|
|
|
TCHAR* read_buffer;
|
|
|
|
HANDLE input_handle;
|
|
|
|
#endif
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_INFO(TAG, "Certificate details:");
|
|
|
|
WLog_INFO(TAG, "\tSubject: %s", subject);
|
|
|
|
WLog_INFO(TAG, "\tIssuer: %s", issuer);
|
|
|
|
WLog_INFO(TAG, "\tThumbprint: %s", fingerprint);
|
|
|
|
WLog_INFO(TAG, "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.");
|
2013-03-19 04:12:51 +04:00
|
|
|
/* TODO: ask for user validation */
|
|
|
|
#if 0
|
|
|
|
input_handle = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
|
|
|
|
GetConsoleMode(input_handle, &mode);
|
|
|
|
mode |= ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT;
|
|
|
|
SetConsoleMode(input_handle, mode);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-04-27 16:52:45 +04:00
|
|
|
static BOOL wf_auto_reconnect(freerdp* instance)
|
|
|
|
{
|
|
|
|
wfContext* wfc = (wfContext *)instance->context;
|
|
|
|
|
|
|
|
UINT32 num_retries = 0;
|
|
|
|
UINT32 max_retries = instance->settings->AutoReconnectMaxRetries;
|
|
|
|
|
|
|
|
/* Only auto reconnect on network disconnects. */
|
|
|
|
if (freerdp_error_info(instance) != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* A network disconnect was detected */
|
2015-01-30 06:57:58 +03:00
|
|
|
WLog_ERR(TAG, "Network disconnect!");
|
2014-09-12 19:13:01 +04:00
|
|
|
|
2014-04-27 16:52:45 +04:00
|
|
|
if (!instance->settings->AutoReconnectionEnabled)
|
|
|
|
{
|
|
|
|
/* No auto-reconnect - just quit */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform an auto-reconnect. */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* Quit retrying if max retries has been exceeded */
|
|
|
|
if (num_retries++ >= max_retries)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Attempt the next reconnect */
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_INFO(TAG, "Attempting reconnect (%u of %u)", num_retries, max_retries);
|
|
|
|
|
2014-04-27 16:52:45 +04:00
|
|
|
if (freerdp_reconnect(instance))
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sleep(5000);
|
|
|
|
}
|
|
|
|
|
2015-01-30 06:57:58 +03:00
|
|
|
WLog_ERR(TAG, "Maximum reconnect retries exceeded");
|
2014-04-27 16:52:45 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-05-21 10:52:57 +04:00
|
|
|
void* wf_input_thread(void* arg)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
wMessage message;
|
|
|
|
wMessageQueue* queue;
|
|
|
|
freerdp* instance = (freerdp*) arg;
|
|
|
|
|
|
|
|
assert( NULL != instance);
|
|
|
|
|
|
|
|
status = 1;
|
2015-01-30 06:57:58 +03:00
|
|
|
queue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE);
|
2014-05-21 10:52:57 +04:00
|
|
|
|
|
|
|
while (MessageQueue_Wait(queue))
|
|
|
|
{
|
|
|
|
while (MessageQueue_Peek(queue, &message, TRUE))
|
|
|
|
{
|
|
|
|
status = freerdp_message_queue_process_message(instance,
|
|
|
|
FREERDP_INPUT_MESSAGE_QUEUE, &message);
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExitThread(0);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-16 08:51:48 +04:00
|
|
|
DWORD WINAPI wf_client_thread(LPVOID lpParam)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
|
|
|
MSG msg;
|
2013-04-11 00:58:14 +04:00
|
|
|
int width;
|
|
|
|
int height;
|
2013-03-19 04:12:51 +04:00
|
|
|
BOOL msg_ret;
|
|
|
|
int quit_msg;
|
2015-01-30 06:57:58 +03:00
|
|
|
DWORD nCount;
|
|
|
|
HANDLE handles[64];
|
2013-06-16 06:57:21 +04:00
|
|
|
wfContext* wfc;
|
2013-03-19 19:11:14 +04:00
|
|
|
freerdp* instance;
|
2015-01-30 06:57:58 +03:00
|
|
|
rdpContext* context;
|
2013-03-19 04:12:51 +04:00
|
|
|
rdpChannels* channels;
|
2014-05-21 10:52:57 +04:00
|
|
|
rdpSettings* settings;
|
|
|
|
BOOL async_input;
|
|
|
|
BOOL async_transport;
|
|
|
|
HANDLE input_thread;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2013-03-19 19:11:14 +04:00
|
|
|
instance = (freerdp*) lpParam;
|
2015-01-30 06:57:58 +03:00
|
|
|
context = instance->context;
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc = (wfContext*) instance->context;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2015-01-30 06:57:58 +03:00
|
|
|
if (!freerdp_connect(instance))
|
2013-03-19 04:12:51 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
channels = instance->context->channels;
|
2014-05-21 10:52:57 +04:00
|
|
|
settings = instance->context->settings;
|
|
|
|
|
|
|
|
async_input = settings->AsyncInput;
|
|
|
|
async_transport = settings->AsyncTransport;
|
|
|
|
|
|
|
|
if (async_input)
|
|
|
|
{
|
2015-05-05 14:55:48 +03:00
|
|
|
if (!(input_thread = CreateThread(NULL, 0,
|
2014-05-21 10:52:57 +04:00
|
|
|
(LPTHREAD_START_ROUTINE) wf_input_thread,
|
2015-05-05 14:55:48 +03:00
|
|
|
instance, 0, NULL)))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to create async input thread.");
|
|
|
|
goto disconnect;
|
|
|
|
}
|
2014-05-21 10:52:57 +04:00
|
|
|
}
|
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
while (1)
|
|
|
|
{
|
2015-01-30 06:57:58 +03:00
|
|
|
nCount = 0;
|
2013-03-19 04:12:51 +04:00
|
|
|
|
2014-10-03 18:27:47 +04:00
|
|
|
if (freerdp_focus_required(instance))
|
|
|
|
{
|
|
|
|
wf_event_focus_in(wfc);
|
|
|
|
wf_event_focus_in(wfc);
|
|
|
|
}
|
|
|
|
|
2014-05-21 10:52:57 +04:00
|
|
|
if (!async_transport)
|
2013-03-19 04:12:51 +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-03-19 04:12:51 +04:00
|
|
|
}
|
2014-05-21 10:52:57 +04:00
|
|
|
|
2015-01-30 06:57:58 +03:00
|
|
|
if (MsgWaitForMultipleObjects(nCount, handles, FALSE, 1000, QS_ALLINPUT) == WAIT_FAILED)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2015-01-30 06:57:58 +03:00
|
|
|
WLog_ERR(TAG, "wfreerdp_run: WaitForMultipleObjects failed: 0x%04X", GetLastError());
|
2013-03-19 04:12:51 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-05-21 10:52:57 +04:00
|
|
|
if (!async_transport)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
2015-01-30 06:57:58 +03:00
|
|
|
if (!freerdp_check_event_handles(context))
|
2014-05-21 10:52:57 +04:00
|
|
|
{
|
|
|
|
if (wf_auto_reconnect(instance))
|
|
|
|
continue;
|
2014-04-27 16:52:45 +04:00
|
|
|
|
2015-01-30 06:57:58 +03:00
|
|
|
WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
|
2014-05-21 10:52:57 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
2015-01-30 06:57:58 +03:00
|
|
|
|
2015-03-17 15:02:41 +03:00
|
|
|
if (freerdp_shall_disconnect(instance))
|
2013-03-19 04:12:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
quit_msg = FALSE;
|
2013-03-19 05:54:50 +04:00
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
|
|
|
|
{
|
|
|
|
msg_ret = GetMessage(&msg, NULL, 0, 0);
|
|
|
|
|
2013-04-11 00:58:14 +04:00
|
|
|
if (instance->settings->EmbeddedWindow)
|
|
|
|
{
|
|
|
|
if ((msg.message == WM_SETFOCUS) && (msg.lParam == 1))
|
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
PostMessage(wfc->hwnd, WM_SETFOCUS, 0, 0);
|
2013-04-11 00:58:14 +04:00
|
|
|
}
|
|
|
|
else if ((msg.message == WM_KILLFOCUS) && (msg.lParam == 1))
|
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
PostMessage(wfc->hwnd, WM_KILLFOCUS, 0, 0);
|
2013-04-11 00:58:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg.message == WM_SIZE)
|
|
|
|
{
|
|
|
|
width = LOWORD(msg.lParam);
|
|
|
|
height = HIWORD(msg.lParam);
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
SetWindowPos(wfc->hwnd, HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED);
|
2013-04-11 00:58:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((msg_ret == 0) || (msg_ret == -1))
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
|
|
|
quit_msg = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (quit_msg)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cleanup */
|
2015-01-20 13:26:00 +03:00
|
|
|
freerdp_channels_disconnect(channels, instance);
|
2014-05-21 10:52:57 +04:00
|
|
|
|
|
|
|
if (async_input)
|
|
|
|
{
|
|
|
|
wMessageQueue* input_queue;
|
2015-01-30 06:57:58 +03:00
|
|
|
input_queue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE);
|
2015-05-23 23:47:18 +03:00
|
|
|
if (MessageQueue_PostQuit(input_queue, 0))
|
|
|
|
WaitForSingleObject(input_thread, INFINITE);
|
2014-05-21 10:52:57 +04:00
|
|
|
CloseHandle(input_thread);
|
|
|
|
}
|
|
|
|
|
2015-05-05 14:55:48 +03:00
|
|
|
disconnect:
|
2013-06-16 06:57:21 +04:00
|
|
|
freerdp_disconnect(instance);
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_DBG(TAG, "Main thread exited.");
|
2015-01-30 06:57:58 +03:00
|
|
|
|
2013-09-05 15:39:43 +04:00
|
|
|
ExitThread(0);
|
2013-03-19 04:12:51 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-19 05:54:50 +04:00
|
|
|
DWORD WINAPI wf_keyboard_thread(LPVOID lpParam)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
BOOL status;
|
2013-06-16 06:57:21 +04:00
|
|
|
wfContext* wfc;
|
2013-03-19 04:12:51 +04:00
|
|
|
HHOOK hook_handle;
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc = (wfContext*) lpParam;
|
2013-09-05 15:39:43 +04:00
|
|
|
assert(NULL != wfc);
|
2013-03-19 05:54:50 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
hook_handle = SetWindowsHookEx(WH_KEYBOARD_LL, wf_ll_kbd_proc, wfc->hInstance, 0);
|
2013-03-19 04:12:51 +04:00
|
|
|
|
|
|
|
if (hook_handle)
|
|
|
|
{
|
2013-03-19 05:54:50 +04:00
|
|
|
while ((status = GetMessage(&msg, NULL, 0, 0)) != 0)
|
2013-03-19 04:12:51 +04:00
|
|
|
{
|
|
|
|
if (status == -1)
|
|
|
|
{
|
2015-01-30 06:57:58 +03:00
|
|
|
WLog_ERR(TAG, "keyboard thread error getting message");
|
2013-03-19 04:12:51 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
2013-03-19 05:54:50 +04:00
|
|
|
|
2013-03-19 04:12:51 +04:00
|
|
|
UnhookWindowsHookEx(hook_handle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-30 06:57:58 +03:00
|
|
|
WLog_ERR(TAG, "failed to install keyboard hook");
|
2013-03-19 04:12:51 +04:00
|
|
|
}
|
|
|
|
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_DBG(TAG, "Keyboard thread exited.");
|
2013-09-05 15:39:43 +04:00
|
|
|
ExitThread(0);
|
2013-03-19 04:12:51 +04:00
|
|
|
return (DWORD) NULL;
|
|
|
|
}
|
2013-03-19 05:54:50 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
rdpSettings* freerdp_client_get_settings(wfContext* wfc)
|
2013-03-19 05:54:50 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
return wfc->instance->settings;
|
2013-03-19 05:54:50 +04:00
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
int freerdp_client_focus_in(wfContext* wfc)
|
2013-03-19 05:54:50 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
PostThreadMessage(wfc->mainThreadId, WM_SETFOCUS, 0, 1);
|
2013-03-19 05:54:50 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
int freerdp_client_focus_out(wfContext* wfc)
|
2013-03-19 05:54:50 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
PostThreadMessage(wfc->mainThreadId, WM_KILLFOCUS, 0, 1);
|
2013-04-11 00:58:14 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
int freerdp_client_set_window_size(wfContext* wfc, int width, int height)
|
2013-04-30 23:18:26 +04:00
|
|
|
{
|
2014-09-15 21:48:57 +04:00
|
|
|
WLog_DBG(TAG, "freerdp_client_set_window_size %d, %d", width, height);
|
2014-09-12 19:13:01 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if ((width != wfc->client_width) || (height != wfc->client_height))
|
2013-04-11 00:58:14 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
PostThreadMessage(wfc->mainThreadId, WM_SIZE, SIZE_RESTORED, ((UINT) height << 16) | (UINT) width);
|
2013-04-11 00:58:14 +04:00
|
|
|
}
|
|
|
|
|
2013-03-19 05:54:50 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-23 00:08:47 +04:00
|
|
|
// TODO: Some of that code is a duplicate of wf_pre_connect. Refactor?
|
2013-06-16 06:57:21 +04:00
|
|
|
int freerdp_client_load_settings_from_rdp_file(wfContext* wfc, char* filename)
|
2013-04-23 00:08:47 +04:00
|
|
|
{
|
|
|
|
rdpSettings* settings;
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
settings = wfc->instance->settings;
|
2013-04-23 00:08:47 +04:00
|
|
|
|
|
|
|
if (filename)
|
|
|
|
{
|
|
|
|
settings->ConnectionFile = _strdup(filename);
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!settings->ConnectionFile)
|
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
2013-04-23 00:08:47 +04:00
|
|
|
|
|
|
|
// free old settings file
|
2013-06-16 06:57:21 +04:00
|
|
|
freerdp_client_rdp_file_free(wfc->connectionRdpFile);
|
|
|
|
wfc->connectionRdpFile = freerdp_client_rdp_file_new();
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_INFO(TAG, "Using connection file: %s", settings->ConnectionFile);
|
2013-04-23 00:08:47 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (!freerdp_client_parse_rdp_file(wfc->connectionRdpFile, settings->ConnectionFile))
|
2013-04-23 00:08:47 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (!freerdp_client_populate_settings_from_rdp_file(wfc->connectionRdpFile, settings))
|
2013-04-23 00:08:47 +04:00
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-10 09:34:17 +04:00
|
|
|
void wf_size_scrollbars(wfContext* wfc, UINT32 client_width, UINT32 client_height)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
2014-02-10 09:34:17 +04:00
|
|
|
if (wfc->disablewindowtracking)
|
2013-04-26 23:46:36 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
// prevent infinite message loop
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->disablewindowtracking = TRUE;
|
2013-04-26 23:46:36 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->instance->settings->SmartSizing)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->xCurrentScroll = 0;
|
|
|
|
wfc->yCurrentScroll = 0;
|
2013-04-30 19:15:04 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (wfc->xScrollVisible || wfc->yScrollVisible)
|
2013-04-30 19:15:04 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
if (ShowScrollBar(wfc->hwnd, SB_BOTH, FALSE))
|
2013-04-30 19:15:04 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->xScrollVisible = FALSE;
|
|
|
|
wfc->yScrollVisible = FALSE;
|
2013-04-30 19:15:04 +04:00
|
|
|
}
|
|
|
|
}
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCROLLINFO si;
|
2013-06-16 06:57:21 +04:00
|
|
|
BOOL horiz = wfc->xScrollVisible;
|
|
|
|
BOOL vert = wfc->yScrollVisible;;
|
2013-04-26 23:46:36 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (!horiz && client_width < wfc->instance->settings->DesktopWidth)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
2015-03-17 15:02:41 +03:00
|
|
|
horiz = TRUE;
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
2013-06-16 06:57:21 +04:00
|
|
|
else if (horiz && client_width >= wfc->instance->settings->DesktopWidth/* - GetSystemMetrics(SM_CXVSCROLL)*/)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
2015-03-17 15:02:41 +03:00
|
|
|
horiz = FALSE;
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (!vert && client_height < wfc->instance->settings->DesktopHeight)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
|
|
|
vert = TRUE;
|
|
|
|
}
|
2013-06-16 06:57:21 +04:00
|
|
|
else if (vert && client_height >= wfc->instance->settings->DesktopHeight/* - GetSystemMetrics(SM_CYHSCROLL)*/)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
|
|
|
vert = FALSE;
|
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (horiz == vert && (horiz != wfc->xScrollVisible && vert != wfc->yScrollVisible))
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
if (ShowScrollBar(wfc->hwnd, SB_BOTH, horiz))
|
2013-04-30 19:15:04 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->xScrollVisible = horiz;
|
|
|
|
wfc->yScrollVisible = vert;
|
2013-04-30 19:15:04 +04:00
|
|
|
}
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (horiz != wfc->xScrollVisible)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
if (ShowScrollBar(wfc->hwnd, SB_HORZ, horiz))
|
2013-04-30 19:15:04 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->xScrollVisible = horiz;
|
2013-04-30 19:15:04 +04:00
|
|
|
}
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (vert != wfc->yScrollVisible)
|
2013-04-26 23:46:36 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
if (ShowScrollBar(wfc->hwnd, SB_VERT, vert))
|
2013-04-30 19:15:04 +04:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->yScrollVisible = vert;
|
2013-04-30 19:15:04 +04:00
|
|
|
}
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (horiz)
|
|
|
|
{
|
2015-03-17 15:02:41 +03:00
|
|
|
// The horizontal scrolling range is defined by
|
|
|
|
// (bitmap_width) - (client_width). The current horizontal
|
|
|
|
// scroll value remains within the horizontal scrolling range.
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->xMaxScroll = MAX(wfc->instance->settings->DesktopWidth - client_width, 0);
|
|
|
|
wfc->xCurrentScroll = MIN(wfc->xCurrentScroll, wfc->xMaxScroll);
|
2015-03-17 15:02:41 +03:00
|
|
|
si.cbSize = sizeof(si);
|
|
|
|
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
|
2013-06-16 06:57:21 +04:00
|
|
|
si.nMin = wfc->xMinScroll;
|
|
|
|
si.nMax = wfc->instance->settings->DesktopWidth;
|
2015-03-17 15:02:41 +03:00
|
|
|
si.nPage = client_width;
|
2013-06-16 06:57:21 +04:00
|
|
|
si.nPos = wfc->xCurrentScroll;
|
|
|
|
SetScrollInfo(wfc->hwnd, SB_HORZ, &si, TRUE);
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vert)
|
|
|
|
{
|
2015-03-17 15:02:41 +03:00
|
|
|
// The vertical scrolling range is defined by
|
|
|
|
// (bitmap_height) - (client_height). The current vertical
|
|
|
|
// scroll value remains within the vertical scrolling range.
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->yMaxScroll = MAX(wfc->instance->settings->DesktopHeight - client_height, 0);
|
|
|
|
wfc->yCurrentScroll = MIN(wfc->yCurrentScroll, wfc->yMaxScroll);
|
2015-03-17 15:02:41 +03:00
|
|
|
si.cbSize = sizeof(si);
|
|
|
|
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
|
2013-06-16 06:57:21 +04:00
|
|
|
si.nMin = wfc->yMinScroll;
|
|
|
|
si.nMax = wfc->instance->settings->DesktopHeight;
|
2015-03-17 15:02:41 +03:00
|
|
|
si.nPage = client_height;
|
2013-06-16 06:57:21 +04:00
|
|
|
si.nPos = wfc->yCurrentScroll;
|
|
|
|
SetScrollInfo(wfc->hwnd, SB_VERT, &si, TRUE);
|
2013-04-26 23:46:36 +04:00
|
|
|
}
|
|
|
|
}
|
2013-04-30 19:15:04 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
wfc->disablewindowtracking = FALSE;
|
|
|
|
wf_update_canvas_diff(wfc);
|
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL wfreerdp_client_global_init(void)
|
2013-06-16 06:57:21 +04:00
|
|
|
{
|
|
|
|
WSADATA wsaData;
|
|
|
|
|
|
|
|
if (!getenv("HOME"))
|
|
|
|
{
|
|
|
|
char home[MAX_PATH * 2] = "HOME=";
|
|
|
|
strcat(home, getenv("HOMEDRIVE"));
|
|
|
|
strcat(home, getenv("HOMEPATH"));
|
|
|
|
_putenv(home);
|
|
|
|
}
|
|
|
|
|
|
|
|
WSAStartup(0x101, &wsaData);
|
|
|
|
|
|
|
|
#if defined(WITH_DEBUG) || defined(_DEBUG)
|
|
|
|
wf_create_console();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
freerdp_register_addin_provider(freerdp_channels_load_static_addin_entry, 0);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-06-16 06:57:21 +04:00
|
|
|
}
|
|
|
|
|
2013-06-16 08:51:48 +04:00
|
|
|
void wfreerdp_client_global_uninit(void)
|
2013-06-16 06:57:21 +04:00
|
|
|
{
|
|
|
|
WSACleanup();
|
|
|
|
}
|
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
BOOL wfreerdp_client_new(freerdp* instance, rdpContext* context)
|
2013-06-16 06:57:21 +04:00
|
|
|
{
|
|
|
|
wfContext* wfc = (wfContext*) context;
|
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(wfreerdp_client_global_init()))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!(context->channels = freerdp_channels_new()))
|
|
|
|
return FALSE;
|
2013-06-16 08:51:48 +04:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
instance->PreConnect = wf_pre_connect;
|
|
|
|
instance->PostConnect = wf_post_connect;
|
|
|
|
instance->Authenticate = wf_authenticate;
|
|
|
|
instance->VerifyCertificate = wf_verify_certificate;
|
|
|
|
|
|
|
|
wfc->instance = instance;
|
2014-10-24 19:30:04 +04:00
|
|
|
wfc->settings = instance->settings;
|
2014-10-25 03:46:02 +04:00
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
return TRUE;
|
2013-06-16 06:57:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void wfreerdp_client_free(freerdp* instance, rdpContext* context)
|
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (context->channels)
|
|
|
|
{
|
|
|
|
freerdp_channels_close(context->channels, instance);
|
|
|
|
freerdp_channels_free(context->channels);
|
|
|
|
context->channels = NULL;
|
|
|
|
}
|
2015-01-20 13:26:00 +03:00
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
if (context->cache)
|
2015-04-28 18:00:41 +03:00
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
cache_free(context->cache);
|
2015-04-28 18:00:41 +03:00
|
|
|
context->cache = NULL;
|
|
|
|
}
|
2013-06-16 06:57:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int wfreerdp_client_start(rdpContext* context)
|
|
|
|
{
|
|
|
|
HWND hWndParent;
|
|
|
|
HINSTANCE hInstance;
|
|
|
|
wfContext* wfc = (wfContext*) context;
|
|
|
|
freerdp* instance = context->instance;
|
|
|
|
|
|
|
|
hInstance = GetModuleHandle(NULL);
|
|
|
|
hWndParent = (HWND) instance->settings->ParentWindowId;
|
|
|
|
instance->settings->EmbeddedWindow = (hWndParent) ? TRUE : FALSE;
|
|
|
|
|
|
|
|
wfc->hWndParent = hWndParent;
|
|
|
|
wfc->hInstance = hInstance;
|
|
|
|
wfc->cursor = LoadCursor(NULL, IDC_ARROW);
|
|
|
|
wfc->icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
|
|
|
|
wfc->wndClassName = _tcsdup(_T("FreeRDP"));
|
|
|
|
|
|
|
|
wfc->wndClass.cbSize = sizeof(WNDCLASSEX);
|
|
|
|
wfc->wndClass.style = CS_HREDRAW | CS_VREDRAW;
|
|
|
|
wfc->wndClass.lpfnWndProc = wf_event_proc;
|
|
|
|
wfc->wndClass.cbClsExtra = 0;
|
|
|
|
wfc->wndClass.cbWndExtra = 0;
|
|
|
|
wfc->wndClass.hCursor = wfc->cursor;
|
|
|
|
wfc->wndClass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
|
|
|
|
wfc->wndClass.lpszMenuName = NULL;
|
|
|
|
wfc->wndClass.lpszClassName = wfc->wndClassName;
|
|
|
|
wfc->wndClass.hInstance = hInstance;
|
|
|
|
wfc->wndClass.hIcon = wfc->icon;
|
|
|
|
wfc->wndClass.hIconSm = wfc->icon;
|
|
|
|
RegisterClassEx(&(wfc->wndClass));
|
|
|
|
|
|
|
|
wfc->keyboardThread = CreateThread(NULL, 0, wf_keyboard_thread, (void*) wfc, 0, &wfc->keyboardThreadId);
|
|
|
|
|
|
|
|
if (!wfc->keyboardThread)
|
|
|
|
return -1;
|
|
|
|
|
2013-06-16 08:51:48 +04:00
|
|
|
freerdp_client_load_addins(context->channels, instance->settings);
|
2013-06-16 06:57:21 +04:00
|
|
|
|
2013-06-16 08:51:48 +04:00
|
|
|
wfc->thread = CreateThread(NULL, 0, wf_client_thread, (void*) instance, 0, &wfc->mainThreadId);
|
2013-06-16 06:57:21 +04:00
|
|
|
|
|
|
|
if (!wfc->thread)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int wfreerdp_client_stop(rdpContext* context)
|
|
|
|
{
|
|
|
|
wfContext* wfc = (wfContext*) context;
|
|
|
|
|
2013-09-05 15:39:43 +04:00
|
|
|
if (wfc->thread)
|
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
PostThreadMessage(wfc->mainThreadId, WM_QUIT, 0, 0);
|
|
|
|
|
2013-09-05 15:39:43 +04:00
|
|
|
WaitForSingleObject(wfc->thread, INFINITE);
|
|
|
|
CloseHandle(wfc->thread);
|
|
|
|
wfc->thread = NULL;
|
|
|
|
wfc->mainThreadId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wfc->keyboardThread)
|
|
|
|
{
|
2013-06-16 06:57:21 +04:00
|
|
|
PostThreadMessage(wfc->keyboardThreadId, WM_QUIT, 0, 0);
|
|
|
|
|
2013-09-05 15:39:43 +04:00
|
|
|
WaitForSingleObject(wfc->keyboardThread, INFINITE);
|
|
|
|
CloseHandle(wfc->keyboardThread);
|
|
|
|
|
|
|
|
wfc->keyboardThread = NULL;
|
|
|
|
wfc->keyboardThreadId = 0;
|
|
|
|
}
|
|
|
|
|
2013-06-16 06:57:21 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
|
|
|
|
{
|
|
|
|
pEntryPoints->Version = 1;
|
|
|
|
pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
|
|
|
|
|
|
|
|
pEntryPoints->GlobalInit = wfreerdp_client_global_init;
|
|
|
|
pEntryPoints->GlobalUninit = wfreerdp_client_global_uninit;
|
|
|
|
|
|
|
|
pEntryPoints->ContextSize = sizeof(wfContext);
|
|
|
|
pEntryPoints->ClientNew = wfreerdp_client_new;
|
|
|
|
pEntryPoints->ClientFree = wfreerdp_client_free;
|
|
|
|
|
|
|
|
pEntryPoints->ClientStart = wfreerdp_client_start;
|
|
|
|
pEntryPoints->ClientStop = wfreerdp_client_stop;
|
|
|
|
|
|
|
|
return 0;
|
2013-05-31 22:54:15 +04:00
|
|
|
}
|