2014-10-13 13:43:16 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2014-11-17 18:36:28 +03:00
|
|
|
* Wayland Client
|
2014-10-13 13:43:16 +04:00
|
|
|
*
|
|
|
|
* Copyright 2014 Manuel Bachmann <tarnyko@tarnyko.net>
|
2016-04-05 18:07:45 +03:00
|
|
|
* Copyright 2016 Thincast Technologies GmbH
|
|
|
|
* Copyright 2016 Armin Novak <armin.novak@thincast.com>
|
2014-10-13 13:43:16 +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.
|
|
|
|
*/
|
|
|
|
|
2024-01-23 18:49:54 +03:00
|
|
|
#include <math.h>
|
2014-10-13 13:43:16 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2016-08-03 19:44:26 +03:00
|
|
|
#include <locale.h>
|
2019-01-25 13:47:15 +03:00
|
|
|
#include <float.h>
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2021-10-18 11:18:42 +03:00
|
|
|
#include <winpr/sysinfo.h>
|
|
|
|
|
2014-10-13 13:43:16 +04:00
|
|
|
#include <freerdp/client/cmdline.h>
|
|
|
|
#include <freerdp/channels/channels.h>
|
|
|
|
#include <freerdp/gdi/gdi.h>
|
2016-08-03 19:44:26 +03:00
|
|
|
#include <freerdp/client.h>
|
|
|
|
#include <freerdp/utils/signal.h>
|
2017-07-13 14:29:00 +03:00
|
|
|
#include <freerdp/locale/keyboard.h>
|
2016-08-03 19:44:26 +03:00
|
|
|
|
2016-01-07 01:56:05 +03:00
|
|
|
#include <linux/input.h>
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
#include <uwac/uwac.h>
|
|
|
|
|
2014-11-17 18:36:28 +03:00
|
|
|
#include "wlfreerdp.h"
|
2016-01-07 01:56:05 +03:00
|
|
|
#include "wlf_input.h"
|
2018-12-19 18:18:13 +03:00
|
|
|
#include "wlf_cliprdr.h"
|
2018-12-18 14:30:31 +03:00
|
|
|
#include "wlf_disp.h"
|
2016-08-03 19:44:26 +03:00
|
|
|
#include "wlf_channels.h"
|
2019-01-25 15:05:51 +03:00
|
|
|
#include "wlf_pointer.h"
|
2016-01-07 01:56:05 +03:00
|
|
|
|
2019-02-08 13:50:34 +03:00
|
|
|
#define TAG CLIENT_TAG("wayland")
|
|
|
|
|
2019-01-24 13:19:20 +03:00
|
|
|
static BOOL wl_update_buffer(wlfContext* context_w, INT32 ix, INT32 iy, INT32 iw, INT32 ih)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
2020-06-15 16:49:21 +03:00
|
|
|
BOOL res = FALSE;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpGdi* gdi = NULL;
|
|
|
|
char* data = NULL;
|
|
|
|
UINT32 x = 0;
|
|
|
|
UINT32 y = 0;
|
|
|
|
UINT32 w = 0;
|
|
|
|
UINT32 h = 0;
|
2019-01-24 17:10:08 +03:00
|
|
|
UwacSize geometry;
|
2024-01-23 18:49:54 +03:00
|
|
|
size_t stride = 0;
|
|
|
|
UwacReturnCode rc = UWAC_ERROR_INTERNAL;
|
2019-01-25 13:47:15 +03:00
|
|
|
RECTANGLE_16 area;
|
2017-11-16 14:42:33 +03:00
|
|
|
|
2019-01-18 16:38:51 +03:00
|
|
|
if (!context_w)
|
2017-11-16 14:42:33 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2019-01-24 13:19:20 +03:00
|
|
|
if ((ix < 0) || (iy < 0) || (iw < 0) || (ih < 0))
|
|
|
|
return FALSE;
|
|
|
|
|
2020-06-15 16:49:21 +03:00
|
|
|
EnterCriticalSection(&context_w->critical);
|
2019-01-24 13:19:20 +03:00
|
|
|
x = (UINT32)ix;
|
|
|
|
y = (UINT32)iy;
|
|
|
|
w = (UINT32)iw;
|
|
|
|
h = (UINT32)ih;
|
2019-01-24 17:10:08 +03:00
|
|
|
rc = UwacWindowGetDrawingBufferGeometry(context_w->window, &geometry, &stride);
|
2016-01-07 01:56:05 +03:00
|
|
|
data = UwacWindowGetDrawingBuffer(context_w->window);
|
2016-08-03 19:44:26 +03:00
|
|
|
|
2019-01-24 17:10:08 +03:00
|
|
|
if (!data || (rc != UWAC_SUCCESS))
|
2020-06-15 16:49:21 +03:00
|
|
|
goto fail;
|
2016-02-25 02:41:19 +03:00
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
gdi = context_w->common.context.gdi;
|
2019-01-18 16:38:51 +03:00
|
|
|
|
|
|
|
if (!gdi)
|
2020-06-15 16:49:21 +03:00
|
|
|
goto fail;
|
2019-01-18 16:38:51 +03:00
|
|
|
|
2019-01-24 17:10:08 +03:00
|
|
|
/* Ignore output if the surface size does not match. */
|
2019-02-07 16:39:15 +03:00
|
|
|
if (((INT64)x > geometry.width) || ((INT64)y > geometry.height))
|
2020-06-15 16:49:21 +03:00
|
|
|
{
|
|
|
|
res = TRUE;
|
|
|
|
goto fail;
|
|
|
|
}
|
2019-01-24 17:10:08 +03:00
|
|
|
|
2019-01-25 13:47:15 +03:00
|
|
|
area.left = x;
|
|
|
|
area.top = y;
|
|
|
|
area.right = x + w;
|
|
|
|
area.bottom = y + h;
|
2019-01-24 17:10:08 +03:00
|
|
|
|
2023-10-13 10:48:44 +03:00
|
|
|
if (!wlf_copy_image(
|
|
|
|
gdi->primary_buffer, gdi->stride, gdi->width, gdi->height, data, stride, geometry.width,
|
|
|
|
geometry.height, &area,
|
|
|
|
freerdp_settings_get_bool(context_w->common.context.settings, FreeRDP_SmartSizing)))
|
2020-06-15 16:49:21 +03:00
|
|
|
goto fail;
|
2019-01-25 13:47:15 +03:00
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
if (!wlf_scale_coordinates(&context_w->common.context, &x, &y, FALSE))
|
2020-06-15 16:49:21 +03:00
|
|
|
goto fail;
|
2019-01-25 13:47:15 +03:00
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
if (!wlf_scale_coordinates(&context_w->common.context, &w, &h, FALSE))
|
2020-06-15 16:49:21 +03:00
|
|
|
goto fail;
|
2014-11-17 18:36:28 +03:00
|
|
|
|
2016-02-25 02:41:19 +03:00
|
|
|
if (UwacWindowAddDamage(context_w->window, x, y, w, h) != UWAC_SUCCESS)
|
2020-06-15 16:49:21 +03:00
|
|
|
goto fail;
|
2016-02-25 02:41:19 +03:00
|
|
|
|
2019-07-25 19:17:04 +03:00
|
|
|
if (UwacWindowSubmitBuffer(context_w->window, false) != UWAC_SUCCESS)
|
2020-06-15 16:49:21 +03:00
|
|
|
goto fail;
|
2019-01-24 14:01:40 +03:00
|
|
|
|
2020-06-15 16:49:21 +03:00
|
|
|
res = TRUE;
|
|
|
|
fail:
|
|
|
|
LeaveCriticalSection(&context_w->critical);
|
|
|
|
return res;
|
2014-10-13 13:43:16 +04:00
|
|
|
}
|
|
|
|
|
2019-01-18 16:38:51 +03:00
|
|
|
static BOOL wl_end_paint(rdpContext* context)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpGdi* gdi = NULL;
|
|
|
|
wlfContext* context_w = NULL;
|
|
|
|
INT32 x = 0;
|
|
|
|
INT32 y = 0;
|
|
|
|
INT32 w = 0;
|
|
|
|
INT32 h = 0;
|
2019-01-18 16:38:51 +03:00
|
|
|
|
|
|
|
if (!context || !context->gdi || !context->gdi->primary)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gdi = context->gdi;
|
|
|
|
|
|
|
|
if (gdi->primary->hdc->hwnd->invalid->null)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
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;
|
2019-11-06 17:24:51 +03:00
|
|
|
context_w = (wlfContext*)context;
|
2022-06-23 08:57:38 +03:00
|
|
|
if (!wl_update_buffer(context_w, x, y, w, h))
|
|
|
|
{
|
2020-09-18 12:20:22 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gdi->primary->hdc->hwnd->invalid->null = TRUE;
|
|
|
|
gdi->primary->hdc->hwnd->ninvalid = 0;
|
|
|
|
return TRUE;
|
2019-01-18 16:38:51 +03:00
|
|
|
}
|
|
|
|
|
2019-01-22 12:29:08 +03:00
|
|
|
static BOOL wl_refresh_display(wlfContext* context)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpGdi* gdi = NULL;
|
2019-01-22 12:29:08 +03:00
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
if (!context || !context->common.context.gdi)
|
2019-01-22 12:29:08 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2022-01-19 11:27:39 +03:00
|
|
|
gdi = context->common.context.gdi;
|
2019-01-22 12:29:08 +03:00
|
|
|
return wl_update_buffer(context, 0, 0, gdi->width, gdi->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL wl_resize_display(rdpContext* context)
|
|
|
|
{
|
|
|
|
wlfContext* wlc = (wlfContext*)context;
|
|
|
|
rdpGdi* gdi = context->gdi;
|
|
|
|
rdpSettings* settings = context->settings;
|
|
|
|
|
2023-10-13 10:48:44 +03:00
|
|
|
if (!gdi_resize(gdi, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
|
|
|
|
freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)))
|
2019-01-22 12:29:08 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return wl_refresh_display(wlc);
|
|
|
|
}
|
2016-01-07 01:56:05 +03:00
|
|
|
|
2015-04-20 17:20:16 +03:00
|
|
|
static BOOL wl_pre_connect(freerdp* instance)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpSettings* settings = NULL;
|
|
|
|
wlfContext* context = NULL;
|
|
|
|
const UwacOutput* output = NULL;
|
2017-08-17 20:33:44 +03:00
|
|
|
UwacSize resolution;
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
if (!instance)
|
2015-04-20 17:20:16 +03:00
|
|
|
return FALSE;
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (wlfContext*)instance->context;
|
2022-03-23 15:18:35 +03:00
|
|
|
WINPR_ASSERT(context);
|
2016-08-03 19:44:26 +03:00
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
settings = instance->context->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2024-08-20 12:00:28 +03:00
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_CertificateCallbackPreferPEM, TRUE))
|
|
|
|
return FALSE;
|
|
|
|
|
2023-10-13 10:48:44 +03:00
|
|
|
if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMajorType, OSMAJORTYPE_UNIX))
|
|
|
|
return FALSE;
|
|
|
|
if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMinorType, OSMINORTYPE_NATIVE_WAYLAND))
|
|
|
|
return FALSE;
|
2019-11-06 17:24:51 +03:00
|
|
|
PubSub_SubscribeChannelConnected(instance->context->pubSub, wlf_OnChannelConnectedEventHandler);
|
2016-08-03 19:44:26 +03:00
|
|
|
PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
|
2018-02-14 12:14:33 +03:00
|
|
|
wlf_OnChannelDisconnectedEventHandler);
|
2016-08-03 19:44:26 +03:00
|
|
|
|
2023-10-13 10:48:44 +03:00
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_Fullscreen))
|
2017-08-17 20:33:44 +03:00
|
|
|
{
|
|
|
|
// Use the resolution of the first display output
|
2020-05-05 11:31:26 +03:00
|
|
|
output = UwacDisplayGetOutput(context->display, 0);
|
2017-11-06 16:02:22 +03:00
|
|
|
|
2020-05-05 11:31:26 +03:00
|
|
|
if ((output != NULL) && (UwacOutputGetResolution(output, &resolution) == UWAC_SUCCESS))
|
2017-08-17 20:33:44 +03:00
|
|
|
{
|
2023-10-13 10:48:44 +03:00
|
|
|
if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth,
|
|
|
|
(UINT32)resolution.width))
|
|
|
|
return FALSE;
|
|
|
|
if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight,
|
|
|
|
(UINT32)resolution.height))
|
|
|
|
return FALSE;
|
2017-08-17 20:33:44 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "Failed to get output resolution! Check your display settings");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-13 13:43:16 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-04-20 17:20:16 +03:00
|
|
|
static BOOL wl_post_connect(freerdp* instance)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
2017-11-16 14:42:33 +03:00
|
|
|
if (!instance || !instance->context)
|
|
|
|
return FALSE;
|
|
|
|
|
2024-04-06 08:24:34 +03:00
|
|
|
wlfContext* context = (wlfContext*)instance->context;
|
|
|
|
WINPR_ASSERT(context);
|
2019-02-08 14:49:32 +03:00
|
|
|
|
2024-04-06 08:24:34 +03:00
|
|
|
rdpSettings* settings = instance->context->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
|
|
|
const char* title = "FreeRDP";
|
2023-10-13 10:48:44 +03:00
|
|
|
const char* wtitle = freerdp_settings_get_string(settings, FreeRDP_WindowTitle);
|
|
|
|
if (wtitle)
|
|
|
|
title = wtitle;
|
2020-04-14 12:47:42 +03:00
|
|
|
|
2024-04-06 08:24:34 +03:00
|
|
|
const char* app_id = "wlfreerdp";
|
|
|
|
const char* wmclass = freerdp_settings_get_string(settings, FreeRDP_WmClass);
|
|
|
|
if (wmclass)
|
|
|
|
app_id = wmclass;
|
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
if (!gdi_init(instance, PIXEL_FORMAT_BGRA32))
|
2015-05-08 22:39:23 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2024-04-06 08:24:34 +03:00
|
|
|
rdpGdi* gdi = instance->context->gdi;
|
2016-08-03 19:44:26 +03:00
|
|
|
|
2019-01-24 13:19:20 +03:00
|
|
|
if (!gdi || (gdi->width < 0) || (gdi->height < 0))
|
2015-04-20 17:20:16 +03:00
|
|
|
return FALSE;
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2019-01-25 15:05:51 +03:00
|
|
|
if (!wlf_register_pointer(instance->context->graphics))
|
|
|
|
return FALSE;
|
|
|
|
|
2024-04-06 08:24:34 +03:00
|
|
|
UINT32 w = (UINT32)gdi->width;
|
|
|
|
UINT32 h = (UINT32)gdi->height;
|
2019-02-19 16:12:25 +03:00
|
|
|
|
2023-10-13 10:48:44 +03:00
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_SmartSizing) && !context->fullscreen)
|
2019-02-08 14:49:32 +03:00
|
|
|
{
|
2023-10-13 10:48:44 +03:00
|
|
|
const UINT32 sw = freerdp_settings_get_uint32(settings, FreeRDP_SmartSizingWidth);
|
|
|
|
if (sw > 0)
|
|
|
|
w = sw;
|
2019-02-08 14:49:32 +03:00
|
|
|
|
2023-10-13 10:48:44 +03:00
|
|
|
const UINT32 sh = freerdp_settings_get_uint32(settings, FreeRDP_SmartSizingHeight);
|
|
|
|
if (sh > 0)
|
|
|
|
h = sh;
|
2019-02-08 14:49:32 +03:00
|
|
|
}
|
|
|
|
|
2024-04-06 08:24:34 +03:00
|
|
|
context->window = UwacCreateWindowShm(context->display, w, h, WL_SHM_FORMAT_XRGB8888);
|
2016-08-03 19:44:26 +03:00
|
|
|
|
2024-04-06 08:24:34 +03:00
|
|
|
if (!context->window)
|
2015-04-20 17:20:16 +03:00
|
|
|
return FALSE;
|
2014-11-17 18:36:28 +03:00
|
|
|
|
2023-10-13 10:48:44 +03:00
|
|
|
UwacWindowSetFullscreenState(
|
2024-04-06 08:24:34 +03:00
|
|
|
context->window, NULL,
|
|
|
|
freerdp_settings_get_bool(instance->context->settings, FreeRDP_Fullscreen));
|
|
|
|
UwacWindowSetTitle(context->window, title);
|
|
|
|
UwacWindowSetAppId(context->window, app_id);
|
2019-01-24 13:19:20 +03:00
|
|
|
UwacWindowSetOpaqueRegion(context->window, 0, 0, w, h);
|
2022-03-23 15:18:35 +03:00
|
|
|
instance->context->update->EndPaint = wl_end_paint;
|
|
|
|
instance->context->update->DesktopResize = wl_resize_display;
|
2023-10-13 10:48:44 +03:00
|
|
|
UINT32 KeyboardLayout =
|
|
|
|
freerdp_settings_get_uint32(instance->context->settings, FreeRDP_KeyboardLayout);
|
|
|
|
const char* KeyboardRemappingList =
|
|
|
|
freerdp_settings_get_string(instance->context->settings, FreeRDP_KeyboardRemappingList);
|
|
|
|
|
|
|
|
freerdp_keyboard_init_ex(KeyboardLayout, KeyboardRemappingList);
|
2018-12-18 14:30:31 +03:00
|
|
|
|
|
|
|
if (!(context->disp = wlf_disp_new(context)))
|
|
|
|
return FALSE;
|
|
|
|
|
2018-12-19 18:18:13 +03:00
|
|
|
context->clipboard = wlf_clipboard_new(context);
|
|
|
|
|
|
|
|
if (!context->clipboard)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-01-24 14:01:40 +03:00
|
|
|
return wl_refresh_display(context);
|
2014-10-13 13:43:16 +04:00
|
|
|
}
|
|
|
|
|
2015-04-20 17:20:16 +03:00
|
|
|
static void wl_post_disconnect(freerdp* instance)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
wlfContext* context = NULL;
|
2016-08-03 19:44:26 +03:00
|
|
|
|
2015-04-20 17:20:16 +03:00
|
|
|
if (!instance)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!instance->context)
|
|
|
|
return;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (wlfContext*)instance->context;
|
2016-01-07 01:56:05 +03:00
|
|
|
gdi_free(instance);
|
2018-12-19 18:18:13 +03:00
|
|
|
wlf_clipboard_free(context->clipboard);
|
2018-12-18 14:30:31 +03:00
|
|
|
wlf_disp_free(context->disp);
|
2016-08-03 19:44:26 +03:00
|
|
|
|
2016-01-07 01:56:05 +03:00
|
|
|
if (context->window)
|
|
|
|
UwacDestroyWindow(&context->window);
|
|
|
|
}
|
2015-04-20 17:20:16 +03:00
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
static BOOL handle_uwac_events(freerdp* instance, UwacDisplay* display)
|
|
|
|
{
|
2016-01-07 01:56:05 +03:00
|
|
|
UwacEvent event;
|
2024-01-23 18:49:54 +03:00
|
|
|
wlfContext* context = NULL;
|
2016-01-07 01:56:05 +03:00
|
|
|
|
|
|
|
if (UwacDisplayDispatch(display, 1) < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-01-18 16:38:51 +03:00
|
|
|
context = (wlfContext*)instance->context;
|
|
|
|
|
2016-01-07 01:56:05 +03:00
|
|
|
while (UwacHasEvent(display))
|
|
|
|
{
|
|
|
|
if (UwacNextEvent(display, &event) != UWAC_SUCCESS)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/*printf("UWAC event type %d\n", event.type);*/
|
2016-08-03 19:44:26 +03:00
|
|
|
switch (event.type)
|
|
|
|
{
|
2019-01-25 15:05:51 +03:00
|
|
|
case UWAC_EVENT_NEW_SEAT:
|
|
|
|
context->seat = event.seat_new.seat;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UWAC_EVENT_REMOVED_SEAT:
|
|
|
|
context->seat = NULL;
|
|
|
|
break;
|
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
case UWAC_EVENT_FRAME_DONE:
|
2022-01-11 10:45:49 +03:00
|
|
|
{
|
2020-06-18 09:42:24 +03:00
|
|
|
EnterCriticalSection(&context->critical);
|
2024-01-23 18:49:54 +03:00
|
|
|
UwacReturnCode r = UwacWindowSubmitBuffer(context->window, false);
|
2020-06-18 09:42:24 +03:00
|
|
|
LeaveCriticalSection(&context->critical);
|
2022-01-11 10:45:49 +03:00
|
|
|
if (r != UWAC_SUCCESS)
|
2019-01-25 13:47:15 +03:00
|
|
|
return FALSE;
|
2022-01-11 10:45:49 +03:00
|
|
|
}
|
2022-06-23 08:57:38 +03:00
|
|
|
break;
|
2016-08-03 19:44:26 +03:00
|
|
|
|
|
|
|
case UWAC_EVENT_POINTER_ENTER:
|
|
|
|
if (!wlf_handle_pointer_enter(instance, &event.mouse_enter_leave))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UWAC_EVENT_POINTER_MOTION:
|
|
|
|
if (!wlf_handle_pointer_motion(instance, &event.mouse_motion))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UWAC_EVENT_POINTER_BUTTONS:
|
|
|
|
if (!wlf_handle_pointer_buttons(instance, &event.mouse_button))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UWAC_EVENT_POINTER_AXIS:
|
2021-03-02 11:34:39 +03:00
|
|
|
if (!wlf_handle_pointer_axis(instance, &event.mouse_axis))
|
|
|
|
return FALSE;
|
2021-01-27 21:42:32 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UWAC_EVENT_POINTER_AXIS_DISCRETE:
|
2021-03-02 11:34:39 +03:00
|
|
|
if (!wlf_handle_pointer_axis_discrete(instance, &event.mouse_axis))
|
2016-08-03 19:44:26 +03:00
|
|
|
return FALSE;
|
2021-03-02 11:34:39 +03:00
|
|
|
break;
|
2016-08-03 19:44:26 +03:00
|
|
|
|
2021-03-02 11:34:39 +03:00
|
|
|
case UWAC_EVENT_POINTER_FRAME:
|
|
|
|
if (!wlf_handle_pointer_frame(instance, &event.mouse_frame))
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
case UWAC_EVENT_POINTER_SOURCE:
|
|
|
|
if (!wlf_handle_pointer_source(instance, &event.mouse_source))
|
|
|
|
return FALSE;
|
2016-08-03 19:44:26 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UWAC_EVENT_KEY:
|
|
|
|
if (!wlf_handle_key(instance, &event.key))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2020-03-25 18:52:30 +03:00
|
|
|
case UWAC_EVENT_TOUCH_UP:
|
2020-03-27 11:08:32 +03:00
|
|
|
if (!wlf_handle_touch_up(instance, &event.touchUp))
|
2020-03-25 18:52:30 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UWAC_EVENT_TOUCH_DOWN:
|
2020-03-27 11:08:32 +03:00
|
|
|
if (!wlf_handle_touch_down(instance, &event.touchDown))
|
2020-03-25 18:52:30 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UWAC_EVENT_TOUCH_MOTION:
|
2020-03-27 11:08:32 +03:00
|
|
|
if (!wlf_handle_touch_motion(instance, &event.touchMotion))
|
2020-03-25 18:52:30 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
case UWAC_EVENT_KEYBOARD_ENTER:
|
2023-10-13 10:48:44 +03:00
|
|
|
if (freerdp_settings_get_bool(instance->context->settings, FreeRDP_GrabKeyboard))
|
2019-01-22 15:46:46 +03:00
|
|
|
UwacSeatInhibitShortcuts(event.keyboard_enter_leave.seat, true);
|
2019-01-25 13:47:15 +03:00
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
if (!wlf_keyboard_enter(instance, &event.keyboard_enter_leave))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-02-04 15:24:49 +03:00
|
|
|
case UWAC_EVENT_KEYBOARD_MODIFIERS:
|
|
|
|
if (!wlf_keyboard_modifiers(instance, &event.keyboard_modifiers))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2019-01-18 16:38:51 +03:00
|
|
|
case UWAC_EVENT_CONFIGURE:
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!wlf_disp_handle_configure(context->disp, event.configure.width,
|
|
|
|
event.configure.height))
|
2018-12-18 14:30:31 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2019-01-18 16:38:51 +03:00
|
|
|
if (!wl_refresh_display(context))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2018-12-19 18:18:13 +03:00
|
|
|
case UWAC_EVENT_CLIPBOARD_AVAILABLE:
|
|
|
|
case UWAC_EVENT_CLIPBOARD_OFFER:
|
|
|
|
case UWAC_EVENT_CLIPBOARD_SELECT:
|
|
|
|
if (!wlf_cliprdr_handle_event(context->clipboard, &event.clipboard))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-01-30 16:38:03 +03:00
|
|
|
case UWAC_EVENT_CLOSE:
|
|
|
|
context->closed = TRUE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
default:
|
|
|
|
break;
|
2016-01-07 01:56:05 +03:00
|
|
|
}
|
|
|
|
}
|
2016-08-03 19:44:26 +03:00
|
|
|
|
2016-01-07 01:56:05 +03:00
|
|
|
return TRUE;
|
2015-04-20 17:20:16 +03:00
|
|
|
}
|
|
|
|
|
2019-02-19 16:12:25 +03:00
|
|
|
static BOOL handle_window_events(freerdp* instance)
|
|
|
|
{
|
2022-03-23 15:18:35 +03:00
|
|
|
if (!instance)
|
2019-02-19 16:12:25 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-04-22 12:05:29 +03:00
|
|
|
static int wlfreerdp_run(freerdp* instance)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
wlfContext* context = NULL;
|
2021-08-25 12:14:35 +03:00
|
|
|
HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
|
2017-11-16 14:42:33 +03:00
|
|
|
DWORD status = WAIT_ABANDONED;
|
2021-10-18 11:18:42 +03:00
|
|
|
HANDLE timer = NULL;
|
|
|
|
LARGE_INTEGER due;
|
|
|
|
|
|
|
|
TimerEventArgs timerEvent;
|
|
|
|
EventArgsInit(&timerEvent, "xfreerdp");
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
if (!instance)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
context = (wlfContext*)instance->context;
|
|
|
|
|
|
|
|
if (!context)
|
|
|
|
return -1;
|
|
|
|
|
2015-04-22 12:05:29 +03:00
|
|
|
if (!freerdp_connect(instance))
|
|
|
|
{
|
2018-12-18 14:30:31 +03:00
|
|
|
WLog_Print(context->log, WLOG_ERROR, "Failed to connect");
|
2016-04-05 18:07:45 +03:00
|
|
|
return -1;
|
2015-04-22 12:05:29 +03:00
|
|
|
}
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2021-10-18 11:18:42 +03:00
|
|
|
timer = CreateWaitableTimerA(NULL, FALSE, "mainloop-periodic-timer");
|
|
|
|
|
|
|
|
if (!timer)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "failed to create timer");
|
|
|
|
goto disconnect;
|
|
|
|
}
|
|
|
|
|
|
|
|
due.QuadPart = 0;
|
|
|
|
|
|
|
|
if (!SetWaitableTimer(timer, &due, 20, NULL, NULL, FALSE))
|
|
|
|
{
|
|
|
|
goto disconnect;
|
|
|
|
}
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
while (!freerdp_shall_disconnect_context(instance->context))
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
2021-10-18 11:18:42 +03:00
|
|
|
DWORD count = 0;
|
|
|
|
handles[count++] = timer;
|
|
|
|
handles[count++] = context->displayHandle;
|
|
|
|
count += freerdp_get_event_handles(instance->context, &handles[count],
|
|
|
|
ARRAYSIZE(handles) - count);
|
2016-08-03 19:44:26 +03:00
|
|
|
|
2021-10-18 11:18:42 +03:00
|
|
|
if (count <= 2)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
2018-12-18 14:30:31 +03:00
|
|
|
WLog_Print(context->log, WLOG_ERROR, "Failed to get FreeRDP file descriptor");
|
2014-10-13 13:43:16 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-11-16 14:42:33 +03:00
|
|
|
status = WaitForMultipleObjects(count, handles, FALSE, INFINITE);
|
2016-08-03 19:44:26 +03:00
|
|
|
|
2015-04-22 12:05:29 +03:00
|
|
|
if (WAIT_FAILED == status)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_Print(context->log, WLOG_ERROR, "WaitForMultipleObjects failed");
|
2014-10-13 13:43:16 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
if (!handle_uwac_events(instance, context->display))
|
|
|
|
{
|
2018-12-18 14:30:31 +03:00
|
|
|
WLog_Print(context->log, WLOG_ERROR, "error handling UWAC events");
|
2014-10-13 13:43:16 +04:00
|
|
|
break;
|
|
|
|
}
|
2016-01-07 01:56:05 +03:00
|
|
|
|
2021-01-30 16:38:03 +03:00
|
|
|
if (context->closed)
|
|
|
|
{
|
|
|
|
WLog_Print(context->log, WLOG_INFO, "Closed from Wayland");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (freerdp_check_event_handles(instance->context) != TRUE)
|
|
|
|
{
|
2019-02-19 16:12:25 +03:00
|
|
|
if (client_auto_reconnect_ex(instance, handle_window_events))
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
2019-11-06 17:24:51 +03:00
|
|
|
* Indicate an unsuccessful connection attempt if reconnect
|
|
|
|
* did not succeed and no other error was specified.
|
|
|
|
*/
|
2019-02-19 16:12:25 +03:00
|
|
|
if (freerdp_error_info(instance) == 0)
|
|
|
|
status = 42;
|
|
|
|
}
|
|
|
|
|
2017-11-06 16:02:22 +03:00
|
|
|
if (freerdp_get_last_error(instance->context) == FREERDP_ERROR_SUCCESS)
|
2018-12-18 14:30:31 +03:00
|
|
|
WLog_Print(context->log, WLOG_ERROR, "Failed to check FreeRDP file descriptor");
|
2017-11-06 16:02:22 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
break;
|
|
|
|
}
|
2021-10-18 11:18:42 +03:00
|
|
|
|
|
|
|
if ((status != WAIT_TIMEOUT) && (status == WAIT_OBJECT_0))
|
|
|
|
{
|
|
|
|
timerEvent.now = GetTickCount64();
|
2022-01-19 11:27:39 +03:00
|
|
|
PubSub_OnTimer(context->common.context.pubSub, context, &timerEvent);
|
2021-10-18 11:18:42 +03:00
|
|
|
}
|
2014-10-13 13:43:16 +04:00
|
|
|
}
|
|
|
|
|
2021-10-18 11:18:42 +03:00
|
|
|
disconnect:
|
|
|
|
if (timer)
|
2024-09-16 05:58:36 +03:00
|
|
|
(void)CloseHandle(timer);
|
2015-01-20 13:24:36 +03:00
|
|
|
freerdp_disconnect(instance);
|
2017-11-16 14:42:33 +03:00
|
|
|
return status;
|
2014-10-13 13:43:16 +04:00
|
|
|
}
|
|
|
|
|
2017-11-16 14:42:33 +03:00
|
|
|
static BOOL wlf_client_global_init(void)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
2024-08-26 16:39:33 +03:00
|
|
|
(void)setlocale(LC_ALL, "");
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
if (freerdp_handle_signals() != 0)
|
|
|
|
return FALSE;
|
2016-01-07 01:56:05 +03:00
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
2016-01-07 01:56:05 +03:00
|
|
|
|
2017-11-16 14:42:33 +03:00
|
|
|
static void wlf_client_global_uninit(void)
|
2016-08-03 19:44:26 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-11-16 14:42:33 +03:00
|
|
|
static int wlf_logon_error_info(freerdp* instance, UINT32 data, UINT32 type)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
wlfContext* wlf = NULL;
|
2017-11-16 14:42:33 +03:00
|
|
|
const char* str_data = freerdp_get_logon_error_info_data(data);
|
|
|
|
const char* str_type = freerdp_get_logon_error_info_type(type);
|
|
|
|
|
|
|
|
if (!instance || !instance->context)
|
|
|
|
return -1;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
wlf = (wlfContext*)instance->context;
|
|
|
|
WLog_Print(wlf->log, WLOG_INFO, "Logon Error Info %s [%s]", str_data, str_type);
|
2017-11-16 14:42:33 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-03-02 11:34:39 +03:00
|
|
|
static void wlf_client_free(freerdp* instance, rdpContext* context)
|
|
|
|
{
|
|
|
|
wlfContext* wlf = (wlfContext*)instance->context;
|
|
|
|
|
|
|
|
if (!context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (wlf->display)
|
|
|
|
UwacCloseDisplay(&wlf->display);
|
|
|
|
|
|
|
|
if (wlf->displayHandle)
|
2024-09-16 05:58:36 +03:00
|
|
|
(void)CloseHandle(wlf->displayHandle);
|
2021-03-02 11:34:39 +03:00
|
|
|
ArrayList_Free(wlf->events);
|
|
|
|
DeleteCriticalSection(&wlf->critical);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void* uwac_event_clone(const void* val)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UwacEvent* copy = NULL;
|
2021-08-02 13:13:34 +03:00
|
|
|
const UwacEvent* ev = (const UwacEvent*)val;
|
2021-03-02 11:34:39 +03:00
|
|
|
|
|
|
|
copy = calloc(1, sizeof(UwacEvent));
|
|
|
|
if (!copy)
|
|
|
|
return NULL;
|
|
|
|
*copy = *ev;
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
static BOOL wlf_client_new(freerdp* instance, rdpContext* context)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
wObject* obj = NULL;
|
|
|
|
UwacReturnCode status = UWAC_ERROR_INTERNAL;
|
2019-11-06 17:24:51 +03:00
|
|
|
wlfContext* wfl = (wlfContext*)context;
|
2016-08-03 19:44:26 +03:00
|
|
|
|
|
|
|
if (!instance || !context)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-10-13 13:43:16 +04:00
|
|
|
instance->PreConnect = wl_pre_connect;
|
|
|
|
instance->PostConnect = wl_post_connect;
|
2015-04-20 17:20:16 +03:00
|
|
|
instance->PostDisconnect = wl_post_disconnect;
|
2017-11-16 14:42:33 +03:00
|
|
|
instance->LogonErrorInfo = wlf_logon_error_info;
|
2018-12-18 14:30:31 +03:00
|
|
|
wfl->log = WLog_Get(TAG);
|
2016-08-03 19:44:26 +03:00
|
|
|
wfl->display = UwacOpenDisplay(NULL, &status);
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2018-12-18 14:30:31 +03:00
|
|
|
if (!wfl->display || (status != UWAC_SUCCESS) || !wfl->log)
|
2016-08-03 19:44:26 +03:00
|
|
|
return FALSE;
|
2015-04-20 17:20:16 +03:00
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
wfl->displayHandle = CreateFileDescriptorEvent(NULL, FALSE, FALSE,
|
2019-11-06 17:24:51 +03:00
|
|
|
UwacDisplayGetFd(wfl->display), WINPR_FD_READ);
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
if (!wfl->displayHandle)
|
|
|
|
return FALSE;
|
2014-10-16 17:44:48 +04:00
|
|
|
|
2021-03-02 11:34:39 +03:00
|
|
|
wfl->events = ArrayList_New(FALSE);
|
|
|
|
if (!wfl->events)
|
|
|
|
return FALSE;
|
2016-08-03 19:44:26 +03:00
|
|
|
|
2021-03-02 11:34:39 +03:00
|
|
|
obj = ArrayList_Object(wfl->events);
|
|
|
|
obj->fnObjectNew = uwac_event_clone;
|
|
|
|
obj->fnObjectFree = free;
|
2016-08-03 19:44:26 +03:00
|
|
|
|
2021-03-02 11:34:39 +03:00
|
|
|
InitializeCriticalSection(&wfl->critical);
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2021-03-02 11:34:39 +03:00
|
|
|
return TRUE;
|
2016-08-03 19:44:26 +03:00
|
|
|
}
|
2015-04-20 17:20:16 +03:00
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
static int wfl_client_start(rdpContext* context)
|
|
|
|
{
|
2019-01-24 13:19:20 +03:00
|
|
|
WINPR_UNUSED(context);
|
2016-08-03 19:44:26 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2015-04-20 17:20:16 +03:00
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
|
|
|
|
{
|
2022-10-13 17:25:36 +03:00
|
|
|
WINPR_ASSERT(pEntryPoints);
|
2016-08-03 19:44:26 +03:00
|
|
|
ZeroMemory(pEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS));
|
|
|
|
pEntryPoints->Version = RDP_CLIENT_INTERFACE_VERSION;
|
|
|
|
pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
|
|
|
|
pEntryPoints->GlobalInit = wlf_client_global_init;
|
|
|
|
pEntryPoints->GlobalUninit = wlf_client_global_uninit;
|
|
|
|
pEntryPoints->ContextSize = sizeof(wlfContext);
|
|
|
|
pEntryPoints->ClientNew = wlf_client_new;
|
|
|
|
pEntryPoints->ClientFree = wlf_client_free;
|
|
|
|
pEntryPoints->ClientStart = wfl_client_start;
|
2022-01-19 14:11:48 +03:00
|
|
|
pEntryPoints->ClientStop = freerdp_client_common_stop;
|
2016-08-03 19:44:26 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
int rc = -1;
|
2024-01-23 18:49:54 +03:00
|
|
|
int status = 0;
|
2016-08-03 19:44:26 +03:00
|
|
|
RDP_CLIENT_ENTRY_POINTS clientEntryPoints;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpContext* context = NULL;
|
|
|
|
rdpSettings* settings = NULL;
|
|
|
|
wlfContext* wlc = NULL;
|
2020-04-18 00:29:29 +03:00
|
|
|
|
2023-03-01 10:34:52 +03:00
|
|
|
freerdp_client_warn_deprecated(argc, argv);
|
|
|
|
|
2016-08-03 19:44:26 +03:00
|
|
|
RdpClientEntry(&clientEntryPoints);
|
|
|
|
context = freerdp_client_context_new(&clientEntryPoints);
|
|
|
|
if (!context)
|
|
|
|
goto fail;
|
2020-04-18 00:29:29 +03:00
|
|
|
wlc = (wlfContext*)context;
|
|
|
|
settings = context->settings;
|
2016-08-03 19:44:26 +03:00
|
|
|
|
2020-04-18 00:29:29 +03:00
|
|
|
status = freerdp_client_settings_parse_command_line(settings, argc, argv, FALSE);
|
2016-08-03 19:44:26 +03:00
|
|
|
if (status)
|
2020-04-18 00:29:29 +03:00
|
|
|
{
|
2021-01-22 11:44:55 +03:00
|
|
|
rc = freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
|
2021-02-25 01:44:28 +03:00
|
|
|
|
2023-10-13 10:48:44 +03:00
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_ListMonitors))
|
2020-04-18 00:29:29 +03:00
|
|
|
wlf_list_monitors(wlc);
|
|
|
|
|
2021-01-22 11:44:55 +03:00
|
|
|
goto fail;
|
2020-04-18 00:29:29 +03:00
|
|
|
}
|
2016-08-03 19:44:26 +03:00
|
|
|
|
|
|
|
if (freerdp_client_start(context) != 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
rc = wlfreerdp_run(context->instance);
|
|
|
|
|
|
|
|
if (freerdp_client_stop(context) != 0)
|
|
|
|
rc = -1;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
freerdp_client_context_free(context);
|
|
|
|
return rc;
|
|
|
|
}
|
2019-01-25 13:47:15 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL wlf_copy_image(const void* src, size_t srcStride, size_t srcWidth, size_t srcHeight, void* dst,
|
|
|
|
size_t dstStride, size_t dstWidth, size_t dstHeight, const RECTANGLE_16* area,
|
|
|
|
BOOL scale)
|
2019-01-25 13:47:15 +03:00
|
|
|
{
|
|
|
|
BOOL rc = FALSE;
|
|
|
|
|
|
|
|
if (!src || !dst || !area)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (scale)
|
|
|
|
{
|
2019-05-06 14:18:31 +03:00
|
|
|
return freerdp_image_scale(dst, PIXEL_FORMAT_BGRA32, dstStride, 0, 0, dstWidth, dstHeight,
|
|
|
|
src, PIXEL_FORMAT_BGRA32, srcStride, 0, 0, srcWidth, srcHeight);
|
2019-01-25 13:47:15 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-08-26 17:33:59 +03:00
|
|
|
const size_t baseSrcOffset = 1ULL * area->top * srcStride + 4ULL * area->left;
|
|
|
|
const size_t baseDstOffset = 1ULL * area->top * dstStride + 4ULL * area->left;
|
2019-02-07 16:39:15 +03:00
|
|
|
const size_t width = MIN((size_t)area->right - area->left, dstWidth - area->left);
|
|
|
|
const size_t height = MIN((size_t)area->bottom - area->top, dstHeight - area->top);
|
2019-01-25 13:47:15 +03:00
|
|
|
const BYTE* psrc = (const BYTE*)src;
|
|
|
|
BYTE* pdst = (BYTE*)dst;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t i = 0; i < height; i++)
|
2019-01-25 13:47:15 +03:00
|
|
|
{
|
|
|
|
const size_t srcOffset = i * srcStride + baseSrcOffset;
|
|
|
|
const size_t dstOffset = i * dstStride + baseDstOffset;
|
|
|
|
memcpy(&pdst[dstOffset], &psrc[srcOffset], width * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2019-01-29 15:14:45 +03:00
|
|
|
BOOL wlf_scale_coordinates(rdpContext* context, UINT32* px, UINT32* py, BOOL fromLocalToRDP)
|
2019-01-25 13:47:15 +03:00
|
|
|
{
|
|
|
|
wlfContext* wlf = (wlfContext*)context;
|
2024-09-02 15:57:55 +03:00
|
|
|
UwacSize geometry = { 0 };
|
2019-01-25 13:47:15 +03:00
|
|
|
|
|
|
|
if (!context || !px || !py || !context->gdi)
|
|
|
|
return FALSE;
|
|
|
|
|
2023-10-13 10:48:44 +03:00
|
|
|
if (!freerdp_settings_get_bool(context->settings, FreeRDP_SmartSizing))
|
2019-01-25 13:47:15 +03:00
|
|
|
return TRUE;
|
|
|
|
|
2024-09-02 15:57:55 +03:00
|
|
|
rdpGdi* gdi = context->gdi;
|
2019-01-25 13:47:15 +03:00
|
|
|
|
|
|
|
if (UwacWindowGetDrawingBufferGeometry(wlf->window, &geometry, NULL) != UWAC_SUCCESS)
|
|
|
|
return FALSE;
|
|
|
|
|
2024-09-02 15:57:55 +03:00
|
|
|
const double sx = 1.0 * geometry.width / (double)gdi->width;
|
|
|
|
const double sy = 1.0 * geometry.height / (double)gdi->height;
|
2019-01-29 15:14:45 +03:00
|
|
|
|
|
|
|
if (!fromLocalToRDP)
|
|
|
|
{
|
2024-09-02 15:57:55 +03:00
|
|
|
*px *= (UINT32)lround(sx);
|
|
|
|
*py *= (UINT32)lround(sy);
|
2019-01-29 15:14:45 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-09-02 15:57:55 +03:00
|
|
|
*px /= (UINT32)lround(sx);
|
|
|
|
*py /= (UINT32)lround(sy);
|
2019-01-29 15:14:45 +03:00
|
|
|
}
|
|
|
|
|
2019-01-25 13:47:15 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|