aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormzuther <mzuther@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2010-01-20 10:59:43 +0000
committermzuther <mzuther@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2010-01-20 10:59:43 +0000
commit04562ff4b758f446c9ce4d99234f359ebf4f3651 (patch)
tree4e5049b78753b0165e47571403f43328cde5d9e8
parenteb67cb9dabaf5942dec2caef646a7ff0b269e1db (diff)
downloadlcd4linux-04562ff4b758f446c9ce4d99234f359ebf4f3651.tar.gz
X11 driver: handle key presses (arrows, RET and ESC) in addition to clicks on the GUI buttons
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1088 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
-rw-r--r--drv_X11.c74
1 files changed, 72 insertions, 2 deletions
diff --git a/drv_X11.c b/drv_X11.c
index 2fac8e6..b9b7854 100644
--- a/drv_X11.c
+++ b/drv_X11.c
@@ -343,11 +343,13 @@ static void drv_X11_timer( __attribute__ ((unused))
{
XEvent ev;
XRectangle exp;
+ KeySym key;
int xoffset = border + (DCOLS / XRES) * cgap + DCOLS * (pixel + pgap);
int yoffset = border + (DROWS / YRES) * rgap;
static int btn = 0;
- if (XCheckWindowEvent(dp, w, ExposureMask | ButtonPressMask | ButtonReleaseMask, &ev) == 0
+ if (XCheckWindowEvent
+ (dp, w, ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask, &ev) == 0
/* there is no ClientMessageMask, so this will be checked separately */
&& XCheckTypedWindowEvent(dp, w, ClientMessage, &ev) == 0)
return;
@@ -379,6 +381,74 @@ static void drv_X11_timer( __attribute__ ((unused))
drv_X11_expose(exp.x, exp.y, exp.width, exp.height);
break;
+ case KeyPress:
+ key = XLookupKeysym(&ev.xkey, 0);
+ switch (key) {
+ case XK_Up:
+ btn = 1;
+ break;
+ case XK_Down:
+ btn = 2;
+ break;
+ case XK_Left:
+ btn = 3;
+ break;
+ case XK_Right:
+ btn = 4;
+ break;
+ case XK_Return:
+ btn = 5;
+ break;
+ case XK_Escape:
+ btn = 6;
+ break;
+ default:
+ btn = 0;
+ }
+ /* only register key press if button is defined on GUI */
+ if ((btn > 0) && (btn <= buttons)) {
+ debug("key for button %i pressed", btn);
+ drv_X11_color(BG_COL, 255);
+ XFillRectangle(dp, w, gc, xoffset + 1, yoffset + (btn - 1) * (btnheight + pgap) + 1, btnwidth - 1,
+ btnheight - 2 - 1);
+ drv_generic_keypad_press(btn);
+ } else {
+ debug("key press for button %i ignored", btn);
+ }
+ break;
+
+ case KeyRelease:
+ key = XLookupKeysym(&ev.xkey, 0);
+ switch (key) {
+ case XK_Up:
+ btn = 1;
+ break;
+ case XK_Down:
+ btn = 2;
+ break;
+ case XK_Left:
+ btn = 3;
+ break;
+ case XK_Right:
+ btn = 4;
+ break;
+ case XK_Return:
+ btn = 5;
+ break;
+ case XK_Escape:
+ btn = 6;
+ break;
+ }
+ /* only register key release if button is defined on GUI */
+ if ((btn > 0) && (btn <= buttons)) {
+ debug("key for button %i released", btn);
+ XClearArea(dp, w, xoffset, yoffset + (btn - 1) * (btnheight + pgap), btnwidth, btnheight - 2,
+ 1 /* true */ );
+ } else {
+ debug("key release for button %i ignored", btn);
+ }
+ break;
+
case ButtonPress:
if (ev.xbutton.x >= xoffset && ev.xbutton.x <= xoffset + btnwidth
&& ev.xbutton.y >= yoffset && ev.xbutton.y <= yoffset + buttons * btnheight + (buttons - 1) * pgap) {
@@ -530,7 +600,7 @@ static int drv_X11_start(const char *section)
btnheight = (DROWS * pixel + (DROWS - 1) * pgap) / buttons;
}
- wa.event_mask = ExposureMask | ButtonPressMask | ButtonReleaseMask;
+ wa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask;
sh.min_width = sh.max_width = dimx + 2 * border + btnwidth;
sh.min_height = sh.max_height = dimy + 2 * border;