handler.sh 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/sh
  2. # Default acpi script that takes an entry for all actions
  3. # NOTE: This is a 2.6-centric script. If you use 2.4.x, you'll have to
  4. # modify it to not use /sys
  5. # $1 should be + or - to step up or down the brightness.
  6. step_backlight() {
  7. for backlight in /sys/class/backlight/*/; do
  8. [ -d "$backlight" ] || continue
  9. step=$(( $(cat "$backlight/max_brightness") / 20 ))
  10. [ "$step" -gt "1" ] || step=1 #fallback if gradation is too low
  11. printf '%s' "$(( $(cat "$backlight/brightness") $1 step ))" >"$backlight/brightness"
  12. done
  13. }
  14. minspeed=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq)
  15. maxspeed=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq)
  16. setspeed="/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed"
  17. case "$1" in
  18. button/power)
  19. case "$2" in
  20. PBTN|PWRF)
  21. logger "PowerButton pressed: $2, shutting down..."
  22. shutdown -P now
  23. ;;
  24. *) logger "ACPI action undefined: $2" ;;
  25. esac
  26. ;;
  27. button/sleep)
  28. case "$2" in
  29. SBTN|SLPB)
  30. # suspend-to-ram
  31. logger "Sleep Button pressed: $2, suspending..."
  32. zzz
  33. ;;
  34. *) logger "ACPI action undefined: $2" ;;
  35. esac
  36. ;;
  37. ac_adapter)
  38. case "$2" in
  39. AC|ACAD|ADP0)
  40. case "$4" in
  41. 00000000)
  42. printf '%s' "$minspeed" >"$setspeed"
  43. #/etc/laptop-mode/laptop-mode start
  44. ;;
  45. 00000001)
  46. printf '%s' "$maxspeed" >"$setspeed"
  47. #/etc/laptop-mode/laptop-mode stop
  48. ;;
  49. esac
  50. ;;
  51. *) logger "ACPI action undefined: $2" ;;
  52. esac
  53. ;;
  54. battery)
  55. case "$2" in
  56. BAT0)
  57. case "$4" in
  58. 00000000) #echo "offline" >/dev/tty5
  59. ;;
  60. 00000001) #echo "online" >/dev/tty5
  61. ;;
  62. esac
  63. ;;
  64. CPU0)
  65. ;;
  66. *) logger "ACPI action undefined: $2" ;;
  67. esac
  68. ;;
  69. button/lid)
  70. case "$3" in
  71. close)
  72. # suspend-to-ram
  73. logger "LID closed, suspending..."
  74. zzz
  75. ;;
  76. open)
  77. logger "LID opened"
  78. ;;
  79. *) logger "ACPI action undefined (LID): $2";;
  80. esac
  81. ;;
  82. video/brightnessdown)
  83. step_backlight -
  84. ;;
  85. video/brightnessup)
  86. step_backlight +
  87. ;;
  88. *)
  89. logger "ACPI group/action undefined: $1 / $2"
  90. ;;
  91. esac