Browse Source

windisplay: add a variable to disable Panda's message pump

This is particularly important for Tcl/Tk, which assumes it is in charge of the Windows event loop.

Fixes #586
rdb 6 years ago
parent
commit
55f624e073

+ 4 - 0
direct/src/showbase/ShowBase.py

@@ -3050,6 +3050,10 @@ class ShowBase(DirectObject.DirectObject):
 
         init_app_for_gui()
 
+        # Disable the Windows message loop, since Tcl wants to handle this all
+        # on its own.
+        ConfigVariableBool('disable-message-loop', False).value = True
+
         if ConfigVariableBool('tk-main-loop', True):
             # Put Tkinter in charge of the main loop.  It really
             # seems to like this better; the GUI otherwise becomes

+ 7 - 0
panda/src/windisplay/config_windisplay.cxx

@@ -91,6 +91,13 @@ ConfigVariableBool paste_emit_keystrokes
  PRC_DESC("Handle paste events (Ctrl-V) as separate keystroke events for each "
           "pasted character."));
 
+ConfigVariableBool disable_message_loop
+("disable-message-loop", false,
+ PRC_DESC("If this is false, Panda will process messages from the Windows "
+          "message loop, which is required for normal operation.  You may set "
+          "this to true if some other UI framework (such as Tcl/Tk) needs "
+          "exclusive ownership of the message loop."));
+
 /**
  * Initializes the library.  This must be called at least once before any of
  * the functions or classes in this library can be used.  Normally it will be

+ 1 - 0
panda/src/windisplay/config_windisplay.h

@@ -32,6 +32,7 @@ extern ConfigVariableBool request_dxdisplay_information;
 extern ConfigVariableBool dpi_aware;
 extern ConfigVariableBool dpi_window_resize;
 extern ConfigVariableBool paste_emit_keystrokes;
+extern ConfigVariableBool disable_message_loop;
 
 extern EXPCL_PANDAWIN ConfigVariableBool swapbuffer_framelock;
 

+ 6 - 4
panda/src/windisplay/winGraphicsWindow.cxx

@@ -254,10 +254,12 @@ process_events() {
 
   MSG msg;
 
-  // Handle all the messages on the queue in a row.  Some of these might be
-  // for another window, but they will get dispatched appropriately.
-  while (PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE)) {
-    process_1_event();
+  if (!disable_message_loop) {
+    // Handle all the messages on the queue in a row.  Some of these might be
+    // for another window, but they will get dispatched appropriately.
+    while (PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE)) {
+      process_1_event();
+    }
   }
 }