I created a simple Nushell script that will always disable the default/internal monitor(s) on your laptop or external display when using AR glasses. I find this useful for when using AR glasses such as the XReal One which allows you to change the mode from regular mode to ultra-wide mode and when doing this, it will act as your unplugging the XReal ones and plugging in XReal one again in a new mode, causing the other display to become enabled.
To keep the laptop display always off, weather the laptop lid is either closed or open, this simple Nushell script will always disable the screen every X seconds (You can change it by changing the
waitconstant)Simply copy this script and create a new Nushell script such as
disable-displays.nu, add it to your startup applications with the command ofnu /path/to/disable-displays.nuand it will run in the background. You will need to runxrandrcommand with all of your displays enabled to get the names of the displays and change the constants values in the script accordingly.NOTE: This script may not work with a full Wayland setup and may only work on X11.
Enjoy
# RUN xrandr TO GET THE NAMES OF THE DISPLAYS AND SET THE VARIABLES TO THESE NAMES const ar_glasses_display = 'USB-C-0' const displays = [ 'eDP', 'HDMI-0' ] const wait = 5 def is-ar-glasses-connected [] { return (xrandr | str contains $"($ar_glasses_display) connected") } def disable-display [display: string] { xrandr --output $display --off } def enable-display [display: string] { xrandr --output $display --auto } loop { if (is-ar-glasses-connected) { for current_display in $displays { disable-display $current_display } } else { for current_display in $displays { enable-display $current_display } } sleep ($wait * 1sec) }
OC by @trymeout@lemmy.world
Definitely won’t work on my Wayland desktop running Niri. xrandr doesn’t return anything useful under Wayland, unless I’m mistaken.
But cool to see some use out of nushell! 😃
Niri does not allow
xrandrto disable the monitors, I’d assume other compositors are also like that, sounds like a very out of scope thing to do through xwayland. If that assumption is correct, this won’t work on most modern systems.Also, the way it’s done looks kind of hacky with constant enabling and disabling of displays. I’m sure
xrandrdoes something to prevent useless commands like that from actually working, but I’d do something to not issue them in the first place.My first thought is checking
/sys/class/drmfor whatever state you want, as in with something like this you can see which ports have a display on the other side currently:# This is sh, by the way for a in /sys/class/drm/*/status; do echo "$a: $(cat "$a")"; doneAnd you can listen to udev changes with something like this:
udevadm monitor --kernel --subsystem-match=drmIf an event is emitted, we check if the state of the port we are interested in changed and then do whatever we need.
Though, I’m also not sure if manually disabling the monitor is the correct way, maybe there is a better way of handling it in X11? I’d imagine it wanting to have at least one display enabled is configurable.

