diff --git a/client/Mac/Keyboard.m b/client/Mac/Keyboard.m index d0b5b6c04..98574b792 100644 --- a/client/Mac/Keyboard.m +++ b/client/Mac/Keyboard.m @@ -32,7 +32,7 @@ typedef struct _APPLE_KEYBOARD_DESC APPLE_KEYBOARD_DESC; /* VendorID: 0x05AC (Apple, Inc.) */ -APPLE_KEYBOARD_DESC APPLE_KEYBOARDS[] = +static const APPLE_KEYBOARD_DESC APPLE_KEYBOARDS[] = { { 0x200, APPLE_KEYBOARD_TYPE_ANSI }, { 0x201, APPLE_KEYBOARD_TYPE_ANSI }, /* USB Keyboard [Alps or Logitech, M2452] */ @@ -143,18 +143,18 @@ APPLE_KEYBOARD_DESC APPLE_KEYBOARDS[] = { 0x26A, APPLE_KEYBOARD_TYPE_ANSI } }; -enum APPLE_KEYBOARD_TYPE mac_identify_keyboard_type(uint32_t vendorID, uint32_t productID) +static enum APPLE_KEYBOARD_TYPE mac_identify_keyboard_type(uint32_t vendorID, + uint32_t productID) { enum APPLE_KEYBOARD_TYPE type = APPLE_KEYBOARD_TYPE_ANSI; - + if (vendorID != 0x05AC) /* Apple, Inc. */ return type; - + if ((productID < 0x200) || (productID > 0x26A)) return type; - + type = APPLE_KEYBOARDS[productID - 0x200].Type; - return type; } @@ -165,35 +165,33 @@ enum APPLE_KEYBOARD_TYPE mac_detect_keyboard_type() IOHIDManagerRef tIOHIDManagerRef = NULL; IOHIDDeviceRef* tIOHIDDeviceRefs = nil; enum APPLE_KEYBOARD_TYPE type = APPLE_KEYBOARD_TYPE_ANSI; - - tIOHIDManagerRef = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); - + tIOHIDManagerRef = IOHIDManagerCreate(kCFAllocatorDefault, + kIOHIDOptionsTypeNone); + if (!tIOHIDManagerRef) return type; - + IOHIDManagerSetDeviceMatching(tIOHIDManagerRef, NULL); - IOReturn tIOReturn = IOHIDManagerOpen(tIOHIDManagerRef, kIOHIDOptionsTypeNone); - + if (noErr != tIOReturn) return type; - + deviceCFSetRef = IOHIDManagerCopyDevices(tIOHIDManagerRef); - + if (!deviceCFSetRef) return type; - + CFIndex deviceIndex, deviceCount = CFSetGetCount(deviceCFSetRef); - tIOHIDDeviceRefs = malloc(sizeof(IOHIDDeviceRef) * deviceCount); - + if (!tIOHIDDeviceRefs) return type; - + CFSetGetValues(deviceCFSetRef, (const void**) tIOHIDDeviceRefs); CFRelease(deviceCFSetRef); deviceCFSetRef = NULL; - + for (deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++) { CFTypeRef tCFTypeRef; @@ -201,29 +199,30 @@ enum APPLE_KEYBOARD_TYPE mac_detect_keyboard_type() uint32_t productID = 0; uint32_t countryCode = 0; enum APPLE_KEYBOARD_TYPE ltype; - + if (!tIOHIDDeviceRefs[deviceIndex]) continue; - + inIOHIDDeviceRef = tIOHIDDeviceRefs[deviceIndex]; - tCFTypeRef = IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDVendorIDKey)); - + if (tCFTypeRef) CFNumberGetValue((CFNumberRef) tCFTypeRef, kCFNumberSInt32Type, &vendorID); - - tCFTypeRef = IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDProductIDKey)); - + + tCFTypeRef = IOHIDDeviceGetProperty(inIOHIDDeviceRef, + CFSTR(kIOHIDProductIDKey)); + if (tCFTypeRef) CFNumberGetValue((CFNumberRef) tCFTypeRef, kCFNumberSInt32Type, &productID); - - tCFTypeRef = IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDCountryCodeKey)); - + + tCFTypeRef = IOHIDDeviceGetProperty(inIOHIDDeviceRef, + CFSTR(kIOHIDCountryCodeKey)); + if (tCFTypeRef) CFNumberGetValue((CFNumberRef) tCFTypeRef, kCFNumberSInt32Type, &countryCode); - + ltype = mac_identify_keyboard_type(vendorID, productID); - + if (ltype != APPLE_KEYBOARD_TYPE_ANSI) { type = ltype; @@ -238,9 +237,9 @@ enum APPLE_KEYBOARD_TYPE mac_detect_keyboard_type() CFRelease(deviceCFSetRef); deviceCFSetRef = NULL; } - + if (tIOHIDManagerRef) CFRelease(tIOHIDManagerRef); - + return type; } diff --git a/client/Mac/MRDPView.h b/client/Mac/MRDPView.h index 7231d0657..63cea7888 100644 --- a/client/Mac/MRDPView.h +++ b/client/Mac/MRDPView.h @@ -49,7 +49,6 @@ BOOL skipResizeOnce; BOOL saveInitialDragLoc; BOOL skipMoveWindowOnce; - @public NSPasteboard* pasteboard_rd; NSPasteboard* pasteboard_wr; @@ -62,12 +61,12 @@ - (void) setCursor: (NSCursor*) cursor; - (void) setScrollOffset:(int)xOffset y:(int)yOffset w:(int)width h:(int)height; -- (void) onPasteboardTimerFired :(NSTimer *) timer; +- (void) onPasteboardTimerFired :(NSTimer*) timer; - (void) pause; - (void) resume; - (void) releaseResources; -@property (assign) int is_connected; +@property(assign) int is_connected; @end @@ -83,8 +82,7 @@ BOOL mac_pre_connect(freerdp* instance); BOOL mac_post_connect(freerdp* instance); -BOOL mac_authenticate(freerdp* instance, char** username, char** password, char** domain); - -DWORD mac_client_thread(void* param); +BOOL mac_authenticate(freerdp* instance, char** username, char** password, + char** domain); #endif // MRDPVIEW_H diff --git a/client/Mac/MRDPView.m b/client/Mac/MRDPView.m index 278babdcd..a51e3e781 100644 --- a/client/Mac/MRDPView.m +++ b/client/Mac/MRDPView.m @@ -59,7 +59,7 @@ static BOOL mac_desktop_resize(rdpContext* context); static void update_activity_cb(freerdp* instance); static void input_activity_cb(freerdp* instance); -DWORD mac_client_thread(void* param); +static DWORD mac_client_thread(void* param); @implementation MRDPView @@ -69,19 +69,15 @@ DWORD mac_client_thread(void* param); { rdpSettings* settings; EmbedWindowEventArgs e; - [self initializeView]; - context = rdp_context; mfc = (mfContext*) rdp_context; instance = context->instance; settings = context->settings; - EventArgsInit(&e, "mfreerdp"); e.embed = TRUE; e.handle = (void*) self; PubSub_OnEmbedWindow(context->pubSub, context, &e); - NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; NSRect screenFrame = [screen frame]; @@ -99,7 +95,8 @@ DWORD mac_client_thread(void* param); mfc->client_height = instance->settings->DesktopHeight; mfc->client_width = instance->settings->DesktopWidth; - if (!(mfc->thread = CreateThread(NULL, 0, mac_client_thread, (void*) context, 0, &mfc->mainThreadId))) + if (!(mfc->thread = CreateThread(NULL, 0, mac_client_thread, (void*) context, 0, + &mfc->mainThreadId))) { WLog_ERR(TAG, "failed to create client thread"); return -1; @@ -108,58 +105,60 @@ DWORD mac_client_thread(void* param); return 0; } -DWORD mac_client_update_thread(void* param) +static DWORD mac_client_update_thread(void* param) { int status; wMessage message; wMessageQueue* queue; rdpContext* context = (rdpContext*) param; - status = 1; - queue = freerdp_get_message_queue(context->instance, FREERDP_UPDATE_MESSAGE_QUEUE); - + queue = freerdp_get_message_queue(context->instance, + FREERDP_UPDATE_MESSAGE_QUEUE); + while (MessageQueue_Wait(queue)) { while (MessageQueue_Peek(queue, &message, TRUE)) { - status = freerdp_message_queue_process_message(context->instance, FREERDP_UPDATE_MESSAGE_QUEUE, &message); - + status = freerdp_message_queue_process_message(context->instance, + FREERDP_UPDATE_MESSAGE_QUEUE, &message); + if (!status) break; } - + if (!status) break; } - + ExitThread(0); return 0; } -DWORD mac_client_input_thread(void* param) +static DWORD mac_client_input_thread(void* param) { int status; wMessage message; wMessageQueue* queue; rdpContext* context = (rdpContext*) param; - status = 1; - queue = freerdp_get_message_queue(context->instance, FREERDP_INPUT_MESSAGE_QUEUE); - + queue = freerdp_get_message_queue(context->instance, + FREERDP_INPUT_MESSAGE_QUEUE); + while (MessageQueue_Wait(queue)) { while (MessageQueue_Peek(queue, &message, TRUE)) { - status = freerdp_message_queue_process_message(context->instance, FREERDP_INPUT_MESSAGE_QUEUE, &message); - + status = freerdp_message_queue_process_message(context->instance, + FREERDP_INPUT_MESSAGE_QUEUE, &message); + if (!status) break; } - + if (!status) break; } - + ExitThread(0); return 0; } @@ -172,8 +171,6 @@ DWORD mac_client_thread(void* param) HANDLE events[16]; HANDLE inputEvent; HANDLE inputThread = NULL; - HANDLE updateEvent; - HANDLE updateThread = NULL; DWORD nCount; DWORD nCountTmp; DWORD nCountBase; @@ -182,42 +179,22 @@ DWORD mac_client_thread(void* param) freerdp* instance = context->instance; MRDPView* view = mfc->view; rdpSettings* settings = context->settings; - status = freerdp_connect(context->instance); - + if (!status) { [view setIs_connected:0]; return 0; } - + [view setIs_connected:1]; - nCount = 0; - events[nCount++] = mfc->stopEvent; - - if (settings->AsyncUpdate) - { - if (!(updateThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) mac_client_update_thread, context, 0, NULL))) - { - WLog_ERR(TAG, "failed to create async update thread"); - goto disconnect; - } - } - else - { - if (!(updateEvent = freerdp_get_message_queue_event_handle(instance, FREERDP_UPDATE_MESSAGE_QUEUE))) - { - WLog_ERR(TAG, "failed to get update event handle"); - goto disconnect; - } - events[nCount++] = updateEvent; - } - + if (settings->AsyncInput) { - if (!(inputThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) mac_client_input_thread, context, 0, NULL))) + if (!(inputThread = CreateThread(NULL, 0, + (LPTHREAD_START_ROUTINE) mac_client_input_thread, context, 0, NULL))) { WLog_ERR(TAG, "failed to create async input thread"); goto disconnect; @@ -225,11 +202,13 @@ DWORD mac_client_thread(void* param) } else { - if (!(inputEvent = freerdp_get_message_queue_event_handle(instance, FREERDP_INPUT_MESSAGE_QUEUE))) + if (!(inputEvent = freerdp_get_message_queue_event_handle(instance, + FREERDP_INPUT_MESSAGE_QUEUE))) { WLog_ERR(TAG, "failed to get input event handle"); goto disconnect; } + events[nCount++] = inputEvent; } @@ -241,11 +220,13 @@ DWORD mac_client_thread(void* param) if (!settings->AsyncTransport) { - if (!(nCountTmp = freerdp_get_event_handles(context, &events[nCount], 16 - nCount))) + if (!(nCountTmp = freerdp_get_event_handles(context, &events[nCount], + 16 - nCount))) { WLog_ERR(TAG, "freerdp_get_event_handles failed"); break; } + nCount += nCountTmp; } @@ -263,14 +244,6 @@ DWORD mac_client_thread(void* param) break; } - if (!settings->AsyncUpdate) - { - if (WaitForSingleObject(updateEvent, 0) == WAIT_OBJECT_0) - { - update_activity_cb(instance); - } - } - if (!settings->AsyncInput) { if (WaitForSingleObject(inputEvent, 0) == WAIT_OBJECT_0) @@ -289,29 +262,20 @@ DWORD mac_client_thread(void* param) } } -disconnect: - + disconnect: freerdp_disconnect(instance); - if (settings->AsyncUpdate && updateThread) - { - wMessageQueue* updateQueue = freerdp_get_message_queue(instance, FREERDP_UPDATE_MESSAGE_QUEUE); - if (updateQueue) - { - MessageQueue_PostQuit(updateQueue, 0); - WaitForSingleObject(updateThread, INFINITE); - } - CloseHandle(updateThread); - } - if (settings->AsyncInput && inputThread) { - wMessageQueue* inputQueue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE); + wMessageQueue* inputQueue = freerdp_get_message_queue(instance, + FREERDP_INPUT_MESSAGE_QUEUE); + if (inputQueue) { MessageQueue_PostQuit(inputQueue, 0); WaitForSingleObject(inputThread, INFINITE); } + CloseHandle(inputThread); } @@ -323,12 +287,12 @@ disconnect: - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; - + if (self) { // Initialization code here. } - + return self; } @@ -342,15 +306,14 @@ disconnect: if (!initialized) { cursors = [[NSMutableArray alloc] initWithCapacity:10]; - // setup a mouse tracking area - NSTrackingArea * trackingArea = [[NSTrackingArea alloc] initWithRect:[self visibleRect] options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingCursorUpdate | NSTrackingEnabledDuringMouseDrag | NSTrackingActiveWhenFirstResponder owner:self userInfo:nil]; - + NSTrackingArea* trackingArea = [[NSTrackingArea alloc] initWithRect:[self + visibleRect] options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | + NSTrackingCursorUpdate | NSTrackingEnabledDuringMouseDrag | + NSTrackingActiveWhenFirstResponder owner:self userInfo:nil]; [self addTrackingArea:trackingArea]; - // Set the default cursor currentCursor = [NSCursor arrowCursor]; - initialized = YES; } } @@ -371,144 +334,136 @@ disconnect: return YES; } -- (void) mouseMoved:(NSEvent *)event +- (void) mouseMoved:(NSEvent*)event { [super mouseMoved:event]; - + if (!is_connected) return; - + NSPoint loc = [event locationInWindow]; int x = (int) loc.x; int y = (int) loc.y; - mf_scale_mouse_event(context, instance->input, PTR_FLAGS_MOVE, x, y); } -- (void)mouseDown:(NSEvent *) event +- (void)mouseDown:(NSEvent*) event { [super mouseDown:event]; - + if (!is_connected) return; - + NSPoint loc = [event locationInWindow]; int x = (int) loc.x; int y = (int) loc.y; - - mf_scale_mouse_event(context, instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1, x, y); + mf_scale_mouse_event(context, instance->input, + PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1, x, y); } -- (void) mouseUp:(NSEvent *) event +- (void) mouseUp:(NSEvent*) event { [super mouseUp:event]; - + if (!is_connected) return; - + NSPoint loc = [event locationInWindow]; int x = (int) loc.x; int y = (int) loc.y; - mf_scale_mouse_event(context, instance->input, PTR_FLAGS_BUTTON1, x, y); } -- (void) rightMouseDown:(NSEvent *)event +- (void) rightMouseDown:(NSEvent*)event { [super rightMouseDown:event]; - + if (!is_connected) return; - + NSPoint loc = [event locationInWindow]; int x = (int) loc.x; int y = (int) loc.y; - - mf_scale_mouse_event(context, instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2, x, y); + mf_scale_mouse_event(context, instance->input, + PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2, x, y); } -- (void) rightMouseUp:(NSEvent *)event +- (void) rightMouseUp:(NSEvent*)event { [super rightMouseUp:event]; - + if (!is_connected) return; - + NSPoint loc = [event locationInWindow]; int x = (int) loc.x; int y = (int) loc.y; - mf_scale_mouse_event(context, instance->input, PTR_FLAGS_BUTTON2, x, y); } -- (void) otherMouseDown:(NSEvent *)event +- (void) otherMouseDown:(NSEvent*)event { [super otherMouseDown:event]; - + if (!is_connected) return; - + NSPoint loc = [event locationInWindow]; int x = (int) loc.x; int y = (int) loc.y; - - mf_scale_mouse_event(context, instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON3, x, y); + mf_scale_mouse_event(context, instance->input, + PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON3, x, y); } -- (void) otherMouseUp:(NSEvent *)event +- (void) otherMouseUp:(NSEvent*)event { [super otherMouseUp:event]; - + if (!is_connected) return; - + NSPoint loc = [event locationInWindow]; int x = (int) loc.x; int y = (int) loc.y; - mf_scale_mouse_event(context, instance->input, PTR_FLAGS_BUTTON3, x, y); } -- (void) scrollWheel:(NSEvent *)event +- (void) scrollWheel:(NSEvent*)event { UINT16 flags; - [super scrollWheel:event]; - + if (!is_connected) return; - + NSPoint loc = [event locationInWindow]; int x = (int) loc.x; int y = (int) loc.y; - flags = PTR_FLAGS_WHEEL; - /* 1 event = 120 units */ int units = [event deltaY] * 120; /* send out all accumulated rotations */ - while(units != 0) + while (units != 0) { /* limit to maximum value in WheelRotationMask (9bit signed value) */ int step = MIN(MAX(-256, units), 255); - - mf_scale_mouse_event(context, instance->input, flags | ((UINT16)step & WheelRotationMask), x, y); + mf_scale_mouse_event(context, instance->input, + flags | ((UINT16)step & WheelRotationMask), x, y); units -= step; } } -- (void) mouseDragged:(NSEvent *)event +- (void) mouseDragged:(NSEvent*)event { [super mouseDragged:event]; - + if (!is_connected) return; - + NSPoint loc = [event locationInWindow]; int x = (int) loc.x; int y = (int) loc.y; - // send mouse motion event to RDP server mf_scale_mouse_event(context, instance->input, PTR_FLAGS_MOVE, x, y); } @@ -536,7 +491,6 @@ DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type) * provided by OS X and check for a character to key code mismatch: for instance, * when the output character is '0' for the key code corresponding to the 'i' key. */ - #if 0 switch (keyChar) { @@ -544,18 +498,21 @@ DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type) case 0x00A7: /* section sign */ if (keyCode == APPLE_VK_ISO_Section) keyCode = APPLE_VK_ANSI_Grave; + break; - + case 0x00ED: /* latin small letter i with acute */ case 0x00CD: /* latin capital letter i with acute */ if (keyCode == APPLE_VK_ANSI_Grave) keyCode = APPLE_VK_ISO_Section; + break; } + #endif - + /* Perform keycode correction for all ISO keyboards */ - + if (type == APPLE_KEYBOARD_TYPE_ISO) { if (keyCode == APPLE_VK_ANSI_Grave) @@ -563,11 +520,11 @@ DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type) else if (keyCode == APPLE_VK_ISO_Section) keyCode = APPLE_VK_ANSI_Grave; } - + return keyCode; } -- (void) keyDown:(NSEvent *) event +- (void) keyDown:(NSEvent*) event { DWORD keyCode; DWORD keyFlags; @@ -575,36 +532,34 @@ DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type) DWORD scancode; unichar keyChar; NSString* characters; - + if (!is_connected) return; - + keyFlags = KBD_FLAGS_DOWN; keyCode = [event keyCode]; - characters = [event charactersIgnoringModifiers]; - + if ([characters length] > 0) { keyChar = [characters characterAtIndex:0]; keyCode = fixKeyCode(keyCode, keyChar, mfc->appleKeyboardType); } - + vkcode = GetVirtualKeyCodeFromKeycode(keyCode + 8, KEYCODE_TYPE_APPLE); scancode = GetVirtualScanCodeFromVirtualKeyCode(vkcode, 4); keyFlags |= (scancode & KBDEXT) ? KBDEXT : 0; scancode &= 0xFF; vkcode &= 0xFF; - #if 0 - WLog_ERR(TAG, "keyDown: keyCode: 0x%04X scancode: 0x%04X vkcode: 0x%04X keyFlags: %d name: %s", - keyCode, scancode, vkcode, keyFlags, GetVirtualKeyName(vkcode)); + WLog_ERR(TAG, + "keyDown: keyCode: 0x%04X scancode: 0x%04X vkcode: 0x%04X keyFlags: %d name: %s", + keyCode, scancode, vkcode, keyFlags, GetVirtualKeyName(vkcode)); #endif - freerdp_input_send_keyboard_event(instance->input, keyFlags, scancode); } -- (void) keyUp:(NSEvent *) event +- (void) keyUp:(NSEvent*) event { DWORD keyCode; DWORD keyFlags; @@ -618,9 +573,8 @@ DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type) keyFlags = KBD_FLAGS_RELEASE; keyCode = [event keyCode]; - characters = [event charactersIgnoringModifiers]; - + if ([characters length] > 0) { keyChar = [characters characterAtIndex:0]; @@ -632,12 +586,11 @@ DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type) keyFlags |= (scancode & KBDEXT) ? KBDEXT : 0; scancode &= 0xFF; vkcode &= 0xFF; - #if 0 - WLog_DBG(TAG, "keyUp: key: 0x%04X scancode: 0x%04X vkcode: 0x%04X keyFlags: %d name: %s", - keyCode, scancode, vkcode, keyFlags, GetVirtualKeyName(vkcode)); + WLog_DBG(TAG, + "keyUp: key: 0x%04X scancode: 0x%04X vkcode: 0x%04X keyFlags: %d name: %s", + keyCode, scancode, vkcode, keyFlags, GetVirtualKeyName(vkcode)); #endif - freerdp_input_send_keyboard_event(instance->input, keyFlags, scancode); } @@ -655,16 +608,15 @@ DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type) keyFlags = 0; key = [event keyCode] + 8; modFlags = [event modifierFlags] & NSDeviceIndependentModifierFlagsMask; - vkcode = GetVirtualKeyCodeFromKeycode(key, KEYCODE_TYPE_APPLE); scancode = GetVirtualScanCodeFromVirtualKeyCode(vkcode, 4); keyFlags |= (scancode & KBDEXT) ? KBDEXT : 0; scancode &= 0xFF; vkcode &= 0xFF; - #if 0 - WLog_DBG(TAG, "flagsChanged: key: 0x%04X scancode: 0x%04X vkcode: 0x%04X extended: %d name: %s modFlags: 0x%04X", - key - 8, scancode, vkcode, keyFlags, GetVirtualKeyName(vkcode), modFlags); + WLog_DBG(TAG, + "flagsChanged: key: 0x%04X scancode: 0x%04X vkcode: 0x%04X extended: %d name: %s modFlags: 0x%04X", + key - 8, scancode, vkcode, keyFlags, GetVirtualKeyName(vkcode), modFlags); if (modFlags & NSAlphaShiftKeyMask) WLog_DBG(TAG, "NSAlphaShiftKeyMask"); @@ -686,42 +638,59 @@ DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type) if (modFlags & NSHelpKeyMask) WLog_DBG(TAG, "NSHelpKeyMask"); + #endif if ((modFlags & NSAlphaShiftKeyMask) && !(kbdModFlags & NSAlphaShiftKeyMask)) - freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_DOWN, scancode); - else if (!(modFlags & NSAlphaShiftKeyMask) && (kbdModFlags & NSAlphaShiftKeyMask)) - freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_RELEASE, scancode); + freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_DOWN, + scancode); + else if (!(modFlags & NSAlphaShiftKeyMask) + && (kbdModFlags & NSAlphaShiftKeyMask)) + freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_RELEASE, + scancode); if ((modFlags & NSShiftKeyMask) && !(kbdModFlags & NSShiftKeyMask)) - freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_DOWN, scancode); + freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_DOWN, + scancode); else if (!(modFlags & NSShiftKeyMask) && (kbdModFlags & NSShiftKeyMask)) - freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_RELEASE, scancode); + freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_RELEASE, + scancode); if ((modFlags & NSControlKeyMask) && !(kbdModFlags & NSControlKeyMask)) - freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_DOWN, scancode); + freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_DOWN, + scancode); else if (!(modFlags & NSControlKeyMask) && (kbdModFlags & NSControlKeyMask)) - freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_RELEASE, scancode); + freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_RELEASE, + scancode); if ((modFlags & NSAlternateKeyMask) && !(kbdModFlags & NSAlternateKeyMask)) - freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_DOWN, scancode); + freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_DOWN, + scancode); else if (!(modFlags & NSAlternateKeyMask) && (kbdModFlags & NSAlternateKeyMask)) - freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_RELEASE, scancode); + freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_RELEASE, + scancode); if ((modFlags & NSCommandKeyMask) && !(kbdModFlags & NSCommandKeyMask)) - freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_DOWN, scancode); + freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_DOWN, + scancode); else if (!(modFlags & NSCommandKeyMask) && (kbdModFlags & NSCommandKeyMask)) - freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_RELEASE, scancode); + freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_RELEASE, + scancode); if ((modFlags & NSNumericPadKeyMask) && !(kbdModFlags & NSNumericPadKeyMask)) - freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_DOWN, scancode); - else if (!(modFlags & NSNumericPadKeyMask) && (kbdModFlags & NSNumericPadKeyMask)) - freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_RELEASE, scancode); + freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_DOWN, + scancode); + else if (!(modFlags & NSNumericPadKeyMask) + && (kbdModFlags & NSNumericPadKeyMask)) + freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_RELEASE, + scancode); if ((modFlags & NSHelpKeyMask) && !(kbdModFlags & NSHelpKeyMask)) - freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_DOWN, scancode); + freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_DOWN, + scancode); else if (!(modFlags & NSHelpKeyMask) && (kbdModFlags & NSHelpKeyMask)) - freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_RELEASE, scancode); + freerdp_input_send_keyboard_event(instance->input, keyFlags | KBD_FLAGS_RELEASE, + scancode); kbdModFlags = modFlags; } @@ -737,7 +706,6 @@ DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type) return; gdi_free(context->instance); - free(pixel_data); } @@ -745,20 +713,17 @@ DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type) { if (!context) return; - + if (self->bitmap_context) { CGContextRef cgContext = [[NSGraphicsContext currentContext] graphicsPort]; CGImageRef cgImage = CGBitmapContextCreateImage(self->bitmap_context); - CGContextSaveGState(cgContext); - - CGContextClipToRect(cgContext, CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)); - - CGContextDrawImage(cgContext, CGRectMake(0, 0, [self bounds].size.width, [self bounds].size.height), cgImage); - + CGContextClipToRect(cgContext, CGRectMake(rect.origin.x, rect.origin.y, + rect.size.width, rect.size.height)); + CGContextDrawImage(cgContext, CGRectMake(0, + 0, [self bounds].size.width, [self bounds].size.height), cgImage); CGContextRestoreGState(cgContext); - CGImageRelease(cgImage); } else @@ -779,68 +744,60 @@ DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type) NSData* formatData; const char* formatType; NSPasteboardItem* item; - changeCount = (int) [pasteboard_rd changeCount]; - + if (changeCount == pasteboard_changecount) return; - + pasteboard_changecount = changeCount; - NSArray* items = [pasteboard_rd pasteboardItems]; - + if ([items count] < 1) return; - + item = [items objectAtIndex:0]; - /** * System-Declared Uniform Type Identifiers: * https://developer.apple.com/library/ios/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html */ - formatMatch = FALSE; - - for (NSString* type in [item types]) + + for (NSString * type in [item types]) { formatType = [type UTF8String]; - + if (strcmp(formatType, "public.utf8-plain-text") == 0) { formatData = [item dataForType:type]; formatId = ClipboardRegisterFormat(mfc->clipboard, "UTF8_STRING"); - /* length does not include null terminator */ - size = (UINT32) [formatData length]; data = (BYTE*) malloc(size + 1); [formatData getBytes:data length:size]; data[size] = '\0'; size++; - ClipboardSetData(mfc->clipboard, formatId, (void*) data, size); formatMatch = TRUE; - break; } } - + if (!formatMatch) ClipboardEmpty(mfc->clipboard); - + if (mfc->clipboardSync) mac_cliprdr_send_client_format_list(mfc->cliprdr); } - (void) pause { - dispatch_async(dispatch_get_main_queue(), ^{ + dispatch_async(dispatch_get_main_queue(), ^ + { [self->pasteboard_timer invalidate]; }); - NSArray* trackingAreas = self.trackingAreas; - - for (NSTrackingArea* ta in trackingAreas) + + for (NSTrackingArea * ta in trackingAreas) { [self removeTrackingArea:ta]; } @@ -848,11 +805,14 @@ DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type) - (void)resume { - dispatch_async(dispatch_get_main_queue(), ^{ + dispatch_async(dispatch_get_main_queue(), ^ + { self->pasteboard_timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(onPasteboardTimerFired:) userInfo:nil repeats:YES]; }); - - NSTrackingArea * trackingArea = [[NSTrackingArea alloc] initWithRect:[self visibleRect] options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingCursorUpdate | NSTrackingEnabledDuringMouseDrag | NSTrackingActiveWhenFirstResponder owner:self userInfo:nil]; + NSTrackingArea* trackingArea = [[NSTrackingArea alloc] initWithRect:[self + visibleRect] options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | + NSTrackingCursorUpdate | NSTrackingEnabledDuringMouseDrag | + NSTrackingActiveWhenFirstResponder owner:self userInfo:nil]; [self addTrackingArea:trackingArea]; [trackingArea release]; } @@ -865,14 +825,14 @@ DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type) mfc->client_width = width; } -void mac_OnChannelConnectedEventHandler(rdpContext* context, ChannelConnectedEventArgs* e) +void mac_OnChannelConnectedEventHandler(rdpContext* context, + ChannelConnectedEventArgs* e) { rdpSettings* settings = context->settings; mfContext* mfc = (mfContext*) context; - + if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0) { - } else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0) { @@ -885,23 +845,23 @@ void mac_OnChannelConnectedEventHandler(rdpContext* context, ChannelConnectedEve } else if (strcmp(e->name, ENCOMSP_SVC_CHANNEL_NAME) == 0) { - } } -void mac_OnChannelDisconnectedEventHandler(rdpContext* context, ChannelDisconnectedEventArgs* e) +void mac_OnChannelDisconnectedEventHandler(rdpContext* context, + ChannelDisconnectedEventArgs* e) { rdpSettings* settings = context->settings; mfContext* mfc = (mfContext*) context; - + if (strcmp(e->name, RDPEI_DVC_CHANNEL_NAME) == 0) { - } else if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0) { if (settings->SoftwareGdi) - gdi_graphics_pipeline_uninit(context->gdi, (RdpgfxClientContext*) e->pInterface); + gdi_graphics_pipeline_uninit(context->gdi, + (RdpgfxClientContext*) e->pInterface); } else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0) { @@ -909,32 +869,28 @@ void mac_OnChannelDisconnectedEventHandler(rdpContext* context, ChannelDisconnec } else if (strcmp(e->name, ENCOMSP_SVC_CHANNEL_NAME) == 0) { - } } BOOL mac_pre_connect(freerdp* instance) { rdpSettings* settings; - instance->update->BeginPaint = mac_begin_paint; instance->update->EndPaint = mac_end_paint; instance->update->DesktopResize = mac_desktop_resize; - settings = instance->settings; if (!settings->ServerHostname) { - WLog_ERR(TAG, "error: server hostname was not specified with /v:[:port]"); + WLog_ERR(TAG, + "error: server hostname was not specified with /v:[:port]"); [NSApp terminate:nil]; return -1; } settings->SoftwareGdi = TRUE; - settings->OsMajorType = OSMAJORTYPE_MACINTOSH; settings->OsMinorType = OSMINORTYPE_MACINTOSH; - ZeroMemory(settings->OrderSupport, 32); settings->OrderSupport[NEG_DSTBLT_INDEX] = TRUE; settings->OrderSupport[NEG_PATBLT_INDEX] = TRUE; @@ -949,7 +905,8 @@ BOOL mac_pre_connect(freerdp* instance) settings->OrderSupport[NEG_LINETO_INDEX] = TRUE; settings->OrderSupport[NEG_POLYLINE_INDEX] = TRUE; settings->OrderSupport[NEG_MEMBLT_INDEX] = settings->BitmapCacheEnabled; - settings->OrderSupport[NEG_MEM3BLT_INDEX] = (settings->SoftwareGdi) ? TRUE : FALSE; + settings->OrderSupport[NEG_MEM3BLT_INDEX] = (settings->SoftwareGdi) ? TRUE : + FALSE; settings->OrderSupport[NEG_MEMBLT_V2_INDEX] = settings->BitmapCacheEnabled; settings->OrderSupport[NEG_MEM3BLT_V2_INDEX] = FALSE; settings->OrderSupport[NEG_SAVEBITMAP_INDEX] = FALSE; @@ -960,19 +917,19 @@ BOOL mac_pre_connect(freerdp* instance) settings->OrderSupport[NEG_POLYGON_CB_INDEX] = FALSE; settings->OrderSupport[NEG_ELLIPSE_SC_INDEX] = FALSE; settings->OrderSupport[NEG_ELLIPSE_CB_INDEX] = FALSE; - PubSub_SubscribeChannelConnected(instance->context->pubSub, - (pChannelConnectedEventHandler) mac_OnChannelConnectedEventHandler); - + (pChannelConnectedEventHandler) mac_OnChannelConnectedEventHandler); PubSub_SubscribeChannelDisconnected(instance->context->pubSub, - (pChannelDisconnectedEventHandler) mac_OnChannelDisconnectedEventHandler); + (pChannelDisconnectedEventHandler) mac_OnChannelDisconnectedEventHandler); - if (!freerdp_client_load_addins(instance->context->channels, instance->settings)) + if (!freerdp_client_load_addins(instance->context->channels, + instance->settings)) return FALSE; - if (freerdp_channels_pre_connect(instance->context->channels, instance) != CHANNEL_RC_OK) + if (freerdp_channels_pre_connect(instance->context->channels, + instance) != CHANNEL_RC_OK) return FALSE; - + return TRUE; } @@ -982,9 +939,7 @@ BOOL mac_post_connect(freerdp* instance) rdpSettings* settings; rdpPointer rdp_pointer; mfContext* mfc = (mfContext*) instance->context; - MRDPView* view = (MRDPView*) mfc->view; - ZeroMemory(&rdp_pointer, sizeof(rdpPointer)); rdp_pointer.size = sizeof(rdpPointer); rdp_pointer.New = mf_Pointer_New; @@ -992,59 +947,58 @@ BOOL mac_post_connect(freerdp* instance) rdp_pointer.Set = mf_Pointer_Set; rdp_pointer.SetNull = mf_Pointer_SetNull; rdp_pointer.SetDefault = mf_Pointer_SetDefault; - settings = instance->settings; - if (!gdi_init(instance, PIXEL_FORMAT_XRGB32)) + if (!gdi_init(instance, PIXEL_FORMAT_BGRX32)) return FALSE; - - gdi = instance->context->gdi; + gdi = instance->context->gdi; view->bitmap_context = mac_create_bitmap_context(instance->context); - pointer_cache_register_callbacks(instance->update); graphics_register_pointer(instance->context->graphics, &rdp_pointer); - if (freerdp_channels_post_connect(instance->context->channels, instance) != CHANNEL_RC_OK) + if (freerdp_channels_post_connect(instance->context->channels, + instance) != CHANNEL_RC_OK) return FALSE; /* setup pasteboard (aka clipboard) for copy operations (write only) */ view->pasteboard_wr = [NSPasteboard generalPasteboard]; - /* setup pasteboard for read operations */ - dispatch_async(dispatch_get_main_queue(), ^{ + dispatch_async(dispatch_get_main_queue(), ^ + { view->pasteboard_rd = [NSPasteboard generalPasteboard]; view->pasteboard_changecount = -1; }); - [view resume]; - mfc->appleKeyboardType = mac_detect_keyboard_type(); - return TRUE; } -BOOL mac_authenticate(freerdp* instance, char** username, char** password, char** domain) +BOOL mac_authenticate(freerdp* instance, char** username, char** password, + char** domain) { PasswordDialog* dialog = [PasswordDialog new]; - - dialog.serverHostname = [NSString stringWithCString:instance->settings->ServerHostname encoding:NSUTF8StringEncoding]; + dialog.serverHostname = [NSString stringWithCString: + instance->settings->ServerHostname encoding:NSUTF8StringEncoding]; if (*username) - dialog.username = [NSString stringWithCString:*username encoding:NSUTF8StringEncoding]; + dialog.username = [NSString stringWithCString:*username encoding: + NSUTF8StringEncoding]; if (*password) - dialog.password = [NSString stringWithCString:*password encoding:NSUTF8StringEncoding]; + dialog.password = [NSString stringWithCString:*password encoding: + NSUTF8StringEncoding]; BOOL ok = [dialog runModal]; if (ok) { - const char* submittedUsername = [dialog.username cStringUsingEncoding:NSUTF8StringEncoding]; + const char* submittedUsername = [dialog.username cStringUsingEncoding: + NSUTF8StringEncoding]; *username = malloc((strlen(submittedUsername) + 1) * sizeof(char)); strcpy(*username, submittedUsername); - - const char* submittedPassword = [dialog.password cStringUsingEncoding:NSUTF8StringEncoding]; + const char* submittedPassword = [dialog.password cStringUsingEncoding: + NSUTF8StringEncoding]; *password = malloc((strlen(submittedPassword) + 1) * sizeof(char)); strcpy(*password, submittedPassword); } @@ -1054,6 +1008,7 @@ BOOL mac_authenticate(freerdp* instance, char** username, char** password, char* BOOL mf_Pointer_New(rdpContext* context, rdpPointer* pointer) { + rdpGdi* gdi; NSRect rect; NSImage* image; NSPoint hotSpot; @@ -1063,24 +1018,36 @@ BOOL mf_Pointer_New(rdpContext* context, rdpPointer* pointer) NSBitmapImageRep* bmiRep; MRDPCursor* mrdpCursor = [[MRDPCursor alloc] init]; mfContext* mfc = (mfContext*) context; - MRDPView* view = (MRDPView*) mfc->view; - + MRDPView* view; + UINT32 format; + + if (!mfc || !context || !pointer) + return FALSE; + + view = (MRDPView*) mfc->view; + gdi = context->gdi; + + if (!gdi || !view) + return FALSE; + rect.size.width = pointer->width; rect.size.height = pointer->height; rect.origin.x = pointer->xPos; rect.origin.y = pointer->yPos; - cursor_data = (BYTE*) malloc(rect.size.width * rect.size.height * 4); + if (!cursor_data) return FALSE; + mrdpCursor->cursor_data = cursor_data; + format = PIXEL_FORMAT_RGBA32; if (freerdp_image_copy_from_pointer_data( - cursor_data, PIXEL_FORMAT_ARGB32, - pointer->width * 4, 0, 0, pointer->width, pointer->height, - pointer->xorMaskData, pointer->lengthXorMask, - pointer->andMaskData, pointer->lengthAndMask, - pointer->xorBpp, NULL) < 0) + cursor_data, format, + 0, 0, 0, pointer->width, pointer->height, + pointer->xorMaskData, pointer->lengthXorMask, + pointer->andMaskData, pointer->lengthAndMask, + pointer->xorBpp, NULL) < 0) { free(cursor_data); mrdpCursor->cursor_data = NULL; @@ -1088,33 +1055,30 @@ BOOL mf_Pointer_New(rdpContext* context, rdpPointer* pointer) } /* store cursor bitmap image in representation - required by NSImage */ - bmiRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:(unsigned char **) &cursor_data - pixelsWide:rect.size.width - pixelsHigh:rect.size.height - bitsPerSample:8 - samplesPerPixel:4 - hasAlpha:YES - isPlanar:NO - colorSpaceName:NSDeviceRGBColorSpace - bitmapFormat:0 - bytesPerRow:rect.size.width * 4 - bitsPerPixel:0]; + bmiRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: + (unsigned char**) &cursor_data + pixelsWide:rect.size.width + pixelsHigh:rect.size.height + bitsPerSample:8 + samplesPerPixel:4 + hasAlpha:YES + isPlanar:NO + colorSpaceName:NSDeviceRGBColorSpace + bitmapFormat:0 + bytesPerRow:rect.size.width * GetBytesPerPixel(format) + bitsPerPixel:0]; mrdpCursor->bmiRep = bmiRep; - /* create an image using above representation */ image = [[NSImage alloc] initWithSize:[bmiRep size]]; [image addRepresentation: bmiRep]; [image setFlipped:NO]; mrdpCursor->nsImage = image; - /* need hotspot to create cursor */ hotSpot.x = pointer->xPos; hotSpot.y = pointer->yPos; - cursor = [[NSCursor alloc] initWithImage: image hotSpot:hotSpot]; mrdpCursor->nsCursor = cursor; mrdpCursor->pointer = pointer; - /* save cursor for later use in mf_Pointer_Set() */ ma = view->cursors; [ma addObject:mrdpCursor]; @@ -1126,8 +1090,8 @@ void mf_Pointer_Free(rdpContext* context, rdpPointer* pointer) mfContext* mfc = (mfContext*) context; MRDPView* view = (MRDPView*) mfc->view; NSMutableArray* ma = view->cursors; - - for (MRDPCursor* cursor in ma) + + for (MRDPCursor * cursor in ma) { if (cursor->pointer == pointer) { @@ -1145,10 +1109,9 @@ BOOL mf_Pointer_Set(rdpContext* context, const rdpPointer* pointer) { mfContext* mfc = (mfContext*) context; MRDPView* view = (MRDPView*) mfc->view; - NSMutableArray* ma = view->cursors; - for (MRDPCursor* cursor in ma) + for (MRDPCursor * cursor in ma) { if (cursor->pointer == pointer) { @@ -1178,35 +1141,33 @@ CGContextRef mac_create_bitmap_context(rdpContext* context) { CGContextRef bitmap_context; rdpGdi* gdi = context->gdi; - UINT32 bpp = GetBytesPerPixel(gdi->dstFormat); - + UINT32 bpp = GetBytesPerPixel(gdi->dstFormat); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); - + if (bpp == 2) { bitmap_context = CGBitmapContextCreate(gdi->primary_buffer, - gdi->width, gdi->height, 5, gdi->stride, - colorSpace, kCGBitmapByteOrder16Little | kCGImageAlphaNoneSkipFirst); + gdi->width, gdi->height, 5, gdi->stride, + colorSpace, kCGBitmapByteOrder16Little | kCGImageAlphaNoneSkipFirst); } else { bitmap_context = CGBitmapContextCreate(gdi->primary_buffer, - gdi->width, gdi->height, 8, gdi->stride, - colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst); + gdi->width, gdi->height, 8, gdi->stride, + colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst); } - + CGColorSpaceRelease(colorSpace); - return bitmap_context; } BOOL mac_begin_paint(rdpContext* context) { rdpGdi* gdi = context->gdi; - + if (!gdi) return FALSE; - + gdi->primary->hdc->hwnd->invalid->null = 1; return TRUE; } @@ -1219,12 +1180,11 @@ BOOL mac_end_paint(rdpContext* context) int ww, wh, dw, dh; mfContext* mfc = (mfContext*) context; MRDPView* view = (MRDPView*) mfc->view; - gdi = context->gdi; - + if (!gdi) return FALSE; - + ww = mfc->client_width; wh = mfc->client_height; dw = mfc->context.settings->DesktopWidth; @@ -1232,12 +1192,11 @@ BOOL mac_end_paint(rdpContext* context) if ((!context) || (!context->gdi)) return FALSE; - + if (context->gdi->primary->hdc->hwnd->invalid->null) return TRUE; invalid = gdi->primary->hdc->hwnd->invalid; - newDrawRect.origin.x = invalid->x; newDrawRect.origin.y = invalid->y; newDrawRect.size.width = invalid->w; @@ -1259,9 +1218,7 @@ BOOL mac_end_paint(rdpContext* context) } windows_to_apple_cords(mfc->view, &newDrawRect); - [view setNeedsDisplayInRect:newDrawRect]; - gdi->primary->hdc->hwnd->ninvalid = 0; return TRUE; } @@ -1272,39 +1229,32 @@ BOOL mac_desktop_resize(rdpContext* context) mfContext* mfc = (mfContext*) context; MRDPView* view = (MRDPView*) mfc->view; rdpSettings* settings = context->settings; - /** * TODO: Fix resizing race condition. We should probably implement a message to be * put on the update message queue to be able to properly flush pending updates, * resize, and then continue with post-resizing graphical updates. */ - CGContextRef old_context = view->bitmap_context; view->bitmap_context = NULL; CGContextRelease(old_context); - mfc->width = settings->DesktopWidth; mfc->height = settings->DesktopHeight; - + if (!gdi_resize(context->gdi, mfc->width, mfc->height)) return FALSE; - + view->bitmap_context = mac_create_bitmap_context(context); - + if (!view->bitmap_context) return FALSE; - + mfc->client_width = mfc->width; mfc->client_height = mfc->height; - [view setFrameSize:NSMakeSize(mfc->width, mfc->height)]; - EventArgsInit(&e, "mfreerdp"); e.width = settings->DesktopWidth; e.height = settings->DesktopHeight; - PubSub_OnResizeWindow(context->pubSub, context, &e); - return TRUE; } @@ -1313,16 +1263,16 @@ void update_activity_cb(freerdp* instance) int status; wMessage message; wMessageQueue* queue; - status = 1; queue = freerdp_get_message_queue(instance, FREERDP_UPDATE_MESSAGE_QUEUE); - + if (queue) { while (MessageQueue_Peek(queue, &message, TRUE)) { - status = freerdp_message_queue_process_message(instance, FREERDP_UPDATE_MESSAGE_QUEUE, &message); - + status = freerdp_message_queue_process_message(instance, + FREERDP_UPDATE_MESSAGE_QUEUE, &message); + if (!status) break; } @@ -1338,7 +1288,6 @@ void input_activity_cb(freerdp* instance) int status; wMessage message; wMessageQueue* queue; - status = 1; queue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE); @@ -1346,7 +1295,8 @@ void input_activity_cb(freerdp* instance) { while (MessageQueue_Peek(queue, &message, TRUE)) { - status = freerdp_message_queue_process_message(instance, FREERDP_INPUT_MESSAGE_QUEUE, &message); + status = freerdp_message_queue_process_message(instance, + FREERDP_INPUT_MESSAGE_QUEUE, &message); if (!status) break; diff --git a/client/Mac/mf_client.m b/client/Mac/mf_client.m index 18fe41c46..009af9165 100644 --- a/client/Mac/mf_client.m +++ b/client/Mac/mf_client.m @@ -30,18 +30,17 @@ * Client Interface */ -BOOL mfreerdp_client_global_init() +static BOOL mfreerdp_client_global_init() { freerdp_handle_signals(); return TRUE; } -void mfreerdp_client_global_uninit() +static void mfreerdp_client_global_uninit() { - } -int mfreerdp_client_start(rdpContext* context) +static int mfreerdp_client_start(rdpContext* context) { MRDPView* view; mfContext* mfc = (mfContext*) context; @@ -49,7 +48,8 @@ int mfreerdp_client_start(rdpContext* context) if (mfc->view == NULL) { // view not specified beforehand. Create view dynamically - mfc->view = [[MRDPView alloc] initWithFrame : NSMakeRect(0, 0, context->settings->DesktopWidth, context->settings->DesktopHeight)]; + mfc->view = [[MRDPView alloc] initWithFrame : NSMakeRect(0, 0, + context->settings->DesktopWidth, context->settings->DesktopHeight)]; mfc->view_ownership = TRUE; } @@ -57,10 +57,10 @@ int mfreerdp_client_start(rdpContext* context) return [view rdpStart:context]; } -int mfreerdp_client_stop(rdpContext* context) +static int mfreerdp_client_stop(rdpContext* context) { mfContext* mfc = (mfContext*) context; - + if (mfc->thread) { SetEvent(mfc->stopEvent); @@ -68,7 +68,7 @@ int mfreerdp_client_stop(rdpContext* context) CloseHandle(mfc->thread); mfc->thread = NULL; } - + if (mfc->view_ownership) { MRDPView* view = (MRDPView*) mfc->view; @@ -80,41 +80,41 @@ int mfreerdp_client_stop(rdpContext* context) return 0; } -BOOL mfreerdp_client_new(freerdp* instance, rdpContext* context) +static BOOL mfreerdp_client_new(freerdp* instance, rdpContext* context) +{ + mfContext* mfc; + rdpSettings* settings; + mfc = (mfContext*) instance->context; + mfc->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + context->instance->PreConnect = mac_pre_connect; + context->instance->PostConnect = mac_post_connect; + context->instance->Authenticate = mac_authenticate; + context->channels = freerdp_channels_new(); + settings = instance->settings; + settings->AsyncTransport = TRUE; + settings->AsyncUpdate = TRUE; + settings->AsyncInput = TRUE; + return TRUE; +} + +static void mfreerdp_client_free(freerdp* instance, rdpContext* context) { mfContext* mfc; rdpSettings* settings; + if (!instance || !context) + return; + mfc = (mfContext*) instance->context; - - mfc->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - - context->instance->PreConnect = mac_pre_connect; - context->instance->PostConnect = mac_post_connect; - context->instance->Authenticate = mac_authenticate; - - context->channels = freerdp_channels_new(); - - settings = instance->settings; - - settings->AsyncTransport = TRUE; - settings->AsyncUpdate = TRUE; - settings->AsyncInput = TRUE; - - return TRUE; + CloseHandle(mfc->stopEvent); } -void mfreerdp_client_free(freerdp* instance, rdpContext* context) -{ - -} - -void freerdp_client_mouse_event(rdpContext* cfc, DWORD flags, int x, int y) +static void freerdp_client_mouse_event(rdpContext* cfc, DWORD flags, int x, + int y) { int width, height; rdpInput* input = cfc->instance->input; rdpSettings* settings = cfc->instance->settings; - width = settings->DesktopWidth; height = settings->DesktopHeight; @@ -132,30 +132,28 @@ void freerdp_client_mouse_event(rdpContext* cfc, DWORD flags, int x, int y) input->MouseEvent(input, flags, x, y); } -void mf_scale_mouse_event(void* context, rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) +void mf_scale_mouse_event(void* context, rdpInput* input, UINT16 flags, + UINT16 x, UINT16 y) { mfContext* mfc = (mfContext*) context; MRDPView* view = (MRDPView*) mfc->view; - int ww, wh, dw, dh; - ww = mfc->client_width; wh = mfc->client_height; dw = mfc->context.settings->DesktopWidth; dh = mfc->context.settings->DesktopHeight; - // Convert to windows coordinates y = [view frame].size.height - y; - + if (!mfc->context.settings->SmartSizing || ((ww == dw) && (wh == dh))) { y = y + mfc->yCurrentScroll; - + if (wh != dh) { y -= (dh - wh); } - + input->MouseEvent(input, flags, x + mfc->xCurrentScroll, y); } else @@ -169,16 +167,12 @@ int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints) { pEntryPoints->Version = 1; pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1); - pEntryPoints->GlobalInit = mfreerdp_client_global_init; pEntryPoints->GlobalUninit = mfreerdp_client_global_uninit; - pEntryPoints->ContextSize = sizeof(mfContext); pEntryPoints->ClientNew = mfreerdp_client_new; pEntryPoints->ClientFree = mfreerdp_client_free; - pEntryPoints->ClientStart = mfreerdp_client_start; pEntryPoints->ClientStop = mfreerdp_client_stop; - return 0; } diff --git a/client/Mac/mfreerdp.h b/client/Mac/mfreerdp.h index ed34655fd..96598e44f 100644 --- a/client/Mac/mfreerdp.h +++ b/client/Mac/mfreerdp.h @@ -54,16 +54,9 @@ struct mf_context HANDLE stopEvent; HANDLE keyboardThread; enum APPLE_KEYBOARD_TYPE appleKeyboardType; - - HGDI_DC hdc; - UINT16 srcBpp; - UINT16 dstBpp; - freerdp* instance; DWORD mainThreadId; - DWORD keyboardThreadId; - BOOL disconnect; - BOOL sw_gdi; + DWORD keyboardThreadId; BOOL clipboardSync; wClipboard* clipboard;