c++ - 窗口没有响应 XMoveResizeWindow 请求

标签 c++ c ubuntu x11

我有一个窗口管理器代码,它可以做窗口移动,窗口调整大小。但是,当我尝试使用 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.


因此 :
  • 打开显示器一次
  • 做你的事(创建窗口、接收/处理事件等)
  • 完成后(最后一个窗口关闭):关闭显示(一次)
  • 关于c++ - 窗口没有响应 XMoveResizeWindow 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68651953/

    相关文章:

    c++ - 使用给定键填充包含所有多映射值的 vector

    php - 一个网站的后端代码怎么可能是C++,前端是PHP呢?

    C语言编程,atoi函数

    c - 如何使用 printf 系列可移植地打印 size_t 变量?

    java - Android Studio 没有在 Ubuntu 上下载任何 sdk 和工具

    c++ - Linux 宽字符串到多字节问题

    c++ - boost mapped_file 或 file_mapping

    c - C中的图算法通过将网格读入数组

    git - Init.d 脚本不更新 git 存储库

    ubuntu - Hadoop hdfs群集要在安装的磁盘而不是默认磁盘上配置