phillipberndt / autorandr

Auto-detect the connected display hardware and load the appropriate X11 setup using xrandr
2.48k stars 122 forks source link

Supporting virtual monitors #172

Open chipsenkbeil opened 4 years ago

chipsenkbeil commented 4 years ago

I have a bit of a niche setup and was curious if autorandr is able to support it or what the best practice would be to support it.

My old setup worked great with autorandr: a multi-monitor dock setup where a laptop of 1920x1080 (eDP-1) would hook into a thunderbolt 3 dock containing two 2560x1600 Dell monitors. I'd turn off the laptop display and use the two external displays.

Now, I've moved away from a thunderbolt 3 dock with two external monitors that were 30" to a single super ultrawide 49" Dell monitor. My first step is to turn off my laptop display and enable the 5120x1440 DP-1 monitor, which works well and can be saved and reproduced with autorandr.

My custom component that does not currently work is that I split my single, ultrawide monitor into three virtual monitors via

xrandr --setmonitor DP-1-1 1280/297x1440/340+0+0 DP-1
xrandr --setmonitor DP-1-2 2560/595x1440/340+1280+0 none
xrandr --setmonitor DP-1-3 1280/298x1440/340+3840+0 none

This functionality is not saved by autorandr, so my current process is

  1. Use autorandr -c dock-work to switch to my 5120x1440p monitor and turn off the laptop display
  2. Manually run the xrandr --setmonitor for all three of my virtual monitors
  3. Manually run the xrandr --delmonitor DP-1-3, etc. before switching back to my default profile
  4. Use autorandr -c default to switch to my laptop display and disconnect the 5120x1440p monitor

Is there a better way for me to do this?

phillipberndt commented 4 years ago

Monitors aren't supported at all yet, autorandr is still in the xrandr 1.4 era. I think we should definitely support this. I don't have a 1.5 setup yet though, so I can't add support myself.

RasmusWL commented 4 years ago

To achieve 2) you can use a postswitch script, by placing the commands in ~/.config/autorandr/dock-work/postswitch.

For 3) it's a bit more tricky, as there isn't a good way to execute something when changing away from a profile. I would suggest adding a "global" preswitch script in ~/.config/autorandr/preswitch and running your xrandr --delmonitor if $AUTORANDR_CURRENT_PROFILE is dock-work.

Might not be perfect, but should remove the tedious manual steps :wink:

chipsenkbeil commented 4 years ago

@phillipberndt, I can take a look later as I've switched over to this use case both at home (CRG90 49" monitor) and at work (Dell U4919DW 49" monitor).

For now, I'll give @RasmusWL recommendation a go, which sounds promising. If it works out, I'll share the configurations here. :)

chipsenkbeil commented 4 years ago

Got it working per @RasmusWL suggestion, although I feel like one part is a little off. I needed to use the name of the profile I was switching to (e.g. default) when using $AUTORANDR_CURRENT_PROFILE instead of the profiles I was switching away from. Is this expected? I was trying to find documentation for the environment variables, but didn't see anything.

Using autorandr 1.8.1 in combination with xrandr 1.5.0, I've got the following structure:

dotfiles/autorandr
└── .config
    └── autorandr
        ├── default
        │   ├── config
        │   └── setup
        ├── dock-home
        │   ├── config
        │   ├── postswitch
        │   └── setup
        ├── dock-work
        │   ├── config
        │   ├── postswitch
        │   └── setup
        └── preswitch

$HOME/.config/autorandr/dock-home/postswitch

#!/usr/bin/env bash

# Samsung CRG90 is 5120x1440p & 1190mm x 340mm
xrandr --setmonitor DP-1-1 1280/297x1440/340+0+0 DP-1
xrandr --setmonitor DP-1-2 2560/595x1440/340+1280+0 none
xrandr --setmonitor DP-1-3 1280/298x1440/340+3840+0 none

$HOME/.config/autorandr/dock-work/postswitch

#!/usr/bin/env bash

# Dell U4919DW is 5120x1440p & 1200mm x 340mm
xrandr --setmonitor DP-1-1 1280/300x1440/340+0+0 DP-1
xrandr --setmonitor DP-1-2 2560/600x1440/340+1280+0 none
xrandr --setmonitor DP-1-3 1280/300x1440/340+3840+0 none

$HOME/.config/autorandr/preswitch

#!/usr/bin/env bash

delmon() {
    xrandr --delmonitor "$1" >& /dev/null
}

# If switching away from dock setup
if [ "$AUTORANDR_CURRENT_PROFILE" = "default" ]; then
    delmon "DP-1-3"
    delmon "DP-1-2"
    delmon "DP-1-1"
fi
noughtnaut commented 3 years ago

(Shh, I'm just putting a little note-to-self here)

Is this expected?

Yeano? It's not documented, but that is a known oddity about 'AUTORANDR_CURRENT_PROFILE', which I mean to amend by way of issue "230. Stay tooned...