LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Automating Xorg RandR turning laptop screen off if external monitor is connected (https://www.linuxquestions.org/questions/slackware-14/automating-xorg-randr-turning-laptop-screen-off-if-external-monitor-is-connected-779386/)

Nylex 01-02-2010 05:39 AM

Automating Xorg RandR turning laptop screen off if external monitor is connected
 
Hi all,

I have a netbook (Acer Aspire One) I'm running Slackware 13. and usually, I prefer to connect an external monitor. When I switch my machine on with the monitor connected, the display is duplicated on both screens and since I just want the netbook's screen to be off and only see the display on the external monitor, I can do

xrandr --output LVDS --off

Great! However, it's a hassle to do this every time I log in and I'd like to automate the process if possible. I did some googling and I found that if you want to automate xrandr commands, you can put a script in /etc/X11/Xsession.d/ (see this). I wrote the following script to automate my xrandr commands and since the Xsession.d directory didn't exist, I tried creating it. The script was called 45custom-xrandr_settings, as the one on the RandR wiki is called the same.

Code:

#!/bin/bash

# Check whether the external monitor is connected
xrandr | grep VGA | grep " connected "

# 0 is returned on success
if [ $? -eq 0 ]; then
  xrandr --output LVDS --off
fi

However, when I start my machine with the monitor attached, the script does not seem to be executed (and yes, execute permissions were set!). The script itself works fine, which I know since I executed it manually. I've also tried putting the commands in ~/.xinitrc and /etc/X11/xinit/xinitrc.kde, but they're all ignored.

So, what is the correct way to automate xrandr commands under Slack?

Hangdog42 01-02-2010 06:00 AM

I'm not sure that this is quite the answer you're looking for, but I've run into the same problem with my main laptop and the only automatic solution I found was to have the external monitor listed as the first monitor in xorg.conf. The console displays in both monitors, but X displays in just the external when it is attached. When unattached, the laptop monitor is used.

aocab 01-02-2010 10:01 AM

I myself have to run xrandr to adjust my monitors
resolution / color depth...(or the machine starts in a
higher resolution and lower color depth than I want)

I start in init 4 and am using kde.

I ended up putting the commands in the /etc/kde/kdm/Xsetup file.
And my screens resolution is set to what I want while kdm is starting.

If you are using kdm/kde, maybe you could try and run
your script from this file?

HTH
Cheers

DonnieP 01-02-2010 10:07 AM

Exactly where you put it depends on how you get into X in the first place. In my case I boot to console and use startx. My xinitrc has this in it at the bottom:

xrandr --output LVDS --off --output VGA --mode 1920x1080

# Start the window manager:
startlxde

Nylex 01-02-2010 11:15 AM

Quote:

Originally Posted by Hangdog42 (Post 3811528)
I'm not sure that this is quite the answer you're looking for, but I've run into the same problem with my main laptop and the only automatic solution I found was to have the external monitor listed as the first monitor in xorg.conf. The console displays in both monitors, but X displays in just the external when it is attached. When unattached, the laptop monitor is used.

Thanks for that. The solution below works fine for me. Perhaps you could find something equivalent, for your desktop environment?

Quote:

Originally Posted by aocab (Post 3811658)
I myself have to run xrandr to adjust my monitors
resolution / color depth...(or the machine starts in a
higher resolution and lower color depth than I want)

I start in init 4 and am using kde.

I ended up putting the commands in the /etc/kde/kdm/Xsetup file.
And my screens resolution is set to what I want while kdm is starting.

If you are using kdm/kde, maybe you could try and run
your script from this file?

HTH
Cheers

Works like a charm. Thank you!

Quote:

Originally Posted by DonnieP (Post 3811661)
Exactly where you put it depends on how you get into X in the first place. In my case I boot to console and use startx. My xinitrc has this in it at the bottom:

xrandr --output LVDS --off --output VGA --mode 1920x1080

# Start the window manager:
startlxde

Ahh, I didn't realise that. I start in runlevel 4, using KDE and KDM. Again, the solution posted by aocab works.

Thanks everyone!

mwildam 08-02-2010 11:20 AM

First I want to thank Nylex for posting the script - I am on Ubuntu and experienced the same issue - and more difficult - after login I already saw everything fine and something switched away again after a ~ 5 seconds delay.

So for me this topic was a great help but not sufficient.

Anybody still experiencing the issue after trying what has been posted above, have a look at http://it-tactics.blogspot.com/2010/...g-station.html


All times are GMT -5. The time now is 05:42 PM.