It's extremely clear what you're asking and a really neat idea but unfortunately this is impossible without digging deep into the bowels of the Window Manager and changing the code there.
Workspaces are duplications of your physical monitor set-up and what you're trying to do would create a bunch of problems if your monitors do not have the exact same resolution: windows would have to be moved to fit on the screen when changing around, or panning would need to be enabled automatically, etc, ...
Sorry to be the harbinger of bad news...
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
Best Answer
First you can quickly know how many workspaces you have with the following commands, open a terminal and type:
It should return 2 for both if you have 4 workspaces.
Now with an external monitor, you don't really have 8 workspaces even if this kind of picture can be confusing because both screen are creating an extended desktop (if you are not mirroring), a workspace is delimited here by the orange line:
To answer your question, there's no way to specify the number of workspaces per display (the unity plugin only store global values) but you can force a given window to stay always on visible workspace. I often do that for my mail client that I left on my laptop monitor. It's like having a single workspace. Just click the title bar of your application and select "Always on visible workspace":