From 6826450c8312ab13b52f13728dd4f6433e8f79fb Mon Sep 17 00:00:00 2001 From: mzuther Date: Sun, 11 Jul 2010 11:17:41 +0000 Subject: X11 driver: possibility to ignore auto-repeated KeyPress events git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1125 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- drv_X11.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drv_X11.c b/drv_X11.c index b3f627e..cc54241 100644 --- a/drv_X11.c +++ b/drv_X11.c @@ -94,6 +94,8 @@ static GC gc; static Colormap cm; static Pixmap pm; +static int allow_autorepeat = 1; /* consider auto-repeated KeyPress events? */ + static char myDisplayName[256] = ""; static int opTableEntries = 2; static XrmOptionDescRec opTable[] = { @@ -363,6 +365,9 @@ static void drv_X11_timer( __attribute__ ((unused)) && XCheckTypedWindowEvent(dp, w, ClientMessage, &ev) == 0) return; + /* check whether key has been retriggered by "auto repeat" */ + unsigned short is_retriggered = 0; + switch (ev.type) { case Expose: @@ -429,6 +434,19 @@ static void drv_X11_timer( __attribute__ ((unused)) break; case KeyRelease: + /* check whether key has been retriggered by "auto repeat" */ + if (!allow_autorepeat && XEventsQueued(dp, QueuedAfterReading)) { + XEvent nev; + XPeekEvent(dp, &nev); + + if (nev.type == KeyPress && nev.xkey.time == ev.xkey.time && nev.xkey.keycode == ev.xkey.keycode) { + is_retriggered = 1; + + /* delete retriggered KeyPress event */ + XNextEvent(dp, &ev); + } + } + key = XLookupKeysym(&ev.xkey, 0); switch (key) { case XK_Up: @@ -451,7 +469,7 @@ static void drv_X11_timer( __attribute__ ((unused)) break; } /* only register key release if button is defined on GUI */ - if (btn > 0) { + if (!is_retriggered && (btn > 0)) { if (btn <= buttons) { debug("key for button %i released", btn); XClearArea(dp, w, xoffset, yoffset + (btn - 1) * (btnheight + pgap), btnwidth, btnheight - 2, @@ -572,6 +590,9 @@ static int drv_X11_start(const char *section) free(s); } + /* consider auto-repeated KeyPress events? */ + cfg_number(section, "autorepeat", 1, 0, 1, &allow_autorepeat); + /* virtual keyboard: number of buttons (0..6) */ if (cfg_number(section, "buttons", 0, 0, 6, &buttons) < 0) return -1; -- cgit v1.2.3