X11 window 调整大小卡顿

X11 window resizing stutters

我正在 X11 中创建一个 openGL window 并使用 glxswapbuffers 进行双缓冲。

问题是:渲染看起来不错,但我发现 openGL 内容四处乱跳,window 调整大小时边框断断续续。

我尝试过滤 ConfigureNotify 事件,延迟它们,使用 glXSwapInterval 关闭垂直同步...没有任何效果。

这是我正在使用的代码

void Window::redraw() { // Called by any control which needs redrawing
  XEvent event;
  memset(&event, 0, sizeof(event));
  event.type = Expose;
  event.xexpose.display = display;
  XSendEvent(display, window, False, ExposureMask, &event);
}

void Window::resize(int width, int height) {
  this->Width = width;
  this->Height = height;
}

bool Window::wndProc(XEvent *evt) {
  switch (evt->type) {

      case Expose: {

        if (evt->xexpose.count == 0) { // handle last one only

          while (XCheckTypedWindowEvent(display, window, Expose, evt));

            if (Width != oldWidth || Height != oldHeight)
              resizeViewportAndUpdateDimensions();

          Renderer.drawGLStuff();

          this->redraw();
        }

        return true;

      } break;

      case ConfigureNotify: {
        this->resize(evt->xconfigure.width, evt->xconfigure.height);

        this->redraw();
        return true;
      } break;
  }
}

请注意,这与我通过 XCheckTypedWindowEvent.

解决的 this previous post 不同(严格与调整大小相关)

https://tronche.com/gui/x/xlib/events/window-state-change/configure.html

https://tronche.com/gui/x/xlib/events/structure-control/resize.html

据我所知,这两个 links ConfigureNotify 在更改完成时发生。 ResizeRequest 在尝试调整大小时发生。具体来说:

The X server can report ResizeRequest events to clients wanting information about another client's attempts to change the size of a window.

我不喜欢 "CAN report" 的声音,但我想你应该试一试。不要忘记按照 link 中的说明设置正确的事件位。至于捕获事件时你应该​​做什么我不太确定......我会清除前台缓冲区并等待调整大小完成。