Renju Ashokan
Renju Ashokan

Reputation: 514

Window is not responding to XMoveResizeWindow request

I have one window manager code, which can do window Move, window resize. But when I try to do both at the same time with XMoveResizeWindow, it does not working, and no error log also coming.

My code is given below

void WindowMgrLib::MoveResizeWindow(Window window, int x, int y, int width, int height)
{
    Display *display = XOpenDisplay(NULL);
    XSetErrorHandler(catch_error);
    XMoveResizeWindow(display, window, x, y, width, height);
    printf("x = %d, y= %d, width = %d, height=%d\n", x, y, width, height);
    XFlush(display);
    XCloseDisplay(display);
}

void WindowMgrLib::MoveWindow(Window window, int x, int y)
{
    Display *display = XOpenDisplay(NULL);
    XSetErrorHandler(catch_error);
    XMoveWindow(display, window, x, y);
    XFlush(display);
    XCloseDisplay(display);
}

void WindowMgrLib::ResizeWindow(Window window, int w, int h)
{
    Display *display = XOpenDisplay(NULL);
    XSetErrorHandler(catch_error);
    XResizeWindow(display, window, w, h);
    XFlush(display);
    XCloseDisplay(display);
}

Here WindowMgrLib::MoveWindow and WindowMgrLib::ResizeWindow are working fine. Can somebody tell me what is wrong with WindowMgrLib::MoveResizeWindow?

Upvotes: 1

Views: 294

Answers (1)

XCloseDisplay

The XCloseDisplay function closes the connection to the X server for the display specified in the Display structure and destroys all windows, resource IDs (Window, Font, Pixmap, Colormap, Cursor, and GContext), or other resources that the client has created on this display, unless the close-down mode of the resource has been changed (see XSetCloseDownMode). Therefore, these windows, resource IDs, and other resources should never be referenced again or an error will be generated. Before exiting, you should call XCloseDisplay explicitly so that any pending errors are reported as XCloseDisplay performs a final XSync operation.

Therefore:

  • open the display once
  • do your stuff (creating windows, receive/process events, etc)
  • when finished (last window closed): close the display (once)

Upvotes: 2

Related Questions