FreeRDP/client/Mac/mf_client.m

217 lines
5.3 KiB
Mathematica
Raw Normal View History

/**
* 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>
#include "mfreerdp.h"
#include <winpr/assert.h>
2013-06-15 00:19:03 +04:00
#include <freerdp/constants.h>
#include <freerdp/utils/signal.h>
#include <freerdp/client/cmdline.h>
2022-02-01 18:08:24 +03:00
#include "MRDPView.h"
/**
* Client Interface
*/
2018-11-29 17:46:37 +03:00
static BOOL mfreerdp_client_global_init(void)
{
freerdp_handle_signals();
return TRUE;
}
2018-11-29 17:46:37 +03:00
static void mfreerdp_client_global_uninit(void)
{
}
2019-11-06 17:24:51 +03:00
static int mfreerdp_client_start(rdpContext *context)
{
2019-11-06 17:24:51 +03:00
MRDPView *view;
mfContext *mfc = (mfContext *)context;
2013-06-23 04:27:23 +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)];
mfc->view_ownership = TRUE;
}
2019-11-06 17:24:51 +03:00
view = (MRDPView *)mfc->view;
return [view rdpStart:context];
}
2019-11-06 17:24:51 +03:00
static int mfreerdp_client_stop(rdpContext *context)
{
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
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;
[view releaseResources];
[view release];
mfc->view = nil;
2013-06-23 04:27:23 +04:00
}
2013-06-23 04:27:23 +04:00
return 0;
}
2019-11-06 17:24:51 +03:00
static BOOL mfreerdp_client_new(freerdp *instance, rdpContext *context)
{
2019-11-06 17:24:51 +03:00
mfContext *mfc;
WINPR_ASSERT(instance);
2019-11-06 17:24:51 +03:00
mfc = (mfContext *)instance->context;
WINPR_ASSERT(mfc);
mfc->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!mfc->stopEvent)
return FALSE;
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;
context->instance->AuthenticateEx = mac_authenticate_ex;
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;
return TRUE;
}
2019-11-06 17:24:51 +03:00
static void mfreerdp_client_free(freerdp *instance, rdpContext *context)
{
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);
}
2019-11-06 17:24:51 +03:00
static void mf_scale_mouse_coordinates(mfContext *mfc, UINT16 *px, UINT16 *py)
{
2019-01-17 15:44:04 +03:00
UINT16 x = *px;
UINT16 y = *py;
UINT32 ww = mfc->client_width;
UINT32 wh = mfc->client_height;
UINT32 dw = mfc->common.context.settings->DesktopWidth;
UINT32 dh = mfc->common.context.settings->DesktopHeight;
2016-08-03 16:29:24 +03:00
if (!mfc->common.context.settings->SmartSizing || ((ww == dw) && (wh == dh)))
{
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);
}
else
{
y = y * dh / wh + mfc->yCurrentScroll;
2019-01-17 15:44:04 +03:00
x = x * dw / ww + mfc->xCurrentScroll;
}
2019-01-17 15:44:04 +03:00
*px = x;
*py = y;
}
2022-01-19 15:11:34 +03:00
void mf_scale_mouse_event(void *context, UINT16 flags, UINT16 x, UINT16 y)
{
2019-11-06 17:24:51 +03:00
mfContext *mfc = (mfContext *)context;
MRDPView *view = (MRDPView *)mfc->view;
// Convert to windows coordinates
y = [view frame].size.height - y;
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
}
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-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);
}
2022-01-19 15:11:34 +03:00
void mf_press_mouse_button(void *context, int button, int x, int y, BOOL down)
{
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);
break;
case 1:
2022-01-19 15:11:34 +03:00
mf_scale_mouse_event(context, flags | PTR_FLAGS_BUTTON2, x, y);
break;
case 2:
2022-01-19 15:11:34 +03:00
mf_scale_mouse_event(context, flags | PTR_FLAGS_BUTTON3, x, y);
break;
case 3:
2022-01-19 15:11:34 +03:00
mf_scale_mouse_event_ex(context, xflags | PTR_XFLAGS_BUTTON1, x, y);
break;
case 4:
2022-01-19 15:11:34 +03:00
mf_scale_mouse_event_ex(context, xflags | PTR_XFLAGS_BUTTON2, x, y);
break;
default:
break;
}
}
2019-11-06 17:24:51 +03:00
int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS *pEntryPoints)
{
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;
}