Search code examples
luaawesome-wm

Changing default focused screen on awesome wm


I have a bit of a hacky setup on my laptop where I use optimus-manager to configure my screen layout at X startup based on whether an external monitor is connected or not. If it is, I only want to use the external monitor and not the laptop monitor, but because of a limitation of NVIDIA drivers, I need to leave my laptop monitor on, and just lower the backlight brightness. See my /etc/optimus-manager/xsetup-hybrid.sh for how this works (eDP-1 is my laptop screen, and HDMI-1-0 is my external monitor):

#!/bin/sh

# Everything you write here will be executed by the display manager when setting up the login screen in "hybrid" mode.

xrandr --output eDP-1 --mode 1920x1080 --pos 3000x0 --output HDMI-1-0 --primary --mode 2560x1080 --pos 0x0
if [ "$?" -ne "0" ]; then
    echo "Not connected to display, don't dim internal monitor"
    exit 0
fi

echo 0 | tee /sys/class/backlight/intel_backlight/brightness

Notice that eDP-1 (laptop monitor) is positioned at 3000x0. I've done this to keep the screens far enough apart so that my mouse can't accidentally stray from my external monitor's screen into my laptop monitor's screen.

This works pretty well, but for some reason every time I log into awesome (or anytime I change the screen layout with xrandr for that matter), awesome focuses the laptop monitor screen by default, even though xrandr is specifying the external monitor screen as --primary.

How can I change this behaviour so that my external monitor screen is focused by default if that monitor is connected, falling back to my laptop screen if it isn't?


Solution

  • You could warp the mouse cursor to the primary screen in your config:

    mouse.screen = screen.primary
    

    The above can also be tested in an already running awesome session via awesome-client: awesome-client 'mouse.screen = screen.primary'.

    If you want to decide the pointer coordinates more precisely (the above uses the upper left corner of the screen), there is mouse.coords({ x = 42, y = 21 }).