void xf_hw_desktop_resize(rdpContext* context) { xfInfo* xfi; BOOL same; rdpSettings* settings; xfi = ((xfContext*) context)->xfi; settings = xfi->instance->settings; xf_lock_x11(xfi, TRUE); if (xfi->fullscreen != TRUE) { xfi->width = settings->DesktopWidth; xfi->height = settings->DesktopHeight; if (xfi->window) xf_ResizeDesktopWindow(xfi, xfi->window, settings->DesktopWidth, settings->DesktopHeight); if (xfi->primary) { same = (xfi->primary == xfi->drawing) ? TRUE : FALSE; XFreePixmap(xfi->display, xfi->primary); xfi->primary = XCreatePixmap(xfi->display, xfi->drawable, xfi->width, xfi->height, xfi->depth); if (same) xfi->drawing = xfi->primary; } } else { XSetFunction(xfi->display, xfi->gc, GXcopy); XSetFillStyle(xfi->display, xfi->gc, FillSolid); XSetForeground(xfi->display, xfi->gc, 0); XFillRectangle(xfi->display, xfi->drawable, xfi->gc, 0, 0, xfi->width, xfi->height); } xf_unlock_x11(xfi, TRUE); }
void xf_desktop_resize(rdpUpdate* update) { GDI* gdi; xfInfo* xfi; boolean same; rdpSettings* settings; xfi = GET_XFI(update); gdi = GET_GDI(update); settings = xfi->instance->settings; if (!xfi->fullscreen) { xfi->width = settings->width; xfi->height = settings->height; if (xfi->window) xf_ResizeDesktopWindow(xfi, xfi->window, settings->width, settings->height); if (xfi->primary) { same = (xfi->primary == xfi->drawing ? True : False); XFreePixmap(xfi->display, xfi->primary); xfi->primary = XCreatePixmap(xfi->display, DefaultRootWindow(xfi->display), xfi->width, xfi->height, xfi->depth); if (same) xfi->drawing = xfi->primary; } if (gdi) gdi_resize(gdi, xfi->width, xfi->height); if (gdi && xfi->image) { xfi->image->data = NULL; XDestroyImage(xfi->image); xfi->image = XCreateImage(xfi->display, xfi->visual, xfi->depth, ZPixmap, 0, (char*) gdi->primary_buffer, gdi->width, gdi->height, xfi->scanline_pad, 0); } } }
BOOL xf_keyboard_handle_special_keys(xfContext* xfc, KeySym keysym) { XF_MODIFIER_KEYS mod = { 0 }; xk_keyboard_get_modifier_keys(xfc, &mod); if (!xf_keyboard_execute_action_script(xfc, &mod, keysym)) { return TRUE; } if(!xfc->remote_app && xfc->fullscreen_toggle) { if (keysym == XK_Return) { WLog_DBG(TAG, "X keycode 0x%x, Ctrl: %d, Alt: %d", keysym, mod.Ctrl, mod.Alt); if (mod.Ctrl && mod.Alt) { /* Ctrl-Alt-Enter: toggle full screen */ xf_toggle_fullscreen(xfc); return TRUE; } } } if (!xfc->remote_app) { if ((keysym == XK_Tab) || (keysym == XK_Left) || (keysym == XK_Right)) { WLog_DBG(TAG, "X keycode 0x%x, Ctrl: %d, Alt: %d", keysym, mod.Ctrl, mod.Alt); if (mod.Ctrl && mod.Alt) { /* Works in either full screen or windowed. * If in fullscreen or cursor inside window - need to do * "double" ctrl-alt-* key press and release... * 1st ctrl-alt-[tab-left-right] releases from x11 key binding * 2nd ctrl-alt-[tab-left-right] executes OS system key binding * Note: If windowed and cursor is not in freerdp window, ie., * on tile bar, this doesnt apply and ctrl-alt-[tab-left-right] * key press will work as OS system key binding. */ XUngrabKeyboard(xfc->display, CurrentTime); return TRUE; } } } if ((keysym == XK_c) || (keysym == XK_C)) { if (mod.Ctrl && mod.Alt) { /* Ctrl-Alt-C: toggle control */ xf_toggle_control(xfc); return TRUE; } } #if 0 /* set to 1 to enable multi touch gesture simulation via keyboard */ #ifdef WITH_XRENDER if (!xfc->remote_app && xfc->settings->MultiTouchGestures) { if (mod.Ctrl && mod.Alt) { int pdx = 0; int pdy = 0; int zdx = 0; int zdy = 0; switch(keysym) { case XK_0: /* Ctrl-Alt-0: Reset scaling and panning */ xfc->scaledWidth = xfc->sessionWidth; xfc->scaledHeight = xfc->sessionHeight; xfc->offset_x = 0; xfc->offset_y = 0; if (!xfc->fullscreen && (xfc->sessionWidth != xfc->window->width || xfc->sessionHeight != xfc->window->height)) { xf_ResizeDesktopWindow(xfc, xfc->window, xfc->sessionWidth, xfc->sessionHeight); } xf_draw_screen(xfc, 0, 0, xfc->sessionWidth, xfc->sessionHeight); return TRUE; case XK_1: /* Ctrl-Alt-1: Zoom in */ zdx = zdy = 10; break; case XK_2: /* Ctrl-Alt-2: Zoom out */ zdx = zdy = -10; break; case XK_3: /* Ctrl-Alt-3: Pan left */ pdx = -10; break; case XK_4: /* Ctrl-Alt-4: Pan right */ pdx = 10; break; case XK_5: /* Ctrl-Alt-5: Pan up */ pdy = -10; break; case XK_6: /* Ctrl-Alt-6: Pan up */ pdy = 10; break; } if (pdx != 0 || pdy != 0) { PanningChangeEventArgs e; EventArgsInit(&e, "xfreerdp"); e.dx = pdx; e.dy = pdy; PubSub_OnPanningChange(((rdpContext*) xfc)->pubSub, xfc, &e); return TRUE; } if (zdx != 0 || zdy != 0) { ZoomingChangeEventArgs e; EventArgsInit(&e, "xfreerdp"); e.dx = zdx; e.dy = zdy; PubSub_OnZoomingChange(((rdpContext*) xfc)->pubSub, xfc, &e); return TRUE; } } } #endif /* WITH_XRENDER defined */ #endif /* pinch/zoom/pan simulation */ return FALSE; }
xfWindow* xf_CreateDesktopWindow(xfContext* xfc, char* name, int width, int height) { XEvent xevent; int input_mask; xfWindow* window; Window parentWindow; XClassHint* classHints; rdpSettings* settings; window = (xfWindow*) calloc(1, sizeof(xfWindow)); if (!window) return NULL; settings = xfc->context.settings; parentWindow = (Window) xfc->context.settings->ParentWindowId; window->width = width; window->height = height; window->decorations = xfc->decorations; window->is_mapped = FALSE; window->is_transient = FALSE; window->handle = XCreateWindow(xfc->display, RootWindowOfScreen(xfc->screen), xfc->workArea.x, xfc->workArea.y, xfc->workArea.width, xfc->workArea.height, 0, xfc->depth, InputOutput, xfc->visual, CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap | CWBorderPixel | CWWinGravity | CWBitGravity, &xfc->attribs); window->shmid = shm_open(get_shm_id(), (O_CREAT | O_RDWR), (S_IREAD | S_IWRITE)); if (window->shmid < 0) { DEBUG_X11("xf_CreateDesktopWindow: failed to get access to shared memory - shmget()\n"); } else { void* mem; ftruncate(window->shmid, sizeof(window->handle)); mem = mmap(0, sizeof(window->handle), PROT_READ | PROT_WRITE, MAP_SHARED, window->shmid, 0); if (mem == MAP_FAILED) { DEBUG_X11("xf_CreateDesktopWindow: failed to assign pointer to the memory address - shmat()\n"); } else { window->xfwin = mem; *window->xfwin = window->handle; } } classHints = XAllocClassHint(); if (classHints) { classHints->res_name = "xfreerdp"; if (xfc->context.settings->WmClass) classHints->res_class = xfc->context.settings->WmClass; else classHints->res_class = "xfreerdp"; XSetClassHint(xfc->display, window->handle, classHints); XFree(classHints); } xf_ResizeDesktopWindow(xfc, window, width, height); xf_SetWindowDecorations(xfc, window->handle, window->decorations); xf_SetWindowPID(xfc, window->handle, 0); input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | VisibilityChangeMask | FocusChangeMask | StructureNotifyMask | PointerMotionMask | ExposureMask | PropertyChangeMask; if (xfc->grab_keyboard) input_mask |= EnterWindowMask | LeaveWindowMask; XChangeProperty(xfc->display, window->handle, xfc->_NET_WM_ICON, XA_CARDINAL, 32, PropModeReplace, (BYTE*) xf_icon_prop, ARRAYSIZE(xf_icon_prop)); if (parentWindow) XReparentWindow(xfc->display, window->handle, parentWindow, 0, 0); XSelectInput(xfc->display, window->handle, input_mask); XClearWindow(xfc->display, window->handle); xf_SetWindowTitleText(xfc, window->handle, name); XMapWindow(xfc->display, window->handle); xf_input_init(xfc, window->handle); /* * NOTE: This must be done here to handle reparenting the window, * so that we don't miss the event and hang waiting for the next one */ do { XMaskEvent(xfc->display, VisibilityChangeMask, &xevent); } while (xevent.type != VisibilityNotify); /* * The XCreateWindow call will start the window in the upper-left corner of our current * monitor instead of the upper-left monitor for remote app mode (which uses all monitors). * This extra call after the window is mapped will position the login window correctly */ if (xfc->context.settings->RemoteApplicationMode) { XMoveWindow(xfc->display, window->handle, 0, 0); } else if (settings->DesktopPosX != UINT32_MAX && settings->DesktopPosY != UINT32_MAX) { XMoveWindow(xfc->display, window->handle, settings->DesktopPosX, settings->DesktopPosY); } window->floatbar = xf_floatbar_new(xfc, window->handle, name, settings->Floatbar); return window; }
void xf_SetWindowFullscreen(xfContext* xfc, xfWindow* window, BOOL fullscreen) { UINT32 i; rdpSettings* settings = xfc->context.settings; int startX, startY; UINT32 width = window->width; UINT32 height = window->height; /* xfc->decorations is set by caller depending on settings and whether it is fullscreen or not */ window->decorations = xfc->decorations; /* show/hide decorations (e.g. title bar) as guided by xfc->decorations */ xf_SetWindowDecorations(xfc, window->handle, window->decorations); DEBUG_X11(TAG, "X window decoration set to %d", (int)window->decorations); xf_floatbar_toggle_fullscreen(xfc->window->floatbar, fullscreen); if (fullscreen) { xfc->savedWidth = xfc->window->width; xfc->savedHeight = xfc->window->height; xfc->savedPosX = xfc->window->left; xfc->savedPosY = xfc->window->top; startX = (settings->DesktopPosX != UINT32_MAX) ? settings->DesktopPosX : 0; startY = (settings->DesktopPosY != UINT32_MAX) ? settings->DesktopPosY : 0; } else { width = xfc->savedWidth; height = xfc->savedHeight; startX = xfc->savedPosX; startY = xfc->savedPosY; } /* Determine the x,y starting location for the fullscreen window */ if (fullscreen) { /* Initialize startX and startY with reasonable values */ startX = xfc->context.settings->MonitorDefArray[0].x; startY = xfc->context.settings->MonitorDefArray[0].y; /* Search all monitors to find the lowest startX and startY values */ for (i = 0; i < xfc->context.settings->MonitorCount; i++) { startX = MIN(startX, xfc->context.settings->MonitorDefArray[i].x); startY = MIN(startY, xfc->context.settings->MonitorDefArray[i].y); } /* Lastly apply any monitor shift(translation from remote to local coordinate system) * to startX and startY values */ startX += xfc->context.settings->MonitorLocalShiftX; startY += xfc->context.settings->MonitorLocalShiftY; } /* It is safe to proceed with simply toogling _NET_WM_STATE_FULLSCREEN window state on the following conditions: - The window manager supports multiple monitor full screen - The user requested to use a single monitor to render the remote desktop */ if (xfc->_NET_WM_FULLSCREEN_MONITORS != None || settings->MonitorCount == 1) { xf_ResizeDesktopWindow(xfc, window, width, height); if (fullscreen) { /* enter full screen: move the window before adding NET_WM_STATE_FULLSCREEN */ XMoveWindow(xfc->display, window->handle, startX, startY); } /* Set the fullscreen state */ xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4, fullscreen ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE, xfc->_NET_WM_STATE_FULLSCREEN, 0, 0); if (!fullscreen) { /* leave full screen: move the window after removing NET_WM_STATE_FULLSCREEN */ XMoveWindow(xfc->display, window->handle, startX, startY); } /* Set monitor bounds */ if (settings->MonitorCount > 1) { xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_FULLSCREEN_MONITORS, 5, xfc->fullscreenMonitors.top, xfc->fullscreenMonitors.bottom, xfc->fullscreenMonitors.left, xfc->fullscreenMonitors.right, 1); } } else { if (fullscreen) { xf_SetWindowDecorations(xfc, window->handle, FALSE); if (xfc->fullscreenMonitors.top) { xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4, _NET_WM_STATE_ADD, xfc->fullscreenMonitors.top, 0, 0); } else { XSetWindowAttributes xswa; xswa.override_redirect = True; XChangeWindowAttributes(xfc->display, window->handle, CWOverrideRedirect, &xswa); XRaiseWindow(xfc->display, window->handle); xswa.override_redirect = False; XChangeWindowAttributes(xfc->display, window->handle, CWOverrideRedirect, &xswa); } /* if window is in maximized state, save and remove */ if (xfc->_NET_WM_STATE_MAXIMIZED_VERT != None) { BYTE state; unsigned long nitems; unsigned long bytes; BYTE* prop; if (xf_GetWindowProperty(xfc, window->handle, xfc->_NET_WM_STATE, 255, &nitems, &bytes, &prop)) { state = 0; while (nitems-- > 0) { if (((Atom*) prop)[nitems] == xfc->_NET_WM_STATE_MAXIMIZED_VERT) state |= 0x01; if (((Atom*) prop)[nitems] == xfc->_NET_WM_STATE_MAXIMIZED_HORZ) state |= 0x02; } if (state) { xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4, _NET_WM_STATE_REMOVE, xfc->_NET_WM_STATE_MAXIMIZED_VERT, 0, 0); xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4, _NET_WM_STATE_REMOVE, xfc->_NET_WM_STATE_MAXIMIZED_HORZ, 0, 0); xfc->savedMaximizedState = state; } XFree(prop); } } width = xfc->vscreen.area.right - xfc->vscreen.area.left + 1; height = xfc->vscreen.area.bottom - xfc->vscreen.area.top + 1; DEBUG_X11("X window move and resize %dx%d@%dx%d", startX, startY, width, height); xf_ResizeDesktopWindow(xfc, window, width, height); XMoveWindow(xfc->display, window->handle, startX, startY); } else { xf_SetWindowDecorations(xfc, window->handle, window->decorations); xf_ResizeDesktopWindow(xfc, window, width, height); XMoveWindow(xfc->display, window->handle, startX, startY); if (xfc->fullscreenMonitors.top) { xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4, _NET_WM_STATE_REMOVE, xfc->fullscreenMonitors.top, 0, 0); } /* restore maximized state, if the window was maximized before setting fullscreen */ if (xfc->savedMaximizedState & 0x01) { xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4, _NET_WM_STATE_ADD, xfc->_NET_WM_STATE_MAXIMIZED_VERT, 0, 0); } if (xfc->savedMaximizedState & 0x02) { xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4, _NET_WM_STATE_ADD, xfc->_NET_WM_STATE_MAXIMIZED_HORZ, 0, 0); } xfc->savedMaximizedState = 0; } } }
BOOL xf_keyboard_handle_special_keys(xfContext* xfc, KeySym keysym) { XF_MODIFIER_KEYS mod = { 0 }; xk_keyboard_get_modifier_keys(xfc, &mod); if (!xf_keyboard_execute_action_script(xfc, &mod, keysym)) { return TRUE; } if(xfc->fullscreen_toggle) { if (keysym == XK_Return) { if (mod.Ctrl && mod.Alt) { /* Ctrl-Alt-Enter: toggle full screen */ xf_toggle_fullscreen(xfc); return TRUE; } } } if ((keysym == XK_c) || (keysym == XK_C)) { if (mod.Ctrl && mod.Alt) { /* Ctrl-Alt-C: toggle control */ xf_toggle_control(xfc); return TRUE; } } #if 0 /* set to 1 to enable multi touch gesture simulation via keyboard */ #ifdef WITH_XRENDER if (!xfc->remote_app && xfc->settings->MultiTouchGestures) { if (mod.Ctrl && mod.Alt) { int pdx = 0; int pdy = 0; int zdx = 0; int zdy = 0; switch(keysym) { case XK_0: /* Ctrl-Alt-0: Reset scaling and panning */ xfc->scaledWidth = xfc->sessionWidth; xfc->scaledHeight = xfc->sessionHeight; xfc->offset_x = 0; xfc->offset_y = 0; if (!xfc->fullscreen && (xfc->sessionWidth != xfc->window->width || xfc->sessionHeight != xfc->window->height)) { xf_ResizeDesktopWindow(xfc, xfc->window, xfc->sessionWidth, xfc->sessionHeight); } xf_draw_screen(xfc, 0, 0, xfc->sessionWidth, xfc->sessionHeight); return TRUE; case XK_1: /* Ctrl-Alt-1: Zoom in */ zdx = zdy = 10; break; case XK_2: /* Ctrl-Alt-2: Zoom out */ zdx = zdy = -10; break; case XK_3: /* Ctrl-Alt-3: Pan left */ pdx = -10; break; case XK_4: /* Ctrl-Alt-4: Pan right */ pdx = 10; break; case XK_5: /* Ctrl-Alt-5: Pan up */ pdy = -10; break; case XK_6: /* Ctrl-Alt-6: Pan up */ pdy = 10; break; } if (pdx != 0 || pdy != 0) { PanningChangeEventArgs e; EventArgsInit(&e, "xfreerdp"); e.dx = pdx; e.dy = pdy; PubSub_OnPanningChange(((rdpContext*) xfc)->pubSub, xfc, &e); return TRUE; } if (zdx != 0 || zdy != 0) { ZoomingChangeEventArgs e; EventArgsInit(&e, "xfreerdp"); e.dx = zdx; e.dy = zdy; PubSub_OnZoomingChange(((rdpContext*) xfc)->pubSub, xfc, &e); return TRUE; } } } #endif /* WITH_XRENDER defined */ #endif /* pinch/zoom/pan simulation */ return FALSE; }