KeyEvent stream manipulation

For what I want to do I need to have exclusive access to the keyboard events so that I can rewrite them. I have been experimenting a bit with this in XMonad, but passive grabs don't work. The problem with passive grabs is with overlapping events. This is what happens: * press key A * grab converts from passive to active * KeyEvent keyPress A is delivered to XMonad * B is pressed * KeyEvent keyPress B gets delivered to XMonad (B is registered as passive grab as well, but gets delivered, because technically, we're in an active grab now) * A is released * KeyEvent keyRelease A gets delivered to XMonad * active grab on A reverts to passive (incl some FocusEvents & KeymapNotify to inform us that B is still held) * B is released * KeyEvent keyRelease B gets NOT delivered to XMonad, it's a regular KeyEvent, no grab is active, and the passive grab on B is not triggered, because its keyPress event occurred during another (shadowing) activeGrab. (Actually, if you keep pressing B, after about a second or so, X realizes that there should be a grab active and enters the grab. Unfortunately, this is not fast enough when typing. Just to be clear, this is a problem of passive grabs, not with XMonad. Because of this behaviour it seems that the only thing that gets me there within X is a permanent active grab (keyboardGrab). Other extensions use active grabs, but they only do this for a limited time, usually after being triggered (eg. CycleRecentWS, Submap, GridHS, CycleWindows). So my questions: * Is such a permanent active grab a good idea within X? I'm worrying about problems interacting with other programs who might attempt grabs or XMonad losing the grab and not knowing about it. * If this is not a good idea, what should I look into to get this capability (exclusive access to transform the keyboard event stream, before it reaches any application). * Where/who should I ask to get an informed answer if not here? My end target are X applications, and I expect that there will be a tight integration with the window manager (likely XMonad). But I'm willing to look at a variety of points to hook into the event stream. Thanks

I put up a more extensive description of this problem on stackoverflow
at http://stackoverflow.com/questions/3781831/drop-rewrite-generate-keyboard-ev...
You can reply there or here (preferably here if it is XMonad specific,
as I haven't phrased the question in terms of XMonad on SO).
Thanks for any pointers.
On Thu, Sep 23, 2010 at 10:27 PM, Daniel
For what I want to do I need to have exclusive access to the keyboard events so that I can rewrite them. I have been experimenting a bit with this in XMonad, but passive grabs don't work.
The problem with passive grabs is with overlapping events. This is what happens: * press key A * grab converts from passive to active * KeyEvent keyPress A is delivered to XMonad * B is pressed * KeyEvent keyPress B gets delivered to XMonad (B is registered as passive grab as well, but gets delivered, because technically, we're in an active grab now) * A is released * KeyEvent keyRelease A gets delivered to XMonad * active grab on A reverts to passive (incl some FocusEvents & KeymapNotify to inform us that B is still held) * B is released * KeyEvent keyRelease B gets NOT delivered to XMonad, it's a regular KeyEvent, no grab is active, and the passive grab on B is not triggered, because its keyPress event occurred during another (shadowing) activeGrab. (Actually, if you keep pressing B, after about a second or so, X realizes that there should be a grab active and enters the grab. Unfortunately, this is not fast enough when typing.
Just to be clear, this is a problem of passive grabs, not with XMonad.
Because of this behaviour it seems that the only thing that gets me there within X is a permanent active grab (keyboardGrab). Other extensions use active grabs, but they only do this for a limited time, usually after being triggered (eg. CycleRecentWS, Submap, GridHS, CycleWindows).
So my questions: * Is such a permanent active grab a good idea within X? I'm worrying about problems interacting with other programs who might attempt grabs or XMonad losing the grab and not knowing about it. * If this is not a good idea, what should I look into to get this capability (exclusive access to transform the keyboard event stream, before it reaches any application). * Where/who should I ask to get an informed answer if not here?
My end target are X applications, and I expect that there will be a tight integration with the window manager (likely XMonad). But I'm willing to look at a variety of points to hook into the event stream.
Thanks

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 9/23/10 11:27 , Daniel wrote:
For what I want to do I need to have exclusive access to the keyboard events so that I can rewrite them. I have been experimenting a bit
This really wants to be done in (or with the active help of) the X server. You might want to look at how various accessibility-related programs work.
* active grab on A reverts to passive (incl some FocusEvents & KeymapNotify to inform us that B is still held)
When A is pressed, grab the keyboard and manage key events yourself (which is what you want to do anyway, isn't it?) until all the keys you want to work with are released, at which point you drop the grab. You should probably look for x.org-related mailing lists. - -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkyePGYACgkQIn7hlCsL25UyEACfSgFIUtW4fXREGf692AY42yoT GdgAoMzqKpGIMOnVUDPnedqfKGrVSrbg =5Kpw -----END PGP SIGNATURE-----

On Sun, Sep 26, 2010 at 1:16 AM, Brandon S Allbery KF8NH < allbery@ece.cmu.edu> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 9/23/10 11:27 , Daniel wrote:
For what I want to do I need to have exclusive access to the keyboard events so that I can rewrite them. I have been experimenting a bit
This really wants to be done in (or with the active help of) the X server. You might want to look at how various accessibility-related programs work.
I have figured that one in the meantime (Input Managers are another category of apps which are similar). Unfortunately, I haven't found any pure X based accessibility programs. Most seem to depend on D-Bus in some way. One of those would be AT-SPI initiated by Gnome (seems to be in flux at the moment).
* active grab on A reverts to passive (incl some FocusEvents & KeymapNotify to inform us that B is still held)
When A is pressed, grab the keyboard and manage key events yourself (which is what you want to do anyway, isn't it?) until all the keys you want to work with are released, at which point you drop the grab.
Good idea, didn't think about trying to promote the grab from passive to active in-flight. I'll try that one and see what comes from it.
You should probably look for x.org-related mailing lists.
Yep, I've already sent a mail off to the xorg list, as I figured that the pool of people trying to do something similar is probably larger over there. I have found two additional ways of tackling the problem. One is from an answer on the xorg list which makes use of defining an xkb mapping with 'action' key mappings. I haven't investigated it yet, and at the moment it requires a patch to the xserver which is in the X bugzilla. Another option would be to add an additional layer of indirection on top. I'm currently running the relevant Linux desktop on a VirtualBox VM. VirtualBox attaches the GUI through an inprocess mechanism, which can be remoted via a backwards compatible version of RDP (MS remote desktop protocol). If I stick an additional proxy between the two parties, then I can manipulate the keyboard events freely. Admittedly this is the last solution I will look into, because it sounds like a lot of work, and I cannot stay within XMonad to do the heavy lifting.
- -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkyePGYACgkQIn7hlCsL25UyEACfSgFIUtW4fXREGf692AY42yoT GdgAoMzqKpGIMOnVUDPnedqfKGrVSrbg =5Kpw -----END PGP SIGNATURE----- _______________________________________________ xmonad mailing list xmonad@haskell.org http://www.haskell.org/mailman/listinfo/xmonad

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 9/25/10 15:27 , Daniel wrote:
I have figured that one in the meantime (Input Managers are another category of apps which are similar). Unfortunately, I haven't found any pure X based accessibility programs. Most seem to depend on D-Bus in some way. One of those would be AT-SPI initiated by Gnome (seems to be in flux at the moment).
This seems odd; there were X11 keyboard accessibility programs before there was DBus, although I daresay DBus allows for better server integration. Input methods should do so as well, but may be a bit more painful to deal with. - -- brandon s. allbery [linux,solaris,freebsd,perl] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkyf8+UACgkQIn7hlCsL25V+bACfZ0qHQ8JJF8rQR5BA6CQOLIQ6 NQMAniYFrVULH35cg1y0yS12zuqNffys =EkK+ -----END PGP SIGNATURE-----
participants (2)
-
Brandon S Allbery KF8NH
-
Daniel