2013-06-14 18:00:19 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* X11 Client Interface
|
|
|
|
*
|
|
|
|
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2013-06-14 18:00:19 +04:00
|
|
|
|
|
|
|
#include "mfreerdp.h"
|
2022-01-19 11:27:39 +03:00
|
|
|
|
|
|
|
#include <winpr/assert.h>
|
|
|
|
|
2013-06-15 00:19:03 +04:00
|
|
|
#include <freerdp/constants.h>
|
2013-06-14 18:00:19 +04:00
|
|
|
#include <freerdp/utils/signal.h>
|
|
|
|
#include <freerdp/client/cmdline.h>
|
|
|
|
|
2022-02-01 18:08:24 +03:00
|
|
|
#include "MRDPView.h"
|
|
|
|
|
2013-06-14 18:00:19 +04:00
|
|
|
/**
|
|
|
|
* Client Interface
|
|
|
|
*/
|
|
|
|
|
2018-11-29 17:46:37 +03:00
|
|
|
static BOOL mfreerdp_client_global_init(void)
|
2013-06-14 18:00:19 +04:00
|
|
|
{
|
|
|
|
freerdp_handle_signals();
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2013-06-14 18:00:19 +04:00
|
|
|
}
|
|
|
|
|
2018-11-29 17:46:37 +03:00
|
|
|
static void mfreerdp_client_global_uninit(void)
|
2013-06-14 18:00:19 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static int mfreerdp_client_start(rdpContext *context)
|
2013-06-14 18:00:19 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
MRDPView *view;
|
|
|
|
mfContext *mfc = (mfContext *)context;
|
2013-06-23 04:27:23 +04:00
|
|
|
|
2013-11-05 20:49:42 +04:00
|
|
|
if (mfc->view == NULL)
|
|
|
|
{
|
|
|
|
// view not specified beforehand. Create view dynamically
|
2019-11-06 17:24:51 +03:00
|
|
|
mfc->view =
|
|
|
|
[[MRDPView alloc] initWithFrame:NSMakeRect(0, 0, context->settings->DesktopWidth,
|
|
|
|
context->settings->DesktopHeight)];
|
2013-11-05 20:49:42 +04:00
|
|
|
mfc->view_ownership = TRUE;
|
|
|
|
}
|
2013-06-26 21:45:12 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
view = (MRDPView *)mfc->view;
|
2015-05-05 14:55:48 +03:00
|
|
|
return [view rdpStart:context];
|
2013-06-14 18:00:19 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static int mfreerdp_client_stop(rdpContext *context)
|
2013-06-14 18:00:19 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
mfContext *mfc = (mfContext *)context;
|
2016-08-03 16:29:24 +03:00
|
|
|
|
2022-01-19 14:11:48 +03:00
|
|
|
freerdp_client_common_stop(context);
|
2016-08-03 16:29:24 +03:00
|
|
|
|
2013-11-05 20:49:42 +04:00
|
|
|
if (mfc->view_ownership)
|
2013-06-23 04:27:23 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
MRDPView *view = (MRDPView *)mfc->view;
|
2013-11-05 20:49:42 +04:00
|
|
|
[view releaseResources];
|
|
|
|
[view release];
|
|
|
|
mfc->view = nil;
|
2013-06-23 04:27:23 +04:00
|
|
|
}
|
2013-06-26 21:45:12 +04:00
|
|
|
|
2013-06-23 04:27:23 +04:00
|
|
|
return 0;
|
2013-06-14 18:00:19 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL mfreerdp_client_new(freerdp *instance, rdpContext *context)
|
2013-06-14 18:00:19 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
mfContext *mfc;
|
2022-01-19 11:27:39 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(instance);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
mfc = (mfContext *)instance->context;
|
2022-01-19 11:27:39 +03:00
|
|
|
WINPR_ASSERT(mfc);
|
|
|
|
|
2013-11-05 20:49:42 +04:00
|
|
|
mfc->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
2023-06-19 10:51:26 +03:00
|
|
|
if (!mfc->stopEvent)
|
|
|
|
return FALSE;
|
2013-11-05 20:49:42 +04:00
|
|
|
context->instance->PreConnect = mac_pre_connect;
|
|
|
|
context->instance->PostConnect = mac_post_connect;
|
2018-11-29 18:29:07 +03:00
|
|
|
context->instance->PostDisconnect = mac_post_disconnect;
|
2023-06-19 10:51:26 +03:00
|
|
|
context->instance->AuthenticateEx = mac_authenticate_ex;
|
2018-11-30 13:35:40 +03:00
|
|
|
context->instance->VerifyCertificateEx = mac_verify_certificate_ex;
|
|
|
|
context->instance->VerifyChangedCertificateEx = mac_verify_changed_certificate_ex;
|
2018-11-29 18:29:07 +03:00
|
|
|
context->instance->LogonErrorInfo = mac_logon_error_info;
|
2015-05-05 14:55:48 +03:00
|
|
|
return TRUE;
|
2013-06-14 18:00:19 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static void mfreerdp_client_free(freerdp *instance, rdpContext *context)
|
2013-06-14 18:00:19 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
mfContext *mfc;
|
2016-08-03 16:29:24 +03:00
|
|
|
|
|
|
|
if (!instance || !context)
|
|
|
|
return;
|
2013-06-23 06:55:51 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
mfc = (mfContext *)instance->context;
|
2016-08-03 16:29:24 +03:00
|
|
|
CloseHandle(mfc->stopEvent);
|
2013-06-14 18:00:19 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static void mf_scale_mouse_coordinates(mfContext *mfc, UINT16 *px, UINT16 *py)
|
2013-10-01 22:30:06 +04:00
|
|
|
{
|
2019-01-17 15:44:04 +03:00
|
|
|
UINT16 x = *px;
|
|
|
|
UINT16 y = *py;
|
|
|
|
UINT32 ww = mfc->client_width;
|
|
|
|
UINT32 wh = mfc->client_height;
|
2022-01-19 11:27:39 +03:00
|
|
|
UINT32 dw = mfc->common.context.settings->DesktopWidth;
|
|
|
|
UINT32 dh = mfc->common.context.settings->DesktopHeight;
|
2016-08-03 16:29:24 +03:00
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
if (!mfc->common.context.settings->SmartSizing || ((ww == dw) && (wh == dh)))
|
2013-11-05 20:49:42 +04:00
|
|
|
{
|
|
|
|
y = y + mfc->yCurrentScroll;
|
2019-01-17 15:44:04 +03:00
|
|
|
x = x + mfc->xCurrentScroll;
|
2016-08-03 16:29:24 +03:00
|
|
|
|
2019-01-17 15:44:04 +03:00
|
|
|
y -= (dh - wh);
|
|
|
|
x -= (dw - ww);
|
2013-11-05 20:49:42 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
y = y * dh / wh + mfc->yCurrentScroll;
|
2019-01-17 15:44:04 +03:00
|
|
|
x = x * dw / ww + mfc->xCurrentScroll;
|
2013-11-05 20:49:42 +04:00
|
|
|
}
|
2019-01-17 15:44:04 +03:00
|
|
|
|
|
|
|
*px = x;
|
|
|
|
*py = y;
|
2013-10-01 22:30:06 +04:00
|
|
|
}
|
|
|
|
|
2022-01-19 15:11:34 +03:00
|
|
|
void mf_scale_mouse_event(void *context, UINT16 flags, UINT16 x, UINT16 y)
|
2019-01-10 13:09:57 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
mfContext *mfc = (mfContext *)context;
|
|
|
|
MRDPView *view = (MRDPView *)mfc->view;
|
2019-01-10 13:09:57 +03:00
|
|
|
// Convert to windows coordinates
|
|
|
|
y = [view frame].size.height - y;
|
|
|
|
|
2019-01-23 18:22:29 +03:00
|
|
|
if ((flags & (PTR_FLAGS_WHEEL | PTR_FLAGS_HWHEEL)) == 0)
|
|
|
|
mf_scale_mouse_coordinates(mfc, &x, &y);
|
2022-01-19 15:11:34 +03:00
|
|
|
freerdp_client_send_button_event(&mfc->common, FALSE, flags, x, y);
|
2019-01-17 15:44:04 +03:00
|
|
|
}
|
2019-01-10 13:09:57 +03:00
|
|
|
|
2022-01-19 15:11:34 +03:00
|
|
|
void mf_scale_mouse_event_ex(void *context, UINT16 flags, UINT16 x, UINT16 y)
|
2019-01-17 15:44:04 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
mfContext *mfc = (mfContext *)context;
|
|
|
|
MRDPView *view = (MRDPView *)mfc->view;
|
2019-01-17 15:44:04 +03:00
|
|
|
// Convert to windows coordinates
|
|
|
|
y = [view frame].size.height - y;
|
2019-01-10 13:09:57 +03:00
|
|
|
|
2019-01-17 15:44:04 +03:00
|
|
|
mf_scale_mouse_coordinates(mfc, &x, &y);
|
2022-01-19 15:11:34 +03:00
|
|
|
freerdp_client_send_extended_button_event(&mfc->common, FALSE, flags, x, y);
|
2019-01-10 13:09:57 +03:00
|
|
|
}
|
|
|
|
|
2022-01-19 15:11:34 +03:00
|
|
|
void mf_press_mouse_button(void *context, int button, int x, int y, BOOL down)
|
2019-01-10 13:09:57 +03:00
|
|
|
{
|
|
|
|
UINT16 flags = 0;
|
|
|
|
UINT16 xflags = 0;
|
|
|
|
|
|
|
|
if (down)
|
|
|
|
{
|
|
|
|
flags |= PTR_FLAGS_DOWN;
|
|
|
|
xflags |= PTR_XFLAGS_DOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (button)
|
|
|
|
{
|
|
|
|
case 0:
|
2022-01-19 15:11:34 +03:00
|
|
|
mf_scale_mouse_event(context, flags | PTR_FLAGS_BUTTON1, x, y);
|
2019-01-10 13:09:57 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2022-01-19 15:11:34 +03:00
|
|
|
mf_scale_mouse_event(context, flags | PTR_FLAGS_BUTTON2, x, y);
|
2019-01-10 13:09:57 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2022-01-19 15:11:34 +03:00
|
|
|
mf_scale_mouse_event(context, flags | PTR_FLAGS_BUTTON3, x, y);
|
2019-01-10 13:09:57 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2022-01-19 15:11:34 +03:00
|
|
|
mf_scale_mouse_event_ex(context, xflags | PTR_XFLAGS_BUTTON1, x, y);
|
2019-01-10 13:09:57 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2022-01-19 15:11:34 +03:00
|
|
|
mf_scale_mouse_event_ex(context, xflags | PTR_XFLAGS_BUTTON2, x, y);
|
2019-01-10 13:09:57 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS *pEntryPoints)
|
2013-06-14 18:00:19 +04:00
|
|
|
{
|
2022-01-19 11:27:39 +03:00
|
|
|
WINPR_ASSERT(pEntryPoints);
|
|
|
|
|
2013-06-23 04:27:23 +04:00
|
|
|
pEntryPoints->Version = 1;
|
|
|
|
pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
|
|
|
|
pEntryPoints->GlobalInit = mfreerdp_client_global_init;
|
|
|
|
pEntryPoints->GlobalUninit = mfreerdp_client_global_uninit;
|
|
|
|
pEntryPoints->ContextSize = sizeof(mfContext);
|
|
|
|
pEntryPoints->ClientNew = mfreerdp_client_new;
|
|
|
|
pEntryPoints->ClientFree = mfreerdp_client_free;
|
|
|
|
pEntryPoints->ClientStart = mfreerdp_client_start;
|
|
|
|
pEntryPoints->ClientStop = mfreerdp_client_stop;
|
|
|
|
return 0;
|
2013-06-14 18:00:19 +04:00
|
|
|
}
|