2 * FreeRDP: A Remote Desktop Protocol Client
5 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 #include <X11/Xutil.h>
23 #include <freerdp/utils/event.h>
24 #include <freerdp/utils/hexdump.h>
25 #include <freerdp/utils/rail.h>
26 #include <freerdp/rail/rail.h>
28 #include "xf_window.h"
31 void xf_rail_paint(xfInfo* xfi, rdpRail* rail, uint32 uleft, uint32 utop, uint32 uright, uint32 ubottom)
36 uint32 iwidth, iheight;
37 uint32 ileft, itop, iright, ibottom;
38 uint32 wleft, wtop, wright, wbottom;
40 window_list_rewind(rail->list);
42 while (window_list_has_next(rail->list))
44 window = window_list_get_next(rail->list);
45 xfw = (xfWindow*) window->extra;
47 wleft = window->windowOffsetX;
48 wtop = window->windowOffsetY;
49 wright = window->windowOffsetX + window->windowWidth - 1;
50 wbottom = window->windowOffsetY + window->windowHeight - 1;
52 ileft = MAX(uleft, wleft);
53 itop = MAX(utop, wtop);
54 iright = MIN(uright, wright);
55 ibottom = MIN(ubottom, wbottom);
57 iwidth = iright - ileft + 1;
58 iheight = ibottom - itop + 1;
60 intersect = ((iright > ileft) && (ibottom > itop)) ? true : false;
64 xf_UpdateWindowArea(xfi, xfw, ileft - wleft, itop - wtop, iwidth, iheight);
69 void xf_rail_CreateWindow(rdpRail* rail, rdpWindow* window)
74 xfi = (xfInfo*) rail->extra;
76 xfw = xf_CreateWindow((xfInfo*) rail->extra, window,
77 window->windowOffsetX, window->windowOffsetY,
78 window->windowWidth, window->windowHeight,
81 xf_SetWindowStyle(xfi, xfw, window->style, window->extendedStyle);
83 XStoreName(xfi->display, xfw->handle, window->title);
85 window->extra = (void*) xfw;
86 window->extraId = (void*) xfw->handle;
89 void xf_rail_MoveWindow(rdpRail* rail, rdpWindow* window)
94 xfi = (xfInfo*) rail->extra;
95 xfw = (xfWindow*) window->extra;
97 // Do nothing if window is already in the correct position
98 if ( xfw->left == window->windowOffsetX &&
99 xfw->top == window->windowOffsetY &&
100 xfw->width == window->windowWidth &&
101 xfw->height == window->windowHeight)
106 xf_MoveWindow((xfInfo*) rail->extra, xfw,
107 window->windowOffsetX, window->windowOffsetY,
108 window->windowWidth, window->windowHeight);
111 void xf_rail_ShowWindow(rdpRail* rail, rdpWindow* window, uint8 state)
116 xfi = (xfInfo*) rail->extra;
117 xfw = (xfWindow*) window->extra;
119 xf_ShowWindow((xfInfo*) rail->extra, xfw, state);
122 void xf_rail_SetWindowText(rdpRail* rail, rdpWindow* window)
127 xfi = (xfInfo*) rail->extra;
128 xfw = (xfWindow*) window->extra;
130 XStoreName(xfi->display, xfw->handle, window->title);
133 void xf_rail_SetWindowIcon(rdpRail* rail, rdpWindow* window, rdpIcon* icon)
138 xfi = (xfInfo*) rail->extra;
139 xfw = (xfWindow*) window->extra;
141 icon->extra = freerdp_icon_convert(icon->entry->bitsColor, NULL, icon->entry->bitsMask,
142 icon->entry->width, icon->entry->height, icon->entry->bpp, rail->clrconv);
144 xf_SetWindowIcon(xfi, xfw, icon);
147 void xf_rail_SetWindowRects(rdpRail* rail, rdpWindow* window)
152 xfi = (xfInfo*) rail->extra;
153 xfw = (xfWindow*) window->extra;
155 xf_SetWindowRects(xfi, xfw, window->windowRects, window->numWindowRects);
158 void xf_rail_SetWindowVisibilityRects(rdpRail* rail, rdpWindow* window)
163 xfi = (xfInfo*) rail->extra;
164 xfw = (xfWindow*) window->extra;
166 xf_SetWindowVisibilityRects(xfi, xfw, window->windowRects, window->numWindowRects);
169 void xf_rail_DestroyWindow(rdpRail* rail, rdpWindow* window)
172 xfw = (xfWindow*) window->extra;
173 xf_DestroyWindow((xfInfo*) rail->extra, xfw);
176 void xf_rail_register_callbacks(xfInfo* xfi, rdpRail* rail)
178 rail->extra = (void*) xfi;
179 rail->rail_CreateWindow = xf_rail_CreateWindow;
180 rail->rail_MoveWindow = xf_rail_MoveWindow;
181 rail->rail_ShowWindow = xf_rail_ShowWindow;
182 rail->rail_SetWindowText = xf_rail_SetWindowText;
183 rail->rail_SetWindowIcon = xf_rail_SetWindowIcon;
184 rail->rail_SetWindowRects = xf_rail_SetWindowRects;
185 rail->rail_SetWindowVisibilityRects = xf_rail_SetWindowVisibilityRects;
186 rail->rail_DestroyWindow = xf_rail_DestroyWindow;
189 static void xf_on_free_rail_client_event(RDP_EVENT* event)
191 if (event->event_class == RDP_EVENT_CLASS_RAIL)
193 rail_free_cloned_order(event->event_type, event->user_data);
197 static void xf_send_rail_client_event(rdpChannels* channels, uint16 event_type, void* param)
199 RDP_EVENT* out_event = NULL;
200 void * payload = NULL;
202 payload = rail_clone_order(event_type, param);
205 out_event = freerdp_event_new(RDP_EVENT_CLASS_RAIL, event_type,
206 xf_on_free_rail_client_event, payload);
207 freerdp_channels_send_event(channels, out_event);
211 void xf_rail_send_windowmove(xfInfo* xfi, uint32 windowId, uint32 left, uint32 top, uint32 right, uint32 bottom)
213 rdpChannels* channels;
214 RAIL_WINDOW_MOVE_ORDER window_move;
216 channels = xfi->_context->channels;
218 window_move.windowId = windowId;
219 window_move.left = left;
220 window_move.top = top;
221 window_move.right = right;
222 window_move.bottom = bottom;
224 xf_send_rail_client_event(channels, RDP_EVENT_TYPE_RAIL_CLIENT_WINDOW_MOVE, &window_move);
227 void xf_rail_send_activate(xfInfo* xfi, Window xwindow, boolean enabled)
230 rdpChannels* channels;
231 rdpWindow* rail_window;
232 RAIL_ACTIVATE_ORDER activate;
234 rail = xfi->_context->rail;
235 channels = xfi->_context->channels;
237 rail_window = window_list_get_by_extra_id(rail->list, (void*) xwindow);
239 if (rail_window == NULL)
242 activate.windowId = rail_window->windowId;
243 activate.enabled = enabled;
245 xf_send_rail_client_event(channels, RDP_EVENT_TYPE_RAIL_CLIENT_ACTIVATE, &activate);
248 void xf_rail_send_client_system_command(xfInfo* xfi, uint32 windowId, uint16 command)
250 rdpChannels* channels;
251 RAIL_SYSCOMMAND_ORDER syscommand;
253 channels = xfi->_context->channels;
255 syscommand.windowId = windowId;
256 syscommand.command = command;
258 xf_send_rail_client_event(channels, RDP_EVENT_TYPE_RAIL_CLIENT_SYSCOMMAND, &syscommand);
261 void xf_process_rail_get_sysparams_event(xfInfo* xfi, rdpChannels* channels, RDP_EVENT* event)
263 RAIL_SYSPARAM_ORDER* sysparam;
265 sysparam = (RAIL_SYSPARAM_ORDER*) event->user_data;
267 sysparam->workArea.left = xfi->workArea.x;
268 sysparam->workArea.top = xfi->workArea.y;
269 sysparam->workArea.right = xfi->workArea.x + xfi->workArea.width;
270 sysparam->workArea.bottom = xfi->workArea.y + xfi->workArea.height;
272 sysparam->taskbarPos.left = 0;
273 sysparam->taskbarPos.top = 0;
274 sysparam->taskbarPos.right = 0;
275 sysparam->taskbarPos.bottom = 0;
277 sysparam->dragFullWindows = false;
279 xf_send_rail_client_event(channels, RDP_EVENT_TYPE_RAIL_CLIENT_SET_SYSPARAMS, sysparam);
282 const char* error_code_names[] =
285 "RAIL_EXEC_E_HOOK_NOT_LOADED",
286 "RAIL_EXEC_E_DECODE_FAILED",
287 "RAIL_EXEC_E_NOT_IN_ALLOWLIST",
288 "RAIL_EXEC_E_FILE_NOT_FOUND",
290 "RAIL_EXEC_E_SESSION_LOCKED"
293 void xf_process_rail_exec_result_event(xfInfo* xfi, rdpChannels* channels, RDP_EVENT* event)
295 RAIL_EXEC_RESULT_ORDER* exec_result;
297 exec_result = (RAIL_EXEC_RESULT_ORDER*) event->user_data;
299 if (exec_result->execResult != RAIL_EXEC_S_OK)
301 printf("RAIL exec error: execResult=%s NtError=0x%X\n",
302 error_code_names[exec_result->execResult], exec_result->rawResult);
306 void xf_process_rail_server_sysparam_event(xfInfo* xfi, rdpChannels* channels, RDP_EVENT* event)
308 RAIL_SYSPARAM_ORDER* sysparam = (RAIL_SYSPARAM_ORDER*) event->user_data;
310 switch (sysparam->param)
312 case SPI_SET_SCREEN_SAVE_ACTIVE:
315 case SPI_SET_SCREEN_SAVE_SECURE:
320 void xf_process_rail_server_minmaxinfo_event(xfInfo* xfi, rdpChannels* channels, RDP_EVENT* event)
323 rdpWindow* rail_window = NULL;
324 RAIL_MINMAXINFO_ORDER* minmax = (RAIL_MINMAXINFO_ORDER*) event->user_data;
326 rail = ((rdpContext*) xfi->context)->rail;
327 rail_window = window_list_get_by_id(rail->list, minmax->windowId);
329 if (rail_window != NULL)
331 xfWindow * window = NULL;
332 window = (xfWindow *) rail_window->extra;
334 DEBUG_X11_LMS("windowId=0x%X maxWidth=%d maxHeight=%d maxPosX=%d maxPosY=%d "
335 "minTrackWidth=%d minTrackHeight=%d maxTrackWidth=%d maxTrackHeight=%d",
336 minmax->windowId, minmax->maxWidth, minmax->maxHeight,
337 (sint16)minmax->maxPosX, (sint16)minmax->maxPosY,
338 minmax->minTrackWidth, minmax->minTrackHeight,
339 minmax->maxTrackWidth, minmax->maxTrackHeight);
341 xf_SetWindowMinMaxInfo(xfi, window, minmax->maxWidth, minmax->maxHeight, minmax->maxPosX, minmax->maxPosY,
342 minmax->minTrackWidth, minmax->minTrackHeight, minmax->maxTrackWidth, minmax->maxTrackHeight);
346 const char* movetype_names[] =
353 "RAIL_WMSZ_TOPRIGHT",
355 "RAIL_WMSZ_BOTTOMLEFT",
356 "RAIL_WMSZ_BOTTOMRIGHT",
362 void xf_process_rail_server_localmovesize_event(xfInfo* xfi, rdpChannels* channels, RDP_EVENT* event)
365 rdpWindow* rail_window = NULL;
366 RAIL_LOCALMOVESIZE_ORDER* movesize = (RAIL_LOCALMOVESIZE_ORDER*) event->user_data;
368 rail = ((rdpContext*) xfi->context)->rail;
369 rail_window = window_list_get_by_id(rail->list, movesize->windowId);
371 if (rail_window != NULL)
373 xfWindow* window = NULL;
374 window = (xfWindow*) rail_window->extra;
376 DEBUG_X11_LMS("windowId=0x%X isMoveSizeStart=%d moveSizeType=%s PosX=%d PosY=%d",
377 movesize->windowId, movesize->isMoveSizeStart,
378 movetype_names[movesize->moveSizeType], (sint16) movesize->posX, (sint16) movesize->posY);
380 if (movesize->isMoveSizeStart)
381 xf_StartLocalMoveSize(xfi, window, movesize->moveSizeType, (int) movesize->posX, (int) movesize->posY);
383 xf_StopLocalMoveSize(xfi, window, movesize->moveSizeType, (int) movesize->posX, (int) movesize->posY);
388 void xf_process_rail_appid_resp_event(xfInfo* xfi, rdpChannels* channels, RDP_EVENT* event)
390 RAIL_GET_APPID_RESP_ORDER* appid_resp =
391 (RAIL_GET_APPID_RESP_ORDER*)event->user_data;
393 printf("Server Application ID Response PDU: windowId=0x%X "
394 "applicationId=(length=%d dump)\n",
395 appid_resp->windowId, appid_resp->applicationId.length);
397 freerdp_hexdump(appid_resp->applicationId.string, appid_resp->applicationId.length);
400 void xf_process_rail_langbarinfo_event(xfInfo* xfi, rdpChannels* channels, RDP_EVENT* event)
402 RAIL_LANGBAR_INFO_ORDER* langbar =
403 (RAIL_LANGBAR_INFO_ORDER*) event->user_data;
405 printf("Language Bar Information PDU: languageBarStatus=0x%X\n",
406 langbar->languageBarStatus);
409 void xf_process_rail_event(xfInfo* xfi, rdpChannels* channels, RDP_EVENT* event)
411 switch (event->event_type)
413 case RDP_EVENT_TYPE_RAIL_CHANNEL_GET_SYSPARAMS:
414 xf_process_rail_get_sysparams_event(xfi, channels, event);
417 case RDP_EVENT_TYPE_RAIL_CHANNEL_EXEC_RESULTS:
418 xf_process_rail_exec_result_event(xfi, channels, event);
421 case RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_SYSPARAM:
422 xf_process_rail_server_sysparam_event(xfi, channels, event);
425 case RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_MINMAXINFO:
426 xf_process_rail_server_minmaxinfo_event(xfi, channels, event);
429 case RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_LOCALMOVESIZE:
430 xf_process_rail_server_localmovesize_event(xfi, channels, event);
433 case RDP_EVENT_TYPE_RAIL_CHANNEL_APPID_RESP:
434 xf_process_rail_appid_resp_event(xfi, channels, event);
437 case RDP_EVENT_TYPE_RAIL_CHANNEL_LANGBARINFO:
438 xf_process_rail_langbarinfo_event(xfi, channels, event);