Bug 1162 - Keys get stuck when they're pressed when XDGASetMode is called
Summary: Keys get stuck when they're pressed when XDGASetMode is called
Status: RESOLVED INVALID
Alias: None
Product: xorg
Classification: Unclassified
Component: Server/General (show other bugs)
Version: 6.8.0
Hardware: x86 (IA32) Linux (All)
: high normal
Assignee: Xorg Project Team
QA Contact: Xorg Project Team
URL: http://x.mame.net
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-23 07:22 UTC by Hans de Goede
Modified: 2011-09-25 16:41 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Hans de Goede 2004-08-23 07:22:08 UTC
To reproduce:
-install SDL, with DGA-support compiled in and Mailstrom (Fedora Core versions
 will do fine)
-export export SDL_VIDEODRIVER=dga
-run Maelstrom from an xterm, keep the enter key pressed after typing Maelstrom, 
 untill you see the intro screen
-release the enter key
-exit from Maelstrom
-notice how the enter key is stuck, press it to unstuck it.

Now most people won't keep the enter key pressed after a command but certain
DGA using programs use hotkeys to switch from a normal window to DGA, try for
example:
-download and compile xmame-0.85 (0.86 has a workaround),
 include DGA support
-run it as root
-press alt+home at the same time to switch to DGA mode
-exit completly by pressing ESC
-notice how alt is stuck (and so is home)
Comment 1 Stian Skjelstad 2005-01-13 04:53:26 UTC
I have the same problem in my application. It has a curses interface, and a key
to activate DGA fancy graphic thing, but when I close that window again, the
terminal has never received a key release event, so it keeps re-pressing the key
that activates my fancy graphic thingy.

This bug needs to be solved as it is very annoying, but also a suggesion to how
to work around this problem if you have a buggy Xorg server with this bug. Is it
possible to forge a key-release event to all X clients from another X client,
and in that case, how?
Comment 2 Hans de Goede 2005-01-13 06:26:55 UTC
About the workaround, I've already added a workaround to xmame, the trick is not
to fake a key release after leaving DGA, but to wait for all keys to be released
before entering DGA, this can be done with the following code:

        int i;

        /* HACK HACK HACK, keys get stuck when they are pressed when
           XDGASetMode is called, so wait for all keys to be released */
        do {
          char keys[32];
          XQueryKeymap(display, keys);
          for (i=0; (i<32) && (keys[i]==0); i++) {}
        } while(i<32);
Comment 3 Stian Skjelstad 2005-01-13 08:09:28 UTC
That should work very nice *merge in after the hollyday-vacation*

Thank you!!
Comment 4 Daniel Stone 2007-02-27 01:23:53 UTC
Sorry about the phenomenal bug spam, guys.  Adding xorg-team@ to the QA contact so bugs don't get lost in future.
Comment 5 Daniel Stone 2007-04-07 14:36:39 UTC
hmm.  unless i'm mistaken, focusout should provide an implicit keyrelease.  which means you should just wait to initialise dga until you've got the focus, and then you won't have any problems?

in any case, this doesn't happen for me with xserver from master and xmame 0.106, so it could've been a problem with the old input code.

-> FIXED, please reopen if i'm wrong
Comment 6 Hans de Goede 2007-04-07 22:47:08 UTC
(In reply to comment #5)
> hmm.  unless i'm mistaken, focusout should provide an implicit keyrelease. 
> which means you should just wait to initialise dga until you've got the focus,
> and then you won't have any problems?
> 
> in any case, this doesn't happen for me with xserver from master and xmame
> 0.106, so it could've been a problem with the old input code.
> 

Please notice from the original reproduction instructions for xmame:
-download and compile xmame-0.85 (0.86 has a workaround),

xmame-106 still has this workaround:
        int i;

        /* HACK HACK HACK, keys get stuck when they are pressed when
           XDGASetMode is called, so wait for all keys to be released */
        do {
          char keys[32];
          XQueryKeymap(display, keys);
          for (i=0; (i<32) && (keys[i]==0); i++) {}
        } while(i<32);


Sine I'm no longer active as xmame author / maintainer I even don't have it installed, I did try the Maelstrom reproduction described with the initial bug report too: To reproduce:
-install SDL, with DGA-support compiled in and Mailstrom (Fedora Core versions
 will do fine)
-export export SDL_VIDEODRIVER=dga
-run Maelstrom from an xterm, keep the enter key pressed after typing Maelstrom, 
 untill you see the intro screen
-release the enter key
-exit from Maelstrom
-notice how the enter key is stuck, press it to unstuck it.

With this reproduction method the enter key still gets stuck. Hint, for some reason Maelstrom's display is garbled for me, to exit press a key and then 'q'

> -> FIXED, please reopen if i'm wrong
> 

Reopening.
Comment 7 Daniel Stone 2007-04-08 01:23:46 UTC
'which means you should just wait to initialise dga until you've got the focus, and then you won't have any problems?'

apologies if it seemed like 'kinda works now' was the operative part, but this was the salient part of the message.  if you do a dga keyboard redirection before focus change, then i would expect breakage to ensue.  is this the case?
Comment 8 Hans de Goede 2007-04-08 01:37:30 UTC
(In reply to comment #7)
> 'which means you should just wait to initialise dga until you've got the focus,
> and then you won't have any problems?'
> 
> apologies if it seemed like 'kinda works now' was the operative part, but this
> was the salient part of the message.  if you do a dga keyboard redirection
> before focus change, then i would expect breakage to ensue.  is this the case?
> 

I dunno, i haven't looked at the code for ages and I don't have it available at the moment (can still get to it though) also this used to work back in the XFree 3.x days. Also notice that I've posted reproduction instructions for SDL using apps too, which is code which I didn't even write.

I think its the responsibility of the X-server to properly maintain the key state, currently when a DGA app exits the X-server is reporting keys as pressed while they aren't. Least but not last, if I remember correctly neither xmame nor SDL use dga keyboard redirection, instead the grab the keyboard using the root window as grab window, so that they can still use normal XEvent processing for the keyboard independend of wether they are using DGA or a plain X-window.

Comment 9 Jeremy Huddleston Sequoia 2011-09-25 16:41:50 UTC
Closing based on Daniel's comments.

Alternatively, don't use DGA.  Yuck.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.