Thanks I will try it outSure, it is not my work, i have just take it from the internet and adapted it.
If you want this to be executed every time when you plug in or out HDMI you will have to create a rule for udev (in /etc/udev/rules) that looks like this:Code:#!/bin/sh # # Monitor Toggle # The following script toggles between the internal monitor and an external monitor. # # Version 1.3 # Export Xauthority and display USERID="$(cat /var/run/ConsoleKit/database | grep -B 6 is_active=true | grep uid= | cut -f 2 -d '=')" USER="$(grep $USERID /etc/passwd | cut -f 1 -d ':')" # USER="$(who | grep :0\) | cut -f 1 -d ' ')" export XAUTHORITY=/home/$USER/.Xauthority export DISPLAY=:0 ########### Settings ########### # Use 'xrandr' to find these DP="DP1" VGA="VGA1" HDMI="HDMI1" INTERNAL_DISPLAY="eDP1" # Check /sys/class/drm for the exact location DP_STATUS="$(cat /sys/class/drm/card0-DP-1/status)" VGA_STATUS="$(cat /sys/class/drm/card0-VGA-1/status)" HDMI_STATUS="$(cat /sys/class/drm/card0-HDMI-A-1/status)" # Backlight settings BACKLIGHT_BATTERY=15 BACKLIGHT_AC=50 # Do no change! EXTERNAL_DISPLAY="" # Check to see if the external display is connected if [ "${DP_STATUS}" = connected ]; then EXTERNAL_DISPLAY=$DP fi if [ "${VGA_STATUS}" = connected ]; then EXTERNAL_DISPLAY=$VGA fi if [ "${HDMI_STATUS}" = connected ]; then EXTERNAL_DISPLAY=$HDMI fi # The external display is connected if [ "$EXTERNAL_DISPLAY" != "" ]; then # Set the display settings xrandr --output $INTERNAL_DISPLAY --off # Turn off internal display xrandr --output $EXTERNAL_DISPLAY --auto # Turn on external display # Set the DPI # External monitor definitions: # physical screen size from xrandr (xorg detection isn't right) em_ds_h=$(xrandr | grep $EXTERNAL_DISPLAY | rev | cut -d " " -f 3 | rev | sed 's/mm//') em_ds_v=$(xrandr | grep $EXTERNAL_DISPLAY | rev | cut -d " " -f 1 | rev | sed 's/mm//') em_ds="$em_ds_h"x"$em_ds_v" xrandr --output $EXTERNAL_DISPLAY --fbmm $em_ds # The external display is not connected else # Restore internal display if [ "$EXTERNAL_DISPLAY" != "" ]; then xrandr --output $EXTERNAL_DISPLAY --off # Turn off internal display fi xrandr --output $INTERNAL_DISPLAY --auto # Set the DPI # Internal Monitor definition im_ds_h=$(xrandr | grep $INTERNAL_DISPLAY | rev | cut -d " " -f 3 | rev | sed 's/mm//') im_ds_v=$(xrandr | grep $INTERNAL_DISPLAY | rev | cut -d " " -f 1 | rev | sed 's/mm//') im_ds="$im_ds_h"x"$im_ds_v" xrandr --output $INTERNAL_DISPLAY --fbmm $im_ds fi exit 0
You need of course to change the script path to wherever you created the script.Code:cat /etc/udev/rules.d/99-hdmi.rules SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/screendpi"
Bookmarks