简体   繁体   中英

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?

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 }) .

It's likely apps are being displayed where the mouse currently resides. You could use xdotool to ensure mouse is on desired display to begin with.

#!/bin/sh

##  executed by display manager during login

if [ "$?" -eq "0" ] ; then
    xrandr --output eDP-1 --mode 1920x1080 --pos 3000x0 --output HDMI-1-0 --primary --mode 2560x1080 --pos 0x0
    echo 0 | tee /sys/class/backlight/intel_backlight/brightness

    ##  sudo apt install xdotool
    ##  x, y  coordinates:  half of 2560x1080, so middle of main screen
    xdotool mousemove 1280 540
else
    ##  external display not plugged in
    xrandr --output eDP-1 --mode 1920x1080 --primary --pos 0x0
fi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM