1 /** 2 * FreeRDP: A Remote Desktop Protocol Implementation 3 * X11 Client 4 * 5 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com> 6 * Copyright 2016 Thincast Technologies GmbH 7 * Copyright 2016 Armin Novak <armin.novak@thincast.com> 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 #ifndef FREERDP_CLIENT_X11_FREERDP_H 23 #define FREERDP_CLIENT_X11_FREERDP_H 24 25 #ifdef HAVE_CONFIG_H 26 #include "config.h" 27 #endif 28 29 typedef struct xf_context xfContext; 30 31 #ifdef WITH_XCURSOR 32 #include <X11/Xcursor/Xcursor.h> 33 #endif 34 35 #include <freerdp/api.h> 36 37 #include "xf_window.h" 38 #include "xf_monitor.h" 39 #include "xf_channels.h" 40 41 #if defined(CHANNEL_TSMF_CLIENT) 42 #include <freerdp/client/tsmf.h> 43 #endif 44 45 #include <freerdp/gdi/gdi.h> 46 #include <freerdp/codec/rfx.h> 47 #include <freerdp/codec/nsc.h> 48 #include <freerdp/codec/clear.h> 49 #include <freerdp/codec/color.h> 50 #include <freerdp/codec/bitmap.h> 51 #include <freerdp/codec/h264.h> 52 #include <freerdp/codec/progressive.h> 53 #include <freerdp/codec/region.h> 54 55 #if !defined(XcursorUInt) 56 typedef unsigned int XcursorUInt; 57 #endif 58 59 #if !defined(XcursorPixel) 60 typedef XcursorUInt XcursorPixel; 61 #endif 62 63 struct xf_FullscreenMonitors 64 { 65 UINT32 top; 66 UINT32 bottom; 67 UINT32 left; 68 UINT32 right; 69 }; 70 typedef struct xf_FullscreenMonitors xfFullscreenMonitors; 71 72 struct xf_WorkArea 73 { 74 UINT32 x; 75 UINT32 y; 76 UINT32 width; 77 UINT32 height; 78 }; 79 typedef struct xf_WorkArea xfWorkArea; 80 81 struct xf_pointer 82 { 83 rdpPointer pointer; 84 XcursorPixel* cursorPixels; 85 UINT32 nCursors; 86 UINT32 mCursors; 87 UINT32* cursorWidths; 88 UINT32* cursorHeights; 89 Cursor* cursors; 90 Cursor cursor; 91 }; 92 typedef struct xf_pointer xfPointer; 93 94 struct xf_bitmap 95 { 96 rdpBitmap bitmap; 97 Pixmap pixmap; 98 XImage* image; 99 }; 100 typedef struct xf_bitmap xfBitmap; 101 102 struct xf_glyph 103 { 104 rdpGlyph glyph; 105 Pixmap pixmap; 106 }; 107 typedef struct xf_glyph xfGlyph; 108 109 typedef struct xf_clipboard xfClipboard; 110 typedef struct _xfDispContext xfDispContext; 111 typedef struct _xfVideoContext xfVideoContext; 112 typedef struct xf_rail_icon_cache xfRailIconCache; 113 114 /* Number of buttons that are mapped from X11 to RDP button events. */ 115 #define NUM_BUTTONS_MAPPED 11 116 117 typedef struct 118 { 119 int button; 120 UINT16 flags; 121 } button_map; 122 123 struct xf_context 124 { 125 rdpContext context; 126 DEFINE_RDP_CLIENT_COMMON(); 127 128 GC gc; 129 int xfds; 130 int depth; 131 132 GC gc_mono; 133 BOOL invert; 134 Screen* screen; 135 XImage* image; 136 Pixmap primary; 137 Pixmap drawing; 138 Visual* visual; 139 Display* display; 140 Drawable drawable; 141 Pixmap bitmap_mono; 142 Colormap colormap; 143 int screen_number; 144 int scanline_pad; 145 BOOL big_endian; 146 BOOL fullscreen; 147 BOOL decorations; 148 BOOL grab_keyboard; 149 BOOL unobscured; 150 BOOL debug; 151 HANDLE x11event; 152 xfWindow* window; 153 xfAppWindow* appWindow; 154 xfPointer* pointer; 155 xfWorkArea workArea; 156 xfFullscreenMonitors fullscreenMonitors; 157 int current_desktop; 158 BOOL remote_app; 159 HANDLE mutex; 160 BOOL UseXThreads; 161 BOOL cursorHidden; 162 163 HGDI_DC hdc; 164 UINT32 bitmap_size; 165 BYTE* bitmap_buffer; 166 167 BOOL frame_begin; 168 UINT16 frame_x1; 169 UINT16 frame_y1; 170 UINT16 frame_x2; 171 UINT16 frame_y2; 172 173 int XInputOpcode; 174 175 int savedWidth; 176 int savedHeight; 177 int savedPosX; 178 int savedPosY; 179 180 #ifdef WITH_XRENDER 181 int scaledWidth; 182 int scaledHeight; 183 int offset_x; 184 int offset_y; 185 #endif 186 187 BOOL focused; 188 BOOL use_xinput; 189 BOOL mouse_active; 190 BOOL fullscreen_toggle; 191 BOOL controlToggle; 192 UINT32 KeyboardLayout; 193 BOOL KeyboardState[256]; 194 XModifierKeymap* modifierMap; 195 wArrayList* keyCombinations; 196 wArrayList* xevents; 197 BOOL actionScriptExists; 198 199 XSetWindowAttributes attribs; 200 BOOL complex_regions; 201 VIRTUAL_SCREEN vscreen; 202 #if defined(CHANNEL_TSMF_CLIENT) 203 void* xv_context; 204 #endif 205 206 Atom* supportedAtoms; 207 unsigned long supportedAtomCount; 208 209 Atom UTF8_STRING; 210 211 Atom _XWAYLAND_MAY_GRAB_KEYBOARD; 212 213 Atom _NET_WM_ICON; 214 Atom _MOTIF_WM_HINTS; 215 Atom _NET_CURRENT_DESKTOP; 216 Atom _NET_WORKAREA; 217 218 Atom _NET_SUPPORTED; 219 ATOM _NET_SUPPORTING_WM_CHECK; 220 221 Atom _NET_WM_STATE; 222 Atom _NET_WM_STATE_FULLSCREEN; 223 Atom _NET_WM_STATE_MAXIMIZED_HORZ; 224 Atom _NET_WM_STATE_MAXIMIZED_VERT; 225 Atom _NET_WM_STATE_SKIP_TASKBAR; 226 Atom _NET_WM_STATE_SKIP_PAGER; 227 228 Atom _NET_WM_FULLSCREEN_MONITORS; 229 230 Atom _NET_WM_NAME; 231 Atom _NET_WM_PID; 232 233 Atom _NET_WM_WINDOW_TYPE; 234 Atom _NET_WM_WINDOW_TYPE_NORMAL; 235 Atom _NET_WM_WINDOW_TYPE_DIALOG; 236 Atom _NET_WM_WINDOW_TYPE_UTILITY; 237 Atom _NET_WM_WINDOW_TYPE_POPUP; 238 Atom _NET_WM_WINDOW_TYPE_POPUP_MENU; 239 Atom _NET_WM_WINDOW_TYPE_DROPDOWN_MENU; 240 241 Atom _NET_WM_MOVERESIZE; 242 Atom _NET_MOVERESIZE_WINDOW; 243 244 Atom WM_STATE; 245 Atom WM_PROTOCOLS; 246 Atom WM_DELETE_WINDOW; 247 248 /* Channels */ 249 #if defined(CHANNEL_TSMF_CLIENT) 250 TsmfClientContext* tsmf; 251 #endif 252 253 xfClipboard* clipboard; 254 CliprdrClientContext* cliprdr; 255 xfVideoContext* xfVideo; 256 RdpeiClientContext* rdpei; 257 EncomspClientContext* encomsp; 258 xfDispContext* xfDisp; 259 260 RailClientContext* rail; 261 wHashTable* railWindows; 262 xfRailIconCache* railIconCache; 263 264 BOOL xkbAvailable; 265 BOOL xrenderAvailable; 266 267 /* value to be sent over wire for each logical client mouse button */ 268 button_map button_map[NUM_BUTTONS_MAPPED]; 269 BYTE savedMaximizedState; 270 UINT32 locked; 271 BOOL firstPressRightCtrl; 272 BOOL ungrabKeyboardWithRightCtrl; 273 }; 274 275 BOOL xf_create_window(xfContext* xfc); 276 void xf_toggle_fullscreen(xfContext* xfc); 277 BOOL xf_toggle_control(xfContext* xfc); 278 279 void xf_encomsp_init(xfContext* xfc, EncomspClientContext* encomsp); 280 void xf_encomsp_uninit(xfContext* xfc, EncomspClientContext* encomsp); 281 282 enum XF_EXIT_CODE 283 { 284 /* section 0-15: protocol-independent codes */ 285 XF_EXIT_SUCCESS = 0, 286 XF_EXIT_DISCONNECT = 1, 287 XF_EXIT_LOGOFF = 2, 288 XF_EXIT_IDLE_TIMEOUT = 3, 289 XF_EXIT_LOGON_TIMEOUT = 4, 290 XF_EXIT_CONN_REPLACED = 5, 291 XF_EXIT_OUT_OF_MEMORY = 6, 292 XF_EXIT_CONN_DENIED = 7, 293 XF_EXIT_CONN_DENIED_FIPS = 8, 294 XF_EXIT_USER_PRIVILEGES = 9, 295 XF_EXIT_FRESH_CREDENTIALS_REQUIRED = 10, 296 XF_EXIT_DISCONNECT_BY_USER = 11, 297 298 /* section 16-31: license error set */ 299 XF_EXIT_LICENSE_INTERNAL = 16, 300 XF_EXIT_LICENSE_NO_LICENSE_SERVER = 17, 301 XF_EXIT_LICENSE_NO_LICENSE = 18, 302 XF_EXIT_LICENSE_BAD_CLIENT_MSG = 19, 303 XF_EXIT_LICENSE_HWID_DOESNT_MATCH = 20, 304 XF_EXIT_LICENSE_BAD_CLIENT = 21, 305 XF_EXIT_LICENSE_CANT_FINISH_PROTOCOL = 22, 306 XF_EXIT_LICENSE_CLIENT_ENDED_PROTOCOL = 23, 307 XF_EXIT_LICENSE_BAD_CLIENT_ENCRYPTION = 24, 308 XF_EXIT_LICENSE_CANT_UPGRADE = 25, 309 XF_EXIT_LICENSE_NO_REMOTE_CONNECTIONS = 26, 310 311 /* section 32-127: RDP protocol error set */ 312 XF_EXIT_RDP = 32, 313 314 /* section 128-254: xfreerdp specific exit codes */ 315 XF_EXIT_PARSE_ARGUMENTS = 128, 316 XF_EXIT_MEMORY = 129, 317 XF_EXIT_PROTOCOL = 130, 318 XF_EXIT_CONN_FAILED = 131, 319 XF_EXIT_AUTH_FAILURE = 132, 320 XF_EXIT_NEGO_FAILURE = 133, 321 XF_EXIT_LOGON_FAILURE = 134, 322 XF_EXIT_ACCOUNT_LOCKED_OUT = 135, 323 XF_EXIT_PRE_CONNECT_FAILED = 136, 324 XF_EXIT_CONNECT_UNDEFINED = 137, 325 XF_EXIT_POST_CONNECT_FAILED = 138, 326 XF_EXIT_DNS_ERROR = 139, 327 XF_EXIT_DNS_NAME_NOT_FOUND = 140, 328 XF_EXIT_CONNECT_FAILED = 141, 329 XF_EXIT_MCS_CONNECT_INITIAL_ERROR = 142, 330 XF_EXIT_TLS_CONNECT_FAILED = 143, 331 XF_EXIT_INSUFFICIENT_PRIVILEGES = 144, 332 XF_EXIT_CONNECT_CANCELLED = 145, 333 XF_EXIT_SECURITY_NEGO_CONNECT_FAILED = 146, 334 XF_EXIT_CONNECT_TRANSPORT_FAILED = 147, 335 XF_EXIT_CONNECT_PASSWORD_EXPIRED = 148, 336 XF_EXIT_CONNECT_PASSWORD_MUST_CHANGE = 149, 337 XF_EXIT_CONNECT_KDC_UNREACHABLE = 150, 338 XF_EXIT_CONNECT_ACCOUNT_DISABLED = 151, 339 XF_EXIT_CONNECT_PASSWORD_CERTAINLY_EXPIRED = 152, 340 XF_EXIT_CONNECT_CLIENT_REVOKED = 153, 341 XF_EXIT_CONNECT_WRONG_PASSWORD = 154, 342 XF_EXIT_CONNECT_ACCESS_DENIED = 155, 343 XF_EXIT_CONNECT_ACCOUNT_RESTRICTION = 156, 344 XF_EXIT_CONNECT_ACCOUNT_EXPIRED = 157, 345 XF_EXIT_CONNECT_LOGON_TYPE_NOT_GRANTED = 158, 346 XF_EXIT_CONNECT_NO_OR_MISSING_CREDENTIALS = 159, 347 XF_EXIT_UNKNOWN = 255, 348 }; 349 350 #define xf_lock_x11(xfc) xf_lock_x11_(xfc, __FUNCTION__); 351 #define xf_unlock_x11(xfc) xf_unlock_x11_(xfc, __FUNCTION__); 352 353 void xf_lock_x11_(xfContext* xfc, const char* fkt); 354 void xf_unlock_x11_(xfContext* xfc, const char* fkt); 355 356 BOOL xf_picture_transform_required(xfContext* xfc); 357 358 #define xf_draw_screen(_xfc, _x, _y, _w, _h) \ 359 xf_draw_screen_((_xfc), (_x), (_y), (_w), (_h), __FUNCTION__, __FILE__, __LINE__) 360 void xf_draw_screen_(xfContext* xfc, int x, int y, int w, int h, const char* fkt, const char* file, 361 int line); 362 363 FREERDP_API DWORD xf_exit_code_from_disconnect_reason(DWORD reason); 364 365 #endif /* FREERDP_CLIENT_X11_FREERDP_H */ 366