Skip to content

Commit

Permalink
Add notifications and document configuration variables
Browse files Browse the repository at this point in the history
  • Loading branch information
schlomo committed Jul 1, 2014
1 parent aacdbf1 commit 298bd8e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -39,6 +39,16 @@ In rare cases it might be neccessary to run automirror more than once so that xr
configured to mirror the primary display with **scaling** so that the primary display fills
the entire screen. The scaling does not care about aspect ratios!

## CONFIGURATION

automirror can be configured via environment variables:

* `AUTOMIRROR_PRIMARY_DISPLAY`:
Defaults to `LVDS1`. If this display is present than always configure all other displays to mirror that one.

* `AUTOMIRROR_NOTIFY_COMMAND`:
Defaults to use notify-send(1). Can be set to a command that will be called with a single argument containing a multi-line string. Set to `true` to disable notifications.

## DEVELOPMENT

Please add test cases under `testdata` for everything you want to have covered.
Expand Down
2 changes: 1 addition & 1 deletion automirror.desktop
Expand Up @@ -7,5 +7,5 @@ GenericName=Automatic Display Mirror
Exec=automirror
Icon=automirror
Terminal=false
Categories=Graphics;
Categories=Utility;
Comment=Automatically configure attached monitors for screen mirroring
19 changes: 15 additions & 4 deletions automirror.sh
Expand Up @@ -4,7 +4,8 @@ set -e -E -u
XRANDR_STATUS_PROGRAM=${XRANDR_STATUS_PROGRAM:-xrandr}
XRANDR_SET_PROGRAM=${XRANDR_SET_PROGRAM:-xrandr}

PRIMARY_DISPLAY=${PRIMARY_DISPLAY:-LVDS1}
PRIMARY_DISPLAY=${AUTOMIRROR_PRIMARY_DISPLAY:-LVDS1}
NOTIFY_SEND=( ${AUTOMIRROR_NOTIFY_COMMAND:-notify-send -a automirror -i automirror "Automatic Mirror Configuration"} )

# force called programs to english output
LANG=C LC_ALL=C
Expand Down Expand Up @@ -36,9 +37,11 @@ function get_highest_display {

xrandr_current="$($XRANDR_STATUS_PROGRAM)"

# find connected displays
# find connected displays by filtering those that are connected and have a size set in millimeters (mm)
connected_displays=( $(sed -n -e 's/^\(.*\) connected.*mm$/\1/p' <<<"$xrandr_current") )

# See http://stackoverflow.com/a/1252191/2042547 for how to use sed to replace newlines
# display_list is a list of displays with their maximum/optimum pixel and physical dimensions
display_list="$(sed ':a;N;$!ba;s/\n / /g' <<<"$xrandr_current" | sed -n -e 's/^\([A-Z0-9_-]\+\) connected.* \([0-9]\+\)mm.* \([0-9]\+\)mm.* \([0-9]\+\)x\([0-9]\+\)[ 0-9\.\*]\++.*$/\1 \2 \3 \4 \5/p' )"
: ${connected_displays[@]}
: "$display_list"
Expand All @@ -49,7 +52,7 @@ $xrandr_current"
fi


# if primary display is active then that is our frame buffer size
# if the primary display is NOT connected then use the highest display as primary
if [[ "${connected_displays[*]}" != *$PRIMARY_DISPLAY* ]] ; then
PRIMARY_DISPLAY=$(get_highest_display "$display_list")
fi
Expand All @@ -58,17 +61,25 @@ frame_buffer_resolution=$(get_display_resolution $PRIMARY_DISPLAY "$display_list
: $frame_buffer_resolution

xrandr_set_args=( --fb $frame_buffer_resolution )
notify_string=""
if (( ${#connected_displays[@]} == 1 )) ; then
xrandr_set_args+=( --output $connected_displays --mode $frame_buffer_resolution --scale 1x1 )
notify_string="$connected_displays reset to $frame_buffer_resolution"
else
other_display_list="$(grep -v ^$PRIMARY_DISPLAY <<<"$display_list")"
$XRANDR_SET_PROGRAM $(while read display junk ; do echo " --output $display --scale 1x1 --off" ; done <<<"$other_display_list")
xrandr_set_args+=( --output $PRIMARY_DISPLAY --mode $frame_buffer_resolution --scale 1x1 )
notify_string="$PRIMARY_DISPLAY is primary at $frame_buffer_resolution"
while read display junk ; do
xrandr_set_args+=( --output $display --same-as $PRIMARY_DISPLAY --mode $(get_display_resolution $display "$other_display_list") --scale-from $frame_buffer_resolution )
mode="$(get_display_resolution $display "$other_display_list")"
xrandr_set_args+=( --output $display --same-as $PRIMARY_DISPLAY --mode "$mode" --scale-from $frame_buffer_resolution )
notify_string="$notify_string\n$display is scaled mirror at $mode"
done <<<"$other_display_list"
fi

#logger -s -t "$0" -- Running $XRANDR_SET_PROGRAM "${xrandr_set_args[@]}"

$XRANDR_SET_PROGRAM "${xrandr_set_args[@]}"
ret=$?
"${NOTIFY_SEND[@]}" "$notify_string"
exit $ret
2 changes: 1 addition & 1 deletion debian/control
Expand Up @@ -8,7 +8,7 @@ Build-Depends: debhelper (>= 9)

Package: automirror
Architecture: all
Depends: ${misc:Depends}, x11-xserver-utils
Depends: ${misc:Depends}, x11-xserver-utils, libnotify-bin
Description: Automatically mirror X screen onto available monitors
What it does:
* LVDS1 is primary output if enabled, everything else will be mirror
Expand Down

0 comments on commit 298bd8e

Please sign in to comment.