FreeRDP/client/Wayland/wlf_pointer.c

168 lines
3.9 KiB
C
Raw Normal View History

2019-01-25 15:05:51 +03:00
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Wayland Mouse Pointer
*
* Copyright 2019 Armin Novak <armin.novak@thincast.com>
* Copyright 2019 Thincast Technologies GmbH
*
* 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>
2019-01-25 15:05:51 +03:00
#include "wlf_pointer.h"
#include "wlfreerdp.h"
#define TAG CLIENT_TAG("wayland.pointer")
typedef struct
2019-01-25 15:05:51 +03:00
{
rdpPointer pointer;
size_t size;
void* data;
} wlfPointer;
2019-01-25 15:05:51 +03:00
static BOOL wlf_Pointer_New(rdpContext* context, rdpPointer* pointer)
{
wlfPointer* ptr = (wlfPointer*)pointer;
2019-01-29 15:14:45 +03:00
2019-01-25 15:05:51 +03:00
if (!ptr)
return FALSE;
ptr->size = 4ULL * pointer->width * pointer->height;
ptr->data = winpr_aligned_malloc(ptr->size, 16);
2019-01-29 15:14:45 +03:00
2019-01-25 15:05:51 +03:00
if (!ptr->data)
return FALSE;
if (!freerdp_image_copy_from_pointer_data(
2019-11-06 17:24:51 +03:00
ptr->data, PIXEL_FORMAT_BGRA32, 0, 0, 0, pointer->width, pointer->height,
pointer->xorMaskData, pointer->lengthXorMask, pointer->andMaskData,
pointer->lengthAndMask, pointer->xorBpp, &context->gdi->palette))
2019-01-25 15:05:51 +03:00
{
winpr_aligned_free(ptr->data);
2019-01-25 15:05:51 +03:00
return FALSE;
}
return TRUE;
}
static void wlf_Pointer_Free(rdpContext* context, rdpPointer* pointer)
{
wlfPointer* ptr = (wlfPointer*)pointer;
WINPR_UNUSED(context);
2019-01-29 15:14:45 +03:00
2019-01-25 15:05:51 +03:00
if (ptr)
winpr_aligned_free(ptr->data);
2019-01-25 15:05:51 +03:00
}
static BOOL wlf_Pointer_Set(rdpContext* context, rdpPointer* pointer)
2019-01-25 15:05:51 +03:00
{
wlfContext* wlf = (wlfContext*)context;
wlfPointer* ptr = (wlfPointer*)pointer;
void* data = NULL;
UINT32 w = 0;
UINT32 h = 0;
UINT32 x = 0;
UINT32 y = 0;
size_t size = 0;
UwacReturnCode rc = UWAC_ERROR_INTERNAL;
2019-01-29 15:14:45 +03:00
BOOL res = FALSE;
RECTANGLE_16 area;
2019-01-25 15:05:51 +03:00
if (!wlf || !wlf->seat)
return FALSE;
2019-01-29 15:14:45 +03:00
x = pointer->xPos;
y = pointer->yPos;
w = pointer->width;
h = pointer->height;
if (!wlf_scale_coordinates(context, &x, &y, FALSE) ||
!wlf_scale_coordinates(context, &w, &h, FALSE))
2019-01-25 15:05:51 +03:00
return FALSE;
size = 4ULL * w * h;
2019-01-29 15:14:45 +03:00
data = malloc(size);
if (!data)
return FALSE;
area.top = 0;
area.left = 0;
area.right = (UINT16)pointer->width;
area.bottom = (UINT16)pointer->height;
if (!wlf_copy_image(ptr->data, 4ULL * pointer->width, pointer->width, pointer->height, data,
4ULL * w, w, h, &area,
2023-10-13 10:48:44 +03:00
freerdp_settings_get_bool(context->settings, FreeRDP_SmartSizing)))
2019-01-29 15:14:45 +03:00
goto fail;
rc = UwacSeatSetMouseCursor(wlf->seat, data, size, w, h, x, y);
if (rc == UWAC_SUCCESS)
res = TRUE;
fail:
free(data);
return res;
2019-01-25 15:05:51 +03:00
}
static BOOL wlf_Pointer_SetNull(rdpContext* context)
{
wlfContext* wlf = (wlfContext*)context;
2019-01-29 15:14:45 +03:00
2019-01-25 15:05:51 +03:00
if (!wlf || !wlf->seat)
return FALSE;
if (UwacSeatSetMouseCursor(wlf->seat, NULL, 0, 0, 0, 0, 0) != UWAC_SUCCESS)
return FALSE;
return TRUE;
}
static BOOL wlf_Pointer_SetDefault(rdpContext* context)
{
wlfContext* wlf = (wlfContext*)context;
2019-01-29 15:14:45 +03:00
2019-01-25 15:05:51 +03:00
if (!wlf || !wlf->seat)
return FALSE;
if (UwacSeatSetMouseCursor(wlf->seat, NULL, 1, 0, 0, 0, 0) != UWAC_SUCCESS)
return FALSE;
return TRUE;
}
static BOOL wlf_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y)
{
// TODO
WLog_WARN(TAG, "not implemented");
2019-01-25 15:05:51 +03:00
return TRUE;
}
BOOL wlf_register_pointer(rdpGraphics* graphics)
{
2023-06-26 16:39:27 +03:00
rdpPointer pointer = { 0 };
pointer.size = sizeof(wlfPointer);
pointer.New = wlf_Pointer_New;
pointer.Free = wlf_Pointer_Free;
pointer.Set = wlf_Pointer_Set;
pointer.SetNull = wlf_Pointer_SetNull;
pointer.SetDefault = wlf_Pointer_SetDefault;
pointer.SetPosition = wlf_Pointer_SetPosition;
graphics_register_pointer(graphics, &pointer);
2019-01-25 15:05:51 +03:00
return TRUE;
}