diff options
author | Jens Arnold <amiconn@rockbox.org> | 2005-03-18 23:51:52 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2005-03-18 23:51:52 +0000 |
commit | 74b731edc6e0495d43a37412c60cd23a24789679 (patch) | |
tree | e4d4014047b65f4cf05e9c0ba3d48a05a1eb04f9 /uisimulator/x11/screenhack.c | |
parent | 9101465ae83fd89ebcdf55fc3e831dfca74884ea (diff) | |
download | rockbox-74b731edc6e0495d43a37412c60cd23a24789679.tar.gz rockbox-74b731edc6e0495d43a37412c60cd23a24789679.zip |
Major rework of the x11 simulator button handling. (1) Button repeat should always work correctly now, not sending a release before the repeat(s). Fixes e.g. calling the Ondio menu. (2) Button handling is done in the timer thread, not sleep()ing the main thread for extended times. Fixes slow performance of high-workload plugins (codec tests). (3) The x11 simulator now also contains the queue handling code. (4) The new code requires X11R6 because the multi-threading extension is used.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6215 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/x11/screenhack.c')
-rw-r--r-- | uisimulator/x11/screenhack.c | 69 |
1 files changed, 33 insertions, 36 deletions
diff --git a/uisimulator/x11/screenhack.c b/uisimulator/x11/screenhack.c index d7f21a60ce..d8731e4125 100644 --- a/uisimulator/x11/screenhack.c +++ b/uisimulator/x11/screenhack.c | |||
@@ -125,6 +125,8 @@ char having_new_lcd=True; | |||
125 | char *progname; | 125 | char *progname; |
126 | XrmDatabase db; | 126 | XrmDatabase db; |
127 | XtAppContext app; | 127 | XtAppContext app; |
128 | Display* dpy; | ||
129 | Window window; | ||
128 | Bool mono_p; | 130 | Bool mono_p; |
129 | 131 | ||
130 | static XrmOptionDescRec default_options [] = { | 132 | static XrmOptionDescRec default_options [] = { |
@@ -155,8 +157,8 @@ static char *default_defaults[] = { | |||
155 | 0 | 157 | 0 |
156 | }; | 158 | }; |
157 | 159 | ||
158 | extern Display* dpy; | ||
159 | extern int display_zoom; | 160 | extern int display_zoom; |
161 | extern long current_tick; | ||
160 | 162 | ||
161 | static XrmOptionDescRec *merged_options; | 163 | static XrmOptionDescRec *merged_options; |
162 | static int merged_options_size; | 164 | static int merged_options_size; |
@@ -238,27 +240,23 @@ static Bool MapNotify_event_p (Display *dpy, XEvent *event, XPointer window) | |||
238 | 240 | ||
239 | static Atom XA_WM_PROTOCOLS, XA_WM_DELETE_WINDOW; | 241 | static Atom XA_WM_PROTOCOLS, XA_WM_DELETE_WINDOW; |
240 | 242 | ||
241 | static Bool checkrepeat(time_t prev, | 243 | |
242 | time_t now) | 244 | void kb_disable_auto_repeat(bool on) |
243 | { | 245 | { |
244 | if(now-prev < 50) { | 246 | XKeyboardControl kb; |
245 | return true; | 247 | |
246 | } | 248 | kb.auto_repeat_mode = on ? AutoRepeatModeOff : AutoRepeatModeDefault; |
247 | return false; | 249 | XChangeKeyboardControl(dpy, KBAutoRepeatMode, &kb); |
248 | } | 250 | } |
249 | 251 | ||
250 | /* Dead-trivial event handling. | 252 | /* Dead-trivial event handling. |
251 | Exit if the WM_PROTOCOLS WM_DELETE_WINDOW ClientMessage is received. | 253 | Exit if the WM_PROTOCOLS WM_DELETE_WINDOW ClientMessage is received. |
252 | */ | 254 | */ |
253 | int screenhack_handle_event(Display *dpy, XEvent *event, | 255 | int screenhack_handle_event(XEvent *event, bool *release) |
254 | bool *release, bool *repeat) | ||
255 | { | 256 | { |
256 | int key=0; | 257 | int key=0; |
257 | static time_t lasttime; | ||
258 | static unsigned int lastkeycode; | ||
259 | 258 | ||
260 | *release = FALSE; | 259 | *release = FALSE; |
261 | *repeat = false; | ||
262 | 260 | ||
263 | switch (event->xany.type) { | 261 | switch (event->xany.type) { |
264 | case KeyPress: | 262 | case KeyPress: |
@@ -268,14 +266,9 @@ int screenhack_handle_event(Display *dpy, XEvent *event, | |||
268 | XLookupString (&event->xkey, &c, 1, &keysym, 0); | 266 | XLookupString (&event->xkey, &c, 1, &keysym, 0); |
269 | key = keysym; | 267 | key = keysym; |
270 | #if 0 | 268 | #if 0 |
271 | DEBUGF("Got keypress: %02x %x, time %lx\n", c, | 269 | DEBUGF("Got keypress: %c (%02x) %x, tick %ld\n", c, c, |
272 | event->xkey.keycode, | 270 | event->xkey.keycode, current_tick); |
273 | event->xkey.time); | ||
274 | #endif | 271 | #endif |
275 | if(lastkeycode == event->xkey.keycode) | ||
276 | *repeat = checkrepeat(lasttime, event->xkey.time); | ||
277 | lasttime = event->xkey.time; | ||
278 | lastkeycode = event->xkey.keycode; | ||
279 | } | 272 | } |
280 | break; | 273 | break; |
281 | case KeyRelease: | 274 | case KeyRelease: |
@@ -285,22 +278,21 @@ int screenhack_handle_event(Display *dpy, XEvent *event, | |||
285 | XLookupString (&event->xkey, &c, 1, &keysym, 0); | 278 | XLookupString (&event->xkey, &c, 1, &keysym, 0); |
286 | key = keysym; | 279 | key = keysym; |
287 | #if 0 | 280 | #if 0 |
288 | DEBUGF("Got keyrelease: %c (%02x) %x\n", c, c, | 281 | DEBUGF("Got keyrelease: %c (%02x) %x, tick %ld\n", c, c, |
289 | event->xkey.keycode); | 282 | event->xkey.keycode, current_tick); |
290 | #endif | 283 | #endif |
291 | if(lastkeycode == event->xkey.keycode) | ||
292 | *repeat = checkrepeat(lasttime, event->xkey.time); | ||
293 | lasttime = event->xkey.time; | ||
294 | lastkeycode = event->xkey.keycode; | ||
295 | if(*repeat) | ||
296 | return 0; /* on repeats, return nothing on release */ | ||
297 | |||
298 | *release = TRUE; | 284 | *release = TRUE; |
299 | } | 285 | } |
300 | break; | 286 | break; |
301 | case Expose: | 287 | case Expose: |
302 | screen_redraw(); | 288 | screen_redraw(); |
303 | break; | 289 | break; |
290 | case FocusIn: | ||
291 | kb_disable_auto_repeat(true); | ||
292 | break; | ||
293 | case FocusOut: | ||
294 | kb_disable_auto_repeat(false); | ||
295 | break; | ||
304 | case ClientMessage: | 296 | case ClientMessage: |
305 | if (event->xclient.message_type != XA_WM_PROTOCOLS) { | 297 | if (event->xclient.message_type != XA_WM_PROTOCOLS) { |
306 | char *s = XGetAtomName(dpy, event->xclient.message_type); | 298 | char *s = XGetAtomName(dpy, event->xclient.message_type); |
@@ -320,6 +312,8 @@ int screenhack_handle_event(Display *dpy, XEvent *event, | |||
320 | progname, s1, s2); | 312 | progname, s1, s2); |
321 | } | 313 | } |
322 | else { | 314 | else { |
315 | kb_disable_auto_repeat(false); | ||
316 | XSync(dpy, false); /* force the X server to process that */ | ||
323 | exit (0); | 317 | exit (0); |
324 | } | 318 | } |
325 | break; | 319 | break; |
@@ -330,15 +324,17 @@ int screenhack_handle_event(Display *dpy, XEvent *event, | |||
330 | } | 324 | } |
331 | 325 | ||
332 | 326 | ||
333 | int screenhack_handle_events(bool *release, bool *repeat) | 327 | int screenhack_handle_events(bool *release) |
334 | { | 328 | { |
335 | int key=0; | 329 | int key=0; |
330 | XtAppLock(app); | ||
336 | if(XPending(dpy)) | 331 | if(XPending(dpy)) |
337 | { | 332 | { |
338 | XEvent event; | 333 | XEvent event; |
339 | XNextEvent(dpy, &event); | 334 | XNextEvent(dpy, &event); |
340 | key=screenhack_handle_event(dpy, &event, release, repeat); | 335 | key=screenhack_handle_event(&event, release); |
341 | } | 336 | } |
337 | XtAppUnlock(app); | ||
342 | return key; | 338 | return key; |
343 | } | 339 | } |
344 | 340 | ||
@@ -347,7 +343,7 @@ static Visual *pick_visual (Screen *screen) | |||
347 | { | 343 | { |
348 | #ifdef USE_GL | 344 | #ifdef USE_GL |
349 | /* If we're linking against GL (that is, this is the version of | 345 | /* If we're linking against GL (that is, this is the version of |
350 | screenhack.o that the GL hacks will use, which is different from the | 346 | screenhack.o that the GL hacks will use, which is different from the |
351 | one that the non-GL hacks will use) then try to pick the "best" visual | 347 | one that the non-GL hacks will use) then try to pick the "best" visual |
352 | by interrogating the GL library instead of by asking Xlib. GL knows | 348 | by interrogating the GL library instead of by asking Xlib. GL knows |
353 | better. | 349 | better. |
@@ -379,8 +375,6 @@ static Visual *pick_visual (Screen *screen) | |||
379 | int main (int argc, char **argv) | 375 | int main (int argc, char **argv) |
380 | { | 376 | { |
381 | Widget toplevel; | 377 | Widget toplevel; |
382 | Display *dpy; | ||
383 | Window window; | ||
384 | Screen *screen; | 378 | Screen *screen; |
385 | Visual *visual; | 379 | Visual *visual; |
386 | Colormap cmap; | 380 | Colormap cmap; |
@@ -460,9 +454,11 @@ int main (int argc, char **argv) | |||
460 | does work when passed as an -xrm arg on the command line. So screw it, | 454 | does work when passed as an -xrm arg on the command line. So screw it, |
461 | turn them off from C instead. | 455 | turn them off from C instead. |
462 | */ | 456 | */ |
463 | SgiUseSchemes ("none"); | 457 | SgiUseSchemes ("none"); |
464 | #endif /* __sgi */ | 458 | #endif /* __sgi */ |
465 | 459 | ||
460 | XtToolkitThreadInitialize(); | ||
461 | |||
466 | toplevel = XtAppInitialize (&app, progclass, merged_options, | 462 | toplevel = XtAppInitialize (&app, progclass, merged_options, |
467 | merged_options_size, &argc, argv, | 463 | merged_options_size, &argc, argv, |
468 | merged_defaults, 0, 0); | 464 | merged_defaults, 0, 0); |
@@ -556,7 +552,7 @@ int main (int argc, char **argv) | |||
556 | XGetWindowAttributes (dpy, window, &xgwa); | 552 | XGetWindowAttributes (dpy, window, &xgwa); |
557 | XSelectInput (dpy, window, | 553 | XSelectInput (dpy, window, |
558 | xgwa.your_event_mask | KeyPressMask | KeyRelease | | 554 | xgwa.your_event_mask | KeyPressMask | KeyRelease | |
559 | ButtonPressMask | ExposureMask); | 555 | ButtonPressMask | ExposureMask | FocusChangeMask ); |
560 | XChangeProperty (dpy, window, XA_WM_PROTOCOLS, XA_ATOM, 32, | 556 | XChangeProperty (dpy, window, XA_WM_PROTOCOLS, XA_ATOM, 32, |
561 | PropModeReplace, | 557 | PropModeReplace, |
562 | (unsigned char *) &XA_WM_DELETE_WINDOW, 1); | 558 | (unsigned char *) &XA_WM_DELETE_WINDOW, 1); |
@@ -573,6 +569,7 @@ int main (int argc, char **argv) | |||
573 | 569 | ||
574 | XSync (dpy, False); | 570 | XSync (dpy, False); |
575 | 571 | ||
576 | screenhack (dpy, window); /* doesn't return */ | 572 | kb_disable_auto_repeat(true); |
573 | screenhack(); /* doesn't return */ | ||
577 | return 0; | 574 | return 0; |
578 | } | 575 | } |