The i3 FAQ has migrated to https://www.reddit.com/r/i3wm/. All content here is read-only.

# Move all workspaces to one monitror and back

This post is a wiki. Anyone with karma >100 is welcome to improve it.

Sometimes I have to unplug my external monitor. I'd like to be able to move all the workspaces that were on the external onto the laptop automatically. Ideally, I'd like them to move back when I plug the monitor in again.

More generally, I'd like a way to have all workspaces listed and available on each monitor, so that when I switch workspaces the target pops up on which ever monitor is currently active.

Are these things possible?

edit retag close merge delete

With a udev hotplug script + i3-msg, I'm pretty sure it is.

( 2012-08-07 05:32:43 +0000 )edit

Sort by » oldest newest most voted

This post is a wiki. Anyone with karma >100 is welcome to improve it.

It sounds to me like you want to assign a number of workspaces to your external monitor. See http://i3wm.org/docs/userguide.html#w.... When the output is unavailable, workspaces will be moved to the first available monitor (your laptop monitor) and when it becomes available again, workspaces will be moved there again.

more

The trouble is when you unplug a monitor while a laptop is running, the workspaces are still on the monitor that is not available anymore. How can we those now invisible workspaces automatically to the still active (primary) monitor?

( 2013-08-15 08:18:46 +0000 )edit

I don't have enough karma to edit this answer, but the link is broken.

( 2013-11-11 11:11:26 +0000 )edit

This post is a wiki. Anyone with karma >100 is welcome to improve it.

Sounds like the original poster wants xmonad behavior where whichever monitor is focused, by pressing mod-# that workspace would jump to the focused monitor (if not there already). The current behavior is to put the focus on the monitor to which the workspace is assigned and jump to it there.

I didn't have any luck unplugging my monitor, disabling the external display then re-enabling it. Once a monitor is unplugged it seems all existing workspaces just get moved to whichever one is left (the laptop display).

The documentation, though mentions, a command (that could likely be bound to a key) which will move the workspace to another monitor, that works like this:

$i3-msg move workspace to output [xrandr output name] or$ i3-msg move workspace to output [left|right|up|down]

so if you have two monitors... bind a key to left and bind a key to right and you can just toggle a display between them:

bindsym $mod+v exec i3-msg move workspace to output left bindsym$mod+b exec i3-msg move workspace to output right

I created a script that I run before I unplug my monitor that allows me to 'save' the workspace states... I can then run it again with 'restore' when I plug the monitor back in and it will restore the workspaces to where they were before: i3plug.py

more

I hope this helps you. The following will turn off your monitors when unplugging and turn them on again when you plug it in. Turning the monitor off will force i3 to put all workspaces on the remaining monitor. Turning it on again will simply create a new blank workspace, I'm working on a restore-script but wanted to share the progress so far.

Following Ikraav's comment, we will be using udev for this.

First check if unplugging your monitor actually results in an event. Look for (drm) in the output of the following command:

  #: udevadm monitor --property


Then create a new udev rule, on Ubuntu e.g. in /etc/udev/rules.d/80-monitor-hotplug.rules

  ACTION=="change", SUBSYSTEM=="drm", RUN+="/root/monitor-hotplug.sh"


Then create your script in /root/monitor-hotplug.sh. You will have to replace the adapters with the ones relevant to you, and of course your username.

  #!/bin/sh
export DISPLAY=:0
export XAUTHORITY=/home/vk/.Xauthority
if [ "\$STATUS" = "connected" ]; then
xrandr --output DVI-D-1 --above LVDS-1 --auto --screen 0
else
xrandr --output DVI-D-1 --off --screen 0
fi


And that is it. Still todo:

• Not sure yet how to handle XAUTHORITY for multiple users
• Restore workspaces when plugging back in. The workspace setup could e.g. be cached in a file in the homedir and then restored.
more