Window 没有响应 XMoveResizeWindow 请求

Window is not responding to XMoveResizeWindow request

我有一个 window 管理器代码,可以 window 移动,window 调整大小。但是当我尝试使用 XMoveResizeWindow 同时执行这两项操作时,它不起作用,也没有错误日志出现。

我的代码如下

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);
}

此处 WindowMgrLib::MoveWindowWindowMgrLib::ResizeWindow 工作正常。 有人可以告诉我 WindowMgrLib::MoveResizeWindow 有什么问题吗?

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.

因此:

  • 打开显示一次
  • 做你的事情(创建 windows、receive/process 事件等)
  • 完成后(最后 window 关闭):关闭显示(一次)