17

I would like to achieve a behavior like this: When I use my laptop screen my first workspace is used. When I plug in a second screen (via HDMI) a second workspace is used and all the new opened windows on this second screen will land in the second space, except I switch the workspace on the second screen to another workspace.

When I unplug my second screen all windows will stay in the workspaces they were created in and I can switch the workspaces on my laptop to see them.

Is this behavior already possible?

4
  • I already managed to enable workspaces with Appearance -> Behvior and disabled vertical workspaces with the CompizConfig Settings Manager. There are also Expo and Viewport Switcher Plugins which seem to be able to do what I want but I afraid of changing settings without knowledge there.
    – velop
    Oct 12, 2016 at 8:30
  • Your question is a bit confusing. If you're asking to make displays as two separate workspaces, then the answer is no, not possible. If you are asking to automatically change number of workspaces upon connecting second screen, then that's possible. Please clarify / simplify what you're asking Oct 12, 2016 at 8:36
  • 3
    I found the option Compiz -> Desktop Wall -> Viewport Switching -> Multimonitor bahvior -> Switch separately. But appearently this does not work.
    – velop
    Oct 12, 2016 at 8:58
  • @velop, can you edit these comments into the question?
    – SDsolar
    May 6, 2018 at 21:30

1 Answer 1

3

Is this behavior already possible?

Everything is possible in linux. You will need some basic knowledge about the Xserver, some time and a system to test on, since you are messing with your X and you certainly need the browser running if you need help :-)

In my opinion there are three possible solutions:

  • Multimonitor-setups use Xinerama. The simplest solution i can think of is to add a third virtual screen to your configuration and simply move the windows there using xdotool. There are some downsides to this solution but it would not require the effort of having to move windows between different Xservers which in general is not possible.

  • Since it is not possible to move windows between different Xservers, we need a kind of proxy like xmove or Xpra to do this for us. I think the windows then live in a separate Xfvb session to hide the windows. You can attach and detach to the session.

  • Regardless of what method you are using, you need an event when the monitor gets unplugged. The event should get triggered when the screen is disconnected and also when reconnected. You can daemonize the script to watch for the event.

I would prefer the solution using Xpra for various reasons. I can only give you some hints of how to do it. The solutions are not complete but should get you started.

Xinerama Solution

Setup

The Xinerama setup has to get extended to have a static configuration: See https://help.ubuntu.com/community/XineramaHowTo

see also fake third screen and Xdummy

get affected windows

We can use xdotool to search for windows. Afterwards we can check their position and move them. I am assuming two monitors with 1920x1080 configuration. The following will move all windows from the right to the left xinerama screen.

while read xwindowid; do
    eval $(xdotool getwindowgeometry --shell "$xwindowid")
    if (( X > 1920 && X <= (1920 * 2))); then
        xdotool windowmove --relative $WINDOW -1920 y
    fi
done <<< "$(xdotool search --screen 0 '.*')"

You can now move all the windows from your laptop screen (screen0) to a third (virtual) screen if a monitor gets attached. At the same time you can move any window that is stored on the third screen to the first screen.

XPRA solution

In order to use Xpra for moving the windows, all windows have to get managed by Xpra prior. You have to start the whole desktop using Xpra on system startup. Two times one is your main desktop where you work and the other is mainly a virtual desktop.

xpra start-desktop :99
xpra start-desktop :1 --exit-with-children −−attach

Now you can have Windows for the disconnected screen running in a separate xpra session and attach/detach from it when the monitor switches.

xpra attach :99
xpra detatch :99

There is also a dicontinued gnome shell extension that could be useful if you want to manually move a window from the hidden :99 to the normal :0 between started xpra displays.

The event

  • You can watch for the disconnect/reconnect of a specific display

  • maybe watch for changed dimensions of your xinerama using xwininfo to have it independent of the un-plugged monitor if you want i.e. to extend your setup to 3 monitors and unplug an arbitrary device. Note that this will only work for the xpra solution.

    xwininfo -display :0 -root | grep -e "-geometry"

    -geometry 5760x2160+0+0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .