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 571051 - Evince steals focus when opening a file
Evince steals focus when opening a file
Status: RESOLVED FIXED
Product: evince
Classification: Core
Component: general
2.24.x
Other Linux
: Normal normal
: ---
Assigned To: Evince Maintainers
Evince Maintainers
Depends on:
Blocks:
 
 
Reported: 2009-02-09 14:34 UTC by Wouter Bolsterlee (uws)
Modified: 2013-05-03 00:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed fix (519 bytes, patch)
2009-02-09 19:37 UTC, Wouter Bolsterlee (uws)
none Details | Review

Description Wouter Bolsterlee (uws) 2009-02-09 14:34:12 UTC
Evince steals focus and shows up on top of other windows. This is reproducible for me when I interact with Nautilus just after double-clicking a PDF file (before Evince pops up): the Nautilus window gets obscured by the newly opened Evince window, even after I click on another file in the Nautilus window before the Evince window shows up.

This behaviour is highly annoying, and I believe Evince did behave correctly in the past. Any clue what's happening?
Comment 1 Mariano Suárez-Alvarez 2009-02-09 16:51:05 UTC
In a probably related note, evince is moving its window to the top when the file changes---this is driving me crazy in Fedora 10's evince 2.24.2.
Comment 2 Wouter Bolsterlee (uws) 2009-02-09 16:54:20 UTC
Mariano, agreed, I'm having the same issue here. See bug #304249 for that. (Work-around: minimize the Evince window when writing/compiling LaTeX ;))
Comment 3 Wouter Bolsterlee (uws) 2009-02-09 18:23:47 UTC
After some investigation, it turns out that calling gtk_window_maximize() and gtk_window_unmaximize() makes the window move to the front, at least with Metacity 2.24.x. The setup_size_from_metadata() function inside shell/ev-window.c is called on each document load, and this function calls either gtk_window_maximize() or gtk_window_unmaximize(), depending on the value coming from the "window_maximized" key stored in the metadata file for this uri.

After applying the trivial patch below, Evince does no longer insists on moving the window to the top when a document is (re)loaded, but obviously this change removes the "remember maximization state" feature.

Index: shell/ev-window.c
===================================================================
--- shell/ev-window.c	(revision 3425)
+++ shell/ev-window.c	(working copy)
@@ -989,11 +989,11 @@
 
 	if (ev_metadata_manager_get (uri, "window_maximized", &maximized, FALSE)) {
 		if (g_value_get_boolean (&maximized)) {
-			gtk_window_maximize (GTK_WINDOW (window));
+			// gtk_window_maximize (GTK_WINDOW (window));
 			g_value_unset (&maximized);
 			return;
 		} else {
-			gtk_window_unmaximize (GTK_WINDOW (window));
+			// gtk_window_unmaximize (GTK_WINDOW (window));
 		}
 		g_value_unset (&maximized);
 	}
Comment 4 Wouter Bolsterlee (uws) 2009-02-09 19:35:29 UTC
(In reply to comment #3)
> The setup_size_from_metadata() function inside
> shell/ev-window.c is called on each document load, and
> this function calls either gtk_window_maximize() or
> gtk_window_unmaximize(), depending on the value coming
> from the "window_maximized" key stored in the metadata
> file for this uri.

I should also point out that (un)maximizing is a no-op when reloading the document, since the window is already shown, and in the right state.
Comment 5 Wouter Bolsterlee (uws) 2009-02-09 19:37:36 UTC
Created attachment 128320 [details] [review]
Proposed fix

This patch avoids resizing the window when reloading a document. This fixes the problem described in this bug report for me, and addresses the issue described 304249#131.
Comment 6 Wouter Bolsterlee (uws) 2009-02-09 19:43:26 UTC
I meant bug #304249#c131
Comment 7 Carlos Garcia Campos 2009-02-10 10:28:02 UTC
(In reply to comment #5)
> Created an attachment (id=128320) [edit]
> Proposed fix
> 
> This patch avoids resizing the window when reloading a document. This fixes the
> problem described in this bug report for me, and addresses the issue described
> 304249#131.
> 

The thing is that we should never use the metadata stuff when reloading the document. I've reworked the metadata handling when loading an re-loading. Please try it out (svn trunk r3426) and let me know whether it works. Thanks. 

Comment 8 Wouter Bolsterlee (uws) 2009-02-10 10:34:36 UTC
Confirming that current SVN trunk works just as well as after applying my patch... ;) Yes, I know the code is a lot cleaner now. Thanks.
Comment 9 Wouter Bolsterlee (uws) 2009-02-10 10:37:17 UTC
Regarding this part of your patch:

        if (ev_metadata_manager_get (uri, "window_maximized", &maximized, FALSE)) {
                if (g_value_get_boolean (&maximized)) {
                        gtk_window_maximize (GTK_WINDOW (window));
+                       g_value_unset (&maximized);
+                       return;
                } else {
                        gtk_window_unmaximize (GTK_WINDOW (window));
                }
                g_value_unset (&maximized);
        }


Does reusing "&maximized" and unsetting it twice not cause any problems? (Note: I don't know anything about GValue.)
Comment 10 Wouter Bolsterlee (uws) 2009-02-10 10:39:19 UTC
Ehm, please disregard comment 9. I missed the "return" ;)
Comment 11 Wouter Bolsterlee (uws) 2009-02-10 10:45:58 UTC
Carlos, while we're at it: setup_view_from_metadata() contains this piece of code:

    /* Fullscreen */
    if (ev_metadata_manager_get (uri, "fullscreen", &fullscreen, FALSE)) {
        if (g_value_get_boolean (&fullscreen) && uri) {
            ev_window_run_fullscreen (window);
        }
        g_value_unset (&fullscreen);
    }

This causes Evince to start in full screen mode, and there is no easy way out if you don't know what's happening (i.e. you don't know you have to press Escape). This is seriously bad UI IMHO, and I remember others complaining about this as well. What about ditching this? There is no use case for this feature.
Comment 12 Wouter Bolsterlee (uws) 2009-02-10 11:00:02 UTC
See bug #309364, btw.
Comment 13 Mariano Suárez-Alvarez 2009-02-10 17:59:01 UTC
Should this be closed FIXED?
Comment 14 Wouter Bolsterlee (uws) 2009-02-10 18:22:22 UTC
No, because comment 11 has not been addressed yet.
Comment 15 Germán Poo-Caamaño 2013-05-03 00:09:59 UTC
I am closing this as fixed.  The missing part in comment 11 is already addressed with the toolbar that allows the user to leave the fullscreen state.