Guest User

zaprat

a guest
Aug 3rd, 2013
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. #!/bin/zsh
  2. ############################################################################
  3. # author: milomouse <vincent[at]fea.st> #
  4. # detail: banish the mouse cursor to bottom-right corner of the screen and #
  5. # disable touchpad (optional); also undo this by returning mouse #
  6. # to last position (or center of screen) and enabling touchpad. #
  7. ############################################################################
  8. # depend: xdotool: for controlling the mouse #
  9. # xdpyinfo: for finding screen dimensions #
  10. # synclient: for controlling the touchpad in laptops (optional) #
  11. ############################################################################
  12. unsetopt nomatch
  13. scriptname=$(print - $0(^:t))
  14.  
  15. ## VARIABLE: set a temporary file for storing mouse position.
  16. FILE="/tmp/user-keep/${USER}/.${scriptname}"
  17.  
  18. ## CODE: do not edit below this line unless you know what you are doing.
  19. function _help() {
  20. << EOF
  21. usage: ${scriptname} [option]
  22. options:
  23. -t | --toggle Enable or disable mouse
  24. -d | --disable Force disabling of mouse
  25. -e | --enable Force enabling of mouse
  26. -s | --show Display \$FILE location
  27. -h | --help Display this message
  28.  
  29. depends:
  30. xdotool ($(print ${${${:-=xdotool}/=*/not found}/\/*/installed}))
  31. xdpyinfo ($(print ${${${:-=xdpyinfo}/=*/not found}/\/*/installed}))
  32. synclient ($(print ${${${:-=synclient}/=*/not found}/\/*/installed})) [optional]
  33. EOF
  34. exit
  35. }
  36.  
  37. function __dimensions() {
  38. for exe in xdotool xdpyinfo; do
  39. which ${exe} &>/dev/null || { print "Missing required program: ${exe}" ; _err=1 }
  40. done
  41. [[ ${+_err} == 1 ]] && exit 1
  42. xy=${${${${${(M)${"$(xdpyinfo 2>/dev/null)"}#*dimensions:*\)}#*dimensions*:}/pixels*}// }/x/ }
  43. x=${${(s: :)xy}[1]}
  44. y=${${(s: :)xy}[2]}
  45. }
  46.  
  47. function _mayberat() {
  48. if [[ ${+FILE} == "0" ]]; then
  49. print "You must set a temp file; see source code." && exit 1
  50. fi
  51. if [[ ! -d ${FILE:h} ]]; then
  52. print "Directory for file does not existing, attempting to create..."
  53. mkdir -p ${FILE:h} || { print "Could not create \"${FILE:h}\", make sure you have proper write permissions." ; exit 1 }
  54. fi
  55. if [[ -f ${FILE} ]]; then
  56. _yesrat
  57. else
  58. _norat
  59. fi
  60. }
  61.  
  62. function _yesrat() {
  63. __dimensions
  64. if [[ ${+DISPLAY} == 1 ]]; then
  65. if [[ -f ${FILE} && ${#$(<${FILE})} -eq 2 ]]; then
  66. xdotool mousemove $(<${FILE}) &>/dev/null
  67. rm -f ${FILE} &>/dev/null
  68. else
  69. xdotool mousemove $(($(print ${x})/2)) $(($(print ${y})/2)) &>/dev/null
  70. rm -f ${FILE} &>/dev/null
  71. fi
  72. which synclient &>/dev/null && synclient TouchpadOff=0 &>/dev/null
  73. else
  74. print "\$DISPLAY unavailable, aborting."
  75. exit 1
  76. fi
  77. }
  78.  
  79. function _norat() {
  80. __dimensions
  81. if [[ ${+DISPLAY} == 1 ]]; then
  82. print ${${${$(xdotool getmouselocation 2>/dev/null)[1,2]//:/}#x}#y} >>! ${FILE}
  83. xdotool mousemove $(print ${xy}) &>/dev/null
  84. which synclient &>/dev/null && synclient TouchpadOff=1 &>/dev/null
  85. else
  86. print "\$DISPLAY unavailable, aborting."
  87. exit 1
  88. fi
  89. }
  90.  
  91. [[ -z $1 ]] && _help
  92. case $1 in
  93. '-t'|'--toggle') _mayberat ;;
  94. '-d'|'--disable') _norat ;;
  95. '-e'|'--enable') _yesrat ;;
  96. '-s'|'--show') print ${FILE} ; exit ;;
  97. '-h'|'--help') _help ;;
  98. *) [[ -z $@ ]] && _help || { print "unrecognized operation: $@ (see --help for usage)" ; exit 1 } ;;
  99. esac
Advertisement
Add Comment
Please, Sign In to add comment