The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
1

Move workspace to primary screen

asked 2015-04-08 07:44:16 +0000

rosetree gravatar image

With xrandr it’s possible to set a primary screen. As an example I’m currently using xrandr --output HDMI-0 --auto --right-of LVDS --primary to connect a bigger monitor.

At the moment I’m using the following two commands in my .i3/config to move a workspace from the laptop screen to the VGA-connected monitor and back to my laptop.

bindsym $mod+m move workspace to output VGA-0
bindsym $mod+Shift+m move workspace to output LVDS

These two commands have a few problems. Sometimes I’m using a screen connected with VGA, but sometimes I’m using HDMI. Someday I will have it left of my laptop, on another day I will have it on the right.

So I’m wondering:

  1. Is there a way to move a workspace to the primary screen?
  2. If not: How can I use a single shortcut to move a workspace away from my laptops monitor?
edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
1

answered 2015-04-08 13:46:52 +0000

Adaephon gravatar image

updated 2015-04-08 19:56:59 +0000

The output of xrandr -q shows which, if any, screen is the primary screen. So a small script can be used to retrieve the name of the primary screen and send a workspace to it using i3-msg:

#!/bin/sh
PRIMARY_SCREEN=$( xrandr -q | awk '/ connected primary/ {print $1}' )
if [ -n "$PRIMARY_SCREEN" ] ; then
    i3-msg "move workspace to output $PRIMARY_SCREEN"
else
    # there is no primary screen
    i3-nagbar -m 'No primary screen defined' -t warning
fi

This script can then be bound to a shortcut of your liking:

bindsym $mod+m exec --no-startup-id /path/to/send2primary.sh

You can also use i3's IPC interface to retrieve a list of outputs and move workspaces. For example using ziberna's i3 Python library:

import i3
import sys

activeOutputs = filter(
    lambda x: x[u'active'],
    i3.get_outputs())
try:
    primaryOutput = filter(
        lambda x: x[u'primary'],
        activeOutputs)[0]
except IndexError:
    primaryOutput = None
currentWorkspace = filter(
    lambda x: x[u'focused'],
    i3.get_workspaces())[0]
currentOutput = filter(
    lambda x: x[u'current_workspace'] == currentWorkspace[u'name'], 
    activeOutputs)[0]
otherOutputs = filter(
    lambda x: x[u'name'] != currentOutput[u'name'], 
    activeOutputs)

# if there is a primary screen move to it, 
# else move to the first other output (if there is one)
if primaryOutput:
    i3.move('workspace to output', primaryOutput[u'name']
elif len(otherOutputs) > 0:
    i3.move('workspace to output', otherOutputs[0][u'name']
edit flag offensive delete link more

Comments

Thank you for your answer. I tested the shell script and it works as expected. Just one small bug: A closing bracket is missing at the end of the first line (`PRIMARY_SCREEN=$(…)`). Thanks for your fast help.

rosetree gravatar imagerosetree ( 2015-04-08 14:12:57 +0000 )edit

Thanks for telling me. It is fixed now.

Adaephon gravatar imageAdaephon ( 2015-04-08 19:59:30 +0000 )edit
1

answered 2015-04-08 13:16:30 +0000

i3convert gravatar image

updated 2015-04-08 13:31:35 +0000

  1. This is doable. You have to parse the output of i3-msg -t get_outputs to figure out which output is primary (I recommend using the json library in Python). Then you have to issue move workspace to output ???, where ??? is your workspace. If you don't know how to program (it's never too late to learn!), perhaps someone else fills out the details.
  2. Have you tried move workspace to output right and move workspace to output left? Maybe they will do the job for you? In my config file I have:
bindsym Shift+$mod+bracketright move workspace to output right
bindsym Shift+$mod+bracketleft move workspace to output left
edit flag offensive delete link more

Comments

Thank you for your answer. It’s a useful suggestion and I will keep your second point in mind, maybe that will be more handy in my case. However @Adaephon answered more directly to my question so I will accept his answer. Thanks again!

rosetree gravatar imagerosetree ( 2015-04-08 14:09:00 +0000 )edit

Question Tools

Stats

Asked: 2015-04-08 07:44:16 +0000

Seen: 307 times

Last updated: Apr 08