2013-02-22 08:52:51 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* MacFreeRDP
|
|
|
|
*
|
|
|
|
* Copyright 2012 Thomas Goddard
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2012-05-03 07:15:27 +04:00
|
|
|
|
2013-07-18 00:04:55 +04:00
|
|
|
#include <winpr/windows.h>
|
|
|
|
|
2013-06-18 20:03:22 +04:00
|
|
|
#include "mf_client.h"
|
2013-06-18 22:30:21 +04:00
|
|
|
#import "mfreerdp.h"
|
2012-05-03 07:15:27 +04:00
|
|
|
#import "MRDPView.h"
|
|
|
|
#import "MRDPCursor.h"
|
2013-03-11 05:32:05 +04:00
|
|
|
#import "PasswordDialog.h"
|
2013-03-11 07:14:40 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/input.h>
|
2014-03-04 01:57:43 +04:00
|
|
|
#include <winpr/synch.h>
|
|
|
|
#include <winpr/sysinfo.h>
|
2013-03-11 07:14:40 +04:00
|
|
|
|
2013-03-11 05:35:06 +04:00
|
|
|
#include <freerdp/constants.h>
|
2012-05-03 07:15:27 +04:00
|
|
|
|
2013-05-31 20:48:40 +04:00
|
|
|
#import "freerdp/freerdp.h"
|
|
|
|
#import "freerdp/types.h"
|
|
|
|
#import "freerdp/channels/channels.h"
|
|
|
|
#import "freerdp/gdi/gdi.h"
|
2013-12-11 23:31:54 +04:00
|
|
|
#import "freerdp/gdi/dc.h"
|
|
|
|
#import "freerdp/gdi/region.h"
|
2013-05-31 20:48:40 +04:00
|
|
|
#import "freerdp/graphics.h"
|
|
|
|
#import "freerdp/utils/event.h"
|
|
|
|
#import "freerdp/client/cliprdr.h"
|
|
|
|
#import "freerdp/client/file.h"
|
|
|
|
#import "freerdp/client/cmdline.h"
|
|
|
|
|
|
|
|
void mf_Pointer_New(rdpContext* context, rdpPointer* pointer);
|
|
|
|
void mf_Pointer_Free(rdpContext* context, rdpPointer* pointer);
|
|
|
|
void mf_Pointer_Set(rdpContext* context, rdpPointer* pointer);
|
|
|
|
void mf_Pointer_SetNull(rdpContext* context);
|
|
|
|
void mf_Pointer_SetDefault(rdpContext* context);
|
2014-03-04 01:57:43 +04:00
|
|
|
|
2013-05-31 20:48:40 +04:00
|
|
|
void mac_begin_paint(rdpContext* context);
|
|
|
|
void mac_end_paint(rdpContext* context);
|
2014-03-04 01:57:43 +04:00
|
|
|
void mac_desktop_resize(rdpContext* context);
|
|
|
|
|
2013-07-18 23:41:28 +04:00
|
|
|
static void update_activity_cb(freerdp* instance);
|
|
|
|
static void input_activity_cb(freerdp* instance);
|
|
|
|
static void channel_activity_cb(freerdp* instance);
|
2014-03-04 01:57:43 +04:00
|
|
|
|
2013-05-31 20:48:40 +04:00
|
|
|
int process_plugin_args(rdpSettings* settings, const char* name, RDP_PLUGIN_DATA* plugin_data, void* user_data);
|
|
|
|
int receive_channel_data(freerdp* instance, int chan_id, BYTE* data, int size, int flags, int total_size);
|
2013-06-18 00:44:44 +04:00
|
|
|
|
2013-05-31 20:48:40 +04:00
|
|
|
void process_cliprdr_event(freerdp* instance, wMessage* event);
|
|
|
|
void cliprdr_process_cb_format_list_event(freerdp* instance, RDP_CB_FORMAT_LIST_EVENT* event);
|
|
|
|
void cliprdr_send_data_request(freerdp* instance, UINT32 format);
|
|
|
|
void cliprdr_process_cb_monitor_ready_event(freerdp* inst);
|
|
|
|
void cliprdr_process_cb_data_response_event(freerdp* instance, RDP_CB_DATA_RESPONSE_EVENT* event);
|
|
|
|
void cliprdr_process_text(freerdp* instance, BYTE* data, int len);
|
|
|
|
void cliprdr_send_supported_format_list(freerdp* instance);
|
2013-06-18 05:21:42 +04:00
|
|
|
int register_channel_fds(int* fds, int count, freerdp* instance);
|
2013-05-31 20:48:40 +04:00
|
|
|
|
2013-07-18 23:41:28 +04:00
|
|
|
DWORD mac_client_thread(void* param);
|
2013-07-18 00:04:55 +04:00
|
|
|
|
2013-05-31 20:48:40 +04:00
|
|
|
struct cursor
|
|
|
|
{
|
|
|
|
rdpPointer* pointer;
|
|
|
|
BYTE* cursor_data;
|
|
|
|
void* bmiRep; /* NSBitmapImageRep */
|
|
|
|
void* nsCursor; /* NSCursor */
|
|
|
|
void* nsImage; /* NSImage */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rgba_data
|
|
|
|
{
|
|
|
|
char red;
|
|
|
|
char green;
|
|
|
|
char blue;
|
|
|
|
char alpha;
|
|
|
|
};
|
|
|
|
|
2012-05-03 07:15:27 +04:00
|
|
|
@implementation MRDPView
|
|
|
|
|
|
|
|
@synthesize is_connected;
|
|
|
|
|
2013-06-23 06:55:51 +04:00
|
|
|
- (int) rdpStart:(rdpContext*) rdp_context
|
2013-05-31 20:48:40 +04:00
|
|
|
{
|
2013-06-18 05:21:42 +04:00
|
|
|
rdpSettings* settings;
|
2013-06-23 04:27:23 +04:00
|
|
|
EmbedWindowEventArgs e;
|
2013-06-18 22:30:21 +04:00
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
[self initializeView];
|
2013-06-26 21:45:12 +04:00
|
|
|
|
2013-06-23 06:55:51 +04:00
|
|
|
context = rdp_context;
|
|
|
|
mfc = (mfContext*) rdp_context;
|
|
|
|
instance = context->instance;
|
2013-06-18 22:30:21 +04:00
|
|
|
settings = context->settings;
|
2013-06-20 19:47:28 +04:00
|
|
|
|
2013-06-23 04:27:23 +04:00
|
|
|
EventArgsInit(&e, "mfreerdp");
|
|
|
|
e.embed = TRUE;
|
|
|
|
e.handle = (void*) self;
|
|
|
|
PubSub_OnEmbedWindow(context->pubSub, context, &e);
|
|
|
|
|
2014-03-04 01:57:43 +04:00
|
|
|
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
|
2013-09-21 19:37:39 +04:00
|
|
|
NSRect screenFrame = [screen frame];
|
|
|
|
|
2014-03-04 01:57:43 +04:00
|
|
|
if (instance->settings->Fullscreen)
|
2013-09-21 19:37:39 +04:00
|
|
|
{
|
|
|
|
instance->settings->DesktopWidth = screenFrame.size.width;
|
|
|
|
instance->settings->DesktopHeight = screenFrame.size.height;
|
|
|
|
}
|
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
mfc->client_height = instance->settings->DesktopHeight;
|
|
|
|
mfc->client_width = instance->settings->DesktopWidth;
|
2013-06-23 04:27:23 +04:00
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
mfc->thread = CreateThread(NULL, 0, mac_client_thread, (void*) context, 0, &mfc->mainThreadId);
|
2013-07-18 00:04:55 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-04 01:57:43 +04:00
|
|
|
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);
|
|
|
|
|
|
|
|
while (MessageQueue_Wait(queue))
|
|
|
|
{
|
|
|
|
while (MessageQueue_Peek(queue, &message, TRUE))
|
|
|
|
{
|
|
|
|
status = freerdp_message_queue_process_message(context->instance, FREERDP_UPDATE_MESSAGE_QUEUE, &message);
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExitThread(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
while (MessageQueue_Wait(queue))
|
|
|
|
{
|
|
|
|
while (MessageQueue_Peek(queue, &message, TRUE))
|
|
|
|
{
|
|
|
|
status = freerdp_message_queue_process_message(context->instance, FREERDP_INPUT_MESSAGE_QUEUE, &message);
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ExitThread(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD mac_client_channels_thread(void* param)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
wMessage* event;
|
|
|
|
HANDLE channelsEvent;
|
|
|
|
rdpChannels* channels;
|
|
|
|
rdpContext* context = (rdpContext*) param;
|
|
|
|
|
|
|
|
channels = context->channels;
|
|
|
|
channelsEvent = freerdp_channels_get_event_handle(context->instance);
|
|
|
|
|
|
|
|
while (WaitForSingleObject(channelsEvent, INFINITE) == WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
status = freerdp_channels_process_pending_messages(context->instance);
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
break;
|
|
|
|
|
|
|
|
event = freerdp_channels_pop_event(context->channels);
|
|
|
|
|
|
|
|
if (event)
|
|
|
|
{
|
|
|
|
switch (GetMessageClass(event->id))
|
|
|
|
{
|
|
|
|
case CliprdrChannel_Class:
|
|
|
|
process_cliprdr_event(context->instance, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
freerdp_event_free(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ExitThread(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-18 23:41:28 +04:00
|
|
|
DWORD mac_client_thread(void* param)
|
2013-07-18 00:04:55 +04:00
|
|
|
{
|
2013-07-22 23:33:30 +04:00
|
|
|
@autoreleasepool
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
HANDLE events[4];
|
2014-03-04 01:57:43 +04:00
|
|
|
HANDLE inputEvent;
|
|
|
|
HANDLE inputThread;
|
|
|
|
HANDLE updateEvent;
|
|
|
|
HANDLE updateThread;
|
|
|
|
HANDLE channelsEvent;
|
|
|
|
HANDLE channelsThread;
|
2013-07-22 23:33:30 +04:00
|
|
|
|
|
|
|
DWORD nCount;
|
|
|
|
rdpContext* context = (rdpContext*) param;
|
|
|
|
mfContext* mfc = (mfContext*) context;
|
|
|
|
freerdp* instance = context->instance;
|
|
|
|
MRDPView* view = mfc->view;
|
2013-11-05 20:49:42 +04:00
|
|
|
rdpSettings* settings = context->settings;
|
2013-07-22 23:33:30 +04:00
|
|
|
|
|
|
|
status = freerdp_connect(context->instance);
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
{
|
|
|
|
[view setIs_connected:0];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
[view setIs_connected:1];
|
|
|
|
|
|
|
|
nCount = 0;
|
|
|
|
|
|
|
|
events[nCount++] = mfc->stopEvent;
|
|
|
|
|
2013-11-05 20:49:42 +04:00
|
|
|
if (settings->AsyncUpdate)
|
2013-07-22 23:33:30 +04:00
|
|
|
{
|
2014-03-04 01:57:43 +04:00
|
|
|
updateThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) mac_client_update_thread, context, 0, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
events[nCount++] = updateEvent = freerdp_get_message_queue_event_handle(instance, FREERDP_UPDATE_MESSAGE_QUEUE);
|
2013-07-22 23:33:30 +04:00
|
|
|
}
|
|
|
|
|
2013-11-05 20:49:42 +04:00
|
|
|
if (settings->AsyncInput)
|
2013-07-22 23:33:30 +04:00
|
|
|
{
|
2014-03-04 01:57:43 +04:00
|
|
|
inputThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) mac_client_input_thread, context, 0, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
events[nCount++] = inputEvent = freerdp_get_message_queue_event_handle(instance, FREERDP_INPUT_MESSAGE_QUEUE);
|
2013-07-22 23:33:30 +04:00
|
|
|
}
|
|
|
|
|
2013-11-05 20:49:42 +04:00
|
|
|
if (settings->AsyncChannels)
|
2013-07-22 23:33:30 +04:00
|
|
|
{
|
2014-03-04 01:57:43 +04:00
|
|
|
channelsThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) mac_client_channels_thread, context, 0, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
events[nCount++] = channelsEvent = freerdp_channels_get_event_handle(instance);
|
2013-07-22 23:33:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
|
|
|
|
|
|
|
|
if (WaitForSingleObject(mfc->stopEvent, 0) == WAIT_OBJECT_0)
|
|
|
|
{
|
2013-11-05 20:49:42 +04:00
|
|
|
freerdp_disconnect(instance);
|
2013-07-22 23:33:30 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-04 01:57:43 +04:00
|
|
|
if (!settings->AsyncUpdate)
|
2013-07-22 23:33:30 +04:00
|
|
|
{
|
2014-03-04 01:57:43 +04:00
|
|
|
if (WaitForSingleObject(updateEvent, 0) == WAIT_OBJECT_0)
|
2013-07-22 23:33:30 +04:00
|
|
|
{
|
|
|
|
update_activity_cb(instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-04 01:57:43 +04:00
|
|
|
if (!settings->AsyncInput)
|
2013-07-22 23:33:30 +04:00
|
|
|
{
|
2014-03-04 01:57:43 +04:00
|
|
|
if (WaitForSingleObject(inputEvent, 0) == WAIT_OBJECT_0)
|
2013-07-22 23:33:30 +04:00
|
|
|
{
|
|
|
|
input_activity_cb(instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-04 01:57:43 +04:00
|
|
|
if (!settings->AsyncChannels)
|
2013-07-22 23:33:30 +04:00
|
|
|
{
|
2014-03-04 01:57:43 +04:00
|
|
|
if (WaitForSingleObject(channelsEvent, 0) == WAIT_OBJECT_0)
|
2013-07-22 23:33:30 +04:00
|
|
|
{
|
|
|
|
channel_activity_cb(instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-04 01:57:43 +04:00
|
|
|
if (settings->AsyncUpdate)
|
|
|
|
{
|
|
|
|
wMessageQueue* updateQueue = freerdp_get_message_queue(instance, FREERDP_UPDATE_MESSAGE_QUEUE);
|
|
|
|
MessageQueue_PostQuit(updateQueue, 0);
|
|
|
|
WaitForSingleObject(updateThread, INFINITE);
|
|
|
|
CloseHandle(updateThread);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings->AsyncInput)
|
|
|
|
{
|
|
|
|
wMessageQueue* inputQueue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE);
|
|
|
|
MessageQueue_PostQuit(inputQueue, 0);
|
|
|
|
WaitForSingleObject(inputThread, INFINITE);
|
|
|
|
CloseHandle(inputThread);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings->AsyncChannels)
|
|
|
|
{
|
|
|
|
WaitForSingleObject(channelsThread, INFINITE);
|
|
|
|
CloseHandle(channelsThread);
|
|
|
|
}
|
|
|
|
|
2013-07-22 23:33:30 +04:00
|
|
|
ExitThread(0);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-05-31 20:48:40 +04:00
|
|
|
}
|
|
|
|
|
2012-05-03 07:15:27 +04:00
|
|
|
- (id)initWithFrame:(NSRect)frame
|
|
|
|
{
|
2013-10-08 00:43:23 +04:00
|
|
|
self = [super initWithFrame:frame];
|
2013-02-22 07:04:09 +04:00
|
|
|
|
|
|
|
if (self)
|
|
|
|
{
|
2013-02-22 06:42:47 +04:00
|
|
|
// Initialization code here.
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-06-26 00:05:37 +04:00
|
|
|
- (void) viewDidLoad
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-10-08 00:43:23 +04:00
|
|
|
[self initializeView];
|
2013-06-26 21:45:12 +04:00
|
|
|
}
|
2013-06-23 04:27:23 +04:00
|
|
|
|
2013-06-26 21:45:12 +04:00
|
|
|
- (void) initializeView
|
|
|
|
{
|
2013-10-08 00:43:23 +04:00
|
|
|
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];
|
2013-06-26 21:45:12 +04:00
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
[self addTrackingArea:trackingArea];
|
2013-06-26 21:45:12 +04:00
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
// Set the default cursor
|
|
|
|
currentCursor = [NSCursor arrowCursor];
|
2013-06-26 21:45:12 +04:00
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
initialized = YES;
|
|
|
|
}
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-07-16 20:16:44 +04:00
|
|
|
- (void) setCursor: (NSCursor*) cursor
|
|
|
|
{
|
2013-10-08 00:43:23 +04:00
|
|
|
self->currentCursor = cursor;
|
|
|
|
[[self window] invalidateCursorRectsForView:self];
|
2013-07-16 20:16:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) resetCursorRects
|
|
|
|
{
|
2013-10-08 00:43:23 +04:00
|
|
|
[self addCursorRect:[self visibleRect] cursor:currentCursor];
|
2013-07-16 20:16:44 +04:00
|
|
|
}
|
|
|
|
|
2013-02-22 06:42:47 +04:00
|
|
|
- (BOOL)acceptsFirstResponder
|
|
|
|
{
|
|
|
|
return YES;
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-02-22 06:42:47 +04:00
|
|
|
- (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;
|
2013-10-01 22:30:06 +04:00
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
mf_scale_mouse_event(context, instance->input, PTR_FLAGS_MOVE, x, y);
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseDown:(NSEvent *) event
|
|
|
|
{
|
2013-02-22 06:42:47 +04:00
|
|
|
[super mouseDown:event];
|
|
|
|
|
|
|
|
if (!is_connected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSPoint loc = [event locationInWindow];
|
|
|
|
int x = (int) loc.x;
|
|
|
|
int y = (int) loc.y;
|
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
mf_scale_mouse_event(context, instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1, x, y);
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseUp:(NSEvent *) event
|
|
|
|
{
|
2013-02-22 06:42:47 +04:00
|
|
|
[super mouseUp:event];
|
|
|
|
|
|
|
|
if (!is_connected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSPoint loc = [event locationInWindow];
|
|
|
|
int x = (int) loc.x;
|
|
|
|
int y = (int) loc.y;
|
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
mf_scale_mouse_event(context, instance->input, PTR_FLAGS_BUTTON1, x, y);
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) rightMouseDown:(NSEvent *)event
|
|
|
|
{
|
2013-02-22 06:42:47 +04:00
|
|
|
[super rightMouseDown:event];
|
|
|
|
|
|
|
|
if (!is_connected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSPoint loc = [event locationInWindow];
|
|
|
|
int x = (int) loc.x;
|
|
|
|
int y = (int) loc.y;
|
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
mf_scale_mouse_event(context, instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2, x, y);
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) rightMouseUp:(NSEvent *)event
|
|
|
|
{
|
2013-02-22 06:42:47 +04:00
|
|
|
[super rightMouseUp:event];
|
|
|
|
|
|
|
|
if (!is_connected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSPoint loc = [event locationInWindow];
|
|
|
|
int x = (int) loc.x;
|
|
|
|
int y = (int) loc.y;
|
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
mf_scale_mouse_event(context, instance->input, PTR_FLAGS_BUTTON2, x, y);
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) otherMouseDown:(NSEvent *)event
|
|
|
|
{
|
2013-02-22 06:42:47 +04:00
|
|
|
[super otherMouseDown:event];
|
|
|
|
|
|
|
|
if (!is_connected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSPoint loc = [event locationInWindow];
|
|
|
|
int x = (int) loc.x;
|
|
|
|
int y = (int) loc.y;
|
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
mf_scale_mouse_event(context, instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON3, x, y);
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) otherMouseUp:(NSEvent *)event
|
|
|
|
{
|
2013-02-22 06:42:47 +04:00
|
|
|
[super otherMouseUp:event];
|
|
|
|
|
|
|
|
if (!is_connected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSPoint loc = [event locationInWindow];
|
|
|
|
int x = (int) loc.x;
|
|
|
|
int y = (int) loc.y;
|
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
mf_scale_mouse_event(context, instance->input, PTR_FLAGS_BUTTON3, x, y);
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) scrollWheel:(NSEvent *)event
|
|
|
|
{
|
2013-02-22 08:07:35 +04:00
|
|
|
UINT16 flags;
|
2013-02-22 06:42:47 +04:00
|
|
|
|
|
|
|
[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;
|
2013-09-22 02:07:27 +04:00
|
|
|
|
|
|
|
/* 1 event = 120 units */
|
|
|
|
int units = [event deltaY] * 120;
|
|
|
|
|
|
|
|
/* send out all accumulated rotations */
|
|
|
|
while(units != 0)
|
|
|
|
{
|
|
|
|
/* limit to maximum value in WheelRotationMask (9bit signed value) */
|
|
|
|
int step = MIN(MAX(-256, units), 255);
|
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
mf_scale_mouse_event(context, instance->input, flags | ((UINT16)step & WheelRotationMask), x, y);
|
2013-09-22 02:07:27 +04:00
|
|
|
units -= step;
|
|
|
|
}
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseDragged:(NSEvent *)event
|
|
|
|
{
|
2013-02-22 06:42:47 +04:00
|
|
|
[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
|
2013-10-08 00:43:23 +04:00
|
|
|
mf_scale_mouse_event(context, instance->input, PTR_FLAGS_MOVE, x, y);
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2014-03-04 23:01:01 +04:00
|
|
|
DWORD fixKeyCode(DWORD keyCode, unichar keyChar, enum APPLE_KEYBOARD_TYPE type)
|
2014-01-29 01:23:42 +04:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* In 99% of cases, the given key code is truly keyboard independent.
|
|
|
|
* This function handles the remaining 1% of edge cases.
|
|
|
|
*
|
|
|
|
* Hungarian Keyboard: This is 'QWERTZ' and not 'QWERTY'.
|
|
|
|
* The '0' key is on the left of the '1' key, where '~' is on a US keyboard.
|
|
|
|
* A special 'i' letter key with acute is found on the right of the left shift key.
|
|
|
|
* On the hungarian keyboard, the 'i' key is at the left of the 'Y' key
|
|
|
|
* Some international keyboards have a corresponding key which would be at
|
|
|
|
* the left of the 'Z' key when using a QWERTY layout.
|
|
|
|
*
|
|
|
|
* The Apple Hungarian keyboard sends inverted key codes for the '0' and 'i' keys.
|
|
|
|
* When using the US keyboard layout, key codes are left as-is (inverted).
|
|
|
|
* When using the Hungarian keyboard layout, key codes are swapped (non-inverted).
|
|
|
|
* This means that when using the Hungarian keyboard layout with a US keyboard,
|
|
|
|
* the keys corresponding to '0' and 'i' will effectively be inverted.
|
|
|
|
*
|
|
|
|
* To fix the '0' and 'i' key inversion, we use the corresponding output character
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-03-04 23:01:01 +04:00
|
|
|
#if 0
|
2014-01-29 01:23:42 +04:00
|
|
|
switch (keyChar)
|
|
|
|
{
|
|
|
|
case '0':
|
|
|
|
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;
|
|
|
|
}
|
2014-03-04 23:01:01 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Perform keycode correction for all ISO keyboards */
|
|
|
|
|
|
|
|
if (type == APPLE_KEYBOARD_TYPE_ISO)
|
|
|
|
{
|
|
|
|
if (keyCode == APPLE_VK_ANSI_Grave)
|
|
|
|
keyCode = APPLE_VK_ISO_Section;
|
|
|
|
else if (keyCode == APPLE_VK_ISO_Section)
|
|
|
|
keyCode = APPLE_VK_ANSI_Grave;
|
|
|
|
}
|
2014-01-29 01:23:42 +04:00
|
|
|
|
|
|
|
return keyCode;
|
|
|
|
}
|
|
|
|
|
2012-05-03 07:15:27 +04:00
|
|
|
- (void) keyDown:(NSEvent *) event
|
|
|
|
{
|
2014-01-29 01:23:42 +04:00
|
|
|
DWORD keyCode;
|
2013-10-08 00:43:23 +04:00
|
|
|
DWORD keyFlags;
|
2013-03-11 07:14:40 +04:00
|
|
|
DWORD vkcode;
|
|
|
|
DWORD scancode;
|
2014-01-29 01:23:42 +04:00
|
|
|
unichar keyChar;
|
|
|
|
NSString* characters;
|
2013-02-22 06:42:47 +04:00
|
|
|
|
2013-02-22 07:04:09 +04:00
|
|
|
if (!is_connected)
|
2013-02-22 06:42:47 +04:00
|
|
|
return;
|
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
keyFlags = KBD_FLAGS_DOWN;
|
2014-01-29 01:23:42 +04:00
|
|
|
keyCode = [event keyCode];
|
2013-03-11 07:14:40 +04:00
|
|
|
|
2014-01-29 01:23:42 +04:00
|
|
|
characters = [event charactersIgnoringModifiers];
|
|
|
|
|
|
|
|
if ([characters length] > 0)
|
|
|
|
{
|
|
|
|
keyChar = [characters characterAtIndex:0];
|
2014-03-04 23:01:01 +04:00
|
|
|
keyCode = fixKeyCode(keyCode, keyChar, mfc->appleKeyboardType);
|
2014-01-29 01:23:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
vkcode = GetVirtualKeyCodeFromKeycode(keyCode + 8, KEYCODE_TYPE_APPLE);
|
2013-03-11 07:14:40 +04:00
|
|
|
scancode = GetVirtualScanCodeFromVirtualKeyCode(vkcode, 4);
|
2013-10-08 00:43:23 +04:00
|
|
|
keyFlags |= (scancode & KBDEXT) ? KBDEXT : 0;
|
|
|
|
scancode &= 0xFF;
|
|
|
|
vkcode &= 0xFF;
|
2014-01-29 01:23:42 +04:00
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
#if 0
|
2014-01-29 01:23:42 +04:00
|
|
|
fprintf(stderr, "keyDown: keyCode: 0x%04X scancode: 0x%04X vkcode: 0x%04X keyFlags: %d name: %s\n",
|
|
|
|
keyCode, scancode, vkcode, keyFlags, GetVirtualKeyName(vkcode));
|
2013-10-08 00:43:23 +04:00
|
|
|
#endif
|
2013-03-11 07:14:40 +04:00
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
freerdp_input_send_keyboard_event(instance->input, keyFlags, scancode);
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) keyUp:(NSEvent *) event
|
|
|
|
{
|
2014-01-29 01:23:42 +04:00
|
|
|
DWORD keyCode;
|
2013-10-08 00:43:23 +04:00
|
|
|
DWORD keyFlags;
|
2013-03-11 07:14:40 +04:00
|
|
|
DWORD vkcode;
|
|
|
|
DWORD scancode;
|
2014-01-29 01:23:42 +04:00
|
|
|
unichar keyChar;
|
|
|
|
NSString* characters;
|
2013-10-08 00:43:23 +04:00
|
|
|
|
2013-02-22 07:04:09 +04:00
|
|
|
if (!is_connected)
|
2013-02-22 06:42:47 +04:00
|
|
|
return;
|
2013-10-08 00:43:23 +04:00
|
|
|
|
|
|
|
keyFlags = KBD_FLAGS_RELEASE;
|
2014-01-29 01:23:42 +04:00
|
|
|
keyCode = [event keyCode];
|
|
|
|
|
|
|
|
characters = [event charactersIgnoringModifiers];
|
|
|
|
|
|
|
|
if ([characters length] > 0)
|
|
|
|
{
|
|
|
|
keyChar = [characters characterAtIndex:0];
|
2014-03-04 23:01:01 +04:00
|
|
|
keyCode = fixKeyCode(keyCode, keyChar, mfc->appleKeyboardType);
|
2014-01-29 01:23:42 +04:00
|
|
|
}
|
2013-10-08 00:43:23 +04:00
|
|
|
|
2014-01-29 01:23:42 +04:00
|
|
|
vkcode = GetVirtualKeyCodeFromKeycode(keyCode + 8, KEYCODE_TYPE_APPLE);
|
2013-03-11 07:14:40 +04:00
|
|
|
scancode = GetVirtualScanCodeFromVirtualKeyCode(vkcode, 4);
|
2013-10-08 00:43:23 +04:00
|
|
|
keyFlags |= (scancode & KBDEXT) ? KBDEXT : 0;
|
|
|
|
scancode &= 0xFF;
|
|
|
|
vkcode &= 0xFF;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
fprintf(stderr, "keyUp: key: 0x%04X scancode: 0x%04X vkcode: 0x%04X keyFlags: %d name: %s\n",
|
2014-01-29 01:23:42 +04:00
|
|
|
keyCode, scancode, vkcode, keyFlags, GetVirtualKeyName(vkcode));
|
2013-10-08 00:43:23 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
freerdp_input_send_keyboard_event(instance->input, keyFlags, scancode);
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
- (void) flagsChanged:(NSEvent*) event
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-10-08 00:43:23 +04:00
|
|
|
int key;
|
|
|
|
DWORD keyFlags;
|
|
|
|
DWORD vkcode;
|
|
|
|
DWORD scancode;
|
|
|
|
DWORD modFlags;
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
if (!is_connected)
|
2013-02-22 06:42:47 +04:00
|
|
|
return;
|
2013-10-08 00:43:23 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
fprintf(stderr, "flagsChanged: key: 0x%04X scancode: 0x%04X vkcode: 0x%04X extended: %d name: %s modFlags: 0x%04X\n",
|
|
|
|
key - 8, scancode, vkcode, keyFlags, GetVirtualKeyName(vkcode), modFlags);
|
|
|
|
|
|
|
|
if (modFlags & NSAlphaShiftKeyMask)
|
|
|
|
fprintf(stderr, "NSAlphaShiftKeyMask\n");
|
|
|
|
|
|
|
|
if (modFlags & NSShiftKeyMask)
|
|
|
|
fprintf(stderr, "NSShiftKeyMask\n");
|
|
|
|
|
|
|
|
if (modFlags & NSControlKeyMask)
|
|
|
|
fprintf(stderr, "NSControlKeyMask\n");
|
|
|
|
|
|
|
|
if (modFlags & NSAlternateKeyMask)
|
|
|
|
fprintf(stderr, "NSAlternateKeyMask\n");
|
|
|
|
|
|
|
|
if (modFlags & NSCommandKeyMask)
|
|
|
|
fprintf(stderr, "NSCommandKeyMask\n");
|
|
|
|
|
|
|
|
if (modFlags & NSNumericPadKeyMask)
|
|
|
|
fprintf(stderr, "NSNumericPadKeyMask\n");
|
|
|
|
|
|
|
|
if (modFlags & NSHelpKeyMask)
|
|
|
|
fprintf(stderr, "NSHelpKeyMask\n");
|
|
|
|
#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);
|
|
|
|
|
|
|
|
if ((modFlags & NSShiftKeyMask) && !(kbdModFlags & NSShiftKeyMask))
|
|
|
|
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);
|
|
|
|
|
|
|
|
if ((modFlags & NSControlKeyMask) && !(kbdModFlags & NSControlKeyMask))
|
|
|
|
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);
|
|
|
|
|
|
|
|
if ((modFlags & NSAlternateKeyMask) && !(kbdModFlags & NSAlternateKeyMask))
|
|
|
|
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);
|
|
|
|
|
|
|
|
if ((modFlags & NSCommandKeyMask) && !(kbdModFlags & NSCommandKeyMask))
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if ((modFlags & NSHelpKeyMask) && !(kbdModFlags & NSHelpKeyMask))
|
|
|
|
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);
|
|
|
|
|
|
|
|
kbdModFlags = modFlags;
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) releaseResources
|
|
|
|
{
|
2013-02-22 06:42:47 +04:00
|
|
|
int i;
|
2013-07-18 23:41:28 +04:00
|
|
|
|
2013-02-22 06:42:47 +04:00
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (argv[i])
|
|
|
|
free(argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_connected)
|
|
|
|
return;
|
|
|
|
|
2013-11-22 22:38:42 +04:00
|
|
|
gdi_free(context->instance);
|
|
|
|
|
2013-02-22 06:42:47 +04:00
|
|
|
freerdp_channels_global_uninit();
|
|
|
|
|
|
|
|
if (pixel_data)
|
|
|
|
free(pixel_data);
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-03-11 05:35:06 +04:00
|
|
|
- (void) drawRect:(NSRect)rect
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-06-23 06:55:51 +04:00
|
|
|
if (!context)
|
2013-02-22 06:42:47 +04:00
|
|
|
return;
|
2014-03-04 01:57:43 +04:00
|
|
|
|
2013-06-23 06:55:51 +04:00
|
|
|
if (self->bitmap_context)
|
2013-10-08 00:43:23 +04:00
|
|
|
{
|
2013-06-23 06:55:51 +04:00
|
|
|
CGContextRef cgContext = [[NSGraphicsContext currentContext] graphicsPort];
|
2013-06-23 04:27:23 +04:00
|
|
|
CGImageRef cgImage = CGBitmapContextCreateImage(self->bitmap_context);
|
2014-03-04 01:57:43 +04:00
|
|
|
|
|
|
|
CGContextSaveGState(cgContext);
|
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
CGContextClipToRect(cgContext, CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height));
|
2013-06-23 04:27:23 +04:00
|
|
|
|
2014-03-04 01:57:43 +04:00
|
|
|
CGContextDrawImage(cgContext, CGRectMake(0, 0, [self bounds].size.width, [self bounds].size.height), cgImage);
|
|
|
|
|
|
|
|
CGContextRestoreGState(cgContext);
|
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
CGImageRelease(cgImage);
|
|
|
|
}
|
2013-06-23 04:27:23 +04:00
|
|
|
else
|
|
|
|
{
|
2014-03-04 01:57:43 +04:00
|
|
|
/* Fill the screen with black */
|
2013-09-28 01:36:53 +04:00
|
|
|
[[NSColor blackColor] set];
|
2013-06-23 04:27:23 +04:00
|
|
|
NSRectFill([self bounds]);
|
|
|
|
}
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
- (void) onPasteboardTimerFired :(NSTimer*) timer
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-02-22 08:07:35 +04:00
|
|
|
int i;
|
|
|
|
NSArray* types;
|
2013-02-22 06:42:47 +04:00
|
|
|
|
|
|
|
i = (int) [pasteboard_rd changeCount];
|
2013-02-22 07:04:09 +04:00
|
|
|
|
2013-02-22 06:42:47 +04:00
|
|
|
if (i != pasteboard_changecount)
|
|
|
|
{
|
|
|
|
pasteboard_changecount = i;
|
|
|
|
types = [NSArray arrayWithObject:NSStringPboardType];
|
|
|
|
NSString *str = [pasteboard_rd availableTypeFromArray:types];
|
|
|
|
if (str != nil)
|
|
|
|
{
|
2013-06-23 06:55:51 +04:00
|
|
|
cliprdr_send_supported_format_list(instance);
|
2013-02-22 06:42:47 +04:00
|
|
|
}
|
|
|
|
}
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-10-02 18:24:01 +04:00
|
|
|
- (void) setScrollOffset:(int)xOffset y:(int)yOffset w:(int)width h:(int)height
|
2013-10-01 22:30:06 +04:00
|
|
|
{
|
2013-10-08 00:43:23 +04:00
|
|
|
mfc->yCurrentScroll = yOffset;
|
|
|
|
mfc->xCurrentScroll = xOffset;
|
|
|
|
mfc->client_height = height;
|
|
|
|
mfc->client_width = width;
|
2013-10-01 22:30:06 +04:00
|
|
|
}
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
BOOL mac_pre_connect(freerdp* instance)
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-03-11 05:35:06 +04:00
|
|
|
rdpSettings* settings;
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
instance->update->BeginPaint = mac_begin_paint;
|
|
|
|
instance->update->EndPaint = mac_end_paint;
|
2014-03-04 01:57:43 +04:00
|
|
|
instance->update->DesktopResize = mac_desktop_resize;
|
2013-06-23 04:27:23 +04:00
|
|
|
|
|
|
|
settings = instance->settings;
|
|
|
|
|
|
|
|
if (!settings->ServerHostname)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "error: server hostname was not specified with /v:<server>[:port]\n");
|
|
|
|
[NSApp terminate:nil];
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-12-11 23:31:54 +04:00
|
|
|
settings->SoftwareGdi = TRUE;
|
|
|
|
|
2013-12-10 21:30:25 +04:00
|
|
|
settings->OsMajorType = OSMAJORTYPE_MACINTOSH;
|
|
|
|
settings->OsMinorType = OSMINORTYPE_MACINTOSH;
|
|
|
|
|
|
|
|
ZeroMemory(settings->OrderSupport, 32);
|
|
|
|
settings->OrderSupport[NEG_DSTBLT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_PATBLT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_SCRBLT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_OPAQUE_RECT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_DRAWNINEGRID_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_MULTIDSTBLT_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_MULTIPATBLT_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_MULTISCRBLT_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_MULTIOPAQUERECT_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_MULTI_DRAWNINEGRID_INDEX] = FALSE;
|
|
|
|
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_MEMBLT_V2_INDEX] = settings->BitmapCacheEnabled;
|
|
|
|
settings->OrderSupport[NEG_MEM3BLT_V2_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_SAVEBITMAP_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_GLYPH_INDEX_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_FAST_INDEX_INDEX] = TRUE;
|
|
|
|
settings->OrderSupport[NEG_FAST_GLYPH_INDEX] = TRUE;
|
2014-03-04 01:57:43 +04:00
|
|
|
settings->OrderSupport[NEG_POLYGON_SC_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_POLYGON_CB_INDEX] = FALSE;
|
2013-12-10 21:30:25 +04:00
|
|
|
settings->OrderSupport[NEG_ELLIPSE_SC_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_ELLIPSE_CB_INDEX] = FALSE;
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
freerdp_client_load_addins(instance->context->channels, instance->settings);
|
2013-03-11 05:35:06 +04:00
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
freerdp_channels_pre_connect(instance->context->channels, instance);
|
2013-03-11 08:35:15 +04:00
|
|
|
|
2013-02-22 06:42:47 +04:00
|
|
|
return TRUE;
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
BOOL mac_post_connect(freerdp* instance)
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2014-03-04 01:57:43 +04:00
|
|
|
rdpGdi* gdi;
|
2013-02-22 08:07:35 +04:00
|
|
|
UINT32 flags;
|
2014-03-04 01:57:43 +04:00
|
|
|
rdpSettings* settings;
|
2013-02-22 06:42:47 +04:00
|
|
|
rdpPointer rdp_pointer;
|
2014-03-04 01:57:43 +04:00
|
|
|
mfContext* mfc = (mfContext*) instance->context;
|
2013-06-23 04:27:23 +04:00
|
|
|
|
|
|
|
MRDPView* view = (MRDPView*) mfc->view;
|
2014-03-04 23:01:01 +04:00
|
|
|
|
2013-03-11 20:14:44 +04:00
|
|
|
ZeroMemory(&rdp_pointer, sizeof(rdpPointer));
|
2013-02-22 06:42:47 +04:00
|
|
|
rdp_pointer.size = sizeof(rdpPointer);
|
2013-03-11 20:14:44 +04:00
|
|
|
rdp_pointer.New = mf_Pointer_New;
|
|
|
|
rdp_pointer.Free = mf_Pointer_Free;
|
|
|
|
rdp_pointer.Set = mf_Pointer_Set;
|
|
|
|
rdp_pointer.SetNull = mf_Pointer_SetNull;
|
|
|
|
rdp_pointer.SetDefault = mf_Pointer_SetDefault;
|
2014-03-04 23:01:01 +04:00
|
|
|
|
2014-03-04 01:57:43 +04:00
|
|
|
settings = instance->settings;
|
|
|
|
|
|
|
|
flags = CLRCONV_ALPHA | CLRCONV_RGB555;
|
|
|
|
|
|
|
|
if (settings->ColorDepth > 16)
|
|
|
|
flags |= CLRBUF_32BPP;
|
|
|
|
else
|
|
|
|
flags |= CLRBUF_16BPP;
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
gdi_init(instance, flags, NULL);
|
2014-03-04 01:57:43 +04:00
|
|
|
gdi = instance->context->gdi;
|
|
|
|
|
|
|
|
view->bitmap_context = mac_create_bitmap_context(instance->context);
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
pointer_cache_register_callbacks(instance->update);
|
|
|
|
graphics_register_pointer(instance->context->graphics, &rdp_pointer);
|
2013-06-23 04:27:23 +04:00
|
|
|
|
|
|
|
freerdp_channels_post_connect(instance->context->channels, instance);
|
2013-05-31 20:48:40 +04:00
|
|
|
|
2013-03-11 20:14:44 +04:00
|
|
|
/* setup pasteboard (aka clipboard) for copy operations (write only) */
|
2013-06-18 22:30:21 +04:00
|
|
|
view->pasteboard_wr = [NSPasteboard generalPasteboard];
|
2013-02-22 06:42:47 +04:00
|
|
|
|
2013-03-11 20:14:44 +04:00
|
|
|
/* setup pasteboard for read operations */
|
2013-06-18 22:30:21 +04:00
|
|
|
view->pasteboard_rd = [NSPasteboard generalPasteboard];
|
|
|
|
view->pasteboard_changecount = (int) [view->pasteboard_rd changeCount];
|
|
|
|
view->pasteboard_timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:mfc->view selector:@selector(onPasteboardTimerFired:) userInfo:nil repeats:YES];
|
2014-03-04 23:01:01 +04:00
|
|
|
|
|
|
|
mfc->appleKeyboardType = mac_detect_keyboard_type();
|
2013-06-20 18:03:20 +04:00
|
|
|
|
2013-02-22 06:42:47 +04:00
|
|
|
return TRUE;
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-03-11 05:32:05 +04:00
|
|
|
BOOL mac_authenticate(freerdp* instance, char** username, char** password, char** domain)
|
|
|
|
{
|
2013-03-11 20:14:44 +04:00
|
|
|
PasswordDialog* dialog = [PasswordDialog new];
|
2013-03-11 05:32:05 +04:00
|
|
|
|
2013-03-11 22:59:50 +04:00
|
|
|
dialog.serverHostname = [NSString stringWithCString:instance->settings->ServerHostname encoding:NSUTF8StringEncoding];
|
2013-03-11 05:32:05 +04:00
|
|
|
|
2013-03-11 08:35:15 +04:00
|
|
|
if (*username)
|
2013-03-11 22:59:50 +04:00
|
|
|
dialog.username = [NSString stringWithCString:*username encoding:NSUTF8StringEncoding];
|
2013-03-11 05:32:05 +04:00
|
|
|
|
2013-03-11 08:35:15 +04:00
|
|
|
if (*password)
|
|
|
|
dialog.password = [NSString stringWithCString:*password encoding:NSUTF8StringEncoding];
|
2013-03-11 05:32:05 +04:00
|
|
|
|
2013-03-11 08:35:15 +04:00
|
|
|
BOOL ok = [dialog runModal];
|
2013-06-23 04:27:23 +04:00
|
|
|
|
2013-03-11 08:35:15 +04:00
|
|
|
if (ok)
|
|
|
|
{
|
2013-03-11 22:59:50 +04:00
|
|
|
const char* submittedUsername = [dialog.username cStringUsingEncoding:NSUTF8StringEncoding];
|
2013-03-11 08:35:15 +04:00
|
|
|
*username = malloc((strlen(submittedUsername) + 1) * sizeof(char));
|
|
|
|
strcpy(*username, submittedUsername);
|
2013-03-11 05:32:05 +04:00
|
|
|
|
2013-03-11 08:35:15 +04:00
|
|
|
const char* submittedPassword = [dialog.password cStringUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
*password = malloc((strlen(submittedPassword) + 1) * sizeof(char));
|
|
|
|
strcpy(*password, submittedPassword);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
2013-03-11 05:32:05 +04:00
|
|
|
}
|
|
|
|
|
2013-03-11 20:14:44 +04:00
|
|
|
void mf_Pointer_New(rdpContext* context, rdpPointer* pointer)
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-03-11 20:14:44 +04:00
|
|
|
NSRect rect;
|
|
|
|
NSImage* image;
|
|
|
|
NSPoint hotSpot;
|
|
|
|
NSCursor* cursor;
|
2013-02-22 08:07:35 +04:00
|
|
|
BYTE* cursor_data;
|
2013-03-11 20:14:44 +04:00
|
|
|
NSMutableArray* ma;
|
|
|
|
NSBitmapImageRep* bmiRep;
|
|
|
|
MRDPCursor* mrdpCursor = [[MRDPCursor alloc] init];
|
2013-06-23 04:27:23 +04:00
|
|
|
mfContext* mfc = (mfContext*) context;
|
|
|
|
MRDPView* view = (MRDPView*) mfc->view;
|
2013-02-22 06:42:47 +04:00
|
|
|
|
|
|
|
rect.size.width = pointer->width;
|
|
|
|
rect.size.height = pointer->height;
|
|
|
|
rect.origin.x = pointer->xPos;
|
|
|
|
rect.origin.y = pointer->yPos;
|
|
|
|
|
2013-03-11 20:14:44 +04:00
|
|
|
cursor_data = (BYTE*) malloc(rect.size.width * rect.size.height * 4);
|
2013-02-22 06:42:47 +04:00
|
|
|
mrdpCursor->cursor_data = cursor_data;
|
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
if (pointer->xorBpp > 24)
|
|
|
|
{
|
|
|
|
freerdp_image_swap_color_order(pointer->xorMaskData, pointer->width, pointer->height);
|
2013-07-16 20:16:44 +04:00
|
|
|
}
|
2013-10-08 00:43:23 +04:00
|
|
|
|
2013-02-22 06:42:47 +04:00
|
|
|
freerdp_alpha_cursor_convert(cursor_data, pointer->xorMaskData, pointer->andMaskData,
|
|
|
|
pointer->width, pointer->height, pointer->xorBpp, context->gdi->clrconv);
|
2014-03-04 01:57:43 +04:00
|
|
|
|
2013-03-11 20:14:44 +04:00
|
|
|
/* store cursor bitmap image in representation - required by NSImage */
|
2013-02-22 06:42:47 +04:00
|
|
|
bmiRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:(unsigned char **) &cursor_data
|
2013-06-23 04:27:23 +04:00
|
|
|
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];
|
2013-02-22 06:42:47 +04:00
|
|
|
mrdpCursor->bmiRep = bmiRep;
|
|
|
|
|
2013-03-11 20:14:44 +04:00
|
|
|
/* create an image using above representation */
|
|
|
|
image = [[NSImage alloc] initWithSize:[bmiRep size]];
|
2013-02-22 06:42:47 +04:00
|
|
|
[image addRepresentation: bmiRep];
|
|
|
|
[image setFlipped:NO];
|
|
|
|
mrdpCursor->nsImage = image;
|
|
|
|
|
2013-03-11 20:14:44 +04:00
|
|
|
/* need hotspot to create cursor */
|
2013-02-22 06:42:47 +04:00
|
|
|
hotSpot.x = pointer->xPos;
|
|
|
|
hotSpot.y = pointer->yPos;
|
|
|
|
|
2013-03-11 20:14:44 +04:00
|
|
|
cursor = [[NSCursor alloc] initWithImage: image hotSpot:hotSpot];
|
2013-02-22 06:42:47 +04:00
|
|
|
mrdpCursor->nsCursor = cursor;
|
|
|
|
mrdpCursor->pointer = pointer;
|
|
|
|
|
2013-03-11 20:14:44 +04:00
|
|
|
/* save cursor for later use in mf_Pointer_Set() */
|
2013-06-18 22:30:21 +04:00
|
|
|
ma = view->cursors;
|
2013-02-22 06:42:47 +04:00
|
|
|
[ma addObject:mrdpCursor];
|
|
|
|
}
|
2012-05-03 07:15:27 +04:00
|
|
|
|
2013-03-11 20:14:44 +04:00
|
|
|
void mf_Pointer_Free(rdpContext* context, rdpPointer* pointer)
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-06-23 04:27:23 +04:00
|
|
|
mfContext* mfc = (mfContext*) context;
|
|
|
|
MRDPView* view = (MRDPView*) mfc->view;
|
2013-06-18 22:30:21 +04:00
|
|
|
NSMutableArray* ma = view->cursors;
|
2013-02-22 06:42:47 +04:00
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
for (MRDPCursor* cursor in ma)
|
2013-02-22 06:42:47 +04:00
|
|
|
{
|
2013-02-22 07:04:09 +04:00
|
|
|
if (cursor->pointer == pointer)
|
|
|
|
{
|
2013-02-22 06:42:47 +04:00
|
|
|
cursor->nsImage = nil;
|
|
|
|
cursor->nsCursor = nil;
|
|
|
|
cursor->bmiRep = nil;
|
|
|
|
free(cursor->cursor_data);
|
|
|
|
[ma removeObject:cursor];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-03-11 20:14:44 +04:00
|
|
|
void mf_Pointer_Set(rdpContext* context, rdpPointer* pointer)
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-06-23 04:27:23 +04:00
|
|
|
mfContext* mfc = (mfContext*) context;
|
|
|
|
MRDPView* view = (MRDPView*) mfc->view;
|
|
|
|
|
2013-06-18 22:30:21 +04:00
|
|
|
NSMutableArray* ma = view->cursors;
|
2013-03-19 07:28:19 +04:00
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
for (MRDPCursor* cursor in ma)
|
2013-02-22 06:42:47 +04:00
|
|
|
{
|
2013-02-22 07:04:09 +04:00
|
|
|
if (cursor->pointer == pointer)
|
|
|
|
{
|
2013-10-08 00:43:23 +04:00
|
|
|
[view setCursor:cursor->nsCursor];
|
2013-02-22 06:42:47 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-10-08 00:43:23 +04:00
|
|
|
|
|
|
|
NSLog(@"Cursor not found");
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-03-11 20:14:44 +04:00
|
|
|
void mf_Pointer_SetNull(rdpContext* context)
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-03-19 07:28:19 +04:00
|
|
|
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-03-11 20:14:44 +04:00
|
|
|
void mf_Pointer_SetDefault(rdpContext* context)
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-07-16 20:16:44 +04:00
|
|
|
mfContext* mfc = (mfContext*) context;
|
|
|
|
MRDPView* view = (MRDPView*) mfc->view;
|
2013-10-08 00:43:23 +04:00
|
|
|
[view setCursor:[NSCursor arrowCursor]];
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2014-03-04 01:57:43 +04:00
|
|
|
CGContextRef mac_create_bitmap_context(rdpContext* context)
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2014-03-04 01:57:43 +04:00
|
|
|
CGContextRef bitmap_context;
|
|
|
|
rdpGdi* gdi = context->gdi;
|
2013-03-19 07:28:19 +04:00
|
|
|
|
2014-03-04 01:57:43 +04:00
|
|
|
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
|
|
|
|
|
|
|
if (gdi->dstBpp == 16)
|
|
|
|
{
|
|
|
|
bitmap_context = CGBitmapContextCreate(gdi->primary_buffer,
|
|
|
|
gdi->width, gdi->height, 5, gdi->width * 2, colorSpace,
|
|
|
|
kCGBitmapByteOrder16Little | kCGImageAlphaNoneSkipFirst);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bitmap_context = CGBitmapContextCreate(gdi->primary_buffer,
|
|
|
|
gdi->width, gdi->height, 8, gdi->width * 4, colorSpace,
|
|
|
|
kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst);
|
|
|
|
}
|
|
|
|
|
|
|
|
CGColorSpaceRelease(colorSpace);
|
2013-03-19 07:28:19 +04:00
|
|
|
|
2014-03-04 01:57:43 +04:00
|
|
|
return bitmap_context;
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
void mac_begin_paint(rdpContext* context)
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-02-22 06:42:47 +04:00
|
|
|
rdpGdi* gdi = context->gdi;
|
2013-11-25 09:25:16 +04:00
|
|
|
|
|
|
|
if (!gdi)
|
|
|
|
return;
|
|
|
|
|
2013-02-22 06:42:47 +04:00
|
|
|
gdi->primary->hdc->hwnd->invalid->null = 1;
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void mac_end_paint(rdpContext* context)
|
|
|
|
{
|
2013-02-22 08:07:35 +04:00
|
|
|
rdpGdi* gdi;
|
2013-12-11 23:31:54 +04:00
|
|
|
HGDI_RGN invalid;
|
|
|
|
NSRect newDrawRect;
|
2013-11-25 09:25:16 +04:00
|
|
|
int ww, wh, dw, dh;
|
2013-06-23 04:27:23 +04:00
|
|
|
mfContext* mfc = (mfContext*) context;
|
|
|
|
MRDPView* view = (MRDPView*) mfc->view;
|
2013-10-01 22:30:06 +04:00
|
|
|
|
2013-11-25 09:25:16 +04:00
|
|
|
gdi = context->gdi;
|
|
|
|
|
|
|
|
if (!gdi)
|
|
|
|
return;
|
|
|
|
|
2013-10-08 00:43:23 +04:00
|
|
|
ww = mfc->client_width;
|
|
|
|
wh = mfc->client_height;
|
|
|
|
dw = mfc->context.settings->DesktopWidth;
|
|
|
|
dh = mfc->context.settings->DesktopHeight;
|
2013-10-01 22:30:06 +04:00
|
|
|
|
2013-12-11 23:31:54 +04:00
|
|
|
if ((!context) || (!context->gdi))
|
2013-02-22 06:42:47 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (context->gdi->primary->hdc->hwnd->invalid->null)
|
|
|
|
return;
|
2013-06-23 04:27:23 +04:00
|
|
|
|
2013-12-11 23:31:54 +04:00
|
|
|
invalid = gdi->primary->hdc->hwnd->invalid;
|
2013-10-08 00:43:23 +04:00
|
|
|
|
2013-12-11 23:31:54 +04:00
|
|
|
newDrawRect.origin.x = invalid->x;
|
|
|
|
newDrawRect.origin.y = invalid->y;
|
|
|
|
newDrawRect.size.width = invalid->w;
|
|
|
|
newDrawRect.size.height = invalid->h;
|
2013-10-08 00:43:23 +04:00
|
|
|
|
2013-12-11 23:31:54 +04:00
|
|
|
if (mfc->context.settings->SmartSizing && (ww != dw || wh != dh))
|
|
|
|
{
|
|
|
|
newDrawRect.origin.y = newDrawRect.origin.y * wh / dh - 1;
|
|
|
|
newDrawRect.size.height = newDrawRect.size.height * wh / dh + 1;
|
|
|
|
newDrawRect.origin.x = newDrawRect.origin.x * ww / dw - 1;
|
|
|
|
newDrawRect.size.width = newDrawRect.size.width * ww / dw + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newDrawRect.origin.y = newDrawRect.origin.y - 1;
|
|
|
|
newDrawRect.size.height = newDrawRect.size.height + 1;
|
|
|
|
newDrawRect.origin.x = newDrawRect.origin.x - 1;
|
|
|
|
newDrawRect.size.width = newDrawRect.size.width + 1;
|
|
|
|
}
|
2013-10-08 00:43:23 +04:00
|
|
|
|
2013-12-11 23:31:54 +04:00
|
|
|
windows_to_apple_cords(mfc->view, &newDrawRect);
|
|
|
|
|
|
|
|
[view setNeedsDisplayInRect:newDrawRect];
|
2013-10-08 00:43:23 +04:00
|
|
|
|
2013-02-22 06:42:47 +04:00
|
|
|
gdi->primary->hdc->hwnd->ninvalid = 0;
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2014-03-04 01:57:43 +04:00
|
|
|
void 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;
|
|
|
|
|
|
|
|
gdi_resize(context->gdi, mfc->width, mfc->height);
|
|
|
|
|
|
|
|
view->bitmap_context = mac_create_bitmap_context(context);
|
|
|
|
}
|
2013-06-20 18:03:20 +04:00
|
|
|
|
2013-07-18 23:41:28 +04:00
|
|
|
static void update_activity_cb(freerdp* instance)
|
2013-06-20 18:03:20 +04:00
|
|
|
{
|
2013-06-23 04:27:23 +04:00
|
|
|
int status;
|
|
|
|
wMessage message;
|
|
|
|
wMessageQueue* queue;
|
2014-03-04 01:57:43 +04:00
|
|
|
|
2013-06-23 04:27:23 +04:00
|
|
|
status = 1;
|
|
|
|
queue = freerdp_get_message_queue(instance, FREERDP_UPDATE_MESSAGE_QUEUE);
|
2013-07-18 23:41:28 +04:00
|
|
|
|
2013-06-23 04:27:23 +04:00
|
|
|
if (queue)
|
|
|
|
{
|
|
|
|
while (MessageQueue_Peek(queue, &message, TRUE))
|
|
|
|
{
|
|
|
|
status = freerdp_message_queue_process_message(instance, FREERDP_UPDATE_MESSAGE_QUEUE, &message);
|
2014-03-04 01:57:43 +04:00
|
|
|
|
2013-06-23 04:27:23 +04:00
|
|
|
if (!status)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-07-18 23:41:28 +04:00
|
|
|
else
|
|
|
|
{
|
2013-10-08 00:43:23 +04:00
|
|
|
fprintf(stderr, "update_activity_cb: No queue!\n");
|
2013-07-18 23:41:28 +04:00
|
|
|
}
|
2013-06-20 18:03:20 +04:00
|
|
|
}
|
|
|
|
|
2013-07-18 23:41:28 +04:00
|
|
|
static void input_activity_cb(freerdp* instance)
|
2013-06-21 04:55:49 +04:00
|
|
|
{
|
2013-06-23 04:27:23 +04:00
|
|
|
int status;
|
|
|
|
wMessage message;
|
2013-10-08 00:43:23 +04:00
|
|
|
wMessageQueue* queue;
|
2013-06-21 04:55:49 +04:00
|
|
|
|
2013-06-23 04:27:23 +04:00
|
|
|
status = 1;
|
|
|
|
queue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE);
|
2013-06-21 04:55:49 +04:00
|
|
|
|
2013-06-23 04:27:23 +04:00
|
|
|
if (queue)
|
|
|
|
{
|
|
|
|
while (MessageQueue_Peek(queue, &message, TRUE))
|
|
|
|
{
|
|
|
|
status = freerdp_message_queue_process_message(instance, FREERDP_INPUT_MESSAGE_QUEUE, &message);
|
2013-06-21 04:55:49 +04:00
|
|
|
|
2013-06-23 04:27:23 +04:00
|
|
|
if (!status)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-10-08 00:43:23 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "input_activity_cb: No queue!\n");
|
|
|
|
}
|
2013-06-21 04:55:49 +04:00
|
|
|
}
|
|
|
|
|
2013-07-18 23:41:28 +04:00
|
|
|
static void channel_activity_cb(freerdp* instance)
|
2013-02-22 06:42:47 +04:00
|
|
|
{
|
2013-10-08 00:43:23 +04:00
|
|
|
wMessage* event;
|
2013-06-20 23:00:50 +04:00
|
|
|
|
2013-06-23 04:27:23 +04:00
|
|
|
freerdp_channels_process_pending_messages(instance);
|
|
|
|
event = freerdp_channels_pop_event(instance->context->channels);
|
2013-10-08 00:43:23 +04:00
|
|
|
|
2013-06-23 04:27:23 +04:00
|
|
|
if (event)
|
|
|
|
{
|
2013-10-08 00:43:23 +04:00
|
|
|
fprintf(stderr, "channel_activity_cb: message %d\n", event->id);
|
|
|
|
|
|
|
|
switch (GetMessageClass(event->id))
|
2013-06-23 04:27:23 +04:00
|
|
|
{
|
|
|
|
case CliprdrChannel_Class:
|
|
|
|
process_cliprdr_event(instance, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
freerdp_event_free(event);
|
|
|
|
}
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int process_plugin_args(rdpSettings* settings, const char* name, RDP_PLUGIN_DATA* plugin_data, void* user_data)
|
|
|
|
{
|
2013-02-22 06:42:47 +04:00
|
|
|
rdpChannels* channels = (rdpChannels*) user_data;
|
|
|
|
|
|
|
|
freerdp_channels_load_plugin(channels, settings, name, plugin_data);
|
2013-02-22 08:07:35 +04:00
|
|
|
|
2013-02-22 06:42:47 +04:00
|
|
|
return 1;
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stuff related to clipboard redirection
|
|
|
|
*/
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
void cliprdr_process_cb_data_request_event(freerdp* instance)
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-02-22 08:07:35 +04:00
|
|
|
int len;
|
|
|
|
NSArray* types;
|
|
|
|
RDP_CB_DATA_RESPONSE_EVENT* event;
|
2013-06-23 04:27:23 +04:00
|
|
|
mfContext* mfc = (mfContext*) instance->context;
|
2013-06-18 22:30:21 +04:00
|
|
|
MRDPView* view = (MRDPView*) mfc->view;
|
2013-06-23 04:27:23 +04:00
|
|
|
|
2013-03-29 08:15:29 +04:00
|
|
|
event = (RDP_CB_DATA_RESPONSE_EVENT*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_DataResponse, NULL, NULL);
|
2013-02-22 07:04:09 +04:00
|
|
|
|
2013-02-22 06:42:47 +04:00
|
|
|
types = [NSArray arrayWithObject:NSStringPboardType];
|
2013-06-18 22:30:21 +04:00
|
|
|
NSString* str = [view->pasteboard_rd availableTypeFromArray:types];
|
2013-02-22 07:04:09 +04:00
|
|
|
|
2013-02-22 06:42:47 +04:00
|
|
|
if (str == nil)
|
|
|
|
{
|
|
|
|
event->data = NULL;
|
|
|
|
event->size = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-18 22:30:21 +04:00
|
|
|
NSString* data = [view->pasteboard_rd stringForType:NSStringPboardType];
|
2013-02-22 06:42:47 +04:00
|
|
|
len = (int) ([data length] * 2 + 2);
|
|
|
|
event->data = malloc(len);
|
|
|
|
[data getCString:(char *) event->data maxLength:len encoding:NSUnicodeStringEncoding];
|
|
|
|
event->size = len;
|
|
|
|
}
|
2013-02-22 07:04:09 +04:00
|
|
|
|
2013-03-29 08:15:29 +04:00
|
|
|
freerdp_channels_send_event(instance->context->channels, (wMessage*) event);
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
void cliprdr_send_data_request(freerdp* instance, UINT32 format)
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-02-22 06:42:47 +04:00
|
|
|
RDP_CB_DATA_REQUEST_EVENT* event;
|
|
|
|
|
2013-03-29 08:15:29 +04:00
|
|
|
event = (RDP_CB_DATA_REQUEST_EVENT*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_DataRequest, NULL, NULL);
|
2013-02-22 08:07:35 +04:00
|
|
|
|
2013-02-22 06:42:47 +04:00
|
|
|
event->format = format;
|
2013-03-29 08:15:29 +04:00
|
|
|
freerdp_channels_send_event(instance->context->channels, (wMessage*) event);
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* at the moment, only the following formats are supported
|
|
|
|
* CB_FORMAT_TEXT
|
|
|
|
* CB_FORMAT_UNICODETEXT
|
|
|
|
*/
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
void cliprdr_process_cb_data_response_event(freerdp* instance, RDP_CB_DATA_RESPONSE_EVENT* event)
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-02-22 08:07:35 +04:00
|
|
|
NSString* str;
|
|
|
|
NSArray* types;
|
2013-06-23 04:27:23 +04:00
|
|
|
mfContext* mfc = (mfContext*) instance->context;
|
2013-06-18 22:30:21 +04:00
|
|
|
MRDPView* view = (MRDPView*) mfc->view;
|
2013-06-23 04:27:23 +04:00
|
|
|
|
2013-02-22 07:04:09 +04:00
|
|
|
if (event->size == 0)
|
2013-02-22 06:42:47 +04:00
|
|
|
return;
|
|
|
|
|
2013-06-18 22:30:21 +04:00
|
|
|
if (view->pasteboard_format == CB_FORMAT_TEXT || view->pasteboard_format == CB_FORMAT_UNICODETEXT)
|
2013-02-22 07:04:09 +04:00
|
|
|
{
|
2013-02-22 06:42:47 +04:00
|
|
|
str = [[NSString alloc] initWithCharacters:(unichar *) event->data length:event->size / 2];
|
|
|
|
types = [[NSArray alloc] initWithObjects:NSStringPboardType, nil];
|
2013-06-18 22:30:21 +04:00
|
|
|
[view->pasteboard_wr declareTypes:types owner:mfc->view];
|
|
|
|
[view->pasteboard_wr setString:str forType:NSStringPboardType];
|
2013-02-22 06:42:47 +04:00
|
|
|
}
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
void cliprdr_process_cb_monitor_ready_event(freerdp* instance)
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-03-29 08:15:29 +04:00
|
|
|
wMessage* event;
|
2013-02-22 06:42:47 +04:00
|
|
|
RDP_CB_FORMAT_LIST_EVENT* format_list_event;
|
|
|
|
|
2013-03-29 08:15:29 +04:00
|
|
|
event = freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_FormatList, NULL, NULL);
|
2013-02-22 06:42:47 +04:00
|
|
|
|
2013-03-11 20:14:44 +04:00
|
|
|
format_list_event = (RDP_CB_FORMAT_LIST_EVENT*) event;
|
2013-02-22 06:42:47 +04:00
|
|
|
format_list_event->num_formats = 0;
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
freerdp_channels_send_event(instance->context->channels, event);
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* list of supported clipboard formats; currently only the following are supported
|
|
|
|
* CB_FORMAT_TEXT
|
|
|
|
* CB_FORMAT_UNICODETEXT
|
|
|
|
*/
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
void cliprdr_process_cb_format_list_event(freerdp* instance, RDP_CB_FORMAT_LIST_EVENT* event)
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-02-22 06:42:47 +04:00
|
|
|
int i;
|
2013-06-23 04:27:23 +04:00
|
|
|
mfContext* mfc = (mfContext*) instance->context;
|
2013-06-18 22:30:21 +04:00
|
|
|
MRDPView* view = (MRDPView*) mfc->view;
|
2013-06-23 04:27:23 +04:00
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
if (event->num_formats == 0)
|
2013-02-22 06:42:47 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < event->num_formats; i++)
|
|
|
|
{
|
|
|
|
switch (event->formats[i])
|
|
|
|
{
|
2013-06-23 04:27:23 +04:00
|
|
|
case CB_FORMAT_RAW:
|
|
|
|
printf("CB_FORMAT_RAW: not yet supported\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CB_FORMAT_TEXT:
|
|
|
|
case CB_FORMAT_UNICODETEXT:
|
|
|
|
view->pasteboard_format = CB_FORMAT_UNICODETEXT;
|
|
|
|
cliprdr_send_data_request(instance, CB_FORMAT_UNICODETEXT);
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CB_FORMAT_DIB:
|
|
|
|
printf("CB_FORMAT_DIB: not yet supported\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CB_FORMAT_HTML:
|
|
|
|
printf("CB_FORMAT_HTML\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CB_FORMAT_PNG:
|
|
|
|
printf("CB_FORMAT_PNG: not yet supported\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CB_FORMAT_JPEG:
|
|
|
|
printf("CB_FORMAT_JPEG: not yet supported\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CB_FORMAT_GIF:
|
|
|
|
printf("CB_FORMAT_GIF: not yet supported\n");
|
|
|
|
break;
|
2013-02-22 06:42:47 +04:00
|
|
|
}
|
|
|
|
}
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-03-29 08:15:29 +04:00
|
|
|
void process_cliprdr_event(freerdp* instance, wMessage* event)
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-02-22 07:04:09 +04:00
|
|
|
if (event)
|
|
|
|
{
|
2013-03-29 08:15:29 +04:00
|
|
|
switch (GetMessageType(event->id))
|
2013-02-22 06:42:47 +04:00
|
|
|
{
|
2013-06-23 04:27:23 +04:00
|
|
|
/*
|
2013-03-11 20:14:44 +04:00
|
|
|
* Monitor Ready PDU is sent by server to indicate that it has been
|
|
|
|
* initialized and is ready. This PDU is transmitted by the server after it has sent
|
|
|
|
* Clipboard Capabilities PDU
|
|
|
|
*/
|
2013-06-23 04:27:23 +04:00
|
|
|
case CliprdrChannel_MonitorReady:
|
|
|
|
cliprdr_process_cb_monitor_ready_event(instance);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
2013-03-11 20:14:44 +04:00
|
|
|
* The Format List PDU is sent either by the client or the server when its
|
|
|
|
* local system clipboard is updated with new clipboard data. This PDU
|
|
|
|
* contains the Clipboard Format ID and name pairs of the new Clipboard
|
|
|
|
* Formats on the clipboard
|
|
|
|
*/
|
2013-06-23 04:27:23 +04:00
|
|
|
case CliprdrChannel_FormatList:
|
|
|
|
cliprdr_process_cb_format_list_event(instance, (RDP_CB_FORMAT_LIST_EVENT*) event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
2013-03-11 20:14:44 +04:00
|
|
|
* The Format Data Request PDU is sent by the receipient of the Format List PDU.
|
|
|
|
* It is used to request the data for one of the formats that was listed in the
|
|
|
|
* Format List PDU
|
|
|
|
*/
|
2013-06-23 04:27:23 +04:00
|
|
|
case CliprdrChannel_DataRequest:
|
|
|
|
cliprdr_process_cb_data_request_event(instance);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
2013-03-11 20:14:44 +04:00
|
|
|
* The Format Data Response PDU is sent as a reply to the Format Data Request PDU.
|
|
|
|
* It is used to indicate whether processing of the Format Data Request PDU
|
|
|
|
* was successful. If the processing was successful, the Format Data Response PDU
|
|
|
|
* includes the contents of the requested clipboard data
|
|
|
|
*/
|
2013-06-23 04:27:23 +04:00
|
|
|
case CliprdrChannel_DataResponse:
|
|
|
|
cliprdr_process_cb_data_response_event(instance, (RDP_CB_DATA_RESPONSE_EVENT*) event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("process_cliprdr_event: unknown event type %d\n", GetMessageType(event->id));
|
|
|
|
break;
|
2013-02-22 06:42:47 +04:00
|
|
|
}
|
|
|
|
}
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
void cliprdr_send_supported_format_list(freerdp* instance)
|
2012-05-03 07:15:27 +04:00
|
|
|
{
|
2013-02-22 06:42:47 +04:00
|
|
|
RDP_CB_FORMAT_LIST_EVENT* event;
|
|
|
|
|
2013-03-29 08:15:29 +04:00
|
|
|
event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_FormatList, NULL, NULL);
|
2013-02-22 06:42:47 +04:00
|
|
|
|
2013-02-22 08:07:35 +04:00
|
|
|
event->formats = (UINT32*) malloc(sizeof(UINT32) * 1);
|
2013-02-22 06:42:47 +04:00
|
|
|
event->num_formats = 1;
|
|
|
|
event->formats[0] = CB_FORMAT_UNICODETEXT;
|
2013-02-22 08:07:35 +04:00
|
|
|
|
2013-03-29 08:15:29 +04:00
|
|
|
freerdp_channels_send_event(instance->context->channels, (wMessage*) event);
|
2012-05-03 07:15:27 +04:00
|
|
|
}
|
|
|
|
|
2012-06-20 20:57:20 +04:00
|
|
|
/**
|
|
|
|
* given a rect with 0,0 at the top left (windows cords)
|
|
|
|
* convert it to a rect with 0,0 at the bottom left (apple cords)
|
2013-07-16 20:16:44 +04:00
|
|
|
*
|
|
|
|
* Note: the formula works for conversions in both directions.
|
|
|
|
*
|
2012-06-20 20:57:20 +04:00
|
|
|
*/
|
|
|
|
|
2013-06-18 05:21:42 +04:00
|
|
|
void windows_to_apple_cords(MRDPView* view, NSRect* r)
|
2012-06-20 20:57:20 +04:00
|
|
|
{
|
2013-10-08 23:03:05 +04:00
|
|
|
r->origin.y = [view frame].size.height - (r->origin.y + r->size.height);
|
2012-06-20 20:57:20 +04:00
|
|
|
}
|
|
|
|
|
2013-10-01 22:30:06 +04:00
|
|
|
|
2012-05-03 07:15:27 +04:00
|
|
|
@end
|