njsmith / partiwm

[defunct] Experiments with window managers in Python + GTK+, including the original version of xpra
GNU General Public License v2.0
23 stars 3 forks source link

real keyboard support #6

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
xpra's keyboard support is pretty lame.

We should probably stop sending shift over the wire, and we should probably
start remapping the keyboard whenever it is annoying. (libfakekey is
actually some existing code that uses the same approach, though we wouldn't
want to use it directly.)

The super-fancy way to do this would be to keep an LRU of which keyvals the
user transmits, and keep the top ~150 mapped at any given moment. Much
stupider approaches will work too.

Critical functions for this: gtk.gdk.keyval_to_unicode,
gtk.gdk.unicode_to_keyval

(But note that not all keyvals can be represented as unicode, even though
all unicode can be represented as keyvals using a complex encoding
mechanism that gdk, fortunately, already knows. Fortunately, even weird
unicode characters have a keyval name, as in
gtk.gdk.keyval_name/gtk.gdk.keyval_from_name -- "U<xxxx>".) 

Original issue reported on code.google.com by njsmith@ucsd.edu on 7 Nov 2009 at 5:13

GoogleCodeExporter commented 9 years ago
Another part of this problem is handling missed key events (e.g., user puts key 
down,
changes focus, and then releases the key -- we only see the key down, not the 
key up).

Initial report:

    http://thread.gmane.org/gmane.comp.window-managers.parti.general/22

Background: the source of the problem here is that the xpra client receives a
key-down event for Alt_L, but never receives a key-up event. That's fine; apps 
never
care whether they see both halves of this kind of event -- some apps (e.g. OOo) 
look
for Alt like a normal key, so if they get the event they do something (like 
activate
the menu) but if they don't then eh, and some (all) apps care whether the 
modifier
bits are set on other key events they receive, but no-one actually needs to 
match up
the beginning and end of things like Alt presses.

For xpra's purposes, this is tricky because: we do want to forward keys like 
Alt_L,
to make things like OOo's menu access functionality work. But, having forwarded 
the
key-down, we *have to know that that key is down and that that's why the meta 
bit is
set* because later on, when we receive a key event *without* the meta bit set, 
the
only way we can disable the meta bit is to synthesize an unpress of Alt_L. (And
ideally doing something to prevent any app from getting that synthetic event 
and like
activating the menu or something -- maybe grab the keyboard before issuing the 
fake
event.) Currently we detect that the meta bit should be released, and we try to 
do
that, but we do it by unpressing the key that *we* would have used to enable 
the meta
bit, which doesn't help because the X server doesn't think that that key is down
anyway. We have to unpress the *actual* key that enabled the meta bit.

I don't see how to do this without some very careful tracking of which keysyms
activate which bits in the modifier state vector, and really the modifier map 
on the
client and server will have to match, ugh.

Option 1: fully mirror all X keyboard-fu from the client whenever a client 
connects
(or has its keyboard reconfigured). This is even probably-not-that-hard if we 
only
have to worry about core keyboard handling; if we have to handle Xkb then 
AIEEEEE.
Then build some sort of keyboard state tracking machinery ourselves to figure 
out
what's going on. This state tracking machinery has to exactly match that in the 
X
server AIEEEEEEEEE.

Option 2: simply do not forward modifier keypresses from the client to the 
server (or
have the server ignore them, not sure which is cleaner). Make the server's 
synthetic
modifier handling be the *only* modifier handling. This breaks the case where 
tapping
Alt_L activates the menu in OOo, and I'm sure that will annoy someone sooner or
later; I'm not sure I care. Also, we can't filter out Shift at the moment 
without
breaking everything -- so the problem will persist for Shift. Sigh.

Question: is it possible to ask the X server which keys are depressed? If so, 
then
that's both good and bad -- good because it would allow us to sync up state
occasionally by having the client query and then tell the server, bad because it
would require state tracking for *all* keys to make things fully correct on the
server side. (Hmm, but if it's possible, then maybe there's a radically 
different
approach to keyboard handling: whenever the client receives a key event of any 
sort,
it ignores what the event actually says and instead just deltas the new keyboard
state against the previously-sent keyboard state and sends *that* to the 
server. That
might be nice... it also requires the ability to package up keyboard 
configuration
and send it over, though.) 

Original comment by njsmith@ucsd.edu on 7 Nov 2009 at 5:15

GoogleCodeExporter commented 9 years ago
It is possible to ask the X server which keys are pressed -- XQueryKeymap 
returns a
bitmap (among other things). (Cribbed from x11vnc source.)

*But* the clever state synchronization approach described at the end there won't
work, because we need to know the *order* in which keys are pressed, not just 
which
keys are pressed. Sigh.

Original comment by njsmith@ucsd.edu on 7 Nov 2009 at 5:15

GoogleCodeExporter commented 9 years ago
I have worked around this on my setup. The problem was that alt was not being 
recognised as a modifier key and so upon switching back to the window in 
question, 
the resetting of the modifiers didn't include alt. My xmodmap lists the Alt_L 
and 
Alt_R keys under mod1, and has no entries for alt, and the other keys 
grok_modifier_map lists after mod1-5. If in xpra/keys.py I add mod1 to that 
list, add 
an entry in _keyname_for_mod in xpra/server.py, it correctly unsets them.

There is code to work out what modifiers should mean in grok_modifier_map, I 
see, but 
it won't work because Alt_L is said to mean "alt" rather than "mod1" in that 
function. (And also that seems to be disabled in the latest version.)

Original comment by thefishf...@gmail.com on 28 Apr 2010 at 11:38

GoogleCodeExporter commented 9 years ago
For me personally the problem was the shift key locking. After investigating 
thefishface's fix I put in some debug statements and found that the cause was 
my 
GNOME shortcut for switching keyboard layouts: both shift keys together. This 
led to 
client.py:_key_action to act like this:

= 'Shift' down =
name = Shift_L
modifiers = []
depressed = True

= 'Shift' up =
name = ISO_Prev_Group
modifiers = ['shift']
depressed = False

Thus xpra never sends the shift release and the SHOUTING starts.

I don't know enough about X keyboard handling to speculate on the root cause; 
I'll 
just disable the shortcut key when working from home. :)

Original comment by lastor...@gmail.com on 1 May 2010 at 11:33

GoogleCodeExporter commented 9 years ago
Note to self: what I'm currently thinking as a strategy is: client sends 
modifier/keycode/keyval mapping to server, as a kind of FYI. On key events, 
client sends: keycode, list of keyvals associated with that keycode, list of 
modifier bits, possibly the interpreted keyval (arguably shouldn't be 
necessary, but). Server pokes around at the keymap as necessary to get 
something equivalent, and if there are any mismatched modifiers, it grabs the 
keyboard and issues some keypresses to straighten them out. (This might take 
some trial and error, because of issues like locking vs. non-locking modifier 
keys, but that's okay, we can just keep poking the keys until the modifier map 
looks right.)

Remember to put up all keys before applying a change to the modifier map...

Original comment by njsmith@ucsd.edu on 3 Aug 2010 at 5:38

GoogleCodeExporter commented 9 years ago
I first encountered xpra two days ago and really liked the idea. The keyboard 
issues are problematic. I would think the goal would be to get the X 
functionality as close to X forwarding as possible. Why not use a model similar 
to the one used to send events over ssh X forwarding? Maybe forwarding _all_ 
kbd input, even when windows aren't focused, should do the job. 

Original comment by gwach...@gmail.com on 23 Aug 2010 at 7:47

GoogleCodeExporter commented 9 years ago
This also mangles Alt-Tab, when you Alt-Tab back the Alt key is stuck until you 
re-press it.

Original comment by norm...@google.com on 4 May 2011 at 9:17

GoogleCodeExporter commented 9 years ago
I just got xpra working between my Linux workstation and Mac laptop.  This is 
exactly the kind of solution I was looking for, so I want to thank the 
developer.

With that said, the stuck keys problem in this issue is proving a real 
annoyance.  So I am essentially doing a "bump" to this issue.

Original comment by mtennant@chromium.org on 10 May 2011 at 11:25

GoogleCodeExporter commented 9 years ago
This issue became more of a showstopper for me just yesterday.  I use a Linux 
desktop at work, and when I left work one of my X applications that I am 
running through xpra (XEmacs) was in the state where it thought the Linux 'Alt' 
key was down.  I went home and attached the xpra session to my Mac, and the 
XEmacs application was unrecoverable.  I never could find the key or key 
sequence on the Mac keyboard that would send the "alt key up" signal I needed 
to use the XEmacs application.

Only when I got back to work today, attached the session to my Linux desktop 
again, was I able to recover the application by pressing the 'Alt' key.

Without a workaround in this scenario this becomes a much greater concern for 
me.  I do hope a solution can be implemented, because I love the concept.

Original comment by mtennant@chromium.org on 12 May 2011 at 5:02

GoogleCodeExporter commented 9 years ago
You're not saying which version you have installed, so I assume that this is 
0.0.6 from the partiwm releases?
If so, bear in mind that there were some significant improvements in the 
repository since that release.

Also, you may want to try the xpra packages I provide here:
http://winswitch.org/downloads/
In v0.0.7.20 I added a workaround for modifier keys with multiple keyval 
mappings, this mostly solved the problems for me (although I don't use the 
intel mac client natively - only through VirtualBox, which may hide some 
keyboard mapping issues)

I will probably re-write this workaround^W hack in the future as it is not 
particularly efficient or elegant (but the important thing is, it seems to 
work!).

I would appreciate if you could let me know is this works (or even if not) for 
you.

(sorry for the re-post: I replied to list instead of bug tracker)

Original comment by tot...@gmail.com on 13 May 2011 at 3:48

GoogleCodeExporter commented 9 years ago
Hi,

You're correct, I am using the 0.0.6 version, on both Linux and Mac.  For
Linux (ubuntu) it was what came with "apt-get install xpra".

I'm happy to try something more recent from the repository and give you
feedback.  Is there a particular tag or branch I should try, or the current
head?

Original comment by mtennant@chromium.org on 13 May 2011 at 9:37

GoogleCodeExporter commented 9 years ago
Hi,

I tried the latest source on Linux (ubuntu), downloading with this command:
hg clone https://partiwm.googlecode.com/hg/ partiwm

I was able to build it after installing the packages you suggested in
README.xpra (since I previous got xpra itself via aptitude).  Note that your
suggested list of packages should say "cython" instead of "python-cython".

I tested it out, and the behavior appears to be no different from before.
 Every time I "Alt-Tab" between X applications running through xpra, I have
to hit 'alt' one more time.

At this point, I don't think I will install the newer version to my Mac, as
it doesn't appear to be promising.  Am I missing something?  It sounds like
you expected different results.  Or perhaps I didn't get a newer version
like I thought I did.  The output of "xpra --version" (the newly compiled
xpra) is still 0.0.6.  I am assuming you just haven't bumped it, yet.

-Matt

Original comment by mtennant@chromium.org on 13 May 2011 at 10:46

GoogleCodeExporter commented 9 years ago
Looks like you went through a lot of effort to download and compile the source 
(upstream - not my version), but you haven't tried the link I had posted?
http://winswitch.org/downloads/
Try that first. The keymap fix I refer to is not upstream (yet).

Original comment by tot...@gmail.com on 14 May 2011 at 5:00

GoogleCodeExporter commented 9 years ago
It appears I misunderstood your previous message, then.  I thought you
mentioned winswitch.org as an alternative, not your recommendation.  I
looked at it more closely, and for awhile I wondered what winswitch had to
do with xpra.  I was hesitant to download anything from the download page
you listed.

However, after checking the FAQ page I understood the connection between
winswitch and xpra.  Then I found http://winswitch.org/src/ , where I was
able to download xpra-0.0.7.20 directly.  I built and tried that out on my
ubuntu (version 10.04) workstation (xpra servera and client), but found the
"stuck key" (specifically the "alt" key) behavior to be unchanged.  Again, I
will hold off on installing this to my Mac (my second xpra client) given
that it does not seem to be an improvement.

As an aside, I noticed that running "./xpra --version" with this download
still produces "xpra v0.0.6".  I am absolutely certain I grabbed the right
tarball, because the tarball has the version number in the name.  I am also
certain I am running the 'xpra' executable that was compiled within that
source.  So either the version number was not bumped in the source, or the
tarball at http://winswitch.org/src/ was not loaded properly.  If the latter
is true, then perhaps I still haven't tested the correct fix, yet.

-Matt

Original comment by mtennant@chromium.org on 16 May 2011 at 8:11

GoogleCodeExporter commented 9 years ago
Like David responded on the mailing list (David: Matt only reads the 
bugtracker): you are not using the version you downloaded from winswitch (you 
probably still have the old copy installed first on your PYTHONPATH, remove it).
The reason why you are not seeing improvements is because you aren't using 
it... As for the "hesitant to download" from my site, I am afraid I can't 
really help you with that: it's not just open-source, but every build script 
and installer files are available and documented... your call.

Also, note that you will need this newer version on the Mac client, it is 
included in the DMGs available on the site. You must upgrade both the server(s) 
and clients, the v0.0.7.x branch is no longer compatible with the old v0.0.6.x 
(which is now almost 3 years old)

Original comment by tot...@gmail.com on 17 May 2011 at 3:24