FreeRDP
wlf_pointer.c
1 
21 #include <freerdp/config.h>
22 
23 #include "wlf_pointer.h"
24 #include "wlfreerdp.h"
25 
26 #define TAG CLIENT_TAG("wayland.pointer")
27 
28 typedef struct
29 {
30  rdpPointer pointer;
31  size_t size;
32  void* data;
33 } wlfPointer;
34 
35 static BOOL wlf_Pointer_New(rdpContext* context, rdpPointer* pointer)
36 {
37  wlfPointer* ptr = (wlfPointer*)pointer;
38 
39  if (!ptr)
40  return FALSE;
41 
42  ptr->size = 4ULL * pointer->width * pointer->height;
43  ptr->data = winpr_aligned_malloc(ptr->size, 16);
44 
45  if (!ptr->data)
46  return FALSE;
47 
48  if (!freerdp_image_copy_from_pointer_data(
49  ptr->data, PIXEL_FORMAT_BGRA32, 0, 0, 0, pointer->width, pointer->height,
50  pointer->xorMaskData, pointer->lengthXorMask, pointer->andMaskData,
51  pointer->lengthAndMask, pointer->xorBpp, &context->gdi->palette))
52  {
53  winpr_aligned_free(ptr->data);
54  return FALSE;
55  }
56 
57  return TRUE;
58 }
59 
60 static void wlf_Pointer_Free(rdpContext* context, rdpPointer* pointer)
61 {
62  wlfPointer* ptr = (wlfPointer*)pointer;
63  WINPR_UNUSED(context);
64 
65  if (ptr)
66  winpr_aligned_free(ptr->data);
67 }
68 
69 static BOOL wlf_Pointer_Set(rdpContext* context, rdpPointer* pointer)
70 {
71  wlfContext* wlf = (wlfContext*)context;
72  wlfPointer* ptr = (wlfPointer*)pointer;
73  void* data = NULL;
74  UINT32 w = 0;
75  UINT32 h = 0;
76  UINT32 x = 0;
77  UINT32 y = 0;
78  size_t size = 0;
79  UwacReturnCode rc = UWAC_ERROR_INTERNAL;
80  BOOL res = FALSE;
81  RECTANGLE_16 area;
82 
83  if (!wlf || !wlf->seat)
84  return FALSE;
85 
86  x = pointer->xPos;
87  y = pointer->yPos;
88  w = pointer->width;
89  h = pointer->height;
90 
91  if (!wlf_scale_coordinates(context, &x, &y, FALSE) ||
92  !wlf_scale_coordinates(context, &w, &h, FALSE))
93  return FALSE;
94 
95  size = 4ULL * w * h;
96  data = malloc(size);
97 
98  if (!data)
99  return FALSE;
100 
101  area.top = 0;
102  area.left = 0;
103  area.right = (UINT16)pointer->width;
104  area.bottom = (UINT16)pointer->height;
105 
106  if (!wlf_copy_image(ptr->data, 4ULL * pointer->width, pointer->width, pointer->height, data,
107  4ULL * w, w, h, &area,
108  freerdp_settings_get_bool(context->settings, FreeRDP_SmartSizing)))
109  goto fail;
110 
111  rc = UwacSeatSetMouseCursor(wlf->seat, data, size, w, h, x, y);
112 
113  if (rc == UWAC_SUCCESS)
114  res = TRUE;
115 
116 fail:
117  free(data);
118  return res;
119 }
120 
121 static BOOL wlf_Pointer_SetNull(rdpContext* context)
122 {
123  wlfContext* wlf = (wlfContext*)context;
124 
125  if (!wlf || !wlf->seat)
126  return FALSE;
127 
128  if (UwacSeatSetMouseCursor(wlf->seat, NULL, 0, 0, 0, 0, 0) != UWAC_SUCCESS)
129  return FALSE;
130 
131  return TRUE;
132 }
133 
134 static BOOL wlf_Pointer_SetDefault(rdpContext* context)
135 {
136  wlfContext* wlf = (wlfContext*)context;
137 
138  if (!wlf || !wlf->seat)
139  return FALSE;
140 
141  if (UwacSeatSetMouseCursor(wlf->seat, NULL, 1, 0, 0, 0, 0) != UWAC_SUCCESS)
142  return FALSE;
143 
144  return TRUE;
145 }
146 
147 static BOOL wlf_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y)
148 {
149  // TODO
150  WLog_WARN(TAG, "not implemented");
151  return TRUE;
152 }
153 
154 BOOL wlf_register_pointer(rdpGraphics* graphics)
155 {
156  rdpPointer pointer = { 0 };
157 
158  pointer.size = sizeof(wlfPointer);
159  pointer.New = wlf_Pointer_New;
160  pointer.Free = wlf_Pointer_Free;
161  pointer.Set = wlf_Pointer_Set;
162  pointer.SetNull = wlf_Pointer_SetNull;
163  pointer.SetDefault = wlf_Pointer_SetDefault;
164  pointer.SetPosition = wlf_Pointer_SetPosition;
165  graphics_register_pointer(graphics, &pointer);
166  return TRUE;
167 }
FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.