qt5: key repeat support

Fixes #1692
This commit is contained in:
Christian Prochaska 2015-09-21 16:58:46 +02:00 committed by Christian Helmuth
parent 0f8fcab3bd
commit fd533b0c93
2 changed files with 27 additions and 0 deletions

View File

@ -116,10 +116,24 @@ void QNitpickerPlatformWindow::_process_key_event(Input::Event *ev)
{ {
const bool pressed = (ev->type() == Input::Event::PRESS); const bool pressed = (ev->type() == Input::Event::PRESS);
const int keycode = ev->code(); const int keycode = ev->code();
if (pressed) {
_last_keycode = keycode;
_key_repeat_timer->start(KEY_REPEAT_DELAY_MS);
} else
_key_repeat_timer->stop();
_keyboard_handler.processKeycode(keycode, pressed, false); _keyboard_handler.processKeycode(keycode, pressed, false);
} }
void QNitpickerPlatformWindow::_key_repeat()
{
_key_repeat_timer->start(KEY_REPEAT_RATE_MS);
_keyboard_handler.processKeycode(_last_keycode, true, true);
}
void QNitpickerPlatformWindow::_handle_input(unsigned int) void QNitpickerPlatformWindow::_handle_input(unsigned int)
{ {
for (int i = 0, num_ev = _input_session.flush(); i < num_ev; i++) { for (int i = 0, num_ev = _input_session.flush(); i < num_ev; i++) {
@ -241,6 +255,8 @@ QNitpickerPlatformWindow::QNitpickerPlatformWindow(QWindow *window,
_resize_handle(!window->flags().testFlag(Qt::Popup)), _resize_handle(!window->flags().testFlag(Qt::Popup)),
_decoration(!window->flags().testFlag(Qt::Popup)), _decoration(!window->flags().testFlag(Qt::Popup)),
_egl_surface(EGL_NO_SURFACE), _egl_surface(EGL_NO_SURFACE),
_key_repeat_timer(this),
_last_keycode(0),
_input_signal_dispatcher(_signal_receiver, *this, _input_signal_dispatcher(_signal_receiver, *this,
&QNitpickerPlatformWindow::_input), &QNitpickerPlatformWindow::_input),
_mode_changed_signal_dispatcher(_signal_receiver, *this, _mode_changed_signal_dispatcher(_signal_receiver, *this,
@ -274,6 +290,9 @@ QNitpickerPlatformWindow::QNitpickerPlatformWindow(QWindow *window,
connect(this, SIGNAL(_mode_changed(unsigned int)), connect(this, SIGNAL(_mode_changed(unsigned int)),
this, SLOT(_handle_mode_changed(unsigned int)), this, SLOT(_handle_mode_changed(unsigned int)),
Qt::QueuedConnection); Qt::QueuedConnection);
connect(_key_repeat_timer, SIGNAL(timeout()),
this, SLOT(_key_repeat()));
} }
QWindow *QNitpickerPlatformWindow::window() const QWindow *QNitpickerPlatformWindow::window() const

View File

@ -37,6 +37,11 @@ class QNitpickerPlatformWindow : public QObject, public QPlatformWindow
private: private:
enum {
KEY_REPEAT_DELAY_MS = 500, /* 500 ms delay before first repetition */
KEY_REPEAT_RATE_MS = 50 /* 50 ms delay between repetitions */
};
Nitpicker::Connection _nitpicker_session; Nitpicker::Connection _nitpicker_session;
Framebuffer::Session_client _framebuffer_session; Framebuffer::Session_client _framebuffer_session;
unsigned char *_framebuffer; unsigned char *_framebuffer;
@ -53,6 +58,8 @@ class QNitpickerPlatformWindow : public QObject, public QPlatformWindow
bool _resize_handle; bool _resize_handle;
bool _decoration; bool _decoration;
EGLSurface _egl_surface; EGLSurface _egl_surface;
QMember<QTimer> _key_repeat_timer;
int _last_keycode;
Genode::Signal_dispatcher<QNitpickerPlatformWindow> _input_signal_dispatcher; Genode::Signal_dispatcher<QNitpickerPlatformWindow> _input_signal_dispatcher;
Genode::Signal_dispatcher<QNitpickerPlatformWindow> _mode_changed_signal_dispatcher; Genode::Signal_dispatcher<QNitpickerPlatformWindow> _mode_changed_signal_dispatcher;
@ -67,6 +74,7 @@ class QNitpickerPlatformWindow : public QObject, public QPlatformWindow
void _handle_input(unsigned int); void _handle_input(unsigned int);
void _handle_mode_changed(unsigned int); void _handle_mode_changed(unsigned int);
void _key_repeat();
Q_SIGNALS: Q_SIGNALS: