This forum has been archived. All content is frozen. Please use KDE Discuss instead.

External Monitor Configuration Scripts

Tags: xrandr, external monitor, script, lvds, vga, configuration, on the fly xrandr, external monitor, script, lvds, vga, configuration, on the fly xrandr, external monitor, script, lvds, vga, configuration, on the fly
(comma "," separated)
User avatar
Thailandian
Registered Member
Posts
30
Karma
1
OS
Here are 5 scripts that I use for controlling my monitor outputs. I have an Acer "emachine" D725 laptop, which has an onboard Intel graphics card. My external monitor is an LG L1750SQ.

The first script, I put in my .kde4/env directory so it fires off before KDE loads. The if statement detects whether there is an external monitor plugged in. The rest sets up the appropriate video output.
Code: Select all
#!/bin/bash
myvar="$(xrandr -q)"
if [[ $myvar == *"VGA connected"* ]]
then
  xrandr --output VGA --auto;
  xrandr --output LVDS --auto;
  xrandr --output LVDS --off;
else
  xrandr --output LVDS --auto;
fi
Line 4 of this seems redundant, turning the LVDS on, then turning it off immediately, but without it, my mouse pointer kept disappearing. Not sure if that is peculiar to my system, or a bug somewhere. You could try removing it - see what happens.

The other four scripts are for changing monitor configs on the fly. If you try them, don't panic if your monitors turn off and on, with other funky behaviour in between. My guess is this is just xrandr sorting through the tangle of different resolutions.

This one is for Laptop monitor only:
Code: Select all
#!/bin/bash
  xrandr --output LVDS --auto;
  xrandr --output VGA --off;

And this for VGA only:
Code: Select all
#!/bin/bash
myvar="$(xrandr -q)"
if [[ $myvar == *"VGA connected"* ]]
then
  xrandr --output VGA --auto;
  xrandr --output LVDS --off;
fi
which is the same as the autoconfiguration script without the else statement. If you don't have an external monitor plugged in, it will do nothing, so you don't turn off your laptop monitor accidentally.

This is for Left Xinerama:
Code: Select all
#!/bin/bash
myvar="$(xrandr -q)"
if [[ $myvar == *"VGA connected"* ]]
then
  xrandr --output LVDS --auto --left-of VGA;
fi

and Right Xinerama:
Code: Select all
#!/bin/bash
myvar="$(xrandr -q)"
if [[ $myvar == *"VGA connected"* ]]
then
  xrandr --output LVDS --auto --right-of VGA;
fi

I put all these in a folderview folder and keep that on one of my virtual desktops. The only one I have set to a hotkey is the one for Laptop monitor only, just in case there is a blackout, so I can turn my laptop monitor back on without rebooting.

I have recently added to the autoconfiguration script to select a different set of desktop activities depending on which monitor I use, but that is a much more involved process, so I put it in a separate tutorial at: viewtopic.php?f=14&t=88644

Hope these help someone.
mescobal
Registered Member
Posts
8
Karma
0
OS
Why isn't this a built-in feature?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
I believe this is due to the lack of a maintainer as such for the utilities which handle RandR interaction.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Unfortunately there is not much you can do here, cloning is only really possible with the same resolution...


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
strycat
Registered Member
Posts
18
Karma
0
Just wanted to say thanks for posting this information. I was having some serious issues with my laptop switching between the builtin display and dual external monitors.

It was fairly simple to add just one more xrandr command to handle the 2nd monitor. Also the display names were slightly different. I'd never had figured it out unless I had come across this post.

Code: Select all
#!/bin/bash

# from viewtopic.php?f=14&t=88659
# this goes in .kde4/env

myvar="$(xrandr -q)"
if [[ $myvar == *"VGA1 connected"* ]]
then
# assuming if one is connected that both are...
xrandr --output LVDS1 --auto;
xrandr --output LVDS1 --off;
xrandr --output VGA1 --auto;
xrandr --output HDMI1 --mode 1680x1050 --right-of VGA1;

else
xrandr --output LVDS1 --auto;
fi



Thanks again for the post. Now to see if I can get the custom activities working for each situation.
didi_X8
Registered Member
Posts
18
Karma
0
OS
Is there a possibility to react on a configuration change while KDE is running?
I mostly keep my laptop in standby mode, so it doesn't help me if the check is only done when KDE loads.

I observed:
Code: Select all
$ dbus-monitor
...
method call sender=:1.2 -> dest=org.freedesktop.DBus serial=29902 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameHasOwner
   string "org.kde.internal.KSettingsWidget-kcm_randr"
method call sender=:1.2 -> dest=org.kde.knotify serial=29903 path=/Notify; interface=org.kde.KNotify; member=event
   string "messageInformation"
   string "kde"
   array [
   ]
   string ""
   string "A new monitor output has been connected.

Do you wish to run a configuration tool to adjust the monitor setup?"
   array [
   ]
   array [
   ]
   int32 -1
   int64 12583049
method return sender=:1.20 -> dest=:1.2 reply_serial=29903
   int32 5238
...

If I understand right, KDE can detect the event. If so, it should possible to add a script as hook I guess. Any idea?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
D-Bus allows you to connect to signals sent by applications. In this case you are watching communication to KNotify - which is a KDE Notification service.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
matt1606
Registered Member
Posts
2
Karma
0
OS
Hi,

I've become interested in this topic and wrote a simple udev rule and a script to control the monitor connection status changes.
It goes like this:

/etc/udev/rules.d/99-monitor-hotplug.rules
Code: Select all
ACTION=="change", SUBSYSTEM=="drm", RUN+="/etc/udev/scripts/monitor_hotplug.sh"


/etc/udev/scripts/monitor_hotplug.sh
Code: Select all
#!/bin/bash

IN="LVDS1"
EXT="VGA1"
USER="__your_normal_user__"

export XAUTHORITY=/home/$USER/.Xauthority
export DISPLAY=:0.0

status="$(cat /sys/class/drm/card0-VGA-1/status)"

if [ "${status}" = disconnected ]
then
    xrandr --output $EXT --off
elif [ "${status}" = connected ]
then
        xrandr --output $EXT --auto --right-of $IN
fi




Remember to change the IN, EXT, USER variables and /sys path ("card0-VGA-1") in the script to suit your configuration. Add the executable flag for the script:
chmod +x /etc/udev/scripts/monitor_hotplug.sh

It works like this:
1) udev change ACTION in drm SUBSYSTEM is triggered when the monitor is being plugged in/out, which runs the monitor-hotplug script
2) depending on the monitor connection state the script runs xrandr command with specific parameters
danmcknutt
Registered Member
Posts
3
Karma
0
I finally made the switch from windows to mint 15 kde. So far I dont think I will ever look back.

Im running a monitor off vga and my tv off the hdmi. The tv isnt always on and I want it to automatically change settings when I power it on. Being sick of the display managment change monitor screwing up the auto detect settings everytime and not wanting to manually set them I disabled it. Then I made a simple script that I run and it changes the to my desired settings but thats tedious coming from the automation of windows. I cannot use the last script mentioned because the status of my device reads connected whether the tv is on or off. Is there some sort of different script i can run or can i change the display management monitor to run my script instead of asking me for it to try automatically?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Does the output of "xrandr" change on your system, if the TV is on or off? Presumably some change must occur for display management to have detected it.

Also, which version of KDE are you using? Newer versions are often shipped with KScreen in many distributions now, which works significantly better than the older display management (krandr) system.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
danmcknutt
Registered Member
Posts
3
Karma
0
I have kde 4.10.5 so i do have kscreen. Im not exactly sure how to see the output of xrandr or where to look. I have noticed that if i run "udevadm monitor --property" in terminal and turn the tv on I get this

Code: Select all
KERNEL[1802.213759] change   /devices/pci0000:00/0000:00:01.0/0000:01:05.0/drm/card0 (drm)
ACTION=change
DEVNAME=dri/card0
DEVPATH=/devices/pci0000:00/0000:00:01.0/0000:01:05.0/drm/card0
DEVTYPE=drm_minor
HOTPLUG=1
MAJOR=226
MINOR=0
SEQNUM=2261
SUBSYSTEM=drm
UDEV_LOG=3

UDEV  [1802.218156] change   /devices/pci0000:00/0000:00:01.0/0000:01:05.0/drm/card0 (drm)
ACTION=change
DEVNAME=/dev/dri/card0
DEVPATH=/devices/pci0000:00/0000:00:01.0/0000:01:05.0/drm/card0
DEVTYPE=drm_minor
HOTPLUG=1
MAJOR=226
MINOR=0
SEQNUM=2261
SUBSYSTEM=drm
TAGS=:udev-acl:
UDEV_LOG=3
USEC_INITIALIZED=19397837

KERNEL[1802.963897] change   /devices/pci0000:00/0000:00:01.0/0000:01:05.0/drm/card0 (drm)
ACTION=change
DEVNAME=dri/card0
DEVPATH=/devices/pci0000:00/0000:00:01.0/0000:01:05.0/drm/card0
DEVTYPE=drm_minor
HOTPLUG=1
MAJOR=226
MINOR=0
SEQNUM=2262
SUBSYSTEM=drm
UDEV_LOG=3

UDEV  [1802.967607] change   /devices/pci0000:00/0000:00:01.0/0000:01:05.0/drm/card0 (drm)
ACTION=change
DEVNAME=/dev/dri/card0
DEVPATH=/devices/pci0000:00/0000:00:01.0/0000:01:05.0/drm/card0
DEVTYPE=drm_minor
HOTPLUG=1
MAJOR=226
MINOR=0
SEQNUM=2262
SUBSYSTEM=drm
TAGS=:udev-acl:
UDEV_LOG=3
USEC_INITIALIZED=19397837
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
"xrandr" in this case is a command which is probably part of an X11 utilities package if it is not available on your system.
Unfortunately that udev information doesn't seem to be too helpful in this case.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
danmcknutt
Registered Member
Posts
3
Karma
0
There is no difference in xrandr whether the tv is off or on
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Unfortunate. As far as I can see it is not possible then to determine the difference.
One last thing you could check is the output of "xrandr --prop" - which may differ as I suspect some information won't be available if the TV is off.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], Yahoo [Bot]