Bug 601 - There is no trivial way to make a difference between "useful" events and "useless" release events generated by default by XOrg
Summary: There is no trivial way to make a difference between "useful" events and "use...
Status: RESOLVED FIXED
Alias: None
Product: Newt
Classification: JogAmp
Component: x11 (show other bugs)
Version: 1
Hardware: All linux
: --- enhancement
Assignee: Sven Gothel
URL: http://forum.jogamp.org/NEWT-KeyEvent...
Depends on:
Blocks:
 
Reported: 2012-07-02 13:40 CEST by Julien Gouesse
Modified: 2012-10-27 02:51 CEST (History)
3 users (show)

See Also:
Type: ---
SCM Refs:
jogl 646714d3dab87396b9a3119bf90ca26e0b1c97ce jogl 8777a6f0b8d5aa7c97643c68c4641593c6fa2c46 jogl b008de41549e38aebdfcb7b094046235a8dde72f jogl 2f9c77a347b76bebdadd4bec1ac92aa7ab72365f
Workaround: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Julien Gouesse 2012-07-02 13:40:34 CEST
The useless release events are generated in the native level by XOrg, this is its default behavior. It means that a release event is generated just before the next press event for the same key or mouse button. NEWT is quite low level, this behavior is platform-dependent but as it is a Java API, developers may expect the same behavior for the same feature on all supported platforms which is not currently the case as Microsoft Windows do not generate these useless release events.

There are three options:
- do not modify the API
- allow to enable or disable the auto-repeat
- mark "useless" release events as auto-repeat events

The first option is not satisfying as each developer working on higher level APIs will have to implement some "tricks" to ignore these events and it is more difficult when you cannot access them in the native code.

The second option is nice for gaming in full screen mode but not for general applications as it is impossible to set this value for a single program but rather for the whole session (XAutoRepeatOff or XkbSetDetectableAutorepeat). Maybe some developers don't know how to use a shutdown hook.

The third solution is the safest one, existing applications require no change, it won't change the way events are delivered, the same approach is used in Qt (see QKeyEvent::isAutoRepeat()). This example might be helpful:
http://stackoverflow.com/posts/3220822/revisions

Maybe it should be done only in JOGL 2.1 to avoid changing the public API now.
Comment 1 Sven Gothel 2012-09-16 16:02:38 CEST
How about we do solution 3 + add these useless auto-repeat events on other platforms ?
Then we would also have the same behavior .. and the information required.

How about OSX ?

On Windows we can simply inject the release event as auto-repeat,
on X11 as done in you link.

Good stuff

~Sven
Comment 2 Julien Gouesse 2012-09-16 16:40:23 CEST
(In reply to comment #1)
> How about we do solution 3 + add these useless auto-repeat events on other
> platforms ?
> Then we would also have the same behavior .. and the information required.
That's better, good idea, it would be more consistent.

> 
> How about OSX ?
> 
I don't know Mac OS X a lot. I can investigate tomorrow if you want.

> On Windows we can simply inject the release event as auto-repeat,
> on X11 as done in you link.
Why not injecting them as "useful" events under Windows instead of marking them all useless?

> 
> Good stuff
> 
> ~Sven
Thanks.

Maybe there are auto-repeat mechanisms under Windows for accessibility but I don't know its APIs a lot.
Comment 3 Sven Gothel 2012-09-16 21:16:58 CEST
http://jogamp.org/git/?p=jogl.git;a=commit;h=646714d3dab87396b9a3119bf90ca26e0b1c97ce

com.jogamp.newt.event.KeyEvent:

Key events are delivered in the following order:

1 EVENT_KEY_PRESSED
2 EVENT_KEY_RELEASED
3 EVENT_KEY_TYPED

In case the native platform does not deliver keyboard events in the above order or skip events, 
the NEWT driver will reorder and inject synthetic events if required.

Besides regular modifiers like InputEvent##SHIFT_MASK etc., the InputEvent.AUTOREPEAT_MASK bit is added if repetition is detected.

Hope this suits us .. and matches your expectations.
Comment 4 Sven Gothel 2012-09-16 21:26:00 CEST
Completed .. w/ commit 8777a6f0b8d5aa7c97643c68c4641593c6fa2c46
Comment 5 Julien Gouesse 2012-09-16 21:42:45 CEST
(In reply to comment #4)
> Completed .. w/ commit 8777a6f0b8d5aa7c97643c68c4641593c6fa2c46

Thank you very much. I will look at the modifications, test them and modify Ardor3D (remove our dirty hacks).
Comment 6 Sven Gothel 2012-10-25 16:21:49 CEST
We have figured out that the event sequence w/ auto-repeat is not consistent.

Note Event order:
  EVENT_KEY_PRESSED
  EVENT_KEY_RELEASED
  EVENT_KEY_TYPED

D = pressed, U = released, T = typed
0 = normal, 1 = auto-repeat

D(0), [ U(1), T(1), D(1), U(1) T(1) ..], U(0) T(0)

The idea is if you mask out auto-repeat in your event listener
you just get one long pressed key D/U/T triple.
Comment 7 Sven Gothel 2012-10-26 16:45:12 CEST
Adding unit tests for typed key order w/ and w/o auto repeat. Incl. fix for Windows.
    
Auto-Repeat tests recognizes whether auto-repeat could be triggered by AWT Robot.
The latter is not possible on Windows, hence manual testing was required on this platform.
    
Impact: X11, Windows and OSX produce proper key sequence incl. auto-repeat modifier mask.

http://jogamp.org/git/?p=jogl.git;a=commit;h=b008de41549e38aebdfcb7b094046235a8dde72f
Comment 8 Sven Gothel 2012-10-27 02:51:17 CEST
Enhanced w/ multiple key support, see Bug 631 and:
  <http://jogamp.org/git/?p=jogl.git;a=commit;h=2f9c77a347b76bebdadd4bec1ac92aa7ab72365f>