From 41f615e849b45416bedde18d6d418e6ad841135e Mon Sep 17 00:00:00 2001 From: Laxmikant Rashinkar Date: Sat, 23 Jun 2012 18:26:44 -0700 Subject: [PATCH] Fixed following issues in RAIL mode + two finger scrolling + after a resize operation, scrolling causes window resize instead of scrolling + unable to drag rectangle out of monitor boundaries + dragging rail app to secondary monitor was causing Exec access error --- client/Mac/MRDPRailView.h | 2 + client/Mac/MRDPRailView.m | 182 +++++--------------------------------- client/Mac/Mac/MRDPView.m | 141 ++++------------------------- 3 files changed, 41 insertions(+), 284 deletions(-) diff --git a/client/Mac/MRDPRailView.h b/client/Mac/MRDPRailView.h index 179f82c7e..17a7cf4a4 100644 --- a/client/Mac/MRDPRailView.h +++ b/client/Mac/MRDPRailView.h @@ -44,6 +44,8 @@ void mac_rail_MoveWindow(rdpRail *rail, rdpWindow *window); void apple_to_windowMove(NSRect * r, RAIL_WINDOW_MOVE_ORDER * windowMove); void mac_send_rail_client_event(rdpChannels *channels, uint16 event_type, void *param); +void windows_to_apple_cords(NSRect * r); +void rail_MoveWindow(rdpRail * rail, rdpWindow * window); @end diff --git a/client/Mac/MRDPRailView.m b/client/Mac/MRDPRailView.m index 29dfdb6b0..f4409006e 100644 --- a/client/Mac/MRDPRailView.m +++ b/client/Mac/MRDPRailView.m @@ -17,8 +17,6 @@ extern struct kkey g_keys[]; - (void) updateDisplay { boolean moveWindow = NO; - int i; - NSRect drawRect; NSRect srcRectOuter; NSRect destRectOuter; @@ -37,7 +35,7 @@ extern struct kkey g_keys[]; srcRectOuter = NSMakeRect(0, 0, self->width, self->height); destRectOuter = [[self window] frame]; - + // cannot be bigger than our current screen size NSRect screenSize = [[NSScreen mainScreen] frame]; if (destRectOuter.size.width > screenSize.size.width) { @@ -45,22 +43,13 @@ extern struct kkey g_keys[]; moveWindow = YES; } - // RAIL_TODO do not hardcode to 22 if (destRectOuter.size.height > screenSize.size.height) { destRectOuter.size.height = screenSize.size.height; moveWindow = YES; } - // cannot have negative cords - if (destRectOuter.origin.x < 0) { - destRectOuter.origin.x = 0; - moveWindow = YES; - } - - if (destRectOuter.origin.y < 0) { - destRectOuter.origin.y = 0; - moveWindow = YES; - } + if (destRectOuter.origin.x + destRectOuter.size.width > width) + destRectOuter.size.width = width - destRectOuter.origin.x; [self setupBmiRep:destRectOuter.size.width :destRectOuter.size.height]; @@ -72,41 +61,16 @@ extern struct kkey g_keys[]; //skipMoveWindowOnce = TRUE; //mac_send_rail_client_event(g_mrdpRailView->rdp_instance->context->channels, RDP_EVENT_TYPE_RAIL_CLIENT_WINDOW_MOVE, &newWndLoc); } - - //printf("MRDPRailView : updateDisplay : drawing %d rectangles\n", gdi->primary->hdc->hwnd->ninvalid); - // if src and dest rect are not the same size, copy the entire - // rectangle in one go instead of in many small rectangles + destRectOuter.origin.y = height - destRectOuter.origin.y - destRectOuter.size.height; + rail_convert_color_space(pixelData, (char *) gdi->primary_buffer, + &destRectOuter, self->width, self->height); - //if (destRectOuter.size.width != self->width) { - if (1) { - destRectOuter.origin.y = height - destRectOuter.origin.y - destRectOuter.size.height; - rail_convert_color_space1(pixelData, (char *) gdi->primary_buffer, - &destRectOuter, self->width, self->height); - - if (moveWindow) - [self setNeedsDisplayInRect:destRectOuter]; - else - [self setNeedsDisplayInRect:[self frame]]; + if (moveWindow) + [self setNeedsDisplayInRect:destRectOuter]; + else + [self setNeedsDisplayInRect:[self frame]]; - gdi->primary->hdc->hwnd->ninvalid = 0; - - return; - } - - for (i = 0; i < gdi->primary->hdc->hwnd->ninvalid; i++) - { - drawRect.origin.x = gdi->primary->hdc->hwnd->cinvalid[i].x; - drawRect.origin.y = gdi->primary->hdc->hwnd->cinvalid[i].y; - drawRect.size.width = gdi->primary->hdc->hwnd->cinvalid[i].w; - drawRect.size.height = gdi->primary->hdc->hwnd->cinvalid[i].h; - - rail_convert_color_space(pixelData, (char *) gdi->primary_buffer, - &drawRect, &destRectOuter, - &drawRect, &srcRectOuter); - - [self setNeedsDisplayInRect:drawRect]; - } gdi->primary->hdc->hwnd->ninvalid = 0; } @@ -282,22 +246,23 @@ extern struct kkey g_keys[]; uint16 flags; [super scrollWheel:event]; - + NSRect winFrame = [[self window] frame]; NSPoint loc = [event locationInWindow]; int x = (int) (winFrame.origin.x + loc.x); int y = (int) (winFrame.origin.y + loc.y); y = height - y; - + flags = PTR_FLAGS_WHEEL; - if ([event deltaY] < 0) { + if ([event scrollingDeltaY] < 0) { flags |= PTR_FLAGS_WHEEL_NEGATIVE | 0x0088; } else { flags |= 0x0078; } - x += (int) [event deltaX]; - y += (int) [event deltaY]; + x += (int) [event scrollingDeltaX]; + y += (int) [event scrollingDeltaY]; + rdp_instance->input->MouseEvent(rdp_instance->input, flags, x, y); } @@ -308,7 +273,7 @@ extern struct kkey g_keys[]; - (void) mouseDragged:(NSEvent *)event { [super mouseDragged:event]; - + NSRect winFrame = [[self window] frame]; NSPoint loc = [event locationInWindow]; int x = (int) loc.x; @@ -324,9 +289,8 @@ extern struct kkey g_keys[]; winFrame.origin.x += newX; winFrame.origin.y += newY; - - [[self window] setFrame:winFrame display:YES]; + [[self window] setFrame:winFrame display:YES]; return; } @@ -508,43 +472,6 @@ extern struct kkey g_keys[]; rdp_instance->input->MouseEvent(rdp_instance->input, PTR_FLAGS_MOVE, x, y); } -// RAIL_TODO delete this -- (void) __mouseDragged:(NSEvent *)event -{ - [super mouseDragged:event]; - - NSPoint loc = [event locationInWindow]; - int x = (int) loc.x; - int y = (int) loc.y; - - if (isMoveSizeInProgress) { - if (saveInitialDragLoc) { - saveInitialDragLoc = NO; - savedDragLocation.x = x; - savedDragLocation.y = y; - return; - } - - int newX = x - savedDragLocation.x; - int newY = y - savedDragLocation.y; - - NSRect r = [[self window] frame]; - r.origin.x += newX; - r.origin.y += newY; - [[self window] setFrame:r display:YES]; - - return; - } - - NSRect winFrame = [[self window] frame]; - x = (int) (winFrame.origin.x + loc.x); - y = (int) (winFrame.origin.y + loc.y); - y = height - y; - - // send mouse motion event to RDP server - rdp_instance->input->MouseEvent(rdp_instance->input, PTR_FLAGS_MOVE, x, y); -} - /** ********************************************************************* * called when a key is pressed ***********************************************************************/ @@ -738,71 +665,7 @@ void rail_cvt_from_rect(char *dest, char *src, NSRect destRect, int destWidth, i /** ********************************************************************* * color space conversion used specifically in RAIL ***********************************************************************/ - -int rail_convert_color_space(char * destBuf, char * srcBuf, - NSRect * destRect, NSRect * destRectOuter, - NSRect * srcRect, NSRect * srcRectOuter) -{ - int i; - int j; - int numRows; - int srcX; - int srcY; - int destX; - int destY; - int pixelsPerRow; - int pixel; - int pixel1; - int pixel2; - int * src32; - int * dest32; - - int destWidth = destRectOuter->size.width; - int destHeight = destRectOuter->size.height; - int srcWidth = srcRectOuter->size.width; - int srcHeight = srcRectOuter->size.height; - - if ((!destBuf) || (!srcBuf)) { - return 1; - } - - if ((destRect->size.width != srcRect->size.width) || (destRect->size.height != srcRect->size.height)) { - printf("##### RAIL_TODO: rail_convert_color_space : destRect & srcRect dimensions don't match\n"); - return 1; - } - - numRows = srcRect->size.height; - srcX = srcRect->origin.x; - srcY = srcRect->origin.y; - destX = destRect->origin.x; - destY = destRect->origin.y; - pixelsPerRow = destRect->size.width; - - for (i = 0; i < numRows; i++) - { - src32 = (int *) (srcBuf + ((srcY + i) * srcWidth + srcX) * 4); - dest32 = (int *) (destBuf + ((destY + i) * destWidth + destX) * 4); - - for (j = 0; j < pixelsPerRow; j++) - { - pixel = *src32; - pixel1 = (pixel & 0x00ff0000) >> 16; - pixel2 = (pixel & 0x000000ff) << 16; - pixel = (pixel & 0xff00ff00) | pixel1 | pixel2; - - *dest32 = pixel; - src32++; - dest32++; - } - } - - destRect->origin.y = destHeight - destRect->origin.y - destRect->size.height; - - return 0; -} - -// RAIL_TODO rename this func -void rail_convert_color_space1(char *destBuf, char * srcBuf, +void rail_convert_color_space(char *destBuf, char * srcBuf, NSRect * destRect, int width, int height) { int i; @@ -825,13 +688,14 @@ void rail_convert_color_space1(char *destBuf, char * srcBuf, if ((!destBuf) || (!srcBuf)) { return; } - - numRows = destHeight; + + numRows = (destRect->origin.y + destHeight > height) ? height - destRect->origin.y : destHeight; + pixelsPerRow = destWidth; + srcX = destRect->origin.x; srcY = destRect->origin.y; destX = 0; destY = 0; - pixelsPerRow = destWidth; for (i = 0; i < numRows; i++) { diff --git a/client/Mac/Mac/MRDPView.m b/client/Mac/Mac/MRDPView.m index f1801e701..c86a7d92a 100644 --- a/client/Mac/Mac/MRDPView.m +++ b/client/Mac/Mac/MRDPView.m @@ -21,14 +21,10 @@ * - when we move the window to a 2nd monitor, display stops working * - RAIL: * - - * - - * - done - tool tips to be correctly positioned - * - done - dragging is slightly of - * - done - resize after dragging not working * - dragging app from macbook to monitor gives exec/access err * - unable to drag rect out of monitor boundaries * - two finger scroll - * - moving scroll bar does a window resize instead of a scroll + * - done - moving scroll bar does a window resize instead of a scroll * - * - * - @@ -39,12 +35,6 @@ #define RUN_IN_XCODE -// LK_TODO -#define GOT_HERE //printf("### got here: %s : %s() : %d\n", __FILE__, __func__, __LINE__) - -// RAIL_TODO DELETE WHEN DONE TESTING -#define MRDP_DRAW_INDIVIDUAL_RECTS - @implementation MRDPView MRDPView *g_mrdpview; @@ -285,7 +275,7 @@ struct kkey g_keys[256] = [self addTrackingArea:trackingArea]; mouseInClientArea = YES; - + [self setAcceptsTouchEvents:YES]; printScreenInfo(); } @@ -490,28 +480,7 @@ struct kkey g_keys[256] = NSPoint loc = [event locationInWindow]; int x = (int) loc.x; int y = (int) loc.y; - -// RAIL_TODO delete this if not reqd -#if 0 - - if ((isRemoteApp) && (isMoveSizeInProgress)) { - if (saveInitialDragLoc) { - saveInitialDragLoc = NO; - savedDragLocation.x = x; - savedDragLocation.y = y; - return; - } - - int newX = x - savedDragLocation.x; - int newY = y - savedDragLocation.y; - - NSRect r = [[self window] frame]; - r.origin.x += newX; - r.origin.y += newY; - [[g_mrdpview window] setFrame:r display:YES]; - } -#endif - + y = height - y; // send mouse motion event to RDP server @@ -734,63 +703,6 @@ struct kkey g_keys[256] = instance methods ************************************************************************/ -/** ********************************************************************* - * called when RDP server wants us to update a rect with new data - ***********************************************************************/ - -- (void) my_draw_rect:(void *)context -{ - int w; - int h; - - rdpContext * ctx = (rdpContext *) context; - - struct rgba_data - { - char red; - char green; - char blue; - char alpha; - }; - - if (isRemoteApp && currentWindow) { - NSRect vrect = [ [currentWindow view] frame]; - [[currentWindow view] setNeedsDisplayInRect:vrect]; - // actual drawing will be done in MRDPRailView:drawRect() - return; - } - - w = width; - h = height; - rect.origin.x = 0; - rect.origin.y = 0; - rect.size.width = w; - rect.size.height = h; - - if (!bmiRep) { - pixel_data = (char *) malloc(w * h * sizeof(struct rgba_data)); - bmiRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:(unsigned char **) &pixel_data - pixelsWide:w - pixelsHigh:h - bitsPerSample:8 - samplesPerPixel:sizeof(struct rgba_data) - hasAlpha:YES - isPlanar:NO - colorSpaceName:NSDeviceRGBColorSpace - bitmapFormat:0 //NSAlphaFirstBitmapFormat - bytesPerRow:w * sizeof(struct rgba_data) - bitsPerPixel:0]; - } - -#ifdef MRDP_DRAW_INDIVIDUAL_RECTS - [self setNeedsDisplayInRect:rect]; - return; -#endif - - convert_color_space(pixel_data, (char *) ctx->gdi->primary_buffer, &rect, w, h); - [self setNeedsDisplayInRect:rect]; -} - /** ********************************************************************* * save state info for use by other methods later on ***********************************************************************/ @@ -941,7 +853,6 @@ struct kkey g_keys[256] = [[g_mrdpview window] orderOut:g_mrdpview]; } -// RAIL_TODO is this func required - (void) windowDidResize:(NSNotification *) notification { } @@ -1101,7 +1012,7 @@ boolean mac_pre_connect(freerdp *inst) g_mrdpview->argv[i++] = cptr; cptr = (char *)malloc(80); - strcpy(cptr, "jay"); + strcpy(cptr, "lk"); g_mrdpview->argv[i++] = cptr; cptr = (char *)malloc(80); @@ -1109,7 +1020,7 @@ boolean mac_pre_connect(freerdp *inst) g_mrdpview->argv[i++] = cptr; cptr = (char *)malloc(80); - strcpy(cptr, "tucker"); + strcpy(cptr, "abc@@@123"); g_mrdpview->argv[i++] = cptr; #if 1 @@ -1141,7 +1052,7 @@ boolean mac_pre_connect(freerdp *inst) #endif cptr = (char *)malloc(80); -#if 0 +#if 1 strcpy(cptr, "mousey.homeip.net:45990"); #else strcpy(cptr, "192.168.168.227"); @@ -1530,8 +1441,6 @@ void channel_activity_cb( freerdp *inst = (freerdp *) info; RDP_EVENT* event; - GOT_HERE; - freerdp_channels_check_fds(inst->context->channels, inst); event = freerdp_channels_pop_event(inst->context->channels); if (event) { @@ -1886,12 +1795,10 @@ void mac_process_rail_event(freerdp *inst, RDP_EVENT *event) break; case RDP_EVENT_TYPE_RAIL_CHANNEL_APPID_RESP: - GOT_HERE; //xf_process_rail_appid_resp_event(xfi, channels, event); break; case RDP_EVENT_TYPE_RAIL_CHANNEL_LANGBARINFO: - GOT_HERE; //xf_process_rail_langbarinfo_event(xfi, channels, event); break; } @@ -1985,9 +1892,9 @@ void mac_rail_CreateWindow(rdpRail *rail, rdpWindow *window) } else { [newWindow makeKeyAndOrderFront:NSApp]; - [[g_mrdpview window] resignFirstResponder]; - [g_mrdpview resignFirstResponder]; - [[g_mrdpview window] setNextResponder:newWindow]; + //[[g_mrdpview window] resignFirstResponder]; + //[g_mrdpview resignFirstResponder]; + //[[g_mrdpview window] setNextResponder:newWindow]; } return; @@ -2044,7 +1951,6 @@ void mac_rail_DestroyWindow(rdpRail *rail, rdpWindow *window) } else { g_mrdpview->currentWindow = nil; - // RAIL_TODO [[g_mrdpview window] makeKeyAndOrderFront:[g_mrdpview window]]; [NSApp terminate:nil]; } return; @@ -2054,8 +1960,6 @@ void mac_rail_DestroyWindow(rdpRail *rail, rdpWindow *window) void mac_rail_register_callbacks(freerdp *inst, rdpRail *rail) { - GOT_HERE; - rail->extra = (void *) inst; rail->rail_CreateWindow = mac_rail_CreateWindow; rail->rail_MoveWindow = mac_rail_MoveWindow; @@ -2096,8 +2000,6 @@ void mac_process_rail_server_sysparam_event(rdpChannels* channels, RDP_EVENT* ev { RAIL_SYSPARAM_ORDER* sysparam = (RAIL_SYSPARAM_ORDER*) event->user_data; - GOT_HERE; - switch (sysparam->param) { case SPI_SET_SCREEN_SAVE_ACTIVE: @@ -2116,8 +2018,6 @@ void mac_process_rail_exec_result_event(rdpChannels* channels, RDP_EVENT* event) { RAIL_EXEC_RESULT_ORDER* exec_result; - GOT_HERE; - exec_result = (RAIL_EXEC_RESULT_ORDER*) event->user_data; if (exec_result->execResult != RAIL_EXEC_S_OK) { @@ -2139,13 +2039,7 @@ void mac_process_rail_exec_result_event(rdpChannels* channels, RDP_EVENT* event) void mac_process_rail_server_minmaxinfo_event(rdpChannels* channels, RDP_EVENT* event) { - RAIL_MINMAXINFO_ORDER * minmax = (RAIL_MINMAXINFO_ORDER*) event->user_data; - -#if 0 - printf("minmax_info: maxPosX=%d maxPosY=%d maxWidth=%d maxHeight=%d minTrackWidth=%d minTrackHeight=%d maxTrackWidth=%d maxTrackHeight=%d\n", - minmax->maxPosX, minmax->maxPosY, minmax->maxWidth, minmax->maxHeight, - minmax->minTrackWidth, minmax->minTrackHeight, minmax->maxTrackWidth, minmax->maxTrackHeight); -#endif + //RAIL_MINMAXINFO_ORDER * minmax = (RAIL_MINMAXINFO_ORDER*) event->user_data; } /** ********************************************************************* @@ -2157,7 +2051,7 @@ void mac_process_rail_server_minmaxinfo_event(rdpChannels* channels, RDP_EVENT* void mac_process_rail_server_localmovesize_event(freerdp *inst, RDP_EVENT *event) { RAIL_LOCALMOVESIZE_ORDER * moveSize = (RAIL_LOCALMOVESIZE_ORDER *) event->user_data; - + switch (moveSize->moveSizeType) { case RAIL_WMSZ_LEFT: [g_mrdpview->currentWindow view]->localMoveType = RAIL_WMSZ_LEFT; @@ -2204,9 +2098,8 @@ void mac_process_rail_server_localmovesize_event(freerdp *inst, RDP_EVENT *event [g_mrdpview->currentWindow view]->isMoveSizeInProgress = NO; [g_mrdpview->currentWindow view]->saveInitialDragLoc = NO; - //NSRect rect = [[g_mrdpview->currentWindow view] frame]; NSRect r = [[[g_mrdpview->currentWindow view] window] frame]; - + // let RDP server know where this window is located RAIL_WINDOW_MOVE_ORDER windowMove; apple_to_windowMove(&r, &windowMove); @@ -2225,6 +2118,10 @@ void mac_process_rail_server_localmovesize_event(freerdp *inst, RDP_EVENT *event default: break; } + + if (moveSize->isMoveSizeStart == 0) + [g_mrdpview->currentWindow view]->localMoveType = 0; + return; } @@ -2233,8 +2130,6 @@ void mac_send_rail_client_event(rdpChannels *channels, uint16 event_type, void * RDP_EVENT *out_event = NULL; void *payload = NULL; - GOT_HERE; - payload = rail_clone_order(event_type, param); if (payload != NULL) { out_event = freerdp_event_new(RDP_EVENT_CLASS_RAIL, event_type, @@ -2245,8 +2140,6 @@ void mac_send_rail_client_event(rdpChannels *channels, uint16 event_type, void * void mac_on_free_rail_client_event(RDP_EVENT* event) { - GOT_HERE; - if (event->event_class == RDP_EVENT_CLASS_RAIL) { rail_free_cloned_order(event->event_type, event->user_data); @@ -2255,8 +2148,6 @@ void mac_on_free_rail_client_event(RDP_EVENT* event) void mac_rail_enable_remoteapp_mode() { - GOT_HERE; - if (!g_mrdpview->isRemoteApp) g_mrdpview->isRemoteApp = TRUE; }