Browse Source

x11display: Time out waiting for ConfigureNotify event

Fixes #1087
rdb 3 years ago
parent
commit
0a827cf65c

+ 1 - 1
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;

+ 1 - 1
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;

+ 2 - 2
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

+ 24 - 4
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();
   }
 }
 

+ 1 - 1
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;