laptop_hacks
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
laptop_hacks [2017/03/04 02:28] – [Power Disconnect/Connect events] admin | laptop_hacks [2020/02/08 16:41] (current) – [Laptop Hacks] admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====Laptop Hacks===== | =====Laptop Hacks===== | ||
- | Ho boy, this got difficult really quickly - in 2012 I had everything working on my laptop with the LXDE spin of fedora plus fluxbox. After a quick spurt of travel using all the laptoppy things like conserving battery life, suspend/ | + | Ho boy, this got difficult really quickly - in 2011 I had everything working on my laptop |
Maybe it'll help you too - but you will almost certainly need to some make tweaks for your particular setup. | Maybe it'll help you too - but you will almost certainly need to some make tweaks for your particular setup. | ||
- | Why go through all this? Why not just use a full DE like KDE or gnome to take care of it? With KDE the best I could get (without digging just as deep as I have done here) was about 4 hours of battery life. By doing the hard work and understanding what's going on I can get up to 6.5 hours! Not bad. | + | Why go through all this? Why not just use a full DE like KDE or gnome to take care of it? With KDE the best I could get was about 4 hours of battery life. By doing the hard work and understanding what's going on I can get up to 6.5 hours! Not bad. |
====Who' | ====Who' | ||
- | This section applies to NOT using a full desktop like gnome or KDE - those monsters do it all for you, nothing to see here, please move along. | + | Several players: |
- | For the rest of us using i3, fluxbox etc we need to first install | + | * acpid: for suspend |
+ | * DBus: for power connect/ | ||
+ | * acpi: to get battery status | ||
+ | * systemctl: but, of course! | ||
+ | * ???: DBus? lid opening & closing - just seems to work | ||
+ | |||
+ | ====Suspend==== | ||
+ | |||
+ | Install | ||
systemctl enable acpid | systemctl enable acpid | ||
systemctl start acpid | systemctl start acpid | ||
- | It turns out that there are several players that respond to laptop events like lid opening & closing, ac power connection, suspend etc even without the distraction of gnome and KDE. Notably | + | Put this into '' |
- | How to tell? AFAICS you look at the logs - '' | + | event=button/sleep |
+ | action=systemctl suspend | ||
- | How to change it? No idea - possibly installing '' | + | ====Tweaking touchpad==== |
+ | |||
+ | Seems the synaptics driver is deprecated in favour of libinput | ||
+ | |||
+ | Section " | ||
+ | Identifier " | ||
+ | Driver " | ||
+ | MatchIsTouchpad " | ||
+ | Option " | ||
+ | Option " | ||
+ | Option " | ||
+ | EndSection | ||
====Power Disconnect/ | ====Power Disconnect/ | ||
Line 26: | Line 46: | ||
These events come through DBus, so I run this in my '' | These events come through DBus, so I run this in my '' | ||
- | # if there' | + | # if there' |
- | upower -e |grep -q battery && power-monitor & | + | upower -e |grep -q battery && |
+ | | ||
+ | xfce4-power-manager & | ||
+ | } | ||
- | Where, '' | + | Where, '' |
#!/bin/env python | #!/bin/env python | ||
| | ||
- | import gobject, os | + | |
+ | # requires dbus-python | ||
+ | |||
+ | | ||
gobject.threads_init() | gobject.threads_init() | ||
| | ||
Line 40: | Line 66: | ||
import dbus | import dbus | ||
bus = dbus.SystemBus() | bus = dbus.SystemBus() | ||
+ | | ||
+ | sys.dont_write_bytecode = True | ||
| | ||
def backtick(command): | def backtick(command): | ||
Line 52: | Line 80: | ||
return(value) | return(value) | ||
| | ||
+ | # power connection events | ||
def ac(*args, **kwargs): | def ac(*args, **kwargs): | ||
- | if args[1][' | + | |
- | print(" | + | print args |
- | os.system(" | + | try: |
- | else: | + | |
- | print(" | + | print(" |
- | os.system(" | + | os.system(" |
- | | + | else: |
+ | print(" | ||
+ | os.system(" | ||
+ | except: | ||
+ | | ||
+ | |||
+ | # warn user or suspend | ||
def check_battery(*args, | def check_battery(*args, | ||
battery_status = backtick(" | battery_status = backtick(" | ||
- | print(battery_status) | + | print(" |
if " | if " | ||
percent = int( backtick(" | percent = int( backtick(" | ||
- | | + | |
- | if percent < 10: backtick(" | + | print(" |
+ | os.system(" | ||
+ | if percent < 10: | ||
+ | print(" | ||
+ | os.system(" | ||
gobject.timeout_add(60 * 1000, check_battery) | gobject.timeout_add(60 * 1000, check_battery) | ||
| | ||
Line 76: | Line 115: | ||
l = gobject.MainLoop() | l = gobject.MainLoop() | ||
l.run() | l.run() | ||
+ | | ||
Put this in '' | Put this in '' | ||
- | #!/bin/sh | + | #!/usr/bin/env bash |
| | ||
POWER=" | POWER=" | ||
[[ " | [[ " | ||
| | ||
- | | + | echo " |
- | | + | |
- | exit 1 | + | |
- | } | + | |
- | + | ||
- | LOG=/ | + | |
- | echo " | + | |
- | exec >$LOG 2>&1 | + | |
| | ||
case " | case " | ||
OFF) | OFF) | ||
battery-status | battery-status | ||
- | | ||
- | logger -t $0 "power disconnect: killing bluetooth" | ||
- | systemctl stop bluetooth.target | ||
- | BT_PID=$(ps -ef |grep ' | ||
- | [[ " | ||
- | rmmod bnep btbcm btrtl btusb btintel bluetooth | ||
| | ||
- | sudo / | + | |
- | sudo / | + | sudo $( which brightness ) 20 |
- | sudo / | + | sudo $( which 02-pm-power-tweaks) true |
+ | sudo $( which 03-pm-power-hda) true | ||
| | ||
- | powertop --auto-tune | + | |
sleep 3 | sleep 3 | ||
| | ||
battery-status | battery-status | ||
- | | ||
- | echo " | ||
- | echo " | ||
- | echo " | ||
;; | ;; | ||
ON) | ON) | ||
- | sudo / | + | |
- | sudo / | + | sudo $( which brightness ) 100 |
- | sudo / | + | sudo $( which 02-pm-power-tweaks) false |
- | + | sudo $( which 03-pm-power-hda) false | |
- | logger -t $0 "power connect: starting bluetooth" | + | |
- | modprobe bluetooth | + | |
- | systemctl start bluetooth.target | + | |
- | + | ||
- | modprobe uvcvideo r8169 mii | + | |
;; | ;; | ||
esac | esac | ||
| | ||
pkill -0 i3blocks && pkill -RTMIN+9 i3blocks | pkill -0 i3blocks && pkill -RTMIN+9 i3blocks | ||
- | + | | |
- | cat $LOG | + | |
- | + | ||
- | Put this in '' | + | |
- | + | ||
- | #!/bin/sh | + | |
- | + | ||
- | logger -t $0 "$0 $@" | + | |
- | case " | + | |
- | true) | + | |
- | # called by pm-powersave on power disconnect | + | |
- | + | ||
- | xbacklight -display :0 -set 1 | + | |
- | logger -t $0 "power disconnect: xbacklight -set 10" | + | |
- | ;; | + | |
- | false) | + | |
- | xbacklight -display :0 -set 40 | + | |
- | logger -t $0 "power connect: xbacklight -set 40" | + | |
- | ALARM_PID_FILE="/ | + | |
- | [[ -f $ALARM_PID_FILE ]] && { | + | |
- | logger -t $0 "alarm pids = $( cat $ALARM_PID_FILE )" | + | |
- | for PID in $(cat $ALARM_PID_FILE); | + | |
- | [[ $PID > 0 ]] && kill $PID | + | |
- | done | + | |
- | rm $ALARM_PID_FILE | + | |
- | } | + | |
- | ;; | + | |
- | esac | + | |
- | exit 0 | + | |
Put this in '' | Put this in '' | ||
Line 181: | Line 170: | ||
Put this in '' | Put this in '' | ||
- | #!/bin/sh | + | #!/usr/bin/env bash |
# BH | # BH | ||
| | ||
Line 187: | Line 176: | ||
case " | case " | ||
true) | true) | ||
- | | + | |
+ | systemctl stop bluetooth.target | ||
+ | rfkill block bluetooth | ||
+ | BT_PID=$(ps -ef |grep ' | ||
+ | [[ " | ||
| | ||
echo 5 > / | echo 5 > / | ||
echo 0 > / | echo 0 > / | ||
- | echo 1 > / | + | |
- | echo ondemand | + | echo powersave |
echo 1500 > / | echo 1500 > / | ||
for i in / | for i in / | ||
Line 200: | Line 193: | ||
echo Y > / | echo Y > / | ||
echo 1 > / | echo 1 > / | ||
- | for i in /sys/bus/{pci,i2c}/ | + | for i in / |
+ | iw dev wlp3s0 set power_save on | ||
;; | ;; | ||
false) | false) | ||
+ | logger -t $0 "power connect" | ||
echo 0 > / | echo 0 > / | ||
echo 1 > / | echo 1 > / | ||
- | echo 0 > / | + | |
- | echo ondemand | + | echo performance |
echo 500 > / | echo 500 > / | ||
for i in / | for i in / | ||
Line 214: | Line 209: | ||
#echo Y > / | #echo Y > / | ||
#echo 1 > / | #echo 1 > / | ||
- | #for i in /sys/bus/{pci,i2c}/ | + | #for i in / |
+ | |||
+ | modprobe bluetooth | ||
+ | rfkill unblock bluetooth | ||
+ | |||
+ | systemctl start bluetooth.target | ||
+ | |||
+ | modprobe uvcvideo r8169 mii | ||
+ | iw dev wlp3s0 set power_save off | ||
;; | ;; | ||
esac | esac | ||
Line 220: | Line 223: | ||
exit 0 | exit 0 | ||
| | ||
- | + | To run stuff on ' | |
- | ====hibernate/ | + | |
- | + | ||
- | Put this into ''/ | + | |
- | + | ||
- | event=button/ | + | |
- | action=systemctl suspend | + | |
- | + | ||
- | I need to reset my synaptics touch pad on resume | + | |
- | + | ||
- | #!/bin/sh | + | |
- | + | ||
- | [ " | + | |
- | echo $0': $DISPLAY not set' >& | + | |
- | exit 1 | + | |
- | } | + | |
- | + | ||
- | pkill syndaemon | + | |
- | syndaemon -i 1 -d -K | + | |
- | synclient VertEdgeScroll=1 HorizEdgeScroll=1 VertTwoFingerScroll=1 HorizTwoFingerScroll=1 PalmDetect=1 TapButton1=1 TapButton2=2 # RTCornerButton=2 | + | |
- | + | ||
- | If using '' | + | |
[Unit] | [Unit] | ||
- | Description=User resume | + | Description=Run on 'resume' |
After=suspend.target | After=suspend.target | ||
| | ||
[Service] | [Service] | ||
- | User=%I | + | User=root |
- | Type=simple | + | Type=oneshot |
- | ExecStart=/usr/local/bin/set-synaptics | + | ExecStart=/sbin/hdparm -y /dev/sda # puts aux disc into standby |
| | ||
[Install] | [Install] | ||
WantedBy=suspend.target | WantedBy=suspend.target | ||
- | then run '' | + | and run '' |
+ | brightness is this: | ||
+ | |||
+ | #!/bin/bash | ||
+ | | ||
+ | # since xbacklight isn't working (nouveau?) | ||
+ | # https:// | ||
+ | | ||
+ | # needs to be run as root | ||
+ | | ||
+ | NEW_VALUE=${1: | ||
+ | | ||
+ | # base dir for backlight class | ||
+ | basedir="/ | ||
+ | | ||
+ | # get the backlight handler | ||
+ | handler=$basedir$(ls $basedir |head -n 1)"/" | ||
+ | | ||
+ | # get current brightness | ||
+ | old_brightness=$(cat $handler" | ||
+ | | ||
+ | # get max brightness | ||
+ | max_brightness=$(cat $handler" | ||
+ | | ||
+ | # get current brightness % | ||
+ | old_brightness_p=$(( 100 * $old_brightness / $max_brightness )) | ||
+ | | ||
+ | # calculate new brightness % | ||
+ | if [[ $NEW_VALUE == [+-]* ]]; then | ||
+ | new_brightness_p=$(($old_brightness_p + $NEW_VALUE)) | ||
+ | else | ||
+ | new_brightness_p=$NEW_VALUE | ||
+ | fi | ||
+ | | ||
+ | # calculate new brightness value | ||
+ | new_brightness=$(( $max_brightness * $new_brightness_p / 100 )) | ||
+ | | ||
+ | (( new_brightness <= max_brightness && new_brightness >= 0 )) && { | ||
+ | # set the new brightness value | ||
+ | echo $new_brightness > $handler" | ||
+ | } | ||
+ | | ||
====Disable nouveau==== | ====Disable nouveau==== | ||
laptop_hacks.1488619711.txt.gz · Last modified: 2017/03/04 02:28 by admin