diff --git a/client/X11/generate_argument_docbook.c b/client/X11/generate_argument_docbook.c index aaab2239c..4b49f34da 100644 --- a/client/X11/generate_argument_docbook.c +++ b/client/X11/generate_argument_docbook.c @@ -154,9 +154,9 @@ int main(int argc, char *argv[]) fprintf(fp, "\t\t\t\t\t%s\n", format); fprintf(fp, "\t\t\t\t\n"); fprintf(fp, "\t\t\t\n"); - free(name); - free(format); - free(text); + free((void*) name); + free((void*) format); + free((void*) text); } fprintf(fp, "\t\t\n"); fprintf(fp, "\t\n"); diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index 682c0cfca..7df1f8768 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -299,15 +299,16 @@ static const char *get_shm_id() return shm_id; } -xfWindow *xf_CreateDesktopWindow(xfContext *xfc, char *name, int width, int height, BOOL decorations) +xfWindow* xf_CreateDesktopWindow(xfContext *xfc, char *name, int width, int height, BOOL decorations) { - xfWindow *window; + xfWindow* window; XEvent xevent; - rdpSettings *settings; - window = (xfWindow *) malloc(sizeof(xfWindow)); - ZeroMemory(window, sizeof(xfWindow)); + rdpSettings* settings; + window = (xfWindow*) calloc(1, sizeof(xfWindow)); + settings = xfc->instance->settings; - if(window) + + if (window) { int input_mask; XClassHint *class_hints; @@ -322,48 +323,65 @@ xfWindow *xf_CreateDesktopWindow(xfContext *xfc, char *name, int width, int heig 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_EXCL | O_RDWR, S_IREAD | S_IWRITE); - if(window->shmid < 0) + + 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)); - window->xfwin = mmap(0, sizeof(window->handle), PROT_READ | PROT_WRITE, MAP_SHARED, window->shmid, 0); - if(window->xfwin == (int *) -1) + + mem = mmap(0, sizeof(window->handle), PROT_READ | PROT_WRITE, MAP_SHARED, window->shmid, 0); + + if (mem == ((int*) -1)) { DEBUG_X11("xf_CreateDesktopWindow: failed to assign pointer to the memory address - shmat()\n"); } else { + window->xfwin = mem; *window->xfwin = window->handle; } } + class_hints = XAllocClassHint(); - if(class_hints) + + if (class_hints) { class_hints->res_name = "xfreerdp"; - if(xfc->instance->settings->WmClass) + + if (xfc->instance->settings->WmClass) class_hints->res_class = xfc->instance->settings->WmClass; else class_hints->res_class = "xfreerdp"; + XSetClassHint(xfc->display, window->handle, class_hints); XFree(class_hints); } + xf_ResizeDesktopWindow(xfc, window, width, height); xf_SetWindowDecorations(xfc, window, decorations); xf_SetWindowPID(xfc, window, 0); + input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | VisibilityChangeMask | FocusChangeMask | StructureNotifyMask | PointerMotionMask | ExposureMask | PropertyChangeMask; - if(xfc->grab_keyboard) + + 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(xfc->settings->ParentWindowId) + + if (xfc->settings->ParentWindowId) XReparentWindow(xfc->display, window->handle, (Window) xfc->settings->ParentWindowId, 0, 0); + XSelectInput(xfc->display, window->handle, input_mask); XClearWindow(xfc->display, window->handle); XMapWindow(xfc->display, window->handle); @@ -382,15 +400,14 @@ xfWindow *xf_CreateDesktopWindow(xfContext *xfc, char *name, int width, int heig * 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->instance->settings->RemoteApplicationMode) + if (xfc->instance->settings->RemoteApplicationMode) { XMoveWindow(xfc->display, window->handle, 0, 0); } - else - if(settings->DesktopPosX || settings->DesktopPosY) - { - XMoveWindow(xfc->display, window->handle, settings->DesktopPosX, settings->DesktopPosY); - } + else if(settings->DesktopPosX || settings->DesktopPosY) + { + XMoveWindow(xfc->display, window->handle, settings->DesktopPosX, settings->DesktopPosY); + } } xf_SetWindowText(xfc, window, name); return window; @@ -845,7 +862,7 @@ void xf_DestroyWindow(xfContext *xfc, xfWindow *window) shm_unlink(get_shm_id()); - window->xfwin = -1; + window->xfwin = (Window*) -1; window->shmid = -1; free(window);