You are not logged in.
Pages: 1
Hi guys,
I'm using XFCE 4.12 on a laptop with 1280x800 screen that is occasionally connected to an external 24" full HD monitor.
I just want the following:
1\ if the external monitor is connected, I want to switch off the laptop screen using only the external one (resolution 1920x1080).
2\ if the external monitor is not connected, I want to use the laptop one (resolution 1280x800).
I was able to achieve this behaviour just in the login screen calling xrandr with the "display-setup-script" in the /etc/lightdm/lightdm.conf but, as soon as I'm logged on XFCE, that setup is lost and the xfce default display setup is applied.
Is there a way to create 2 different display settings, calling one or another based on the fact that my external monitor is connected or not?
Any other suggestion to achieve the result is really appreciated.
Cheers
mm
Offline
Hello and welcome.
You could use a udev rule and script such as this one that will called and executed when udev reports the connection/disconnection of the monitor.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Hi ToZ,
thanks for your suggestion, I've played a bit with the udev rules (total beginner here) and the script that call xrandr, not able to get the result yet so I need a bit further help:
1\ concerning the script, I had to remove following part since in my distribution (fedora 24) the ck-list-session command is not found:
uid=$(ck-list-sessions | awk 'BEGIN { unix_user = ""; } /^Session/ { unix_user = ""; } /unix-user =/ { gsub(/'\''/,"",$3); unix_user = $3; } /x11-display = '\'$display\''/ { print unix_user; exit (0); }')
if [ -n "$uid" ]; then
# from https://wiki.archlinux.org/index.php/Ac … _Power_Off
export XAUTHORITY=$(ps -C Xorg -f --no-header | sed -n 's/.*-auth //; s/ -[^ ].*//; p')
else
echo "unable to find an X session"
exit 1
fi
Even with this modification, calling it manually after the login the script works as expected, detecting which monitors are connected and setting the proper resolution.
2\ concerning udev rules, I've created the file /etc/udev/rules.d/99-monitor-hotplug.rules exactly as indicated at the link you suggested, but the rule seems not triggered neither at login time, nor if I disconnect and reconnect the VGA screen.
Thanks again
Offline
I don't use fedora so I can't offer specific advice, but try adding some debug statements to the /usr/local/bin/monitor-hotplug.sh file, statements like:
echo "Executing hotplug.sh" >> /tmp/debug.log
...to see if the file is being called. Then plug/unplug the monitor and see if the script is being called.
I'll test the script here as well.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Okay, finished testing and it doesn't work for me either.
Then I found post #8 from this thread and this solution worked for me. My files:
/etc/udev/rules.d/99-monitor-hotplug.rules
ACTION=="change", KERNEL=="card0", SUBSYSTEM=="drm", RUN+="/usr/bin/systemctl start hot_plug.service"
/etc/systemd/system/hot_plug.service
[Unit]
Description=Monitor hotplug
[Service]
Type=simple
RemainAfterExit=no
User=toz
ExecStart=/usr/local/bin/hotplug_monitor.sh
[Install]
WantedBy=multi-user.target
/usr/local/bin/hotplug_monitor.sh
#!/bin/bash
######################################
## /usr/local/bin/hotplug_monitor.sh
######################################
echo "enter" > /tmp/hotplug.log
X_USER=toz
export DISPLAY=:0
export XAUTHORITY=/home/$X_USER/.Xauthority
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
function connect()
{
#connect DP2
echo "inside connect()" >> /tmp/hotplug.log
xrandr --output DP2 --auto --right-of LVDS1 >> /tmp/screen
}
function disconnect(){
echo "inside disconnect()" >> /tmp/hotplug.log
xrandr --output DP2 --off
}
if [ $(cat /sys/class/drm/card0-DP-2/status) == "connected" ] ; then
connect
elif [ $(cat /sys/class/drm/card0-DP-2/status) == "disconnected" ] ; then
disconnect
else
exit
fi
echo "exit" >> /tmp/hotplug.log
Note 1: Make sure you change the userid (toz) in files 2 & 3, the userid (1000) in file #3, and video card file names and xrandr commands (xard0-DP-2) in #3.
Note: I'm logging everything to /tmp/hotplug.log if you want to see what is happening.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Hi,
the script, service and udev rule works like a charm on Fedora 24 (just had to change the parameters you've indicated).
The only problem is that the udev rule apparently is triggerered when I hot plug or unplug the VGA connector, while during boot the script is not triggered.
As result, if I boot the laptop with the external monitor attached, I still see both of them on.
Using lightdm.conf parameter display-setup-script won't help as well, cause in this case the laptop screen is swtiched off just before lightdm start but, just after login, it is switched on again......
Offline
As result, if I boot the laptop with the external monitor attached, I still see both of them on.
Using lightdm.conf parameter display-setup-script won't help as well, cause in this case the laptop screen is swtiched off just before lightdm start but, just after login, it is switched on again......
You can try running that same script from your startup applications, but it may just result in the the laptop screen flashing on then off again. Might be worth a try to see what happens.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Hi,
effectively calling the same script at startup works, even if I confirm your suspect: the laptop screen is switched off when lightdm start, then it comes back to some "default" mirrored screens, then is fixed 2nd time when the login is completed.
I've just created the following file:
$HOME/.config/autostart/monitor-resfix.desktop
with this code:
[Desktop Entry]
Name=Monitor Resolution Fix
Exec=/usr/local/bin/monitor-hotplug.sh
Terminal=true
Type=Application
I've kept the idea from this post:
https://ask.fedoraproject.org/en/questi … fedora-24/
In this way I've got the expected result.... still not clear to me which program set back the "default" mirrored screen after lightdm.
Thanks again for your patience and help
Offline
Pages: 1
[ Generated in 0.016 seconds, 11 queries executed - Memory usage: 573.93 KiB (Peak: 590.77 KiB) ]