Browse Source

x11: Add function for detecting auto repeat key events (#1735)

omn14 8 months ago
parent
commit
98a50a794d

+ 4 - 0
panda/src/x11display/config_x11display.cxx

@@ -91,6 +91,10 @@ ConfigVariableBool x_send_startup_notification
           "lets the window manager know that an application has launched, so "
           "that it no longer needs to display a spinning mouse cursor."));
 
+ConfigVariableBool x_detectable_auto_repeat
+("x-detectable-auto-repeat", false,
+ PRC_DESC("Set this true to enable detectable auto-repeat for keyboard input."));
+
 /**
  * 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/x11display/config_x11display.h

@@ -37,5 +37,6 @@ extern ConfigVariableInt x_cursor_size;
 extern ConfigVariableString x_wm_class_name;
 extern ConfigVariableString x_wm_class;
 extern ConfigVariableBool x_send_startup_notification;
+extern ConfigVariableBool x_detectable_auto_repeat;
 
 #endif

+ 22 - 2
panda/src/x11display/x11GraphicsWindow.cxx

@@ -97,8 +97,7 @@ x11GraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
                   int flags,
                   GraphicsStateGuardian *gsg,
                   GraphicsOutput *host) :
-  GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host)
-{
+  GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) {
   x11GraphicsPipe *x11_pipe;
   DCAST_INTO_V(x11_pipe, _pipe);
   _display = x11_pipe->get_display();
@@ -126,6 +125,8 @@ x11GraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
   PT(GraphicsWindowInputDevice) device = GraphicsWindowInputDevice::pointer_and_keyboard(this, "keyboard_mouse");
   add_input_device(device);
   _input = device;
+
+  enable_detectable_auto_repeat();
 }
 
 /**
@@ -2745,3 +2746,22 @@ xim_preedit_done(XIC ic, XPointer client_data, XPointer call_data) {
   x11GraphicsWindow *window = (x11GraphicsWindow *)client_data;
   window->handle_preedit_done();
 }
+
+/**
+ * Enables detectable auto-repeat if supported by the X server.
+ */
+void x11GraphicsWindow::
+enable_detectable_auto_repeat() {
+  if (!x_detectable_auto_repeat) {
+    return;
+  }
+  
+  Bool supported;
+  if (XkbSetDetectableAutoRepeat(_display, True, &supported)) {
+    x11display_cat.info() << "Detectable auto-repeat enabled.\n";
+  } else if (!supported) {
+    x11display_cat.warning() << "Detectable auto-repeat is not supported by the X server.\n";
+  } else {
+    x11display_cat.error() << "Failed to set detectable auto-repeat.\n";
+  }
+}

+ 2 - 0
panda/src/x11display/x11GraphicsWindow.h

@@ -46,6 +46,8 @@ public:
 
   INLINE X11_Window get_xwindow() const;
 
+  void enable_detectable_auto_repeat();
+
 protected:
   virtual void close_window();
   virtual bool open_window();