summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2003-04-23 18:49:57 +0000
committerDaniel Stenberg <daniel@haxx.se>2003-04-23 18:49:57 +0000
commiteae511030cd7540e37a11d4c6d5147fd5c186a1a (patch)
treef5658e9f0bd569faa840cba8d877be00cc3cdaac
parent4ccffb658931503b3badb70a99d72a0cfb9834b1 (diff)
downloadrockbox-eae511030cd7540e37a11d4c6d5147fd5c186a1a.tar.gz
rockbox-eae511030cd7540e37a11d4c6d5147fd5c186a1a.zip
Now supports key-repeat in the simulator!
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3594 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--uisimulator/x11/button-x11.c16
-rw-r--r--uisimulator/x11/screenhack.c60
-rw-r--r--uisimulator/x11/screenhack.h4
3 files changed, 54 insertions, 26 deletions
diff --git a/uisimulator/x11/button-x11.c b/uisimulator/x11/button-x11.c
index 9f009f0e72..ae16e2e891 100644
--- a/uisimulator/x11/button-x11.c
+++ b/uisimulator/x11/button-x11.c
@@ -18,6 +18,7 @@
****************************************************************************/
#include "button.h"
#include "kernel.h"
+#include "debug.h"
#include "X11/keysym.h"
@@ -62,15 +63,15 @@ int button_set_release(int newmask)
* Q=On Return=Menu
*/
-/* from uibasic.c */
-extern int screenhack_handle_events(bool *release);
+extern int screenhack_handle_events(bool *release, bool *repeat);
static int get_raw_button (void)
{
int k;
bool release=false; /* is this a release event */
-
- switch(screenhack_handle_events(&release))
+ bool repeat=false; /* is the key a repeated one */
+ int ev=screenhack_handle_events(&release, &repeat);
+ switch(ev)
{
case XK_KP_Left:
case XK_Left:
@@ -145,13 +146,18 @@ static int get_raw_button (void)
default:
k = 0;
+ if(ev)
+ DEBUGF("received ev %d\n", ev);
break;
}
- if ( release )
+ if(release)
/* return a release event */
k |= BUTTON_REL;
+ if(repeat)
+ k |= BUTTON_REPEAT;
+
return k;
}
diff --git a/uisimulator/x11/screenhack.c b/uisimulator/x11/screenhack.c
index 81650b57d7..c4d43e5eb7 100644
--- a/uisimulator/x11/screenhack.c
+++ b/uisimulator/x11/screenhack.c
@@ -57,6 +57,8 @@
#include "version.h"
#include "vroot.h"
+#include "debug.h"
+
#ifndef isupper
# define isupper(c) ((c) >= 'A' && (c) <= 'Z')
#endif
@@ -207,14 +209,28 @@ static Bool MapNotify_event_p (Display *dpy, XEvent *event, XPointer window)
static Atom XA_WM_PROTOCOLS, XA_WM_DELETE_WINDOW;
-/* Dead-trivial event handling: exits if "q" or "ESC" are typed.
+static Bool checkrepeat(time_t prev,
+ time_t now)
+{
+ if(now-prev < 50) {
+ DEBUGF("Consider this a button repeat\n");
+ return true;
+ }
+ return false;
+}
+
+/* Dead-trivial event handling.
Exit if the WM_PROTOCOLS WM_DELETE_WINDOW ClientMessage is received.
*/
-int screenhack_handle_event(Display *dpy, XEvent *event, bool *release)
+int screenhack_handle_event(Display *dpy, XEvent *event,
+ bool *release, bool *repeat)
{
int key=0;
+ static time_t lasttime;
+ static unsigned int lastkeycode;
*release = FALSE;
+ *repeat = false;
switch (event->xany.type) {
case KeyPress:
@@ -223,7 +239,15 @@ int screenhack_handle_event(Display *dpy, XEvent *event, bool *release)
unsigned char c = 0;
XLookupString (&event->xkey, &c, 1, &keysym, 0);
key = keysym;
- /* fprintf(stderr, "KEY PRESSED: %c (%02x)\n", c, c); */
+#if 0
+ DEBUGF("Got keypress: %02x %x, time %lx\n", c,
+ event->xkey.keycode,
+ event->xkey.time);
+#endif
+ if(lastkeycode == event->xkey.keycode)
+ *repeat = checkrepeat(lasttime, event->xkey.time);
+ lasttime = event->xkey.time;
+ lastkeycode = event->xkey.keycode;
}
break;
case KeyRelease:
@@ -232,29 +256,27 @@ int screenhack_handle_event(Display *dpy, XEvent *event, bool *release)
unsigned char c = 0;
XLookupString (&event->xkey, &c, 1, &keysym, 0);
key = keysym;
- /* fprintf(stderr, "KEY RELEASED: %c (%02x) %x\n", c, c,
- event->xkey.keycode); */
-
+#if 0
+ DEBUGF("Got keyrelease: %c (%02x) %x\n", c, c,
+ event->xkey.keycode);
+#endif
+ if(lastkeycode == event->xkey.keycode)
+ *repeat = checkrepeat(lasttime, event->xkey.time);
+ lasttime = event->xkey.time;
+ lastkeycode = event->xkey.keycode;
+ if(*repeat)
+ return 0; /* on repeats, return nothing on release */
+
*release = TRUE;
}
break;
case Expose:
{
- /*
- int x=event->xexpose.width+event->xexpose.x;
- int y=event->xexpose.height+event->xexpose.y;
- screen_resized(x, y);
- fprintf(stderr, "WINDOW RESIZED to width %d height %d\n",
- x, y);
- */
screen_redraw();
}
break;
default:
break;
- case ButtonPress:
- fprintf(stderr, "BUTTON PRESSED: x: %d y:%d\n",event->xbutton.x,event->xbutton.y);
- break;
case ClientMessage:
{
if (event->xclient.message_type != XA_WM_PROTOCOLS) {
@@ -281,14 +303,14 @@ int screenhack_handle_event(Display *dpy, XEvent *event, bool *release)
}
-int screenhack_handle_events(bool *release)
+int screenhack_handle_events(bool *release, bool *repeat)
{
int key=0;
- while (XPending(dpy))
+ if(XPending(dpy))
{
XEvent event;
XNextEvent(dpy, &event);
- key=screenhack_handle_event(dpy, &event, release);
+ key=screenhack_handle_event(dpy, &event, release, repeat);
}
return key;
}
diff --git a/uisimulator/x11/screenhack.h b/uisimulator/x11/screenhack.h
index ac9b01bf75..f4496d69c5 100644
--- a/uisimulator/x11/screenhack.h
+++ b/uisimulator/x11/screenhack.h
@@ -40,8 +40,8 @@ extern XrmOptionDescRec options [];
extern char *defaults [];
extern void screenhack (Display*,Window);
-extern int screenhack_handle_event(Display*, XEvent*, bool *);
-extern int screenhack_handle_events(bool *);
+extern int screenhack_handle_event(Display*, XEvent*, bool *, bool *);
+extern int screenhack_handle_events(bool *, bool *);
extern void screen_redraw();
extern void screen_resized();