summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorARAMIS STACH HAIDUSKI FERNANDES <aramis@guinness.c3sl.ufpr.br>2008-08-25 17:02:30 -0300
committerARAMIS STACH HAIDUSKI FERNANDES <aramis@guinness.c3sl.ufpr.br>2008-08-25 17:02:30 -0300
commitf9638c8174d51583210ead48371e435d2cb65023 (patch)
tree37b127db136ff8b4046b5b42ed1ca4aa3346b245
parent022cfa921ce724c716bb5046244aacee071ae967 (diff)
New file containing functions that use xrandr to set maximum resolution,
configure screen layout, etc.
-rwxr-xr-xmdm/src/xrandr-functions137
1 files changed, 137 insertions, 0 deletions
diff --git a/mdm/src/xrandr-functions b/mdm/src/xrandr-functions
new file mode 100755
index 0000000..32c49ea
--- /dev/null
+++ b/mdm/src/xrandr-functions
@@ -0,0 +1,137 @@
+#! /bin/bash
+# The following functions are specific for configuring X resolutions
+# This is important for multihead on cards with more than one output
+
+MDM_ETC=/etc/mdm
+SCREEN_POSITIONS=
+SCREEN_SIZES=
+SCREEN_AMOUNT=
+OUTPUT_NAMES=
+XRANDR_INFO=${MDM_ETC}/xrandr.info
+
+# The following functions are used to configure the maximum
+# resolution available to current screen.
+
+function xrandr_configure_layout () {
+ # We do need a value for $SCREEN_SIZES
+ if [ -z "$SCREEN_SIZES" ]; then
+ xrandr_screen_amount
+ fi
+
+ # Test if $OUTPUT_NAMES is not null (it happens with older drivers
+ # and/or older versions of xrandr).
+ # In case, screen resolution might be already configured
+ OUTPUT_NAMES=(`xrandr|grep "\<connected"|cut -d' ' -f1`)
+ if [ -n "$OUTPUT_NAMES" ]; then
+
+ if [ "${#OUTPUT_NAMES[@]}" == "1" ]; then
+ xrandr --output ${OUTPUT_NAMES[0]} --mode ${SCREEN_SIZES[0]}
+ else
+ # Configuring the first head:
+ xrandr --output ${OUTPUT_NAMES[0]} --mode ${SCREEN_SIZES[0]}
+
+ # To configure the other heads, it is necessary to have
+ # the first head already configured.
+ for (( a = 1; a < ${#OUTPUT_NAMES[@]}; a++ )); do
+ j=$(($a-1))
+ xrandr --output ${OUTPUT_NAMES[$a]} \
+ --right-of ${OUTPUT_NAMES[$j]}
+ done
+ fi
+ fi
+}
+
+function xrandr_set_resolutions () {
+
+ if [ -z "$SCREEN_SIZES" ];then
+ xrandr_screen_amount
+ fi
+ # We may have none outputs, it happens when there are no
+ # monitors connected to the outputs.
+ # Old drivers give us information even with the monitors shut down
+ if [ ! -z "$OUTPUT_NAMES" ]; then
+ # Trying one head:
+ if [ "${#OUTPUT_NAMES[@]}" = "1" ]; then
+ xrandr --output ${OUTPUT_NAMES[@]} --mode ${SCREEN_SIZES} 2>/dev/null
+ # The following sequence will only be activated with
+ # more than one head:
+ else
+ # Configuring the first head:
+ xrandr --output ${OUTPUT_NAMES[0]} --mode ${SCREEN_SIZES[0]}
+
+ # To configure the other heads, it is necessary to have
+ # the first head already configured.
+ for (( b=1; b < ${#OUTPUT_NAMES[@]}; b++ )); do
+ xrandr --output ${OUTPUT_NAMES[$b]} \
+ --mode ${SCREEN_SIZES[$b]} 2>/dev/null
+ done
+ fi
+ fi
+}
+
+function xrandr_set_screen_amount () {
+
+ SCREEN_SIZES=(`xrandr|grep -A1 "\<connected" |
+ tr -s ' '| egrep "^ [0-9]*x[0-9]*" |
+ cut -d' ' -f2`)
+
+ # According to driver in use, different
+ # outputs may occur, that is the reason for us to
+ # check if there is a value on $SCREEN_SIZES
+ if [ -z "$SCREEN_SIZES" ]; then
+ SCREEN_SIZES=`xrandr|grep "maximum" |
+ awk '{print $(NF-2)"x"$NF}'`
+ fi
+
+ # In case the xrandr version is older than 1.2:
+ if [ -z "$SCREEN_SIZES" ]; then
+ SCREEN_SIZES=`xrandr|egrep -m1 "( |\*)[0-9] "|
+ awk '{print $2"x"$4}'`
+ fi
+
+ OUTPUT_NAMES=(`xrandr|grep "\<connected"|cut -d' ' -f1`)
+ SCREEN_AMOUNT=${#OUTPUT_NAMES[@]}
+ OUTPUT_NAMES=${OUTPUT_NAMES:=none}
+
+ if (( ${#SCREEN_SIZES[@]} < ${#OUTPUT_NAMES[@]} ));then
+ for (( l = 0 ; l < ${#OUTPUT_NAMES[@]} ; l++ )); do
+ if [ -z "${SREEN_SIZES[l]}" ]; then
+ SCREEN_SIZES[l]=$SCREEN_SIZES
+ fi
+ done
+ fi
+}
+
+function xrandr_set_screen_position () {
+
+ xrandr_screen_amount
+
+ if (( "$SCREEN_AMOUNT" > 1 )); then
+ SCREEN_POSITIONS[0]=0
+ for (( k=0; k<$((SCREEN_AMOUNT-1)); k++)); do
+ SCREEN_POSITIONS[((k+1))]=$((`echo ${SCREEN_SIZES[k]}|
+ cut -d'x' -f1`+${SCREEN_POSITIONS[k]}))
+ done
+ else
+ SCREEN_POSITIONS=0
+ fi
+}
+
+function xrandr_create_info_file () {
+
+ xrandr_screen_position
+
+ # Generating a header
+ if [ ! -f "$XRANDR_INFO" ]; then
+ echo "Xrandr info file generated on: `date`" >> $XRANDR_INFO
+ fi
+ echo >> $XRANDR_INFO
+ echo "DISPLAY=`echo $DISPLAY`" >> $XRANDR_INFO
+ echo "SCREEN_AMOUNT=$SCREEN_AMOUNT" >> $XRANDR_INFO
+ echo "OUTPUT_NAMES=${OUTPUT_NAMES[@]}" >> $XRANDR_INFO
+ echo "SCREEN_SIZES=${SCREEN_SIZES[@]}" >> $XRANDR_INFO
+ echo "SCREEN_POSITIONS=${SCREEN_POSITIONS[@]}" >> $XRANDR_INFO
+ echo "------------ end ------------" >> $XRANDR_INFO
+ # Unsetting all vector positions
+ unset SCREEN_POSITIONS
+}