I created a simple Bash script that will always disable the default/internal monitor on your laptop when using AR glasses (or any other external monitor). 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 interal laptop display to become enabled.

To keep the laptop display always off, weather the laptop lid is either closed or open, this simple bash script will always disable the laptop screen every X seconds (You can change it by changing the wait variable)

Simply copy this script and create a new bash script such as disable-display.sh, make the script file executable and add it to your startup applications and it will run in the background. You will need to run xrandr command with all of your displays enabled to get the names of the displays and change the variable names in the script accordingly.

NOTE: This script may not work with a full Wayland setup and may only work on X11.

Enjoy

#!/bin/bash

#RUN xrandr TO GET THE NAMES OF THE DISPLAYS AND SET THE VARIABLES TO THESE NAMES

readonly default_display="eDP"
readonly external_display="USB-C-0"

readonly wait=5

while true; do
    #Check if there is an external display connected
    if xrandr | grep -q "$external_display connected"; then
        #Disable the internal display
        xrandr --output $default_display --off
    fi

    sleep $wait
done
    • oshu@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      1 day ago

      It just looks weird to me to stick a semicolon into the middle of a line when a compound command isn’t actually needed.

      • smeg@feddit.uk
        link
        fedilink
        English
        arrow-up
        1
        ·
        17 hours ago

        So you’d rather it all be on one line? I’d only do that if it’s a very simple command, otherwise you’re just making the code harder to read.

        • oshu@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          17 hours ago

          No the opposite. I think more shorter lines makes it easier to read than fewer longer lines.

          • smeg@feddit.uk
            link
            fedilink
            English
            arrow-up
            1
            ·
            16 hours ago
            while true; do
            

            isn’t exactly harder to read than

            while true
            do
            

            though, is it? And going back to my original point, I don’t like while true being on its own as to me it looks like it’s meant to be a separate statement rather than part of the do/done block.

            • oshu@lemmy.world
              link
              fedilink
              arrow-up
              1
              ·
              14 hours ago

              Its a personal style choice.

              With a blank line before the ‘while’ and another after the ‘done’ its a nice little easy to identify block. I don’t know how the ‘while’ would look like its not a part of that block.

              A midline semicolon just looks ugly to me so I don’t do it unless it is the only way to make a statement work.