mfreerdp: refactoring

This commit is contained in:
Marc-André Moreau 2013-06-22 22:55:51 -04:00
parent bda3a7e9cc
commit 3d479448a3
6 changed files with 97 additions and 99 deletions

View File

@ -42,8 +42,8 @@
@interface MRDPView : NSView
{
CFRunLoopSourceRef run_loop_src_channels;
CFRunLoopSourceRef run_loop_src_update;
CFRunLoopSourceRef run_loop_src_input;
CFRunLoopSourceRef run_loop_src_update;
CFRunLoopSourceRef run_loop_src_input;
NSBitmapImageRep* bmiRep;
NSMutableArray* cursors;
@ -51,8 +51,8 @@
NSTimer* pasteboard_timer;
NSRect prevWinPosition;
int titleBarHeight;
void* rdp_instance;
void* rdp_context;
freerdp* instance;
rdpContext* context;
CGContextRef bitmap_context;
char* pixel_data;
int width;
@ -87,7 +87,7 @@
int is_connected;
}
- (int) rdpStart :(rdpContext*) context;
- (int) rdpStart :(rdpContext*) rdp_context;
- (void) rdpConnectError;
- (void) rdpRemoteAppError;
- (void) onPasteboardTimerFired :(NSTimer *) timer;

View File

@ -122,18 +122,18 @@ struct rgba_data
@synthesize is_connected;
- (int) rdpStart:(rdpContext*) context
- (int) rdpStart:(rdpContext*) rdp_context
{
int status;
mfContext* mfc;
rdpSettings* settings;
EmbedWindowEventArgs e;
mfc = (mfContext*) context;
context = rdp_context;
mfc = (mfContext*) rdp_context;
instance = context->instance;
settings = context->settings;
mfc->view = self;
rdp_instance = context->instance;
rdp_context = mfc;
EventArgsInit(&e, "mfreerdp");
e.embed = TRUE;
@ -150,9 +150,9 @@ struct rgba_data
// instance->VerifyCertificate = mf_verify_certificate;
// instance->LogonErrorInfo = mf_logon_error_info;
status = freerdp_client_start(context);
status = freerdp_connect(context->instance);
if (status)
if (!status)
{
[self setIs_connected:0];
[self rdpConnectError];
@ -175,8 +175,6 @@ struct rgba_data
return 0;
}
/************************************************************************
methods we override
************************************************************************/
@ -259,7 +257,7 @@ struct rgba_data
y = height - y;
// send mouse motion event to RDP server
((freerdp*)rdp_instance)->input->MouseEvent(((freerdp*)rdp_instance)->input, PTR_FLAGS_MOVE, x, y);
instance->input->MouseEvent(instance->input, PTR_FLAGS_MOVE, x, y);
}
/** *********************************************************************
@ -279,7 +277,7 @@ struct rgba_data
y = height - y;
((freerdp*)rdp_instance)->input->MouseEvent(((freerdp*)rdp_instance)->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1, x, y);
instance->input->MouseEvent(instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1, x, y);
}
/** *********************************************************************
@ -299,7 +297,7 @@ struct rgba_data
y = height - y;
((freerdp*)rdp_instance)->input->MouseEvent(((freerdp*)rdp_instance)->input, PTR_FLAGS_BUTTON1, x, y);
instance->input->MouseEvent(instance->input, PTR_FLAGS_BUTTON1, x, y);
}
/** *********************************************************************
@ -319,7 +317,7 @@ struct rgba_data
y = height - y;
((freerdp*)rdp_instance)->input->MouseEvent(((freerdp*)rdp_instance)->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2, x, y);
instance->input->MouseEvent(instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2, x, y);
}
/** *********************************************************************
@ -339,7 +337,7 @@ struct rgba_data
y = height - y;
((freerdp*)rdp_instance)->input->MouseEvent(((freerdp*)rdp_instance)->input, PTR_FLAGS_BUTTON2, x, y);
instance->input->MouseEvent(instance->input, PTR_FLAGS_BUTTON2, x, y);
}
/** *********************************************************************
@ -359,7 +357,7 @@ struct rgba_data
y = height - y;
((freerdp*)rdp_instance)->input->MouseEvent(((freerdp*)rdp_instance)->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON3, x, y);
instance->input->MouseEvent(instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON3, x, y);
}
/** *********************************************************************
@ -379,7 +377,7 @@ struct rgba_data
y = height - y;
((freerdp*)rdp_instance)->input->MouseEvent(((freerdp*)rdp_instance)->input, PTR_FLAGS_BUTTON3, x, y);
instance->input->MouseEvent(instance->input, PTR_FLAGS_BUTTON3, x, y);
}
- (void) scrollWheel:(NSEvent *)event
@ -407,7 +405,7 @@ struct rgba_data
x += (int) [event deltaX];
y += (int) [event deltaY];
((freerdp*)rdp_instance)->input->MouseEvent(((freerdp*)rdp_instance)->input, flags, x, y);
instance->input->MouseEvent(instance->input, flags, x, y);
}
/** *********************************************************************
@ -429,7 +427,7 @@ struct rgba_data
y = height - y;
// send mouse motion event to RDP server
((freerdp*)rdp_instance)->input->MouseEvent(((freerdp*)rdp_instance)->input, PTR_FLAGS_MOVE, x, y);
instance->input->MouseEvent(instance->input, PTR_FLAGS_MOVE, x, y);
}
/** *********************************************************************
@ -452,7 +450,7 @@ struct rgba_data
scancode = GetVirtualScanCodeFromVirtualKeyCode(vkcode, 4);
extended = (scancode & KBDEXT) ? KBDEXT : 0;
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, extended | KBD_FLAGS_DOWN, scancode & 0xFF);
instance->input->KeyboardEvent(instance->input, extended | KBD_FLAGS_DOWN, scancode & 0xFF);
}
/** *********************************************************************
@ -475,7 +473,7 @@ struct rgba_data
scancode = GetVirtualScanCodeFromVirtualKeyCode(vkcode, 4);
extended = (scancode & KBDEXT) ? KBDEXT : 0;
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, extended | KBD_FLAGS_RELEASE, scancode & 0xFF);
instance->input->KeyboardEvent(instance->input, extended | KBD_FLAGS_RELEASE, scancode & 0xFF);
}
/** *********************************************************************
@ -501,96 +499,96 @@ struct rgba_data
// left shift
if ((kdlshift == 0) && ((mf & 2) != 0)) {
// left shift went down
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, KBD_FLAGS_DOWN, 0x2a);
instance->input->KeyboardEvent(instance->input, KBD_FLAGS_DOWN, 0x2a);
kdlshift = 1;
}
if ((kdlshift != 0) && ((mf & 2) == 0)) {
// left shift went up
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, KBD_FLAGS_RELEASE, 0x2a);
instance->input->KeyboardEvent(instance->input, KBD_FLAGS_RELEASE, 0x2a);
kdlshift = 0;
}
// right shift
if ((kdrshift == 0) && ((mf & 4) != 0)) {
// right shift went down
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, KBD_FLAGS_DOWN, 0x36);
instance->input->KeyboardEvent(instance->input, KBD_FLAGS_DOWN, 0x36);
kdrshift = 1;
}
if ((kdrshift != 0) && ((mf & 4) == 0)) {
// right shift went up
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, KBD_FLAGS_RELEASE, 0x36);
instance->input->KeyboardEvent(instance->input, KBD_FLAGS_RELEASE, 0x36);
kdrshift = 0;
}
// left ctrl
if ((kdlctrl == 0) && ((mf & 1) != 0)) {
// left ctrl went down
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, KBD_FLAGS_DOWN, 0x1d);
instance->input->KeyboardEvent(instance->input, KBD_FLAGS_DOWN, 0x1d);
kdlctrl = 1;
}
if ((kdlctrl != 0) && ((mf & 1) == 0)) {
// left ctrl went up
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, KBD_FLAGS_RELEASE, 0x1d);
instance->input->KeyboardEvent(instance->input, KBD_FLAGS_RELEASE, 0x1d);
kdlctrl = 0;
}
// right ctrl
if ((kdrctrl == 0) && ((mf & 0x2000) != 0)) {
// right ctrl went down
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, 1 | KBD_FLAGS_DOWN, 0x1d);
instance->input->KeyboardEvent(instance->input, 1 | KBD_FLAGS_DOWN, 0x1d);
kdrctrl = 1;
}
if ((kdrctrl != 0) && ((mf & 0x2000) == 0)) {
// right ctrl went up
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, 1 | KBD_FLAGS_RELEASE, 0x1d);
instance->input->KeyboardEvent(instance->input, 1 | KBD_FLAGS_RELEASE, 0x1d);
kdrctrl = 0;
}
// left alt
if ((kdlalt == 0) && ((mf & 0x20) != 0)) {
// left alt went down
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, KBD_FLAGS_DOWN, 0x38);
instance->input->KeyboardEvent(instance->input, KBD_FLAGS_DOWN, 0x38);
kdlalt = 1;
}
if ((kdlalt != 0) && ((mf & 0x20) == 0)) {
// left alt went up
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, KBD_FLAGS_RELEASE, 0x38);
instance->input->KeyboardEvent(instance->input, KBD_FLAGS_RELEASE, 0x38);
kdlalt = 0;
}
// right alt
if ((kdralt == 0) && ((mf & 0x40) != 0)) {
// right alt went down
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, 1 | KBD_FLAGS_DOWN, 0x38);
instance->input->KeyboardEvent(instance->input, 1 | KBD_FLAGS_DOWN, 0x38);
kdralt = 1;
}
if ((kdralt != 0) && ((mf & 0x40) == 0)) {
// right alt went up
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, 1 | KBD_FLAGS_RELEASE, 0x38);
instance->input->KeyboardEvent(instance->input, 1 | KBD_FLAGS_RELEASE, 0x38);
kdralt = 0;
}
// left meta
if ((kdlmeta == 0) && ((mf & 0x08) != 0)) {
// left meta went down
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, 1 | KBD_FLAGS_DOWN, 0x5b);
instance->input->KeyboardEvent(instance->input, 1 | KBD_FLAGS_DOWN, 0x5b);
kdlmeta = 1;
}
if ((kdlmeta != 0) && ((mf & 0x08) == 0)) {
// left meta went up
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, 1 | KBD_FLAGS_RELEASE, 0x5b);
instance->input->KeyboardEvent(instance->input, 1 | KBD_FLAGS_RELEASE, 0x5b);
kdlmeta = 0;
}
// right meta
if ((kdrmeta == 0) && ((mf & 0x10) != 0)) {
// right meta went down
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, 1 | KBD_FLAGS_DOWN, 0x5c);
instance->input->KeyboardEvent(instance->input, 1 | KBD_FLAGS_DOWN, 0x5c);
kdrmeta = 1;
}
if ((kdrmeta != 0) && ((mf & 0x10) == 0)) {
// right meta went up
((freerdp*)rdp_instance)->input->KeyboardEvent(((freerdp*)rdp_instance)->input, 1 | KBD_FLAGS_RELEASE, 0x5c);
instance->input->KeyboardEvent(instance->input, 1 | KBD_FLAGS_RELEASE, 0x5c);
kdrmeta = 0;
}
}
@ -622,9 +620,9 @@ struct rgba_data
if (run_loop_src_channels != 0)
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), run_loop_src_channels, kCFRunLoopDefaultMode);
freerdp_client_stop((rdpContext*) self->rdp_context);
freerdp_client_stop(self->context);
freerdp_client_context_free((rdpContext*) self->rdp_context);
freerdp_client_context_free(self->context);
}
@ -634,16 +632,16 @@ struct rgba_data
- (void) drawRect:(NSRect)rect
{
if (!rdp_context)
if (!context)
return;
if(self->bitmap_context)
if (self->bitmap_context)
{
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
CGContextRef cgContext = [[NSGraphicsContext currentContext] graphicsPort];
CGImageRef cgImage = CGBitmapContextCreateImage(self->bitmap_context);
CGContextClipToRect(context, CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height));
CGContextDrawImage(context, 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);
CGImageRelease(cgImage);
}
@ -761,7 +759,7 @@ struct rgba_data
NSString *str = [pasteboard_rd availableTypeFromArray:types];
if (str != nil)
{
cliprdr_send_supported_format_list(rdp_instance);
cliprdr_send_supported_format_list(instance);
}
}
}

View File

@ -7,6 +7,7 @@
//
#import "AppDelegate.h"
#import "MacFreeRDP-library/mfreerdp.h"
#import "MacFreeRDP-library/mf_client.h"
@implementation AppDelegate
@ -25,18 +26,22 @@
- (void) applicationDidFinishLaunching:(NSNotification*)aNotification
{
int status;
mfContext* mfc;
[self CreateContext];
status = [self ParseCommandLineArguments];
mfc = (mfContext*) context;
mfc->view = (void*) mrdpView;
if (status < 0)
{
}
else
{
[mrdpView rdpStart:context];
freerdp_client_start(context);
}
}
@ -54,10 +59,10 @@
{
int i;
int len;
int status;
char* cptr;
int argc;
char** argv = nil;
int status;
NSArray *args = [[NSProcessInfo processInfo] arguments];

View File

@ -7,10 +7,8 @@
//
#import <Cocoa/Cocoa.h>
#import <MacFreeRDP-library/MRDPView.h>
int main(int argc, char *argv[])
{
[MRDPView class];
return NSApplicationMain(argc, (const char **)argv);
return NSApplicationMain(argc, (const char**) argv);
}

View File

@ -43,14 +43,11 @@ void mfreerdp_client_global_uninit()
int mfreerdp_client_start(rdpContext* context)
{
int status;
MRDPView* view;
mfContext* mfc = (mfContext*) context;
status = freerdp_connect(context->instance);
if (!status)
{
return -1;
}
view = (MRDPView*) mfc->view;
[view rdpStart:context];
return 0;
}
@ -134,6 +131,7 @@ int mfreerdp_client_new(freerdp* instance, rdpContext* context)
void mfreerdp_client_free(freerdp* instance, rdpContext* context)
{
}
void freerdp_client_mouse_event(rdpContext* cfc, DWORD flags, int x, int y)
@ -148,7 +146,6 @@ void freerdp_client_mouse_event(rdpContext* cfc, DWORD flags, int x, int y)
if (x < 0)
x = 0;
// if (x >= width)
x = width - 1;
if (y < 0)

View File

@ -24,53 +24,53 @@ typedef struct mf_context mfContext;
struct mf_context
{
rdpContext context;
rdpContext context;
DEFINE_RDP_CLIENT_COMMON();
void* view;
int width;
int height;
int offset_x;
int offset_y;
int fs_toggle;
int fullscreen;
int percentscreen;
char window_title[64];
int client_x;
int client_y;
int client_width;
int client_height;
void* view;
HANDLE keyboardThread;
int width;
int height;
int offset_x;
int offset_y;
int fs_toggle;
int fullscreen;
int percentscreen;
char window_title[64];
int client_x;
int client_y;
int client_width;
int client_height;
HGDI_DC hdc;
UINT16 srcBpp;
UINT16 dstBpp;
freerdp* instance;
HANDLE keyboardThread;
DWORD mainThreadId;
DWORD keyboardThreadId;
BOOL disconnect;
BOOL sw_gdi;
HGDI_DC hdc;
UINT16 srcBpp;
UINT16 dstBpp;
freerdp* instance;
rdpFile* connectionRdpFile;
DWORD mainThreadId;
DWORD keyboardThreadId;
BOOL disconnect;
BOOL sw_gdi;
// Keep track of window size and position, disable when in fullscreen mode.
BOOL disablewindowtracking;
rdpFile* connectionRdpFile;
// These variables are required for horizontal scrolling.
BOOL updating_scrollbars;
BOOL xScrollVisible;
int xMinScroll; // minimum horizontal scroll value
int xCurrentScroll; // current horizontal scroll value
int xMaxScroll; // maximum horizontal scroll value
// Keep track of window size and position, disable when in fullscreen mode.
BOOL disablewindowtracking;
// These variables are required for vertical scrolling.
BOOL yScrollVisible;
int yMinScroll; // minimum vertical scroll value
int yCurrentScroll; // current vertical scroll value
int yMaxScroll; // maximum vertical scroll value
// These variables are required for horizontal scrolling.
BOOL updating_scrollbars;
BOOL xScrollVisible;
int xMinScroll; // minimum horizontal scroll value
int xCurrentScroll; // current horizontal scroll value
int xMaxScroll; // maximum horizontal scroll value
// These variables are required for vertical scrolling.
BOOL yScrollVisible;
int yMinScroll; // minimum vertical scroll value
int yCurrentScroll; // current vertical scroll value
int yMaxScroll; // maximum vertical scroll value
};
#endif // MFREERDP_H