From 0a827cf65c617e39a228de4406084ab5d5eba776 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 7 Nov 2022 12:56:03 +0100 Subject: [PATCH] x11display: Time out waiting for ConfigureNotify event Fixes #1087 --- panda/src/egldisplay/eglGraphicsWindow.cxx | 2 +- panda/src/glxdisplay/glxGraphicsWindow.cxx | 2 +- panda/src/tinydisplay/tinyXGraphicsWindow.cxx | 4 +-- panda/src/x11display/x11GraphicsWindow.cxx | 28 ++++++++++++++++--- panda/src/x11display/x11GraphicsWindow.h | 2 +- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/panda/src/egldisplay/eglGraphicsWindow.cxx b/panda/src/egldisplay/eglGraphicsWindow.cxx index 31002c9fa6..e82ea6862f 100644 --- a/panda/src/egldisplay/eglGraphicsWindow.cxx +++ b/panda/src/egldisplay/eglGraphicsWindow.cxx @@ -80,7 +80,7 @@ begin_frame(FrameMode mode, Thread *current_thread) { if (_gsg == nullptr) { return false; } - if (_awaiting_configure) { + if (_awaiting_configure_since != -1) { // Don't attempt to draw while we have just reconfigured the window and we // haven't got the notification back yet. return false; diff --git a/panda/src/glxdisplay/glxGraphicsWindow.cxx b/panda/src/glxdisplay/glxGraphicsWindow.cxx index 85757f2faa..449d1f66a0 100644 --- a/panda/src/glxdisplay/glxGraphicsWindow.cxx +++ b/panda/src/glxdisplay/glxGraphicsWindow.cxx @@ -60,7 +60,7 @@ begin_frame(FrameMode mode, Thread *current_thread) { if (_gsg == nullptr) { return false; } - if (_awaiting_configure) { + if (_awaiting_configure_since != -1) { // Don't attempt to draw while we have just reconfigured the window and we // haven't got the notification back yet. return false; diff --git a/panda/src/tinydisplay/tinyXGraphicsWindow.cxx b/panda/src/tinydisplay/tinyXGraphicsWindow.cxx index 1e71324baf..a1e83326c4 100644 --- a/panda/src/tinydisplay/tinyXGraphicsWindow.cxx +++ b/panda/src/tinydisplay/tinyXGraphicsWindow.cxx @@ -86,7 +86,7 @@ begin_frame(FrameMode mode, Thread *current_thread) { if (_gsg == nullptr) { return false; } - if (_awaiting_configure) { + if (_awaiting_configure_since != -1) { // Don't attempt to draw while we have just reconfigured the window and we // haven't got the notification back yet. return false; @@ -238,7 +238,7 @@ process_events() { break; case ConfigureNotify: - _awaiting_configure = false; + _awaiting_configure_since = -1; if (_properties.get_fixed_size()) { // If the window properties indicate a fixed size only, undo any // attempt by the user to change them. In X, there doesn't appear to diff --git a/panda/src/x11display/x11GraphicsWindow.cxx b/panda/src/x11display/x11GraphicsWindow.cxx index 8548d05eea..c8ab5e1e9c 100644 --- a/panda/src/x11display/x11GraphicsWindow.cxx +++ b/panda/src/x11display/x11GraphicsWindow.cxx @@ -115,7 +115,7 @@ x11GraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, _XRRSetScreenConfig = x11_pipe->_XRRSetScreenConfig; } - _awaiting_configure = false; + _awaiting_configure_since = -1; _dga_mouse_enabled = false; _override_redirect = False; _wm_delete_window = x11_pipe->_wm_delete_window; @@ -238,7 +238,7 @@ begin_frame(FrameMode mode, Thread *current_thread) { if (_gsg == nullptr) { return false; } - if (_awaiting_configure) { + if (_awaiting_configure_since != -1) { // Don't attempt to draw while we have just reconfigured the window and we // haven't got the notification back yet. return false; @@ -481,7 +481,14 @@ process_events() { if (got_configure_event) { // Now handle the last configure event we found. - _awaiting_configure = false; + if (x11display_cat.is_debug() && _awaiting_configure_since != -1) { + unsigned long elapsed = (unsigned long)(clock() - _awaiting_configure_since) / (CLOCKS_PER_SEC / 10000); + x11display_cat.debug() + << "Received ConfigureNotify event after " + << (elapsed / 10) << "." << (elapsed % 10) << " ms\n"; + } + + _awaiting_configure_since = -1; // Is this the inner corner or the outer corner? The Xlib docs say it // should be the outer corner, but it appears to be the inner corner on my @@ -523,6 +530,19 @@ process_events() { changed_properties = true; } + else if (_awaiting_configure_since != -1) { + unsigned long elapsed = (clock() - _awaiting_configure_since); + if (elapsed > CLOCKS_PER_SEC / 10) { + // Accept that we're never going to get that configure notify event. + if (x11display_cat.is_debug()) { + elapsed /= (CLOCKS_PER_SEC / 10000); + x11display_cat.debug() + << "Giving up on waiting for ConfigureNotify event after " + << (elapsed / 10) << "." << (elapsed % 10) << " ms\n"; + } + _awaiting_configure_since = -1; + } + } if (properties.has_foreground() && ( _properties.get_mouse_mode() == WindowProperties::M_confined || @@ -949,7 +969,7 @@ set_properties_now(WindowProperties &properties) { XReconfigureWMWindow(_display, _xwindow, _screen, value_mask, &changes); // Don't draw anything until this is done reconfiguring. - _awaiting_configure = true; + _awaiting_configure_since = clock(); } } diff --git a/panda/src/x11display/x11GraphicsWindow.h b/panda/src/x11display/x11GraphicsWindow.h index f512b16a19..ca44e4d426 100644 --- a/panda/src/x11display/x11GraphicsWindow.h +++ b/panda/src/x11display/x11GraphicsWindow.h @@ -90,7 +90,7 @@ protected: GraphicsWindowInputDevice *_input; long _event_mask; - bool _awaiting_configure; + clock_t _awaiting_configure_since; bool _dga_mouse_enabled; Bool _override_redirect; Atom _wm_delete_window;