public
Last active

  • Download Gist
envy-video
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
#!/bin/bash
 
LOG=/tmp/switch_log
TMP=/tmp/switch_tmp
SWITCH_FILE=/sys/kernel/debug/vgaswitcheroo/switch
DIS_CHECK=DIS:+
IGD_CHEClK=IGD:+
NOW=`date`
 
case $1 in
sleep)
echo "--${NOW}--" >> $LOG
echo "Sleeping" >> $LOG
 
# check if DIS is active
grep -q $DIS_CHECK $SWITCH_FILE
if [ "$?" -eq "0" ]; then
echo "DIS active" >> $LOG
# record current state
echo "DIS:+" > $TMP
 
# activate IGD
echo "DIGD" > $SWITCH_FILE
# restart gdm - activates switch
/etc/rc.d/gdm restart
else
# record IGD state for wakeup
echo "IGD:+" > $TMP
fi
# assume we are on IGD already
# power on un-used (discrete) card (somehow this prevents issues)
echo "ON" > $SWITCH_FILE
 
;;
wake)
echo "--${NOW}--" >> $LOG
echo "Waking" >> $LOG
 
# check if DIS *was* active
grep -q $DIS_CHECK $TMP
if [ "$?" -eq "0" ]; then
echo "DIS *was* active. Re-enabling." >> $LOG
# activate DIS
echo "DDIS" > $SWITCH_FILE
# restart gdm - activates switch
/etc/rc.d/gdm restart
 
# power on IGD for brightness
echo "ON" > $SWITCH_FILE
else
echo "IGD *was* active. Turning off DIS for power saving." >> $LOG
echo "OFF" > $SWITCH_FILE
fi
;;
ac-on)
echo "--${NOW}--" >> $LOG
echo "AC power. Enable DIS" >> $LOG
 
echo "DDIS" > $SWITCH_FILE
 
if [ $2 != "boot" ]; then
/etc/rc.d/gdm restart
fi
 
echo "ON" > $SWITCH_FILE
 
;;
ac-off)
echo "--${NOW}--" >> $LOG
echo "Battery power. Enable IGD" >> $LOG
 
echo "DIGD" > $SWITCH_FILE
 
if [ $2 != "boot" ]; then
/etc/rc.d/gdm restart
fi
 
echo "OFF" > $SWITCH_FILE
 
;;
esac
 
# alway log switch state after running this
cat $SWITCH_FILE >> $LOG

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.