Kitxuuu commited on
Commit
5cc96f3
·
verified ·
1 Parent(s): 726d0da

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. local-test-freerdp-delta-01/afc-freerdp/client/Android/BuildFlags.java.in +6 -0
  2. local-test-freerdp-delta-01/afc-freerdp/client/Mac/CMakeLists.txt +92 -0
  3. local-test-freerdp-delta-01/afc-freerdp/client/Mac/CertificateDialog.h +60 -0
  4. local-test-freerdp-delta-01/afc-freerdp/client/Mac/CertificateDialog.m +135 -0
  5. local-test-freerdp-delta-01/afc-freerdp/client/Mac/CertificateDialog.xib +169 -0
  6. local-test-freerdp-delta-01/afc-freerdp/client/Mac/Clipboard.h +31 -0
  7. local-test-freerdp-delta-01/afc-freerdp/client/Mac/Clipboard.m +432 -0
  8. local-test-freerdp-delta-01/afc-freerdp/client/Mac/Credits.rtf +21 -0
  9. local-test-freerdp-delta-01/afc-freerdp/client/Mac/Info.plist +30 -0
  10. local-test-freerdp-delta-01/afc-freerdp/client/Mac/Keyboard.h +27 -0
  11. local-test-freerdp-delta-01/afc-freerdp/client/Mac/Keyboard.m +240 -0
  12. local-test-freerdp-delta-01/afc-freerdp/client/Mac/MRDPCursor.h +34 -0
  13. local-test-freerdp-delta-01/afc-freerdp/client/Mac/MRDPCursor.m +24 -0
  14. local-test-freerdp-delta-01/afc-freerdp/client/Mac/MRDPView.h +91 -0
  15. local-test-freerdp-delta-01/afc-freerdp/client/Mac/MRDPView.m +1534 -0
  16. local-test-freerdp-delta-01/afc-freerdp/client/Mac/ModuleOptions.cmake +3 -0
  17. local-test-freerdp-delta-01/afc-freerdp/client/Mac/PasswordDialog.h +49 -0
  18. local-test-freerdp-delta-01/afc-freerdp/client/Mac/PasswordDialog.m +140 -0
  19. local-test-freerdp-delta-01/afc-freerdp/client/Mac/PasswordDialog.xib +132 -0
  20. local-test-freerdp-delta-01/afc-freerdp/client/Mac/main.m +25 -0
  21. local-test-freerdp-delta-01/afc-freerdp/client/Mac/mf_client.h +46 -0
  22. local-test-freerdp-delta-01/afc-freerdp/client/Mac/mf_client.m +220 -0
  23. local-test-freerdp-delta-01/afc-freerdp/client/Mac/mfreerdp.h +86 -0
  24. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL2/sdl_monitor.cpp +394 -0
  25. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL2/sdl_monitor.hpp +29 -0
  26. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL2/sdl_touch.hpp +36 -0
  27. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL2/sdl_utils.cpp +342 -0
  28. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_channels.cpp +83 -0
  29. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_channels.hpp +29 -0
  30. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_clip.hpp +157 -0
  31. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_disp.cpp +473 -0
  32. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_disp.hpp +80 -0
  33. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_freerdp.cpp +1744 -0
  34. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_freerdp.hpp +97 -0
  35. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_kbd.cpp +550 -0
  36. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_kbd.hpp +77 -0
  37. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_monitor.cpp +393 -0
  38. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_monitor.hpp +29 -0
  39. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_pointer.cpp +207 -0
  40. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_pointer.hpp +27 -0
  41. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_touch.cpp +279 -0
  42. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_touch.hpp +36 -0
  43. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_types.hpp +46 -0
  44. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_utils.cpp +346 -0
  45. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_utils.hpp +112 -0
  46. local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_window.hpp +64 -0
  47. local-test-freerdp-delta-01/afc-freerdp/client/Windows/CMakeLists.txt +87 -0
  48. local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_channels.c +86 -0
  49. local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_defaults.c +161 -0
  50. local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_defaults.h +28 -0
local-test-freerdp-delta-01/afc-freerdp/client/Android/BuildFlags.java.in ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ package com.freerdp.freerdpcore.utils;
2
+
3
+ public class BuildFlags
4
+ {
5
+ private final static boolean USE_OPENSSL_DEFAULT_NAMES = @USE_OPENSSL_DEFAULT_NAMES@;
6
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Mac/CMakeLists.txt ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ cmake_minimum_required(VERSION 3.13)
2
+
3
+ if(NOT FREERDP_DEFAULT_PROJECT_VERSION)
4
+ set(FREERDP_DEFAULT_PROJECT_VERSION "1.0.0.0")
5
+ endif()
6
+
7
+ project(MacFreeRDP-library VERSION ${FREERDP_DEFAULT_PROJECT_VERSION})
8
+
9
+ message("project ${PROJECT_NAME} is using version ${PROJECT_VERSION}")
10
+
11
+ cmake_policy(SET CMP0026 OLD)
12
+ cmake_policy(SET CMP0045 OLD)
13
+
14
+ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/)
15
+ include(CommonConfigOptions)
16
+
17
+ find_library(FOUNDATION_LIBRARY Foundation REQUIRED)
18
+ find_library(COCOA_LIBRARY Cocoa REQUIRED)
19
+ find_library(APPKIT_LIBRARY AppKit REQUIRED)
20
+ find_library(IOKIT_LIBRARY IOKit REQUIRED)
21
+ find_library(COREGRAPHICS_LIBRARY CoreGraphics REQUIRED)
22
+
23
+ set(EXTRA_LIBS ${COCOA_LIBRARY} ${FOUNDATION_LIBRARY} ${APPKIT_LIBRARY} ${IOKIT_LIBRARY})
24
+
25
+ set(XIBS CertificateDialog.xib PasswordDialog.xib)
26
+
27
+ set(SOURCES "")
28
+
29
+ set(OBJECTIVE_SOURCES
30
+ main.m
31
+ mf_client.m
32
+ MRDPCursor.m
33
+ MRDPView.m
34
+ Keyboard.m
35
+ Clipboard.m
36
+ CertificateDialog.m
37
+ PasswordDialog.m
38
+ )
39
+
40
+ list(APPEND SOURCES ${OBJECTIVE_SOURCES})
41
+
42
+ set(HEADERS
43
+ mfreerdp.h
44
+ mf_client.h
45
+ MRDPCursor.h
46
+ MRDPView.h
47
+ Keyboard.h
48
+ Clipboard.h
49
+ CertificateDialog.h
50
+ PasswordDialog.h
51
+ )
52
+
53
+ set(RESOURCES "en.lproj/InfoPlist.strings")
54
+
55
+ # Include XIB file in Xcode resources.
56
+ if("${CMAKE_GENERATOR}" MATCHES "Xcode")
57
+ message(STATUS "Adding Xcode XIB resources for ${MODULE_NAME}")
58
+ list(APPEND RESOURCES ${XIBS})
59
+ set(IS_XCODE ON)
60
+ endif()
61
+
62
+ add_library(${PROJECT_NAME} ../common/client.c ${SOURCES} ${HEADERS} ${RESOURCES})
63
+
64
+ set(LIBS ${EXTRA_LIBS} freerdp-client)
65
+
66
+ target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBS})
67
+
68
+ set_target_properties(${PROJECT_NAME} PROPERTIES RESOURCE "${RESOURCES}")
69
+
70
+ if(NOT IS_XCODE)
71
+ find_program(IBTOOL ibtool REQUIRED HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin")
72
+
73
+ # Compile the .xib files using the 'ibtool' program with the destination being the app package
74
+ foreach(xib ${XIBS})
75
+ get_filename_component(XIB_WE ${xib} NAME_WE)
76
+ set(NIB ${CMAKE_CURRENT_BINARY_DIR}/${XIB_WE}.nib)
77
+ list(APPEND NIBS ${NIB})
78
+
79
+ add_custom_command(
80
+ TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${IBTOOL} --errors --warnings --notices --output-format
81
+ human-readable-text --compile ${NIB} ${CMAKE_CURRENT_SOURCE_DIR}/${xib}
82
+ COMMENT "Compiling ${xib}"
83
+ )
84
+ endforeach()
85
+
86
+ install(FILES ${NIBS} DESTINATION ${CMAKE_INSTALL_DATADIR})
87
+ endif()
88
+
89
+ install(TARGETS ${PROJECT_NAME} COMPONENT client RESOURCE DESTINATION ${CMAKE_INSTALL_DATADIR})
90
+
91
+ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
92
+ add_subdirectory(cli)
local-test-freerdp-delta-01/afc-freerdp/client/Mac/CertificateDialog.h ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * MacFreeRDP
4
+ *
5
+ * Copyright 2018 Armin Novak <[email protected]>
6
+ * Copyright 2018 Thicast Technologies GmbH
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #import <Cocoa/Cocoa.h>
22
+
23
+ @interface CertificateDialog : NSWindowController
24
+ {
25
+ @public
26
+ NSTextField *textCommonName;
27
+ NSTextField *textSubject;
28
+ NSTextField *textIssuer;
29
+ NSTextField *textFingerprint;
30
+ NSTextField *textMismatch;
31
+ NSTextField *messageLabel;
32
+ NSString *serverHostname;
33
+
34
+ BOOL hostMismatch;
35
+ BOOL changed;
36
+ int result;
37
+ }
38
+ @property(retain) IBOutlet NSTextField *textCommonName;
39
+ @property(retain) IBOutlet NSTextField *textSubject;
40
+ @property(retain) IBOutlet NSTextField *textIssuer;
41
+ @property(retain) IBOutlet NSTextField *textFingerprint;
42
+ @property(retain) IBOutlet NSTextField *textMismatch;
43
+ @property(retain) IBOutlet NSTextField *messageLabel;
44
+
45
+ - (IBAction)onAccept:(NSObject *)sender;
46
+ - (IBAction)onTemporary:(NSObject *)sender;
47
+ - (IBAction)onCancel:(NSObject *)sender;
48
+
49
+ @property(retain) NSString *serverHostname;
50
+ @property(retain) NSString *commonName;
51
+ @property(retain) NSString *subject;
52
+ @property(retain) NSString *issuer;
53
+ @property(retain) NSString *fingerprint;
54
+ @property BOOL hostMismatch;
55
+ @property BOOL changed;
56
+ @property(readonly) int result;
57
+
58
+ - (int)runModal:(NSWindow *)mainWindow;
59
+
60
+ @end
local-test-freerdp-delta-01/afc-freerdp/client/Mac/CertificateDialog.m ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * MacFreeRDP
4
+ *
5
+ * Copyright 2018 Armin Novak <[email protected]>
6
+ * Copyright 2018 Thicast Technologies GmbH
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #import "CertificateDialog.h"
22
+ #import <freerdp/client/cmdline.h>
23
+
24
+ #import <CoreGraphics/CoreGraphics.h>
25
+
26
+ @interface CertificateDialog ()
27
+
28
+ @property int result;
29
+
30
+ @end
31
+
32
+ @implementation CertificateDialog
33
+
34
+ @synthesize textCommonName;
35
+ @synthesize textFingerprint;
36
+ @synthesize textIssuer;
37
+ @synthesize textSubject;
38
+ @synthesize textMismatch;
39
+ @synthesize messageLabel;
40
+ @synthesize serverHostname;
41
+ @synthesize commonName;
42
+ @synthesize fingerprint;
43
+ @synthesize issuer;
44
+ @synthesize subject;
45
+ @synthesize hostMismatch;
46
+ @synthesize changed;
47
+ @synthesize result;
48
+
49
+ - (id)init
50
+ {
51
+ return [self initWithWindowNibName:@"CertificateDialog"];
52
+ }
53
+
54
+ - (void)windowDidLoad
55
+ {
56
+ [super windowDidLoad];
57
+ // Implement this method to handle any initialization after your window controller's window has
58
+ // been loaded from its nib file.
59
+ [self.window setTitle:self.serverHostname];
60
+ if (self.changed)
61
+ [self.messageLabel setStringValue:[NSString stringWithFormat:@"Changed certificate for %@",
62
+ self.serverHostname]];
63
+ else
64
+ [self.messageLabel setStringValue:[NSString stringWithFormat:@"New Certificate for %@",
65
+ self.serverHostname]];
66
+
67
+ if (!self.hostMismatch)
68
+ [self.textMismatch
69
+ setStringValue:[NSString stringWithFormat:
70
+ @"NOTE: The server name matches the certificate, good."]];
71
+ else
72
+ [self.textMismatch
73
+ setStringValue:[NSString
74
+ stringWithFormat:
75
+ @"ATTENTION: The common name does not match the server name!"]];
76
+ [self.textCommonName setStringValue:self.commonName];
77
+ [self.textFingerprint setStringValue:self.fingerprint];
78
+ [self.textIssuer setStringValue:self.issuer];
79
+ [self.textSubject setStringValue:self.subject];
80
+ }
81
+
82
+ - (IBAction)onAccept:(NSObject *)sender
83
+ {
84
+ [NSApp stopModalWithCode:1];
85
+ }
86
+
87
+ - (IBAction)onTemporary:(NSObject *)sender
88
+ {
89
+ [NSApp stopModalWithCode:2];
90
+ }
91
+
92
+ - (IBAction)onCancel:(NSObject *)sender
93
+ {
94
+ [NSApp stopModalWithCode:0];
95
+ }
96
+
97
+ - (int)runModal:(NSWindow *)mainWindow
98
+ {
99
+ if ([mainWindow respondsToSelector:@selector(beginSheet:completionHandler:)])
100
+ {
101
+ [mainWindow beginSheet:self.window completionHandler:nil];
102
+ self.result = [NSApp runModalForWindow:self.window];
103
+ [mainWindow endSheet:self.window];
104
+ }
105
+ else
106
+ {
107
+ [NSApp beginSheet:self.window
108
+ modalForWindow:mainWindow
109
+ modalDelegate:nil
110
+ didEndSelector:nil
111
+ contextInfo:nil];
112
+ self.result = [NSApp runModalForWindow:self.window];
113
+ [NSApp endSheet:self.window];
114
+ }
115
+
116
+ [self.window orderOut:nil];
117
+ return self.result;
118
+ }
119
+
120
+ - (void)dealloc
121
+ {
122
+ [textCommonName release];
123
+ [textFingerprint release];
124
+ [textIssuer release];
125
+ [textSubject release];
126
+ [messageLabel release];
127
+ [serverHostname release];
128
+ [commonName release];
129
+ [fingerprint release];
130
+ [issuer release];
131
+ [subject release];
132
+ [super dealloc];
133
+ }
134
+
135
+ @end
local-test-freerdp-delta-01/afc-freerdp/client/Mac/CertificateDialog.xib ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
3
+ <dependencies>
4
+ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
5
+ <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
6
+ </dependencies>
7
+ <objects>
8
+ <customObject id="-2" userLabel="File's Owner" customClass="CertificateDialog">
9
+ <connections>
10
+ <outlet property="messageLabel" destination="7" id="50"/>
11
+ <outlet property="textCommonName" destination="2HW-of-a4n" id="4442"/>
12
+ <outlet property="textFingerprint" destination="cLB-ZO-jvx" id="4445"/>
13
+ <outlet property="textIssuer" destination="kHA-F4-dxw" id="4444"/>
14
+ <outlet property="textMismatch" destination="LgQ-ni-jXv" id="5550"/>
15
+ <outlet property="textSubject" destination="R9r-82-XAH" id="4443"/>
16
+ <outlet property="window" destination="1" id="3"/>
17
+ </connections>
18
+ </customObject>
19
+ <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
20
+ <customObject id="-3" userLabel="Application" customClass="NSObject"/>
21
+ <window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" visibleAtLaunch="NO" animationBehavior="default" id="1">
22
+ <windowStyleMask key="styleMask" titled="YES" texturedBackground="YES"/>
23
+ <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
24
+ <rect key="contentRect" x="196" y="240" width="641" height="338"/>
25
+ <rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
26
+ <view key="contentView" id="2">
27
+ <rect key="frame" x="0.0" y="0.0" width="641" height="338"/>
28
+ <autoresizingMask key="autoresizingMask"/>
29
+ <subviews>
30
+ <textField verticalHuggingPriority="750" id="7">
31
+ <rect key="frame" x="47" y="274" width="344" height="17"/>
32
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
33
+ <textFieldCell key="cell" scrollable="YES" sendsActionOnEndEditing="YES" title="Certificate for SERVER_NAME" placeholderString="" id="20">
34
+ <font key="font" metaFont="system"/>
35
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
36
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
37
+ </textFieldCell>
38
+ </textField>
39
+ <button verticalHuggingPriority="750" id="8">
40
+ <rect key="frame" x="545" y="13" width="82" height="32"/>
41
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
42
+ <buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="18">
43
+ <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
44
+ <font key="font" metaFont="system"/>
45
+ <string key="keyEquivalent" base64-UTF8="YES">
46
+ Gw
47
+ </string>
48
+ </buttonCell>
49
+ <connections>
50
+ <action selector="onCancel:" target="-2" id="52"/>
51
+ </connections>
52
+ </button>
53
+ <button verticalHuggingPriority="750" id="9">
54
+ <rect key="frame" x="463" y="13" width="82" height="32"/>
55
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
56
+ <buttonCell key="cell" type="push" title="OK" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="17">
57
+ <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
58
+ <font key="font" metaFont="system"/>
59
+ <string key="keyEquivalent" base64-UTF8="YES">
60
+ DQ
61
+ </string>
62
+ </buttonCell>
63
+ <connections>
64
+ <accessibilityConnection property="link" destination="8" id="cks-Lf-tCO"/>
65
+ <action selector="onAccept:" target="-2" id="522"/>
66
+ </connections>
67
+ </button>
68
+ <button verticalHuggingPriority="750" id="7I5-a2-h65">
69
+ <rect key="frame" x="358" y="13" width="105" height="32"/>
70
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
71
+ <buttonCell key="cell" type="push" title="Temporary" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="i6y-0u-COa">
72
+ <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
73
+ <font key="font" metaFont="system"/>
74
+ </buttonCell>
75
+ <connections>
76
+ <accessibilityConnection property="link" destination="9" id="5nn-SX-Rqq"/>
77
+ <action selector="onTemporary:" target="-2" id="BWk-o1-tug"/>
78
+ </connections>
79
+ </button>
80
+ <textField verticalHuggingPriority="750" id="LgQ-ni-jXv">
81
+ <rect key="frame" x="47" y="236" width="582" height="36"/>
82
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
83
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" title="ATTENTION: The common name does not match the server name!" id="94f-Om-tJh">
84
+ <font key="font" metaFont="system"/>
85
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
86
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
87
+ </textFieldCell>
88
+ </textField>
89
+ <textField verticalHuggingPriority="750" id="5">
90
+ <rect key="frame" x="47" y="186" width="89" height="17"/>
91
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
92
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" title="Subject" id="22">
93
+ <font key="font" metaFont="system"/>
94
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
95
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
96
+ </textFieldCell>
97
+ </textField>
98
+ <textField verticalHuggingPriority="750" id="vA4-qf-QuW">
99
+ <rect key="frame" x="47" y="161" width="89" height="17"/>
100
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
101
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" title="Issuer" id="tAl-Qh-OR9">
102
+ <font key="font" metaFont="system"/>
103
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
104
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
105
+ </textFieldCell>
106
+ </textField>
107
+ <textField verticalHuggingPriority="750" id="10">
108
+ <rect key="frame" x="47" y="211" width="89" height="17"/>
109
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
110
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" title="Common" id="15">
111
+ <font key="font" metaFont="system"/>
112
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
113
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
114
+ </textFieldCell>
115
+ </textField>
116
+ <textField verticalHuggingPriority="750" id="2HW-of-a4n">
117
+ <rect key="frame" x="140" y="211" width="305" height="17"/>
118
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
119
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" title="COMMON NAME" id="N48-2i-W6H">
120
+ <font key="font" metaFont="system"/>
121
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
122
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
123
+ </textFieldCell>
124
+ </textField>
125
+ <textField verticalHuggingPriority="750" id="R9r-82-XAH">
126
+ <rect key="frame" x="140" y="186" width="305" height="17"/>
127
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
128
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" title="SUBJECT" id="iGw-oh-i3p">
129
+ <font key="font" metaFont="system"/>
130
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
131
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
132
+ </textFieldCell>
133
+ </textField>
134
+ <textField verticalHuggingPriority="750" id="kHA-F4-dxw">
135
+ <rect key="frame" x="140" y="161" width="305" height="17"/>
136
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
137
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" title="ISSUER" id="daP-a0-hI1">
138
+ <font key="font" metaFont="system"/>
139
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
140
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
141
+ </textFieldCell>
142
+ </textField>
143
+ <textField verticalHuggingPriority="750" id="cLB-ZO-jvx">
144
+ <rect key="frame" x="140" y="117" width="483" height="36"/>
145
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
146
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" title="FINGERPRINT" id="VqU-vO-noG">
147
+ <font key="font" metaFont="system"/>
148
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
149
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
150
+ </textFieldCell>
151
+ </textField>
152
+ <textField verticalHuggingPriority="750" id="VLG-f9-Gcl">
153
+ <rect key="frame" x="47" y="136" width="89" height="17"/>
154
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
155
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" title="Fingerprint" id="49l-Xk-MUH">
156
+ <font key="font" metaFont="system"/>
157
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
158
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
159
+ </textFieldCell>
160
+ </textField>
161
+ </subviews>
162
+ </view>
163
+ <connections>
164
+ <outlet property="delegate" destination="-2" id="4"/>
165
+ </connections>
166
+ <point key="canvasLocation" x="228.5" y="102"/>
167
+ </window>
168
+ </objects>
169
+ </document>
local-test-freerdp-delta-01/afc-freerdp/client/Mac/Clipboard.h ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ *
4
+ * Copyright 2014 Marc-Andre Moreau <[email protected]>
5
+ * Copyright 2015 Thincast Technologies GmbH
6
+ * Copyright 2015 DI (FH) Martin Haimberger <[email protected]>
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #import "mfreerdp.h"
22
+ #import "mf_client.h"
23
+
24
+ #import "freerdp/freerdp.h"
25
+ #import "freerdp/channels/channels.h"
26
+ #import "freerdp/client/cliprdr.h"
27
+
28
+ int mac_cliprdr_send_client_format_list(CliprdrClientContext* cliprdr);
29
+
30
+ void mac_cliprdr_init(mfContext* mfc, CliprdrClientContext* cliprdr);
31
+ void mac_cliprdr_uninit(mfContext* mfc, CliprdrClientContext* cliprdr);
local-test-freerdp-delta-01/afc-freerdp/client/Mac/Clipboard.m ADDED
@@ -0,0 +1,432 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ *
4
+ * Copyright 2014 Marc-Andre Moreau <[email protected]>
5
+ * Copyright 2015 Thincast Technologies GmbH
6
+ * Copyright 2015 DI (FH) Martin Haimberger <[email protected]>
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #import "Clipboard.h"
22
+ #import "MRDPView.h"
23
+
24
+ int mac_cliprdr_send_client_format_list(CliprdrClientContext *cliprdr)
25
+ {
26
+ UINT32 formatId;
27
+ UINT32 numFormats;
28
+ UINT32 *pFormatIds;
29
+ const char *formatName;
30
+ CLIPRDR_FORMAT *formats;
31
+ CLIPRDR_FORMAT_LIST formatList = { 0 };
32
+
33
+ WINPR_ASSERT(cliprdr);
34
+ mfContext *mfc = (mfContext *)cliprdr->custom;
35
+ WINPR_ASSERT(mfc);
36
+
37
+ pFormatIds = NULL;
38
+ numFormats = ClipboardGetFormatIds(mfc->clipboard, &pFormatIds);
39
+
40
+ formats = (CLIPRDR_FORMAT *)calloc(numFormats, sizeof(CLIPRDR_FORMAT));
41
+
42
+ if (!formats)
43
+ return -1;
44
+
45
+ for (UINT32 index = 0; index < numFormats; index++)
46
+ {
47
+ formatId = pFormatIds[index];
48
+ formatName = ClipboardGetFormatName(mfc->clipboard, formatId);
49
+
50
+ formats[index].formatId = formatId;
51
+ formats[index].formatName = NULL;
52
+
53
+ if ((formatId > CF_MAX) && formatName)
54
+ formats[index].formatName = _strdup(formatName);
55
+ }
56
+
57
+ formatList.common.msgFlags = 0;
58
+ formatList.numFormats = numFormats;
59
+ formatList.formats = formats;
60
+ formatList.common.msgType = CB_FORMAT_LIST;
61
+
62
+ mfc->cliprdr->ClientFormatList(mfc->cliprdr, &formatList);
63
+
64
+ for (UINT32 index = 0; index < numFormats; index++)
65
+ {
66
+ free(formats[index].formatName);
67
+ }
68
+
69
+ free(pFormatIds);
70
+ free(formats);
71
+
72
+ return 1;
73
+ }
74
+
75
+ static int mac_cliprdr_send_client_format_list_response(CliprdrClientContext *cliprdr, BOOL status)
76
+ {
77
+ CLIPRDR_FORMAT_LIST_RESPONSE formatListResponse;
78
+
79
+ formatListResponse.common.msgType = CB_FORMAT_LIST_RESPONSE;
80
+ formatListResponse.common.msgFlags = status ? CB_RESPONSE_OK : CB_RESPONSE_FAIL;
81
+ formatListResponse.common.dataLen = 0;
82
+
83
+ cliprdr->ClientFormatListResponse(cliprdr, &formatListResponse);
84
+
85
+ return 1;
86
+ }
87
+
88
+ static int mac_cliprdr_send_client_format_data_request(CliprdrClientContext *cliprdr,
89
+ UINT32 formatId)
90
+ {
91
+ CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest = { 0 };
92
+ WINPR_ASSERT(cliprdr);
93
+
94
+ mfContext *mfc = (mfContext *)cliprdr->custom;
95
+ WINPR_ASSERT(mfc);
96
+
97
+ formatDataRequest.common.msgType = CB_FORMAT_DATA_REQUEST;
98
+ formatDataRequest.common.msgFlags = 0;
99
+
100
+ formatDataRequest.requestedFormatId = formatId;
101
+ mfc->requestedFormatId = formatId;
102
+ (void)ResetEvent(mfc->clipboardRequestEvent);
103
+
104
+ cliprdr->ClientFormatDataRequest(cliprdr, &formatDataRequest);
105
+
106
+ return 1;
107
+ }
108
+
109
+ static int mac_cliprdr_send_client_capabilities(CliprdrClientContext *cliprdr)
110
+ {
111
+ CLIPRDR_CAPABILITIES capabilities;
112
+ CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet;
113
+
114
+ capabilities.cCapabilitiesSets = 1;
115
+ capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET *)&(generalCapabilitySet);
116
+
117
+ generalCapabilitySet.capabilitySetType = CB_CAPSTYPE_GENERAL;
118
+ generalCapabilitySet.capabilitySetLength = 12;
119
+
120
+ generalCapabilitySet.version = CB_CAPS_VERSION_2;
121
+ generalCapabilitySet.generalFlags = CB_USE_LONG_FORMAT_NAMES;
122
+
123
+ cliprdr->ClientCapabilities(cliprdr, &capabilities);
124
+
125
+ return 1;
126
+ }
127
+
128
+ /**
129
+ * Function description
130
+ *
131
+ * @return 0 on success, otherwise a Win32 error code
132
+ */
133
+ static UINT mac_cliprdr_monitor_ready(CliprdrClientContext *cliprdr,
134
+ const CLIPRDR_MONITOR_READY *monitorReady)
135
+ {
136
+ mfContext *mfc = (mfContext *)cliprdr->custom;
137
+
138
+ mfc->clipboardSync = TRUE;
139
+ mac_cliprdr_send_client_capabilities(cliprdr);
140
+ mac_cliprdr_send_client_format_list(cliprdr);
141
+
142
+ return CHANNEL_RC_OK;
143
+ }
144
+
145
+ /**
146
+ * Function description
147
+ *
148
+ * @return 0 on success, otherwise a Win32 error code
149
+ */
150
+ static UINT mac_cliprdr_server_capabilities(CliprdrClientContext *cliprdr,
151
+ const CLIPRDR_CAPABILITIES *capabilities)
152
+ {
153
+ CLIPRDR_CAPABILITY_SET *capabilitySet;
154
+ mfContext *mfc = (mfContext *)cliprdr->custom;
155
+
156
+ for (UINT32 index = 0; index < capabilities->cCapabilitiesSets; index++)
157
+ {
158
+ capabilitySet = &(capabilities->capabilitySets[index]);
159
+
160
+ if ((capabilitySet->capabilitySetType == CB_CAPSTYPE_GENERAL) &&
161
+ (capabilitySet->capabilitySetLength >= CB_CAPSTYPE_GENERAL_LEN))
162
+ {
163
+ CLIPRDR_GENERAL_CAPABILITY_SET *generalCapabilitySet =
164
+ (CLIPRDR_GENERAL_CAPABILITY_SET *)capabilitySet;
165
+
166
+ mfc->clipboardCapabilities = generalCapabilitySet->generalFlags;
167
+ break;
168
+ }
169
+ }
170
+
171
+ return CHANNEL_RC_OK;
172
+ }
173
+
174
+ /**
175
+ * Function description
176
+ *
177
+ * @return 0 on success, otherwise a Win32 error code
178
+ */
179
+ static UINT mac_cliprdr_server_format_list(CliprdrClientContext *cliprdr,
180
+ const CLIPRDR_FORMAT_LIST *formatList)
181
+ {
182
+ CLIPRDR_FORMAT *format;
183
+ mfContext *mfc = (mfContext *)cliprdr->custom;
184
+
185
+ if (mfc->serverFormats)
186
+ {
187
+ for (UINT32 index = 0; index < mfc->numServerFormats; index++)
188
+ {
189
+ free(mfc->serverFormats[index].formatName);
190
+ }
191
+
192
+ free(mfc->serverFormats);
193
+ mfc->serverFormats = NULL;
194
+ mfc->numServerFormats = 0;
195
+ }
196
+
197
+ if (formatList->numFormats < 1)
198
+ return CHANNEL_RC_OK;
199
+
200
+ mfc->numServerFormats = formatList->numFormats;
201
+ mfc->serverFormats = (CLIPRDR_FORMAT *)calloc(mfc->numServerFormats, sizeof(CLIPRDR_FORMAT));
202
+
203
+ if (!mfc->serverFormats)
204
+ return CHANNEL_RC_NO_MEMORY;
205
+
206
+ for (UINT32 index = 0; index < mfc->numServerFormats; index++)
207
+ {
208
+ mfc->serverFormats[index].formatId = formatList->formats[index].formatId;
209
+ mfc->serverFormats[index].formatName = NULL;
210
+
211
+ if (formatList->formats[index].formatName)
212
+ mfc->serverFormats[index].formatName = _strdup(formatList->formats[index].formatName);
213
+ }
214
+
215
+ mac_cliprdr_send_client_format_list_response(cliprdr, TRUE);
216
+
217
+ for (UINT32 index = 0; index < mfc->numServerFormats; index++)
218
+ {
219
+ format = &(mfc->serverFormats[index]);
220
+
221
+ if (format->formatId == CF_UNICODETEXT)
222
+ {
223
+ mac_cliprdr_send_client_format_data_request(cliprdr, CF_UNICODETEXT);
224
+ break;
225
+ }
226
+ else if (format->formatId == CF_OEMTEXT)
227
+ {
228
+ mac_cliprdr_send_client_format_data_request(cliprdr, CF_OEMTEXT);
229
+ break;
230
+ }
231
+ else if (format->formatId == CF_TEXT)
232
+ {
233
+ mac_cliprdr_send_client_format_data_request(cliprdr, CF_TEXT);
234
+ break;
235
+ }
236
+ }
237
+
238
+ return CHANNEL_RC_OK;
239
+ }
240
+
241
+ /**
242
+ * Function description
243
+ *
244
+ * @return 0 on success, otherwise a Win32 error code
245
+ */
246
+ static UINT
247
+ mac_cliprdr_server_format_list_response(CliprdrClientContext *cliprdr,
248
+ const CLIPRDR_FORMAT_LIST_RESPONSE *formatListResponse)
249
+ {
250
+ return CHANNEL_RC_OK;
251
+ }
252
+
253
+ /**
254
+ * Function description
255
+ *
256
+ * @return 0 on success, otherwise a Win32 error code
257
+ */
258
+ static UINT
259
+ mac_cliprdr_server_lock_clipboard_data(CliprdrClientContext *cliprdr,
260
+ const CLIPRDR_LOCK_CLIPBOARD_DATA *lockClipboardData)
261
+ {
262
+ return CHANNEL_RC_OK;
263
+ }
264
+
265
+ /**
266
+ * Function description
267
+ *
268
+ * @return 0 on success, otherwise a Win32 error code
269
+ */
270
+ static UINT
271
+ mac_cliprdr_server_unlock_clipboard_data(CliprdrClientContext *cliprdr,
272
+ const CLIPRDR_UNLOCK_CLIPBOARD_DATA *unlockClipboardData)
273
+ {
274
+ return CHANNEL_RC_OK;
275
+ }
276
+
277
+ /**
278
+ * Function description
279
+ *
280
+ * @return 0 on success, otherwise a Win32 error code
281
+ */
282
+ static UINT
283
+ mac_cliprdr_server_format_data_request(CliprdrClientContext *cliprdr,
284
+ const CLIPRDR_FORMAT_DATA_REQUEST *formatDataRequest)
285
+ {
286
+ BYTE *data;
287
+ UINT32 size;
288
+ UINT32 formatId;
289
+ CLIPRDR_FORMAT_DATA_RESPONSE response = { 0 };
290
+
291
+ WINPR_ASSERT(cliprdr);
292
+
293
+ mfContext *mfc = (mfContext *)cliprdr->custom;
294
+ WINPR_ASSERT(mfc);
295
+
296
+ formatId = formatDataRequest->requestedFormatId;
297
+ data = (BYTE *)ClipboardGetData(mfc->clipboard, formatId, &size);
298
+
299
+ response.common.msgFlags = CB_RESPONSE_OK;
300
+ response.common.dataLen = size;
301
+ response.requestedFormatData = data;
302
+
303
+ if (!data)
304
+ {
305
+ response.common.msgFlags = CB_RESPONSE_FAIL;
306
+ response.common.dataLen = 0;
307
+ response.requestedFormatData = NULL;
308
+ }
309
+
310
+ cliprdr->ClientFormatDataResponse(cliprdr, &response);
311
+
312
+ free(data);
313
+
314
+ return CHANNEL_RC_OK;
315
+ }
316
+
317
+ /**
318
+ * Function description
319
+ *
320
+ * @return 0 on success, otherwise a Win32 error code
321
+ */
322
+ static UINT
323
+ mac_cliprdr_server_format_data_response(CliprdrClientContext *cliprdr,
324
+ const CLIPRDR_FORMAT_DATA_RESPONSE *formatDataResponse)
325
+ {
326
+ UINT32 formatId;
327
+ CLIPRDR_FORMAT *format = NULL;
328
+ mfContext *mfc = (mfContext *)cliprdr->custom;
329
+ MRDPView *view = (MRDPView *)mfc->view;
330
+
331
+ if (formatDataResponse->common.msgFlags & CB_RESPONSE_FAIL)
332
+ {
333
+ (void)SetEvent(mfc->clipboardRequestEvent);
334
+ return ERROR_INTERNAL_ERROR;
335
+ }
336
+
337
+ for (UINT32 index = 0; index < mfc->numServerFormats; index++)
338
+ {
339
+ if (mfc->requestedFormatId == mfc->serverFormats[index].formatId)
340
+ format = &(mfc->serverFormats[index]);
341
+ }
342
+
343
+ if (!format)
344
+ {
345
+ (void)SetEvent(mfc->clipboardRequestEvent);
346
+ return ERROR_INTERNAL_ERROR;
347
+ }
348
+
349
+ if (format->formatName)
350
+ formatId = ClipboardRegisterFormat(mfc->clipboard, format->formatName);
351
+ else
352
+ formatId = format->formatId;
353
+
354
+ const size_t size = formatDataResponse->common.dataLen;
355
+
356
+ ClipboardSetData(mfc->clipboard, formatId, formatDataResponse->requestedFormatData, size);
357
+
358
+ (void)SetEvent(mfc->clipboardRequestEvent);
359
+
360
+ if ((formatId == CF_TEXT) || (formatId == CF_OEMTEXT) || (formatId == CF_UNICODETEXT))
361
+ {
362
+ formatId = ClipboardRegisterFormat(mfc->clipboard, "text/plain");
363
+
364
+ UINT32 dstSize = 0;
365
+ char *data = ClipboardGetData(mfc->clipboard, formatId, &dstSize);
366
+
367
+ dstSize = strnlen(data, dstSize); /* we need the size without the null terminator */
368
+
369
+ NSString *str = [[NSString alloc] initWithBytes:(void *)data
370
+ length:dstSize
371
+ encoding:NSUTF8StringEncoding];
372
+ free(data);
373
+
374
+ NSArray *types = [[NSArray alloc] initWithObjects:NSPasteboardTypeString, nil];
375
+ [view->pasteboard_wr declareTypes:types owner:view];
376
+ [view->pasteboard_wr setString:str forType:NSPasteboardTypeString];
377
+ }
378
+
379
+ return CHANNEL_RC_OK;
380
+ }
381
+
382
+ /**
383
+ * Function description
384
+ *
385
+ * @return 0 on success, otherwise a Win32 error code
386
+ */
387
+ static UINT
388
+ mac_cliprdr_server_file_contents_request(CliprdrClientContext *cliprdr,
389
+ const CLIPRDR_FILE_CONTENTS_REQUEST *fileContentsRequest)
390
+ {
391
+ return CHANNEL_RC_OK;
392
+ }
393
+
394
+ /**
395
+ * Function description
396
+ *
397
+ * @return 0 on success, otherwise a Win32 error code
398
+ */
399
+ static UINT mac_cliprdr_server_file_contents_response(
400
+ CliprdrClientContext *cliprdr, const CLIPRDR_FILE_CONTENTS_RESPONSE *fileContentsResponse)
401
+ {
402
+ return CHANNEL_RC_OK;
403
+ }
404
+
405
+ void mac_cliprdr_init(mfContext *mfc, CliprdrClientContext *cliprdr)
406
+ {
407
+ cliprdr->custom = (void *)mfc;
408
+ mfc->cliprdr = cliprdr;
409
+
410
+ mfc->clipboard = ClipboardCreate();
411
+ mfc->clipboardRequestEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
412
+
413
+ cliprdr->MonitorReady = mac_cliprdr_monitor_ready;
414
+ cliprdr->ServerCapabilities = mac_cliprdr_server_capabilities;
415
+ cliprdr->ServerFormatList = mac_cliprdr_server_format_list;
416
+ cliprdr->ServerFormatListResponse = mac_cliprdr_server_format_list_response;
417
+ cliprdr->ServerLockClipboardData = mac_cliprdr_server_lock_clipboard_data;
418
+ cliprdr->ServerUnlockClipboardData = mac_cliprdr_server_unlock_clipboard_data;
419
+ cliprdr->ServerFormatDataRequest = mac_cliprdr_server_format_data_request;
420
+ cliprdr->ServerFormatDataResponse = mac_cliprdr_server_format_data_response;
421
+ cliprdr->ServerFileContentsRequest = mac_cliprdr_server_file_contents_request;
422
+ cliprdr->ServerFileContentsResponse = mac_cliprdr_server_file_contents_response;
423
+ }
424
+
425
+ void mac_cliprdr_uninit(mfContext *mfc, CliprdrClientContext *cliprdr)
426
+ {
427
+ cliprdr->custom = NULL;
428
+ mfc->cliprdr = NULL;
429
+
430
+ ClipboardDestroy(mfc->clipboard);
431
+ (void)CloseHandle(mfc->clipboardRequestEvent);
432
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Mac/Credits.rtf ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {\rtf1\ansi\ansicpg1252\cocoartf1138\cocoasubrtf320
2
+ {\fonttbl\f0\fswiss\fcharset0 Helvetica;}
3
+ {\colortbl;\red255\green255\blue255;}
4
+ \vieww9600\viewh8400\viewkind0
5
+ \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720
6
+
7
+ \f0\b\fs24 \cf0 Engineering:
8
+ \b0 \
9
+ Jay sorg\
10
+ Marc-Andre Moreau\
11
+ Vic Lee\
12
+ Otvaio Salvador \
13
+ Laxmikant Rashinkar\
14
+ and others\
15
+ \
16
+
17
+ \b Human Interface Design:
18
+ \b0 \
19
+ Laxmikant Rashinkar\
20
+ Jay Sorg\
21
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Mac/Info.plist ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>NSCameraUsageDescription</key>
6
+ <string>This application requires camera access to redirect it to the remote host</string>
7
+ <key>NSMicrophoneUsageDescription</key>
8
+ <string>This application requires microphone access to redirect it to the remote host</string>
9
+ <key>CFBundleDevelopmentRegion</key>
10
+ <string>English</string>
11
+ <key>CFBundleIconFile</key>
12
+ <string></string>
13
+ <key>CFBundleIdentifier</key>
14
+ <string>FreeRDP.Mac</string>
15
+ <key>CFBundleInfoDictionaryVersion</key>
16
+ <string>6.0</string>
17
+ <key>CFBundleName</key>
18
+ <string></string>
19
+ <key>CFBundlePackageType</key>
20
+ <string>FMWK</string>
21
+ <key>CFBundleShortVersionString</key>
22
+ <string>1.0</string>
23
+ <key>CFBundleSignature</key>
24
+ <string>????</string>
25
+ <key>CFBundleVersion</key>
26
+ <string>1</string>
27
+ <key>NSPrincipalClass</key>
28
+ <string></string>
29
+ </dict>
30
+ </plist>
local-test-freerdp-delta-01/afc-freerdp/client/Mac/Keyboard.h ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * MacFreeRDP
4
+ *
5
+ * Copyright 2014 Marc-Andre Moreau <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ enum APPLE_KEYBOARD_TYPE
21
+ {
22
+ APPLE_KEYBOARD_TYPE_ANSI,
23
+ APPLE_KEYBOARD_TYPE_ISO,
24
+ APPLE_KEYBOARD_TYPE_JIS
25
+ };
26
+
27
+ enum APPLE_KEYBOARD_TYPE mac_detect_keyboard_type(void);
local-test-freerdp-delta-01/afc-freerdp/client/Mac/Keyboard.m ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * MacFreeRDP
4
+ *
5
+ * Copyright 2014 Marc-Andre Moreau <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #import "Keyboard.h"
21
+
22
+ #include <CoreFoundation/CoreFoundation.h>
23
+
24
+ #include <IOKit/IOKitLib.h>
25
+ #include <IOKit/hid/IOHIDManager.h>
26
+
27
+ typedef struct
28
+ {
29
+ uint32_t ProductId;
30
+ enum APPLE_KEYBOARD_TYPE Type;
31
+ } APPLE_KEYBOARD_DESC;
32
+
33
+ /* VendorID: 0x05AC (Apple, Inc.) */
34
+
35
+ static const APPLE_KEYBOARD_DESC APPLE_KEYBOARDS[] = {
36
+ { 0x200, APPLE_KEYBOARD_TYPE_ANSI },
37
+ { 0x201, APPLE_KEYBOARD_TYPE_ANSI }, /* USB Keyboard [Alps or Logitech, M2452] */
38
+ { 0x202, APPLE_KEYBOARD_TYPE_ANSI }, /* Keyboard [ALPS] */
39
+ { 0x203, APPLE_KEYBOARD_TYPE_ANSI },
40
+ { 0x204, APPLE_KEYBOARD_TYPE_ANSI },
41
+ { 0x205, APPLE_KEYBOARD_TYPE_ANSI }, /* Extended Keyboard [Mitsumi] */
42
+ { 0x206, APPLE_KEYBOARD_TYPE_ANSI }, /* Extended Keyboard [Mitsumi] */
43
+ { 0x207, APPLE_KEYBOARD_TYPE_ANSI },
44
+ { 0x208, APPLE_KEYBOARD_TYPE_ANSI },
45
+ { 0x209, APPLE_KEYBOARD_TYPE_ANSI },
46
+ { 0x20A, APPLE_KEYBOARD_TYPE_ANSI },
47
+ { 0x20B, APPLE_KEYBOARD_TYPE_ANSI }, /* Pro Keyboard [Mitsumi, A1048/US layout] */
48
+ { 0x20C, APPLE_KEYBOARD_TYPE_ANSI }, /* Extended Keyboard [Mitsumi] */
49
+ { 0x20D, APPLE_KEYBOARD_TYPE_ANSI }, /* Pro Keyboard [Mitsumi, A1048/JIS layout] */
50
+ { 0x20E, APPLE_KEYBOARD_TYPE_ANSI }, /* Internal Keyboard/Trackpad (ANSI) */
51
+ { 0x20F, APPLE_KEYBOARD_TYPE_ISO }, /* Internal Keyboard/Trackpad (ISO) */
52
+ { 0x210, APPLE_KEYBOARD_TYPE_ANSI },
53
+ { 0x211, APPLE_KEYBOARD_TYPE_ANSI },
54
+ { 0x212, APPLE_KEYBOARD_TYPE_ANSI },
55
+ { 0x213, APPLE_KEYBOARD_TYPE_ANSI },
56
+ { 0x214, APPLE_KEYBOARD_TYPE_ANSI }, /* Internal Keyboard/Trackpad (ANSI) */
57
+ { 0x215, APPLE_KEYBOARD_TYPE_ISO }, /* Internal Keyboard/Trackpad (ISO) */
58
+ { 0x216, APPLE_KEYBOARD_TYPE_JIS }, /* Internal Keyboard/Trackpad (JIS) */
59
+ { 0x217, APPLE_KEYBOARD_TYPE_ANSI }, /* Internal Keyboard/Trackpad (ANSI) */
60
+ { 0x218, APPLE_KEYBOARD_TYPE_ISO }, /* Internal Keyboard/Trackpad (ISO) */
61
+ { 0x219, APPLE_KEYBOARD_TYPE_JIS }, /* Internal Keyboard/Trackpad (JIS) */
62
+ { 0x21A, APPLE_KEYBOARD_TYPE_ANSI }, /* Internal Keyboard/Trackpad (ANSI) */
63
+ { 0x21B, APPLE_KEYBOARD_TYPE_ISO }, /* Internal Keyboard/Trackpad (ISO) */
64
+ { 0x21C, APPLE_KEYBOARD_TYPE_JIS }, /* Internal Keyboard/Trackpad (JIS) */
65
+ { 0x21D, APPLE_KEYBOARD_TYPE_ANSI }, /* Aluminum Mini Keyboard (ANSI) */
66
+ { 0x21E, APPLE_KEYBOARD_TYPE_ISO }, /* Aluminum Mini Keyboard (ISO) */
67
+ { 0x21F, APPLE_KEYBOARD_TYPE_JIS }, /* Aluminum Mini Keyboard (JIS) */
68
+ { 0x220, APPLE_KEYBOARD_TYPE_ANSI }, /* Aluminum Keyboard (ANSI) */
69
+ { 0x221, APPLE_KEYBOARD_TYPE_JIS }, /* Aluminum Keyboard (JIS) */
70
+ { 0x222, APPLE_KEYBOARD_TYPE_JIS }, /* Aluminum Keyboard (JIS) */
71
+ { 0x223, APPLE_KEYBOARD_TYPE_ANSI }, /* Internal Keyboard/Trackpad (ANSI) */
72
+ { 0x224, APPLE_KEYBOARD_TYPE_ISO }, /* Internal Keyboard/Trackpad (ISO) */
73
+ { 0x225, APPLE_KEYBOARD_TYPE_JIS }, /* Internal Keyboard/Trackpad (JIS) */
74
+ { 0x226, APPLE_KEYBOARD_TYPE_ANSI },
75
+ { 0x227, APPLE_KEYBOARD_TYPE_ANSI },
76
+ { 0x228, APPLE_KEYBOARD_TYPE_ANSI },
77
+ { 0x229, APPLE_KEYBOARD_TYPE_ANSI }, /* Internal Keyboard/Trackpad (MacBook Pro) (ANSI) */
78
+ { 0x22A, APPLE_KEYBOARD_TYPE_ISO }, /* Internal Keyboard/Trackpad (MacBook Pro) (ISO) */
79
+ { 0x22B, APPLE_KEYBOARD_TYPE_JIS }, /* Internal Keyboard/Trackpad (MacBook Pro) (JIS) */
80
+ { 0x22C, APPLE_KEYBOARD_TYPE_ANSI },
81
+ { 0x22D, APPLE_KEYBOARD_TYPE_ANSI },
82
+ { 0x22E, APPLE_KEYBOARD_TYPE_ANSI },
83
+ { 0x22F, APPLE_KEYBOARD_TYPE_ANSI },
84
+ { 0x230, APPLE_KEYBOARD_TYPE_ANSI }, /* Internal Keyboard/Trackpad (MacBook Pro 4,1) (ANSI) */
85
+ { 0x231, APPLE_KEYBOARD_TYPE_ISO }, /* Internal Keyboard/Trackpad (MacBook Pro 4,1) (ISO) */
86
+ { 0x232, APPLE_KEYBOARD_TYPE_JIS }, /* Internal Keyboard/Trackpad (MacBook Pro 4,1) (JIS) */
87
+ { 0x233, APPLE_KEYBOARD_TYPE_ANSI },
88
+ { 0x234, APPLE_KEYBOARD_TYPE_ANSI },
89
+ { 0x235, APPLE_KEYBOARD_TYPE_ANSI },
90
+ { 0x236, APPLE_KEYBOARD_TYPE_ANSI }, /* Internal Keyboard/Trackpad (ANSI) */
91
+ { 0x237, APPLE_KEYBOARD_TYPE_ISO }, /* Internal Keyboard/Trackpad (ISO) */
92
+ { 0x238, APPLE_KEYBOARD_TYPE_JIS }, /* Internal Keyboard/Trackpad (JIS) */
93
+ { 0x239, APPLE_KEYBOARD_TYPE_ANSI },
94
+ { 0x23A, APPLE_KEYBOARD_TYPE_ANSI },
95
+ { 0x23B, APPLE_KEYBOARD_TYPE_ANSI },
96
+ { 0x23C, APPLE_KEYBOARD_TYPE_ANSI },
97
+ { 0x23D, APPLE_KEYBOARD_TYPE_ANSI },
98
+ { 0x23E, APPLE_KEYBOARD_TYPE_ANSI },
99
+ { 0x23F, APPLE_KEYBOARD_TYPE_ANSI }, /* Internal Keyboard/Trackpad (ANSI) */
100
+ { 0x240, APPLE_KEYBOARD_TYPE_ISO }, /* Internal Keyboard/Trackpad (ISO) */
101
+ { 0x241, APPLE_KEYBOARD_TYPE_JIS }, /* Internal Keyboard/Trackpad (JIS) */
102
+ { 0x242, APPLE_KEYBOARD_TYPE_ANSI }, /* Internal Keyboard/Trackpad (ANSI) */
103
+ { 0x243, APPLE_KEYBOARD_TYPE_ISO }, /* Internal Keyboard/Trackpad (ISO) */
104
+ { 0x244, APPLE_KEYBOARD_TYPE_JIS }, /* Internal Keyboard/Trackpad (JIS) */
105
+ { 0x245, APPLE_KEYBOARD_TYPE_ANSI }, /* Internal Keyboard/Trackpad (ANSI) */
106
+ { 0x246, APPLE_KEYBOARD_TYPE_ISO }, /* Internal Keyboard/Trackpad (ISO) */
107
+ { 0x247, APPLE_KEYBOARD_TYPE_JIS }, /* Internal Keyboard/Trackpad (JIS) */
108
+ { 0x248, APPLE_KEYBOARD_TYPE_ANSI },
109
+ { 0x249, APPLE_KEYBOARD_TYPE_ANSI },
110
+ { 0x24A, APPLE_KEYBOARD_TYPE_ISO }, /* Internal Keyboard/Trackpad (MacBook Air) (ISO) */
111
+ { 0x24B, APPLE_KEYBOARD_TYPE_ANSI },
112
+ { 0x24C, APPLE_KEYBOARD_TYPE_ANSI },
113
+ { 0x24D, APPLE_KEYBOARD_TYPE_ISO }, /* Internal Keyboard/Trackpad (MacBook Air) (ISO) */
114
+ { 0x24E, APPLE_KEYBOARD_TYPE_ANSI },
115
+ { 0x24F, APPLE_KEYBOARD_TYPE_ANSI },
116
+ { 0x250, APPLE_KEYBOARD_TYPE_ISO }, /* Aluminium Keyboard (ISO) */
117
+ { 0x251, APPLE_KEYBOARD_TYPE_ANSI },
118
+ { 0x252, APPLE_KEYBOARD_TYPE_ANSI }, /* Internal Keyboard/Trackpad (ANSI) */
119
+ { 0x253, APPLE_KEYBOARD_TYPE_ISO }, /* Internal Keyboard/Trackpad (ISO) */
120
+ { 0x254, APPLE_KEYBOARD_TYPE_JIS }, /* Internal Keyboard/Trackpad (JIS) */
121
+ { 0x255, APPLE_KEYBOARD_TYPE_ANSI },
122
+ { 0x256, APPLE_KEYBOARD_TYPE_ANSI },
123
+ { 0x257, APPLE_KEYBOARD_TYPE_ANSI },
124
+ { 0x258, APPLE_KEYBOARD_TYPE_ANSI },
125
+ { 0x259, APPLE_KEYBOARD_TYPE_ANSI },
126
+ { 0x25A, APPLE_KEYBOARD_TYPE_ANSI },
127
+ { 0x25B, APPLE_KEYBOARD_TYPE_ANSI },
128
+ { 0x25C, APPLE_KEYBOARD_TYPE_ANSI },
129
+ { 0x25D, APPLE_KEYBOARD_TYPE_ANSI },
130
+ { 0x25E, APPLE_KEYBOARD_TYPE_ANSI },
131
+ { 0x25F, APPLE_KEYBOARD_TYPE_ANSI },
132
+ { 0x260, APPLE_KEYBOARD_TYPE_ANSI },
133
+ { 0x261, APPLE_KEYBOARD_TYPE_ANSI },
134
+ { 0x262, APPLE_KEYBOARD_TYPE_ANSI },
135
+ { 0x263, APPLE_KEYBOARD_TYPE_ANSI }, /* Apple Internal Keyboard / Trackpad (MacBook Retina) */
136
+ { 0x264, APPLE_KEYBOARD_TYPE_ANSI },
137
+ { 0x265, APPLE_KEYBOARD_TYPE_ANSI },
138
+ { 0x266, APPLE_KEYBOARD_TYPE_ANSI },
139
+ { 0x267, APPLE_KEYBOARD_TYPE_ANSI },
140
+ { 0x268, APPLE_KEYBOARD_TYPE_ANSI },
141
+ { 0x269, APPLE_KEYBOARD_TYPE_ANSI },
142
+ { 0x26A, APPLE_KEYBOARD_TYPE_ANSI }
143
+ };
144
+
145
+ static enum APPLE_KEYBOARD_TYPE mac_identify_keyboard_type(uint32_t vendorID, uint32_t productID)
146
+ {
147
+ enum APPLE_KEYBOARD_TYPE type = APPLE_KEYBOARD_TYPE_ANSI;
148
+
149
+ if (vendorID != 0x05AC) /* Apple, Inc. */
150
+ return type;
151
+
152
+ if ((productID < 0x200) || (productID > 0x26A))
153
+ return type;
154
+
155
+ type = APPLE_KEYBOARDS[productID - 0x200].Type;
156
+ return type;
157
+ }
158
+
159
+ enum APPLE_KEYBOARD_TYPE mac_detect_keyboard_type(void)
160
+ {
161
+ CFSetRef deviceCFSetRef = NULL;
162
+ IOHIDDeviceRef inIOHIDDeviceRef = NULL;
163
+ IOHIDManagerRef tIOHIDManagerRef = NULL;
164
+ IOHIDDeviceRef *tIOHIDDeviceRefs = nil;
165
+ enum APPLE_KEYBOARD_TYPE type = APPLE_KEYBOARD_TYPE_ANSI;
166
+ tIOHIDManagerRef = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
167
+
168
+ if (!tIOHIDManagerRef)
169
+ return type;
170
+
171
+ IOHIDManagerSetDeviceMatching(tIOHIDManagerRef, NULL);
172
+ IOReturn tIOReturn = IOHIDManagerOpen(tIOHIDManagerRef, kIOHIDOptionsTypeNone);
173
+
174
+ if (noErr != tIOReturn)
175
+ return type;
176
+
177
+ deviceCFSetRef = IOHIDManagerCopyDevices(tIOHIDManagerRef);
178
+
179
+ if (!deviceCFSetRef)
180
+ return type;
181
+
182
+ CFIndex deviceIndex, deviceCount = CFSetGetCount(deviceCFSetRef);
183
+ tIOHIDDeviceRefs = malloc(sizeof(IOHIDDeviceRef) * deviceCount);
184
+
185
+ if (!tIOHIDDeviceRefs)
186
+ return type;
187
+
188
+ CFSetGetValues(deviceCFSetRef, (const void **)tIOHIDDeviceRefs);
189
+ CFRelease(deviceCFSetRef);
190
+ deviceCFSetRef = NULL;
191
+
192
+ for (deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++)
193
+ {
194
+ CFTypeRef tCFTypeRef;
195
+ uint32_t vendorID = 0;
196
+ uint32_t productID = 0;
197
+ uint32_t countryCode = 0;
198
+ enum APPLE_KEYBOARD_TYPE ltype;
199
+
200
+ if (!tIOHIDDeviceRefs[deviceIndex])
201
+ continue;
202
+
203
+ inIOHIDDeviceRef = tIOHIDDeviceRefs[deviceIndex];
204
+ tCFTypeRef = IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDVendorIDKey));
205
+
206
+ if (tCFTypeRef)
207
+ CFNumberGetValue((CFNumberRef)tCFTypeRef, kCFNumberSInt32Type, &vendorID);
208
+
209
+ tCFTypeRef = IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDProductIDKey));
210
+
211
+ if (tCFTypeRef)
212
+ CFNumberGetValue((CFNumberRef)tCFTypeRef, kCFNumberSInt32Type, &productID);
213
+
214
+ tCFTypeRef = IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDCountryCodeKey));
215
+
216
+ if (tCFTypeRef)
217
+ CFNumberGetValue((CFNumberRef)tCFTypeRef, kCFNumberSInt32Type, &countryCode);
218
+
219
+ ltype = mac_identify_keyboard_type(vendorID, productID);
220
+
221
+ if (ltype != APPLE_KEYBOARD_TYPE_ANSI)
222
+ {
223
+ type = ltype;
224
+ break;
225
+ }
226
+ }
227
+
228
+ free(tIOHIDDeviceRefs);
229
+
230
+ if (deviceCFSetRef)
231
+ {
232
+ CFRelease(deviceCFSetRef);
233
+ deviceCFSetRef = NULL;
234
+ }
235
+
236
+ if (tIOHIDManagerRef)
237
+ CFRelease(tIOHIDManagerRef);
238
+
239
+ return type;
240
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Mac/MRDPCursor.h ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * MacFreeRDP
4
+ *
5
+ * Copyright 2012 Thomas Goddard
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #import <Cocoa/Cocoa.h>
21
+
22
+ #include "freerdp/graphics.h"
23
+
24
+ @interface MRDPCursor : NSObject
25
+ {
26
+ @public
27
+ rdpPointer *pointer;
28
+ BYTE *cursor_data;
29
+ NSBitmapImageRep *bmiRep;
30
+ NSCursor *nsCursor;
31
+ NSImage *nsImage;
32
+ }
33
+
34
+ @end
local-test-freerdp-delta-01/afc-freerdp/client/Mac/MRDPCursor.m ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * MacFreeRDP
4
+ *
5
+ * Copyright 2012 Thomas Goddard
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #import "MRDPCursor.h"
21
+
22
+ @implementation MRDPCursor
23
+
24
+ @end
local-test-freerdp-delta-01/afc-freerdp/client/Mac/MRDPView.h ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef FREERDP_CLIENT_MAC_MRDPVIEW_H
2
+ #define FREERDP_CLIENT_MAC_MRDPVIEW_H
3
+
4
+ /**
5
+ * FreeRDP: A Remote Desktop Protocol Implementation
6
+ * MacFreeRDP
7
+ *
8
+ * Copyright 2012 Thomas Goddard
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+
23
+ #import <Cocoa/Cocoa.h>
24
+
25
+ #import "mfreerdp.h"
26
+ #import "mf_client.h"
27
+ #import "Keyboard.h"
28
+
29
+ #import <CoreGraphics/CoreGraphics.h>
30
+
31
+ @interface MRDPView : NSView
32
+ {
33
+ mfContext *mfc;
34
+ NSBitmapImageRep *bmiRep;
35
+ NSMutableArray *cursors;
36
+ NSMutableArray *windows;
37
+ NSTimer *pasteboard_timer;
38
+ NSCursor *currentCursor;
39
+ NSRect prevWinPosition;
40
+ freerdp *instance;
41
+ rdpContext *context;
42
+ CGContextRef bitmap_context;
43
+ char *pixel_data;
44
+ int argc;
45
+ char **argv;
46
+ DWORD kbdModFlags;
47
+ BOOL initialized;
48
+ NSPoint savedDragLocation;
49
+ BOOL firstCreateWindow;
50
+ BOOL isMoveSizeInProgress;
51
+ BOOL skipResizeOnce;
52
+ BOOL saveInitialDragLoc;
53
+ BOOL skipMoveWindowOnce;
54
+ @public
55
+ NSPasteboard *pasteboard_rd;
56
+ NSPasteboard *pasteboard_wr;
57
+ int pasteboard_changecount;
58
+ int pasteboard_format;
59
+ int is_connected;
60
+ }
61
+
62
+ - (int)rdpStart:(rdpContext *)rdp_context;
63
+ - (void)setCursor:(NSCursor *)cursor;
64
+ - (void)setScrollOffset:(int)xOffset y:(int)yOffset w:(int)width h:(int)height;
65
+
66
+ - (void)onPasteboardTimerFired:(NSTimer *)timer;
67
+ - (void)pause;
68
+ - (void)resume;
69
+ - (void)releaseResources;
70
+
71
+ @property(assign) int is_connected;
72
+
73
+ @end
74
+
75
+ BOOL mac_pre_connect(freerdp *instance);
76
+ BOOL mac_post_connect(freerdp *instance);
77
+ void mac_post_disconnect(freerdp *instance);
78
+ BOOL mac_authenticate_ex(freerdp *instance, char **username, char **password, char **domain,
79
+ rdp_auth_reason reason);
80
+
81
+ DWORD mac_verify_certificate_ex(freerdp *instance, const char *host, UINT16 port,
82
+ const char *common_name, const char *subject, const char *issuer,
83
+ const char *fingerprint, DWORD flags);
84
+ DWORD mac_verify_changed_certificate_ex(freerdp *instance, const char *host, UINT16 port,
85
+ const char *common_name, const char *subject,
86
+ const char *issuer, const char *fingerprint,
87
+ const char *old_subject, const char *old_issuer,
88
+ const char *old_fingerprint, DWORD flags);
89
+
90
+ int mac_logon_error_info(freerdp *instance, UINT32 data, UINT32 type);
91
+ #endif /* FREERDP_CLIENT_MAC_MRDPVIEW_H */
local-test-freerdp-delta-01/afc-freerdp/client/Mac/MRDPView.m ADDED
@@ -0,0 +1,1534 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * MacFreeRDP
4
+ *
5
+ * Copyright 2012 Thomas Goddard
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #include <winpr/windows.h>
21
+
22
+ #include "mf_client.h"
23
+ #import "mfreerdp.h"
24
+ #import "MRDPView.h"
25
+ #import "MRDPCursor.h"
26
+ #import "Clipboard.h"
27
+ #import "PasswordDialog.h"
28
+ #import "CertificateDialog.h"
29
+
30
+ #include <winpr/crt.h>
31
+ #include <winpr/assert.h>
32
+ #include <winpr/input.h>
33
+ #include <winpr/synch.h>
34
+ #include <winpr/sysinfo.h>
35
+
36
+ #include <freerdp/constants.h>
37
+
38
+ #import "freerdp/freerdp.h"
39
+ #import "freerdp/types.h"
40
+ #import "freerdp/config.h"
41
+ #import "freerdp/channels/channels.h"
42
+ #import "freerdp/gdi/gdi.h"
43
+ #import "freerdp/gdi/dc.h"
44
+ #import "freerdp/gdi/region.h"
45
+ #import "freerdp/graphics.h"
46
+ #import "freerdp/client/file.h"
47
+ #import "freerdp/client/cmdline.h"
48
+ #import "freerdp/log.h"
49
+
50
+ #import <CoreGraphics/CoreGraphics.h>
51
+
52
+ #define TAG CLIENT_TAG("mac")
53
+
54
+ static BOOL mf_Pointer_New(rdpContext *context, rdpPointer *pointer);
55
+ static void mf_Pointer_Free(rdpContext *context, rdpPointer *pointer);
56
+ static BOOL mf_Pointer_Set(rdpContext *context, rdpPointer *pointer);
57
+ static BOOL mf_Pointer_SetNull(rdpContext *context);
58
+ static BOOL mf_Pointer_SetDefault(rdpContext *context);
59
+ static BOOL mf_Pointer_SetPosition(rdpContext *context, UINT32 x, UINT32 y);
60
+
61
+ static BOOL mac_begin_paint(rdpContext *context);
62
+ static BOOL mac_end_paint(rdpContext *context);
63
+ static BOOL mac_desktop_resize(rdpContext *context);
64
+
65
+ static void input_activity_cb(freerdp *instance);
66
+
67
+ static DWORD WINAPI mac_client_thread(void *param);
68
+ static void windows_to_apple_cords(MRDPView *view, NSRect *r);
69
+ static CGContextRef mac_create_bitmap_context(rdpContext *context);
70
+
71
+ @implementation MRDPView
72
+
73
+ @synthesize is_connected;
74
+
75
+ - (int)rdpStart:(rdpContext *)rdp_context
76
+ {
77
+ rdpSettings *settings;
78
+ EmbedWindowEventArgs e;
79
+ [self initializeView];
80
+
81
+ WINPR_ASSERT(rdp_context);
82
+ context = rdp_context;
83
+ mfc = (mfContext *)rdp_context;
84
+
85
+ instance = context->instance;
86
+ WINPR_ASSERT(instance);
87
+
88
+ settings = context->settings;
89
+ WINPR_ASSERT(settings);
90
+
91
+ EventArgsInit(&e, "mfreerdp");
92
+ e.embed = TRUE;
93
+ e.handle = (void *)self;
94
+ PubSub_OnEmbedWindow(context->pubSub, context, &e);
95
+ NSScreen *screen = [[NSScreen screens] objectAtIndex:0];
96
+ NSRect screenFrame = [screen frame];
97
+
98
+ if (freerdp_settings_get_bool(settings, FreeRDP_Fullscreen))
99
+ {
100
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, screenFrame.size.width))
101
+ return -1;
102
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, screenFrame.size.height))
103
+ return -1;
104
+ [self enterFullScreenMode:[NSScreen mainScreen] withOptions:nil];
105
+ }
106
+ else
107
+ {
108
+ [self exitFullScreenModeWithOptions:nil];
109
+ }
110
+
111
+ mfc->client_height = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
112
+ mfc->client_width = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
113
+
114
+ if (!(mfc->common.thread =
115
+ CreateThread(NULL, 0, mac_client_thread, (void *)context, 0, &mfc->mainThreadId)))
116
+ {
117
+ WLog_ERR(TAG, "failed to create client thread");
118
+ return -1;
119
+ }
120
+
121
+ return 0;
122
+ }
123
+
124
+ DWORD WINAPI mac_client_thread(void *param)
125
+ {
126
+ @autoreleasepool
127
+ {
128
+ int status;
129
+ DWORD rc;
130
+ HANDLE events[16] = { 0 };
131
+ HANDLE inputEvent;
132
+ DWORD nCount;
133
+ DWORD nCountTmp;
134
+ DWORD nCountBase;
135
+ rdpContext *context = (rdpContext *)param;
136
+ mfContext *mfc = (mfContext *)context;
137
+ freerdp *instance = context->instance;
138
+ MRDPView *view = mfc->view;
139
+ rdpSettings *settings = context->settings;
140
+ status = freerdp_connect(context->instance);
141
+
142
+ if (!status)
143
+ {
144
+ [view setIs_connected:0];
145
+ return 0;
146
+ }
147
+
148
+ [view setIs_connected:1];
149
+ nCount = 0;
150
+ events[nCount++] = mfc->stopEvent;
151
+
152
+ if (!(inputEvent =
153
+ freerdp_get_message_queue_event_handle(instance, FREERDP_INPUT_MESSAGE_QUEUE)))
154
+ {
155
+ WLog_ERR(TAG, "failed to get input event handle");
156
+ goto disconnect;
157
+ }
158
+
159
+ events[nCount++] = inputEvent;
160
+
161
+ nCountBase = nCount;
162
+
163
+ while (!freerdp_shall_disconnect_context(instance->context))
164
+ {
165
+ nCount = nCountBase;
166
+ {
167
+ if (!(nCountTmp = freerdp_get_event_handles(context, &events[nCount], 16 - nCount)))
168
+ {
169
+ WLog_ERR(TAG, "freerdp_get_event_handles failed");
170
+ break;
171
+ }
172
+
173
+ nCount += nCountTmp;
174
+ }
175
+ rc = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
176
+
177
+ if (rc >= (WAIT_OBJECT_0 + nCount))
178
+ {
179
+ WLog_ERR(TAG, "WaitForMultipleObjects failed (0x%08X)", rc);
180
+ break;
181
+ }
182
+
183
+ if (rc == WAIT_OBJECT_0)
184
+ {
185
+ /* stop event triggered */
186
+ break;
187
+ }
188
+
189
+ if (WaitForSingleObject(inputEvent, 0) == WAIT_OBJECT_0)
190
+ {
191
+ input_activity_cb(instance);
192
+ }
193
+
194
+ {
195
+ if (!freerdp_check_event_handles(context))
196
+ {
197
+ WLog_ERR(TAG, "freerdp_check_event_handles failed");
198
+ break;
199
+ }
200
+ }
201
+ }
202
+
203
+ disconnect:
204
+ [view setIs_connected:0];
205
+ freerdp_disconnect(instance);
206
+
207
+ ExitThread(0);
208
+ return 0;
209
+ }
210
+ }
211
+
212
+ - (id)initWithFrame:(NSRect)frame
213
+ {
214
+ self = [super initWithFrame:frame];
215
+
216
+ if (self)
217
+ {
218
+ // Initialization code here.
219
+ }
220
+
221
+ return self;
222
+ }
223
+
224
+ - (void)viewDidLoad
225
+ {
226
+ [self initializeView];
227
+ }
228
+
229
+ - (void)initializeView
230
+ {
231
+ if (!initialized)
232
+ {
233
+ cursors = [[NSMutableArray alloc] initWithCapacity:10];
234
+ // setup a mouse tracking area
235
+ NSTrackingArea *trackingArea = [[NSTrackingArea alloc]
236
+ initWithRect:[self visibleRect]
237
+ options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved |
238
+ NSTrackingCursorUpdate | NSTrackingEnabledDuringMouseDrag |
239
+ NSTrackingActiveWhenFirstResponder
240
+ owner:self
241
+ userInfo:nil];
242
+ [self addTrackingArea:trackingArea];
243
+ // Set the default cursor
244
+ currentCursor = [NSCursor arrowCursor];
245
+ initialized = YES;
246
+ }
247
+ }
248
+
249
+ - (void)setCursor:(NSCursor *)cursor
250
+ {
251
+ self->currentCursor = cursor;
252
+ dispatch_async(dispatch_get_main_queue(), ^{
253
+ [[self window] invalidateCursorRectsForView:self];
254
+ });
255
+ }
256
+
257
+ - (void)resetCursorRects
258
+ {
259
+ [self addCursorRect:[self visibleRect] cursor:currentCursor];
260
+ }
261
+
262
+ - (BOOL)acceptsFirstResponder
263
+ {
264
+ return YES;
265
+ }
266
+
267
+ - (void)mouseMoved:(NSEvent *)event
268
+ {
269
+ [super mouseMoved:event];
270
+
271
+ if (!self.is_connected)
272
+ return;
273
+
274
+ NSPoint loc = [event locationInWindow];
275
+ int x = (int)loc.x;
276
+ int y = (int)loc.y;
277
+ mf_scale_mouse_event(context, PTR_FLAGS_MOVE, x, y);
278
+ }
279
+
280
+ - (void)mouseDown:(NSEvent *)event
281
+ {
282
+ [super mouseDown:event];
283
+
284
+ if (!self.is_connected)
285
+ return;
286
+
287
+ NSPoint loc = [event locationInWindow];
288
+ int x = (int)loc.x;
289
+ int y = (int)loc.y;
290
+ mf_press_mouse_button(context, 0, x, y, TRUE);
291
+ }
292
+
293
+ - (void)mouseUp:(NSEvent *)event
294
+ {
295
+ [super mouseUp:event];
296
+
297
+ if (!self.is_connected)
298
+ return;
299
+
300
+ NSPoint loc = [event locationInWindow];
301
+ int x = (int)loc.x;
302
+ int y = (int)loc.y;
303
+ mf_press_mouse_button(context, 0, x, y, FALSE);
304
+ }
305
+
306
+ - (void)rightMouseDown:(NSEvent *)event
307
+ {
308
+ [super rightMouseDown:event];
309
+
310
+ if (!self.is_connected)
311
+ return;
312
+
313
+ NSPoint loc = [event locationInWindow];
314
+ int x = (int)loc.x;
315
+ int y = (int)loc.y;
316
+ mf_press_mouse_button(context, 1, x, y, TRUE);
317
+ }
318
+
319
+ - (void)rightMouseUp:(NSEvent *)event
320
+ {
321
+ [super rightMouseUp:event];
322
+
323
+ if (!self.is_connected)
324
+ return;
325
+
326
+ NSPoint loc = [event locationInWindow];
327
+ int x = (int)loc.x;
328
+ int y = (int)loc.y;
329
+ mf_press_mouse_button(context, 1, x, y, FALSE);
330
+ }
331
+
332
+ - (void)otherMouseDown:(NSEvent *)event
333
+ {
334
+ [super otherMouseDown:event];
335
+
336
+ if (!self.is_connected)
337
+ return;
338
+
339
+ NSPoint loc = [event locationInWindow];
340
+ int x = (int)loc.x;
341
+ int y = (int)loc.y;
342
+ int pressed = [event buttonNumber];
343
+ mf_press_mouse_button(context, pressed, x, y, TRUE);
344
+ }
345
+
346
+ - (void)otherMouseUp:(NSEvent *)event
347
+ {
348
+ [super otherMouseUp:event];
349
+
350
+ if (!self.is_connected)
351
+ return;
352
+
353
+ NSPoint loc = [event locationInWindow];
354
+ int x = (int)loc.x;
355
+ int y = (int)loc.y;
356
+ int pressed = [event buttonNumber];
357
+ mf_press_mouse_button(context, pressed, x, y, FALSE);
358
+ }
359
+
360
+ - (void)scrollWheel:(NSEvent *)event
361
+ {
362
+ UINT16 flags;
363
+ [super scrollWheel:event];
364
+
365
+ if (!self.is_connected)
366
+ return;
367
+
368
+ float dx = [event deltaX];
369
+ float dy = [event deltaY];
370
+ /* 1 event = 120 units */
371
+ UINT16 units = 0;
372
+
373
+ if (fabsf(dy) > FLT_EPSILON)
374
+ {
375
+ flags = PTR_FLAGS_WHEEL;
376
+ units = fabsf(dy) * 120;
377
+
378
+ if (dy < 0)
379
+ flags |= PTR_FLAGS_WHEEL_NEGATIVE;
380
+ }
381
+ else if (fabsf(dx) > FLT_EPSILON)
382
+ {
383
+ flags = PTR_FLAGS_HWHEEL;
384
+ units = fabsf(dx) * 120;
385
+
386
+ if (dx > 0)
387
+ flags |= PTR_FLAGS_WHEEL_NEGATIVE;
388
+ }
389
+ else
390
+ return;
391
+
392
+ /* Wheel rotation steps:
393
+ *
394
+ * positive: 0 ... 0xFF -> slow ... fast
395
+ * negative: 0 ... 0xFF -> fast ... slow
396
+ */
397
+ UINT16 step = units;
398
+ if (step > 0xFF)
399
+ step = 0xFF;
400
+
401
+ /* Negative rotation, so count down steps from top
402
+ * 9bit twos complement */
403
+ if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
404
+ step = 0x100 - step;
405
+
406
+ mf_scale_mouse_event(context, flags | step, 0, 0);
407
+ }
408
+
409
+ - (void)mouseDragged:(NSEvent *)event
410
+ {
411
+ [super mouseDragged:event];
412
+
413
+ if (!self.is_connected)
414
+ return;
415
+
416
+ NSPoint loc = [event locationInWindow];
417
+ int x = (int)loc.x;
418
+ int y = (int)loc.y;
419
+ // send mouse motion event to RDP server
420
+ mf_scale_mouse_event(context, PTR_FLAGS_MOVE, x, y);
421
+ }
422
+
423
+ static DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type)
424
+ {
425
+ /**
426
+ * In 99% of cases, the given key code is truly keyboard independent.
427
+ * This function handles the remaining 1% of edge cases.
428
+ *
429
+ * Hungarian Keyboard: This is 'QWERTZ' and not 'QWERTY'.
430
+ * The '0' key is on the left of the '1' key, where '~' is on a US keyboard.
431
+ * A special 'i' letter key with acute is found on the right of the left shift key.
432
+ * On the hungarian keyboard, the 'i' key is at the left of the 'Y' key
433
+ * Some international keyboards have a corresponding key which would be at
434
+ * the left of the 'Z' key when using a QWERTY layout.
435
+ *
436
+ * The Apple Hungarian keyboard sends inverted key codes for the '0' and 'i' keys.
437
+ * When using the US keyboard layout, key codes are left as-is (inverted).
438
+ * When using the Hungarian keyboard layout, key codes are swapped (non-inverted).
439
+ * This means that when using the Hungarian keyboard layout with a US keyboard,
440
+ * the keys corresponding to '0' and 'i' will effectively be inverted.
441
+ *
442
+ * To fix the '0' and 'i' key inversion, we use the corresponding output character
443
+ * provided by OS X and check for a character to key code mismatch: for instance,
444
+ * when the output character is '0' for the key code corresponding to the 'i' key.
445
+ */
446
+ #if 0
447
+ switch (keyChar)
448
+ {
449
+ case '0':
450
+ case 0x00A7: /* section sign */
451
+ if (keyCode == APPLE_VK_ISO_Section)
452
+ keyCode = APPLE_VK_ANSI_Grave;
453
+
454
+ break;
455
+
456
+ case 0x00ED: /* latin small letter i with acute */
457
+ case 0x00CD: /* latin capital letter i with acute */
458
+ if (keyCode == APPLE_VK_ANSI_Grave)
459
+ keyCode = APPLE_VK_ISO_Section;
460
+
461
+ break;
462
+ }
463
+
464
+ #endif
465
+
466
+ /* Perform keycode correction for all ISO keyboards */
467
+
468
+ if (type == APPLE_KEYBOARD_TYPE_ISO)
469
+ {
470
+ if (keyCode == APPLE_VK_ANSI_Grave)
471
+ keyCode = APPLE_VK_ISO_Section;
472
+ else if (keyCode == APPLE_VK_ISO_Section)
473
+ keyCode = APPLE_VK_ANSI_Grave;
474
+ }
475
+
476
+ return keyCode;
477
+ }
478
+
479
+ - (void)flagsChanged:(NSEvent *)event
480
+ {
481
+ if (!is_connected)
482
+ return;
483
+
484
+ DWORD modFlags = [event modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask;
485
+
486
+ WINPR_ASSERT(instance);
487
+ WINPR_ASSERT(instance->context);
488
+
489
+ rdpInput *input = instance->context->input;
490
+
491
+ #if defined(WITH_DEBUG_KBD)
492
+ WLog_DBG(TAG, "flagsChanged: modFlags: 0x%04X kbdModFlags: 0x%04X", modFlags, kbdModFlags);
493
+ #endif
494
+
495
+ updateFlagStates(input, modFlags, kbdModFlags);
496
+ kbdModFlags = modFlags;
497
+ }
498
+
499
+ - (void)keyDown:(NSEvent *)event
500
+ {
501
+ DWORD keyCode;
502
+ DWORD keyFlags;
503
+ DWORD vkcode;
504
+ DWORD scancode;
505
+ unichar keyChar;
506
+ NSString *characters;
507
+
508
+ if (!is_connected)
509
+ return;
510
+
511
+ [self flagsChanged:event];
512
+
513
+ keyFlags = KBD_FLAGS_DOWN;
514
+ keyCode = [event keyCode];
515
+ characters = [event charactersIgnoringModifiers];
516
+
517
+ if ([characters length] > 0)
518
+ {
519
+ keyChar = [characters characterAtIndex:0];
520
+ keyCode = fixKeyCode(keyCode, keyChar, mfc->appleKeyboardType);
521
+ }
522
+
523
+ vkcode = GetVirtualKeyCodeFromKeycode(keyCode, WINPR_KEYCODE_TYPE_APPLE);
524
+ scancode = GetVirtualScanCodeFromVirtualKeyCode(vkcode, 4);
525
+ keyFlags |= (scancode & KBDEXT) ? KBDEXT : 0;
526
+ scancode &= 0xFF;
527
+ vkcode &= 0xFF;
528
+
529
+ #if defined(WITH_DEBUG_KBD)
530
+ WLog_DBG(TAG, "keyDown: keyCode: 0x%04X scancode: 0x%04X vkcode: 0x%04X keyFlags: %d name: %s",
531
+ keyCode, scancode, vkcode, keyFlags, GetVirtualKeyName(vkcode));
532
+ #endif
533
+
534
+ WINPR_ASSERT(instance->context);
535
+ freerdp_input_send_keyboard_event(instance->context->input, keyFlags, scancode);
536
+ }
537
+
538
+ - (void)keyUp:(NSEvent *)event
539
+ {
540
+ DWORD keyCode;
541
+ DWORD keyFlags;
542
+ DWORD vkcode;
543
+ DWORD scancode;
544
+ unichar keyChar;
545
+ NSString *characters;
546
+
547
+ if (!is_connected)
548
+ return;
549
+
550
+ [self flagsChanged:event];
551
+
552
+ keyFlags = KBD_FLAGS_RELEASE;
553
+ keyCode = [event keyCode];
554
+ characters = [event charactersIgnoringModifiers];
555
+
556
+ if ([characters length] > 0)
557
+ {
558
+ keyChar = [characters characterAtIndex:0];
559
+ keyCode = fixKeyCode(keyCode, keyChar, mfc->appleKeyboardType);
560
+ }
561
+
562
+ vkcode = GetVirtualKeyCodeFromKeycode(keyCode, WINPR_KEYCODE_TYPE_APPLE);
563
+ scancode = GetVirtualScanCodeFromVirtualKeyCode(vkcode, 4);
564
+ keyFlags |= (scancode & KBDEXT) ? KBDEXT : 0;
565
+ scancode &= 0xFF;
566
+ vkcode &= 0xFF;
567
+ #if defined(WITH_DEBUG_KBD)
568
+ WLog_DBG(TAG, "keyUp: key: 0x%04X scancode: 0x%04X vkcode: 0x%04X keyFlags: %d name: %s",
569
+ keyCode, scancode, vkcode, keyFlags, GetVirtualKeyName(vkcode));
570
+ #endif
571
+ WINPR_ASSERT(instance->context);
572
+ freerdp_input_send_keyboard_event(instance->context->input, keyFlags, scancode);
573
+ }
574
+
575
+ static BOOL updateFlagState(rdpInput *input, DWORD modFlags, DWORD aKbdModFlags, DWORD flag)
576
+ {
577
+ BOOL press = ((modFlags & flag) != 0) && ((aKbdModFlags & flag) == 0);
578
+ BOOL release = ((modFlags & flag) == 0) && ((aKbdModFlags & flag) != 0);
579
+ DWORD keyFlags = 0;
580
+ const char *name = NULL;
581
+ DWORD scancode = 0;
582
+
583
+ if ((modFlags & flag) == (aKbdModFlags & flag))
584
+ return TRUE;
585
+
586
+ switch (flag)
587
+ {
588
+ case NSEventModifierFlagCapsLock:
589
+ name = "NSEventModifierFlagCapsLock";
590
+ scancode = RDP_SCANCODE_CAPSLOCK;
591
+ release = press = TRUE;
592
+ break;
593
+ case NSEventModifierFlagShift:
594
+ name = "NSEventModifierFlagShift";
595
+ scancode = RDP_SCANCODE_LSHIFT;
596
+ break;
597
+
598
+ case NSEventModifierFlagControl:
599
+ name = "NSEventModifierFlagControl";
600
+ scancode = RDP_SCANCODE_LCONTROL;
601
+ break;
602
+
603
+ case NSEventModifierFlagOption:
604
+ name = "NSEventModifierFlagOption";
605
+ scancode = RDP_SCANCODE_LMENU;
606
+ break;
607
+
608
+ case NSEventModifierFlagCommand:
609
+ name = "NSEventModifierFlagCommand";
610
+ scancode = RDP_SCANCODE_LWIN;
611
+ break;
612
+
613
+ case NSEventModifierFlagNumericPad:
614
+ name = "NSEventModifierFlagNumericPad";
615
+ scancode = RDP_SCANCODE_NUMLOCK;
616
+ release = press = TRUE;
617
+ break;
618
+
619
+ case NSEventModifierFlagHelp:
620
+ name = "NSEventModifierFlagHelp";
621
+ scancode = RDP_SCANCODE_HELP;
622
+ break;
623
+
624
+ case NSEventModifierFlagFunction:
625
+ name = "NSEventModifierFlagFunction";
626
+ scancode = RDP_SCANCODE_HELP;
627
+ break;
628
+
629
+ default:
630
+ WLog_ERR(TAG, "Invalid flag: 0x%08" PRIx32 ", not supported", flag);
631
+ return FALSE;
632
+ }
633
+
634
+ keyFlags = (scancode & KBDEXT);
635
+ scancode &= 0xFF;
636
+
637
+ #if defined(WITH_DEBUG_KBD)
638
+ if (press || release)
639
+ WLog_DBG(TAG, "changing flag %s[0x%08" PRIx32 "] to %s", name, flag,
640
+ press ? "DOWN" : "RELEASE");
641
+ #endif
642
+
643
+ if (press)
644
+ {
645
+ if (!freerdp_input_send_keyboard_event(input, keyFlags | KBD_FLAGS_DOWN, scancode))
646
+ return FALSE;
647
+ }
648
+
649
+ if (release)
650
+ {
651
+ if (!freerdp_input_send_keyboard_event(input, keyFlags | KBD_FLAGS_RELEASE, scancode))
652
+ return FALSE;
653
+ }
654
+
655
+ return TRUE;
656
+ }
657
+
658
+ static BOOL updateFlagStates(rdpInput *input, UINT32 modFlags, UINT32 aKbdModFlags)
659
+ {
660
+ updateFlagState(input, modFlags, aKbdModFlags, NSEventModifierFlagCapsLock);
661
+ updateFlagState(input, modFlags, aKbdModFlags, NSEventModifierFlagShift);
662
+ updateFlagState(input, modFlags, aKbdModFlags, NSEventModifierFlagControl);
663
+ updateFlagState(input, modFlags, aKbdModFlags, NSEventModifierFlagOption);
664
+ updateFlagState(input, modFlags, aKbdModFlags, NSEventModifierFlagCommand);
665
+ updateFlagState(input, modFlags, aKbdModFlags, NSEventModifierFlagNumericPad);
666
+ return TRUE;
667
+ }
668
+
669
+ static BOOL releaseFlagStates(rdpInput *input, UINT32 aKbdModFlags)
670
+ {
671
+ return updateFlagStates(input, 0, aKbdModFlags);
672
+ }
673
+
674
+ - (void)releaseResources
675
+ {
676
+ for (int i = 0; i < argc; i++)
677
+ free(argv[i]);
678
+
679
+ if (!is_connected)
680
+ return;
681
+
682
+ free(pixel_data);
683
+ }
684
+
685
+ - (void)drawRect:(NSRect)rect
686
+ {
687
+ if (!context)
688
+ return;
689
+
690
+ if (self->bitmap_context)
691
+ {
692
+ CGContextRef cgContext = [[NSGraphicsContext currentContext] CGContext];
693
+ CGImageRef cgImage = CGBitmapContextCreateImage(self->bitmap_context);
694
+ CGContextSaveGState(cgContext);
695
+ CGContextClipToRect(
696
+ cgContext, CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height));
697
+ CGContextDrawImage(cgContext,
698
+ CGRectMake(0, 0, [self bounds].size.width, [self bounds].size.height),
699
+ cgImage);
700
+ CGContextRestoreGState(cgContext);
701
+ CGImageRelease(cgImage);
702
+ }
703
+ else
704
+ {
705
+ /* Fill the screen with black */
706
+ [[NSColor blackColor] set];
707
+ NSRectFill([self bounds]);
708
+ }
709
+ }
710
+
711
+ - (void)onPasteboardTimerFired:(NSTimer *)timer
712
+ {
713
+ UINT32 formatId;
714
+ BOOL formatMatch;
715
+ int changeCount;
716
+ NSData *formatData;
717
+ NSString *formatString;
718
+ const char *formatType;
719
+ NSPasteboardItem *item;
720
+ changeCount = (int)[pasteboard_rd changeCount];
721
+
722
+ if (changeCount == pasteboard_changecount)
723
+ return;
724
+
725
+ pasteboard_changecount = changeCount;
726
+ NSArray *items = [pasteboard_rd pasteboardItems];
727
+
728
+ if ([items count] < 1)
729
+ return;
730
+
731
+ item = [items objectAtIndex:0];
732
+ /**
733
+ * System-Declared Uniform Type Identifiers:
734
+ * https://developer.apple.com/library/ios/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html
735
+ */
736
+ formatMatch = FALSE;
737
+
738
+ for (NSString *type in [item types])
739
+ {
740
+ formatType = [type UTF8String];
741
+
742
+ if (strcmp(formatType, "public.utf8-plain-text") == 0)
743
+ {
744
+ formatData = [item dataForType:type];
745
+
746
+ if (formatData == nil)
747
+ {
748
+ break;
749
+ }
750
+
751
+ formatString = [[NSString alloc] initWithData:formatData encoding:NSUTF8StringEncoding];
752
+
753
+ const char *data = [formatString cStringUsingEncoding:NSUTF8StringEncoding];
754
+ const size_t dataLen = [formatString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
755
+ formatId = ClipboardRegisterFormat(mfc->clipboard, "text/plain");
756
+ ClipboardSetData(mfc->clipboard, formatId, data, dataLen + 1);
757
+ [formatString release];
758
+
759
+ formatMatch = TRUE;
760
+
761
+ break;
762
+ }
763
+ }
764
+
765
+ if (!formatMatch)
766
+ ClipboardEmpty(mfc->clipboard);
767
+
768
+ if (mfc->clipboardSync)
769
+ mac_cliprdr_send_client_format_list(mfc->cliprdr);
770
+ }
771
+
772
+ - (void)pause
773
+ {
774
+ dispatch_async(dispatch_get_main_queue(), ^{
775
+ [self->pasteboard_timer invalidate];
776
+ });
777
+ NSArray *trackingAreas = self.trackingAreas;
778
+
779
+ for (NSTrackingArea *ta in trackingAreas)
780
+ {
781
+ [self removeTrackingArea:ta];
782
+ }
783
+ releaseFlagStates(instance->context->input, kbdModFlags);
784
+ kbdModFlags = 0;
785
+ }
786
+
787
+ - (void)resume
788
+ {
789
+ if (!self.is_connected)
790
+ return;
791
+
792
+ releaseFlagStates(instance->context->input, kbdModFlags);
793
+ kbdModFlags = 0;
794
+ freerdp_input_send_focus_in_event(instance->context->input, 0);
795
+
796
+ dispatch_async(dispatch_get_main_queue(), ^{
797
+ self->pasteboard_timer =
798
+ [NSTimer scheduledTimerWithTimeInterval:0.5
799
+ target:self
800
+ selector:@selector(onPasteboardTimerFired:)
801
+ userInfo:nil
802
+ repeats:YES];
803
+
804
+ NSTrackingArea *trackingArea = [[NSTrackingArea alloc]
805
+ initWithRect:[self visibleRect]
806
+ options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved |
807
+ NSTrackingCursorUpdate | NSTrackingEnabledDuringMouseDrag |
808
+ NSTrackingActiveWhenFirstResponder
809
+ owner:self
810
+ userInfo:nil];
811
+ [self addTrackingArea:trackingArea];
812
+ [trackingArea release];
813
+ });
814
+ }
815
+
816
+ - (void)setScrollOffset:(int)xOffset y:(int)yOffset w:(int)width h:(int)height
817
+ {
818
+ WINPR_ASSERT(mfc);
819
+
820
+ mfc->yCurrentScroll = yOffset;
821
+ mfc->xCurrentScroll = xOffset;
822
+ mfc->client_height = height;
823
+ mfc->client_width = width;
824
+ }
825
+
826
+ static void mac_OnChannelConnectedEventHandler(void *context, const ChannelConnectedEventArgs *e)
827
+ {
828
+ rdpSettings *settings;
829
+ mfContext *mfc = (mfContext *)context;
830
+
831
+ WINPR_ASSERT(mfc);
832
+ WINPR_ASSERT(e);
833
+
834
+ settings = mfc->common.context.settings;
835
+ WINPR_ASSERT(settings);
836
+
837
+ if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
838
+ {
839
+ mac_cliprdr_init(mfc, (CliprdrClientContext *)e->pInterface);
840
+ }
841
+ else if (strcmp(e->name, ENCOMSP_SVC_CHANNEL_NAME) == 0)
842
+ {
843
+ }
844
+ else
845
+ freerdp_client_OnChannelConnectedEventHandler(context, e);
846
+ }
847
+
848
+ static void mac_OnChannelDisconnectedEventHandler(void *context,
849
+ const ChannelDisconnectedEventArgs *e)
850
+ {
851
+ rdpSettings *settings;
852
+ mfContext *mfc = (mfContext *)context;
853
+
854
+ WINPR_ASSERT(mfc);
855
+ WINPR_ASSERT(e);
856
+
857
+ settings = mfc->common.context.settings;
858
+ WINPR_ASSERT(settings);
859
+
860
+ if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
861
+ {
862
+ mac_cliprdr_uninit(mfc, (CliprdrClientContext *)e->pInterface);
863
+ }
864
+ else if (strcmp(e->name, ENCOMSP_SVC_CHANNEL_NAME) == 0)
865
+ {
866
+ }
867
+ else
868
+ freerdp_client_OnChannelDisconnectedEventHandler(context, e);
869
+ }
870
+
871
+ BOOL mac_pre_connect(freerdp *instance)
872
+ {
873
+ rdpSettings *settings;
874
+ rdpUpdate *update;
875
+
876
+ WINPR_ASSERT(instance);
877
+ WINPR_ASSERT(instance->context);
878
+
879
+ update = instance->context->update;
880
+ WINPR_ASSERT(update);
881
+
882
+ update->BeginPaint = mac_begin_paint;
883
+ update->EndPaint = mac_end_paint;
884
+ update->DesktopResize = mac_desktop_resize;
885
+
886
+ settings = instance->context->settings;
887
+ WINPR_ASSERT(settings);
888
+
889
+ if (!freerdp_settings_get_string(settings, FreeRDP_ServerHostname))
890
+ {
891
+ WLog_ERR(TAG, "error: server hostname was not specified with /v:<server>[:port]");
892
+ return FALSE;
893
+ }
894
+
895
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMajorType, OSMAJORTYPE_MACINTOSH))
896
+ return FALSE;
897
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMinorType, OSMINORTYPE_MACINTOSH))
898
+ return FALSE;
899
+ PubSub_SubscribeChannelConnected(instance->context->pubSub, mac_OnChannelConnectedEventHandler);
900
+ PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
901
+ mac_OnChannelDisconnectedEventHandler);
902
+
903
+ return TRUE;
904
+ }
905
+
906
+ BOOL mac_post_connect(freerdp *instance)
907
+ {
908
+ rdpGdi *gdi;
909
+ rdpPointer rdp_pointer = { 0 };
910
+ mfContext *mfc;
911
+ MRDPView *view;
912
+
913
+ WINPR_ASSERT(instance);
914
+
915
+ mfc = (mfContext *)instance->context;
916
+ WINPR_ASSERT(mfc);
917
+
918
+ view = (MRDPView *)mfc->view;
919
+ WINPR_ASSERT(view);
920
+
921
+ rdp_pointer.size = sizeof(rdpPointer);
922
+ rdp_pointer.New = mf_Pointer_New;
923
+ rdp_pointer.Free = mf_Pointer_Free;
924
+ rdp_pointer.Set = mf_Pointer_Set;
925
+ rdp_pointer.SetNull = mf_Pointer_SetNull;
926
+ rdp_pointer.SetDefault = mf_Pointer_SetDefault;
927
+ rdp_pointer.SetPosition = mf_Pointer_SetPosition;
928
+
929
+ if (!gdi_init(instance, PIXEL_FORMAT_BGRX32))
930
+ return FALSE;
931
+
932
+ gdi = instance->context->gdi;
933
+ view->bitmap_context = mac_create_bitmap_context(instance->context);
934
+ graphics_register_pointer(instance->context->graphics, &rdp_pointer);
935
+ /* setup pasteboard (aka clipboard) for copy operations (write only) */
936
+ view->pasteboard_wr = [NSPasteboard generalPasteboard];
937
+ /* setup pasteboard for read operations */
938
+ dispatch_async(dispatch_get_main_queue(), ^{
939
+ view->pasteboard_rd = [NSPasteboard generalPasteboard];
940
+ view->pasteboard_changecount = -1;
941
+ });
942
+ [view resume];
943
+ mfc->appleKeyboardType = mac_detect_keyboard_type();
944
+ return TRUE;
945
+ }
946
+
947
+ void mac_post_disconnect(freerdp *instance)
948
+ {
949
+ mfContext *mfc;
950
+ MRDPView *view;
951
+ if (!instance || !instance->context)
952
+ return;
953
+
954
+ mfc = (mfContext *)instance->context;
955
+ view = (MRDPView *)mfc->view;
956
+
957
+ [view pause];
958
+
959
+ PubSub_UnsubscribeChannelConnected(instance->context->pubSub,
960
+ mac_OnChannelConnectedEventHandler);
961
+ PubSub_UnsubscribeChannelDisconnected(instance->context->pubSub,
962
+ mac_OnChannelDisconnectedEventHandler);
963
+ gdi_free(instance);
964
+ }
965
+
966
+ static BOOL mac_show_auth_dialog(MRDPView *view, NSString *title, char **username, char **password,
967
+ char **domain)
968
+ {
969
+ WINPR_ASSERT(view);
970
+ WINPR_ASSERT(title);
971
+ WINPR_ASSERT(username);
972
+ WINPR_ASSERT(password);
973
+ WINPR_ASSERT(domain);
974
+
975
+ PasswordDialog *dialog = [PasswordDialog new];
976
+
977
+ dialog.serverHostname = title;
978
+
979
+ if (*username)
980
+ dialog.username = [NSString stringWithCString:*username encoding:NSUTF8StringEncoding];
981
+
982
+ if (*password)
983
+ dialog.password = [NSString stringWithCString:*password encoding:NSUTF8StringEncoding];
984
+
985
+ if (*domain)
986
+ dialog.domain = [NSString stringWithCString:*domain encoding:NSUTF8StringEncoding];
987
+
988
+ free(*username);
989
+ free(*password);
990
+ free(*domain);
991
+ *username = NULL;
992
+ *password = NULL;
993
+ *domain = NULL;
994
+
995
+ dispatch_sync(dispatch_get_main_queue(), ^{
996
+ [dialog performSelectorOnMainThread:@selector(runModal:)
997
+ withObject:[view window]
998
+ waitUntilDone:TRUE];
999
+ });
1000
+ BOOL ok = dialog.modalCode;
1001
+
1002
+ if (ok)
1003
+ {
1004
+ const char *submittedUsername = [dialog.username cStringUsingEncoding:NSUTF8StringEncoding];
1005
+ const size_t submittedUsernameLen =
1006
+ [dialog.username lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1007
+ if (submittedUsername && (submittedUsernameLen > 0))
1008
+ *username = strndup(submittedUsername, submittedUsernameLen);
1009
+
1010
+ if (!(*username))
1011
+ return FALSE;
1012
+
1013
+ const char *submittedPassword = [dialog.password cStringUsingEncoding:NSUTF8StringEncoding];
1014
+ const size_t submittedPasswordLen =
1015
+ [dialog.password lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1016
+ if (submittedPassword && (submittedPasswordLen > 0))
1017
+ *password = strndup(submittedPassword, submittedPasswordLen);
1018
+
1019
+ if (!(*password))
1020
+ return FALSE;
1021
+
1022
+ const char *submittedDomain = [dialog.domain cStringUsingEncoding:NSUTF8StringEncoding];
1023
+ const size_t submittedDomainLen =
1024
+ [dialog.domain lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1025
+ if (submittedDomain && (submittedDomainLen > 0))
1026
+ {
1027
+ *domain = strndup(submittedDomain, submittedDomainLen);
1028
+ if (!(*domain))
1029
+ return FALSE;
1030
+ }
1031
+ }
1032
+
1033
+ return ok;
1034
+ }
1035
+
1036
+ static BOOL mac_authenticate_raw(freerdp *instance, char **username, char **password, char **domain,
1037
+ rdp_auth_reason reason)
1038
+ {
1039
+ BOOL pinOnly = FALSE;
1040
+
1041
+ WINPR_ASSERT(instance);
1042
+ WINPR_ASSERT(instance->context);
1043
+ WINPR_ASSERT(instance->context->settings);
1044
+
1045
+ const rdpSettings *settings = instance->context->settings;
1046
+ mfContext *mfc = (mfContext *)instance->context;
1047
+ MRDPView *view = (MRDPView *)mfc->view;
1048
+ NSString *title = NULL;
1049
+
1050
+ switch (reason)
1051
+ {
1052
+ case AUTH_SMARTCARD_PIN:
1053
+ pinOnly = TRUE;
1054
+ title = [NSString
1055
+ stringWithFormat:@"%@:%u",
1056
+ [NSString stringWithCString:freerdp_settings_get_string(
1057
+ settings, FreeRDP_ServerHostname)
1058
+ encoding:NSUTF8StringEncoding],
1059
+ freerdp_settings_get_uint32(settings, FreeRDP_ServerPort)];
1060
+ break;
1061
+ case AUTH_TLS:
1062
+ case AUTH_RDP:
1063
+ case AUTH_NLA:
1064
+ title = [NSString
1065
+ stringWithFormat:@"%@:%u",
1066
+ [NSString stringWithCString:freerdp_settings_get_string(
1067
+ settings, FreeRDP_ServerHostname)
1068
+ encoding:NSUTF8StringEncoding],
1069
+ freerdp_settings_get_uint32(settings, FreeRDP_ServerPort)];
1070
+ break;
1071
+ case GW_AUTH_HTTP:
1072
+ case GW_AUTH_RDG:
1073
+ case GW_AUTH_RPC:
1074
+ title = [NSString
1075
+ stringWithFormat:@"%@:%u",
1076
+ [NSString stringWithCString:freerdp_settings_get_string(
1077
+ settings, FreeRDP_GatewayHostname)
1078
+ encoding:NSUTF8StringEncoding],
1079
+ freerdp_settings_get_uint32(settings, FreeRDP_GatewayPort)];
1080
+ break;
1081
+ default:
1082
+ return FALSE;
1083
+ }
1084
+
1085
+ if (!username || !password || !domain)
1086
+ return FALSE;
1087
+
1088
+ if (!*username && !pinOnly)
1089
+ {
1090
+ if (!mac_show_auth_dialog(view, title, username, password, domain))
1091
+ goto fail;
1092
+ }
1093
+ else if (!*domain && !pinOnly)
1094
+ {
1095
+ if (!mac_show_auth_dialog(view, title, username, password, domain))
1096
+ goto fail;
1097
+ }
1098
+ else if (!*password)
1099
+ {
1100
+ if (!mac_show_auth_dialog(view, title, username, password, domain))
1101
+ goto fail;
1102
+ }
1103
+
1104
+ return TRUE;
1105
+ fail:
1106
+ free(*username);
1107
+ free(*domain);
1108
+ free(*password);
1109
+ *username = NULL;
1110
+ *domain = NULL;
1111
+ *password = NULL;
1112
+ return FALSE;
1113
+ }
1114
+
1115
+ BOOL mac_authenticate_ex(freerdp *instance, char **username, char **password, char **domain,
1116
+ rdp_auth_reason reason)
1117
+ {
1118
+ WINPR_ASSERT(instance);
1119
+ WINPR_ASSERT(username);
1120
+ WINPR_ASSERT(password);
1121
+ WINPR_ASSERT(domain);
1122
+
1123
+ NSString *title;
1124
+ switch (reason)
1125
+ {
1126
+ case AUTH_NLA:
1127
+ break;
1128
+
1129
+ case AUTH_TLS:
1130
+ case AUTH_RDP:
1131
+ case AUTH_SMARTCARD_PIN: /* in this case password is pin code */
1132
+ if ((*username) && (*password))
1133
+ return TRUE;
1134
+ break;
1135
+ case GW_AUTH_HTTP:
1136
+ case GW_AUTH_RDG:
1137
+ case GW_AUTH_RPC:
1138
+ break;
1139
+ default:
1140
+ return FALSE;
1141
+ }
1142
+
1143
+ return mac_authenticate_raw(instance, username, password, domain, reason);
1144
+ }
1145
+
1146
+ DWORD mac_verify_certificate_ex(freerdp *instance, const char *host, UINT16 port,
1147
+ const char *common_name, const char *subject, const char *issuer,
1148
+ const char *fingerprint, DWORD flags)
1149
+ {
1150
+ mfContext *mfc = (mfContext *)instance->context;
1151
+ MRDPView *view = (MRDPView *)mfc->view;
1152
+ CertificateDialog *dialog = [CertificateDialog new];
1153
+ const char *type = "RDP-Server";
1154
+ char hostname[8192] = { 0 };
1155
+
1156
+ if (flags & VERIFY_CERT_FLAG_GATEWAY)
1157
+ type = "RDP-Gateway";
1158
+
1159
+ if (flags & VERIFY_CERT_FLAG_REDIRECT)
1160
+ type = "RDP-Redirect";
1161
+
1162
+ sprintf_s(hostname, sizeof(hostname), "%s %s:%" PRIu16, type, host, port);
1163
+ dialog.serverHostname = [NSString stringWithCString:hostname encoding:NSUTF8StringEncoding];
1164
+ dialog.commonName = [NSString stringWithCString:common_name encoding:NSUTF8StringEncoding];
1165
+ dialog.subject = [NSString stringWithCString:subject encoding:NSUTF8StringEncoding];
1166
+ dialog.issuer = [NSString stringWithCString:issuer encoding:NSUTF8StringEncoding];
1167
+ dialog.fingerprint = [NSString stringWithCString:fingerprint encoding:NSUTF8StringEncoding];
1168
+
1169
+ if (flags & VERIFY_CERT_FLAG_MISMATCH)
1170
+ dialog.hostMismatch = TRUE;
1171
+
1172
+ if (flags & VERIFY_CERT_FLAG_CHANGED)
1173
+ dialog.changed = TRUE;
1174
+
1175
+ [dialog performSelectorOnMainThread:@selector(runModal:)
1176
+ withObject:[view window]
1177
+ waitUntilDone:TRUE];
1178
+ return dialog.result;
1179
+ }
1180
+
1181
+ DWORD mac_verify_changed_certificate_ex(freerdp *instance, const char *host, UINT16 port,
1182
+ const char *common_name, const char *subject,
1183
+ const char *issuer, const char *fingerprint,
1184
+ const char *old_subject, const char *old_issuer,
1185
+ const char *old_fingerprint, DWORD flags)
1186
+ {
1187
+ mfContext *mfc = (mfContext *)instance->context;
1188
+ MRDPView *view = (MRDPView *)mfc->view;
1189
+ CertificateDialog *dialog = [CertificateDialog new];
1190
+ const char *type = "RDP-Server";
1191
+ char hostname[8192];
1192
+
1193
+ if (flags & VERIFY_CERT_FLAG_GATEWAY)
1194
+ type = "RDP-Gateway";
1195
+
1196
+ if (flags & VERIFY_CERT_FLAG_REDIRECT)
1197
+ type = "RDP-Redirect";
1198
+
1199
+ sprintf_s(hostname, sizeof(hostname), "%s %s:%" PRIu16, type, host, port);
1200
+ dialog.serverHostname = [NSString stringWithCString:hostname encoding:NSUTF8StringEncoding];
1201
+ dialog.commonName = [NSString stringWithCString:common_name encoding:NSUTF8StringEncoding];
1202
+ dialog.subject = [NSString stringWithCString:subject encoding:NSUTF8StringEncoding];
1203
+ dialog.issuer = [NSString stringWithCString:issuer encoding:NSUTF8StringEncoding];
1204
+ dialog.fingerprint = [NSString stringWithCString:fingerprint encoding:NSUTF8StringEncoding];
1205
+
1206
+ if (flags & VERIFY_CERT_FLAG_MISMATCH)
1207
+ dialog.hostMismatch = TRUE;
1208
+
1209
+ if (flags & VERIFY_CERT_FLAG_CHANGED)
1210
+ dialog.changed = TRUE;
1211
+
1212
+ [dialog performSelectorOnMainThread:@selector(runModal:)
1213
+ withObject:[view window]
1214
+ waitUntilDone:TRUE];
1215
+ return dialog.result;
1216
+ }
1217
+
1218
+ int mac_logon_error_info(freerdp *instance, UINT32 data, UINT32 type)
1219
+ {
1220
+ const char *str_data = freerdp_get_logon_error_info_data(data);
1221
+ const char *str_type = freerdp_get_logon_error_info_type(type);
1222
+ // TODO: Error message dialog
1223
+ WLog_INFO(TAG, "Logon Error Info %s [%s]", str_data, str_type);
1224
+ return 1;
1225
+ }
1226
+
1227
+ BOOL mf_Pointer_New(rdpContext *context, rdpPointer *pointer)
1228
+ {
1229
+ rdpGdi *gdi;
1230
+ NSRect rect;
1231
+ NSImage *image;
1232
+ NSPoint hotSpot;
1233
+ NSCursor *cursor;
1234
+ BYTE *cursor_data;
1235
+ NSMutableArray *ma;
1236
+ NSBitmapImageRep *bmiRep;
1237
+ MRDPCursor *mrdpCursor = [[MRDPCursor alloc] init];
1238
+ mfContext *mfc = (mfContext *)context;
1239
+ MRDPView *view;
1240
+ UINT32 format;
1241
+
1242
+ if (!mfc || !context || !pointer)
1243
+ return FALSE;
1244
+
1245
+ view = (MRDPView *)mfc->view;
1246
+ gdi = context->gdi;
1247
+
1248
+ if (!gdi || !view)
1249
+ return FALSE;
1250
+
1251
+ rect.size.width = pointer->width;
1252
+ rect.size.height = pointer->height;
1253
+ rect.origin.x = pointer->xPos;
1254
+ rect.origin.y = pointer->yPos;
1255
+ cursor_data = (BYTE *)malloc(rect.size.width * rect.size.height * 4);
1256
+
1257
+ if (!cursor_data)
1258
+ return FALSE;
1259
+
1260
+ mrdpCursor->cursor_data = cursor_data;
1261
+ format = PIXEL_FORMAT_RGBA32;
1262
+
1263
+ if (!freerdp_image_copy_from_pointer_data(cursor_data, format, 0, 0, 0, pointer->width,
1264
+ pointer->height, pointer->xorMaskData,
1265
+ pointer->lengthXorMask, pointer->andMaskData,
1266
+ pointer->lengthAndMask, pointer->xorBpp, NULL))
1267
+ {
1268
+ free(cursor_data);
1269
+ mrdpCursor->cursor_data = NULL;
1270
+ return FALSE;
1271
+ }
1272
+
1273
+ /* store cursor bitmap image in representation - required by NSImage */
1274
+ bmiRep = [[NSBitmapImageRep alloc]
1275
+ initWithBitmapDataPlanes:(unsigned char **)&cursor_data
1276
+ pixelsWide:rect.size.width
1277
+ pixelsHigh:rect.size.height
1278
+ bitsPerSample:8
1279
+ samplesPerPixel:4
1280
+ hasAlpha:YES
1281
+ isPlanar:NO
1282
+ colorSpaceName:NSDeviceRGBColorSpace
1283
+ bitmapFormat:0
1284
+ bytesPerRow:rect.size.width * FreeRDPGetBytesPerPixel(format)
1285
+ bitsPerPixel:0];
1286
+ mrdpCursor->bmiRep = bmiRep;
1287
+ /* create an image using above representation */
1288
+ image = [[NSImage alloc] initWithSize:[bmiRep size]];
1289
+ [image addRepresentation:bmiRep];
1290
+ mrdpCursor->nsImage = image;
1291
+ /* need hotspot to create cursor */
1292
+ hotSpot.x = pointer->xPos;
1293
+ hotSpot.y = pointer->yPos;
1294
+ cursor = [[NSCursor alloc] initWithImage:image hotSpot:hotSpot];
1295
+ mrdpCursor->nsCursor = cursor;
1296
+ mrdpCursor->pointer = pointer;
1297
+ /* save cursor for later use in mf_Pointer_Set() */
1298
+ ma = view->cursors;
1299
+ [ma addObject:mrdpCursor];
1300
+ return TRUE;
1301
+ }
1302
+
1303
+ void mf_Pointer_Free(rdpContext *context, rdpPointer *pointer)
1304
+ {
1305
+ mfContext *mfc = (mfContext *)context;
1306
+ MRDPView *view = (MRDPView *)mfc->view;
1307
+ NSMutableArray *ma = view->cursors;
1308
+
1309
+ for (MRDPCursor *cursor in ma)
1310
+ {
1311
+ if (cursor->pointer == pointer)
1312
+ {
1313
+ cursor->nsImage = nil;
1314
+ cursor->nsCursor = nil;
1315
+ cursor->bmiRep = nil;
1316
+ free(cursor->cursor_data);
1317
+ [ma removeObject:cursor];
1318
+ return;
1319
+ }
1320
+ }
1321
+ }
1322
+
1323
+ BOOL mf_Pointer_Set(rdpContext *context, rdpPointer *pointer)
1324
+ {
1325
+ mfContext *mfc = (mfContext *)context;
1326
+ MRDPView *view = (MRDPView *)mfc->view;
1327
+ NSMutableArray *ma = view->cursors;
1328
+
1329
+ for (MRDPCursor *cursor in ma)
1330
+ {
1331
+ if (cursor->pointer == pointer)
1332
+ {
1333
+ [view setCursor:cursor->nsCursor];
1334
+ return TRUE;
1335
+ }
1336
+ }
1337
+
1338
+ NSLog(@"Cursor not found");
1339
+ return TRUE;
1340
+ }
1341
+
1342
+ BOOL mf_Pointer_SetNull(rdpContext *context)
1343
+ {
1344
+ return TRUE;
1345
+ }
1346
+
1347
+ BOOL mf_Pointer_SetDefault(rdpContext *context)
1348
+ {
1349
+ mfContext *mfc = (mfContext *)context;
1350
+ MRDPView *view = (MRDPView *)mfc->view;
1351
+ [view setCursor:[NSCursor arrowCursor]];
1352
+ return TRUE;
1353
+ }
1354
+
1355
+ static BOOL mf_Pointer_SetPosition(rdpContext *context, UINT32 x, UINT32 y)
1356
+ {
1357
+ mfContext *mfc = (mfContext *)context;
1358
+
1359
+ if (!mfc)
1360
+ return FALSE;
1361
+
1362
+ /* TODO: Set pointer position */
1363
+ return TRUE;
1364
+ }
1365
+
1366
+ CGContextRef mac_create_bitmap_context(rdpContext *context)
1367
+ {
1368
+ CGContextRef bitmap_context;
1369
+ rdpGdi *gdi = context->gdi;
1370
+ UINT32 bpp = FreeRDPGetBytesPerPixel(gdi->dstFormat);
1371
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
1372
+
1373
+ if (bpp == 2)
1374
+ {
1375
+ bitmap_context = CGBitmapContextCreate(
1376
+ gdi->primary_buffer, gdi->width, gdi->height, 5, gdi->stride, colorSpace,
1377
+ kCGBitmapByteOrder16Little | kCGImageAlphaNoneSkipFirst);
1378
+ }
1379
+ else
1380
+ {
1381
+ bitmap_context = CGBitmapContextCreate(
1382
+ gdi->primary_buffer, gdi->width, gdi->height, 8, gdi->stride, colorSpace,
1383
+ kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst);
1384
+ }
1385
+
1386
+ CGColorSpaceRelease(colorSpace);
1387
+ return bitmap_context;
1388
+ }
1389
+
1390
+ BOOL mac_begin_paint(rdpContext *context)
1391
+ {
1392
+ rdpGdi *gdi = context->gdi;
1393
+
1394
+ if (!gdi)
1395
+ return FALSE;
1396
+
1397
+ gdi->primary->hdc->hwnd->invalid->null = TRUE;
1398
+ return TRUE;
1399
+ }
1400
+
1401
+ BOOL mac_end_paint(rdpContext *context)
1402
+ {
1403
+ rdpGdi *gdi;
1404
+ HGDI_RGN invalid;
1405
+ NSRect newDrawRect;
1406
+ int ww, wh, dw, dh;
1407
+ mfContext *mfc = (mfContext *)context;
1408
+ MRDPView *view = (MRDPView *)mfc->view;
1409
+ gdi = context->gdi;
1410
+
1411
+ if (!gdi)
1412
+ return FALSE;
1413
+
1414
+ ww = mfc->client_width;
1415
+ wh = mfc->client_height;
1416
+ dw = freerdp_settings_get_uint32(mfc->common.context.settings, FreeRDP_DesktopWidth);
1417
+ dh = freerdp_settings_get_uint32(mfc->common.context.settings, FreeRDP_DesktopHeight);
1418
+
1419
+ if ((!context) || (!context->gdi))
1420
+ return FALSE;
1421
+
1422
+ if (context->gdi->primary->hdc->hwnd->invalid->null)
1423
+ return TRUE;
1424
+
1425
+ invalid = gdi->primary->hdc->hwnd->invalid;
1426
+ newDrawRect.origin.x = invalid->x;
1427
+ newDrawRect.origin.y = invalid->y;
1428
+ newDrawRect.size.width = invalid->w;
1429
+ newDrawRect.size.height = invalid->h;
1430
+
1431
+ if (freerdp_settings_get_bool(mfc->common.context.settings, FreeRDP_SmartSizing) &&
1432
+ (ww != dw || wh != dh))
1433
+ {
1434
+ newDrawRect.origin.y = newDrawRect.origin.y * wh / dh - 1;
1435
+ newDrawRect.size.height = newDrawRect.size.height * wh / dh + 1;
1436
+ newDrawRect.origin.x = newDrawRect.origin.x * ww / dw - 1;
1437
+ newDrawRect.size.width = newDrawRect.size.width * ww / dw + 1;
1438
+ }
1439
+ else
1440
+ {
1441
+ newDrawRect.origin.y = newDrawRect.origin.y - 1;
1442
+ newDrawRect.size.height = newDrawRect.size.height + 1;
1443
+ newDrawRect.origin.x = newDrawRect.origin.x - 1;
1444
+ newDrawRect.size.width = newDrawRect.size.width + 1;
1445
+ }
1446
+
1447
+ windows_to_apple_cords(mfc->view, &newDrawRect);
1448
+ dispatch_sync(dispatch_get_main_queue(), ^{
1449
+ [view setNeedsDisplayInRect:newDrawRect];
1450
+ });
1451
+ gdi->primary->hdc->hwnd->ninvalid = 0;
1452
+ return TRUE;
1453
+ }
1454
+
1455
+ BOOL mac_desktop_resize(rdpContext *context)
1456
+ {
1457
+ ResizeWindowEventArgs e;
1458
+ mfContext *mfc = (mfContext *)context;
1459
+ MRDPView *view = (MRDPView *)mfc->view;
1460
+ rdpSettings *settings = context->settings;
1461
+
1462
+ if (!context->gdi)
1463
+ return TRUE;
1464
+
1465
+ /**
1466
+ * TODO: Fix resizing race condition. We should probably implement a message to be
1467
+ * put on the update message queue to be able to properly flush pending updates,
1468
+ * resize, and then continue with post-resizing graphical updates.
1469
+ */
1470
+ CGContextRef old_context = view->bitmap_context;
1471
+ view->bitmap_context = NULL;
1472
+ CGContextRelease(old_context);
1473
+ mfc->width = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
1474
+ mfc->height = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
1475
+
1476
+ if (!gdi_resize(context->gdi, mfc->width, mfc->height))
1477
+ return FALSE;
1478
+
1479
+ view->bitmap_context = mac_create_bitmap_context(context);
1480
+
1481
+ if (!view->bitmap_context)
1482
+ return FALSE;
1483
+
1484
+ mfc->client_width = mfc->width;
1485
+ mfc->client_height = mfc->height;
1486
+ [view setFrameSize:NSMakeSize(mfc->width, mfc->height)];
1487
+ EventArgsInit(&e, "mfreerdp");
1488
+ e.width = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
1489
+ e.height = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
1490
+ PubSub_OnResizeWindow(context->pubSub, context, &e);
1491
+ return TRUE;
1492
+ }
1493
+
1494
+ void input_activity_cb(freerdp *instance)
1495
+ {
1496
+ int status;
1497
+ wMessage message;
1498
+ wMessageQueue *queue;
1499
+ status = 1;
1500
+ queue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE);
1501
+
1502
+ if (queue)
1503
+ {
1504
+ while (MessageQueue_Peek(queue, &message, TRUE))
1505
+ {
1506
+ status = freerdp_message_queue_process_message(instance, FREERDP_INPUT_MESSAGE_QUEUE,
1507
+ &message);
1508
+
1509
+ if (!status)
1510
+ break;
1511
+ }
1512
+ }
1513
+ else
1514
+ {
1515
+ WLog_ERR(TAG, "input_activity_cb: No queue!");
1516
+ }
1517
+ }
1518
+
1519
+ /**
1520
+ * given a rect with 0,0 at the top left (windows cords)
1521
+ * convert it to a rect with 0,0 at the bottom left (apple cords)
1522
+ *
1523
+ * Note: the formula works for conversions in both directions.
1524
+ *
1525
+ */
1526
+
1527
+ void windows_to_apple_cords(MRDPView *view, NSRect *r)
1528
+ {
1529
+ dispatch_sync(dispatch_get_main_queue(), ^{
1530
+ r->origin.y = [view frame].size.height - (r->origin.y + r->size.height);
1531
+ });
1532
+ }
1533
+
1534
+ @end
local-test-freerdp-delta-01/afc-freerdp/client/Mac/ModuleOptions.cmake ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ set(FREERDP_CLIENT_NAME "mfreerdp")
2
+ set(FREERDP_CLIENT_PLATFORM "MacOSX")
3
+ set(FREERDP_CLIENT_VENDOR "FreeRDP")
local-test-freerdp-delta-01/afc-freerdp/client/Mac/PasswordDialog.h ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * MacFreeRDP
4
+ *
5
+ * Copyright 2013 Christian Hofstaedtler
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #import <Cocoa/Cocoa.h>
21
+
22
+ @interface PasswordDialog : NSWindowController
23
+ {
24
+ @public
25
+ NSTextField *usernameText;
26
+ NSTextField *passwordText;
27
+ NSTextField *messageLabel;
28
+ NSString *serverHostname;
29
+ NSString *username;
30
+ NSString *password;
31
+ NSString *domain;
32
+ BOOL modalCode;
33
+ }
34
+ @property(retain) IBOutlet NSTextField *usernameText;
35
+ @property(retain) IBOutlet NSTextField *passwordText;
36
+ @property(retain) IBOutlet NSTextField *messageLabel;
37
+
38
+ - (IBAction)onOK:(NSObject *)sender;
39
+ - (IBAction)onCancel:(NSObject *)sender;
40
+
41
+ @property(retain) NSString *serverHostname;
42
+ @property(retain) NSString *username;
43
+ @property(retain) NSString *password;
44
+ @property(retain) NSString *domain;
45
+ @property(readonly) BOOL modalCode;
46
+
47
+ - (BOOL)runModal:(NSWindow *)mainWindow;
48
+
49
+ @end
local-test-freerdp-delta-01/afc-freerdp/client/Mac/PasswordDialog.m ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * MacFreeRDP
4
+ *
5
+ * Copyright 2013 Christian Hofstaedtler
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #import "PasswordDialog.h"
21
+ #import <freerdp/client/cmdline.h>
22
+
23
+ #import <CoreGraphics/CoreGraphics.h>
24
+
25
+ @interface PasswordDialog ()
26
+
27
+ @property BOOL modalCode;
28
+
29
+ @end
30
+
31
+ @implementation PasswordDialog
32
+
33
+ @synthesize usernameText;
34
+ @synthesize passwordText;
35
+ @synthesize messageLabel;
36
+ @synthesize serverHostname;
37
+ @synthesize username;
38
+ @synthesize password;
39
+ @synthesize domain;
40
+ @synthesize modalCode;
41
+
42
+ - (id)init
43
+ {
44
+ return [self initWithWindowNibName:@"PasswordDialog"];
45
+ }
46
+
47
+ - (void)windowDidLoad
48
+ {
49
+ [super windowDidLoad];
50
+ // Implement this method to handle any initialization after your window controller's window has
51
+ // been loaded from its nib file.
52
+ [self.window setTitle:self.serverHostname];
53
+ [self.messageLabel
54
+ setStringValue:[NSString stringWithFormat:@"Authenticate to %@", self.serverHostname]];
55
+ NSMutableString *domainUser = [[NSMutableString alloc] initWithString:@""];
56
+
57
+ if (self.domain != nil &&
58
+ [[self.domain stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]
59
+ length] > 0)
60
+ {
61
+ [domainUser appendFormat:@"%@\\", self.domain];
62
+ }
63
+
64
+ if (self.username != nil)
65
+ {
66
+ [domainUser appendString:self.username];
67
+ [self.window makeFirstResponder:self.passwordText];
68
+ }
69
+
70
+ [self.usernameText setStringValue:domainUser];
71
+ }
72
+
73
+ - (IBAction)onOK:(NSObject *)sender
74
+ {
75
+ char *submittedUser = NULL;
76
+ char *submittedDomain = NULL;
77
+
78
+ if (freerdp_parse_username(
79
+ [self.usernameText.stringValue cStringUsingEncoding:NSUTF8StringEncoding],
80
+ &submittedUser, &submittedDomain))
81
+ {
82
+ if (submittedUser)
83
+ self.username = [NSString stringWithCString:submittedUser
84
+ encoding:NSUTF8StringEncoding];
85
+ if (submittedDomain)
86
+ self.domain = [NSString stringWithCString:submittedDomain
87
+ encoding:NSUTF8StringEncoding];
88
+ }
89
+ else
90
+ {
91
+ self.username = self.usernameText.stringValue;
92
+ }
93
+
94
+ self.password = self.passwordText.stringValue;
95
+ free(submittedUser);
96
+ free(submittedDomain);
97
+ [NSApp stopModalWithCode:TRUE];
98
+ }
99
+
100
+ - (IBAction)onCancel:(NSObject *)sender
101
+ {
102
+ [NSApp stopModalWithCode:FALSE];
103
+ }
104
+
105
+ - (BOOL)runModal:(NSWindow *)mainWindow
106
+ {
107
+ if ([mainWindow respondsToSelector:@selector(beginSheet:completionHandler:)])
108
+ {
109
+ [mainWindow beginSheet:self.window completionHandler:nil];
110
+ self.modalCode = [NSApp runModalForWindow:self.window];
111
+ [mainWindow endSheet:self.window];
112
+ }
113
+ else
114
+ {
115
+ [NSApp beginSheet:self.window
116
+ modalForWindow:mainWindow
117
+ modalDelegate:nil
118
+ didEndSelector:nil
119
+ contextInfo:nil];
120
+ self.modalCode = [NSApp runModalForWindow:self.window];
121
+ [NSApp endSheet:self.window];
122
+ }
123
+
124
+ [self.window orderOut:nil];
125
+ return self.modalCode;
126
+ }
127
+
128
+ - (void)dealloc
129
+ {
130
+ [usernameText release];
131
+ [passwordText release];
132
+ [messageLabel release];
133
+ [serverHostname release];
134
+ [username release];
135
+ [password release];
136
+ [domain release];
137
+ [super dealloc];
138
+ }
139
+
140
+ @end
local-test-freerdp-delta-01/afc-freerdp/client/Mac/PasswordDialog.xib ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
3
+ <dependencies>
4
+ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11201"/>
5
+ </dependencies>
6
+ <objects>
7
+ <customObject id="-2" userLabel="File's Owner" customClass="PasswordDialog">
8
+ <connections>
9
+ <outlet property="messageLabel" destination="7" id="50"/>
10
+ <outlet property="passwordText" destination="6" id="48"/>
11
+ <outlet property="usernameText" destination="11" id="49"/>
12
+ <outlet property="window" destination="1" id="3"/>
13
+ </connections>
14
+ </customObject>
15
+ <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
16
+ <customObject id="-3" userLabel="Application"/>
17
+ <window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" visibleAtLaunch="NO" animationBehavior="default" id="1">
18
+ <windowStyleMask key="styleMask" titled="YES" texturedBackground="YES"/>
19
+ <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
20
+ <rect key="contentRect" x="196" y="240" width="480" height="270"/>
21
+ <rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
22
+ <view key="contentView" id="2">
23
+ <rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
24
+ <autoresizingMask key="autoresizingMask"/>
25
+ <subviews>
26
+ <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="5">
27
+ <rect key="frame" x="47" y="127" width="106" height="17"/>
28
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Password:" id="22">
29
+ <font key="font" metaFont="system"/>
30
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
31
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
32
+ </textFieldCell>
33
+ </textField>
34
+ <secureTextField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="6">
35
+ <rect key="frame" x="159" y="124" width="233" height="22"/>
36
+ <secureTextFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" placeholderString="Password" drawsBackground="YES" usesSingleLineMode="YES" id="21">
37
+ <font key="font" metaFont="system"/>
38
+ <color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
39
+ <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
40
+ <allowedInputSourceLocales>
41
+ <string>NSAllRomanInputSourcesLocaleIdentifier</string>
42
+ </allowedInputSourceLocales>
43
+ </secureTextFieldCell>
44
+ </secureTextField>
45
+ <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="7">
46
+ <rect key="frame" x="47" y="206" width="344" height="17"/>
47
+ <constraints>
48
+ <constraint firstAttribute="width" constant="340" id="19"/>
49
+ </constraints>
50
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Connect to SERVER_NAME" placeholderString="" id="20">
51
+ <font key="font" metaFont="system"/>
52
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
53
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
54
+ </textFieldCell>
55
+ </textField>
56
+ <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="8">
57
+ <rect key="frame" x="384" y="13" width="82" height="32"/>
58
+ <buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="18">
59
+ <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
60
+ <font key="font" metaFont="system"/>
61
+ <string key="keyEquivalent" base64-UTF8="YES">
62
+ Gw
63
+ </string>
64
+ </buttonCell>
65
+ <connections>
66
+ <action selector="onCancel:" target="-2" id="52"/>
67
+ </connections>
68
+ </button>
69
+ <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9">
70
+ <rect key="frame" x="302" y="13" width="82" height="32"/>
71
+ <constraints>
72
+ <constraint firstAttribute="width" constant="70" id="16"/>
73
+ </constraints>
74
+ <buttonCell key="cell" type="push" title="OK" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="17">
75
+ <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
76
+ <font key="font" metaFont="system"/>
77
+ <string key="keyEquivalent" base64-UTF8="YES">
78
+ DQ
79
+ </string>
80
+ </buttonCell>
81
+ <connections>
82
+ <action selector="onOK:" target="-2" id="51"/>
83
+ </connections>
84
+ </button>
85
+ <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="10">
86
+ <rect key="frame" x="47" y="159" width="106" height="17"/>
87
+ <constraints>
88
+ <constraint firstAttribute="width" constant="102" id="14"/>
89
+ </constraints>
90
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Username:" id="15">
91
+ <font key="font" metaFont="system"/>
92
+ <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
93
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
94
+ </textFieldCell>
95
+ </textField>
96
+ <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="11">
97
+ <rect key="frame" x="159" y="156" width="233" height="22"/>
98
+ <constraints>
99
+ <constraint firstAttribute="width" constant="233" id="12"/>
100
+ </constraints>
101
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" placeholderString="username@domain" drawsBackground="YES" id="13">
102
+ <font key="font" metaFont="system"/>
103
+ <color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
104
+ <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
105
+ </textFieldCell>
106
+ </textField>
107
+ </subviews>
108
+ <constraints>
109
+ <constraint firstItem="6" firstAttribute="leading" secondItem="11" secondAttribute="leading" id="25"/>
110
+ <constraint firstItem="5" firstAttribute="centerY" secondItem="6" secondAttribute="centerY" id="27"/>
111
+ <constraint firstItem="6" firstAttribute="leading" secondItem="5" secondAttribute="trailing" constant="8" symbolic="YES" id="28"/>
112
+ <constraint firstItem="6" firstAttribute="trailing" secondItem="11" secondAttribute="trailing" id="30"/>
113
+ <constraint firstItem="11" firstAttribute="leading" secondItem="10" secondAttribute="trailing" constant="8" symbolic="YES" id="31"/>
114
+ <constraint firstItem="8" firstAttribute="leading" secondItem="9" secondAttribute="trailing" constant="12" symbolic="YES" id="32"/>
115
+ <constraint firstItem="10" firstAttribute="leading" secondItem="5" secondAttribute="leading" id="34"/>
116
+ <constraint firstItem="10" firstAttribute="leading" secondItem="7" secondAttribute="leading" id="37"/>
117
+ <constraint firstAttribute="bottom" secondItem="9" secondAttribute="bottom" constant="20" symbolic="YES" id="39"/>
118
+ <constraint firstItem="5" firstAttribute="centerY" secondItem="2" secondAttribute="centerY" id="41"/>
119
+ <constraint firstAttribute="bottom" secondItem="8" secondAttribute="bottom" constant="20" symbolic="YES" id="42"/>
120
+ <constraint firstAttribute="trailing" secondItem="8" secondAttribute="trailing" constant="20" symbolic="YES" id="43"/>
121
+ <constraint firstItem="7" firstAttribute="leading" secondItem="2" secondAttribute="leading" constant="49" id="44"/>
122
+ <constraint firstItem="7" firstAttribute="top" secondItem="2" secondAttribute="top" constant="47" id="45"/>
123
+ <constraint firstItem="6" firstAttribute="top" secondItem="11" secondAttribute="bottom" constant="10" symbolic="YES" id="46"/>
124
+ <constraint firstItem="10" firstAttribute="baseline" secondItem="11" secondAttribute="baseline" id="47"/>
125
+ </constraints>
126
+ </view>
127
+ <connections>
128
+ <outlet property="delegate" destination="-2" id="4"/>
129
+ </connections>
130
+ </window>
131
+ </objects>
132
+ </document>
local-test-freerdp-delta-01/afc-freerdp/client/Mac/main.m ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * MacFreeRDP
4
+ *
5
+ * Copyright 2012 Thomas Goddard
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #import <Cocoa/Cocoa.h>
21
+
22
+ int main(int argc, char *argv[])
23
+ {
24
+ return NSApplicationMain(argc, argv);
25
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Mac/mf_client.h ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Windows Client
4
+ *
5
+ * Copyright 2009-2011 Jay Sorg
6
+ * Copyright 2010-2011 Vic Lee
7
+ * Copyright 2010-2011 Marc-Andre Moreau <[email protected]>
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_MAC_CLIENT_H
23
+ #define FREERDP_CLIENT_MAC_CLIENT_H
24
+
25
+ #include <freerdp/client.h>
26
+
27
+ #ifdef __cplusplus
28
+ extern "C"
29
+ {
30
+ #endif
31
+
32
+ FREERDP_API void mf_press_mouse_button(void* context, int button, int x, int y, BOOL down);
33
+ FREERDP_API void mf_scale_mouse_event(void* context, UINT16 flags, UINT16 x, UINT16 y);
34
+ FREERDP_API void mf_scale_mouse_event_ex(void* context, UINT16 flags, UINT16 x, UINT16 y);
35
+
36
+ /**
37
+ * Client Interface
38
+ */
39
+
40
+ FREERDP_API int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints);
41
+
42
+ #ifdef __cplusplus
43
+ }
44
+ #endif
45
+
46
+ #endif /* FREERDP_CLIENT_MAC_CLIENT_H */
local-test-freerdp-delta-01/afc-freerdp/client/Mac/mf_client.m ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * X11 Client Interface
4
+ *
5
+ * Copyright 2013 Marc-Andre Moreau <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #include <freerdp/config.h>
21
+
22
+ #include "mfreerdp.h"
23
+
24
+ #include <winpr/assert.h>
25
+
26
+ #include <freerdp/constants.h>
27
+ #include <freerdp/utils/signal.h>
28
+ #include <freerdp/client/cmdline.h>
29
+
30
+ #include "MRDPView.h"
31
+
32
+ /**
33
+ * Client Interface
34
+ */
35
+
36
+ static BOOL mfreerdp_client_global_init(void)
37
+ {
38
+ freerdp_handle_signals();
39
+ return TRUE;
40
+ }
41
+
42
+ static void mfreerdp_client_global_uninit(void)
43
+ {
44
+ }
45
+
46
+ static int mfreerdp_client_start(rdpContext *context)
47
+ {
48
+ MRDPView *view;
49
+ mfContext *mfc = (mfContext *)context;
50
+
51
+ if (mfc->view == NULL)
52
+ {
53
+ // view not specified beforehand. Create view dynamically
54
+ mfc->view = [[MRDPView alloc]
55
+ initWithFrame:NSMakeRect(
56
+ 0, 0,
57
+ freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopWidth),
58
+ freerdp_settings_get_uint32(context->settings,
59
+ FreeRDP_DesktopHeight))];
60
+ mfc->view_ownership = TRUE;
61
+ }
62
+
63
+ view = (MRDPView *)mfc->view;
64
+ return [view rdpStart:context];
65
+ }
66
+
67
+ static int mfreerdp_client_stop(rdpContext *context)
68
+ {
69
+ mfContext *mfc = (mfContext *)context;
70
+
71
+ freerdp_client_common_stop(context);
72
+
73
+ if (mfc->view_ownership)
74
+ {
75
+ MRDPView *view = (MRDPView *)mfc->view;
76
+ [view releaseResources];
77
+ [view release];
78
+ mfc->view = nil;
79
+ }
80
+
81
+ return 0;
82
+ }
83
+
84
+ static BOOL mfreerdp_client_new(freerdp *instance, rdpContext *context)
85
+ {
86
+ mfContext *mfc;
87
+
88
+ WINPR_ASSERT(instance);
89
+
90
+ mfc = (mfContext *)instance->context;
91
+ WINPR_ASSERT(mfc);
92
+
93
+ mfc->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
94
+ if (!mfc->stopEvent)
95
+ return FALSE;
96
+ context->instance->PreConnect = mac_pre_connect;
97
+ context->instance->PostConnect = mac_post_connect;
98
+ context->instance->PostDisconnect = mac_post_disconnect;
99
+ context->instance->AuthenticateEx = mac_authenticate_ex;
100
+ context->instance->VerifyCertificateEx = mac_verify_certificate_ex;
101
+ context->instance->VerifyChangedCertificateEx = mac_verify_changed_certificate_ex;
102
+ context->instance->LogonErrorInfo = mac_logon_error_info;
103
+ return TRUE;
104
+ }
105
+
106
+ static void mfreerdp_client_free(freerdp *instance, rdpContext *context)
107
+ {
108
+ mfContext *mfc;
109
+
110
+ if (!instance || !context)
111
+ return;
112
+
113
+ mfc = (mfContext *)instance->context;
114
+ (void)CloseHandle(mfc->stopEvent);
115
+ }
116
+
117
+ static void mf_scale_mouse_coordinates(mfContext *mfc, UINT16 *px, UINT16 *py)
118
+ {
119
+ UINT16 x = *px;
120
+ UINT16 y = *py;
121
+ UINT32 ww = mfc->client_width;
122
+ UINT32 wh = mfc->client_height;
123
+ UINT32 dw = freerdp_settings_get_uint32(mfc->common.context.settings, FreeRDP_DesktopWidth);
124
+ UINT32 dh = freerdp_settings_get_uint32(mfc->common.context.settings, FreeRDP_DesktopHeight);
125
+
126
+ if (!freerdp_settings_get_bool(mfc->common.context.settings, FreeRDP_SmartSizing) ||
127
+ ((ww == dw) && (wh == dh)))
128
+ {
129
+ y = y + mfc->yCurrentScroll;
130
+ x = x + mfc->xCurrentScroll;
131
+
132
+ y -= (dh - wh);
133
+ x -= (dw - ww);
134
+ }
135
+ else
136
+ {
137
+ y = y * dh / wh + mfc->yCurrentScroll;
138
+ x = x * dw / ww + mfc->xCurrentScroll;
139
+ }
140
+
141
+ *px = x;
142
+ *py = y;
143
+ }
144
+
145
+ void mf_scale_mouse_event(void *context, UINT16 flags, UINT16 x, UINT16 y)
146
+ {
147
+ mfContext *mfc = (mfContext *)context;
148
+ MRDPView *view = (MRDPView *)mfc->view;
149
+ // Convert to windows coordinates
150
+ y = [view frame].size.height - y;
151
+
152
+ if ((flags & (PTR_FLAGS_WHEEL | PTR_FLAGS_HWHEEL)) == 0)
153
+ mf_scale_mouse_coordinates(mfc, &x, &y);
154
+ freerdp_client_send_button_event(&mfc->common, FALSE, flags, x, y);
155
+ }
156
+
157
+ void mf_scale_mouse_event_ex(void *context, UINT16 flags, UINT16 x, UINT16 y)
158
+ {
159
+ mfContext *mfc = (mfContext *)context;
160
+ MRDPView *view = (MRDPView *)mfc->view;
161
+ // Convert to windows coordinates
162
+ y = [view frame].size.height - y;
163
+
164
+ mf_scale_mouse_coordinates(mfc, &x, &y);
165
+ freerdp_client_send_extended_button_event(&mfc->common, FALSE, flags, x, y);
166
+ }
167
+
168
+ void mf_press_mouse_button(void *context, int button, int x, int y, BOOL down)
169
+ {
170
+ UINT16 flags = 0;
171
+ UINT16 xflags = 0;
172
+
173
+ if (down)
174
+ {
175
+ flags |= PTR_FLAGS_DOWN;
176
+ xflags |= PTR_XFLAGS_DOWN;
177
+ }
178
+
179
+ switch (button)
180
+ {
181
+ case 0:
182
+ mf_scale_mouse_event(context, flags | PTR_FLAGS_BUTTON1, x, y);
183
+ break;
184
+
185
+ case 1:
186
+ mf_scale_mouse_event(context, flags | PTR_FLAGS_BUTTON2, x, y);
187
+ break;
188
+
189
+ case 2:
190
+ mf_scale_mouse_event(context, flags | PTR_FLAGS_BUTTON3, x, y);
191
+ break;
192
+
193
+ case 3:
194
+ mf_scale_mouse_event_ex(context, xflags | PTR_XFLAGS_BUTTON1, x, y);
195
+ break;
196
+
197
+ case 4:
198
+ mf_scale_mouse_event_ex(context, xflags | PTR_XFLAGS_BUTTON2, x, y);
199
+ break;
200
+
201
+ default:
202
+ break;
203
+ }
204
+ }
205
+
206
+ int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS *pEntryPoints)
207
+ {
208
+ WINPR_ASSERT(pEntryPoints);
209
+
210
+ pEntryPoints->Version = 1;
211
+ pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
212
+ pEntryPoints->GlobalInit = mfreerdp_client_global_init;
213
+ pEntryPoints->GlobalUninit = mfreerdp_client_global_uninit;
214
+ pEntryPoints->ContextSize = sizeof(mfContext);
215
+ pEntryPoints->ClientNew = mfreerdp_client_new;
216
+ pEntryPoints->ClientFree = mfreerdp_client_free;
217
+ pEntryPoints->ClientStart = mfreerdp_client_start;
218
+ pEntryPoints->ClientStop = mfreerdp_client_stop;
219
+ return 0;
220
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Mac/mfreerdp.h ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef FREERDP_CLIENT_MAC_FREERDP_H
2
+ #define FREERDP_CLIENT_MAC_FREERDP_H
3
+
4
+ #include <freerdp/freerdp.h>
5
+ #include <freerdp/client/file.h>
6
+ #include <freerdp/api.h>
7
+ #include <freerdp/freerdp.h>
8
+
9
+ #include <freerdp/gdi/gdi.h>
10
+ #include <freerdp/gdi/dc.h>
11
+ #include <freerdp/gdi/gfx.h>
12
+ #include <freerdp/gdi/region.h>
13
+ #include <freerdp/channels/channels.h>
14
+
15
+ #include <freerdp/client/channels.h>
16
+ #include <freerdp/client/rdpei.h>
17
+ #include <freerdp/client/rdpgfx.h>
18
+ #include <freerdp/client/cliprdr.h>
19
+ #include <freerdp/client/encomsp.h>
20
+
21
+ #include <winpr/crt.h>
22
+ #include <winpr/synch.h>
23
+ #include <winpr/thread.h>
24
+ #include <winpr/clipboard.h>
25
+
26
+ #include "Keyboard.h"
27
+ #include <CoreGraphics/CoreGraphics.h>
28
+
29
+ typedef struct
30
+ {
31
+ rdpClientContext common;
32
+
33
+ void* view;
34
+ BOOL view_ownership;
35
+
36
+ int width;
37
+ int height;
38
+ int offset_x;
39
+ int offset_y;
40
+ int fs_toggle;
41
+ int fullscreen;
42
+ int percentscreen;
43
+ char window_title[64];
44
+ int client_x;
45
+ int client_y;
46
+ int client_width;
47
+ int client_height;
48
+
49
+ HANDLE stopEvent;
50
+ HANDLE keyboardThread;
51
+ enum APPLE_KEYBOARD_TYPE appleKeyboardType;
52
+
53
+ DWORD mainThreadId;
54
+ DWORD keyboardThreadId;
55
+
56
+ BOOL clipboardSync;
57
+ wClipboard* clipboard;
58
+ UINT32 numServerFormats;
59
+ UINT32 requestedFormatId;
60
+ HANDLE clipboardRequestEvent;
61
+ CLIPRDR_FORMAT* serverFormats;
62
+ CliprdrClientContext* cliprdr;
63
+ UINT32 clipboardCapabilities;
64
+
65
+ rdpFile* connectionRdpFile;
66
+
67
+ // Keep track of window size and position, disable when in fullscreen mode.
68
+ BOOL disablewindowtracking;
69
+
70
+ // These variables are required for horizontal scrolling.
71
+ BOOL updating_scrollbars;
72
+ BOOL xScrollVisible;
73
+ int xMinScroll; // minimum horizontal scroll value
74
+ int xCurrentScroll; // current horizontal scroll value
75
+ int xMaxScroll; // maximum horizontal scroll value
76
+
77
+ // These variables are required for vertical scrolling.
78
+ BOOL yScrollVisible;
79
+ int yMinScroll; // minimum vertical scroll value
80
+ int yCurrentScroll; // current vertical scroll value
81
+ int yMaxScroll; // maximum vertical scroll value
82
+
83
+ CGEventFlags kbdFlags;
84
+ } mfContext;
85
+
86
+ #endif /* FREERDP_CLIENT_MAC_FREERDP_H */
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL2/sdl_monitor.cpp ADDED
@@ -0,0 +1,394 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * X11 Monitor Handling
4
+ *
5
+ * Copyright 2011 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2017 David Fort <[email protected]>
7
+ * Copyright 2018 Kai Harms <[email protected]>
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
+ #include <freerdp/config.h>
23
+
24
+ #include <cstdio>
25
+ #include <cstdlib>
26
+ #include <cstring>
27
+ #include <algorithm>
28
+
29
+ #include <SDL.h>
30
+
31
+ #include <winpr/assert.h>
32
+ #include <winpr/crt.h>
33
+
34
+ #include <freerdp/log.h>
35
+
36
+ #define TAG CLIENT_TAG("sdl")
37
+
38
+ #include "sdl_monitor.hpp"
39
+ #include "sdl_freerdp.hpp"
40
+
41
+ using MONITOR_INFO = struct
42
+ {
43
+ RECTANGLE_16 area;
44
+ RECTANGLE_16 workarea;
45
+ BOOL primary;
46
+ };
47
+
48
+ using VIRTUAL_SCREEN = struct
49
+ {
50
+ int nmonitors;
51
+ RECTANGLE_16 area;
52
+ RECTANGLE_16 workarea;
53
+ MONITOR_INFO* monitors;
54
+ };
55
+
56
+ /* See MSDN Section on Multiple Display Monitors: http://msdn.microsoft.com/en-us/library/dd145071
57
+ */
58
+
59
+ int sdl_list_monitors(SdlContext* sdl)
60
+ {
61
+ SDL_Init(SDL_INIT_VIDEO);
62
+ const int nmonitors = SDL_GetNumVideoDisplays();
63
+
64
+ printf("listing %d monitors:\n", nmonitors);
65
+ for (int i = 0; i < nmonitors; i++)
66
+ {
67
+ SDL_Rect rect = {};
68
+ const int brc = SDL_GetDisplayBounds(i, &rect);
69
+ const char* name = SDL_GetDisplayName(i);
70
+
71
+ if (brc != 0)
72
+ continue;
73
+ printf(" %s [%d] [%s] %dx%d\t+%d+%d\n", (i == 0) ? "*" : " ", i, name, rect.w, rect.h,
74
+ rect.x, rect.y);
75
+ }
76
+
77
+ SDL_Quit();
78
+ return 0;
79
+ }
80
+
81
+ static BOOL sdl_apply_max_size(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight)
82
+ {
83
+ WINPR_ASSERT(sdl);
84
+ WINPR_ASSERT(pMaxWidth);
85
+ WINPR_ASSERT(pMaxHeight);
86
+
87
+ auto settings = sdl->context()->settings;
88
+ WINPR_ASSERT(settings);
89
+
90
+ *pMaxWidth = 0;
91
+ *pMaxHeight = 0;
92
+
93
+ for (size_t x = 0; x < freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount); x++)
94
+ {
95
+ auto monitor = static_cast<const rdpMonitor*>(
96
+ freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x));
97
+
98
+ if (freerdp_settings_get_bool(settings, FreeRDP_Fullscreen))
99
+ {
100
+ *pMaxWidth = WINPR_ASSERTING_INT_CAST(uint32_t, monitor->width);
101
+ *pMaxHeight = WINPR_ASSERTING_INT_CAST(uint32_t, monitor->height);
102
+ }
103
+ else if (freerdp_settings_get_bool(settings, FreeRDP_Workarea))
104
+ {
105
+ SDL_Rect rect = {};
106
+ SDL_GetDisplayUsableBounds(WINPR_ASSERTING_INT_CAST(int, monitor->orig_screen), &rect);
107
+ *pMaxWidth = WINPR_ASSERTING_INT_CAST(uint32_t, rect.w);
108
+ *pMaxHeight = WINPR_ASSERTING_INT_CAST(uint32_t, rect.h);
109
+ }
110
+ else if (freerdp_settings_get_uint32(settings, FreeRDP_PercentScreen) > 0)
111
+ {
112
+ SDL_Rect rect = {};
113
+ SDL_GetDisplayUsableBounds(WINPR_ASSERTING_INT_CAST(int, monitor->orig_screen), &rect);
114
+
115
+ *pMaxWidth = WINPR_ASSERTING_INT_CAST(uint32_t, rect.w);
116
+ *pMaxHeight = WINPR_ASSERTING_INT_CAST(uint32_t, rect.h);
117
+
118
+ if (freerdp_settings_get_bool(settings, FreeRDP_PercentScreenUseWidth))
119
+ *pMaxWidth = (WINPR_ASSERTING_INT_CAST(uint32_t, rect.w) *
120
+ freerdp_settings_get_uint32(settings, FreeRDP_PercentScreen)) /
121
+ 100;
122
+
123
+ if (freerdp_settings_get_bool(settings, FreeRDP_PercentScreenUseHeight))
124
+ *pMaxHeight = (WINPR_ASSERTING_INT_CAST(uint32_t, rect.h) *
125
+ freerdp_settings_get_uint32(settings, FreeRDP_PercentScreen)) /
126
+ 100;
127
+ }
128
+ else if (freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) &&
129
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight))
130
+ {
131
+ *pMaxWidth = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
132
+ *pMaxHeight = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
133
+ }
134
+ }
135
+ return TRUE;
136
+ }
137
+
138
+ #if SDL_VERSION_ATLEAST(2, 0, 10)
139
+ static UINT32 sdl_orientaion_to_rdp(SDL_DisplayOrientation orientation)
140
+ {
141
+ switch (orientation)
142
+ {
143
+ case SDL_ORIENTATION_LANDSCAPE:
144
+ return ORIENTATION_LANDSCAPE;
145
+ case SDL_ORIENTATION_LANDSCAPE_FLIPPED:
146
+ return ORIENTATION_LANDSCAPE_FLIPPED;
147
+ case SDL_ORIENTATION_PORTRAIT_FLIPPED:
148
+ return ORIENTATION_PORTRAIT_FLIPPED;
149
+ case SDL_ORIENTATION_PORTRAIT:
150
+ default:
151
+ return ORIENTATION_PORTRAIT;
152
+ }
153
+ }
154
+ #endif
155
+
156
+ static Uint32 scale(Uint32 val, float scale)
157
+ {
158
+ const auto dval = static_cast<float>(val);
159
+ const auto sval = dval / scale;
160
+ return static_cast<Uint32>(sval);
161
+ }
162
+
163
+ static BOOL sdl_apply_display_properties(SdlContext* sdl)
164
+ {
165
+ WINPR_ASSERT(sdl);
166
+
167
+ rdpSettings* settings = sdl->context()->settings;
168
+ WINPR_ASSERT(settings);
169
+
170
+ if (!freerdp_settings_get_bool(settings, FreeRDP_Fullscreen) &&
171
+ !freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
172
+ return TRUE;
173
+
174
+ const UINT32 numIds = freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds);
175
+ std::vector<rdpMonitor> monitors;
176
+
177
+ for (UINT32 x = 0; x < numIds; x++)
178
+ {
179
+ auto id = static_cast<const int*>(
180
+ freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorIds, x));
181
+ WINPR_ASSERT(id);
182
+
183
+ float ddpi = 1.0f;
184
+ float hdpi = 1.0f;
185
+ float vdpi = 1.0f;
186
+ SDL_Rect rect = {};
187
+
188
+ if (SDL_GetDisplayBounds(*id, &rect) < 0)
189
+ return FALSE;
190
+
191
+ if (SDL_GetDisplayDPI(*id, &ddpi, &hdpi, &vdpi) < 0)
192
+ return FALSE;
193
+
194
+ WINPR_ASSERT(rect.w > 0);
195
+ WINPR_ASSERT(rect.h > 0);
196
+ WINPR_ASSERT(ddpi > 0);
197
+ WINPR_ASSERT(hdpi > 0);
198
+ WINPR_ASSERT(vdpi > 0);
199
+
200
+ bool highDpi = hdpi > 100;
201
+
202
+ if (highDpi)
203
+ {
204
+ // HighDPI is problematic with SDL: We can only get native resolution by creating a
205
+ // window. Work around this by checking the supported resolutions (and keep maximum)
206
+ // Also scale the DPI
207
+ const SDL_Rect scaleRect = rect;
208
+ for (int i = 0; i < SDL_GetNumDisplayModes(*id); i++)
209
+ {
210
+ SDL_DisplayMode mode = {};
211
+ SDL_GetDisplayMode(WINPR_ASSERTING_INT_CAST(int, x), i, &mode);
212
+
213
+ if (mode.w > rect.w)
214
+ {
215
+ rect.w = mode.w;
216
+ rect.h = mode.h;
217
+ }
218
+ else if (mode.w == rect.w)
219
+ {
220
+ if (mode.h > rect.h)
221
+ {
222
+ rect.w = mode.w;
223
+ rect.h = mode.h;
224
+ }
225
+ }
226
+ }
227
+
228
+ const float dw = 1.0f * static_cast<float>(rect.w) / static_cast<float>(scaleRect.w);
229
+ const float dh = 1.0f * static_cast<float>(rect.h) / static_cast<float>(scaleRect.h);
230
+ hdpi /= dw;
231
+ vdpi /= dh;
232
+ }
233
+
234
+ #if SDL_VERSION_ATLEAST(2, 0, 10)
235
+ const SDL_DisplayOrientation orientation = SDL_GetDisplayOrientation(*id);
236
+ const UINT32 rdp_orientation = sdl_orientaion_to_rdp(orientation);
237
+ #else
238
+ const UINT32 rdp_orientation = ORIENTATION_LANDSCAPE;
239
+ #endif
240
+
241
+ rdpMonitor monitor = {};
242
+
243
+ /* windows uses 96 dpi as 'default' and the scale factors are in percent. */
244
+ const auto factor = ddpi / 96.0f * 100.0f;
245
+ monitor.orig_screen = x;
246
+ monitor.x = rect.x;
247
+ monitor.y = rect.y;
248
+ monitor.width = rect.w;
249
+ monitor.height = rect.h;
250
+ monitor.is_primary = x == 0;
251
+ monitor.attributes.desktopScaleFactor = static_cast<UINT32>(factor);
252
+ monitor.attributes.deviceScaleFactor = 100;
253
+ monitor.attributes.orientation = rdp_orientation;
254
+ monitor.attributes.physicalWidth = scale(WINPR_ASSERTING_INT_CAST(uint32_t, rect.w), hdpi);
255
+ monitor.attributes.physicalHeight = scale(WINPR_ASSERTING_INT_CAST(uint32_t, rect.h), vdpi);
256
+ monitors.emplace_back(monitor);
257
+ }
258
+ return freerdp_settings_set_monitor_def_array_sorted(settings, monitors.data(),
259
+ monitors.size());
260
+ }
261
+
262
+ static BOOL sdl_detect_single_window(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight)
263
+ {
264
+ WINPR_ASSERT(sdl);
265
+ WINPR_ASSERT(pMaxWidth);
266
+ WINPR_ASSERT(pMaxHeight);
267
+
268
+ rdpSettings* settings = sdl->context()->settings;
269
+ WINPR_ASSERT(settings);
270
+
271
+ if ((!freerdp_settings_get_bool(settings, FreeRDP_UseMultimon) &&
272
+ !freerdp_settings_get_bool(settings, FreeRDP_SpanMonitors)) ||
273
+ (freerdp_settings_get_bool(settings, FreeRDP_Workarea) &&
274
+ !freerdp_settings_get_bool(settings, FreeRDP_RemoteApplicationMode)))
275
+ {
276
+ /* If no monitors were specified on the command-line then set the current monitor as active
277
+ */
278
+ if (freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds) == 0)
279
+ {
280
+ const size_t id = (!sdl->windows.empty())
281
+ ? WINPR_ASSERTING_INT_CAST(
282
+ uint32_t, sdl->windows.begin()->second.displayIndex())
283
+ : 0;
284
+ if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorIds, &id, 1))
285
+ return FALSE;
286
+ }
287
+ else
288
+ {
289
+
290
+ /* Always sets number of monitors from command-line to just 1.
291
+ * If the monitor is invalid then we will default back to current monitor
292
+ * later as a fallback. So, there is no need to validate command-line entry here.
293
+ */
294
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_NumMonitorIds, 1))
295
+ return FALSE;
296
+ }
297
+
298
+ // TODO: Fill monitor struct
299
+ if (!sdl_apply_display_properties(sdl))
300
+ return FALSE;
301
+ return sdl_apply_max_size(sdl, pMaxWidth, pMaxHeight);
302
+ }
303
+ return TRUE;
304
+ }
305
+
306
+ BOOL sdl_detect_monitors(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight)
307
+ {
308
+ WINPR_ASSERT(sdl);
309
+ WINPR_ASSERT(pMaxWidth);
310
+ WINPR_ASSERT(pMaxHeight);
311
+
312
+ rdpSettings* settings = sdl->context()->settings;
313
+ WINPR_ASSERT(settings);
314
+
315
+ const int numDisplays = SDL_GetNumVideoDisplays();
316
+ auto nr = freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds);
317
+ if (numDisplays < 0)
318
+ return FALSE;
319
+
320
+ if (nr == 0)
321
+ {
322
+ if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorIds, nullptr,
323
+ static_cast<size_t>(numDisplays)))
324
+ return FALSE;
325
+ for (size_t x = 0; x < static_cast<size_t>(numDisplays); x++)
326
+ {
327
+ if (!freerdp_settings_set_pointer_array(settings, FreeRDP_MonitorIds, x, &x))
328
+ return FALSE;
329
+ }
330
+ }
331
+ else
332
+ {
333
+
334
+ /* There were more IDs supplied than there are monitors */
335
+ if (nr > static_cast<UINT32>(numDisplays))
336
+ {
337
+ WLog_ERR(TAG,
338
+ "Found %" PRIu32 " monitor IDs, but only have %" PRIu32 " monitors connected",
339
+ nr, numDisplays);
340
+ return FALSE;
341
+ }
342
+
343
+ std::vector<UINT32> used;
344
+ for (size_t x = 0; x < nr; x++)
345
+ {
346
+ auto cur = static_cast<const UINT32*>(
347
+ freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorIds, x));
348
+ WINPR_ASSERT(cur);
349
+
350
+ auto id = *cur;
351
+
352
+ /* the ID is no valid monitor index */
353
+ if (id >= nr)
354
+ {
355
+ WLog_ERR(TAG,
356
+ "Supplied monitor ID[%" PRIuz "]=%" PRIu32 " is invalid, only [0-%" PRIu32
357
+ "] are allowed",
358
+ x, id, nr - 1);
359
+ return FALSE;
360
+ }
361
+
362
+ /* The ID is already taken */
363
+ if (std::find(used.begin(), used.end(), id) != used.end())
364
+ {
365
+ WLog_ERR(TAG, "Duplicate monitor ID[%" PRIuz "]=%" PRIu32 " detected", x, id);
366
+ return FALSE;
367
+ }
368
+ used.push_back(*cur);
369
+ }
370
+ }
371
+
372
+ if (!sdl_apply_display_properties(sdl))
373
+ return FALSE;
374
+
375
+ return sdl_detect_single_window(sdl, pMaxWidth, pMaxHeight);
376
+ }
377
+
378
+ INT64 sdl_monitor_id_for_index(SdlContext* sdl, UINT32 index)
379
+ {
380
+ WINPR_ASSERT(sdl);
381
+ auto settings = sdl->context()->settings;
382
+
383
+ auto nr = freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds);
384
+ if (nr == 0)
385
+ return index;
386
+
387
+ if (nr <= index)
388
+ return -1;
389
+
390
+ auto cur = static_cast<const UINT32*>(
391
+ freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorIds, index));
392
+ WINPR_ASSERT(cur);
393
+ return *cur;
394
+ }
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL2/sdl_monitor.hpp ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * SDL Monitor Handling
4
+ *
5
+ * Copyright 2023 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #pragma once
21
+
22
+ #include <freerdp/api.h>
23
+ #include <freerdp/freerdp.h>
24
+
25
+ #include "sdl_types.hpp"
26
+
27
+ int sdl_list_monitors(SdlContext* sdl);
28
+ BOOL sdl_detect_monitors(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight);
29
+ INT64 sdl_monitor_id_for_index(SdlContext* sdl, UINT32 index);
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL2/sdl_touch.hpp ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP SDL touch/mouse input
4
+ *
5
+ * Copyright 2022 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #pragma once
21
+
22
+ #include <winpr/wtypes.h>
23
+
24
+ #include <SDL.h>
25
+ #include "sdl_types.hpp"
26
+
27
+ BOOL sdl_scale_coordinates(SdlContext* sdl, Uint32 windowId, INT32* px, INT32* py,
28
+ BOOL fromLocalToRDP, BOOL applyOffset);
29
+
30
+ BOOL sdl_handle_mouse_motion(SdlContext* sdl, const SDL_MouseMotionEvent* ev);
31
+ BOOL sdl_handle_mouse_wheel(SdlContext* sdl, const SDL_MouseWheelEvent* ev);
32
+ BOOL sdl_handle_mouse_button(SdlContext* sdl, const SDL_MouseButtonEvent* ev);
33
+
34
+ BOOL sdl_handle_touch_down(SdlContext* sdl, const SDL_TouchFingerEvent* ev);
35
+ BOOL sdl_handle_touch_up(SdlContext* sdl, const SDL_TouchFingerEvent* ev);
36
+ BOOL sdl_handle_touch_motion(SdlContext* sdl, const SDL_TouchFingerEvent* ev);
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL2/sdl_utils.cpp ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * SDL Client
4
+ *
5
+ * Copyright 2022 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #include <cassert>
21
+ #include "sdl_utils.hpp"
22
+
23
+ #include "sdl_freerdp.hpp"
24
+
25
+ #include <SDL.h>
26
+
27
+ #include <freerdp/version.h>
28
+
29
+ const char* sdl_event_type_str(Uint32 type)
30
+ {
31
+ #define STR(x) #x
32
+ #define EV_CASE_STR(x) \
33
+ case x: \
34
+ return STR(x)
35
+
36
+ switch (type)
37
+ {
38
+ EV_CASE_STR(SDL_FIRSTEVENT);
39
+ EV_CASE_STR(SDL_QUIT);
40
+ EV_CASE_STR(SDL_APP_TERMINATING);
41
+ EV_CASE_STR(SDL_APP_LOWMEMORY);
42
+ EV_CASE_STR(SDL_APP_WILLENTERBACKGROUND);
43
+ EV_CASE_STR(SDL_APP_DIDENTERBACKGROUND);
44
+ EV_CASE_STR(SDL_APP_WILLENTERFOREGROUND);
45
+ EV_CASE_STR(SDL_APP_DIDENTERFOREGROUND);
46
+ #if SDL_VERSION_ATLEAST(2, 0, 10)
47
+ EV_CASE_STR(SDL_DISPLAYEVENT);
48
+ #endif
49
+ EV_CASE_STR(SDL_WINDOWEVENT);
50
+ EV_CASE_STR(SDL_SYSWMEVENT);
51
+ EV_CASE_STR(SDL_KEYDOWN);
52
+ EV_CASE_STR(SDL_KEYUP);
53
+ EV_CASE_STR(SDL_TEXTEDITING);
54
+ EV_CASE_STR(SDL_TEXTINPUT);
55
+ EV_CASE_STR(SDL_KEYMAPCHANGED);
56
+ EV_CASE_STR(SDL_MOUSEMOTION);
57
+ EV_CASE_STR(SDL_MOUSEBUTTONDOWN);
58
+ EV_CASE_STR(SDL_MOUSEBUTTONUP);
59
+ EV_CASE_STR(SDL_MOUSEWHEEL);
60
+ EV_CASE_STR(SDL_JOYAXISMOTION);
61
+ EV_CASE_STR(SDL_JOYBALLMOTION);
62
+ EV_CASE_STR(SDL_JOYHATMOTION);
63
+ EV_CASE_STR(SDL_JOYBUTTONDOWN);
64
+ EV_CASE_STR(SDL_JOYBUTTONUP);
65
+ EV_CASE_STR(SDL_JOYDEVICEADDED);
66
+ EV_CASE_STR(SDL_JOYDEVICEREMOVED);
67
+ EV_CASE_STR(SDL_CONTROLLERAXISMOTION);
68
+ EV_CASE_STR(SDL_CONTROLLERBUTTONDOWN);
69
+ EV_CASE_STR(SDL_CONTROLLERBUTTONUP);
70
+ EV_CASE_STR(SDL_CONTROLLERDEVICEADDED);
71
+ EV_CASE_STR(SDL_CONTROLLERDEVICEREMOVED);
72
+ EV_CASE_STR(SDL_CONTROLLERDEVICEREMAPPED);
73
+ #if SDL_VERSION_ATLEAST(2, 0, 14)
74
+ EV_CASE_STR(SDL_LOCALECHANGED);
75
+ EV_CASE_STR(SDL_CONTROLLERTOUCHPADDOWN);
76
+ EV_CASE_STR(SDL_CONTROLLERTOUCHPADMOTION);
77
+ EV_CASE_STR(SDL_CONTROLLERTOUCHPADUP);
78
+ EV_CASE_STR(SDL_CONTROLLERSENSORUPDATE);
79
+ #endif
80
+ EV_CASE_STR(SDL_FINGERDOWN);
81
+ EV_CASE_STR(SDL_FINGERUP);
82
+ EV_CASE_STR(SDL_FINGERMOTION);
83
+ EV_CASE_STR(SDL_DOLLARGESTURE);
84
+ EV_CASE_STR(SDL_DOLLARRECORD);
85
+ EV_CASE_STR(SDL_MULTIGESTURE);
86
+ EV_CASE_STR(SDL_CLIPBOARDUPDATE);
87
+ EV_CASE_STR(SDL_DROPFILE);
88
+ EV_CASE_STR(SDL_DROPTEXT);
89
+ EV_CASE_STR(SDL_DROPBEGIN);
90
+ EV_CASE_STR(SDL_DROPCOMPLETE);
91
+ EV_CASE_STR(SDL_AUDIODEVICEADDED);
92
+ EV_CASE_STR(SDL_AUDIODEVICEREMOVED);
93
+ #if SDL_VERSION_ATLEAST(2, 0, 9)
94
+ EV_CASE_STR(SDL_SENSORUPDATE);
95
+ #endif
96
+ EV_CASE_STR(SDL_RENDER_TARGETS_RESET);
97
+ EV_CASE_STR(SDL_RENDER_DEVICE_RESET);
98
+ EV_CASE_STR(SDL_USEREVENT);
99
+
100
+ EV_CASE_STR(SDL_USEREVENT_CERT_DIALOG);
101
+ EV_CASE_STR(SDL_USEREVENT_CERT_RESULT);
102
+ EV_CASE_STR(SDL_USEREVENT_SHOW_DIALOG);
103
+ EV_CASE_STR(SDL_USEREVENT_SHOW_RESULT);
104
+ EV_CASE_STR(SDL_USEREVENT_AUTH_DIALOG);
105
+ EV_CASE_STR(SDL_USEREVENT_AUTH_RESULT);
106
+ EV_CASE_STR(SDL_USEREVENT_SCARD_DIALOG);
107
+ EV_CASE_STR(SDL_USEREVENT_RETRY_DIALOG);
108
+ EV_CASE_STR(SDL_USEREVENT_SCARD_RESULT);
109
+ EV_CASE_STR(SDL_USEREVENT_UPDATE);
110
+ EV_CASE_STR(SDL_USEREVENT_CREATE_WINDOWS);
111
+ EV_CASE_STR(SDL_USEREVENT_WINDOW_RESIZEABLE);
112
+ EV_CASE_STR(SDL_USEREVENT_WINDOW_FULLSCREEN);
113
+ EV_CASE_STR(SDL_USEREVENT_WINDOW_MINIMIZE);
114
+ EV_CASE_STR(SDL_USEREVENT_POINTER_NULL);
115
+ EV_CASE_STR(SDL_USEREVENT_POINTER_DEFAULT);
116
+ EV_CASE_STR(SDL_USEREVENT_POINTER_POSITION);
117
+ EV_CASE_STR(SDL_USEREVENT_POINTER_SET);
118
+ EV_CASE_STR(SDL_USEREVENT_QUIT);
119
+
120
+ EV_CASE_STR(SDL_LASTEVENT);
121
+ default:
122
+ return "SDL_UNKNOWNEVENT";
123
+ }
124
+ #undef EV_CASE_STR
125
+ #undef STR
126
+ }
127
+
128
+ const char* sdl_error_string(Sint32 res)
129
+ {
130
+ if (res == 0)
131
+ return nullptr;
132
+
133
+ return SDL_GetError();
134
+ }
135
+
136
+ BOOL sdl_log_error_ex(Sint32 res, wLog* log, const char* what, const char* file, size_t line,
137
+ const char* fkt)
138
+ {
139
+ const char* msg = sdl_error_string(res);
140
+
141
+ WINPR_UNUSED(file);
142
+
143
+ if (!msg)
144
+ return FALSE;
145
+
146
+ WLog_Print(log, WLOG_ERROR, "[%s:%" PRIuz "][%s]: %s", fkt, line, what, msg);
147
+ return TRUE;
148
+ }
149
+
150
+ BOOL sdl_push_user_event(Uint32 type, ...)
151
+ {
152
+ SDL_Event ev = {};
153
+ SDL_UserEvent* event = &ev.user;
154
+
155
+ va_list ap = {};
156
+ va_start(ap, type);
157
+ event->type = type;
158
+ switch (type)
159
+ {
160
+ case SDL_USEREVENT_AUTH_RESULT:
161
+ {
162
+ auto arg = reinterpret_cast<SDL_UserAuthArg*>(ev.padding);
163
+ arg->user = va_arg(ap, char*);
164
+ arg->domain = va_arg(ap, char*);
165
+ arg->password = va_arg(ap, char*);
166
+ arg->result = va_arg(ap, Sint32);
167
+ }
168
+ break;
169
+ case SDL_USEREVENT_AUTH_DIALOG:
170
+ {
171
+ auto arg = reinterpret_cast<SDL_UserAuthArg*>(ev.padding);
172
+
173
+ arg->title = va_arg(ap, char*);
174
+ arg->user = va_arg(ap, char*);
175
+ arg->domain = va_arg(ap, char*);
176
+ arg->password = va_arg(ap, char*);
177
+ arg->result = va_arg(ap, Sint32);
178
+ }
179
+ break;
180
+ case SDL_USEREVENT_SCARD_DIALOG:
181
+ {
182
+ event->data1 = va_arg(ap, char*);
183
+ event->data2 = va_arg(ap, char**);
184
+ event->code = va_arg(ap, Sint32);
185
+ }
186
+ break;
187
+ case SDL_USEREVENT_RETRY_DIALOG:
188
+ break;
189
+ case SDL_USEREVENT_SCARD_RESULT:
190
+ case SDL_USEREVENT_SHOW_RESULT:
191
+ case SDL_USEREVENT_CERT_RESULT:
192
+ event->code = va_arg(ap, Sint32);
193
+ break;
194
+
195
+ case SDL_USEREVENT_SHOW_DIALOG:
196
+ event->data1 = va_arg(ap, char*);
197
+ event->data2 = va_arg(ap, char*);
198
+ event->code = va_arg(ap, Sint32);
199
+ break;
200
+ case SDL_USEREVENT_CERT_DIALOG:
201
+ event->data1 = va_arg(ap, char*);
202
+ event->data2 = va_arg(ap, char*);
203
+ break;
204
+ case SDL_USEREVENT_UPDATE:
205
+ event->data1 = va_arg(ap, void*);
206
+ break;
207
+ case SDL_USEREVENT_POINTER_POSITION:
208
+ event->data1 = reinterpret_cast<void*>(static_cast<uintptr_t>(va_arg(ap, UINT32)));
209
+ event->data2 = reinterpret_cast<void*>(static_cast<uintptr_t>(va_arg(ap, UINT32)));
210
+ break;
211
+ case SDL_USEREVENT_POINTER_SET:
212
+ event->data1 = va_arg(ap, void*);
213
+ event->data2 = va_arg(ap, void*);
214
+ break;
215
+ case SDL_USEREVENT_CREATE_WINDOWS:
216
+ event->data1 = va_arg(ap, void*);
217
+ break;
218
+ case SDL_USEREVENT_WINDOW_FULLSCREEN:
219
+ case SDL_USEREVENT_WINDOW_RESIZEABLE:
220
+ event->data1 = va_arg(ap, void*);
221
+ event->code = va_arg(ap, int);
222
+ break;
223
+ case SDL_USEREVENT_WINDOW_MINIMIZE:
224
+ case SDL_USEREVENT_QUIT:
225
+ case SDL_USEREVENT_POINTER_NULL:
226
+ case SDL_USEREVENT_POINTER_DEFAULT:
227
+ break;
228
+ default:
229
+ va_end(ap);
230
+ return FALSE;
231
+ }
232
+ va_end(ap);
233
+ return SDL_PushEvent(&ev) == 1;
234
+ }
235
+
236
+ CriticalSection::CriticalSection()
237
+ {
238
+ InitializeCriticalSection(&_section);
239
+ }
240
+
241
+ CriticalSection::~CriticalSection()
242
+ {
243
+ DeleteCriticalSection(&_section);
244
+ }
245
+
246
+ void CriticalSection::lock()
247
+ {
248
+ EnterCriticalSection(&_section);
249
+ }
250
+
251
+ void CriticalSection::unlock()
252
+ {
253
+ LeaveCriticalSection(&_section);
254
+ }
255
+
256
+ WinPREvent::WinPREvent(bool initial) : _handle(CreateEventA(nullptr, TRUE, initial, nullptr))
257
+ {
258
+ }
259
+
260
+ WinPREvent::~WinPREvent()
261
+ {
262
+ (void)CloseHandle(_handle);
263
+ }
264
+
265
+ void WinPREvent::set()
266
+ {
267
+ (void)SetEvent(_handle);
268
+ }
269
+
270
+ void WinPREvent::clear()
271
+ {
272
+ (void)ResetEvent(_handle);
273
+ }
274
+
275
+ bool WinPREvent::isSet() const
276
+ {
277
+ return WaitForSingleObject(_handle, 0) == WAIT_OBJECT_0;
278
+ }
279
+
280
+ HANDLE WinPREvent::handle() const
281
+ {
282
+ return _handle;
283
+ }
284
+
285
+ bool sdl_push_quit()
286
+ {
287
+ SDL_Event ev = {};
288
+ ev.type = SDL_QUIT;
289
+ SDL_PushEvent(&ev);
290
+ return true;
291
+ }
292
+
293
+ std::string sdl_window_event_str(Uint8 ev)
294
+ {
295
+ switch (ev)
296
+ {
297
+ case SDL_WINDOWEVENT_NONE:
298
+ return "SDL_WINDOWEVENT_NONE";
299
+ case SDL_WINDOWEVENT_SHOWN:
300
+ return "SDL_WINDOWEVENT_SHOWN";
301
+ case SDL_WINDOWEVENT_HIDDEN:
302
+ return "SDL_WINDOWEVENT_HIDDEN";
303
+ case SDL_WINDOWEVENT_EXPOSED:
304
+ return "SDL_WINDOWEVENT_EXPOSED";
305
+ case SDL_WINDOWEVENT_MOVED:
306
+ return "SDL_WINDOWEVENT_MOVED";
307
+ case SDL_WINDOWEVENT_RESIZED:
308
+ return "SDL_WINDOWEVENT_RESIZED";
309
+ case SDL_WINDOWEVENT_SIZE_CHANGED:
310
+ return "SDL_WINDOWEVENT_SIZE_CHANGED";
311
+ case SDL_WINDOWEVENT_MINIMIZED:
312
+ return "SDL_WINDOWEVENT_MINIMIZED";
313
+ case SDL_WINDOWEVENT_MAXIMIZED:
314
+ return "SDL_WINDOWEVENT_MAXIMIZED";
315
+ case SDL_WINDOWEVENT_RESTORED:
316
+ return "SDL_WINDOWEVENT_RESTORED";
317
+ case SDL_WINDOWEVENT_ENTER:
318
+ return "SDL_WINDOWEVENT_ENTER";
319
+ case SDL_WINDOWEVENT_LEAVE:
320
+ return "SDL_WINDOWEVENT_LEAVE";
321
+ case SDL_WINDOWEVENT_FOCUS_GAINED:
322
+ return "SDL_WINDOWEVENT_FOCUS_GAINED";
323
+ case SDL_WINDOWEVENT_FOCUS_LOST:
324
+ return "SDL_WINDOWEVENT_FOCUS_LOST";
325
+ case SDL_WINDOWEVENT_CLOSE:
326
+ return "SDL_WINDOWEVENT_CLOSE";
327
+ #if SDL_VERSION_ATLEAST(2, 0, 5)
328
+ case SDL_WINDOWEVENT_TAKE_FOCUS:
329
+ return "SDL_WINDOWEVENT_TAKE_FOCUS";
330
+ case SDL_WINDOWEVENT_HIT_TEST:
331
+ return "SDL_WINDOWEVENT_HIT_TEST";
332
+ #endif
333
+ #if SDL_VERSION_ATLEAST(2, 0, 18)
334
+ case SDL_WINDOWEVENT_ICCPROF_CHANGED:
335
+ return "SDL_WINDOWEVENT_ICCPROF_CHANGED";
336
+ case SDL_WINDOWEVENT_DISPLAY_CHANGED:
337
+ return "SDL_WINDOWEVENT_DISPLAY_CHANGED";
338
+ #endif
339
+ default:
340
+ return "SDL_WINDOWEVENT_UNKNOWN";
341
+ }
342
+ }
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_channels.cpp ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * SDL Client Channels
4
+ *
5
+ * Copyright 2022 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #include <freerdp/config.h>
21
+
22
+ #include <winpr/assert.h>
23
+
24
+ #include <freerdp/client/rail.h>
25
+ #include <freerdp/client/cliprdr.h>
26
+ #include <freerdp/client/disp.h>
27
+
28
+ #include "sdl_channels.hpp"
29
+ #include "sdl_freerdp.hpp"
30
+ #include "sdl_disp.hpp"
31
+
32
+ void sdl_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e)
33
+ {
34
+ auto sdl = get_context(context);
35
+
36
+ WINPR_ASSERT(sdl);
37
+ WINPR_ASSERT(e);
38
+
39
+ if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0)
40
+ {
41
+ }
42
+ else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
43
+ {
44
+ auto clip = reinterpret_cast<CliprdrClientContext*>(e->pInterface);
45
+ WINPR_ASSERT(clip);
46
+ sdl->clip.init(clip);
47
+ }
48
+ else if (strcmp(e->name, DISP_DVC_CHANNEL_NAME) == 0)
49
+ {
50
+ auto disp = reinterpret_cast<DispClientContext*>(e->pInterface);
51
+ WINPR_ASSERT(disp);
52
+ sdl->disp.init(disp);
53
+ }
54
+ else
55
+ freerdp_client_OnChannelConnectedEventHandler(context, e);
56
+ }
57
+
58
+ void sdl_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e)
59
+ {
60
+ auto sdl = get_context(context);
61
+
62
+ WINPR_ASSERT(sdl);
63
+ WINPR_ASSERT(e);
64
+
65
+ // TODO: Set resizeable depending on disp channel and /dynamic-resolution
66
+ if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0)
67
+ {
68
+ }
69
+ else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
70
+ {
71
+ auto clip = reinterpret_cast<CliprdrClientContext*>(e->pInterface);
72
+ WINPR_ASSERT(clip);
73
+ clip->custom = nullptr;
74
+ }
75
+ else if (strcmp(e->name, DISP_DVC_CHANNEL_NAME) == 0)
76
+ {
77
+ auto disp = reinterpret_cast<DispClientContext*>(e->pInterface);
78
+ WINPR_ASSERT(disp);
79
+ sdl->disp.uninit(disp);
80
+ }
81
+ else
82
+ freerdp_client_OnChannelDisconnectedEventHandler(context, e);
83
+ }
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_channels.hpp ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * SDL Client Channels
4
+ *
5
+ * Copyright 2022 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #pragma once
21
+
22
+ #include <freerdp/freerdp.h>
23
+ #include <freerdp/client/channels.h>
24
+
25
+ int sdl_on_channel_connected(freerdp* instance, const char* name, void* pInterface);
26
+ int sdl_on_channel_disconnected(freerdp* instance, const char* name, void* pInterface);
27
+
28
+ void sdl_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e);
29
+ void sdl_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e);
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_clip.hpp ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * SDL Client keyboard helper
4
+ *
5
+ * Copyright 2024 Armin Novak <[email protected]>
6
+ * Copyright 2024 Thincast Technologies GmbH
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ #pragma once
22
+
23
+ #include <utility>
24
+ #include <vector>
25
+ #include <atomic>
26
+ #include <queue>
27
+ #include <map>
28
+
29
+ #include <winpr/wtypes.h>
30
+ #include <freerdp/freerdp.h>
31
+ #include <freerdp/client/client_cliprdr_file.h>
32
+ #include <SDL3/SDL.h>
33
+
34
+ #include "sdl_types.hpp"
35
+ #include "sdl_utils.hpp"
36
+
37
+ /** @brief a clipboard format request */
38
+ class ClipRequest
39
+ {
40
+ public:
41
+ ClipRequest(UINT32 format, const std::string& mime);
42
+ ClipRequest(const ClipRequest& other) = default;
43
+ ClipRequest(ClipRequest&& other) = default;
44
+ ~ClipRequest() = default;
45
+
46
+ ClipRequest& operator=(const ClipRequest& other) = delete;
47
+ ClipRequest& operator=(ClipRequest&& other) = delete;
48
+
49
+ [[nodiscard]] uint32_t format() const;
50
+ [[nodiscard]] std::string formatstr() const;
51
+ [[nodiscard]] std::string mime() const;
52
+ [[nodiscard]] bool success() const;
53
+ void setSuccess(bool status);
54
+
55
+ private:
56
+ uint32_t _format;
57
+ std::string _mime;
58
+ bool _success;
59
+ };
60
+
61
+ class CliprdrFormat
62
+ {
63
+ public:
64
+ CliprdrFormat(uint32_t formatID, const char* formatName) : _formatID(formatID)
65
+ {
66
+ if (formatName)
67
+ _formatName = formatName;
68
+ }
69
+
70
+ [[nodiscard]] uint32_t formatId() const
71
+ {
72
+ return _formatID;
73
+ }
74
+
75
+ [[nodiscard]] const char* formatName() const
76
+ {
77
+ if (_formatName.empty())
78
+ return nullptr;
79
+ return _formatName.c_str();
80
+ }
81
+
82
+ private:
83
+ uint32_t _formatID;
84
+ std::string _formatName;
85
+ };
86
+
87
+ /** @brief object that handles clipboard context for the SDL3 client */
88
+ class sdlClip
89
+ {
90
+ public:
91
+ explicit sdlClip(SdlContext* sdl);
92
+ virtual ~sdlClip();
93
+
94
+ BOOL init(CliprdrClientContext* clip);
95
+ BOOL uninit(CliprdrClientContext* clip);
96
+
97
+ bool handle_update(const SDL_ClipboardEvent& ev);
98
+
99
+ private:
100
+ UINT SendClientCapabilities();
101
+ void clearServerFormats();
102
+ UINT SendFormatListResponse(BOOL status);
103
+ UINT SendDataResponse(const BYTE* data, size_t size);
104
+ UINT SendDataRequest(uint32_t formatID, const std::string& mime);
105
+
106
+ std::string getServerFormat(uint32_t id);
107
+ uint32_t serverIdForMime(const std::string& mime);
108
+
109
+ static UINT MonitorReady(CliprdrClientContext* context,
110
+ const CLIPRDR_MONITOR_READY* monitorReady);
111
+
112
+ static UINT ReceiveServerCapabilities(CliprdrClientContext* context,
113
+ const CLIPRDR_CAPABILITIES* capabilities);
114
+ static UINT ReceiveServerFormatList(CliprdrClientContext* context,
115
+ const CLIPRDR_FORMAT_LIST* formatList);
116
+ static UINT ReceiveFormatListResponse(CliprdrClientContext* context,
117
+ const CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse);
118
+ static std::shared_ptr<BYTE> ReceiveFormatDataRequestHandle(
119
+ sdlClip* clipboard, const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest, uint32_t& len);
120
+ static UINT ReceiveFormatDataRequest(CliprdrClientContext* context,
121
+ const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest);
122
+ static UINT ReceiveFormatDataResponse(CliprdrClientContext* context,
123
+ const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse);
124
+
125
+ static const void* SDLCALL ClipDataCb(void* userdata, const char* mime_type, size_t* size);
126
+ static void SDLCALL ClipCleanCb(void* userdata);
127
+
128
+ static bool mime_is_file(const std::string& mime);
129
+ static bool mime_is_text(const std::string& mime);
130
+ static bool mime_is_image(const std::string& mime);
131
+ static bool mime_is_html(const std::string& mime);
132
+
133
+ SdlContext* _sdl = nullptr;
134
+ CliprdrFileContext* _file = nullptr;
135
+ CliprdrClientContext* _ctx = nullptr;
136
+ wLog* _log = nullptr;
137
+ wClipboard* _system = nullptr;
138
+ std::atomic<bool> _sync = false;
139
+ HANDLE _event;
140
+
141
+ std::vector<CliprdrFormat> _serverFormats;
142
+ CriticalSection _lock;
143
+
144
+ std::queue<ClipRequest> _request_queue;
145
+
146
+ struct cache_entry
147
+ {
148
+ cache_entry(size_t len, std::shared_ptr<void> p) : size(len), ptr(std::move(p))
149
+ {
150
+ }
151
+
152
+ size_t size;
153
+ std::shared_ptr<void> ptr;
154
+ };
155
+ std::map<std::string, cache_entry> _cache_data;
156
+ std::vector<const char*> _current_mimetypes;
157
+ };
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_disp.cpp ADDED
@@ -0,0 +1,473 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * SDL Display Control Channel
4
+ *
5
+ * Copyright 2023 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #include <vector>
21
+ #include <winpr/sysinfo.h>
22
+ #include <winpr/assert.h>
23
+
24
+ #include <freerdp/gdi/gdi.h>
25
+
26
+ #include <SDL3/SDL.h>
27
+
28
+ #include "sdl_disp.hpp"
29
+ #include "sdl_kbd.hpp"
30
+ #include "sdl_utils.hpp"
31
+ #include "sdl_freerdp.hpp"
32
+
33
+ #include <freerdp/log.h>
34
+ #define TAG CLIENT_TAG("sdl.disp")
35
+
36
+ static constexpr UINT64 RESIZE_MIN_DELAY = 200; /* minimum delay in ms between two resizes */
37
+ static constexpr unsigned MAX_RETRIES = 5;
38
+
39
+ BOOL sdlDispContext::settings_changed()
40
+ {
41
+ auto settings = _sdl->context()->settings;
42
+ WINPR_ASSERT(settings);
43
+
44
+ if (_lastSentWidth != _targetWidth)
45
+ return TRUE;
46
+
47
+ if (_lastSentHeight != _targetHeight)
48
+ return TRUE;
49
+
50
+ if (_lastSentDesktopOrientation !=
51
+ freerdp_settings_get_uint16(settings, FreeRDP_DesktopOrientation))
52
+ return TRUE;
53
+
54
+ if (_lastSentDesktopScaleFactor !=
55
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopScaleFactor))
56
+ return TRUE;
57
+
58
+ if (_lastSentDeviceScaleFactor !=
59
+ freerdp_settings_get_uint32(settings, FreeRDP_DeviceScaleFactor))
60
+ return TRUE;
61
+ /* TODO
62
+ if (_fullscreen != _sdl->fullscreen)
63
+ return TRUE;
64
+ */
65
+ return FALSE;
66
+ }
67
+
68
+ BOOL sdlDispContext::update_last_sent()
69
+ {
70
+ WINPR_ASSERT(_sdl);
71
+
72
+ auto settings = _sdl->context()->settings;
73
+ WINPR_ASSERT(settings);
74
+
75
+ _lastSentWidth = _targetWidth;
76
+ _lastSentHeight = _targetHeight;
77
+ _lastSentDesktopOrientation = freerdp_settings_get_uint16(settings, FreeRDP_DesktopOrientation);
78
+ _lastSentDesktopScaleFactor = freerdp_settings_get_uint32(settings, FreeRDP_DesktopScaleFactor);
79
+ _lastSentDeviceScaleFactor = freerdp_settings_get_uint32(settings, FreeRDP_DeviceScaleFactor);
80
+ // TODO _fullscreen = _sdl->fullscreen;
81
+ return TRUE;
82
+ }
83
+
84
+ BOOL sdlDispContext::sendResize()
85
+ {
86
+ DISPLAY_CONTROL_MONITOR_LAYOUT layout = {};
87
+ auto settings = _sdl->context()->settings;
88
+
89
+ if (!settings)
90
+ return FALSE;
91
+
92
+ if (!_activated || !_disp)
93
+ return TRUE;
94
+
95
+ if (GetTickCount64() - _lastSentDate < RESIZE_MIN_DELAY)
96
+ return TRUE;
97
+
98
+ _lastSentDate = GetTickCount64();
99
+
100
+ if (!settings_changed())
101
+ return TRUE;
102
+
103
+ const UINT32 mcount = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
104
+ if (_sdl->fullscreen && (mcount > 0))
105
+ {
106
+ auto monitors = static_cast<const rdpMonitor*>(
107
+ freerdp_settings_get_pointer(settings, FreeRDP_MonitorDefArray));
108
+ if (sendLayout(monitors, mcount) != CHANNEL_RC_OK)
109
+ return FALSE;
110
+ }
111
+ else
112
+ {
113
+ _waitingResize = TRUE;
114
+ layout.Flags = DISPLAY_CONTROL_MONITOR_PRIMARY;
115
+ layout.Top = layout.Left = 0;
116
+ layout.Width = WINPR_ASSERTING_INT_CAST(uint32_t, _targetWidth);
117
+ layout.Height = WINPR_ASSERTING_INT_CAST(uint32_t, _targetHeight);
118
+ layout.Orientation = freerdp_settings_get_uint16(settings, FreeRDP_DesktopOrientation);
119
+ layout.DesktopScaleFactor =
120
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopScaleFactor);
121
+ layout.DeviceScaleFactor = freerdp_settings_get_uint32(settings, FreeRDP_DeviceScaleFactor);
122
+ layout.PhysicalWidth = WINPR_ASSERTING_INT_CAST(uint32_t, _targetWidth);
123
+ layout.PhysicalHeight = WINPR_ASSERTING_INT_CAST(uint32_t, _targetHeight);
124
+
125
+ if (IFCALLRESULT(CHANNEL_RC_OK, _disp->SendMonitorLayout, _disp, 1, &layout) !=
126
+ CHANNEL_RC_OK)
127
+ return FALSE;
128
+ }
129
+ return update_last_sent();
130
+ }
131
+
132
+ BOOL sdlDispContext::set_window_resizable()
133
+ {
134
+ _sdl->update_resizeable(TRUE);
135
+ return TRUE;
136
+ }
137
+
138
+ static BOOL sdl_disp_check_context(void* context, SdlContext** ppsdl, sdlDispContext** ppsdlDisp,
139
+ rdpSettings** ppSettings)
140
+ {
141
+ if (!context)
142
+ return FALSE;
143
+
144
+ auto sdl = get_context(context);
145
+ if (!sdl)
146
+ return FALSE;
147
+
148
+ if (!sdl->context()->settings)
149
+ return FALSE;
150
+
151
+ *ppsdl = sdl;
152
+ *ppsdlDisp = &sdl->disp;
153
+ *ppSettings = sdl->context()->settings;
154
+ return TRUE;
155
+ }
156
+
157
+ void sdlDispContext::OnActivated(void* context, const ActivatedEventArgs* e)
158
+ {
159
+ SdlContext* sdl = nullptr;
160
+ sdlDispContext* sdlDisp = nullptr;
161
+ rdpSettings* settings = nullptr;
162
+
163
+ if (!sdl_disp_check_context(context, &sdl, &sdlDisp, &settings))
164
+ return;
165
+
166
+ sdlDisp->_waitingResize = FALSE;
167
+
168
+ if (sdlDisp->_activated && !freerdp_settings_get_bool(settings, FreeRDP_Fullscreen))
169
+ {
170
+ sdlDisp->set_window_resizable();
171
+
172
+ if (e->firstActivation)
173
+ return;
174
+
175
+ sdlDisp->addTimer();
176
+ }
177
+ }
178
+
179
+ void sdlDispContext::OnGraphicsReset(void* context, const GraphicsResetEventArgs* e)
180
+ {
181
+ SdlContext* sdl = nullptr;
182
+ sdlDispContext* sdlDisp = nullptr;
183
+ rdpSettings* settings = nullptr;
184
+
185
+ WINPR_UNUSED(e);
186
+ if (!sdl_disp_check_context(context, &sdl, &sdlDisp, &settings))
187
+ return;
188
+
189
+ sdlDisp->_waitingResize = FALSE;
190
+
191
+ if (sdlDisp->_activated && !freerdp_settings_get_bool(settings, FreeRDP_Fullscreen))
192
+ {
193
+ sdlDisp->set_window_resizable();
194
+ sdlDisp->addTimer();
195
+ }
196
+ }
197
+
198
+ Uint32 sdlDispContext::OnTimer(void* param, SDL_TimerID timerID, Uint32 interval)
199
+ {
200
+ auto ctx = static_cast<sdlDispContext*>(param);
201
+ if (!ctx)
202
+ return 0;
203
+
204
+ SdlContext* sdl = ctx->_sdl;
205
+ if (!sdl)
206
+ return 0;
207
+
208
+ sdlDispContext* sdlDisp = nullptr;
209
+ rdpSettings* settings = nullptr;
210
+
211
+ if (!sdl_disp_check_context(sdl->context(), &sdl, &sdlDisp, &settings))
212
+ return 0;
213
+
214
+ WLog_Print(sdl->log, WLOG_TRACE, "checking for display changes...");
215
+ if (!sdlDisp->_activated || freerdp_settings_get_bool(settings, FreeRDP_Fullscreen))
216
+ return 0;
217
+ else
218
+ {
219
+ auto rc = sdlDisp->sendResize();
220
+ if (!rc)
221
+ WLog_Print(sdl->log, WLOG_TRACE, "sent new display layout, result %d", rc);
222
+ }
223
+ if (sdlDisp->_timer_retries++ >= MAX_RETRIES)
224
+ {
225
+ WLog_Print(sdl->log, WLOG_TRACE, "deactivate timer, retries exceeded");
226
+ return 0;
227
+ }
228
+
229
+ WLog_Print(sdl->log, WLOG_TRACE, "fire timer one more time");
230
+ return interval;
231
+ }
232
+
233
+ UINT sdlDispContext::sendLayout(const rdpMonitor* monitors, size_t nmonitors)
234
+ {
235
+ UINT ret = CHANNEL_RC_OK;
236
+
237
+ WINPR_ASSERT(monitors);
238
+ WINPR_ASSERT(nmonitors > 0);
239
+
240
+ auto settings = _sdl->context()->settings;
241
+ WINPR_ASSERT(settings);
242
+
243
+ std::vector<DISPLAY_CONTROL_MONITOR_LAYOUT> layouts;
244
+ layouts.resize(nmonitors);
245
+
246
+ for (size_t i = 0; i < nmonitors; i++)
247
+ {
248
+ auto monitor = &monitors[i];
249
+ auto layout = &layouts[i];
250
+
251
+ layout->Flags = (monitor->is_primary ? DISPLAY_CONTROL_MONITOR_PRIMARY : 0);
252
+ layout->Left = monitor->x;
253
+ layout->Top = monitor->y;
254
+ layout->Width = WINPR_ASSERTING_INT_CAST(uint32_t, monitor->width);
255
+ layout->Height = WINPR_ASSERTING_INT_CAST(uint32_t, monitor->height);
256
+ layout->Orientation = ORIENTATION_LANDSCAPE;
257
+ layout->PhysicalWidth = monitor->attributes.physicalWidth;
258
+ layout->PhysicalHeight = monitor->attributes.physicalHeight;
259
+
260
+ switch (monitor->attributes.orientation)
261
+ {
262
+ case 90:
263
+ layout->Orientation = ORIENTATION_PORTRAIT;
264
+ break;
265
+
266
+ case 180:
267
+ layout->Orientation = ORIENTATION_LANDSCAPE_FLIPPED;
268
+ break;
269
+
270
+ case 270:
271
+ layout->Orientation = ORIENTATION_PORTRAIT_FLIPPED;
272
+ break;
273
+
274
+ case 0:
275
+ default:
276
+ /* MS-RDPEDISP - 2.2.2.2.1:
277
+ * Orientation (4 bytes): A 32-bit unsigned integer that specifies the
278
+ * orientation of the monitor in degrees. Valid values are 0, 90, 180
279
+ * or 270
280
+ *
281
+ * So we default to ORIENTATION_LANDSCAPE
282
+ */
283
+ layout->Orientation = ORIENTATION_LANDSCAPE;
284
+ break;
285
+ }
286
+
287
+ layout->DesktopScaleFactor =
288
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopScaleFactor);
289
+ layout->DeviceScaleFactor =
290
+ freerdp_settings_get_uint32(settings, FreeRDP_DeviceScaleFactor);
291
+ }
292
+
293
+ WINPR_ASSERT(_disp);
294
+ const size_t len = layouts.size();
295
+ WINPR_ASSERT(len <= UINT32_MAX);
296
+ ret = IFCALLRESULT(CHANNEL_RC_OK, _disp->SendMonitorLayout, _disp, static_cast<UINT32>(len),
297
+ layouts.data());
298
+ return ret;
299
+ }
300
+
301
+ BOOL sdlDispContext::addTimer()
302
+ {
303
+ if (SDL_WasInit(SDL_INIT_EVENTS) == 0)
304
+ return FALSE;
305
+
306
+ SDL_RemoveTimer(_timer);
307
+ WLog_Print(_sdl->log, WLOG_TRACE, "adding new display check timer");
308
+
309
+ _timer_retries = 0;
310
+ sendResize();
311
+ _timer = SDL_AddTimer(1000, sdlDispContext::OnTimer, this);
312
+ return TRUE;
313
+ }
314
+
315
+ BOOL sdlDispContext::handle_display_event(const SDL_DisplayEvent* ev)
316
+ {
317
+ WINPR_ASSERT(ev);
318
+
319
+ switch (ev->type)
320
+ {
321
+ case SDL_EVENT_DISPLAY_ADDED:
322
+ SDL_Log("A new display with id %u was connected", ev->displayID);
323
+ return TRUE;
324
+ case SDL_EVENT_DISPLAY_REMOVED:
325
+ SDL_Log("The display with id %u was disconnected", ev->displayID);
326
+ return TRUE;
327
+ case SDL_EVENT_DISPLAY_ORIENTATION:
328
+ SDL_Log("The orientation of display with id %u was changed", ev->displayID);
329
+ return TRUE;
330
+ default:
331
+ return TRUE;
332
+ }
333
+ }
334
+
335
+ BOOL sdlDispContext::handle_window_event(const SDL_WindowEvent* ev)
336
+ {
337
+ WINPR_ASSERT(ev);
338
+
339
+ auto bordered = freerdp_settings_get_bool(_sdl->context()->settings, FreeRDP_Decorations);
340
+
341
+ auto it = _sdl->windows.find(ev->windowID);
342
+ if (it != _sdl->windows.end())
343
+ it->second.setBordered(bordered);
344
+
345
+ switch (ev->type)
346
+ {
347
+ case SDL_EVENT_WINDOW_HIDDEN:
348
+ case SDL_EVENT_WINDOW_MINIMIZED:
349
+ gdi_send_suppress_output(_sdl->context()->gdi, TRUE);
350
+
351
+ return TRUE;
352
+
353
+ case SDL_EVENT_WINDOW_EXPOSED:
354
+ case SDL_EVENT_WINDOW_SHOWN:
355
+ case SDL_EVENT_WINDOW_MAXIMIZED:
356
+ case SDL_EVENT_WINDOW_RESTORED:
357
+ gdi_send_suppress_output(_sdl->context()->gdi, FALSE);
358
+ return TRUE;
359
+
360
+ case SDL_EVENT_WINDOW_RESIZED:
361
+ case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
362
+ _targetWidth = ev->data1;
363
+ _targetHeight = ev->data2;
364
+ return addTimer();
365
+
366
+ case SDL_EVENT_WINDOW_MOUSE_LEAVE:
367
+ WINPR_ASSERT(_sdl);
368
+ _sdl->input.keyboard_grab(ev->windowID, false);
369
+ return TRUE;
370
+ case SDL_EVENT_WINDOW_MOUSE_ENTER:
371
+ WINPR_ASSERT(_sdl);
372
+ _sdl->input.keyboard_grab(ev->windowID, true);
373
+ return _sdl->input.keyboard_focus_in();
374
+ case SDL_EVENT_WINDOW_FOCUS_GAINED:
375
+ return _sdl->input.keyboard_focus_in();
376
+
377
+ default:
378
+ return TRUE;
379
+ }
380
+ }
381
+
382
+ UINT sdlDispContext::DisplayControlCaps(DispClientContext* disp, UINT32 maxNumMonitors,
383
+ UINT32 maxMonitorAreaFactorA, UINT32 maxMonitorAreaFactorB)
384
+ {
385
+ /* we're called only if dynamic resolution update is activated */
386
+ WINPR_ASSERT(disp);
387
+
388
+ auto sdlDisp = reinterpret_cast<sdlDispContext*>(disp->custom);
389
+ return sdlDisp->DisplayControlCaps(maxNumMonitors, maxMonitorAreaFactorA,
390
+ maxMonitorAreaFactorB);
391
+ }
392
+
393
+ UINT sdlDispContext::DisplayControlCaps(UINT32 maxNumMonitors, UINT32 maxMonitorAreaFactorA,
394
+ UINT32 maxMonitorAreaFactorB)
395
+ {
396
+ auto settings = _sdl->context()->settings;
397
+ WINPR_ASSERT(settings);
398
+
399
+ WLog_DBG(TAG,
400
+ "DisplayControlCapsPdu: MaxNumMonitors: %" PRIu32 " MaxMonitorAreaFactorA: %" PRIu32
401
+ " MaxMonitorAreaFactorB: %" PRIu32 "",
402
+ maxNumMonitors, maxMonitorAreaFactorA, maxMonitorAreaFactorB);
403
+ _activated = TRUE;
404
+
405
+ if (freerdp_settings_get_bool(settings, FreeRDP_Fullscreen))
406
+ return CHANNEL_RC_OK;
407
+
408
+ WLog_DBG(TAG, "DisplayControlCapsPdu: setting the window as resizable");
409
+ return set_window_resizable() ? CHANNEL_RC_OK : CHANNEL_RC_NO_MEMORY;
410
+ }
411
+
412
+ BOOL sdlDispContext::init(DispClientContext* disp)
413
+ {
414
+ if (!disp)
415
+ return FALSE;
416
+
417
+ auto settings = _sdl->context()->settings;
418
+
419
+ if (!settings)
420
+ return FALSE;
421
+
422
+ _disp = disp;
423
+ disp->custom = this;
424
+
425
+ if (freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate))
426
+ {
427
+ disp->DisplayControlCaps = sdlDispContext::DisplayControlCaps;
428
+ }
429
+
430
+ _sdl->update_resizeable(TRUE);
431
+ return TRUE;
432
+ }
433
+
434
+ BOOL sdlDispContext::uninit(DispClientContext* disp)
435
+ {
436
+ if (!disp)
437
+ return FALSE;
438
+
439
+ _disp = nullptr;
440
+ _sdl->update_resizeable(FALSE);
441
+ return TRUE;
442
+ }
443
+
444
+ sdlDispContext::sdlDispContext(SdlContext* sdl) : _sdl(sdl)
445
+ {
446
+ SDL_Init(SDL_INIT_EVENTS | SDL_INIT_VIDEO);
447
+
448
+ WINPR_ASSERT(_sdl);
449
+ WINPR_ASSERT(_sdl->context()->settings);
450
+ WINPR_ASSERT(_sdl->context()->pubSub);
451
+
452
+ auto settings = _sdl->context()->settings;
453
+ auto pubSub = _sdl->context()->pubSub;
454
+
455
+ _lastSentWidth = _targetWidth = WINPR_ASSERTING_INT_CAST(
456
+ int32_t, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth));
457
+ _lastSentHeight = _targetHeight = WINPR_ASSERTING_INT_CAST(
458
+ int32_t, freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight));
459
+ PubSub_SubscribeActivated(pubSub, sdlDispContext::OnActivated);
460
+ PubSub_SubscribeGraphicsReset(pubSub, sdlDispContext::OnGraphicsReset);
461
+ addTimer();
462
+ }
463
+
464
+ sdlDispContext::~sdlDispContext()
465
+ {
466
+ wPubSub* pubSub = _sdl->context()->pubSub;
467
+ WINPR_ASSERT(pubSub);
468
+
469
+ PubSub_UnsubscribeActivated(pubSub, sdlDispContext::OnActivated);
470
+ PubSub_UnsubscribeGraphicsReset(pubSub, sdlDispContext::OnGraphicsReset);
471
+ SDL_RemoveTimer(_timer);
472
+ SDL_Quit();
473
+ }
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_disp.hpp ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * SDL Display Control Channel
4
+ *
5
+ * Copyright 2023 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+ #pragma once
20
+
21
+ #include <freerdp/types.h>
22
+ #include <freerdp/event.h>
23
+ #include <freerdp/client/disp.h>
24
+
25
+ #include "sdl_types.hpp"
26
+
27
+ #include <SDL3/SDL.h>
28
+
29
+ class sdlDispContext
30
+ {
31
+
32
+ public:
33
+ explicit sdlDispContext(SdlContext* sdl);
34
+ sdlDispContext(const sdlDispContext& other) = delete;
35
+ sdlDispContext(sdlDispContext&& other) = delete;
36
+ ~sdlDispContext();
37
+
38
+ sdlDispContext& operator=(const sdlDispContext& other) = delete;
39
+ sdlDispContext& operator=(sdlDispContext&& other) = delete;
40
+
41
+ BOOL init(DispClientContext* disp);
42
+ BOOL uninit(DispClientContext* disp);
43
+
44
+ BOOL handle_display_event(const SDL_DisplayEvent* ev);
45
+
46
+ BOOL handle_window_event(const SDL_WindowEvent* ev);
47
+
48
+ private:
49
+ UINT DisplayControlCaps(UINT32 maxNumMonitors, UINT32 maxMonitorAreaFactorA,
50
+ UINT32 maxMonitorAreaFactorB);
51
+ BOOL set_window_resizable();
52
+
53
+ BOOL sendResize();
54
+ BOOL settings_changed();
55
+ BOOL update_last_sent();
56
+ UINT sendLayout(const rdpMonitor* monitors, size_t nmonitors);
57
+
58
+ BOOL addTimer();
59
+
60
+ static UINT DisplayControlCaps(DispClientContext* disp, UINT32 maxNumMonitors,
61
+ UINT32 maxMonitorAreaFactorA, UINT32 maxMonitorAreaFactorB);
62
+ static void OnActivated(void* context, const ActivatedEventArgs* e);
63
+ static void OnGraphicsReset(void* context, const GraphicsResetEventArgs* e);
64
+ static Uint32 SDLCALL OnTimer(void* param, SDL_TimerID timerID, Uint32 interval);
65
+
66
+ SdlContext* _sdl = nullptr;
67
+ DispClientContext* _disp = nullptr;
68
+ int _lastSentWidth = -1;
69
+ int _lastSentHeight = -1;
70
+ UINT64 _lastSentDate = 0;
71
+ int _targetWidth = -1;
72
+ int _targetHeight = -1;
73
+ BOOL _activated = FALSE;
74
+ BOOL _waitingResize = FALSE;
75
+ UINT16 _lastSentDesktopOrientation = 0;
76
+ UINT32 _lastSentDesktopScaleFactor = 0;
77
+ UINT32 _lastSentDeviceScaleFactor = 0;
78
+ SDL_TimerID _timer = 0;
79
+ unsigned _timer_retries = 0;
80
+ };
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_freerdp.cpp ADDED
@@ -0,0 +1,1744 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP SDL UI
4
+ *
5
+ * Copyright 2022 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #include <memory>
21
+ #include <mutex>
22
+ #include <iostream>
23
+
24
+ #include <freerdp/config.h>
25
+
26
+ #include <cerrno>
27
+ #include <cstdio>
28
+ #include <cstring>
29
+
30
+ #include <freerdp/freerdp.h>
31
+ #include <freerdp/constants.h>
32
+ #include <freerdp/gdi/gdi.h>
33
+ #include <freerdp/streamdump.h>
34
+ #include <freerdp/utils/signal.h>
35
+
36
+ #include <freerdp/client/file.h>
37
+ #include <freerdp/client/cmdline.h>
38
+ #include <freerdp/client/cliprdr.h>
39
+ #include <freerdp/client/channels.h>
40
+ #include <freerdp/channels/channels.h>
41
+
42
+ #include <winpr/crt.h>
43
+ #include <winpr/config.h>
44
+ #include <winpr/assert.h>
45
+ #include <winpr/synch.h>
46
+ #include <freerdp/log.h>
47
+
48
+ #include <SDL3/SDL.h>
49
+ #include <SDL3/SDL_hints.h>
50
+ #include <SDL3/SDL_video.h>
51
+ #include <SDL3/SDL_oldnames.h>
52
+
53
+ #include "sdl_channels.hpp"
54
+ #include "sdl_freerdp.hpp"
55
+ #include "sdl_utils.hpp"
56
+ #include "sdl_disp.hpp"
57
+ #include "sdl_monitor.hpp"
58
+ #include "sdl_kbd.hpp"
59
+ #include "sdl_touch.hpp"
60
+ #include "sdl_pointer.hpp"
61
+ #include "sdl_prefs.hpp"
62
+ #include "dialogs/sdl_dialogs.hpp"
63
+ #include "scoped_guard.hpp"
64
+
65
+ #include <aad/sdl_webview.hpp>
66
+
67
+ #define SDL_TAG CLIENT_TAG("SDL")
68
+
69
+ enum SDL_EXIT_CODE
70
+ {
71
+ /* section 0-15: protocol-independent codes */
72
+ SDL_EXIT_SUCCESS = 0,
73
+ SDL_EXIT_DISCONNECT = 1,
74
+ SDL_EXIT_LOGOFF = 2,
75
+ SDL_EXIT_IDLE_TIMEOUT = 3,
76
+ SDL_EXIT_LOGON_TIMEOUT = 4,
77
+ SDL_EXIT_CONN_REPLACED = 5,
78
+ SDL_EXIT_OUT_OF_MEMORY = 6,
79
+ SDL_EXIT_CONN_DENIED = 7,
80
+ SDL_EXIT_CONN_DENIED_FIPS = 8,
81
+ SDL_EXIT_USER_PRIVILEGES = 9,
82
+ SDL_EXIT_FRESH_CREDENTIALS_REQUIRED = 10,
83
+ SDL_EXIT_DISCONNECT_BY_USER = 11,
84
+
85
+ /* section 16-31: license error set */
86
+ SDL_EXIT_LICENSE_INTERNAL = 16,
87
+ SDL_EXIT_LICENSE_NO_LICENSE_SERVER = 17,
88
+ SDL_EXIT_LICENSE_NO_LICENSE = 18,
89
+ SDL_EXIT_LICENSE_BAD_CLIENT_MSG = 19,
90
+ SDL_EXIT_LICENSE_HWID_DOESNT_MATCH = 20,
91
+ SDL_EXIT_LICENSE_BAD_CLIENT = 21,
92
+ SDL_EXIT_LICENSE_CANT_FINISH_PROTOCOL = 22,
93
+ SDL_EXIT_LICENSE_CLIENT_ENDED_PROTOCOL = 23,
94
+ SDL_EXIT_LICENSE_BAD_CLIENT_ENCRYPTION = 24,
95
+ SDL_EXIT_LICENSE_CANT_UPGRADE = 25,
96
+ SDL_EXIT_LICENSE_NO_REMOTE_CONNECTIONS = 26,
97
+
98
+ /* section 32-127: RDP protocol error set */
99
+ SDL_EXIT_RDP = 32,
100
+
101
+ /* section 128-254: xfreerdp specific exit codes */
102
+ SDL_EXIT_PARSE_ARGUMENTS = 128,
103
+ SDL_EXIT_MEMORY = 129,
104
+ SDL_EXIT_PROTOCOL = 130,
105
+ SDL_EXIT_CONN_FAILED = 131,
106
+ SDL_EXIT_AUTH_FAILURE = 132,
107
+ SDL_EXIT_NEGO_FAILURE = 133,
108
+ SDL_EXIT_LOGON_FAILURE = 134,
109
+ SDL_EXIT_ACCOUNT_LOCKED_OUT = 135,
110
+ SDL_EXIT_PRE_CONNECT_FAILED = 136,
111
+ SDL_EXIT_CONNECT_UNDEFINED = 137,
112
+ SDL_EXIT_POST_CONNECT_FAILED = 138,
113
+ SDL_EXIT_DNS_ERROR = 139,
114
+ SDL_EXIT_DNS_NAME_NOT_FOUND = 140,
115
+ SDL_EXIT_CONNECT_FAILED = 141,
116
+ SDL_EXIT_MCS_CONNECT_INITIAL_ERROR = 142,
117
+ SDL_EXIT_TLS_CONNECT_FAILED = 143,
118
+ SDL_EXIT_INSUFFICIENT_PRIVILEGES = 144,
119
+ SDL_EXIT_CONNECT_CANCELLED = 145,
120
+
121
+ SDL_EXIT_CONNECT_TRANSPORT_FAILED = 147,
122
+ SDL_EXIT_CONNECT_PASSWORD_EXPIRED = 148,
123
+ SDL_EXIT_CONNECT_PASSWORD_MUST_CHANGE = 149,
124
+ SDL_EXIT_CONNECT_KDC_UNREACHABLE = 150,
125
+ SDL_EXIT_CONNECT_ACCOUNT_DISABLED = 151,
126
+ SDL_EXIT_CONNECT_PASSWORD_CERTAINLY_EXPIRED = 152,
127
+ SDL_EXIT_CONNECT_CLIENT_REVOKED = 153,
128
+ SDL_EXIT_CONNECT_WRONG_PASSWORD = 154,
129
+ SDL_EXIT_CONNECT_ACCESS_DENIED = 155,
130
+ SDL_EXIT_CONNECT_ACCOUNT_RESTRICTION = 156,
131
+ SDL_EXIT_CONNECT_ACCOUNT_EXPIRED = 157,
132
+ SDL_EXIT_CONNECT_LOGON_TYPE_NOT_GRANTED = 158,
133
+ SDL_EXIT_CONNECT_NO_OR_MISSING_CREDENTIALS = 159,
134
+
135
+ SDL_EXIT_UNKNOWN = 255,
136
+ };
137
+
138
+ struct sdl_exit_code_map_t
139
+ {
140
+ DWORD error;
141
+ int code;
142
+ const char* code_tag;
143
+ };
144
+
145
+ #define ENTRY(x, y) \
146
+ { \
147
+ x, y, #y \
148
+ }
149
+ static const struct sdl_exit_code_map_t sdl_exit_code_map[] = {
150
+ ENTRY(FREERDP_ERROR_SUCCESS, SDL_EXIT_SUCCESS), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_DISCONNECT),
151
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LOGOFF), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_IDLE_TIMEOUT),
152
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LOGON_TIMEOUT),
153
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_REPLACED),
154
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_OUT_OF_MEMORY),
155
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_DENIED),
156
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_DENIED_FIPS),
157
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_USER_PRIVILEGES),
158
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_FRESH_CREDENTIALS_REQUIRED),
159
+ ENTRY(ERRINFO_LOGOFF_BY_USER, SDL_EXIT_DISCONNECT_BY_USER),
160
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_UNKNOWN),
161
+
162
+ /* section 16-31: license error set */
163
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_INTERNAL),
164
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_NO_LICENSE_SERVER),
165
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_NO_LICENSE),
166
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_BAD_CLIENT_MSG),
167
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_HWID_DOESNT_MATCH),
168
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_BAD_CLIENT),
169
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CANT_FINISH_PROTOCOL),
170
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CLIENT_ENDED_PROTOCOL),
171
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_BAD_CLIENT_ENCRYPTION),
172
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CANT_UPGRADE),
173
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_NO_REMOTE_CONNECTIONS),
174
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CANT_UPGRADE),
175
+
176
+ /* section 32-127: RDP protocol error set */
177
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_RDP),
178
+
179
+ /* section 128-254: xfreerdp specific exit codes */
180
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_PARSE_ARGUMENTS), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_MEMORY),
181
+ ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_PROTOCOL), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_FAILED),
182
+
183
+ ENTRY(FREERDP_ERROR_AUTHENTICATION_FAILED, SDL_EXIT_AUTH_FAILURE),
184
+ ENTRY(FREERDP_ERROR_SECURITY_NEGO_CONNECT_FAILED, SDL_EXIT_NEGO_FAILURE),
185
+ ENTRY(FREERDP_ERROR_CONNECT_LOGON_FAILURE, SDL_EXIT_LOGON_FAILURE),
186
+ ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_LOCKED_OUT, SDL_EXIT_ACCOUNT_LOCKED_OUT),
187
+ ENTRY(FREERDP_ERROR_PRE_CONNECT_FAILED, SDL_EXIT_PRE_CONNECT_FAILED),
188
+ ENTRY(FREERDP_ERROR_CONNECT_UNDEFINED, SDL_EXIT_CONNECT_UNDEFINED),
189
+ ENTRY(FREERDP_ERROR_POST_CONNECT_FAILED, SDL_EXIT_POST_CONNECT_FAILED),
190
+ ENTRY(FREERDP_ERROR_DNS_ERROR, SDL_EXIT_DNS_ERROR),
191
+ ENTRY(FREERDP_ERROR_DNS_NAME_NOT_FOUND, SDL_EXIT_DNS_NAME_NOT_FOUND),
192
+ ENTRY(FREERDP_ERROR_CONNECT_FAILED, SDL_EXIT_CONNECT_FAILED),
193
+ ENTRY(FREERDP_ERROR_MCS_CONNECT_INITIAL_ERROR, SDL_EXIT_MCS_CONNECT_INITIAL_ERROR),
194
+ ENTRY(FREERDP_ERROR_TLS_CONNECT_FAILED, SDL_EXIT_TLS_CONNECT_FAILED),
195
+ ENTRY(FREERDP_ERROR_INSUFFICIENT_PRIVILEGES, SDL_EXIT_INSUFFICIENT_PRIVILEGES),
196
+ ENTRY(FREERDP_ERROR_CONNECT_CANCELLED, SDL_EXIT_CONNECT_CANCELLED),
197
+ ENTRY(FREERDP_ERROR_CONNECT_TRANSPORT_FAILED, SDL_EXIT_CONNECT_TRANSPORT_FAILED),
198
+ ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_EXPIRED, SDL_EXIT_CONNECT_PASSWORD_EXPIRED),
199
+ ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_MUST_CHANGE, SDL_EXIT_CONNECT_PASSWORD_MUST_CHANGE),
200
+ ENTRY(FREERDP_ERROR_CONNECT_KDC_UNREACHABLE, SDL_EXIT_CONNECT_KDC_UNREACHABLE),
201
+ ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_DISABLED, SDL_EXIT_CONNECT_ACCOUNT_DISABLED),
202
+ ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_CERTAINLY_EXPIRED,
203
+ SDL_EXIT_CONNECT_PASSWORD_CERTAINLY_EXPIRED),
204
+ ENTRY(FREERDP_ERROR_CONNECT_CLIENT_REVOKED, SDL_EXIT_CONNECT_CLIENT_REVOKED),
205
+ ENTRY(FREERDP_ERROR_CONNECT_WRONG_PASSWORD, SDL_EXIT_CONNECT_WRONG_PASSWORD),
206
+ ENTRY(FREERDP_ERROR_CONNECT_ACCESS_DENIED, SDL_EXIT_CONNECT_ACCESS_DENIED),
207
+ ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_RESTRICTION, SDL_EXIT_CONNECT_ACCOUNT_RESTRICTION),
208
+ ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_EXPIRED, SDL_EXIT_CONNECT_ACCOUNT_EXPIRED),
209
+ ENTRY(FREERDP_ERROR_CONNECT_LOGON_TYPE_NOT_GRANTED, SDL_EXIT_CONNECT_LOGON_TYPE_NOT_GRANTED),
210
+ ENTRY(FREERDP_ERROR_CONNECT_NO_OR_MISSING_CREDENTIALS,
211
+ SDL_EXIT_CONNECT_NO_OR_MISSING_CREDENTIALS)
212
+ };
213
+
214
+ static const struct sdl_exit_code_map_t* sdl_map_entry_by_code(int exit_code)
215
+ {
216
+ for (const auto& x : sdl_exit_code_map)
217
+ {
218
+ const struct sdl_exit_code_map_t* cur = &x;
219
+ if (cur->code == exit_code)
220
+ return cur;
221
+ }
222
+ return nullptr;
223
+ }
224
+
225
+ static void sdl_hide_connection_dialog(SdlContext* sdl)
226
+ {
227
+ WINPR_ASSERT(sdl);
228
+ std::lock_guard<CriticalSection> lock(sdl->critical);
229
+ if (sdl->connection_dialog)
230
+ sdl->connection_dialog->hide();
231
+ }
232
+
233
+ static const struct sdl_exit_code_map_t* sdl_map_entry_by_error(UINT32 error)
234
+ {
235
+ for (const auto& x : sdl_exit_code_map)
236
+ {
237
+ const struct sdl_exit_code_map_t* cur = &x;
238
+ if (cur->error == error)
239
+ return cur;
240
+ }
241
+ return nullptr;
242
+ }
243
+
244
+ static int sdl_map_error_to_exit_code(DWORD error)
245
+ {
246
+ const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_error(error);
247
+ if (entry)
248
+ return entry->code;
249
+
250
+ return SDL_EXIT_CONN_FAILED;
251
+ }
252
+
253
+ static const char* sdl_map_error_to_code_tag(UINT32 error)
254
+ {
255
+ const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_error(error);
256
+ if (entry)
257
+ return entry->code_tag;
258
+ return nullptr;
259
+ }
260
+
261
+ static const char* sdl_map_to_code_tag(int code)
262
+ {
263
+ const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_code(code);
264
+ if (entry)
265
+ return entry->code_tag;
266
+ return nullptr;
267
+ }
268
+
269
+ static int error_info_to_error(freerdp* instance, DWORD* pcode, char** msg, size_t* len)
270
+ {
271
+ const DWORD code = freerdp_error_info(instance);
272
+ const char* name = freerdp_get_error_info_name(code);
273
+ const char* str = freerdp_get_error_info_string(code);
274
+ const int exit_code = sdl_map_error_to_exit_code(code);
275
+
276
+ winpr_asprintf(msg, len, "Terminate with %s due to ERROR_INFO %s [0x%08" PRIx32 "]: %s",
277
+ sdl_map_error_to_code_tag(code), name, code, str);
278
+ WLog_DBG(SDL_TAG, "%s", *msg);
279
+ if (pcode)
280
+ *pcode = code;
281
+ return exit_code;
282
+ }
283
+
284
+ /* This function is called whenever a new frame starts.
285
+ * It can be used to reset invalidated areas. */
286
+ static BOOL sdl_begin_paint(rdpContext* context)
287
+ {
288
+ rdpGdi* gdi = nullptr;
289
+ auto sdl = get_context(context);
290
+
291
+ WINPR_ASSERT(sdl);
292
+
293
+ HANDLE handles[] = { sdl->update_complete.handle(), freerdp_abort_event(context) };
294
+ const DWORD status = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
295
+ switch (status)
296
+ {
297
+ case WAIT_OBJECT_0:
298
+ break;
299
+ default:
300
+ return FALSE;
301
+ }
302
+ sdl->update_complete.clear();
303
+
304
+ gdi = context->gdi;
305
+ WINPR_ASSERT(gdi);
306
+ WINPR_ASSERT(gdi->primary);
307
+ WINPR_ASSERT(gdi->primary->hdc);
308
+ WINPR_ASSERT(gdi->primary->hdc->hwnd);
309
+ WINPR_ASSERT(gdi->primary->hdc->hwnd->invalid);
310
+ gdi->primary->hdc->hwnd->invalid->null = TRUE;
311
+ gdi->primary->hdc->hwnd->ninvalid = 0;
312
+
313
+ return TRUE;
314
+ }
315
+
316
+ static BOOL sdl_redraw(SdlContext* sdl)
317
+ {
318
+ WINPR_ASSERT(sdl);
319
+
320
+ auto gdi = sdl->context()->gdi;
321
+ return gdi_send_suppress_output(gdi, FALSE);
322
+ }
323
+
324
+ class SdlEventUpdateTriggerGuard
325
+ {
326
+ private:
327
+ SdlContext* _sdl;
328
+
329
+ public:
330
+ explicit SdlEventUpdateTriggerGuard(SdlContext* sdl) : _sdl(sdl)
331
+ {
332
+ }
333
+ ~SdlEventUpdateTriggerGuard()
334
+ {
335
+ _sdl->update_complete.set();
336
+ }
337
+ SdlEventUpdateTriggerGuard(const SdlEventUpdateTriggerGuard&) = delete;
338
+ SdlEventUpdateTriggerGuard(SdlEventUpdateTriggerGuard&&) = delete;
339
+ SdlEventUpdateTriggerGuard& operator=(const SdlEventUpdateTriggerGuard&) = delete;
340
+ SdlEventUpdateTriggerGuard& operator=(SdlEventUpdateTriggerGuard&&) = delete;
341
+ };
342
+
343
+ static bool sdl_draw_to_window_rect(SdlContext* sdl, SdlWindow& window, SDL_Surface* surface,
344
+ SDL_Point offset, const SDL_Rect& srcRect)
345
+ {
346
+ SDL_Rect dstRect = { offset.x + srcRect.x, offset.y + srcRect.y, srcRect.w, srcRect.h };
347
+ return window.blit(surface, srcRect, dstRect);
348
+ }
349
+
350
+ static bool sdl_draw_to_window_rect(SdlContext* sdl, SdlWindow& window, SDL_Surface* surface,
351
+ SDL_Point offset, const std::vector<SDL_Rect>& rects = {})
352
+ {
353
+ if (rects.empty())
354
+ {
355
+ return sdl_draw_to_window_rect(sdl, window, surface, offset,
356
+ { 0, 0, surface->w, surface->h });
357
+ }
358
+ for (auto& srcRect : rects)
359
+ {
360
+ if (!sdl_draw_to_window_rect(sdl, window, surface, offset, srcRect))
361
+ return false;
362
+ }
363
+ return true;
364
+ }
365
+
366
+ static bool sdl_draw_to_window_scaled_rect(SdlContext* sdl, SdlWindow& window, SDL_Surface* surface,
367
+ const SDL_Rect& srcRect)
368
+ {
369
+ SDL_Rect dstRect = srcRect;
370
+ sdl_scale_coordinates(sdl, window.id(), &dstRect.x, &dstRect.y, FALSE, TRUE);
371
+ sdl_scale_coordinates(sdl, window.id(), &dstRect.w, &dstRect.h, FALSE, TRUE);
372
+ return window.blit(surface, srcRect, dstRect);
373
+ }
374
+
375
+ static BOOL sdl_draw_to_window_scaled_rect(SdlContext* sdl, SdlWindow& window, SDL_Surface* surface,
376
+ const std::vector<SDL_Rect>& rects = {})
377
+ {
378
+ if (rects.empty())
379
+ {
380
+ return sdl_draw_to_window_scaled_rect(sdl, window, surface,
381
+ { 0, 0, surface->w, surface->h });
382
+ }
383
+ for (const auto& srcRect : rects)
384
+ {
385
+ if (!sdl_draw_to_window_scaled_rect(sdl, window, surface, srcRect))
386
+ return FALSE;
387
+ }
388
+ return TRUE;
389
+ }
390
+
391
+ static BOOL sdl_draw_to_window(SdlContext* sdl, SdlWindow& window,
392
+ const std::vector<SDL_Rect>& rects = {})
393
+ {
394
+ WINPR_ASSERT(sdl);
395
+
396
+ auto context = sdl->context();
397
+ auto gdi = context->gdi;
398
+
399
+ auto size = window.rect();
400
+
401
+ if (!freerdp_settings_get_bool(context->settings, FreeRDP_SmartSizing))
402
+ {
403
+ if (gdi->width < size.w)
404
+ {
405
+ window.setOffsetX((size.w - gdi->width) / 2);
406
+ }
407
+ if (gdi->height < size.h)
408
+ {
409
+ window.setOffsetY((size.h - gdi->height) / 2);
410
+ }
411
+
412
+ auto surface = sdl->primary.get();
413
+ if (!sdl_draw_to_window_rect(sdl, window, surface, { window.offsetX(), window.offsetY() },
414
+ rects))
415
+ return FALSE;
416
+ }
417
+ else
418
+ {
419
+ if (!sdl_draw_to_window_scaled_rect(sdl, window, sdl->primary.get(), rects))
420
+ return FALSE;
421
+ }
422
+ window.updateSurface();
423
+ return TRUE;
424
+ }
425
+
426
+ static BOOL sdl_draw_to_window(SdlContext* sdl, std::map<Uint32, SdlWindow>& windows,
427
+ const std::vector<SDL_Rect>& rects = {})
428
+ {
429
+ for (auto& window : windows)
430
+ {
431
+ if (!sdl_draw_to_window(sdl, window.second, rects))
432
+ return FALSE;
433
+ }
434
+
435
+ return TRUE;
436
+ }
437
+
438
+ static BOOL sdl_end_paint_process(rdpContext* context)
439
+ {
440
+ rdpGdi* gdi = nullptr;
441
+ auto sdl = get_context(context);
442
+
443
+ WINPR_ASSERT(context);
444
+
445
+ SdlEventUpdateTriggerGuard guard(sdl);
446
+
447
+ gdi = context->gdi;
448
+ WINPR_ASSERT(gdi);
449
+ WINPR_ASSERT(gdi->primary);
450
+ WINPR_ASSERT(gdi->primary->hdc);
451
+ WINPR_ASSERT(gdi->primary->hdc->hwnd);
452
+ WINPR_ASSERT(gdi->primary->hdc->hwnd->invalid);
453
+ if (gdi->suppressOutput || gdi->primary->hdc->hwnd->invalid->null)
454
+ return TRUE;
455
+
456
+ const INT32 ninvalid = gdi->primary->hdc->hwnd->ninvalid;
457
+ const GDI_RGN* cinvalid = gdi->primary->hdc->hwnd->cinvalid;
458
+
459
+ if (ninvalid < 1)
460
+ return TRUE;
461
+
462
+ std::vector<SDL_Rect> rects;
463
+ for (INT32 x = 0; x < ninvalid; x++)
464
+ {
465
+ auto& rgn = cinvalid[x];
466
+ rects.push_back({ rgn.x, rgn.y, rgn.w, rgn.h });
467
+ }
468
+
469
+ return sdl_draw_to_window(sdl, sdl->windows, rects);
470
+ }
471
+
472
+ /* This function is called when the library completed composing a new
473
+ * frame. Read out the changed areas and blit them to your output device.
474
+ * The image buffer will have the format specified by gdi_init
475
+ */
476
+ static BOOL sdl_end_paint(rdpContext* context)
477
+ {
478
+ auto sdl = get_context(context);
479
+ WINPR_ASSERT(sdl);
480
+
481
+ std::lock_guard<CriticalSection> lock(sdl->critical);
482
+ const BOOL rc = sdl_push_user_event(SDL_EVENT_USER_UPDATE, context);
483
+
484
+ return rc;
485
+ }
486
+
487
+ static void sdl_destroy_primary(SdlContext* sdl)
488
+ {
489
+ if (!sdl)
490
+ return;
491
+ sdl->primary.reset();
492
+ }
493
+
494
+ /* Create a SDL surface from the GDI buffer */
495
+ static BOOL sdl_create_primary(SdlContext* sdl)
496
+ {
497
+ rdpGdi* gdi = nullptr;
498
+
499
+ WINPR_ASSERT(sdl);
500
+
501
+ gdi = sdl->context()->gdi;
502
+ WINPR_ASSERT(gdi);
503
+
504
+ sdl_destroy_primary(sdl);
505
+ sdl->primary =
506
+ SDLSurfacePtr(SDL_CreateSurfaceFrom(static_cast<int>(gdi->width),
507
+ static_cast<int>(gdi->height), sdl->sdl_pixel_format,
508
+ gdi->primary_buffer, static_cast<int>(gdi->stride)),
509
+ SDL_DestroySurface);
510
+ if (!sdl->primary)
511
+ return FALSE;
512
+
513
+ SDL_SetSurfaceBlendMode(sdl->primary.get(), SDL_BLENDMODE_NONE);
514
+ SDL_Rect surfaceRect = { 0, 0, gdi->width, gdi->height };
515
+ SDL_FillSurfaceRect(sdl->primary.get(), &surfaceRect,
516
+ SDL_MapSurfaceRGBA(sdl->primary.get(), 0, 0, 0, 0xff));
517
+
518
+ return TRUE;
519
+ }
520
+
521
+ static BOOL sdl_desktop_resize(rdpContext* context)
522
+ {
523
+ rdpGdi* gdi = nullptr;
524
+ rdpSettings* settings = nullptr;
525
+ auto sdl = get_context(context);
526
+
527
+ WINPR_ASSERT(sdl);
528
+ WINPR_ASSERT(context);
529
+
530
+ settings = context->settings;
531
+ WINPR_ASSERT(settings);
532
+
533
+ std::lock_guard<CriticalSection> lock(sdl->critical);
534
+ gdi = context->gdi;
535
+ if (!gdi_resize(gdi, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
536
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)))
537
+ return FALSE;
538
+ return sdl_create_primary(sdl);
539
+ }
540
+
541
+ /* This function is called to output a System BEEP */
542
+ static BOOL sdl_play_sound(rdpContext* context, const PLAY_SOUND_UPDATE* play_sound)
543
+ {
544
+ /* TODO: Implement */
545
+ WINPR_UNUSED(context);
546
+ WINPR_UNUSED(play_sound);
547
+ return TRUE;
548
+ }
549
+
550
+ static BOOL sdl_wait_for_init(SdlContext* sdl)
551
+ {
552
+ WINPR_ASSERT(sdl);
553
+ sdl->initialize.set();
554
+
555
+ HANDLE handles[] = { sdl->initialized.handle(), freerdp_abort_event(sdl->context()) };
556
+
557
+ const DWORD rc = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
558
+ switch (rc)
559
+ {
560
+ case WAIT_OBJECT_0:
561
+ return TRUE;
562
+ default:
563
+ return FALSE;
564
+ }
565
+ }
566
+
567
+ /* Called before a connection is established.
568
+ * Set all configuration options to support and load channels here. */
569
+ static BOOL sdl_pre_connect(freerdp* instance)
570
+ {
571
+ WINPR_ASSERT(instance);
572
+ WINPR_ASSERT(instance->context);
573
+
574
+ auto sdl = get_context(instance->context);
575
+
576
+ auto settings = instance->context->settings;
577
+ WINPR_ASSERT(settings);
578
+
579
+ if (!freerdp_settings_set_bool(settings, FreeRDP_CertificateCallbackPreferPEM, TRUE))
580
+ return FALSE;
581
+
582
+ /* Optional OS identifier sent to server */
583
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMajorType, OSMAJORTYPE_UNIX))
584
+ return FALSE;
585
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMinorType, OSMINORTYPE_NATIVE_SDL))
586
+ return FALSE;
587
+ /* OrderSupport is initialized at this point.
588
+ * Only override it if you plan to implement custom order
589
+ * callbacks or deactivate certain features. */
590
+ /* Register the channel listeners.
591
+ * They are required to set up / tear down channels if they are loaded. */
592
+ PubSub_SubscribeChannelConnected(instance->context->pubSub, sdl_OnChannelConnectedEventHandler);
593
+ PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
594
+ sdl_OnChannelDisconnectedEventHandler);
595
+
596
+ if (!freerdp_settings_get_bool(settings, FreeRDP_AuthenticationOnly))
597
+ {
598
+ UINT32 maxWidth = 0;
599
+ UINT32 maxHeight = 0;
600
+
601
+ if (!sdl_wait_for_init(sdl))
602
+ return FALSE;
603
+
604
+ std::lock_guard<CriticalSection> lock(sdl->critical);
605
+ if (!freerdp_settings_get_bool(settings, FreeRDP_UseCommonStdioCallbacks))
606
+ sdl->connection_dialog = std::make_unique<SDLConnectionDialog>(instance->context);
607
+ if (sdl->connection_dialog)
608
+ {
609
+ sdl->connection_dialog->setTitle("Connecting to '%s'",
610
+ freerdp_settings_get_server_name(settings));
611
+ sdl->connection_dialog->showInfo(
612
+ "The connection is being established\n\nPlease wait...");
613
+ }
614
+ if (!sdl_detect_monitors(sdl, &maxWidth, &maxHeight))
615
+ return FALSE;
616
+
617
+ if ((maxWidth != 0) && (maxHeight != 0) &&
618
+ !freerdp_settings_get_bool(settings, FreeRDP_SmartSizing))
619
+ {
620
+ WLog_Print(sdl->log, WLOG_INFO, "Update size to %ux%u", maxWidth, maxHeight);
621
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, maxWidth))
622
+ return FALSE;
623
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, maxHeight))
624
+ return FALSE;
625
+ }
626
+ }
627
+ else
628
+ {
629
+ /* Check +auth-only has a username and password. */
630
+ if (!freerdp_settings_get_string(settings, FreeRDP_Password))
631
+ {
632
+ WLog_Print(sdl->log, WLOG_INFO, "auth-only, but no password set. Please provide one.");
633
+ return FALSE;
634
+ }
635
+
636
+ if (!freerdp_settings_set_bool(settings, FreeRDP_DeactivateClientDecoding, TRUE))
637
+ return FALSE;
638
+
639
+ WLog_Print(sdl->log, WLOG_INFO, "Authentication only. Don't connect SDL.");
640
+ }
641
+
642
+ /* TODO: Any code your client requires */
643
+ return TRUE;
644
+ }
645
+
646
+ static const char* sdl_window_get_title(rdpSettings* settings)
647
+ {
648
+ const char* windowTitle = nullptr;
649
+ UINT32 port = 0;
650
+ BOOL addPort = 0;
651
+ const char* name = nullptr;
652
+ const char* prefix = "FreeRDP:";
653
+
654
+ if (!settings)
655
+ return nullptr;
656
+
657
+ windowTitle = freerdp_settings_get_string(settings, FreeRDP_WindowTitle);
658
+ if (windowTitle)
659
+ return windowTitle;
660
+
661
+ name = freerdp_settings_get_server_name(settings);
662
+ port = freerdp_settings_get_uint32(settings, FreeRDP_ServerPort);
663
+
664
+ addPort = (port != 3389);
665
+
666
+ char buffer[MAX_PATH + 64] = {};
667
+
668
+ if (!addPort)
669
+ (void)sprintf_s(buffer, sizeof(buffer), "%s %s", prefix, name);
670
+ else
671
+ (void)sprintf_s(buffer, sizeof(buffer), "%s %s:%" PRIu32, prefix, name, port);
672
+
673
+ if (!freerdp_settings_set_string(settings, FreeRDP_WindowTitle, buffer))
674
+ return nullptr;
675
+ return freerdp_settings_get_string(settings, FreeRDP_WindowTitle);
676
+ }
677
+
678
+ static void sdl_term_handler(int signum, const char* signame, void* context)
679
+ {
680
+ sdl_push_quit();
681
+ }
682
+
683
+ static void sdl_cleanup_sdl(SdlContext* sdl)
684
+ {
685
+ if (!sdl)
686
+ return;
687
+
688
+ std::lock_guard<CriticalSection> lock(sdl->critical);
689
+ sdl->windows.clear();
690
+ sdl->connection_dialog.reset();
691
+
692
+ sdl_destroy_primary(sdl);
693
+
694
+ freerdp_del_signal_cleanup_handler(sdl->context(), sdl_term_handler);
695
+ TTF_Quit();
696
+ SDL_Quit();
697
+ }
698
+
699
+ static BOOL sdl_create_windows(SdlContext* sdl)
700
+ {
701
+ WINPR_ASSERT(sdl);
702
+
703
+ auto settings = sdl->context()->settings;
704
+ auto title = sdl_window_get_title(settings);
705
+
706
+ UINT32 windowCount = freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount);
707
+
708
+ for (UINT32 x = 0; x < windowCount; x++)
709
+ {
710
+ auto id = sdl_monitor_id_for_index(sdl, x);
711
+ if (id < 0)
712
+ return FALSE;
713
+
714
+ auto monitor = static_cast<rdpMonitor*>(
715
+ freerdp_settings_get_pointer_array_writable(settings, FreeRDP_MonitorDefArray, x));
716
+
717
+ auto w = WINPR_ASSERTING_INT_CAST(Uint32, monitor->width);
718
+ auto h = WINPR_ASSERTING_INT_CAST(Uint32, monitor->height);
719
+ if (!(freerdp_settings_get_bool(settings, FreeRDP_UseMultimon) ||
720
+ freerdp_settings_get_bool(settings, FreeRDP_Fullscreen)))
721
+ {
722
+ w = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
723
+ h = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
724
+ }
725
+
726
+ Uint32 flags = 0;
727
+ auto startupX = SDL_WINDOWPOS_CENTERED_DISPLAY(id);
728
+ auto startupY = SDL_WINDOWPOS_CENTERED_DISPLAY(id);
729
+
730
+ if (monitor->attributes.desktopScaleFactor > 100)
731
+ {
732
+ flags |= SDL_WINDOW_HIGH_PIXEL_DENSITY;
733
+ }
734
+
735
+ if (freerdp_settings_get_bool(settings, FreeRDP_Fullscreen) &&
736
+ !freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
737
+ {
738
+ flags |= SDL_WINDOW_FULLSCREEN;
739
+ }
740
+
741
+ if (freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
742
+ {
743
+ flags |= SDL_WINDOW_BORDERLESS;
744
+ }
745
+
746
+ if (!freerdp_settings_get_bool(settings, FreeRDP_Decorations))
747
+ flags |= SDL_WINDOW_BORDERLESS;
748
+
749
+ SdlWindow window{ title,
750
+ static_cast<int>(startupX),
751
+ static_cast<int>(startupY),
752
+ static_cast<int>(w),
753
+ static_cast<int>(h),
754
+ flags };
755
+ ScopeGuard guard1([&]() { sdl->windows_created.set(); });
756
+ if (!window.window())
757
+ return FALSE;
758
+
759
+ if (freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
760
+ {
761
+ auto r = window.rect();
762
+ window.setOffsetX(0 - r.x);
763
+ window.setOffsetY(0 - r.y);
764
+ }
765
+
766
+ sdl->windows.insert({ window.id(), std::move(window) });
767
+ }
768
+
769
+ return TRUE;
770
+ }
771
+
772
+ static BOOL sdl_wait_create_windows(SdlContext* sdl)
773
+ {
774
+ std::lock_guard<CriticalSection> lock(sdl->critical);
775
+ sdl->windows_created.clear();
776
+ if (!sdl_push_user_event(SDL_EVENT_USER_CREATE_WINDOWS, sdl))
777
+ return FALSE;
778
+
779
+ HANDLE handles[] = { sdl->initialized.handle(), freerdp_abort_event(sdl->context()) };
780
+
781
+ const DWORD rc = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
782
+ switch (rc)
783
+ {
784
+ case WAIT_OBJECT_0:
785
+ return TRUE;
786
+ default:
787
+ return FALSE;
788
+ }
789
+ }
790
+
791
+ static bool shall_abort(SdlContext* sdl)
792
+ {
793
+ std::lock_guard<CriticalSection> lock(sdl->critical);
794
+ if (freerdp_shall_disconnect_context(sdl->context()))
795
+ {
796
+ if (sdl->rdp_thread_running)
797
+ return false;
798
+ if (!sdl->connection_dialog)
799
+ return true;
800
+ return !sdl->connection_dialog->running();
801
+ }
802
+ return false;
803
+ }
804
+
805
+ static int sdl_run(SdlContext* sdl)
806
+ {
807
+ int rc = -1;
808
+ WINPR_ASSERT(sdl);
809
+
810
+ HANDLE handles[] = { sdl->initialize.handle(), freerdp_abort_event(sdl->context()) };
811
+ const DWORD status = WaitForMultipleObjects(ARRAYSIZE(handles), handles, FALSE, INFINITE);
812
+ switch (status)
813
+ {
814
+ case WAIT_OBJECT_0:
815
+ break;
816
+ default:
817
+ return -1;
818
+ }
819
+
820
+ SDL_Init(SDL_INIT_VIDEO);
821
+ TTF_Init();
822
+ SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
823
+ SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
824
+
825
+ freerdp_add_signal_cleanup_handler(sdl->context(), sdl_term_handler);
826
+
827
+ sdl->initialized.set();
828
+
829
+ while (!shall_abort(sdl))
830
+ {
831
+ SDL_Event windowEvent = {};
832
+ while (!shall_abort(sdl) && SDL_WaitEventTimeout(nullptr, 1000))
833
+ {
834
+ /* Only poll standard SDL events and SDL_EVENT_USERS meant to create dialogs.
835
+ * do not process the dialog return value events here.
836
+ */
837
+ const int prc = SDL_PeepEvents(&windowEvent, 1, SDL_GETEVENT, SDL_EVENT_FIRST,
838
+ SDL_EVENT_USER_RETRY_DIALOG);
839
+ if (prc < 0)
840
+ {
841
+ if (sdl_log_error(prc, sdl->log, "SDL_PeepEvents"))
842
+ continue;
843
+ }
844
+
845
+ #if defined(WITH_DEBUG_SDL_EVENTS)
846
+ SDL_Log("got event %s [0x%08" PRIx32 "]", sdl_event_type_str(windowEvent.type),
847
+ windowEvent.type);
848
+ #endif
849
+ std::lock_guard<CriticalSection> lock(sdl->critical);
850
+ /* The session might have been disconnected while we were waiting for a new SDL event.
851
+ * In that case ignore the SDL event and terminate. */
852
+ if (freerdp_shall_disconnect_context(sdl->context()))
853
+ continue;
854
+
855
+ if (sdl->connection_dialog)
856
+ {
857
+ if (sdl->connection_dialog->handle(windowEvent))
858
+ {
859
+ continue;
860
+ }
861
+ }
862
+
863
+ switch (windowEvent.type)
864
+ {
865
+ case SDL_EVENT_QUIT:
866
+ freerdp_abort_connect_context(sdl->context());
867
+ break;
868
+ case SDL_EVENT_KEY_DOWN:
869
+ case SDL_EVENT_KEY_UP:
870
+ {
871
+ const SDL_KeyboardEvent* ev = &windowEvent.key;
872
+ sdl->input.keyboard_handle_event(ev);
873
+ }
874
+ break;
875
+ case SDL_EVENT_KEYMAP_CHANGED:
876
+ {
877
+ }
878
+ break; // TODO: Switch keyboard layout
879
+ case SDL_EVENT_MOUSE_MOTION:
880
+ {
881
+ const SDL_MouseMotionEvent* ev = &windowEvent.motion;
882
+ sdl_handle_mouse_motion(sdl, ev);
883
+ }
884
+ break;
885
+ case SDL_EVENT_MOUSE_BUTTON_DOWN:
886
+ case SDL_EVENT_MOUSE_BUTTON_UP:
887
+ {
888
+ const SDL_MouseButtonEvent* ev = &windowEvent.button;
889
+ sdl_handle_mouse_button(sdl, ev);
890
+ }
891
+ break;
892
+ case SDL_EVENT_MOUSE_WHEEL:
893
+ {
894
+ const SDL_MouseWheelEvent* ev = &windowEvent.wheel;
895
+ sdl_handle_mouse_wheel(sdl, ev);
896
+ }
897
+ break;
898
+ case SDL_EVENT_FINGER_DOWN:
899
+ {
900
+ const SDL_TouchFingerEvent* ev = &windowEvent.tfinger;
901
+ sdl_handle_touch_down(sdl, ev);
902
+ }
903
+ break;
904
+ case SDL_EVENT_FINGER_UP:
905
+ {
906
+ const SDL_TouchFingerEvent* ev = &windowEvent.tfinger;
907
+ sdl_handle_touch_up(sdl, ev);
908
+ }
909
+ break;
910
+ case SDL_EVENT_FINGER_MOTION:
911
+ {
912
+ const SDL_TouchFingerEvent* ev = &windowEvent.tfinger;
913
+ sdl_handle_touch_motion(sdl, ev);
914
+ }
915
+ break;
916
+
917
+ case SDL_EVENT_RENDER_TARGETS_RESET:
918
+ sdl_redraw(sdl);
919
+ break;
920
+ case SDL_EVENT_RENDER_DEVICE_RESET:
921
+ sdl_redraw(sdl);
922
+ break;
923
+ case SDL_EVENT_WILL_ENTER_FOREGROUND:
924
+ sdl_redraw(sdl);
925
+ break;
926
+ case SDL_EVENT_USER_CERT_DIALOG:
927
+ {
928
+ auto title = static_cast<const char*>(windowEvent.user.data1);
929
+ auto msg = static_cast<const char*>(windowEvent.user.data2);
930
+ sdl_cert_dialog_show(title, msg);
931
+ }
932
+ break;
933
+ case SDL_EVENT_USER_SHOW_DIALOG:
934
+ {
935
+ auto title = static_cast<const char*>(windowEvent.user.data1);
936
+ auto msg = static_cast<const char*>(windowEvent.user.data2);
937
+ sdl_message_dialog_show(title, msg, windowEvent.user.code);
938
+ }
939
+ break;
940
+ case SDL_EVENT_USER_SCARD_DIALOG:
941
+ {
942
+ auto title = static_cast<const char*>(windowEvent.user.data1);
943
+ auto msg = static_cast<const char**>(windowEvent.user.data2);
944
+ sdl_scard_dialog_show(title, windowEvent.user.code, msg);
945
+ }
946
+ break;
947
+ case SDL_EVENT_USER_AUTH_DIALOG:
948
+ sdl_auth_dialog_show(
949
+ reinterpret_cast<const SDL_UserAuthArg*>(windowEvent.padding));
950
+ break;
951
+ case SDL_EVENT_USER_UPDATE:
952
+ {
953
+ auto context = static_cast<rdpContext*>(windowEvent.user.data1);
954
+ sdl_end_paint_process(context);
955
+ }
956
+ break;
957
+ case SDL_EVENT_USER_CREATE_WINDOWS:
958
+ {
959
+ auto ctx = static_cast<SdlContext*>(windowEvent.user.data1);
960
+ sdl_create_windows(ctx);
961
+ }
962
+ break;
963
+ case SDL_EVENT_USER_WINDOW_RESIZEABLE:
964
+ {
965
+ auto window = static_cast<SdlWindow*>(windowEvent.user.data1);
966
+ const bool use = windowEvent.user.code != 0;
967
+ if (window)
968
+ window->resizeable(use);
969
+ }
970
+ break;
971
+ case SDL_EVENT_USER_WINDOW_FULLSCREEN:
972
+ {
973
+ auto window = static_cast<SdlWindow*>(windowEvent.user.data1);
974
+ const bool enter = windowEvent.user.code != 0;
975
+ if (window)
976
+ window->fullscreen(enter);
977
+ }
978
+ break;
979
+ case SDL_EVENT_USER_WINDOW_MINIMIZE:
980
+ for (auto& window : sdl->windows)
981
+ {
982
+ window.second.minimize();
983
+ }
984
+ break;
985
+ case SDL_EVENT_USER_POINTER_NULL:
986
+ SDL_HideCursor();
987
+ break;
988
+ case SDL_EVENT_USER_POINTER_DEFAULT:
989
+ {
990
+ SDL_Cursor* def = SDL_GetDefaultCursor();
991
+ SDL_SetCursor(def);
992
+ SDL_ShowCursor();
993
+ }
994
+ break;
995
+ case SDL_EVENT_USER_POINTER_POSITION:
996
+ {
997
+ const auto x =
998
+ static_cast<INT32>(reinterpret_cast<uintptr_t>(windowEvent.user.data1));
999
+ const auto y =
1000
+ static_cast<INT32>(reinterpret_cast<uintptr_t>(windowEvent.user.data2));
1001
+
1002
+ SDL_Window* window = SDL_GetMouseFocus();
1003
+ if (window)
1004
+ {
1005
+ const Uint32 id = SDL_GetWindowID(window);
1006
+
1007
+ INT32 sx = x;
1008
+ INT32 sy = y;
1009
+ if (sdl_scale_coordinates(sdl, id, &sx, &sy, FALSE, FALSE))
1010
+ SDL_WarpMouseInWindow(window, static_cast<float>(sx),
1011
+ static_cast<float>(sy));
1012
+ }
1013
+ }
1014
+ break;
1015
+ case SDL_EVENT_USER_POINTER_SET:
1016
+ sdl_Pointer_Set_Process(&windowEvent.user);
1017
+ break;
1018
+ case SDL_EVENT_CLIPBOARD_UPDATE:
1019
+ sdl->clip.handle_update(windowEvent.clipboard);
1020
+ break;
1021
+ case SDL_EVENT_USER_QUIT:
1022
+ default:
1023
+ if ((windowEvent.type >= SDL_EVENT_DISPLAY_FIRST) &&
1024
+ (windowEvent.type <= SDL_EVENT_DISPLAY_LAST))
1025
+ {
1026
+ const SDL_DisplayEvent* ev = &windowEvent.display;
1027
+ sdl->disp.handle_display_event(ev);
1028
+ }
1029
+ else if ((windowEvent.type >= SDL_EVENT_WINDOW_FIRST) &&
1030
+ (windowEvent.type <= SDL_EVENT_WINDOW_LAST))
1031
+ {
1032
+ const SDL_WindowEvent* ev = &windowEvent.window;
1033
+ auto window = sdl->windows.find(ev->windowID);
1034
+ if (window != sdl->windows.end())
1035
+ {
1036
+ sdl->disp.handle_window_event(ev);
1037
+
1038
+ switch (ev->type)
1039
+ {
1040
+ case SDL_EVENT_WINDOW_RESIZED:
1041
+ case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
1042
+ window->second.fill();
1043
+ window->second.updateSurface();
1044
+ break;
1045
+ case SDL_EVENT_WINDOW_MOVED:
1046
+ {
1047
+ auto r = window->second.rect();
1048
+ auto id = window->second.id();
1049
+ WLog_DBG(SDL_TAG, "%lu: %dx%d-%dx%d", id, r.x, r.y, r.w, r.h);
1050
+ }
1051
+ break;
1052
+ default:
1053
+ break;
1054
+ }
1055
+ }
1056
+ }
1057
+ break;
1058
+ }
1059
+ }
1060
+ }
1061
+
1062
+ rc = 1;
1063
+
1064
+ sdl_cleanup_sdl(sdl);
1065
+ return rc;
1066
+ }
1067
+
1068
+ /* Called after a RDP connection was successfully established.
1069
+ * Settings might have changed during negotiation of client / server feature
1070
+ * support.
1071
+ *
1072
+ * Set up local framebuffers and paing callbacks.
1073
+ * If required, register pointer callbacks to change the local mouse cursor
1074
+ * when hovering over the RDP window
1075
+ */
1076
+ static BOOL sdl_post_connect(freerdp* instance)
1077
+ {
1078
+ WINPR_ASSERT(instance);
1079
+
1080
+ auto context = instance->context;
1081
+ WINPR_ASSERT(context);
1082
+
1083
+ auto sdl = get_context(context);
1084
+
1085
+ // Retry was successful, discard dialog
1086
+ sdl_hide_connection_dialog(sdl);
1087
+
1088
+ if (freerdp_settings_get_bool(context->settings, FreeRDP_AuthenticationOnly))
1089
+ {
1090
+ /* Check +auth-only has a username and password. */
1091
+ if (!freerdp_settings_get_string(context->settings, FreeRDP_Password))
1092
+ {
1093
+ WLog_Print(sdl->log, WLOG_INFO, "auth-only, but no password set. Please provide one.");
1094
+ return FALSE;
1095
+ }
1096
+
1097
+ WLog_Print(sdl->log, WLOG_INFO, "Authentication only. Don't connect to X.");
1098
+ return TRUE;
1099
+ }
1100
+
1101
+ if (!sdl_wait_create_windows(sdl))
1102
+ return FALSE;
1103
+
1104
+ sdl->sdl_pixel_format = SDL_PIXELFORMAT_BGRA32;
1105
+ if (!gdi_init(instance, PIXEL_FORMAT_BGRA32))
1106
+ return FALSE;
1107
+
1108
+ if (!sdl_create_primary(sdl))
1109
+ return FALSE;
1110
+
1111
+ if (!sdl_register_pointer(instance->context->graphics))
1112
+ return FALSE;
1113
+
1114
+ WINPR_ASSERT(context->update);
1115
+
1116
+ context->update->BeginPaint = sdl_begin_paint;
1117
+ context->update->EndPaint = sdl_end_paint;
1118
+ context->update->PlaySound = sdl_play_sound;
1119
+ context->update->DesktopResize = sdl_desktop_resize;
1120
+ context->update->SetKeyboardIndicators = sdlInput::keyboard_set_indicators;
1121
+ context->update->SetKeyboardImeStatus = sdlInput::keyboard_set_ime_status;
1122
+
1123
+ sdl->update_resizeable(FALSE);
1124
+ sdl->update_fullscreen(freerdp_settings_get_bool(context->settings, FreeRDP_Fullscreen) ||
1125
+ freerdp_settings_get_bool(context->settings, FreeRDP_UseMultimon));
1126
+ return TRUE;
1127
+ }
1128
+
1129
+ /* This function is called whether a session ends by failure or success.
1130
+ * Clean up everything allocated by pre_connect and post_connect.
1131
+ */
1132
+ static void sdl_post_disconnect(freerdp* instance)
1133
+ {
1134
+ if (!instance)
1135
+ return;
1136
+
1137
+ if (!instance->context)
1138
+ return;
1139
+
1140
+ PubSub_UnsubscribeChannelConnected(instance->context->pubSub,
1141
+ sdl_OnChannelConnectedEventHandler);
1142
+ PubSub_UnsubscribeChannelDisconnected(instance->context->pubSub,
1143
+ sdl_OnChannelDisconnectedEventHandler);
1144
+ gdi_free(instance);
1145
+ }
1146
+
1147
+ static void sdl_post_final_disconnect(freerdp* instance)
1148
+ {
1149
+ if (!instance)
1150
+ return;
1151
+
1152
+ if (!instance->context)
1153
+ return;
1154
+ }
1155
+
1156
+ static void sdl_client_cleanup(SdlContext* sdl, int exit_code, const std::string& error_msg)
1157
+ {
1158
+ WINPR_ASSERT(sdl);
1159
+
1160
+ rdpContext* context = sdl->context();
1161
+ WINPR_ASSERT(context);
1162
+ rdpSettings* settings = context->settings;
1163
+ WINPR_ASSERT(settings);
1164
+
1165
+ sdl->rdp_thread_running = false;
1166
+ bool showError = false;
1167
+ if (freerdp_settings_get_bool(settings, FreeRDP_AuthenticationOnly))
1168
+ WLog_Print(sdl->log, WLOG_INFO, "Authentication only, exit status %s [%" PRId32 "]",
1169
+ sdl_map_to_code_tag(exit_code), exit_code);
1170
+ else
1171
+ {
1172
+ switch (exit_code)
1173
+ {
1174
+ case SDL_EXIT_SUCCESS:
1175
+ case SDL_EXIT_DISCONNECT:
1176
+ case SDL_EXIT_LOGOFF:
1177
+ case SDL_EXIT_DISCONNECT_BY_USER:
1178
+ case SDL_EXIT_CONNECT_CANCELLED:
1179
+ break;
1180
+ default:
1181
+ {
1182
+ std::lock_guard<CriticalSection> lock(sdl->critical);
1183
+ if (sdl->connection_dialog && !error_msg.empty())
1184
+ {
1185
+ sdl->connection_dialog->showError(error_msg.c_str());
1186
+ showError = true;
1187
+ }
1188
+ }
1189
+ break;
1190
+ }
1191
+ }
1192
+
1193
+ if (!showError)
1194
+ sdl_hide_connection_dialog(sdl);
1195
+
1196
+ sdl->exit_code = exit_code;
1197
+ sdl_push_user_event(SDL_EVENT_USER_QUIT);
1198
+ SDL_CleanupTLS();
1199
+ }
1200
+
1201
+ static int sdl_client_thread_connect(SdlContext* sdl, std::string& error_msg)
1202
+ {
1203
+ WINPR_ASSERT(sdl);
1204
+
1205
+ auto instance = sdl->context()->instance;
1206
+ WINPR_ASSERT(instance);
1207
+
1208
+ sdl->rdp_thread_running = true;
1209
+ BOOL rc = freerdp_connect(instance);
1210
+
1211
+ rdpContext* context = sdl->context();
1212
+ rdpSettings* settings = context->settings;
1213
+ WINPR_ASSERT(settings);
1214
+
1215
+ int exit_code = SDL_EXIT_SUCCESS;
1216
+ if (!rc)
1217
+ {
1218
+ UINT32 error = freerdp_get_last_error(context);
1219
+ exit_code = sdl_map_error_to_exit_code(error);
1220
+ }
1221
+
1222
+ if (freerdp_settings_get_bool(settings, FreeRDP_AuthenticationOnly))
1223
+ {
1224
+ DWORD code = freerdp_get_last_error(context);
1225
+ freerdp_abort_connect_context(context);
1226
+ WLog_Print(sdl->log, WLOG_ERROR, "Authentication only, %s [0x%08" PRIx32 "] %s",
1227
+ freerdp_get_last_error_name(code), code, freerdp_get_last_error_string(code));
1228
+ return exit_code;
1229
+ }
1230
+
1231
+ if (!rc)
1232
+ {
1233
+ DWORD code = freerdp_error_info(instance);
1234
+ if (exit_code == SDL_EXIT_SUCCESS)
1235
+ {
1236
+ char* msg = nullptr;
1237
+ size_t len = 0;
1238
+ exit_code = error_info_to_error(instance, &code, &msg, &len);
1239
+ if (msg)
1240
+ error_msg = msg;
1241
+ free(msg);
1242
+ }
1243
+
1244
+ auto last = freerdp_get_last_error(context);
1245
+ if (error_msg.empty())
1246
+ {
1247
+ char* msg = nullptr;
1248
+ size_t len = 0;
1249
+ winpr_asprintf(&msg, &len, "%s [0x%08" PRIx32 "]\n%s",
1250
+ freerdp_get_last_error_name(last), last,
1251
+ freerdp_get_last_error_string(last));
1252
+ if (msg)
1253
+ error_msg = msg;
1254
+ free(msg);
1255
+ }
1256
+
1257
+ if (exit_code == SDL_EXIT_SUCCESS)
1258
+ {
1259
+ if (last == FREERDP_ERROR_AUTHENTICATION_FAILED)
1260
+ exit_code = SDL_EXIT_AUTH_FAILURE;
1261
+ else if (code == ERRINFO_SUCCESS)
1262
+ exit_code = SDL_EXIT_CONN_FAILED;
1263
+ }
1264
+
1265
+ sdl_hide_connection_dialog(sdl);
1266
+ }
1267
+
1268
+ return exit_code;
1269
+ }
1270
+
1271
+ static int sdl_client_thread_run(SdlContext* sdl, std::string& error_msg)
1272
+ {
1273
+ WINPR_ASSERT(sdl);
1274
+
1275
+ auto context = sdl->context();
1276
+ WINPR_ASSERT(context);
1277
+
1278
+ auto instance = context->instance;
1279
+ WINPR_ASSERT(instance);
1280
+
1281
+ int exit_code = SDL_EXIT_SUCCESS;
1282
+ while (!freerdp_shall_disconnect_context(context))
1283
+ {
1284
+ HANDLE handles[MAXIMUM_WAIT_OBJECTS] = {};
1285
+ /*
1286
+ * win8 and server 2k12 seem to have some timing issue/race condition
1287
+ * when a initial sync request is send to sync the keyboard indicators
1288
+ * sending the sync event twice fixed this problem
1289
+ */
1290
+ if (freerdp_focus_required(instance))
1291
+ {
1292
+ auto ctx = get_context(context);
1293
+ WINPR_ASSERT(ctx);
1294
+ if (!ctx->input.keyboard_focus_in())
1295
+ break;
1296
+ if (!ctx->input.keyboard_focus_in())
1297
+ break;
1298
+ }
1299
+
1300
+ const DWORD nCount = freerdp_get_event_handles(context, handles, ARRAYSIZE(handles));
1301
+
1302
+ if (nCount == 0)
1303
+ {
1304
+ WLog_Print(sdl->log, WLOG_ERROR, "freerdp_get_event_handles failed");
1305
+ break;
1306
+ }
1307
+
1308
+ const DWORD status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
1309
+
1310
+ if (status == WAIT_FAILED)
1311
+ break;
1312
+
1313
+ if (!freerdp_check_event_handles(context))
1314
+ {
1315
+ if (client_auto_reconnect(instance))
1316
+ {
1317
+ // Retry was successful, discard dialog
1318
+ sdl_hide_connection_dialog(sdl);
1319
+ continue;
1320
+ }
1321
+ else
1322
+ {
1323
+ /*
1324
+ * Indicate an unsuccessful connection attempt if reconnect
1325
+ * did not succeed and no other error was specified.
1326
+ */
1327
+ if (freerdp_error_info(instance) == 0)
1328
+ exit_code = SDL_EXIT_CONN_FAILED;
1329
+ }
1330
+
1331
+ if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
1332
+ WLog_Print(sdl->log, WLOG_ERROR, "WaitForMultipleObjects failed with %" PRIu32 "",
1333
+ status);
1334
+ if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
1335
+ WLog_Print(sdl->log, WLOG_ERROR, "Failed to check FreeRDP event handles");
1336
+ break;
1337
+ }
1338
+ }
1339
+
1340
+ if (exit_code == SDL_EXIT_SUCCESS)
1341
+ {
1342
+ DWORD code = 0;
1343
+ {
1344
+ char* emsg = nullptr;
1345
+ size_t elen = 0;
1346
+ exit_code = error_info_to_error(instance, &code, &emsg, &elen);
1347
+ if (emsg)
1348
+ error_msg = emsg;
1349
+ free(emsg);
1350
+ }
1351
+
1352
+ if ((code == ERRINFO_LOGOFF_BY_USER) &&
1353
+ (freerdp_get_disconnect_ultimatum(context) == Disconnect_Ultimatum_user_requested))
1354
+ {
1355
+ const char* msg = "Error info says user did not initiate but disconnect ultimatum says "
1356
+ "they did; treat this as a user logoff";
1357
+
1358
+ char* emsg = nullptr;
1359
+ size_t elen = 0;
1360
+ winpr_asprintf(&emsg, &elen, "%s", msg);
1361
+ if (emsg)
1362
+ error_msg = emsg;
1363
+ free(emsg);
1364
+
1365
+ /* This situation might be limited to Windows XP. */
1366
+ WLog_Print(sdl->log, WLOG_INFO, "%s", msg);
1367
+ exit_code = SDL_EXIT_LOGOFF;
1368
+ }
1369
+ }
1370
+
1371
+ freerdp_disconnect(instance);
1372
+
1373
+ return exit_code;
1374
+ }
1375
+
1376
+ /* RDP main loop.
1377
+ * Connects RDP, loops while running and handles event and dispatch, cleans up
1378
+ * after the connection ends. */
1379
+ static DWORD WINAPI sdl_client_thread_proc(SdlContext* sdl)
1380
+ {
1381
+ WINPR_ASSERT(sdl);
1382
+
1383
+ std::string error_msg;
1384
+ int exit_code = sdl_client_thread_connect(sdl, error_msg);
1385
+ if (exit_code == SDL_EXIT_SUCCESS)
1386
+ exit_code = sdl_client_thread_run(sdl, error_msg);
1387
+ sdl_client_cleanup(sdl, exit_code, error_msg);
1388
+
1389
+ return static_cast<DWORD>(exit_code);
1390
+ }
1391
+
1392
+ /* Optional global initializer.
1393
+ * Here we just register a signal handler to print out stack traces
1394
+ * if available. */
1395
+ static BOOL sdl_client_global_init()
1396
+ {
1397
+ #if defined(_WIN32)
1398
+ WSADATA wsaData = {};
1399
+ const DWORD wVersionRequested = MAKEWORD(1, 1);
1400
+ const int rc = WSAStartup(wVersionRequested, &wsaData);
1401
+ if (rc != 0)
1402
+ {
1403
+ WLog_ERR(SDL_TAG, "WSAStartup failed with %s [%d]", gai_strerrorA(rc), rc);
1404
+ return FALSE;
1405
+ }
1406
+ #endif
1407
+
1408
+ return (freerdp_handle_signals() == 0);
1409
+ }
1410
+
1411
+ /* Optional global tear down */
1412
+ static void sdl_client_global_uninit()
1413
+ {
1414
+ #if defined(_WIN32)
1415
+ WSACleanup();
1416
+ #endif
1417
+ }
1418
+
1419
+ static BOOL sdl_client_new(freerdp* instance, rdpContext* context)
1420
+ {
1421
+ auto sdl = reinterpret_cast<sdl_rdp_context*>(context);
1422
+
1423
+ if (!instance || !context)
1424
+ return FALSE;
1425
+
1426
+ sdl->sdl = new SdlContext(context);
1427
+ if (!sdl->sdl)
1428
+ return FALSE;
1429
+
1430
+ instance->PreConnect = sdl_pre_connect;
1431
+ instance->PostConnect = sdl_post_connect;
1432
+ instance->PostDisconnect = sdl_post_disconnect;
1433
+ instance->PostFinalDisconnect = sdl_post_final_disconnect;
1434
+ instance->AuthenticateEx = sdl_authenticate_ex;
1435
+ instance->VerifyCertificateEx = sdl_verify_certificate_ex;
1436
+ instance->VerifyChangedCertificateEx = sdl_verify_changed_certificate_ex;
1437
+ instance->LogonErrorInfo = sdl_logon_error_info;
1438
+ instance->PresentGatewayMessage = sdl_present_gateway_message;
1439
+ instance->ChooseSmartcard = sdl_choose_smartcard;
1440
+ instance->RetryDialog = sdl_retry_dialog;
1441
+
1442
+ #ifdef WITH_WEBVIEW
1443
+ instance->GetAccessToken = sdl_webview_get_access_token;
1444
+ #else
1445
+ instance->GetAccessToken = client_cli_get_access_token;
1446
+ #endif
1447
+ /* TODO: Client display set up */
1448
+
1449
+ return TRUE;
1450
+ }
1451
+
1452
+ static void sdl_client_free(freerdp* instance, rdpContext* context)
1453
+ {
1454
+ auto sdl = reinterpret_cast<sdl_rdp_context*>(context);
1455
+
1456
+ if (!context)
1457
+ return;
1458
+
1459
+ delete sdl->sdl;
1460
+ }
1461
+
1462
+ static int sdl_client_start(rdpContext* context)
1463
+ {
1464
+ auto sdl = get_context(context);
1465
+ WINPR_ASSERT(sdl);
1466
+
1467
+ sdl->thread = std::thread(sdl_client_thread_proc, sdl);
1468
+ return 0;
1469
+ }
1470
+
1471
+ static int sdl_client_stop(rdpContext* context)
1472
+ {
1473
+ auto sdl = get_context(context);
1474
+ WINPR_ASSERT(sdl);
1475
+
1476
+ /* We do not want to use freerdp_abort_connect_context here.
1477
+ * It would change the exit code and we do not want that. */
1478
+ HANDLE event = freerdp_abort_event(context);
1479
+ if (!SetEvent(event))
1480
+ return -1;
1481
+
1482
+ sdl->thread.join();
1483
+ return 0;
1484
+ }
1485
+
1486
+ static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
1487
+ {
1488
+ WINPR_ASSERT(pEntryPoints);
1489
+
1490
+ ZeroMemory(pEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS));
1491
+ pEntryPoints->Version = RDP_CLIENT_INTERFACE_VERSION;
1492
+ pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
1493
+ pEntryPoints->GlobalInit = sdl_client_global_init;
1494
+ pEntryPoints->GlobalUninit = sdl_client_global_uninit;
1495
+ pEntryPoints->ContextSize = sizeof(sdl_rdp_context);
1496
+ pEntryPoints->ClientNew = sdl_client_new;
1497
+ pEntryPoints->ClientFree = sdl_client_free;
1498
+ pEntryPoints->ClientStart = sdl_client_start;
1499
+ pEntryPoints->ClientStop = sdl_client_stop;
1500
+ return 0;
1501
+ }
1502
+
1503
+ static void context_free(sdl_rdp_context* sdl)
1504
+ {
1505
+ if (sdl)
1506
+ freerdp_client_context_free(&sdl->common.context);
1507
+ }
1508
+
1509
+ static const char* category2str(int category)
1510
+ {
1511
+ switch (category)
1512
+ {
1513
+ case SDL_LOG_CATEGORY_APPLICATION:
1514
+ return "SDL_LOG_CATEGORY_APPLICATION";
1515
+ case SDL_LOG_CATEGORY_ERROR:
1516
+ return "SDL_LOG_CATEGORY_ERROR";
1517
+ case SDL_LOG_CATEGORY_ASSERT:
1518
+ return "SDL_LOG_CATEGORY_ASSERT";
1519
+ case SDL_LOG_CATEGORY_SYSTEM:
1520
+ return "SDL_LOG_CATEGORY_SYSTEM";
1521
+ case SDL_LOG_CATEGORY_AUDIO:
1522
+ return "SDL_LOG_CATEGORY_AUDIO";
1523
+ case SDL_LOG_CATEGORY_VIDEO:
1524
+ return "SDL_LOG_CATEGORY_VIDEO";
1525
+ case SDL_LOG_CATEGORY_RENDER:
1526
+ return "SDL_LOG_CATEGORY_RENDER";
1527
+ case SDL_LOG_CATEGORY_INPUT:
1528
+ return "SDL_LOG_CATEGORY_INPUT";
1529
+ case SDL_LOG_CATEGORY_TEST:
1530
+ return "SDL_LOG_CATEGORY_TEST";
1531
+ case SDL_LOG_CATEGORY_GPU:
1532
+ return "SDL_LOG_CATEGORY_GPU";
1533
+ case SDL_LOG_CATEGORY_RESERVED2:
1534
+ return "SDL_LOG_CATEGORY_RESERVED2";
1535
+ case SDL_LOG_CATEGORY_RESERVED3:
1536
+ return "SDL_LOG_CATEGORY_RESERVED3";
1537
+ case SDL_LOG_CATEGORY_RESERVED4:
1538
+ return "SDL_LOG_CATEGORY_RESERVED4";
1539
+ case SDL_LOG_CATEGORY_RESERVED5:
1540
+ return "SDL_LOG_CATEGORY_RESERVED5";
1541
+ case SDL_LOG_CATEGORY_RESERVED6:
1542
+ return "SDL_LOG_CATEGORY_RESERVED6";
1543
+ case SDL_LOG_CATEGORY_RESERVED7:
1544
+ return "SDL_LOG_CATEGORY_RESERVED7";
1545
+ case SDL_LOG_CATEGORY_RESERVED8:
1546
+ return "SDL_LOG_CATEGORY_RESERVED8";
1547
+ case SDL_LOG_CATEGORY_RESERVED9:
1548
+ return "SDL_LOG_CATEGORY_RESERVED9";
1549
+ case SDL_LOG_CATEGORY_RESERVED10:
1550
+ return "SDL_LOG_CATEGORY_RESERVED10";
1551
+ case SDL_LOG_CATEGORY_CUSTOM:
1552
+ default:
1553
+ return "SDL_LOG_CATEGORY_CUSTOM";
1554
+ }
1555
+ }
1556
+
1557
+ static SDL_LogPriority wloglevel2dl(DWORD level)
1558
+ {
1559
+ switch (level)
1560
+ {
1561
+ case WLOG_TRACE:
1562
+ return SDL_LOG_PRIORITY_VERBOSE;
1563
+ case WLOG_DEBUG:
1564
+ return SDL_LOG_PRIORITY_DEBUG;
1565
+ case WLOG_INFO:
1566
+ return SDL_LOG_PRIORITY_INFO;
1567
+ case WLOG_WARN:
1568
+ return SDL_LOG_PRIORITY_WARN;
1569
+ case WLOG_ERROR:
1570
+ return SDL_LOG_PRIORITY_ERROR;
1571
+ case WLOG_FATAL:
1572
+ return SDL_LOG_PRIORITY_CRITICAL;
1573
+ case WLOG_OFF:
1574
+ default:
1575
+ return SDL_LOG_PRIORITY_VERBOSE;
1576
+ }
1577
+ }
1578
+
1579
+ static DWORD sdlpriority2wlog(SDL_LogPriority priority)
1580
+ {
1581
+ DWORD level = WLOG_OFF;
1582
+ switch (priority)
1583
+ {
1584
+ case SDL_LOG_PRIORITY_VERBOSE:
1585
+ level = WLOG_TRACE;
1586
+ break;
1587
+ case SDL_LOG_PRIORITY_DEBUG:
1588
+ level = WLOG_DEBUG;
1589
+ break;
1590
+ case SDL_LOG_PRIORITY_INFO:
1591
+ level = WLOG_INFO;
1592
+ break;
1593
+ case SDL_LOG_PRIORITY_WARN:
1594
+ level = WLOG_WARN;
1595
+ break;
1596
+ case SDL_LOG_PRIORITY_ERROR:
1597
+ level = WLOG_ERROR;
1598
+ break;
1599
+ case SDL_LOG_PRIORITY_CRITICAL:
1600
+ level = WLOG_FATAL;
1601
+ break;
1602
+ default:
1603
+ break;
1604
+ }
1605
+
1606
+ return level;
1607
+ }
1608
+
1609
+ static void SDLCALL winpr_LogOutputFunction(void* userdata, int category, SDL_LogPriority priority,
1610
+ const char* message)
1611
+ {
1612
+ auto sdl = static_cast<SdlContext*>(userdata);
1613
+ WINPR_ASSERT(sdl);
1614
+
1615
+ const DWORD level = sdlpriority2wlog(priority);
1616
+ auto log = sdl->log;
1617
+ if (!WLog_IsLevelActive(log, level))
1618
+ return;
1619
+
1620
+ WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, level, __LINE__, __FILE__, __func__, "[%s] %s",
1621
+ category2str(category), message);
1622
+ }
1623
+
1624
+ int main(int argc, char* argv[])
1625
+ {
1626
+ int rc = -1;
1627
+ int status = 0;
1628
+ RDP_CLIENT_ENTRY_POINTS clientEntryPoints = {};
1629
+
1630
+ freerdp_client_warn_experimental(argc, argv);
1631
+
1632
+ RdpClientEntry(&clientEntryPoints);
1633
+ std::unique_ptr<sdl_rdp_context, void (*)(sdl_rdp_context*)> sdl_rdp(
1634
+ reinterpret_cast<sdl_rdp_context*>(freerdp_client_context_new(&clientEntryPoints)),
1635
+ context_free);
1636
+
1637
+ if (!sdl_rdp)
1638
+ return -1;
1639
+ auto sdl = sdl_rdp->sdl;
1640
+
1641
+ auto settings = sdl->context()->settings;
1642
+ WINPR_ASSERT(settings);
1643
+
1644
+ status = freerdp_client_settings_parse_command_line(settings, argc, argv, FALSE);
1645
+ if (status)
1646
+ {
1647
+ rc = freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
1648
+ if (freerdp_settings_get_bool(settings, FreeRDP_ListMonitors))
1649
+ sdl_list_monitors(sdl);
1650
+ else
1651
+ {
1652
+ switch (status)
1653
+ {
1654
+ case COMMAND_LINE_STATUS_PRINT:
1655
+ case COMMAND_LINE_STATUS_PRINT_VERSION:
1656
+ case COMMAND_LINE_STATUS_PRINT_BUILDCONFIG:
1657
+ break;
1658
+ case COMMAND_LINE_STATUS_PRINT_HELP:
1659
+ default:
1660
+ SdlPref::print_config_file_help(3);
1661
+ break;
1662
+ }
1663
+ }
1664
+ return rc;
1665
+ }
1666
+
1667
+ SDL_SetLogOutputFunction(winpr_LogOutputFunction, sdl);
1668
+ auto level = WLog_GetLogLevel(sdl->log);
1669
+ SDL_SetLogPriorities(wloglevel2dl(level));
1670
+
1671
+ auto context = sdl->context();
1672
+ WINPR_ASSERT(context);
1673
+
1674
+ if (!stream_dump_register_handlers(context, CONNECTION_STATE_MCS_CREATE_REQUEST, FALSE))
1675
+ return -1;
1676
+
1677
+ if (freerdp_client_start(context) != 0)
1678
+ return -1;
1679
+
1680
+ rc = sdl_run(sdl);
1681
+
1682
+ if (freerdp_client_stop(context) != 0)
1683
+ return -1;
1684
+
1685
+ if (sdl->exit_code != 0)
1686
+ rc = sdl->exit_code;
1687
+
1688
+ return rc;
1689
+ }
1690
+
1691
+ BOOL SdlContext::update_fullscreen(BOOL enter)
1692
+ {
1693
+ std::lock_guard<CriticalSection> lock(critical);
1694
+ for (const auto& window : windows)
1695
+ {
1696
+ if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_FULLSCREEN, &window.second, enter))
1697
+ return FALSE;
1698
+ }
1699
+ fullscreen = enter;
1700
+ return TRUE;
1701
+ }
1702
+
1703
+ BOOL SdlContext::update_minimize()
1704
+ {
1705
+ std::lock_guard<CriticalSection> lock(critical);
1706
+ return sdl_push_user_event(SDL_EVENT_USER_WINDOW_MINIMIZE);
1707
+ }
1708
+
1709
+ BOOL SdlContext::update_resizeable(BOOL enable)
1710
+ {
1711
+ std::lock_guard<CriticalSection> lock(critical);
1712
+
1713
+ const auto settings = context()->settings;
1714
+ const BOOL dyn = freerdp_settings_get_bool(settings, FreeRDP_DynamicResolutionUpdate);
1715
+ const BOOL smart = freerdp_settings_get_bool(settings, FreeRDP_SmartSizing);
1716
+ BOOL use = (dyn && enable) || smart;
1717
+
1718
+ for (const auto& window : windows)
1719
+ {
1720
+ if (!sdl_push_user_event(SDL_EVENT_USER_WINDOW_RESIZEABLE, &window.second, use))
1721
+ return FALSE;
1722
+ }
1723
+ resizeable = use;
1724
+
1725
+ return TRUE;
1726
+ }
1727
+
1728
+ SdlContext::SdlContext(rdpContext* context)
1729
+ : _context(context), log(WLog_Get(SDL_TAG)), update_complete(true), disp(this), input(this),
1730
+ clip(this), primary(nullptr, SDL_DestroySurface), rdp_thread_running(false)
1731
+ {
1732
+ WINPR_ASSERT(context);
1733
+ grab_kbd_enabled = freerdp_settings_get_bool(context->settings, FreeRDP_GrabKeyboard);
1734
+ }
1735
+
1736
+ rdpContext* SdlContext::context() const
1737
+ {
1738
+ return _context;
1739
+ }
1740
+
1741
+ rdpClientContext* SdlContext::common() const
1742
+ {
1743
+ return reinterpret_cast<rdpClientContext*>(_context);
1744
+ }
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_freerdp.hpp ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * SDL Client
4
+ *
5
+ * Copyright 2022 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #pragma once
21
+
22
+ #include <memory>
23
+ #include <thread>
24
+ #include <map>
25
+ #include <atomic>
26
+
27
+ #include <freerdp/freerdp.h>
28
+ #include <freerdp/client/rdpei.h>
29
+ #include <freerdp/client/rail.h>
30
+ #include <freerdp/client/cliprdr.h>
31
+ #include <freerdp/client/rdpgfx.h>
32
+
33
+ #include <SDL3/SDL.h>
34
+ #include <SDL3/SDL_video.h>
35
+
36
+ #include "sdl_types.hpp"
37
+ #include "sdl_disp.hpp"
38
+ #include "sdl_kbd.hpp"
39
+ #include "sdl_clip.hpp"
40
+ #include "sdl_utils.hpp"
41
+ #include "sdl_window.hpp"
42
+ #include "dialogs/sdl_connection_dialog.hpp"
43
+
44
+ using SDLSurfacePtr = std::unique_ptr<SDL_Surface, decltype(&SDL_DestroySurface)>;
45
+
46
+ class SdlContext
47
+ {
48
+ public:
49
+ explicit SdlContext(rdpContext* context);
50
+ SdlContext(const SdlContext& other) = delete;
51
+ SdlContext(SdlContext&& other) = delete;
52
+
53
+ SdlContext& operator=(const SdlContext& other) = delete;
54
+ SdlContext& operator=(SdlContext&& other) = delete;
55
+
56
+ private:
57
+ rdpContext* _context;
58
+
59
+ public:
60
+ wLog* log;
61
+
62
+ /* SDL */
63
+ bool fullscreen = false;
64
+ bool resizeable = false;
65
+ bool grab_mouse = false;
66
+ bool grab_kbd = false;
67
+ bool grab_kbd_enabled = true;
68
+
69
+ std::map<Uint32, SdlWindow> windows;
70
+
71
+ CriticalSection critical;
72
+ std::thread thread;
73
+ WinPREvent initialize;
74
+ WinPREvent initialized;
75
+ WinPREvent update_complete;
76
+ WinPREvent windows_created;
77
+ int exit_code = -1;
78
+
79
+ sdlDispContext disp;
80
+ sdlInput input;
81
+ sdlClip clip;
82
+
83
+ SDLSurfacePtr primary;
84
+
85
+ SDL_PixelFormat sdl_pixel_format = SDL_PIXELFORMAT_UNKNOWN;
86
+
87
+ std::unique_ptr<SDLConnectionDialog> connection_dialog;
88
+
89
+ std::atomic<bool> rdp_thread_running;
90
+
91
+ BOOL update_resizeable(BOOL enable);
92
+ BOOL update_fullscreen(BOOL enter);
93
+ BOOL update_minimize();
94
+
95
+ [[nodiscard]] rdpContext* context() const;
96
+ [[nodiscard]] rdpClientContext* common() const;
97
+ };
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_kbd.cpp ADDED
@@ -0,0 +1,550 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP SDL keyboard helper
4
+ *
5
+ * Copyright 2022 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #include "sdl_kbd.hpp"
21
+ #include "sdl_disp.hpp"
22
+ #include "sdl_freerdp.hpp"
23
+ #include "sdl_utils.hpp"
24
+ #include "sdl_prefs.hpp"
25
+
26
+ #include <SDL3/SDL_oldnames.h>
27
+
28
+ #include <map>
29
+
30
+ #include <freerdp/utils/string.h>
31
+ #include <freerdp/scancode.h>
32
+
33
+ #include <freerdp/log.h>
34
+ #define TAG CLIENT_TAG("SDL.kbd")
35
+
36
+ typedef struct
37
+ {
38
+ Uint32 sdl;
39
+ const char* sdl_name;
40
+ UINT32 rdp;
41
+ const char* rdp_name;
42
+ } scancode_entry_t;
43
+
44
+ #define STR(x) #x
45
+ #define ENTRY(x, y) \
46
+ { \
47
+ x, STR(x), y, #y \
48
+ }
49
+ static const scancode_entry_t map[] = {
50
+ ENTRY(SDL_SCANCODE_UNKNOWN, RDP_SCANCODE_UNKNOWN),
51
+ ENTRY(SDL_SCANCODE_A, RDP_SCANCODE_KEY_A),
52
+ ENTRY(SDL_SCANCODE_B, RDP_SCANCODE_KEY_B),
53
+ ENTRY(SDL_SCANCODE_C, RDP_SCANCODE_KEY_C),
54
+ ENTRY(SDL_SCANCODE_D, RDP_SCANCODE_KEY_D),
55
+ ENTRY(SDL_SCANCODE_E, RDP_SCANCODE_KEY_E),
56
+ ENTRY(SDL_SCANCODE_F, RDP_SCANCODE_KEY_F),
57
+ ENTRY(SDL_SCANCODE_G, RDP_SCANCODE_KEY_G),
58
+ ENTRY(SDL_SCANCODE_H, RDP_SCANCODE_KEY_H),
59
+ ENTRY(SDL_SCANCODE_I, RDP_SCANCODE_KEY_I),
60
+ ENTRY(SDL_SCANCODE_J, RDP_SCANCODE_KEY_J),
61
+ ENTRY(SDL_SCANCODE_K, RDP_SCANCODE_KEY_K),
62
+ ENTRY(SDL_SCANCODE_L, RDP_SCANCODE_KEY_L),
63
+ ENTRY(SDL_SCANCODE_M, RDP_SCANCODE_KEY_M),
64
+ ENTRY(SDL_SCANCODE_N, RDP_SCANCODE_KEY_N),
65
+ ENTRY(SDL_SCANCODE_O, RDP_SCANCODE_KEY_O),
66
+ ENTRY(SDL_SCANCODE_P, RDP_SCANCODE_KEY_P),
67
+ ENTRY(SDL_SCANCODE_Q, RDP_SCANCODE_KEY_Q),
68
+ ENTRY(SDL_SCANCODE_R, RDP_SCANCODE_KEY_R),
69
+ ENTRY(SDL_SCANCODE_S, RDP_SCANCODE_KEY_S),
70
+ ENTRY(SDL_SCANCODE_T, RDP_SCANCODE_KEY_T),
71
+ ENTRY(SDL_SCANCODE_U, RDP_SCANCODE_KEY_U),
72
+ ENTRY(SDL_SCANCODE_V, RDP_SCANCODE_KEY_V),
73
+ ENTRY(SDL_SCANCODE_W, RDP_SCANCODE_KEY_W),
74
+ ENTRY(SDL_SCANCODE_X, RDP_SCANCODE_KEY_X),
75
+ ENTRY(SDL_SCANCODE_Y, RDP_SCANCODE_KEY_Y),
76
+ ENTRY(SDL_SCANCODE_Z, RDP_SCANCODE_KEY_Z),
77
+ ENTRY(SDL_SCANCODE_1, RDP_SCANCODE_KEY_1),
78
+ ENTRY(SDL_SCANCODE_2, RDP_SCANCODE_KEY_2),
79
+ ENTRY(SDL_SCANCODE_3, RDP_SCANCODE_KEY_3),
80
+ ENTRY(SDL_SCANCODE_4, RDP_SCANCODE_KEY_4),
81
+ ENTRY(SDL_SCANCODE_5, RDP_SCANCODE_KEY_5),
82
+ ENTRY(SDL_SCANCODE_6, RDP_SCANCODE_KEY_6),
83
+ ENTRY(SDL_SCANCODE_7, RDP_SCANCODE_KEY_7),
84
+ ENTRY(SDL_SCANCODE_8, RDP_SCANCODE_KEY_8),
85
+ ENTRY(SDL_SCANCODE_9, RDP_SCANCODE_KEY_9),
86
+ ENTRY(SDL_SCANCODE_0, RDP_SCANCODE_KEY_0),
87
+ ENTRY(SDL_SCANCODE_RETURN, RDP_SCANCODE_RETURN),
88
+ ENTRY(SDL_SCANCODE_ESCAPE, RDP_SCANCODE_ESCAPE),
89
+ ENTRY(SDL_SCANCODE_BACKSPACE, RDP_SCANCODE_BACKSPACE),
90
+ ENTRY(SDL_SCANCODE_TAB, RDP_SCANCODE_TAB),
91
+ ENTRY(SDL_SCANCODE_SPACE, RDP_SCANCODE_SPACE),
92
+ ENTRY(SDL_SCANCODE_MINUS, RDP_SCANCODE_OEM_MINUS),
93
+ ENTRY(SDL_SCANCODE_CAPSLOCK, RDP_SCANCODE_CAPSLOCK),
94
+ ENTRY(SDL_SCANCODE_F1, RDP_SCANCODE_F1),
95
+ ENTRY(SDL_SCANCODE_F2, RDP_SCANCODE_F2),
96
+ ENTRY(SDL_SCANCODE_F3, RDP_SCANCODE_F3),
97
+ ENTRY(SDL_SCANCODE_F4, RDP_SCANCODE_F4),
98
+ ENTRY(SDL_SCANCODE_F5, RDP_SCANCODE_F5),
99
+ ENTRY(SDL_SCANCODE_F6, RDP_SCANCODE_F6),
100
+ ENTRY(SDL_SCANCODE_F7, RDP_SCANCODE_F7),
101
+ ENTRY(SDL_SCANCODE_F8, RDP_SCANCODE_F8),
102
+ ENTRY(SDL_SCANCODE_F9, RDP_SCANCODE_F9),
103
+ ENTRY(SDL_SCANCODE_F10, RDP_SCANCODE_F10),
104
+ ENTRY(SDL_SCANCODE_F11, RDP_SCANCODE_F11),
105
+ ENTRY(SDL_SCANCODE_F12, RDP_SCANCODE_F12),
106
+ ENTRY(SDL_SCANCODE_F13, RDP_SCANCODE_F13),
107
+ ENTRY(SDL_SCANCODE_F14, RDP_SCANCODE_F14),
108
+ ENTRY(SDL_SCANCODE_F15, RDP_SCANCODE_F15),
109
+ ENTRY(SDL_SCANCODE_F16, RDP_SCANCODE_F16),
110
+ ENTRY(SDL_SCANCODE_F17, RDP_SCANCODE_F17),
111
+ ENTRY(SDL_SCANCODE_F18, RDP_SCANCODE_F18),
112
+ ENTRY(SDL_SCANCODE_F19, RDP_SCANCODE_F19),
113
+ ENTRY(SDL_SCANCODE_F20, RDP_SCANCODE_F20),
114
+ ENTRY(SDL_SCANCODE_F21, RDP_SCANCODE_F21),
115
+ ENTRY(SDL_SCANCODE_F22, RDP_SCANCODE_F22),
116
+ ENTRY(SDL_SCANCODE_F23, RDP_SCANCODE_F23),
117
+ ENTRY(SDL_SCANCODE_F24, RDP_SCANCODE_F24),
118
+ ENTRY(SDL_SCANCODE_NUMLOCKCLEAR, RDP_SCANCODE_NUMLOCK),
119
+ ENTRY(SDL_SCANCODE_KP_DIVIDE, RDP_SCANCODE_DIVIDE),
120
+ ENTRY(SDL_SCANCODE_KP_MULTIPLY, RDP_SCANCODE_MULTIPLY),
121
+ ENTRY(SDL_SCANCODE_KP_MINUS, RDP_SCANCODE_SUBTRACT),
122
+ ENTRY(SDL_SCANCODE_KP_PLUS, RDP_SCANCODE_ADD),
123
+ ENTRY(SDL_SCANCODE_KP_ENTER, RDP_SCANCODE_RETURN_KP),
124
+ ENTRY(SDL_SCANCODE_KP_1, RDP_SCANCODE_NUMPAD1),
125
+ ENTRY(SDL_SCANCODE_KP_2, RDP_SCANCODE_NUMPAD2),
126
+ ENTRY(SDL_SCANCODE_KP_3, RDP_SCANCODE_NUMPAD3),
127
+ ENTRY(SDL_SCANCODE_KP_4, RDP_SCANCODE_NUMPAD4),
128
+ ENTRY(SDL_SCANCODE_KP_5, RDP_SCANCODE_NUMPAD5),
129
+ ENTRY(SDL_SCANCODE_KP_6, RDP_SCANCODE_NUMPAD6),
130
+ ENTRY(SDL_SCANCODE_KP_7, RDP_SCANCODE_NUMPAD7),
131
+ ENTRY(SDL_SCANCODE_KP_8, RDP_SCANCODE_NUMPAD8),
132
+ ENTRY(SDL_SCANCODE_KP_9, RDP_SCANCODE_NUMPAD9),
133
+ ENTRY(SDL_SCANCODE_KP_0, RDP_SCANCODE_NUMPAD0),
134
+ ENTRY(SDL_SCANCODE_KP_PERIOD, RDP_SCANCODE_OEM_PERIOD),
135
+ ENTRY(SDL_SCANCODE_LCTRL, RDP_SCANCODE_LCONTROL),
136
+ ENTRY(SDL_SCANCODE_LSHIFT, RDP_SCANCODE_LSHIFT),
137
+ ENTRY(SDL_SCANCODE_LALT, RDP_SCANCODE_LMENU),
138
+ ENTRY(SDL_SCANCODE_LGUI, RDP_SCANCODE_LWIN),
139
+ ENTRY(SDL_SCANCODE_RCTRL, RDP_SCANCODE_RCONTROL),
140
+ ENTRY(SDL_SCANCODE_RSHIFT, RDP_SCANCODE_RSHIFT),
141
+ ENTRY(SDL_SCANCODE_RALT, RDP_SCANCODE_RMENU),
142
+ ENTRY(SDL_SCANCODE_RGUI, RDP_SCANCODE_RWIN),
143
+ ENTRY(SDL_SCANCODE_MODE, RDP_SCANCODE_APPS),
144
+ ENTRY(SDL_SCANCODE_MUTE, RDP_SCANCODE_VOLUME_MUTE),
145
+ ENTRY(SDL_SCANCODE_VOLUMEUP, RDP_SCANCODE_VOLUME_UP),
146
+ ENTRY(SDL_SCANCODE_VOLUMEDOWN, RDP_SCANCODE_VOLUME_DOWN),
147
+ ENTRY(SDL_SCANCODE_GRAVE, RDP_SCANCODE_OEM_3),
148
+ ENTRY(SDL_SCANCODE_COMMA, RDP_SCANCODE_OEM_COMMA),
149
+ ENTRY(SDL_SCANCODE_PERIOD, RDP_SCANCODE_OEM_PERIOD),
150
+ ENTRY(SDL_SCANCODE_SLASH, RDP_SCANCODE_OEM_2),
151
+ ENTRY(SDL_SCANCODE_BACKSLASH, RDP_SCANCODE_OEM_5),
152
+ ENTRY(SDL_SCANCODE_SCROLLLOCK, RDP_SCANCODE_SCROLLLOCK),
153
+ ENTRY(SDL_SCANCODE_INSERT, RDP_SCANCODE_INSERT),
154
+ ENTRY(SDL_SCANCODE_PRINTSCREEN, RDP_SCANCODE_PRINTSCREEN),
155
+ ENTRY(SDL_SCANCODE_HOME, RDP_SCANCODE_HOME),
156
+ ENTRY(SDL_SCANCODE_DELETE, RDP_SCANCODE_DELETE),
157
+ ENTRY(SDL_SCANCODE_RIGHT, RDP_SCANCODE_RIGHT),
158
+ ENTRY(SDL_SCANCODE_LEFT, RDP_SCANCODE_LEFT),
159
+ ENTRY(SDL_SCANCODE_DOWN, RDP_SCANCODE_DOWN),
160
+ ENTRY(SDL_SCANCODE_UP, RDP_SCANCODE_UP),
161
+ ENTRY(SDL_SCANCODE_SEMICOLON, RDP_SCANCODE_OEM_1),
162
+ ENTRY(SDL_SCANCODE_PAUSE, RDP_SCANCODE_PAUSE),
163
+ ENTRY(SDL_SCANCODE_PAGEUP, RDP_SCANCODE_PRIOR),
164
+ ENTRY(SDL_SCANCODE_END, RDP_SCANCODE_END),
165
+ ENTRY(SDL_SCANCODE_PAGEDOWN, RDP_SCANCODE_NEXT),
166
+ ENTRY(SDL_SCANCODE_MEDIA_NEXT_TRACK, RDP_SCANCODE_MEDIA_NEXT_TRACK),
167
+ ENTRY(SDL_SCANCODE_MEDIA_PREVIOUS_TRACK, RDP_SCANCODE_MEDIA_PREV_TRACK),
168
+ ENTRY(SDL_SCANCODE_MEDIA_STOP, RDP_SCANCODE_MEDIA_STOP),
169
+ ENTRY(SDL_SCANCODE_MEDIA_PLAY, RDP_SCANCODE_MEDIA_PLAY_PAUSE),
170
+ ENTRY(SDL_SCANCODE_MUTE, RDP_SCANCODE_VOLUME_MUTE),
171
+ ENTRY(SDL_SCANCODE_MEDIA_SELECT, RDP_SCANCODE_LAUNCH_MEDIA_SELECT),
172
+ ENTRY(SDL_SCANCODE_SYSREQ, RDP_SCANCODE_SYSREQ),
173
+ ENTRY(SDL_SCANCODE_LEFTBRACKET, RDP_SCANCODE_OEM_4),
174
+ ENTRY(SDL_SCANCODE_RIGHTBRACKET, RDP_SCANCODE_OEM_6),
175
+ ENTRY(SDL_SCANCODE_APOSTROPHE, RDP_SCANCODE_OEM_7),
176
+ ENTRY(SDL_SCANCODE_NONUSBACKSLASH, RDP_SCANCODE_OEM_102),
177
+ ENTRY(SDL_SCANCODE_SLEEP, RDP_SCANCODE_SLEEP),
178
+ ENTRY(SDL_SCANCODE_EQUALS, RDP_SCANCODE_OEM_PLUS),
179
+ ENTRY(SDL_SCANCODE_KP_COMMA, RDP_SCANCODE_DECIMAL),
180
+ ENTRY(SDL_SCANCODE_FIND, RDP_SCANCODE_BROWSER_SEARCH),
181
+ ENTRY(SDL_SCANCODE_RETURN2, RDP_SCANCODE_RETURN_KP),
182
+ ENTRY(SDL_SCANCODE_AC_SEARCH, RDP_SCANCODE_BROWSER_SEARCH),
183
+ ENTRY(SDL_SCANCODE_AC_HOME, RDP_SCANCODE_BROWSER_HOME),
184
+ ENTRY(SDL_SCANCODE_AC_BACK, RDP_SCANCODE_BROWSER_BACK),
185
+ ENTRY(SDL_SCANCODE_AC_FORWARD, RDP_SCANCODE_BROWSER_FORWARD),
186
+ ENTRY(SDL_SCANCODE_AC_STOP, RDP_SCANCODE_BROWSER_STOP),
187
+
188
+ ENTRY(SDL_SCANCODE_NONUSHASH, RDP_SCANCODE_UNKNOWN),
189
+ ENTRY(SDL_SCANCODE_APPLICATION, RDP_SCANCODE_UNKNOWN),
190
+ ENTRY(SDL_SCANCODE_POWER, RDP_SCANCODE_UNKNOWN),
191
+ ENTRY(SDL_SCANCODE_KP_EQUALS, RDP_SCANCODE_UNKNOWN),
192
+ ENTRY(SDL_SCANCODE_EXECUTE, RDP_SCANCODE_UNKNOWN),
193
+ ENTRY(SDL_SCANCODE_HELP, RDP_SCANCODE_UNKNOWN),
194
+ ENTRY(SDL_SCANCODE_MENU, RDP_SCANCODE_UNKNOWN),
195
+ ENTRY(SDL_SCANCODE_SELECT, RDP_SCANCODE_UNKNOWN),
196
+ ENTRY(SDL_SCANCODE_STOP, RDP_SCANCODE_UNKNOWN),
197
+ ENTRY(SDL_SCANCODE_AGAIN, RDP_SCANCODE_UNKNOWN),
198
+ ENTRY(SDL_SCANCODE_UNDO, RDP_SCANCODE_UNKNOWN),
199
+ ENTRY(SDL_SCANCODE_CUT, RDP_SCANCODE_UNKNOWN),
200
+ ENTRY(SDL_SCANCODE_COPY, RDP_SCANCODE_UNKNOWN),
201
+ ENTRY(SDL_SCANCODE_PASTE, RDP_SCANCODE_UNKNOWN),
202
+ ENTRY(SDL_SCANCODE_KP_EQUALSAS400, RDP_SCANCODE_UNKNOWN),
203
+ ENTRY(SDL_SCANCODE_INTERNATIONAL1, RDP_SCANCODE_UNKNOWN),
204
+ ENTRY(SDL_SCANCODE_INTERNATIONAL2, RDP_SCANCODE_UNKNOWN),
205
+ ENTRY(SDL_SCANCODE_INTERNATIONAL3, RDP_SCANCODE_UNKNOWN),
206
+ ENTRY(SDL_SCANCODE_INTERNATIONAL4, RDP_SCANCODE_UNKNOWN),
207
+ ENTRY(SDL_SCANCODE_INTERNATIONAL5, RDP_SCANCODE_UNKNOWN),
208
+ ENTRY(SDL_SCANCODE_INTERNATIONAL6, RDP_SCANCODE_UNKNOWN),
209
+ ENTRY(SDL_SCANCODE_INTERNATIONAL7, RDP_SCANCODE_UNKNOWN),
210
+ ENTRY(SDL_SCANCODE_INTERNATIONAL8, RDP_SCANCODE_UNKNOWN),
211
+ ENTRY(SDL_SCANCODE_INTERNATIONAL9, RDP_SCANCODE_UNKNOWN),
212
+ ENTRY(SDL_SCANCODE_LANG1, RDP_SCANCODE_UNKNOWN),
213
+ ENTRY(SDL_SCANCODE_LANG2, RDP_SCANCODE_UNKNOWN),
214
+ ENTRY(SDL_SCANCODE_LANG3, RDP_SCANCODE_UNKNOWN),
215
+ ENTRY(SDL_SCANCODE_LANG4, RDP_SCANCODE_UNKNOWN),
216
+ ENTRY(SDL_SCANCODE_LANG5, RDP_SCANCODE_UNKNOWN),
217
+ ENTRY(SDL_SCANCODE_LANG6, RDP_SCANCODE_UNKNOWN),
218
+ ENTRY(SDL_SCANCODE_LANG7, RDP_SCANCODE_UNKNOWN),
219
+ ENTRY(SDL_SCANCODE_LANG8, RDP_SCANCODE_UNKNOWN),
220
+ ENTRY(SDL_SCANCODE_LANG9, RDP_SCANCODE_UNKNOWN),
221
+ ENTRY(SDL_SCANCODE_ALTERASE, RDP_SCANCODE_UNKNOWN),
222
+ ENTRY(SDL_SCANCODE_CANCEL, RDP_SCANCODE_UNKNOWN),
223
+ ENTRY(SDL_SCANCODE_CLEAR, RDP_SCANCODE_UNKNOWN),
224
+ ENTRY(SDL_SCANCODE_PRIOR, RDP_SCANCODE_UNKNOWN),
225
+ ENTRY(SDL_SCANCODE_SEPARATOR, RDP_SCANCODE_UNKNOWN),
226
+ ENTRY(SDL_SCANCODE_OUT, RDP_SCANCODE_UNKNOWN),
227
+ ENTRY(SDL_SCANCODE_OPER, RDP_SCANCODE_UNKNOWN),
228
+ ENTRY(SDL_SCANCODE_CLEARAGAIN, RDP_SCANCODE_UNKNOWN),
229
+ ENTRY(SDL_SCANCODE_CRSEL, RDP_SCANCODE_UNKNOWN),
230
+ ENTRY(SDL_SCANCODE_EXSEL, RDP_SCANCODE_UNKNOWN),
231
+ ENTRY(SDL_SCANCODE_KP_00, RDP_SCANCODE_UNKNOWN),
232
+ ENTRY(SDL_SCANCODE_KP_000, RDP_SCANCODE_UNKNOWN),
233
+ ENTRY(SDL_SCANCODE_THOUSANDSSEPARATOR, RDP_SCANCODE_UNKNOWN),
234
+ ENTRY(SDL_SCANCODE_DECIMALSEPARATOR, RDP_SCANCODE_UNKNOWN),
235
+ ENTRY(SDL_SCANCODE_CURRENCYUNIT, RDP_SCANCODE_UNKNOWN),
236
+ ENTRY(SDL_SCANCODE_CURRENCYSUBUNIT, RDP_SCANCODE_UNKNOWN),
237
+ ENTRY(SDL_SCANCODE_KP_LEFTPAREN, RDP_SCANCODE_UNKNOWN),
238
+ ENTRY(SDL_SCANCODE_KP_RIGHTPAREN, RDP_SCANCODE_UNKNOWN),
239
+ ENTRY(SDL_SCANCODE_KP_LEFTBRACE, RDP_SCANCODE_UNKNOWN),
240
+ ENTRY(SDL_SCANCODE_KP_RIGHTBRACE, RDP_SCANCODE_UNKNOWN),
241
+ ENTRY(SDL_SCANCODE_KP_TAB, RDP_SCANCODE_UNKNOWN),
242
+ ENTRY(SDL_SCANCODE_KP_BACKSPACE, RDP_SCANCODE_UNKNOWN),
243
+ ENTRY(SDL_SCANCODE_KP_A, RDP_SCANCODE_UNKNOWN),
244
+ ENTRY(SDL_SCANCODE_KP_B, RDP_SCANCODE_UNKNOWN),
245
+ ENTRY(SDL_SCANCODE_KP_C, RDP_SCANCODE_UNKNOWN),
246
+ ENTRY(SDL_SCANCODE_KP_D, RDP_SCANCODE_UNKNOWN),
247
+ ENTRY(SDL_SCANCODE_KP_E, RDP_SCANCODE_UNKNOWN),
248
+ ENTRY(SDL_SCANCODE_KP_F, RDP_SCANCODE_UNKNOWN),
249
+ ENTRY(SDL_SCANCODE_KP_XOR, RDP_SCANCODE_UNKNOWN),
250
+ ENTRY(SDL_SCANCODE_KP_POWER, RDP_SCANCODE_UNKNOWN),
251
+ ENTRY(SDL_SCANCODE_KP_PERCENT, RDP_SCANCODE_UNKNOWN),
252
+ ENTRY(SDL_SCANCODE_KP_LESS, RDP_SCANCODE_UNKNOWN),
253
+ ENTRY(SDL_SCANCODE_KP_GREATER, RDP_SCANCODE_UNKNOWN),
254
+ ENTRY(SDL_SCANCODE_KP_AMPERSAND, RDP_SCANCODE_UNKNOWN),
255
+ ENTRY(SDL_SCANCODE_KP_DBLAMPERSAND, RDP_SCANCODE_UNKNOWN),
256
+ ENTRY(SDL_SCANCODE_KP_VERTICALBAR, RDP_SCANCODE_UNKNOWN),
257
+ ENTRY(SDL_SCANCODE_KP_DBLVERTICALBAR, RDP_SCANCODE_UNKNOWN),
258
+ ENTRY(SDL_SCANCODE_KP_COLON, RDP_SCANCODE_UNKNOWN),
259
+ ENTRY(SDL_SCANCODE_KP_HASH, RDP_SCANCODE_UNKNOWN),
260
+ ENTRY(SDL_SCANCODE_KP_SPACE, RDP_SCANCODE_UNKNOWN),
261
+ ENTRY(SDL_SCANCODE_KP_AT, RDP_SCANCODE_UNKNOWN),
262
+ ENTRY(SDL_SCANCODE_KP_EXCLAM, RDP_SCANCODE_UNKNOWN),
263
+ ENTRY(SDL_SCANCODE_KP_MEMSTORE, RDP_SCANCODE_UNKNOWN),
264
+ ENTRY(SDL_SCANCODE_KP_MEMRECALL, RDP_SCANCODE_UNKNOWN),
265
+ ENTRY(SDL_SCANCODE_KP_MEMCLEAR, RDP_SCANCODE_UNKNOWN),
266
+ ENTRY(SDL_SCANCODE_KP_MEMADD, RDP_SCANCODE_UNKNOWN),
267
+ ENTRY(SDL_SCANCODE_KP_MEMSUBTRACT, RDP_SCANCODE_UNKNOWN),
268
+ ENTRY(SDL_SCANCODE_KP_MEMMULTIPLY, RDP_SCANCODE_UNKNOWN),
269
+ ENTRY(SDL_SCANCODE_KP_MEMDIVIDE, RDP_SCANCODE_UNKNOWN),
270
+ ENTRY(SDL_SCANCODE_KP_PLUSMINUS, RDP_SCANCODE_UNKNOWN),
271
+ ENTRY(SDL_SCANCODE_KP_CLEAR, RDP_SCANCODE_UNKNOWN),
272
+ ENTRY(SDL_SCANCODE_KP_CLEARENTRY, RDP_SCANCODE_UNKNOWN),
273
+ ENTRY(SDL_SCANCODE_KP_BINARY, RDP_SCANCODE_UNKNOWN),
274
+ ENTRY(SDL_SCANCODE_KP_OCTAL, RDP_SCANCODE_UNKNOWN),
275
+ ENTRY(SDL_SCANCODE_KP_DECIMAL, RDP_SCANCODE_UNKNOWN),
276
+ ENTRY(SDL_SCANCODE_KP_HEXADECIMAL, RDP_SCANCODE_UNKNOWN),
277
+ ENTRY(SDL_SCANCODE_AC_REFRESH, RDP_SCANCODE_UNKNOWN),
278
+ ENTRY(SDL_SCANCODE_AC_BOOKMARKS, RDP_SCANCODE_UNKNOWN),
279
+ ENTRY(SDL_SCANCODE_MEDIA_EJECT, RDP_SCANCODE_UNKNOWN),
280
+ ENTRY(SDL_SCANCODE_MEDIA_REWIND, RDP_SCANCODE_UNKNOWN),
281
+ ENTRY(SDL_SCANCODE_MEDIA_FAST_FORWARD, RDP_SCANCODE_UNKNOWN)
282
+ };
283
+
284
+ static UINT32 sdl_get_kbd_flags()
285
+ {
286
+ UINT32 flags = 0;
287
+
288
+ SDL_Keymod mod = SDL_GetModState();
289
+ if ((mod & SDL_KMOD_NUM) != 0)
290
+ flags |= KBD_SYNC_NUM_LOCK;
291
+ if ((mod & SDL_KMOD_CAPS) != 0)
292
+ flags |= KBD_SYNC_CAPS_LOCK;
293
+ if ((mod & SDL_KMOD_SCROLL) != 0)
294
+ flags |= KBD_SYNC_SCROLL_LOCK;
295
+
296
+ // TODO: KBD_SYNC_KANA_LOCK
297
+
298
+ return flags;
299
+ }
300
+
301
+ BOOL sdlInput::keyboard_sync_state()
302
+ {
303
+ const UINT32 syncFlags = sdl_get_kbd_flags();
304
+ return freerdp_input_send_synchronize_event(_sdl->context()->input, syncFlags);
305
+ }
306
+
307
+ BOOL sdlInput::keyboard_focus_in()
308
+ {
309
+ auto input = _sdl->context()->input;
310
+ WINPR_ASSERT(input);
311
+
312
+ auto syncFlags = sdl_get_kbd_flags();
313
+ freerdp_input_send_focus_in_event(input, WINPR_ASSERTING_INT_CAST(uint16_t, syncFlags));
314
+
315
+ /* finish with a mouse pointer position like mstsc.exe if required */
316
+ #if 0
317
+ if (xfc->remote_app)
318
+ return;
319
+
320
+ if (XQueryPointer(xfc->display, xfc->window->handle, &w, &w, &d, &d, &x, &y, &state))
321
+ {
322
+ if ((x >= 0) && (x < xfc->window->width) && (y >= 0) && (y < xfc->window->height))
323
+ {
324
+ xf_event_adjust_coordinates(xfc, &x, &y);
325
+ freerdp_client_send_button_event(&xfc->common, FALSE, PTR_FLAGS_MOVE, x, y);
326
+ }
327
+ }
328
+ #endif
329
+ return TRUE;
330
+ }
331
+
332
+ /* This function is called to update the keyboard indicator LED */
333
+ BOOL sdlInput::keyboard_set_indicators(rdpContext* context, UINT16 led_flags)
334
+ {
335
+ WINPR_UNUSED(context);
336
+
337
+ int state = SDL_KMOD_NONE;
338
+
339
+ if ((led_flags & KBD_SYNC_NUM_LOCK) != 0)
340
+ state |= SDL_KMOD_NUM;
341
+ if ((led_flags & KBD_SYNC_CAPS_LOCK) != 0)
342
+ state |= SDL_KMOD_CAPS;
343
+ if ((led_flags & KBD_SYNC_SCROLL_LOCK) != 0)
344
+ state |= SDL_KMOD_SCROLL;
345
+
346
+ // TODO: KBD_SYNC_KANA_LOCK
347
+
348
+ SDL_SetModState(static_cast<SDL_Keymod>(state));
349
+
350
+ return TRUE;
351
+ }
352
+
353
+ /* This function is called to set the IME state */
354
+ BOOL sdlInput::keyboard_set_ime_status(rdpContext* context, UINT16 imeId, UINT32 imeState,
355
+ UINT32 imeConvMode)
356
+ {
357
+ if (!context)
358
+ return FALSE;
359
+
360
+ WLog_WARN(TAG,
361
+ "KeyboardSetImeStatus(unitId=%04" PRIx16 ", imeState=%08" PRIx32
362
+ ", imeConvMode=%08" PRIx32 ") ignored",
363
+ imeId, imeState, imeConvMode);
364
+ return TRUE;
365
+ }
366
+
367
+ uint32_t sdlInput::prefToMask()
368
+ {
369
+ const std::map<std::string, uint32_t> mapping = {
370
+ { "KMOD_LSHIFT", SDL_KMOD_LSHIFT }, { "KMOD_RSHIFT", SDL_KMOD_RSHIFT },
371
+ { "KMOD_LCTRL", SDL_KMOD_LCTRL }, { "KMOD_RCTRL", SDL_KMOD_RCTRL },
372
+ { "KMOD_LALT", SDL_KMOD_LALT }, { "KMOD_RALT", SDL_KMOD_RALT },
373
+ { "KMOD_LGUI", SDL_KMOD_LGUI }, { "KMOD_RGUI", SDL_KMOD_RGUI },
374
+ { "KMOD_NUM", SDL_KMOD_NUM }, { "KMOD_CAPS", SDL_KMOD_CAPS },
375
+ { "KMOD_MODE", SDL_KMOD_MODE }, { "KMOD_SCROLL", SDL_KMOD_SCROLL },
376
+ { "KMOD_CTRL", SDL_KMOD_CTRL }, { "KMOD_SHIFT", SDL_KMOD_SHIFT },
377
+ { "KMOD_ALT", SDL_KMOD_ALT }, { "KMOD_GUI", SDL_KMOD_GUI }
378
+ };
379
+ uint32_t mod = SDL_KMOD_NONE;
380
+ for (const auto& val : SdlPref::instance()->get_array("SDL_KeyModMask", { "KMOD_RSHIFT" }))
381
+ {
382
+ auto it = mapping.find(val);
383
+ if (it != mapping.end())
384
+ {
385
+ mod |= it->second;
386
+ }
387
+ }
388
+ return mod;
389
+ }
390
+
391
+ static Uint32 sdl_scancode_val(const char* scancodeName)
392
+ {
393
+ for (const auto& cur : map)
394
+ {
395
+ if (strcmp(cur.sdl_name, scancodeName) == 0)
396
+ return cur.sdl;
397
+ }
398
+
399
+ return SDL_SCANCODE_UNKNOWN;
400
+ }
401
+
402
+ static UINT32 sdl_scancode_to_rdp(Uint32 scancode)
403
+ {
404
+ UINT32 rdp = RDP_SCANCODE_UNKNOWN;
405
+
406
+ for (const auto& cur : map)
407
+ {
408
+ if (cur.sdl == scancode)
409
+ {
410
+ rdp = cur.rdp;
411
+ break;
412
+ }
413
+ }
414
+
415
+ #if defined(WITH_DEBUG_SDL_KBD_EVENTS)
416
+ auto code = static_cast<SDL_Scancode>(scancode);
417
+ WLog_DBG(TAG, "got %s [%s] -> [%s]", SDL_GetScancodeName(code), sdl_scancode_name(scancode),
418
+ sdl_rdp_scancode_name(rdp));
419
+ #endif
420
+ return rdp;
421
+ }
422
+
423
+ uint32_t sdlInput::prefKeyValue(const std::string& key, uint32_t fallback)
424
+ {
425
+ auto item = SdlPref::instance()->get_string(key);
426
+ if (item.empty())
427
+ return fallback;
428
+ auto val = sdl_scancode_val(item.c_str());
429
+ if (val == SDL_SCANCODE_UNKNOWN)
430
+ return fallback;
431
+ return val;
432
+ }
433
+
434
+ std::list<std::string> sdlInput::tokenize(const std::string& data, const std::string& delimiter)
435
+ {
436
+ size_t lastpos = 0;
437
+ size_t pos = 0;
438
+ std::list<std::string> list;
439
+ while ((pos = data.find(delimiter, lastpos)) != std::string::npos)
440
+ {
441
+ auto token = data.substr(lastpos, pos);
442
+ lastpos = pos + 1;
443
+ list.push_back(std::move(token));
444
+ }
445
+ auto token = data.substr(lastpos);
446
+ list.push_back(std::move(token));
447
+ return list;
448
+ }
449
+
450
+ bool sdlInput::extract(const std::string& token, uint32_t& key, uint32_t& value)
451
+ {
452
+ return freerdp_extract_key_value(token.c_str(), &key, &value);
453
+ }
454
+
455
+ BOOL sdlInput::keyboard_handle_event(const SDL_KeyboardEvent* ev)
456
+ {
457
+ WINPR_ASSERT(ev);
458
+ const UINT32 rdp_scancode = sdl_scancode_to_rdp(ev->scancode);
459
+ const SDL_Keymod mods = SDL_GetModState();
460
+
461
+ if ((mods & _hotkeyModmask) == _hotkeyModmask)
462
+ {
463
+ if (ev->type == SDL_EVENT_KEY_DOWN)
464
+ {
465
+ if (ev->scancode == _hotkeyFullscreen)
466
+ {
467
+ _sdl->update_fullscreen(!_sdl->fullscreen);
468
+ return TRUE;
469
+ }
470
+ if (ev->scancode == _hotkeyResizable)
471
+ {
472
+ _sdl->update_resizeable(!_sdl->resizeable);
473
+ return TRUE;
474
+ }
475
+
476
+ if (ev->scancode == _hotkeyGrab)
477
+ {
478
+ _sdl->grab_kbd_enabled = !_sdl->grab_kbd_enabled;
479
+ keyboard_grab(ev->windowID, _sdl->grab_kbd);
480
+ return TRUE;
481
+ }
482
+ if (ev->scancode == _hotkeyDisconnect)
483
+ {
484
+ freerdp_abort_connect_context(_sdl->context());
485
+ return TRUE;
486
+ }
487
+ if (ev->scancode == _hotkeyMinimize)
488
+ {
489
+ _sdl->update_minimize();
490
+ return TRUE;
491
+ }
492
+ }
493
+ }
494
+
495
+ auto scancode = freerdp_keyboard_remap_key(_remapTable, rdp_scancode);
496
+ return freerdp_input_send_keyboard_event_ex(
497
+ _sdl->context()->input, ev->type == SDL_EVENT_KEY_DOWN, ev->repeat, scancode);
498
+ }
499
+
500
+ BOOL sdlInput::keyboard_grab(Uint32 windowID, bool enable)
501
+ {
502
+ auto it = _sdl->windows.find(windowID);
503
+ if (it == _sdl->windows.end())
504
+ return FALSE;
505
+ auto status = enable && _sdl->grab_kbd_enabled;
506
+ _sdl->grab_kbd = status;
507
+ return it->second.grabKeyboard(status);
508
+ }
509
+
510
+ BOOL sdlInput::mouse_focus(Uint32 windowID)
511
+ {
512
+ if (_lastWindowID != windowID)
513
+ {
514
+ _lastWindowID = windowID;
515
+ auto it = _sdl->windows.find(windowID);
516
+ if (it == _sdl->windows.end())
517
+ return FALSE;
518
+
519
+ it->second.raise();
520
+ }
521
+ return TRUE;
522
+ }
523
+
524
+ BOOL sdlInput::mouse_grab(Uint32 windowID, bool enable)
525
+ {
526
+ auto it = _sdl->windows.find(windowID);
527
+ if (it == _sdl->windows.end())
528
+ return FALSE;
529
+ _sdl->grab_mouse = enable;
530
+ return it->second.grabMouse(enable);
531
+ }
532
+
533
+ sdlInput::sdlInput(SdlContext* sdl)
534
+ : _sdl(sdl), _lastWindowID(UINT32_MAX), _hotkeyModmask(prefToMask())
535
+ {
536
+ auto list =
537
+ freerdp_settings_get_string(_sdl->context()->settings, FreeRDP_KeyboardRemappingList);
538
+ _remapTable = freerdp_keyboard_remap_string_to_list(list);
539
+ assert(_remapTable);
540
+ _hotkeyFullscreen = prefKeyValue("SDL_Fullscreen", SDL_SCANCODE_RETURN);
541
+ _hotkeyResizable = prefKeyValue("SDL_Resizeable", SDL_SCANCODE_R);
542
+ _hotkeyGrab = prefKeyValue("SDL_Grab", SDL_SCANCODE_G);
543
+ _hotkeyDisconnect = prefKeyValue("SDL_Disconnect", SDL_SCANCODE_D);
544
+ _hotkeyMinimize = prefKeyValue("SDL_Minimize", SDL_SCANCODE_M);
545
+ }
546
+
547
+ sdlInput::~sdlInput()
548
+ {
549
+ freerdp_keyboard_remap_free(_remapTable);
550
+ }
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_kbd.hpp ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * SDL Client keyboard helper
4
+ *
5
+ * Copyright 2022 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #pragma once
21
+
22
+ #include <string>
23
+ #include <map>
24
+ #include <list>
25
+ #include <atomic>
26
+
27
+ #include <winpr/wtypes.h>
28
+ #include <freerdp/freerdp.h>
29
+ #include <freerdp/locale/keyboard.h>
30
+ #include <SDL3/SDL.h>
31
+
32
+ #include "sdl_types.hpp"
33
+
34
+ class sdlInput
35
+ {
36
+ public:
37
+ explicit sdlInput(SdlContext* sdl);
38
+ sdlInput(const sdlInput& other) = delete;
39
+ sdlInput(sdlInput&& other) = delete;
40
+ ~sdlInput();
41
+
42
+ sdlInput& operator=(const sdlInput& other) = delete;
43
+ sdlInput& operator=(sdlInput&& other) = delete;
44
+
45
+ BOOL keyboard_sync_state();
46
+ BOOL keyboard_focus_in();
47
+
48
+ BOOL keyboard_handle_event(const SDL_KeyboardEvent* ev);
49
+
50
+ BOOL keyboard_grab(Uint32 windowID, bool enable);
51
+ BOOL mouse_focus(Uint32 windowID);
52
+ BOOL mouse_grab(Uint32 windowID, bool enable);
53
+
54
+ static BOOL keyboard_set_indicators(rdpContext* context, UINT16 led_flags);
55
+ static BOOL keyboard_set_ime_status(rdpContext* context, UINT16 imeId, UINT32 imeState,
56
+ UINT32 imeConvMode);
57
+
58
+ static uint32_t prefToMask();
59
+ static uint32_t prefKeyValue(const std::string& key, uint32_t fallback = SDL_SCANCODE_UNKNOWN);
60
+
61
+ private:
62
+ static std::list<std::string> tokenize(const std::string& data,
63
+ const std::string& delimiter = ",");
64
+ static bool extract(const std::string& token, uint32_t& key, uint32_t& value);
65
+
66
+ SdlContext* _sdl;
67
+ Uint32 _lastWindowID;
68
+
69
+ // hotkey handling
70
+ uint32_t _hotkeyModmask; // modifier keys mask
71
+ uint32_t _hotkeyFullscreen;
72
+ uint32_t _hotkeyResizable;
73
+ uint32_t _hotkeyGrab;
74
+ uint32_t _hotkeyDisconnect;
75
+ uint32_t _hotkeyMinimize;
76
+ FREERDP_REMAP_TABLE* _remapTable;
77
+ };
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_monitor.cpp ADDED
@@ -0,0 +1,393 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * X11 Monitor Handling
4
+ *
5
+ * Copyright 2011 Marc-Andre Moreau <[email protected]>
6
+ * Copyright 2017 David Fort <[email protected]>
7
+ * Copyright 2018 Kai Harms <[email protected]>
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
+ #include <freerdp/config.h>
23
+
24
+ #include <cstdio>
25
+ #include <cstdlib>
26
+ #include <cstring>
27
+ #include <algorithm>
28
+
29
+ #include <SDL3/SDL.h>
30
+
31
+ #include <winpr/assert.h>
32
+ #include <winpr/crt.h>
33
+
34
+ #include <freerdp/log.h>
35
+
36
+ #define TAG CLIENT_TAG("sdl")
37
+
38
+ #include "sdl_monitor.hpp"
39
+ #include "sdl_freerdp.hpp"
40
+
41
+ typedef struct
42
+ {
43
+ RECTANGLE_16 area;
44
+ RECTANGLE_16 workarea;
45
+ BOOL primary;
46
+ } MONITOR_INFO;
47
+
48
+ typedef struct
49
+ {
50
+ int nmonitors;
51
+ RECTANGLE_16 area;
52
+ RECTANGLE_16 workarea;
53
+ MONITOR_INFO* monitors;
54
+ } VIRTUAL_SCREEN;
55
+
56
+ /* See MSDN Section on Multiple Display Monitors: http://msdn.microsoft.com/en-us/library/dd145071
57
+ */
58
+
59
+ int sdl_list_monitors(SdlContext* sdl)
60
+ {
61
+ SDL_Init(SDL_INIT_VIDEO);
62
+
63
+ int nmonitors = 0;
64
+ auto ids = SDL_GetDisplays(&nmonitors);
65
+
66
+ printf("listing %d monitors:\n", nmonitors);
67
+ for (int i = 0; i < nmonitors; i++)
68
+ {
69
+ SDL_Rect rect = {};
70
+ auto id = ids[i];
71
+ const auto brc = SDL_GetDisplayBounds(id, &rect);
72
+ const char* name = SDL_GetDisplayName(id);
73
+
74
+ if (!brc)
75
+ continue;
76
+ printf(" %s [%u] [%s] %dx%d\t+%d+%d\n", (i == 0) ? "*" : " ", id, name, rect.w, rect.h,
77
+ rect.x, rect.y);
78
+ }
79
+ SDL_free(ids);
80
+ SDL_Quit();
81
+ return 0;
82
+ }
83
+
84
+ static BOOL sdl_apply_max_size(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight)
85
+ {
86
+ WINPR_ASSERT(sdl);
87
+ WINPR_ASSERT(pMaxWidth);
88
+ WINPR_ASSERT(pMaxHeight);
89
+
90
+ auto settings = sdl->context()->settings;
91
+ WINPR_ASSERT(settings);
92
+
93
+ *pMaxWidth = 0;
94
+ *pMaxHeight = 0;
95
+
96
+ for (size_t x = 0; x < freerdp_settings_get_uint32(settings, FreeRDP_MonitorCount); x++)
97
+ {
98
+ auto monitor = static_cast<const rdpMonitor*>(
99
+ freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x));
100
+
101
+ if (freerdp_settings_get_bool(settings, FreeRDP_Fullscreen))
102
+ {
103
+ *pMaxWidth = WINPR_ASSERTING_INT_CAST(uint32_t, monitor->width);
104
+ *pMaxHeight = WINPR_ASSERTING_INT_CAST(uint32_t, monitor->height);
105
+ }
106
+ else if (freerdp_settings_get_bool(settings, FreeRDP_Workarea))
107
+ {
108
+ SDL_Rect rect = {};
109
+ SDL_GetDisplayUsableBounds(monitor->orig_screen, &rect);
110
+ *pMaxWidth = WINPR_ASSERTING_INT_CAST(uint32_t, rect.w);
111
+ *pMaxHeight = WINPR_ASSERTING_INT_CAST(uint32_t, rect.h);
112
+ }
113
+ else if (freerdp_settings_get_uint32(settings, FreeRDP_PercentScreen) > 0)
114
+ {
115
+ SDL_Rect rect = {};
116
+ SDL_GetDisplayUsableBounds(monitor->orig_screen, &rect);
117
+
118
+ *pMaxWidth = WINPR_ASSERTING_INT_CAST(uint32_t, rect.w);
119
+ *pMaxHeight = WINPR_ASSERTING_INT_CAST(uint32_t, rect.h);
120
+
121
+ if (freerdp_settings_get_bool(settings, FreeRDP_PercentScreenUseWidth))
122
+ *pMaxWidth = (WINPR_ASSERTING_INT_CAST(uint32_t, rect.w) *
123
+ freerdp_settings_get_uint32(settings, FreeRDP_PercentScreen)) /
124
+ 100;
125
+
126
+ if (freerdp_settings_get_bool(settings, FreeRDP_PercentScreenUseHeight))
127
+ *pMaxHeight = (WINPR_ASSERTING_INT_CAST(uint32_t, rect.h) *
128
+ freerdp_settings_get_uint32(settings, FreeRDP_PercentScreen)) /
129
+ 100;
130
+ }
131
+ else if (freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) &&
132
+ freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight))
133
+ {
134
+ *pMaxWidth = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
135
+ *pMaxHeight = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
136
+ }
137
+ }
138
+ return TRUE;
139
+ }
140
+
141
+ static UINT32 sdl_orientaion_to_rdp(SDL_DisplayOrientation orientation)
142
+ {
143
+ switch (orientation)
144
+ {
145
+ case SDL_ORIENTATION_LANDSCAPE:
146
+ return ORIENTATION_LANDSCAPE;
147
+ case SDL_ORIENTATION_LANDSCAPE_FLIPPED:
148
+ return ORIENTATION_LANDSCAPE_FLIPPED;
149
+ case SDL_ORIENTATION_PORTRAIT_FLIPPED:
150
+ return ORIENTATION_PORTRAIT_FLIPPED;
151
+ case SDL_ORIENTATION_PORTRAIT:
152
+ default:
153
+ return ORIENTATION_PORTRAIT;
154
+ }
155
+ }
156
+
157
+ static Uint32 scale(Uint32 val, float scale)
158
+ {
159
+ const auto dval = static_cast<float>(val);
160
+ const auto sval = dval / scale;
161
+ return static_cast<Uint32>(sval);
162
+ }
163
+
164
+ static BOOL sdl_apply_display_properties(SdlContext* sdl)
165
+ {
166
+ WINPR_ASSERT(sdl);
167
+
168
+ rdpSettings* settings = sdl->context()->settings;
169
+ WINPR_ASSERT(settings);
170
+ if (!freerdp_settings_get_bool(settings, FreeRDP_Fullscreen) &&
171
+ !freerdp_settings_get_bool(settings, FreeRDP_UseMultimon))
172
+ return TRUE;
173
+
174
+ const UINT32 numIds = freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds);
175
+ std::vector<rdpMonitor> monitors;
176
+
177
+ for (UINT32 x = 0; x < numIds; x++)
178
+ {
179
+ auto id = static_cast<const int*>(
180
+ freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorIds, x));
181
+ WINPR_ASSERT(id);
182
+
183
+ float dpi = SDL_GetDisplayContentScale(WINPR_ASSERTING_INT_CAST(uint32_t, *id));
184
+ float hdpi = dpi;
185
+ float vdpi = dpi;
186
+ SDL_Rect rect = {};
187
+
188
+ if (!SDL_GetDisplayBounds(WINPR_ASSERTING_INT_CAST(uint32_t, *id), &rect))
189
+ return FALSE;
190
+
191
+ WINPR_ASSERT(rect.w > 0);
192
+ WINPR_ASSERT(rect.h > 0);
193
+
194
+ bool highDpi = dpi > 100;
195
+
196
+ if (highDpi)
197
+ {
198
+ // HighDPI is problematic with SDL: We can only get native resolution by creating a
199
+ // window. Work around this by checking the supported resolutions (and keep maximum)
200
+ // Also scale the DPI
201
+ const SDL_Rect scaleRect = rect;
202
+ int count = 0;
203
+ auto modes = SDL_GetFullscreenDisplayModes(x, &count);
204
+ for (int i = 0; i < count; i++)
205
+ {
206
+ auto mode = modes[i];
207
+ if (!mode)
208
+ break;
209
+
210
+ if (mode->w > rect.w)
211
+ {
212
+ rect.w = mode->w;
213
+ rect.h = mode->h;
214
+ }
215
+ else if (mode->w == rect.w)
216
+ {
217
+ if (mode->h > rect.h)
218
+ {
219
+ rect.w = mode->w;
220
+ rect.h = mode->h;
221
+ }
222
+ }
223
+ }
224
+ SDL_free(static_cast<void*>(modes));
225
+
226
+ const float dw = 1.0f * static_cast<float>(rect.w) / static_cast<float>(scaleRect.w);
227
+ const float dh = 1.0f * static_cast<float>(rect.h) / static_cast<float>(scaleRect.h);
228
+ hdpi /= dw;
229
+ vdpi /= dh;
230
+ }
231
+
232
+ const SDL_DisplayOrientation orientation =
233
+ SDL_GetCurrentDisplayOrientation(WINPR_ASSERTING_INT_CAST(uint32_t, *id));
234
+ const UINT32 rdp_orientation = sdl_orientaion_to_rdp(orientation);
235
+
236
+ rdpMonitor monitor = {};
237
+
238
+ /* windows uses 96 dpi as 'default' and the scale factors are in percent. */
239
+ const auto factor = dpi / 96.0f * 100.0f;
240
+ monitor.orig_screen = x;
241
+ monitor.x = rect.x;
242
+ monitor.y = rect.y;
243
+ monitor.width = rect.w;
244
+ monitor.height = rect.h;
245
+ monitor.is_primary = x == 0;
246
+ monitor.attributes.desktopScaleFactor = static_cast<UINT32>(factor);
247
+ monitor.attributes.deviceScaleFactor = 100;
248
+ monitor.attributes.orientation = rdp_orientation;
249
+ monitor.attributes.physicalWidth = scale(WINPR_ASSERTING_INT_CAST(uint32_t, rect.w), hdpi);
250
+ monitor.attributes.physicalHeight = scale(WINPR_ASSERTING_INT_CAST(uint32_t, rect.h), vdpi);
251
+ monitors.emplace_back(monitor);
252
+ }
253
+ return freerdp_settings_set_monitor_def_array_sorted(settings, monitors.data(),
254
+ monitors.size());
255
+ }
256
+
257
+ static BOOL sdl_detect_single_window(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight)
258
+ {
259
+ WINPR_ASSERT(sdl);
260
+ WINPR_ASSERT(pMaxWidth);
261
+ WINPR_ASSERT(pMaxHeight);
262
+
263
+ rdpSettings* settings = sdl->context()->settings;
264
+ WINPR_ASSERT(settings);
265
+
266
+ if ((!freerdp_settings_get_bool(settings, FreeRDP_UseMultimon) &&
267
+ !freerdp_settings_get_bool(settings, FreeRDP_SpanMonitors)) ||
268
+ (freerdp_settings_get_bool(settings, FreeRDP_Workarea) &&
269
+ !freerdp_settings_get_bool(settings, FreeRDP_RemoteApplicationMode)))
270
+ {
271
+ /* If no monitors were specified on the command-line then set the current monitor as active
272
+ */
273
+ if (freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds) == 0)
274
+ {
275
+ const size_t id =
276
+ (!sdl->windows.empty())
277
+ ? WINPR_ASSERTING_INT_CAST(size_t, sdl->windows.begin()->second.displayIndex())
278
+ : 0;
279
+ if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorIds, &id, 1))
280
+ return FALSE;
281
+ }
282
+ else
283
+ {
284
+
285
+ /* Always sets number of monitors from command-line to just 1.
286
+ * If the monitor is invalid then we will default back to current monitor
287
+ * later as a fallback. So, there is no need to validate command-line entry here.
288
+ */
289
+ if (!freerdp_settings_set_uint32(settings, FreeRDP_NumMonitorIds, 1))
290
+ return FALSE;
291
+ }
292
+
293
+ // TODO: Fill monitor struct
294
+ if (!sdl_apply_display_properties(sdl))
295
+ return FALSE;
296
+ return sdl_apply_max_size(sdl, pMaxWidth, pMaxHeight);
297
+ }
298
+ return TRUE;
299
+ }
300
+
301
+ BOOL sdl_detect_monitors(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight)
302
+ {
303
+ WINPR_ASSERT(sdl);
304
+ WINPR_ASSERT(pMaxWidth);
305
+ WINPR_ASSERT(pMaxHeight);
306
+
307
+ rdpSettings* settings = sdl->context()->settings;
308
+ WINPR_ASSERT(settings);
309
+
310
+ std::vector<SDL_DisplayID> ids;
311
+ {
312
+ int numDisplays = 0;
313
+ auto sids = SDL_GetDisplays(&numDisplays);
314
+ if (sids && (numDisplays > 0))
315
+ ids = std::vector<SDL_DisplayID>(sids, sids + numDisplays);
316
+ SDL_free(sids);
317
+ if (numDisplays < 0)
318
+ return FALSE;
319
+ }
320
+
321
+ auto nr = freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds);
322
+ if (nr == 0)
323
+ {
324
+ if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorIds, nullptr, ids.size()))
325
+ return FALSE;
326
+
327
+ for (size_t x = 0; x < ids.size(); x++)
328
+ {
329
+ auto id = ids[x];
330
+ if (!freerdp_settings_set_pointer_array(settings, FreeRDP_MonitorIds, x, &id))
331
+ return FALSE;
332
+ }
333
+ }
334
+ else
335
+ {
336
+ /* There were more IDs supplied than there are monitors */
337
+ if (nr > ids.size())
338
+ {
339
+ WLog_ERR(TAG,
340
+ "Found %" PRIu32 " monitor IDs, but only have %" PRIuz " monitors connected",
341
+ nr, ids.size());
342
+ return FALSE;
343
+ }
344
+
345
+ std::vector<UINT32> used;
346
+ for (size_t x = 0; x < nr; x++)
347
+ {
348
+ auto cur = static_cast<const UINT32*>(
349
+ freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorIds, x));
350
+ WINPR_ASSERT(cur);
351
+
352
+ auto id = *cur;
353
+
354
+ /* the ID is no valid monitor index */
355
+ if (std::find(ids.begin(), ids.end(), id) == ids.end())
356
+ {
357
+ WLog_ERR(TAG, "Supplied monitor ID[%" PRIuz "]=%" PRIu32 " is invalid", x, id);
358
+ return FALSE;
359
+ }
360
+
361
+ /* The ID is already taken */
362
+ if (std::find(used.begin(), used.end(), id) != used.end())
363
+ {
364
+ WLog_ERR(TAG, "Duplicate monitor ID[%" PRIuz "]=%" PRIu32 " detected", x, id);
365
+ return FALSE;
366
+ }
367
+ used.push_back(*cur);
368
+ }
369
+ }
370
+
371
+ if (!sdl_apply_display_properties(sdl))
372
+ return FALSE;
373
+
374
+ return sdl_detect_single_window(sdl, pMaxWidth, pMaxHeight);
375
+ }
376
+
377
+ INT64 sdl_monitor_id_for_index(SdlContext* sdl, UINT32 index)
378
+ {
379
+ WINPR_ASSERT(sdl);
380
+ auto settings = sdl->context()->settings;
381
+
382
+ auto nr = freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds);
383
+ if (nr == 0)
384
+ return index;
385
+
386
+ if (nr <= index)
387
+ return -1;
388
+
389
+ auto cur = static_cast<const UINT32*>(
390
+ freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorIds, index));
391
+ WINPR_ASSERT(cur);
392
+ return *cur;
393
+ }
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_monitor.hpp ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * SDL Monitor Handling
4
+ *
5
+ * Copyright 2023 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #pragma once
21
+
22
+ #include <freerdp/api.h>
23
+ #include <freerdp/freerdp.h>
24
+
25
+ #include "sdl_types.hpp"
26
+
27
+ int sdl_list_monitors(SdlContext* sdl);
28
+ BOOL sdl_detect_monitors(SdlContext* sdl, UINT32* pMaxWidth, UINT32* ppMaxHeight);
29
+ INT64 sdl_monitor_id_for_index(SdlContext* sdl, UINT32 index);
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_pointer.cpp ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * Wayland Mouse Pointer
4
+ *
5
+ * Copyright 2023 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #include <freerdp/config.h>
21
+
22
+ #include <freerdp/gdi/gdi.h>
23
+
24
+ #include "sdl_pointer.hpp"
25
+ #include "sdl_freerdp.hpp"
26
+ #include "sdl_touch.hpp"
27
+ #include "sdl_utils.hpp"
28
+
29
+ #include <SDL3/SDL_mouse.h>
30
+
31
+ typedef struct
32
+ {
33
+ rdpPointer pointer;
34
+ SDL_Cursor* cursor;
35
+ SDL_Surface* image;
36
+ size_t size;
37
+ void* data;
38
+ } sdlPointer;
39
+
40
+ static BOOL sdl_Pointer_New(rdpContext* context, rdpPointer* pointer)
41
+ {
42
+ auto ptr = reinterpret_cast<sdlPointer*>(pointer);
43
+
44
+ WINPR_ASSERT(context);
45
+ if (!ptr)
46
+ return FALSE;
47
+
48
+ rdpGdi* gdi = context->gdi;
49
+ WINPR_ASSERT(gdi);
50
+
51
+ ptr->size = 4ull * pointer->width * pointer->height;
52
+ ptr->data = winpr_aligned_malloc(ptr->size, 16);
53
+
54
+ if (!ptr->data)
55
+ return FALSE;
56
+
57
+ auto data = static_cast<BYTE*>(ptr->data);
58
+ if (!freerdp_image_copy_from_pointer_data(
59
+ data, gdi->dstFormat, 0, 0, 0, pointer->width, pointer->height, pointer->xorMaskData,
60
+ pointer->lengthXorMask, pointer->andMaskData, pointer->lengthAndMask, pointer->xorBpp,
61
+ &context->gdi->palette))
62
+ {
63
+ winpr_aligned_free(ptr->data);
64
+ return FALSE;
65
+ }
66
+
67
+ return TRUE;
68
+ }
69
+
70
+ static void sdl_Pointer_Clear(sdlPointer* ptr)
71
+ {
72
+ WINPR_ASSERT(ptr);
73
+ SDL_DestroyCursor(ptr->cursor);
74
+ SDL_DestroySurface(ptr->image);
75
+ ptr->cursor = nullptr;
76
+ ptr->image = nullptr;
77
+ }
78
+
79
+ static void sdl_Pointer_Free(rdpContext* context, rdpPointer* pointer)
80
+ {
81
+ auto ptr = reinterpret_cast<sdlPointer*>(pointer);
82
+ WINPR_UNUSED(context);
83
+
84
+ if (ptr)
85
+ {
86
+ sdl_Pointer_Clear(ptr);
87
+ winpr_aligned_free(ptr->data);
88
+ ptr->data = nullptr;
89
+ }
90
+ }
91
+
92
+ static BOOL sdl_Pointer_SetDefault(rdpContext* context)
93
+ {
94
+ WINPR_UNUSED(context);
95
+
96
+ return sdl_push_user_event(SDL_EVENT_USER_POINTER_DEFAULT);
97
+ }
98
+
99
+ static BOOL sdl_Pointer_Set(rdpContext* context, rdpPointer* pointer)
100
+ {
101
+ auto sdl = get_context(context);
102
+
103
+ return sdl_push_user_event(SDL_EVENT_USER_POINTER_SET, pointer, sdl);
104
+ }
105
+
106
+ BOOL sdl_Pointer_Set_Process(SDL_UserEvent* uptr)
107
+ {
108
+ INT32 w = 0;
109
+ INT32 h = 0;
110
+ INT32 x = 0;
111
+ INT32 y = 0;
112
+ INT32 sw = 0;
113
+ INT32 sh = 0;
114
+
115
+ WINPR_ASSERT(uptr);
116
+
117
+ auto sdl = static_cast<SdlContext*>(uptr->data2);
118
+ WINPR_ASSERT(sdl);
119
+
120
+ auto context = sdl->context();
121
+ auto ptr = static_cast<sdlPointer*>(uptr->data1);
122
+ WINPR_ASSERT(ptr);
123
+
124
+ rdpPointer* pointer = &ptr->pointer;
125
+
126
+ rdpGdi* gdi = context->gdi;
127
+ WINPR_ASSERT(gdi);
128
+
129
+ x = static_cast<INT32>(pointer->xPos);
130
+ y = static_cast<INT32>(pointer->yPos);
131
+ sw = w = static_cast<INT32>(pointer->width);
132
+ sh = h = static_cast<INT32>(pointer->height);
133
+
134
+ SDL_Window* window = SDL_GetMouseFocus();
135
+ if (!window)
136
+ return sdl_Pointer_SetDefault(context);
137
+
138
+ const Uint32 id = SDL_GetWindowID(window);
139
+
140
+ if (!sdl_scale_coordinates(sdl, id, &x, &y, FALSE, FALSE) ||
141
+ !sdl_scale_coordinates(sdl, id, &sw, &sh, FALSE, FALSE))
142
+ return FALSE;
143
+
144
+ sdl_Pointer_Clear(ptr);
145
+
146
+ ptr->image = SDL_CreateSurface(sw, sh, sdl->sdl_pixel_format);
147
+ if (!ptr->image)
148
+ return FALSE;
149
+
150
+ SDL_LockSurface(ptr->image);
151
+ auto pixels = static_cast<BYTE*>(ptr->image->pixels);
152
+ auto data = static_cast<const BYTE*>(ptr->data);
153
+ const BOOL rc = freerdp_image_scale(
154
+ pixels, gdi->dstFormat, static_cast<UINT32>(ptr->image->pitch), 0, 0,
155
+ static_cast<UINT32>(ptr->image->w), static_cast<UINT32>(ptr->image->h), data,
156
+ gdi->dstFormat, 0, 0, 0, static_cast<UINT32>(w), static_cast<UINT32>(h));
157
+ SDL_UnlockSurface(ptr->image);
158
+ if (!rc)
159
+ return FALSE;
160
+
161
+ ptr->cursor = SDL_CreateColorCursor(ptr->image, x, y);
162
+ if (!ptr->cursor)
163
+ return FALSE;
164
+
165
+ SDL_SetCursor(ptr->cursor);
166
+ SDL_ShowCursor();
167
+ return TRUE;
168
+ }
169
+
170
+ static BOOL sdl_Pointer_SetNull(rdpContext* context)
171
+ {
172
+ WINPR_UNUSED(context);
173
+
174
+ return sdl_push_user_event(SDL_EVENT_USER_POINTER_NULL);
175
+ }
176
+
177
+ static BOOL sdl_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y)
178
+ {
179
+ WINPR_UNUSED(context);
180
+ WINPR_ASSERT(context);
181
+
182
+ return sdl_push_user_event(SDL_EVENT_USER_POINTER_POSITION, x, y);
183
+ }
184
+
185
+ BOOL sdl_register_pointer(rdpGraphics* graphics)
186
+ {
187
+ const rdpPointer pointer = { sizeof(sdlPointer),
188
+ sdl_Pointer_New,
189
+ sdl_Pointer_Free,
190
+ sdl_Pointer_Set,
191
+ sdl_Pointer_SetNull,
192
+ sdl_Pointer_SetDefault,
193
+ sdl_Pointer_SetPosition,
194
+ {},
195
+ 0,
196
+ 0,
197
+ 0,
198
+ 0,
199
+ 0,
200
+ 0,
201
+ 0,
202
+ nullptr,
203
+ nullptr,
204
+ {} };
205
+ graphics_register_pointer(graphics, &pointer);
206
+ return TRUE;
207
+ }
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_pointer.hpp ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * SDL Mouse Pointer
4
+ *
5
+ * Copyright 2023 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #pragma once
21
+
22
+ #include <SDL3/SDL.h>
23
+ #include <freerdp/graphics.h>
24
+
25
+ BOOL sdl_register_pointer(rdpGraphics* graphics);
26
+
27
+ BOOL sdl_Pointer_Set_Process(SDL_UserEvent* uptr);
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_touch.cpp ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP SDL touch/mouse input
4
+ *
5
+ * Copyright 2022 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #include <freerdp/config.h>
21
+
22
+ #include "sdl_touch.hpp"
23
+ #include "sdl_freerdp.hpp"
24
+
25
+ #include <winpr/wtypes.h>
26
+ #include <winpr/assert.h>
27
+
28
+ #include <freerdp/freerdp.h>
29
+ #include <freerdp/gdi/gdi.h>
30
+
31
+ #include <SDL3/SDL.h>
32
+
33
+ BOOL sdl_scale_coordinates(SdlContext* sdl, Uint32 windowId, INT32* px, INT32* py,
34
+ BOOL fromLocalToRDP, BOOL applyOffset)
35
+ {
36
+ rdpGdi* gdi = nullptr;
37
+ double sx = 1.0;
38
+ double sy = 1.0;
39
+
40
+ if (!sdl || !px || !py || !sdl->context()->gdi)
41
+ return FALSE;
42
+
43
+ WINPR_ASSERT(sdl->context()->gdi);
44
+ WINPR_ASSERT(sdl->context()->settings);
45
+
46
+ gdi = sdl->context()->gdi;
47
+
48
+ // TODO: Make this multimonitor ready!
49
+ // TODO: Need to find the primary monitor, get the scale
50
+ // TODO: Need to find the destination monitor, get the scale
51
+ // TODO: All intermediate monitors, get the scale
52
+
53
+ int offset_x = 0;
54
+ int offset_y = 0;
55
+ for (const auto& it : sdl->windows)
56
+ {
57
+ auto& window = it.second;
58
+ const auto id = window.id();
59
+ if (id != windowId)
60
+ {
61
+ continue;
62
+ }
63
+
64
+ auto size = window.rect();
65
+
66
+ sx = size.w / static_cast<double>(gdi->width);
67
+ sy = size.h / static_cast<double>(gdi->height);
68
+ offset_x = window.offsetX();
69
+ offset_y = window.offsetY();
70
+ break;
71
+ }
72
+
73
+ if (freerdp_settings_get_bool(sdl->context()->settings, FreeRDP_SmartSizing))
74
+ {
75
+ if (!fromLocalToRDP)
76
+ {
77
+ *px = static_cast<INT32>(*px * sx);
78
+ *py = static_cast<INT32>(*py * sy);
79
+ }
80
+ else
81
+ {
82
+ *px = static_cast<INT32>(*px / sx);
83
+ *py = static_cast<INT32>(*py / sy);
84
+ }
85
+ }
86
+ else if (applyOffset)
87
+ {
88
+ *px -= offset_x;
89
+ *py -= offset_y;
90
+ }
91
+
92
+ return TRUE;
93
+ }
94
+
95
+ static BOOL sdl_get_touch_scaled(SdlContext* sdl, const SDL_TouchFingerEvent* ev, INT32* px,
96
+ INT32* py, BOOL local)
97
+ {
98
+ Uint32 windowID = 0;
99
+
100
+ WINPR_ASSERT(sdl);
101
+ WINPR_ASSERT(ev);
102
+ WINPR_ASSERT(px);
103
+ WINPR_ASSERT(py);
104
+
105
+ SDL_Window* window = SDL_GetWindowFromID(ev->windowID);
106
+
107
+ if (!window)
108
+ return FALSE;
109
+
110
+ windowID = SDL_GetWindowID(window);
111
+ SDL_Surface* surface = SDL_GetWindowSurface(window);
112
+ if (!surface)
113
+ return FALSE;
114
+
115
+ // TODO: Add the offset of the surface in the global coordinates
116
+ *px = static_cast<INT32>(ev->x * static_cast<float>(surface->w));
117
+ *py = static_cast<INT32>(ev->y * static_cast<float>(surface->h));
118
+ return sdl_scale_coordinates(sdl, windowID, px, py, local, TRUE);
119
+ }
120
+
121
+ static BOOL send_mouse_wheel(SdlContext* sdl, UINT16 flags, INT32 avalue)
122
+ {
123
+ WINPR_ASSERT(sdl);
124
+ if (avalue < 0)
125
+ {
126
+ flags |= PTR_FLAGS_WHEEL_NEGATIVE;
127
+ avalue = -avalue;
128
+ }
129
+
130
+ while (avalue > 0)
131
+ {
132
+ const UINT16 cval = (avalue > 0xFF) ? 0xFF : static_cast<UINT16>(avalue);
133
+ UINT16 cflags = flags | cval;
134
+ /* Convert negative values to 9bit twos complement */
135
+ if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
136
+ cflags = (flags & 0xFF00) | (0x100 - cval);
137
+ if (!freerdp_client_send_wheel_event(sdl->common(), cflags))
138
+ return FALSE;
139
+
140
+ avalue -= cval;
141
+ }
142
+ return TRUE;
143
+ }
144
+
145
+ static UINT32 sdl_scale_pressure(const float pressure)
146
+ {
147
+ const float val = pressure * 0x400; /* [MS-RDPEI] 2.2.3.3.1.1 RDPINPUT_TOUCH_CONTACT */
148
+ if (val < 0.0f)
149
+ return 0;
150
+ if (val > 0x400)
151
+ return 0x400;
152
+ return static_cast<UINT32>(val);
153
+ }
154
+
155
+ BOOL sdl_handle_touch_up(SdlContext* sdl, const SDL_TouchFingerEvent* ev)
156
+ {
157
+ WINPR_ASSERT(sdl);
158
+ WINPR_ASSERT(ev);
159
+
160
+ INT32 x = 0;
161
+ INT32 y = 0;
162
+ if (!sdl_get_touch_scaled(sdl, ev, &x, &y, TRUE))
163
+ return FALSE;
164
+ return freerdp_client_handle_touch(sdl->common(), FREERDP_TOUCH_UP | FREERDP_TOUCH_HAS_PRESSURE,
165
+ static_cast<INT32>(ev->fingerID),
166
+ sdl_scale_pressure(ev->pressure), x, y);
167
+ }
168
+
169
+ BOOL sdl_handle_touch_down(SdlContext* sdl, const SDL_TouchFingerEvent* ev)
170
+ {
171
+ WINPR_ASSERT(sdl);
172
+ WINPR_ASSERT(ev);
173
+
174
+ INT32 x = 0;
175
+ INT32 y = 0;
176
+ if (!sdl_get_touch_scaled(sdl, ev, &x, &y, TRUE))
177
+ return FALSE;
178
+ return freerdp_client_handle_touch(
179
+ sdl->common(), FREERDP_TOUCH_DOWN | FREERDP_TOUCH_HAS_PRESSURE,
180
+ static_cast<INT32>(ev->fingerID), sdl_scale_pressure(ev->pressure), x, y);
181
+ }
182
+
183
+ BOOL sdl_handle_touch_motion(SdlContext* sdl, const SDL_TouchFingerEvent* ev)
184
+ {
185
+ WINPR_ASSERT(sdl);
186
+ WINPR_ASSERT(ev);
187
+
188
+ INT32 x = 0;
189
+ INT32 y = 0;
190
+ if (!sdl_get_touch_scaled(sdl, ev, &x, &y, TRUE))
191
+ return FALSE;
192
+ return freerdp_client_handle_touch(
193
+ sdl->common(), FREERDP_TOUCH_MOTION | FREERDP_TOUCH_HAS_PRESSURE,
194
+ static_cast<INT32>(ev->fingerID), sdl_scale_pressure(ev->pressure), x, y);
195
+ }
196
+
197
+ BOOL sdl_handle_mouse_motion(SdlContext* sdl, const SDL_MouseMotionEvent* ev)
198
+ {
199
+ WINPR_ASSERT(sdl);
200
+ WINPR_ASSERT(ev);
201
+
202
+ sdl->input.mouse_focus(ev->windowID);
203
+ const BOOL relative = freerdp_client_use_relative_mouse_events(sdl->common());
204
+ auto x = static_cast<INT32>(relative ? ev->xrel : ev->x);
205
+ auto y = static_cast<INT32>(relative ? ev->yrel : ev->y);
206
+ sdl_scale_coordinates(sdl, ev->windowID, &x, &y, TRUE, TRUE);
207
+ return freerdp_client_send_button_event(sdl->common(), relative, PTR_FLAGS_MOVE, x, y);
208
+ }
209
+
210
+ BOOL sdl_handle_mouse_wheel(SdlContext* sdl, const SDL_MouseWheelEvent* ev)
211
+ {
212
+ WINPR_ASSERT(sdl);
213
+ WINPR_ASSERT(ev);
214
+
215
+ const BOOL flipped = (ev->direction == SDL_MOUSEWHEEL_FLIPPED);
216
+ const auto x = static_cast<INT32>(ev->x * (flipped ? -1.0f : 1.0f) * 120.0f);
217
+ const auto y = static_cast<INT32>(ev->y * (flipped ? -1.0f : 1.0f) * 120.0f);
218
+ UINT16 flags = 0;
219
+
220
+ if (y != 0)
221
+ {
222
+ flags |= PTR_FLAGS_WHEEL;
223
+ send_mouse_wheel(sdl, flags, y);
224
+ }
225
+
226
+ if (x != 0)
227
+ {
228
+ flags |= PTR_FLAGS_HWHEEL;
229
+ send_mouse_wheel(sdl, flags, x);
230
+ }
231
+ return TRUE;
232
+ }
233
+
234
+ BOOL sdl_handle_mouse_button(SdlContext* sdl, const SDL_MouseButtonEvent* ev)
235
+ {
236
+ UINT16 flags = 0;
237
+ UINT16 xflags = 0;
238
+
239
+ WINPR_ASSERT(sdl);
240
+ WINPR_ASSERT(ev);
241
+
242
+ if (ev->type == SDL_EVENT_MOUSE_BUTTON_DOWN)
243
+ {
244
+ flags |= PTR_FLAGS_DOWN;
245
+ xflags |= PTR_XFLAGS_DOWN;
246
+ }
247
+
248
+ switch (ev->button)
249
+ {
250
+ case 1:
251
+ flags |= PTR_FLAGS_BUTTON1;
252
+ break;
253
+ case 2:
254
+ flags |= PTR_FLAGS_BUTTON3;
255
+ break;
256
+ case 3:
257
+ flags |= PTR_FLAGS_BUTTON2;
258
+ break;
259
+ case 4:
260
+ xflags |= PTR_XFLAGS_BUTTON1;
261
+ break;
262
+ case 5:
263
+ xflags |= PTR_XFLAGS_BUTTON2;
264
+ break;
265
+ default:
266
+ break;
267
+ }
268
+
269
+ const BOOL relative = freerdp_client_use_relative_mouse_events(sdl->common());
270
+ auto x = static_cast<INT32>(relative ? 0 : ev->x);
271
+ auto y = static_cast<INT32>(relative ? 0 : ev->y);
272
+ sdl_scale_coordinates(sdl, ev->windowID, &x, &y, TRUE, TRUE);
273
+ if ((flags & (~PTR_FLAGS_DOWN)) != 0)
274
+ return freerdp_client_send_button_event(sdl->common(), relative, flags, x, y);
275
+ else if ((xflags & (~PTR_XFLAGS_DOWN)) != 0)
276
+ return freerdp_client_send_extended_button_event(sdl->common(), relative, xflags, x, y);
277
+ else
278
+ return FALSE;
279
+ }
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_touch.hpp ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * FreeRDP SDL touch/mouse input
4
+ *
5
+ * Copyright 2022 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #pragma once
21
+
22
+ #include <winpr/wtypes.h>
23
+
24
+ #include <SDL3/SDL.h>
25
+ #include "sdl_types.hpp"
26
+
27
+ BOOL sdl_scale_coordinates(SdlContext* sdl, Uint32 windowId, INT32* px, INT32* py,
28
+ BOOL fromLocalToRDP, BOOL applyOffset);
29
+
30
+ BOOL sdl_handle_mouse_motion(SdlContext* sdl, const SDL_MouseMotionEvent* ev);
31
+ BOOL sdl_handle_mouse_wheel(SdlContext* sdl, const SDL_MouseWheelEvent* ev);
32
+ BOOL sdl_handle_mouse_button(SdlContext* sdl, const SDL_MouseButtonEvent* ev);
33
+
34
+ BOOL sdl_handle_touch_down(SdlContext* sdl, const SDL_TouchFingerEvent* ev);
35
+ BOOL sdl_handle_touch_up(SdlContext* sdl, const SDL_TouchFingerEvent* ev);
36
+ BOOL sdl_handle_touch_motion(SdlContext* sdl, const SDL_TouchFingerEvent* ev);
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_types.hpp ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * SDL Client
4
+ *
5
+ * Copyright 2022 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #pragma once
21
+
22
+ #include <freerdp/freerdp.h>
23
+
24
+ class SdlContext;
25
+
26
+ typedef struct
27
+ {
28
+ rdpClientContext common;
29
+ SdlContext* sdl;
30
+ } sdl_rdp_context;
31
+
32
+ static inline SdlContext* get_context(void* ctx)
33
+ {
34
+ if (!ctx)
35
+ return nullptr;
36
+ auto sdl = static_cast<sdl_rdp_context*>(ctx);
37
+ return sdl->sdl;
38
+ }
39
+
40
+ static inline SdlContext* get_context(rdpContext* ctx)
41
+ {
42
+ if (!ctx)
43
+ return nullptr;
44
+ auto sdl = reinterpret_cast<sdl_rdp_context*>(ctx);
45
+ return sdl->sdl;
46
+ }
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_utils.cpp ADDED
@@ -0,0 +1,346 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * SDL Client
4
+ *
5
+ * Copyright 2022 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #include <cassert>
21
+ #include "sdl_utils.hpp"
22
+
23
+ #include "sdl_freerdp.hpp"
24
+
25
+ #include <SDL3/SDL.h>
26
+
27
+ #include <freerdp/version.h>
28
+
29
+ #define STR(x) #x
30
+ #define EV_CASE_STR(x) \
31
+ case x: \
32
+ return STR(x)
33
+
34
+ const char* sdl_event_type_str(Uint32 type)
35
+ {
36
+ switch (type)
37
+ {
38
+ EV_CASE_STR(SDL_EVENT_FIRST);
39
+ EV_CASE_STR(SDL_EVENT_QUIT);
40
+ EV_CASE_STR(SDL_EVENT_TERMINATING);
41
+ EV_CASE_STR(SDL_EVENT_LOW_MEMORY);
42
+ EV_CASE_STR(SDL_EVENT_WILL_ENTER_BACKGROUND);
43
+ EV_CASE_STR(SDL_EVENT_DID_ENTER_BACKGROUND);
44
+ EV_CASE_STR(SDL_EVENT_WILL_ENTER_FOREGROUND);
45
+ EV_CASE_STR(SDL_EVENT_DID_ENTER_FOREGROUND);
46
+ EV_CASE_STR(SDL_EVENT_LOCALE_CHANGED);
47
+ EV_CASE_STR(SDL_EVENT_SYSTEM_THEME_CHANGED);
48
+ EV_CASE_STR(SDL_EVENT_DISPLAY_ORIENTATION);
49
+ EV_CASE_STR(SDL_EVENT_DISPLAY_ADDED);
50
+ EV_CASE_STR(SDL_EVENT_DISPLAY_REMOVED);
51
+ EV_CASE_STR(SDL_EVENT_DISPLAY_MOVED);
52
+ EV_CASE_STR(SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED);
53
+ EV_CASE_STR(SDL_EVENT_WINDOW_SHOWN);
54
+ EV_CASE_STR(SDL_EVENT_WINDOW_HIDDEN);
55
+ EV_CASE_STR(SDL_EVENT_WINDOW_EXPOSED);
56
+ EV_CASE_STR(SDL_EVENT_WINDOW_MOVED);
57
+ EV_CASE_STR(SDL_EVENT_WINDOW_RESIZED);
58
+ EV_CASE_STR(SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED);
59
+ EV_CASE_STR(SDL_EVENT_WINDOW_MINIMIZED);
60
+ EV_CASE_STR(SDL_EVENT_WINDOW_MAXIMIZED);
61
+ EV_CASE_STR(SDL_EVENT_WINDOW_RESTORED);
62
+ EV_CASE_STR(SDL_EVENT_WINDOW_MOUSE_ENTER);
63
+ EV_CASE_STR(SDL_EVENT_WINDOW_MOUSE_LEAVE);
64
+ EV_CASE_STR(SDL_EVENT_WINDOW_FOCUS_GAINED);
65
+ EV_CASE_STR(SDL_EVENT_WINDOW_FOCUS_LOST);
66
+ EV_CASE_STR(SDL_EVENT_WINDOW_CLOSE_REQUESTED);
67
+ EV_CASE_STR(SDL_EVENT_WINDOW_HIT_TEST);
68
+ EV_CASE_STR(SDL_EVENT_WINDOW_ICCPROF_CHANGED);
69
+ EV_CASE_STR(SDL_EVENT_WINDOW_DISPLAY_CHANGED);
70
+ EV_CASE_STR(SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED);
71
+ EV_CASE_STR(SDL_EVENT_WINDOW_OCCLUDED);
72
+ EV_CASE_STR(SDL_EVENT_WINDOW_ENTER_FULLSCREEN);
73
+ EV_CASE_STR(SDL_EVENT_WINDOW_LEAVE_FULLSCREEN);
74
+ EV_CASE_STR(SDL_EVENT_WINDOW_DESTROYED);
75
+
76
+ EV_CASE_STR(SDL_EVENT_KEY_DOWN);
77
+ EV_CASE_STR(SDL_EVENT_KEY_UP);
78
+ EV_CASE_STR(SDL_EVENT_TEXT_EDITING);
79
+ EV_CASE_STR(SDL_EVENT_TEXT_INPUT);
80
+ EV_CASE_STR(SDL_EVENT_KEYMAP_CHANGED);
81
+ EV_CASE_STR(SDL_EVENT_KEYBOARD_ADDED);
82
+ EV_CASE_STR(SDL_EVENT_KEYBOARD_REMOVED);
83
+
84
+ EV_CASE_STR(SDL_EVENT_MOUSE_MOTION);
85
+ EV_CASE_STR(SDL_EVENT_MOUSE_BUTTON_DOWN);
86
+ EV_CASE_STR(SDL_EVENT_MOUSE_BUTTON_UP);
87
+ EV_CASE_STR(SDL_EVENT_MOUSE_WHEEL);
88
+ EV_CASE_STR(SDL_EVENT_MOUSE_ADDED);
89
+ EV_CASE_STR(SDL_EVENT_MOUSE_REMOVED);
90
+
91
+ EV_CASE_STR(SDL_EVENT_JOYSTICK_AXIS_MOTION);
92
+ EV_CASE_STR(SDL_EVENT_JOYSTICK_BALL_MOTION);
93
+ EV_CASE_STR(SDL_EVENT_JOYSTICK_HAT_MOTION);
94
+ EV_CASE_STR(SDL_EVENT_JOYSTICK_BUTTON_DOWN);
95
+ EV_CASE_STR(SDL_EVENT_JOYSTICK_BUTTON_UP);
96
+ EV_CASE_STR(SDL_EVENT_JOYSTICK_ADDED);
97
+ EV_CASE_STR(SDL_EVENT_JOYSTICK_REMOVED);
98
+ EV_CASE_STR(SDL_EVENT_JOYSTICK_BATTERY_UPDATED);
99
+ EV_CASE_STR(SDL_EVENT_JOYSTICK_UPDATE_COMPLETE);
100
+
101
+ EV_CASE_STR(SDL_EVENT_GAMEPAD_AXIS_MOTION);
102
+ EV_CASE_STR(SDL_EVENT_GAMEPAD_BUTTON_DOWN);
103
+ EV_CASE_STR(SDL_EVENT_GAMEPAD_BUTTON_UP);
104
+ EV_CASE_STR(SDL_EVENT_GAMEPAD_ADDED);
105
+ EV_CASE_STR(SDL_EVENT_GAMEPAD_REMOVED);
106
+ EV_CASE_STR(SDL_EVENT_GAMEPAD_REMAPPED);
107
+ EV_CASE_STR(SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN);
108
+ EV_CASE_STR(SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION);
109
+ EV_CASE_STR(SDL_EVENT_GAMEPAD_TOUCHPAD_UP);
110
+ EV_CASE_STR(SDL_EVENT_GAMEPAD_SENSOR_UPDATE);
111
+ EV_CASE_STR(SDL_EVENT_GAMEPAD_UPDATE_COMPLETE);
112
+ EV_CASE_STR(SDL_EVENT_GAMEPAD_STEAM_HANDLE_UPDATED);
113
+
114
+ EV_CASE_STR(SDL_EVENT_FINGER_DOWN);
115
+ EV_CASE_STR(SDL_EVENT_FINGER_UP);
116
+ EV_CASE_STR(SDL_EVENT_FINGER_MOTION);
117
+
118
+ EV_CASE_STR(SDL_EVENT_CLIPBOARD_UPDATE);
119
+
120
+ EV_CASE_STR(SDL_EVENT_DROP_FILE);
121
+ EV_CASE_STR(SDL_EVENT_DROP_TEXT);
122
+ EV_CASE_STR(SDL_EVENT_DROP_BEGIN);
123
+ EV_CASE_STR(SDL_EVENT_DROP_COMPLETE);
124
+ EV_CASE_STR(SDL_EVENT_DROP_POSITION);
125
+
126
+ EV_CASE_STR(SDL_EVENT_AUDIO_DEVICE_ADDED);
127
+ EV_CASE_STR(SDL_EVENT_AUDIO_DEVICE_REMOVED);
128
+ EV_CASE_STR(SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED);
129
+
130
+ EV_CASE_STR(SDL_EVENT_SENSOR_UPDATE);
131
+
132
+ EV_CASE_STR(SDL_EVENT_PEN_DOWN);
133
+ EV_CASE_STR(SDL_EVENT_PEN_UP);
134
+ EV_CASE_STR(SDL_EVENT_PEN_MOTION);
135
+ EV_CASE_STR(SDL_EVENT_PEN_BUTTON_DOWN);
136
+ EV_CASE_STR(SDL_EVENT_PEN_BUTTON_UP);
137
+ EV_CASE_STR(SDL_EVENT_CAMERA_DEVICE_ADDED);
138
+ EV_CASE_STR(SDL_EVENT_CAMERA_DEVICE_REMOVED);
139
+ EV_CASE_STR(SDL_EVENT_CAMERA_DEVICE_APPROVED);
140
+ EV_CASE_STR(SDL_EVENT_CAMERA_DEVICE_DENIED);
141
+
142
+ EV_CASE_STR(SDL_EVENT_RENDER_TARGETS_RESET);
143
+ EV_CASE_STR(SDL_EVENT_RENDER_DEVICE_RESET);
144
+ EV_CASE_STR(SDL_EVENT_POLL_SENTINEL);
145
+
146
+ EV_CASE_STR(SDL_EVENT_USER);
147
+
148
+ EV_CASE_STR(SDL_EVENT_USER_CERT_DIALOG);
149
+ EV_CASE_STR(SDL_EVENT_USER_CERT_RESULT);
150
+ EV_CASE_STR(SDL_EVENT_USER_SHOW_DIALOG);
151
+ EV_CASE_STR(SDL_EVENT_USER_SHOW_RESULT);
152
+ EV_CASE_STR(SDL_EVENT_USER_AUTH_DIALOG);
153
+ EV_CASE_STR(SDL_EVENT_USER_AUTH_RESULT);
154
+ EV_CASE_STR(SDL_EVENT_USER_SCARD_DIALOG);
155
+ EV_CASE_STR(SDL_EVENT_USER_RETRY_DIALOG);
156
+ EV_CASE_STR(SDL_EVENT_USER_SCARD_RESULT);
157
+ EV_CASE_STR(SDL_EVENT_USER_UPDATE);
158
+ EV_CASE_STR(SDL_EVENT_USER_CREATE_WINDOWS);
159
+ EV_CASE_STR(SDL_EVENT_USER_WINDOW_RESIZEABLE);
160
+ EV_CASE_STR(SDL_EVENT_USER_WINDOW_FULLSCREEN);
161
+ EV_CASE_STR(SDL_EVENT_USER_WINDOW_MINIMIZE);
162
+ EV_CASE_STR(SDL_EVENT_USER_POINTER_NULL);
163
+ EV_CASE_STR(SDL_EVENT_USER_POINTER_DEFAULT);
164
+ EV_CASE_STR(SDL_EVENT_USER_POINTER_POSITION);
165
+ EV_CASE_STR(SDL_EVENT_USER_POINTER_SET);
166
+ EV_CASE_STR(SDL_EVENT_USER_QUIT);
167
+
168
+ EV_CASE_STR(SDL_EVENT_LAST);
169
+ default:
170
+ return "SDL_UNKNOWNEVENT";
171
+ }
172
+ }
173
+
174
+ const char* sdl_error_string(Sint32 res)
175
+ {
176
+ if (res == 0)
177
+ return nullptr;
178
+
179
+ return SDL_GetError();
180
+ }
181
+
182
+ BOOL sdl_log_error_ex(Sint32 res, wLog* log, const char* what, const char* file, size_t line,
183
+ const char* fkt)
184
+ {
185
+ const char* msg = sdl_error_string(res);
186
+
187
+ WINPR_UNUSED(file);
188
+
189
+ if (!msg)
190
+ return FALSE;
191
+
192
+ WLog_Print(log, WLOG_ERROR, "[%s:%" PRIuz "][%s]: %s", fkt, line, what, msg);
193
+ return TRUE;
194
+ }
195
+
196
+ BOOL sdl_push_user_event(Uint32 type, ...)
197
+ {
198
+ SDL_Event ev = {};
199
+ SDL_UserEvent* event = &ev.user;
200
+
201
+ va_list ap = {};
202
+ va_start(ap, type);
203
+ event->type = type;
204
+ switch (type)
205
+ {
206
+ case SDL_EVENT_USER_AUTH_RESULT:
207
+ {
208
+ auto arg = reinterpret_cast<SDL_UserAuthArg*>(ev.padding);
209
+ arg->user = va_arg(ap, char*);
210
+ arg->domain = va_arg(ap, char*);
211
+ arg->password = va_arg(ap, char*);
212
+ arg->result = va_arg(ap, Sint32);
213
+ }
214
+ break;
215
+ case SDL_EVENT_USER_AUTH_DIALOG:
216
+ {
217
+ auto arg = reinterpret_cast<SDL_UserAuthArg*>(ev.padding);
218
+
219
+ arg->title = va_arg(ap, char*);
220
+ arg->user = va_arg(ap, char*);
221
+ arg->domain = va_arg(ap, char*);
222
+ arg->password = va_arg(ap, char*);
223
+ arg->result = va_arg(ap, Sint32);
224
+ }
225
+ break;
226
+ case SDL_EVENT_USER_SCARD_DIALOG:
227
+ {
228
+ event->data1 = va_arg(ap, char*);
229
+ event->data2 = va_arg(ap, char**);
230
+ event->code = va_arg(ap, Sint32);
231
+ }
232
+ break;
233
+ case SDL_EVENT_USER_RETRY_DIALOG:
234
+ break;
235
+ case SDL_EVENT_USER_SCARD_RESULT:
236
+ case SDL_EVENT_USER_SHOW_RESULT:
237
+ case SDL_EVENT_USER_CERT_RESULT:
238
+ event->code = va_arg(ap, Sint32);
239
+ break;
240
+
241
+ case SDL_EVENT_USER_SHOW_DIALOG:
242
+ event->data1 = va_arg(ap, char*);
243
+ event->data2 = va_arg(ap, char*);
244
+ event->code = va_arg(ap, Sint32);
245
+ break;
246
+ case SDL_EVENT_USER_CERT_DIALOG:
247
+ event->data1 = va_arg(ap, char*);
248
+ event->data2 = va_arg(ap, char*);
249
+ break;
250
+ case SDL_EVENT_USER_UPDATE:
251
+ event->data1 = va_arg(ap, void*);
252
+ break;
253
+ case SDL_EVENT_USER_POINTER_POSITION:
254
+ event->data1 = reinterpret_cast<void*>(static_cast<uintptr_t>(va_arg(ap, UINT32)));
255
+ event->data2 = reinterpret_cast<void*>(static_cast<uintptr_t>(va_arg(ap, UINT32)));
256
+ break;
257
+ case SDL_EVENT_USER_POINTER_SET:
258
+ event->data1 = va_arg(ap, void*);
259
+ event->data2 = va_arg(ap, void*);
260
+ break;
261
+ case SDL_EVENT_USER_CREATE_WINDOWS:
262
+ event->data1 = va_arg(ap, void*);
263
+ break;
264
+ case SDL_EVENT_USER_WINDOW_FULLSCREEN:
265
+ case SDL_EVENT_USER_WINDOW_RESIZEABLE:
266
+ event->data1 = va_arg(ap, void*);
267
+ event->code = va_arg(ap, int);
268
+ break;
269
+ case SDL_EVENT_USER_WINDOW_MINIMIZE:
270
+ case SDL_EVENT_USER_QUIT:
271
+ case SDL_EVENT_USER_POINTER_NULL:
272
+ case SDL_EVENT_USER_POINTER_DEFAULT:
273
+ case SDL_EVENT_CLIPBOARD_UPDATE:
274
+ break;
275
+ default:
276
+ va_end(ap);
277
+ return FALSE;
278
+ }
279
+ va_end(ap);
280
+ return SDL_PushEvent(&ev) == 1;
281
+ }
282
+
283
+ CriticalSection::CriticalSection()
284
+ {
285
+ InitializeCriticalSection(&_section);
286
+ }
287
+
288
+ CriticalSection::~CriticalSection()
289
+ {
290
+ DeleteCriticalSection(&_section);
291
+ }
292
+
293
+ void CriticalSection::lock()
294
+ {
295
+ EnterCriticalSection(&_section);
296
+ }
297
+
298
+ void CriticalSection::unlock()
299
+ {
300
+ LeaveCriticalSection(&_section);
301
+ }
302
+
303
+ WinPREvent::WinPREvent(bool initial) : _handle(CreateEventA(nullptr, TRUE, initial, nullptr))
304
+ {
305
+ }
306
+
307
+ WinPREvent::~WinPREvent()
308
+ {
309
+ (void)CloseHandle(_handle);
310
+ }
311
+
312
+ void WinPREvent::set()
313
+ {
314
+ (void)SetEvent(_handle);
315
+ }
316
+
317
+ void WinPREvent::clear()
318
+ {
319
+ (void)ResetEvent(_handle);
320
+ }
321
+
322
+ bool WinPREvent::isSet() const
323
+ {
324
+ return WaitForSingleObject(_handle, 0) == WAIT_OBJECT_0;
325
+ }
326
+
327
+ HANDLE WinPREvent::handle() const
328
+ {
329
+ return _handle;
330
+ }
331
+
332
+ bool sdl_push_quit()
333
+ {
334
+ SDL_Event ev = {};
335
+ ev.type = SDL_EVENT_QUIT;
336
+ SDL_PushEvent(&ev);
337
+ return true;
338
+ }
339
+
340
+ std::string sdl_window_event_str(Uint32 ev)
341
+ {
342
+ if ((ev >= SDL_EVENT_WINDOW_FIRST) && (ev <= SDL_EVENT_WINDOW_LAST))
343
+ return sdl_event_type_str(ev);
344
+
345
+ return "SDL_EVENT_WINDOW_UNKNOWN";
346
+ }
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_utils.hpp ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * SDL Client
4
+ *
5
+ * Copyright 2022 Armin Novak <[email protected]>
6
+ *
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
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
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.
18
+ */
19
+
20
+ #pragma once
21
+
22
+ #include <winpr/synch.h>
23
+ #include <winpr/wlog.h>
24
+
25
+ #include <SDL3/SDL.h>
26
+ #include <string>
27
+ #include <vector>
28
+ #include <memory>
29
+ #include <functional>
30
+
31
+ template <typename T> using deleted_unique_ptr = std::unique_ptr<T, std::function<void(T*)>>;
32
+
33
+ class CriticalSection
34
+ {
35
+ public:
36
+ CriticalSection();
37
+ CriticalSection(const CriticalSection& other) = delete;
38
+ CriticalSection(CriticalSection&& other) = delete;
39
+ ~CriticalSection();
40
+
41
+ CriticalSection& operator=(const CriticalSection& other) = delete;
42
+ CriticalSection& operator=(CriticalSection&& other) = delete;
43
+
44
+ void lock();
45
+ void unlock();
46
+
47
+ private:
48
+ CRITICAL_SECTION _section{};
49
+ };
50
+
51
+ class WinPREvent
52
+ {
53
+ public:
54
+ explicit WinPREvent(bool initial = false);
55
+ ~WinPREvent();
56
+
57
+ void set();
58
+ void clear();
59
+ [[nodiscard]] bool isSet() const;
60
+
61
+ [[nodiscard]] HANDLE handle() const;
62
+
63
+ private:
64
+ HANDLE _handle;
65
+ };
66
+
67
+ enum
68
+ {
69
+ SDL_EVENT_USER_UPDATE = SDL_EVENT_USER + 1,
70
+ SDL_EVENT_USER_CREATE_WINDOWS,
71
+ SDL_EVENT_USER_WINDOW_RESIZEABLE,
72
+ SDL_EVENT_USER_WINDOW_FULLSCREEN,
73
+ SDL_EVENT_USER_WINDOW_MINIMIZE,
74
+ SDL_EVENT_USER_POINTER_NULL,
75
+ SDL_EVENT_USER_POINTER_DEFAULT,
76
+ SDL_EVENT_USER_POINTER_POSITION,
77
+ SDL_EVENT_USER_POINTER_SET,
78
+ SDL_EVENT_USER_QUIT,
79
+ SDL_EVENT_USER_CERT_DIALOG,
80
+ SDL_EVENT_USER_SHOW_DIALOG,
81
+ SDL_EVENT_USER_AUTH_DIALOG,
82
+ SDL_EVENT_USER_SCARD_DIALOG,
83
+ SDL_EVENT_USER_RETRY_DIALOG,
84
+
85
+ SDL_EVENT_USER_CERT_RESULT,
86
+ SDL_EVENT_USER_SHOW_RESULT,
87
+ SDL_EVENT_USER_AUTH_RESULT,
88
+ SDL_EVENT_USER_SCARD_RESULT
89
+ };
90
+
91
+ typedef struct
92
+ {
93
+ Uint32 type;
94
+ Uint32 timestamp;
95
+ char* title;
96
+ char* user;
97
+ char* domain;
98
+ char* password;
99
+ Sint32 result;
100
+ } SDL_UserAuthArg;
101
+
102
+ BOOL sdl_push_user_event(Uint32 type, ...);
103
+
104
+ bool sdl_push_quit();
105
+
106
+ std::string sdl_window_event_str(Uint32 ev);
107
+ const char* sdl_event_type_str(Uint32 type);
108
+ const char* sdl_error_string(Sint32 res);
109
+
110
+ #define sdl_log_error(res, log, what) sdl_log_error_ex(res, log, what, __FILE__, __LINE__, __func__)
111
+ BOOL sdl_log_error_ex(Sint32 res, wLog* log, const char* what, const char* file, size_t line,
112
+ const char* fkt);
local-test-freerdp-delta-01/afc-freerdp/client/SDL/SDL3/sdl_window.hpp ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ * SDL Client
4
+ *
5
+ * Copyright 2023 Armin Novak <[email protected]>
6
+ * Copyright 2023 Thincast Technologies GmbH
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+ #pragma once
21
+
22
+ #include <string>
23
+ #include <SDL3/SDL.h>
24
+
25
+ class SdlWindow
26
+ {
27
+ public:
28
+ SdlWindow(const std::string& title, Sint32 startupX, Sint32 startupY, Sint32 width,
29
+ Sint32 height, Uint32 flags);
30
+ SdlWindow(SdlWindow&& other) noexcept;
31
+ SdlWindow(const SdlWindow& other) = delete;
32
+ ~SdlWindow();
33
+
34
+ SdlWindow& operator=(const SdlWindow& other) = delete;
35
+ SdlWindow& operator=(SdlWindow&& other) = delete;
36
+
37
+ [[nodiscard]] Uint32 id() const;
38
+ [[nodiscard]] int displayIndex() const;
39
+ [[nodiscard]] SDL_Rect rect() const;
40
+ [[nodiscard]] SDL_Window* window() const;
41
+
42
+ [[nodiscard]] Sint32 offsetX() const;
43
+ void setOffsetX(Sint32 x);
44
+
45
+ void setOffsetY(Sint32 y);
46
+ [[nodiscard]] Sint32 offsetY() const;
47
+
48
+ bool grabKeyboard(bool enable);
49
+ bool grabMouse(bool enable);
50
+ void setBordered(bool bordered);
51
+ void raise();
52
+ void resizeable(bool use);
53
+ void fullscreen(bool enter);
54
+ void minimize();
55
+
56
+ bool fill(Uint8 r = 0x00, Uint8 g = 0x00, Uint8 b = 0x00, Uint8 a = 0xff);
57
+ bool blit(SDL_Surface* surface, const SDL_Rect& src, SDL_Rect& dst);
58
+ void updateSurface();
59
+
60
+ private:
61
+ SDL_Window* _window = nullptr;
62
+ Sint32 _offset_x = 0;
63
+ Sint32 _offset_y = 0;
64
+ };
local-test-freerdp-delta-01/afc-freerdp/client/Windows/CMakeLists.txt ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FreeRDP: A Remote Desktop Protocol Implementation
2
+ # FreeRDP Windows cmake build script
3
+ #
4
+ # Copyright 2012 Marc-Andre Moreau <[email protected]>
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ set(MODULE_NAME "wfreerdp-client")
19
+ set(MODULE_PREFIX "FREERDP_CLIENT_WINDOWS_CONTROL")
20
+
21
+ set(${MODULE_PREFIX}_SRCS
22
+ wf_gdi.c
23
+ wf_gdi.h
24
+ wf_event.c
25
+ wf_event.h
26
+ wf_channels.c
27
+ wf_channels.h
28
+ wf_graphics.c
29
+ wf_graphics.h
30
+ wf_cliprdr.c
31
+ wf_cliprdr.h
32
+ wf_rail.c
33
+ wf_rail.h
34
+ wf_client.c
35
+ wf_client.h
36
+ wf_floatbar.c
37
+ wf_floatbar.h
38
+ wf_defaults.h
39
+ wf_defaults.c
40
+ resource/wfreerdp.rc
41
+ resource/resource.h
42
+ )
43
+
44
+ option(WITH_WINDOWS_CERT_STORE
45
+ "Build ${MODULE_NAME} with additional certificate validation against windows certificate store" ON
46
+ )
47
+ if(WITH_WINDOWS_CERT_STORE)
48
+ add_compile_definitions("WITH_WINDOWS_CERT_STORE")
49
+ endif()
50
+
51
+ option(WITH_WIN_CONSOLE "Build ${MODULE_NAME} with console support" OFF)
52
+ if(WITH_WIN_CONSOLE)
53
+ add_compile_definitions("WITH_WIN_CONSOLE")
54
+ set(WIN32_GUI_FLAG "TRUE")
55
+ else()
56
+ set(WIN32_GUI_FLAG "WIN32")
57
+ endif()
58
+
59
+ option(WITH_PROGRESS_BAR "Build ${MODULE_NAME} with connect progress bar (Windows 7+ or 2008 R2+)" ON)
60
+ if(WITH_PROGRESS_BAR)
61
+ add_compile_definitions("WITH_PROGRESS_BAR")
62
+ endif()
63
+
64
+ if(CLIENT_INTERFACE_SHARED)
65
+ addtargetwithresourcefile(${MODULE_NAME} "SHARED" "${FREERDP_VERSION}" ${MODULE_PREFIX}_SRCS)
66
+ else()
67
+ addtargetwithresourcefile(${MODULE_NAME} FALSE "${FREERDP_VERSION}" ${MODULE_PREFIX}_SRCS)
68
+ endif()
69
+ target_include_directories(${MODULE_NAME} INTERFACE $<INSTALL_INTERFACE:include>)
70
+
71
+ list(APPEND PUB_LIBS freerdp-client)
72
+ list(APPEND PUB_LIBS winpr freerdp)
73
+
74
+ list(APPEND PRIV_LIBS msimg32.lib credui.lib)
75
+
76
+ if(MINGW)
77
+ list(APPEND PRIV_LIBS ntdll.lib) # only required with MINGW
78
+ endif()
79
+ target_link_libraries(${MODULE_NAME} PUBLIC ${PUB_LIBS})
80
+ target_link_libraries(${MODULE_NAME} PRIVATE ${PRIV_LIBS})
81
+
82
+ if(WITH_CLIENT_INTERFACE)
83
+ install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries)
84
+ endif()
85
+ add_subdirectory(cli)
86
+
87
+ set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Client/Windows")
local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_channels.c ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ *
4
+ * Copyright 2014 Marc-Andre Moreau <[email protected]>
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #include <freerdp/config.h>
20
+
21
+ #include <winpr/assert.h>
22
+
23
+ #include "wf_channels.h"
24
+
25
+ #include "wf_rail.h"
26
+ #include "wf_cliprdr.h"
27
+
28
+ #include <freerdp/gdi/gfx.h>
29
+ #include <freerdp/gdi/video.h>
30
+
31
+ #include <freerdp/log.h>
32
+ #define TAG CLIENT_TAG("windows")
33
+
34
+ void wf_OnChannelConnectedEventHandler(void* context, const ChannelConnectedEventArgs* e)
35
+ {
36
+ wfContext* wfc = (wfContext*)context;
37
+ rdpSettings* settings;
38
+
39
+ WINPR_ASSERT(wfc);
40
+ WINPR_ASSERT(e);
41
+
42
+ settings = wfc->common.context.settings;
43
+ WINPR_ASSERT(settings);
44
+
45
+ if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0)
46
+ {
47
+ wf_rail_init(wfc, (RailClientContext*)e->pInterface);
48
+ }
49
+ else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
50
+ {
51
+ wf_cliprdr_init(wfc, (CliprdrClientContext*)e->pInterface);
52
+ }
53
+ else if (strcmp(e->name, DISP_DVC_CHANNEL_NAME) == 0)
54
+ {
55
+ wfc->disp = (DispClientContext*)e->pInterface;
56
+ }
57
+ else
58
+ freerdp_client_OnChannelConnectedEventHandler(context, e);
59
+ }
60
+
61
+ void wf_OnChannelDisconnectedEventHandler(void* context, const ChannelDisconnectedEventArgs* e)
62
+ {
63
+ wfContext* wfc = (wfContext*)context;
64
+ rdpSettings* settings;
65
+
66
+ WINPR_ASSERT(wfc);
67
+ WINPR_ASSERT(e);
68
+
69
+ settings = wfc->common.context.settings;
70
+ WINPR_ASSERT(settings);
71
+
72
+ if (strcmp(e->name, RAIL_SVC_CHANNEL_NAME) == 0)
73
+ {
74
+ wf_rail_uninit(wfc, (RailClientContext*)e->pInterface);
75
+ }
76
+ else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
77
+ {
78
+ wf_cliprdr_uninit(wfc, (CliprdrClientContext*)e->pInterface);
79
+ }
80
+ else if (strcmp(e->name, DISP_DVC_CHANNEL_NAME) == 0)
81
+ {
82
+ wfc->disp = NULL;
83
+ }
84
+ else
85
+ freerdp_client_OnChannelDisconnectedEventHandler(context, e);
86
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_defaults.c ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ *
4
+ * Copyright 2022 Stefan Koell
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #include <windows.h>
20
+ #include <wincred.h>
21
+ #include <stdio.h>
22
+ #include <malloc.h>
23
+ #include <freerdp/settings.h>
24
+
25
+ #include "wf_defaults.h"
26
+
27
+ static PCWSTR ValidateString(const BYTE* pb, ULONG cb)
28
+ {
29
+ if (!pb || !cb)
30
+ return 0;
31
+
32
+ if (cb % sizeof(WCHAR) != 0)
33
+ return 0;
34
+
35
+ return (PCWSTR)pb;
36
+ }
37
+
38
+ static void AddDefaultSettings_I(rdpSettings* settings, size_t idHostname, size_t idUsername,
39
+ size_t idDomain, size_t idPassword)
40
+ {
41
+ static const PSTR TERMSRV = "TERMSRV/%s";
42
+
43
+ PSTR TargetName = NULL;
44
+ PSTR UserName = NULL;
45
+ PWSTR TargetNameW = NULL;
46
+ PWSTR ServerHostNameW = NULL;
47
+ PWSTR ParsedUserNameW = NULL;
48
+ PWSTR ParsedDomainW = NULL;
49
+ PWSTR PasswordNullTerminatedW = NULL;
50
+ PCREDENTIALW Credential = { 0 };
51
+
52
+ PCSTR ServerHostname = freerdp_settings_get_string(settings, idHostname);
53
+
54
+ if (!ServerHostname)
55
+ return;
56
+
57
+ BOOL bExistUserName = freerdp_settings_get_string(settings, idUsername) != 0;
58
+ BOOL bExistPassword = freerdp_settings_get_string(settings, idPassword) != 0;
59
+
60
+ if (bExistUserName && bExistPassword)
61
+ return;
62
+
63
+ int len = _snprintf(TargetName, 0, TERMSRV, ServerHostname);
64
+ len++;
65
+ TargetName = (PSTR)malloc(len);
66
+
67
+ if (!TargetName)
68
+ goto fail;
69
+
70
+ _snprintf(TargetName, len, TERMSRV, ServerHostname);
71
+
72
+ TargetName[len - 1] = 0;
73
+
74
+ TargetNameW = ConvertUtf8ToWCharAlloc(TargetName, NULL);
75
+ if (!TargetNameW)
76
+ goto fail;
77
+
78
+ if (!CredReadW(TargetNameW, CRED_TYPE_GENERIC, 0, &Credential))
79
+ goto fail;
80
+
81
+ if (!bExistPassword)
82
+ {
83
+ const WCHAR* PasswordW =
84
+ ValidateString(Credential->CredentialBlob, Credential->CredentialBlobSize);
85
+
86
+ PasswordNullTerminatedW = (PWSTR)calloc(Credential->CredentialBlobSize + 1, sizeof(WCHAR));
87
+
88
+ if (!PasswordNullTerminatedW)
89
+ goto fail;
90
+
91
+ memcpy(PasswordNullTerminatedW, PasswordW, Credential->CredentialBlobSize * sizeof(WCHAR));
92
+
93
+ if (PasswordNullTerminatedW)
94
+ {
95
+ if (!freerdp_settings_set_string_from_utf16(settings, idPassword,
96
+ PasswordNullTerminatedW))
97
+ {
98
+ goto fail;
99
+ }
100
+ }
101
+ }
102
+
103
+ if (!bExistUserName)
104
+ {
105
+ const WCHAR* UserNameW = Credential->UserName;
106
+
107
+ if (UserNameW)
108
+ {
109
+ ParsedUserNameW = calloc(CREDUI_MAX_USERNAME_LENGTH + 1, sizeof(WCHAR));
110
+ if (!ParsedUserNameW)
111
+ goto fail;
112
+
113
+ ParsedDomainW = calloc(CREDUI_MAX_DOMAIN_TARGET_LENGTH + 1, sizeof(WCHAR));
114
+ if (!ParsedDomainW)
115
+ goto fail;
116
+
117
+ DWORD ParseResult =
118
+ CredUIParseUserNameW(UserNameW, ParsedUserNameW, CREDUI_MAX_USERNAME_LENGTH + 1,
119
+ ParsedDomainW, CREDUI_MAX_DOMAIN_TARGET_LENGTH + 1);
120
+
121
+ if (ParseResult == NO_ERROR)
122
+ {
123
+ if (!freerdp_settings_set_string_from_utf16(settings, idUsername, ParsedUserNameW))
124
+ goto fail;
125
+
126
+ if (*ParsedDomainW != 0)
127
+ {
128
+ if (!freerdp_settings_set_string_from_utf16(settings, idDomain, ParsedDomainW))
129
+ goto fail;
130
+ }
131
+ }
132
+ else if (ParseResult == ERROR_INVALID_ACCOUNT_NAME)
133
+ {
134
+ if (!freerdp_settings_set_string_from_utf16(settings, idUsername, UserNameW))
135
+ goto fail;
136
+ }
137
+ }
138
+ }
139
+
140
+ fail:
141
+ if (Credential)
142
+ {
143
+ CredFree(Credential);
144
+ }
145
+ free(TargetName);
146
+ free(UserName);
147
+ free(TargetNameW);
148
+ free(ServerHostNameW);
149
+ free(ParsedUserNameW);
150
+ free(ParsedDomainW);
151
+ free(PasswordNullTerminatedW);
152
+ return;
153
+ }
154
+
155
+ void WINAPI AddDefaultSettings(rdpSettings* settings)
156
+ {
157
+ AddDefaultSettings_I(settings, FreeRDP_ServerHostname, FreeRDP_Username, FreeRDP_Domain,
158
+ FreeRDP_Password);
159
+ AddDefaultSettings_I(settings, FreeRDP_GatewayHostname, FreeRDP_GatewayUsername,
160
+ FreeRDP_GatewayDomain, FreeRDP_GatewayPassword);
161
+ }
local-test-freerdp-delta-01/afc-freerdp/client/Windows/wf_defaults.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * FreeRDP: A Remote Desktop Protocol Implementation
3
+ *
4
+ * Copyright 2022 Stefan Koell
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #ifndef FREERDP_CLIENT_WIN_DEFAULTS_H
20
+ #define FREERDP_CLIENT_WIN_DEFAULTS_H
21
+
22
+ #include <winpr/wtypes.h>
23
+ #include <freerdp/api.h>
24
+ #include <freerdp/settings.h>
25
+
26
+ FREERDP_API void WINAPI AddDefaultSettings(_Inout_ rdpSettings* settings);
27
+
28
+ #endif /* FREERDP_CLIENT_WIN_DEFAULTS_H */