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

Cherry-picked from master
This commit is contained in:
omn14 2025-04-16 13:52:24 +02:00 committed by rdb
parent 23782ec511
commit a01e039669
4 changed files with 69 additions and 2 deletions

View File

@ -84,6 +84,10 @@ ConfigVariableString x_wm_class
PRC_DESC("Specify the value to use for the res_class field of the window's "
"WM_CLASS property."));
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

View File

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

View File

@ -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();
@ -123,6 +122,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();
}
/**
@ -2442,3 +2443,62 @@ cleanup:
return ret;
}
/**
*
*/
int x11GraphicsWindow::
xim_preedit_start(XIC ic, XPointer client_data, XPointer call_data) {
x11GraphicsWindow *window = (x11GraphicsWindow *)client_data;
return window->handle_preedit_start();
}
/**
*
*/
void x11GraphicsWindow::
xim_preedit_draw(XIC ic, XPointer client_data,
XIMPreeditDrawCallbackStruct *call_data) {
x11GraphicsWindow *window = (x11GraphicsWindow *)client_data;
nassertv_always(call_data != nullptr);
window->handle_preedit_draw(*call_data);
}
/**
*
*/
void x11GraphicsWindow::
xim_preedit_caret(XIC ic, XPointer client_data,
XIMPreeditCaretCallbackStruct *call_data) {
x11GraphicsWindow *window = (x11GraphicsWindow *)client_data;
nassertv_always(call_data != nullptr);
window->handle_preedit_caret(*call_data);
}
/**
*
*/
void x11GraphicsWindow::
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";
}
}

View File

@ -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();