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 731760 - window: Keep track of preferred output
window: Keep track of preferred output
Status: RESOLVED FIXED
Product: mutter
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: mutter-maint
mutter-maint
Depends on:
Blocks:
 
 
Reported: 2014-06-17 07:43 UTC by Florian Müllner
Modified: 2014-06-24 22:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
window: Keep track of preferred output (4.27 KB, patch)
2014-06-17 07:43 UTC, Florian Müllner
committed Details | Review
window: Add user_op parameter to update_monitor() (5.08 KB, patch)
2014-06-24 09:40 UTC, Florian Müllner
committed Details | Review

Description Florian Müllner 2014-06-17 07:43:38 UTC
See patch - inspired by https://github.com/aiguofer/return-to-monitor
Comment 1 Florian Müllner 2014-06-17 07:43:41 UTC
Created attachment 278572 [details] [review]
window: Keep track of preferred output

Remember the last monitor a window was moved to by user action and
try to move it back on monitor changes; this should match user
expectations much better when a monitor is unplugged temporarily.
Comment 2 Kamil Páral 2014-06-17 07:55:07 UTC
Just a note, I've just found out that the extension doesn't work correctly with dynamic workspaces:
https://github.com/aiguofer/return-to-monitor/issues/2

I can't read from the patch whether that was taken into account or not, so I just mention it, in case. It would be nice to also keep windows on correct workspaces, not just squash them to the first one, although on the correct monitor. (But of course, I don't want to get greedy, any improvement is welcome:)).
Comment 3 Florian Müllner 2014-06-17 08:10:06 UTC
(In reply to comment #2)
> It would be nice to also keep windows on correct workspaces, not just squash
> them to the first one, although on the correct monitor.

By default we pretend that workspaces don't exist on non-primary monitors, so what the correct workspace should be when moving to the primary monitor is not always obvious (in particular when the app has originally been started on a secondary monitor). So while the patch does not share any code with the extension, it is likely affected by this (more general) issue as well ...
Comment 4 Kamil Páral 2014-06-17 09:11:19 UTC
My naive idea was simply copying the workspaces from the disconnected monitor to the new primary monitor. After reconnecting the original monitor, moving the workspaces back (exactly as they are), with the exception of apps previously being on the secondary monitor. Not sure if it's easily achievable. It seems easy on paper :-)


                            Primary
                            ~~~~~~~
                   .-----------------------.
      Secondary    |        firefox        |
      ~~~~~~~~~    |                       |
  .---------------.|-----------------------|
  |               ||        nautilus       |
  |               ||                       |
  |     xchat     ||-----------------------|
  |               ||         gedit         |
  |               ||                       |
  '---------------''-----------------------'

                   |
                   | disconnect monitor / undock
                   |
       Primary     v
       ~~~~~~~
  .---------------.
  |firefox, xchat |
  |---------------|
  |    nautilus   |
  |---------------|
  |     gedit     |
  '---------------'

                   |
                   | make some changes in apps  
                   |
       Primary     v
       ~~~~~~~
  .---------------.
  |firefox, xchat |
  |---------------|
  |     gedit     |
  |---------------|
  |   rhythmbox   |
  '---------------'

                   |
                   | reconnect monitor / dock   
                   |
                   v        Primary
                            ~~~~~~~
                   .-----------------------.
      Secondary    |        firefox        |
      ~~~~~~~~~    |                       |
  .---------------.|-----------------------|
  |               ||         gedit         |
  |               ||                       |
  |     xchat     ||-----------------------|
  |               ||       rhythmbox       |
  |               ||                       |
  '---------------''-----------------------'
Comment 5 Diego 2014-06-18 03:37:01 UTC
This is great! It was fun making the extension just to get a little better understanding of the extension system, but integrating this into the shelf itself would be the best solution :)

Just wanted to comment on a few use cases that should be considered (if possible):

- 'show only on primary display' set to OFF and 'static' workspaces
  - this is the easiest, and the set up I had in mind originally with the extension
- 'show only on primary display' set to ON and 'static' workspaces
  - I think this may need to account for which physical monitor is which MetaMonitor
- 'show only on primary display' set to OFF and 'dynamic' workspaces
- 'show only on primary display' set to ON and 'dynamic' workspaces
Comment 6 drago01 2014-06-21 11:55:18 UTC
Review of attachment 278572 [details] [review]:

LG, fixes one of the most annoying multi-monitor bugs.
Comment 7 Florian Müllner 2014-06-24 09:39:53 UTC
(In reply to comment #4)
> My naive idea was simply copying the workspaces from the disconnected monitor
> to the new primary monitor. After reconnecting the original monitor, moving the
> workspaces back (exactly as they are), with the exception of apps previously
> being on the secondary monitor. Not sure if it's easily achievable. It seems
> easy on paper :-)

It's not, given that workspaces are per-screen and not per-monitor (or in other words: there is only a single set of workspaces that spans all monitors). There are basically two issues at hand (both only tangentially related to the attached patch) when workspaces-only-on-primary is set:
 (1) when moving a window from a non-primary monitor to the primary,
     we also move it to the active workspace; that's because when
     actually moving the window (dragging or <super><shift>left/right),
     having it suddenly display would be weird (see comment[0]).
     I don't think this applies when moving the window due to changes
     in the screen configuration (e.g. its monitor got unplugged) though,
     I'll attach a patch to preserve the workspace in that case
 (2) when dynamic-workspaces is set, windows on secondary monitors may
     be moved to a different workspace when their workspace is removed;
     that's because windows that are shown on all workspaces are ignored
     when determining "empty" workspaces - I don't see a way around this,
     apart maybe from differentiating between visible-on-all-workspaces-because-sticky
    and visible-on-all-workspaces-because-on-non-primary cases. However
    I think keeping apparently empty workspaces alive for windows on
    secondary monitors would cause more confusion than the current behavior,
    and not sure storing a preferred workspace index and restoring it
    is worth the code (what should happen when a window is moved from the
    sixth workspace to the secondary monitor, but at the time it is returned
    there are only two workspaces?). It's also a bit of a fringe case IMHO - if
    I care deeply about the workspace a window on non-primary monitors is on,
    why would I "disable" workspaces on non-primary monitors?

[0] https://git.gnome.org/browse/mutter/tree/src/core/window.c#n3606
Comment 8 Florian Müllner 2014-06-24 09:40:34 UTC
Created attachment 279092 [details] [review]
window: Add user_op parameter to update_monitor()

When workspaces-only-on-primary is set and a window is moved back to the
primary, we also move it to the active workspace to avoid the confusion
of a visible window suddenly disappearing when crossing the monitor border.
However when the window is not actually moved by the user, preserving the
workspace makes more sense - we already do this in some cases (e.g. when
moving between primary monitors), but miss others (unplugging the previous
monitor); just add an explicit user_op parameter as used elsewhere to cover
all exceptions.
Comment 9 Kamil Páral 2014-06-24 10:54:14 UTC
I'd have to try it, but I think the patch above implements what bothered me most, thanks for that! Simply put, I'd love this to work: 4 workspaces on notebook monitor -> dock it -> 4 workspaces moved to external (now primary) monitor -> undock it -> 4 workspaces moved back to notebook (now primary and only) monitor. I that works, I'll be ecstatic :-) Currently both docking and undocking squashes all windows from all workspaces to a single workspace and I have to manually separate them back into workspaces every time. I have a lot of windows and I dock and undock several times a day.
Comment 10 Florian Müllner 2014-06-24 13:02:54 UTC
(In reply to comment #9)
> I'd have to try it, but I think the patch above implements what bothered me
> most, thanks for that!

Probably not - the case you describe should already work without the patch (i.e. moving from primary to primary); it does appear to be the case here in a brief test ...
Comment 11 Florian Müllner 2014-06-24 22:04:03 UTC
Attachment 278572 [details] pushed as 00c7a27 - window: Keep track of preferred output
Attachment 279092 [details] pushed as 967b6c3 - window: Add user_op parameter to update_monitor()