GNOME Bugzilla – Bug 161361
cross-desktop window selection focus problem
Last modified: 2005-07-24 01:19:43 UTC
Need at least two desktops. 1. open two windows on one destkop 2. give focus to one of the windows 3. switch to a different desktop 4. use the Window Selector applet to select the window that _doesn't_ have focus in the first desktop Expected result: Selected window is raised and given focus Actual result: Window is raised but not given focus This behaviour surprised me to accidentally close Evolution instead of a chat window I was trying to select. PS: I'm using metacity and click-to-focus. Applet version is 2.8.1. Metacity version 2.8.6. Fedora Core 3.
This is a libwnck (or a metacity) problem since we call wnck_window_activate (). Maybe a problem with timestamps...
Yup, a timestamp problem. And one which will require a change to the EWMH to fix (and, once that is fixed, will require modifying Metacity, libwnck, and all apps that call wnck_workspace_activate--though the changes will all be nearly trivial): When you select a window from the Window Selector applet which is not on the current workspace, the applet (via libwnck) sends a _NET_CURRENT_DESKTOP message (to switch workspaces) followed by a _NET_ACTIVE_WINDOW message (to activate the correct window) to the window manager. The former is sent without a timestamp (an EWMH problem), while the latter is sent with one... Now, when Metacity gets the _NET_CURRENT_DESKTOP message it of course calls its routines to switch workspaces. Switching workspaces always involves picking a new focus window. Whenever we focus a window, we need to provide a timestamp. Since one doesn't come with the _NET_CURRENT_DESKTOP message, metacity obtains one by requesting the current Xserver time *as soon as* it has received the _NET_CURRENT_DESKTOP message. Now, the problem is that the _NET_ACTIVE_WINDOW message does come with a timestamp and it is naturally less than the timestamp used for switching workspaces (because the timestamp for switching workspaces isn't obtained until after metacity *receives* the _NET_CURRENT_DESKTOP message, which is naturally later than when the applet is clicked on).
Add one to the "all messages, requests, and events should just have a timestamp since you will need it eventually" file.
Will all_events_need_a_timestamp_file++; be enough or should we start worrying about overflow? ;-)
*** Bug 165875 has been marked as a duplicate of this bug. ***
Putting this on the 2.10.x milestone so I don't forget it...
*** Bug 166716 has been marked as a duplicate of this bug. ***
*** Bug 167222 has been marked as a duplicate of this bug. ***
Oh, what a tangled web we weave... To correctly fix this problem, bug 128380 must first be fixed. (Without that, we'd need an additional EWMH extension because sending both a _NET_CURRENT_DESKTOP and a _NET_ACTIVE_WINDOW message with the same timestamp still results in a race. But there's no point in an additional EWMH extension when there's already something that's supposed to work...) Also, to correctly fix this for mouse and sloppy focus modes, bug 167545 will also need to be fixed (we need a clean-as-possible way to allow the invariants to be broken... *sigh*). Also, libwnck is inherently buggy in regards to timestamps because it uses gtk_get_current_event_time() instead of taking a timestamp parameter in the relevant functions. We have real-world examples already where annoying and somewhat difficult to find bugs resulted from using gtk_get_current_event_time() (see bug 166379), so we really need to fix this too. And, of course, we still need to add a timestamp to _NET_CURRENT_DESKTOP messages like this bug says...
Created attachment 37533 [details] [review] Do all the libwnck stuff This patch does all the libwnck stuff mentioned above (handle the changes to _NET_ACTIVE_WINDOW from bug 128380, make relevant functions take a timestamp parameter, add a timestamp to the _NET_CURRENT_DESKTOP message--I need to email wm-spec-list about this last change). I didn't split it into separate patches because they would have conflicted...
Created attachment 37534 [details] [review] Metacity patch to support _NET_CURRENT_DESKTOP messages with a timestamp As with the last part of the libwnck patch, I need to email wm-spec-list about this one...
Comment on attachment 37533 [details] [review] Do all the libwnck stuff This looks fine but it does change API and require the panel etc. to get rebuilt (and possibly modified), so be sure it's in line with the release policies and so forth. I'm not sure what the rule is here.
Comment on attachment 37534 [details] [review] Metacity patch to support _NET_CURRENT_DESKTOP messages with a timestamp thanks!
*** Bug 167983 has been marked as a duplicate of this bug. ***
Committed both patches, with incrementing LIBWNCK_CURRENT in libwnck/configure.in because of the API changes.
*** Bug 168041 has been marked as a duplicate of this bug. ***
Thanks a lot! :-)
The portion of the libwnck patch due to the behavioral change of _NET_ACTIVE_WINDOW has been reverted on both the gnome-2-10 branch and HEAD, because the behavioral change of _NET_ACTIVE_WINDOW in metacity was reverted (on both gnome-2-10 and HEAD). I don't think this should affect this bug since _NET_CURRENT_DESKTOP messages now come with timestamps (if it does, I can't trigger the race and others seem to claim there isn't one; regardless we still do need a way of replacing _NET_CURRENT_DESKTOP + _NET_ACTIVE_WINDOW with a single message because otherwise the panel is trying to force a particular policy instead of letting the WM decide it), but I thought it was worth mentioning. See bug 128380 for more details about this.