After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 317405 - Add desktop window as a backup choice for focus window when MRU list contains no valid choices
Add desktop window as a backup choice for focus window when MRU list contains...
Status: RESOLVED FIXED
Product: metacity
Classification: Other
Component: general
2.12.x
Other All
: Normal minor
: 2.14.x
Assigned To: Metacity maintainers list
Metacity maintainers list
Depends on:
Blocks:
 
 
Reported: 2005-09-28 07:54 UTC by Runar Ingebrigtsen
Modified: 2006-01-16 06:09 UTC
See Also:
GNOME target: ---
GNOME version: 2.11/2.12


Attachments
patch - focus to desktop when MRU has no other choices (1.37 KB, patch)
2006-01-14 22:35 UTC, Kyle Ambroff
needs-work Details | Review
patch - focus to desktop when MRU has no other choices (v2) (1.30 KB, patch)
2006-01-15 05:54 UTC, Kyle Ambroff
needs-work Details | Review
set focus to desktop when MRU has no valid window choices (v3) (1.79 KB, patch)
2006-01-16 05:41 UTC, Kyle Ambroff
committed Details | Review

Description Runar Ingebrigtsen 2005-09-28 07:54:16 UTC
Closing all programs gives focus to the panel, rather than the desktop (which is
Nautilus). The user believes he is at the desktop and tries to use "CTRL+L" to
get the location dialog. This doesn't work because the panel has focus. The user
have to click the desktop first, then "CTRL+L". This doesn't make sense because
he thought he was at the desktop.

I suggest the Nautilus location shortcut should work when the panel has focus.

Other information:
Comment 1 Vincent Untz 2005-10-01 09:33:03 UTC
I don't think the panel has the focus. It seems like nothing has the focus...
This would be a metacity problem.
Comment 2 Elijah Newren 2005-10-01 14:23:53 UTC
No, closing all programs doesn't give the focus to the panel, or any other
"real" window (it gives focus to the default no-focus-window).  I'm not sure why
I'd expect a user to think that a file manager shortcut would work when there
"aren't any file manager windows open" (yeah, the desktop is a nautilus window
but not many people know that--are the icons on the desktop really a big enough
hint that users would expect this?).  
Comment 3 Runar Ingebrigtsen 2005-10-02 13:39:26 UTC
I'd say yes. In Windows, both the taskbar and the desktop is Explorer. Once you
know a little you'd expect shortcuts to work at both places.
Comment 4 Björn Lindqvist 2005-10-11 07:03:19 UTC
Is there a reason why the desktop isn't always given focus when no other window
has it? 
Comment 5 Elijah Newren 2005-11-14 17:19:01 UTC
See this thread:
http://mail.gnome.org/archives/metacity-devel-list/2005-November/msg00001.html.
 Unless Havoc pipes up and objects (or rejects the patch once it is written),
the suggested change of having the desktop be focused when other windows are
closed will be made.
Comment 6 Elijah Newren 2005-12-27 16:49:35 UTC
Well, I was going to write this patch when I had 10 minutes, but it looks like a great task for someone looking to get involved.  One just needs to modify metacity/src/workspace.c:focus_ancestor_or_mru_window() such that if it gets through the MRU list and doesn't find a valid window, then go through it again looking for a desktop window.

It'd also be nice if the volunteer can update metacity/doc/how-to-get-focus-right.txt at the same time, though that may be more difficult and I can handle that half.
Comment 7 Kyle Ambroff 2006-01-14 22:35:55 UTC
Created attachment 57370 [details] [review]
patch - focus to desktop when MRU has no other choices

This works for me.
Comment 8 Elijah Newren 2006-01-14 23:30:49 UTC
Comment on attachment 57370 [details] [review]
patch - focus to desktop when MRU has no other choices

Thanks for working on this.  It looks good, all I have is a few nitpicks:

Please remove all the tabs in your patch and replace them with spaces.  I know some have crept into Metacity already, but it has been accidental ;)

>+      else if (tmp_window->type == META_WINDOW_DESKTOP)

Almost what you want; there's two minor problems:
  - It may be the case that tmp_window != not_this_one or meta_window_showing_on_its_workspace (tmp_window).  While I can only think of contrived ways to make either possible, it may make the code harder to understand without those checks in there as any windows satsifying those conditions isn't wanted.
  - This will give you the LRU (least recently used) desktop window instead of the MRU one.

>+	  desktop_window = (MetaWindow *) tmp_window;

The typecast is unnecessary; tmp_window is already a MetaWindow*.  ;-)

>+  else if (desktop_window)
>+    {
>+      meta_topic (META_DEBUG_FOCUS,
>+                  "Focusing workspace MRU window %s\n", desktop_window->desc);
>+
>+      meta_window_focus (desktop_window, timestamp);
>+	    
>+      /* Also raise the window in click-to-focus */
>+      if (meta_prefs_get_focus_mode () == META_FOCUS_MODE_CLICK)
>+	meta_window_raise (desktop_window);

This code is correct, though it seems like unnecessary code duplication of the code in the 'if' above it.  I'm afraid we'll modify one of the two in the future for some new feature and forget to modify the other.  It should be possible to have only one copy of this code block; it's not something that would prevent the patch from getting in but it'd be great if you could try to merge the two.
Comment 9 Elijah Newren 2006-01-14 23:36:35 UTC
Oops, I totally got my logic backwards here:

>   - It may be the case that tmp_window != not_this_one or
> meta_window_showing_on_its_workspace (tmp_window).  While I can only think of
> contrived ways to make either possible, it may make the code harder to
> understand without those checks in there as any windows satsifying those
> conditions isn't wanted.

Various phrases above should read instead as "may not be the case", "ways to make either not be true,", and "as only windows satisfying those conditions are wanted".

If I've totally confused you here, let me know and I'll try to clear things up with an alternate explanation.
Comment 10 Kyle Ambroff 2006-01-15 05:54:39 UTC
Created attachment 57385 [details] [review]
patch - focus to desktop when MRU has no other choices (v2)

Thanks for your help Elijah! Sorry about the tabs, I removed them. I think this new patch should be ok.

>   - This will give you the LRU (least recently used) desktop window instead of
> the MRU one.

I think I understand this. I added a check to see if desktop_window was NULL. This means it will stop at the most recently used desktop window, right?
Comment 11 Elijah Newren 2006-01-16 00:05:16 UTC
Comment on attachment 57385 [details] [review]
patch - focus to desktop when MRU has no other choices (v2)

>+               tmp_window->type != META_WINDOW_DOCK &&

Although it doesn't hurt anything, this above line is unnecessary because of the next line:

>+               tmp_window->type == META_WINDOW_DESKTOP)



>+  /* If no window was found, default to the desktop-window */
>+  if (window == NULL && desktop_window != NULL)

The desktop_window != NULL check isn't necessary as the result would be the same.  Perhaps, though, keeping it in just as you already have it is more clear?  I don't know, but anyway it's probably not worth worrying about so feel free to leave this as it is.

>+          window = desktop_window;

Should only be four leading spaces here instead of 8 or however many there are.

Can you fix the couple issues above and create an entry for the ChangeLog?
Comment 12 Kyle Ambroff 2006-01-16 05:41:57 UTC
Created attachment 57451 [details] [review]
set focus to desktop when MRU has no valid window choices (v3)

Ok, I fixed the problems with my last patch, and added an entry to the ChangeLog. Thank you for your patience Elijah.
Comment 13 Elijah Newren 2006-01-16 06:09:26 UTC
Thanks!  I committed it; it'll be in the tarball rolled tomorrow and you'll be in the NEWS and ChangeLog files.  ;-)