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 556696 - jumps to other screen in dual monitor setup after file is loaded
jumps to other screen in dual monitor setup after file is loaded
Status: RESOLVED FIXED
Product: mutter
Classification: Core
Component: general
3.4.x
Other Linux
: Normal normal
: ---
Assigned To: mutter-maint
mutter-maint
: 659658 674641 679158 686646 687069 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2008-10-17 10:22 UTC by Sebastien Bacher
Modified: 2018-02-05 15:11 UTC
See Also:
GNOME target: ---
GNOME version: 2.21/2.22


Attachments
maximize.c (1.11 KB, text/x-csrc)
2012-11-20 16:56 UTC, Alban Crequy
  Details
[PATCH] Fix maximised window jumping to other monitor in dual monitor setup (1.66 KB, patch)
2012-11-23 00:26 UTC, Alban Crequy
none Details | Review
[PATCH] Fix maximised window jumping to other monitor in dual monitor setup (2.28 KB, patch)
2012-11-28 18:57 UTC, Alban Crequy
needs-work Details | Review
[PATCH] Initialize window->user_rect in the initial placement (1.52 KB, patch)
2012-11-29 14:22 UTC, Alban Crequy
committed Details | Review

Description Sebastien Bacher 2008-10-17 10:22:59 UTC
the bug has been opened on https://bugs.launchpad.net/ubuntu/+source/evince/+bug/284427

"Binary package hint: evince

Steps to reproduce this behavior in Ubuntu 8.04 (Hardy Heron) using Evince Document Viewer 2.22.2:

1) Launch Evince from Nautilus
2) Maximize Evince on secondary monitor
3) Close Evince
4) Launch Evince from Nautilus on secondary monitor
5) Evince opens maximized on secondary monitor
6) When the file is completely loaded it jumps maximized to the primary monitor

The problem doesn't occur if Evince is maximized on the primary monitor or if it is left unmaximized in step 2."
Comment 1 Reza Mohammadi 2010-06-15 14:41:25 UTC
Something like this happens for me but for Gedit. I guess it's related to the metacity. My steps:

1) Launch Gedit (mouse should be in the primary monitor which is in the right of the secondary monitor and so 0,0 is in the secondary monitor - actually not exactly 0,0 because resolution of my secondary monitor differs from the primary and is aligned to bottom)
2) Maximize Gedit on the right monitor
3) Close Gedit
4) Open Gedit (mouse should be in the right monitor again)
- Gedit should be maximized in the right monitor in this step
5) Click on an menu item
6) move the pointer on one of the items in the menu list
Gedit jumps to the left monitor for me, although the menu list is still in the right monitor
Comment 2 james 2012-04-17 06:01:11 UTC
This happens to me also and has done for years. It's extremely annoying. Is there any interest to fix this or is there more information needed?
Comment 3 Travis Reitter 2012-11-01 23:55:53 UTC
I was able to reproduce this just now with Gnome 3.4.2 / Fedora 17.
Comment 4 Alban Crequy 2012-11-19 16:21:18 UTC
(In reply to comment #3)
> I was able to reproduce this just now with Gnome 3.4.2 / Fedora 17.

Do you reproduce this in gedit or in evince? I can reproduce the problem but only with gedit. I guess it is a bug in mutter.

It goes through this code:
  gedit/gedit-app.c:780:gedit_app_create_window_real()
	gtk_window_maximize (GTK_WINDOW (window));

This sends a X event to the window manager:
  _NET_WM_STATE _NET_WM_STATE_MAXIMIZED_VERT, _NET_WM_STATE_MAXIMIZED_HORZ

And gnome-shell/mutter receives it in src/core/window.c meta_window_client_message().
Comment 5 Travis Reitter 2012-11-19 18:28:31 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > I was able to reproduce this just now with Gnome 3.4.2 / Fedora 17.
> 
> Do you reproduce this in gedit or in evince? I can reproduce the problem but
> only with gedit. I guess it is a bug in mutter.

Actually, I hadn't tried gedit, but it does have the same behavior, so it makes sense that it might be a Mutter bug.

Note that if I open gedit by name, it appears on the same screen as the cursor. But if I open a document (which had last been viewed as maximized) in Nautilus, regardless of whether it's handled by gedit or Evince, it briefly displays it on the smaller (non-primary) screen, then moves it to the other screen.

> It goes through this code:
>   gedit/gedit-app.c:780:gedit_app_create_window_real()
>     gtk_window_maximize (GTK_WINDOW (window));
> 
> This sends a X event to the window manager:
>   _NET_WM_STATE _NET_WM_STATE_MAXIMIZED_VERT, _NET_WM_STATE_MAXIMIZED_HORZ
> 
> And gnome-shell/mutter receives it in src/core/window.c
> meta_window_client_message().
Comment 6 Alban Crequy 2012-11-20 16:56:19 UTC
Created attachment 229486 [details]
maximize.c

This small program triggers the same window jump. It is racy, so the jump will sometimes happen during gtk_statusbar_push and sometimes in gtk_statusbar_remove.
Comment 7 Germán Poo-Caamaño 2012-11-20 19:15:35 UTC
The test case has nothing to do with evince.  Re-assigning to mutter.
Comment 8 Alban Crequy 2012-11-21 15:30:53 UTC
In mutter/src/core/window.c:meta_window_update_monitor(), I added:
  meta_topic (META_DEBUG_PLACEMENT,
              "meta_window_update_monitor: window %s moves from monitor %d to %d\n",
              window->desc, old->number, window->monitor->number);

And I notice the following logs when the bug happens:

meta_screen_get_monitor_for_window: window 0x1a00003 (maximize) has rect x=1366 y=27 w=1680 h=1023
meta_screen_get_monitor_for_rect: comparing with monitor 0: rect x=1366 y=0 w=1680 h=1050
meta_screen_get_monitor_for_rect: comparing with monitor 1: rect x=0 y=0 w=1366 h=768
meta_window_update_monitor: window 0x1a00003 (maximize) moves from monitor 1 to 0

The window was correctly positioned on the external monitor 1680x1050 and is wrongly moved to the laptop monitor 1366x768.

But in a small program using gdk_screen_get_monitor_at_point(), I notice that GDK and Mutter use different indexes for my monitors: my laptop monitor 1366x768 is #1 according to Mutter or #0 according to GDK. My external monitor 1680x1050 is #0 according to Mutter or #1 according to GDK. My primary monitor (gdk_screen_get_primary_monitor) is #1 (my external monitor). I wonder if it is related to the bug. I am still investigating.
Comment 9 Lionel Landwerlin 2012-11-21 20:13:06 UTC
I was looking at this problem last week, and basically I ended up with the following findings :

Mutter delays the window positioning in case the application resizes its window quickly after its creation. In the case of this bug, by the time mutter hits the positioning code, it has already received a maximize request for the same window.
And that's where is problem is, apparently a portion of the code supposed to maximize the window doesn't take into account the initial position computed by Mutter (which is, like Alban showed, correct). 

I believe that the bug in somewhere around here :

http://git.gnome.org/browse/mutter/tree/src/core/constraints.c?h=gnome-3-6#n576

When we call meta_window_maximize_internal(), we give newly computed position for the window (which is correct). And this maximize_internal() function saves this position into window->saved_rect.
Then meta_window_maximize_internal() calls recalc_window_features() to actually computed the maximized position. To do so, it needs to know which monitor has to be used to compute the new size of the window. And it does so by calling meta_window_get_outer_rect(). That function returns a position that isn't the one computed by mutter and stored in window->saved_rect.

I believe that's the core of the problem, we try to maximize using the coordinates in sync with the Xserver, not the newly computed coordinates.

I see 2 solutions to fix that problem, either for a sync of the coordinates from the Xserver, or change the function doing to maximization to take into account the futurue position of the window.
Comment 10 Lionel Landwerlin 2012-11-21 20:16:06 UTC
*** Bug 686646 has been marked as a duplicate of this bug. ***
Comment 11 Alban Crequy 2012-11-23 00:26:34 UTC
Created attachment 229686 [details] [review]
[PATCH] Fix maximised window jumping to other monitor in dual monitor setup

Thanks for the explanation Lionel. I fixed it by changing the function doing to maximization to remember the initial position computed by Mutter in a way that will be used in the delayed positioning code. It seems to work and not have side effect but Mutter is complex, I might miss something. Reviews welcome!
Comment 12 Alban Crequy 2012-11-23 13:37:03 UTC
*** Bug 674641 has been marked as a duplicate of this bug. ***
Comment 13 Alban Crequy 2012-11-23 13:40:06 UTC
*** Bug 659658 has been marked as a duplicate of this bug. ***
Comment 14 Alban Crequy 2012-11-23 14:20:23 UTC
*** Bug 679158 has been marked as a duplicate of this bug. ***
Comment 15 Lionel Landwerlin 2012-11-27 12:19:47 UTC
Looks good to me.
Comment 16 Alban Crequy 2012-11-28 18:57:09 UTC
Created attachment 230110 [details] [review]
[PATCH] Fix maximised window jumping to other monitor in dual monitor setup

Similar patch, but with code moved into the constraints code that does the maximize, as suggested by Jasper on IRC.

The patch applies fine on git master and on branch gnome-3-6. But I assume we want the fix only on master?
Comment 17 Germán Poo-Caamaño 2012-11-28 19:14:02 UTC
(In reply to comment #16)
> Created an attachment (id=230110) [details] [review]
> [PATCH] Fix maximised window jumping to other monitor in dual monitor setup
> 
> Similar patch, but with code moved into the constraints code that does the
> maximize, as suggested by Jasper on IRC.
> 
> The patch applies fine on git master and on branch gnome-3-6. But I assume we
> want the fix only on master?

IMVVHO, this bug should be also fixed in 3.4 (if this is not too much hassle).  It is too visible, and 3.4 is available is LTS distros.
Comment 18 Alban Crequy 2012-11-29 14:22:42 UTC
Created attachment 230190 [details] [review]
[PATCH] Initialize window->user_rect in the initial placement
Comment 19 Jasper St. Pierre (not reading bugmail) 2012-11-29 20:10:15 UTC
Review of attachment 230190 [details] [review]:

This is fine for me.
Comment 20 Alban Crequy 2012-11-30 13:40:50 UTC
Comment on attachment 230190 [details] [review]
[PATCH] Initialize window->user_rect in the initial placement

(In reply to comment #19)
> Review of attachment 230190 [details] [review]:
> 
> This is fine for me.

Thanks!
Pushed on master, commit e5b467.
Pushed on gnome-3-6, commit 0dee738.
Pushed on gnome-3-4, commit 844ad6f.
Comment 21 Florian Müllner 2018-02-05 15:11:55 UTC
*** Bug 687069 has been marked as a duplicate of this bug. ***