toggle-touchpad.el (4011B)
1 ;;; toggle-touchpad.el -*- lexical-binding: t; -*- 2 3 ;; Copyright (C) 2019 Jamie Beardslee 4 5 ;; Author: Jamie Beardslee <jdb@jamzattack.xyz> 6 ;; Version: 2020.06.07 7 8 ;; This program is free software; you can redistribute it and/or modify 9 ;; it under the terms of the GNU General Public License as published by 10 ;; the Free Software Foundation, either version 3 of the License, or 11 ;; (at your option) any later version. 12 13 ;; This program is distributed in the hope that it will be useful, 14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 ;; GNU General Public License for more details. 17 18 ;; You should have received a copy of the GNU General Public License 19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>. 20 21 ;;; Commentary: 22 23 ;; This file defines the function `toggle-touchpad', which uses xinput 24 ;; to disable or enable the mouse in an X session. This probably only 25 ;; works with my laptop. 26 27 ;;; Code: 28 29 (defvar toggle-touchpad--trackpoint-disabled-p nil 30 "Whether the touchpad is disabled. If the value is non-nil, the 31 touchpad is disabled.") 32 33 (defvar toggle-touchpad--touchpad-disabled-p t 34 "Whether the touchpad is disabled. If the value is non-nil, the 35 touchpad is disabled.") 36 37 (defvar toggle-touchpad--trackpoint-device "TPPS/2 IBM TrackPoint" 38 "The xinput device identifier for the trackpoint. 39 Use \"xinput list\" to see what devices are available.") 40 41 (defvar toggle-touchpad--touchpad-device "SynPS/2 Synaptics TouchPad" 42 "The xinput device identifier for the touchpad. 43 Use \"xinput list\" to see what devices are available.") 44 45 (defun toggle-touchpad-xinput-command (command device) 46 "Use xinput(1) to run COMMAND on DEVICE." 47 (interactive) 48 (start-process "touchpad" " *touchpad*" 49 "xinput" 50 command device)) 51 52 53 ;;; Touchpad 54 55 (defun toggle-touchpad-disable-touchpad () 56 "Disables the touchpad." 57 (toggle-touchpad-xinput-command 58 "disable" toggle-touchpad--touchpad-device) 59 (setq toggle-touchpad--touchpad-disabled-p t)) 60 61 (defun toggle-touchpad-enable-touchpad () 62 "Enables the touchpad." 63 (toggle-touchpad-xinput-command 64 "enable" toggle-touchpad--touchpad-device) 65 (setq toggle-touchpad--touchpad-disabled-p nil)) 66 67 ;;;###autoload 68 (defun toggle-touchpad-toggle-touchpad () 69 "Toggles the touchpad." 70 (interactive) 71 (if toggle-touchpad--touchpad-disabled-p 72 (toggle-touchpad-enable-touchpad) 73 (toggle-touchpad-disable-touchpad))) 74 75 76 ;;; Trackpoint 77 78 (defun toggle-touchpad-disable-trackpoint () 79 "Disables the trackpoint." 80 (toggle-touchpad-xinput-command 81 "disable" toggle-touchpad--trackpoint-device) 82 (setq toggle-touchpad--trackpoint-disabled-p t)) 83 84 (defun toggle-touchpad-enable-trackpoint () 85 "Enables the trackpoint." 86 (toggle-touchpad-xinput-command 87 "enable" toggle-touchpad--trackpoint-device) 88 (setq toggle-touchpad--trackpoint-disabled-p nil)) 89 90 ;;;###autoload 91 (defun toggle-touchpad-toggle-trackpoint () 92 "Toggles the trackpoint." 93 (interactive) 94 (if toggle-touchpad--trackpoint-disabled-p 95 (toggle-touchpad-enable-trackpoint) 96 (toggle-touchpad-disable-trackpoint))) 97 98 99 ;;; Both 100 101 (defun toggle-touchpad-enable-both () 102 "Enables both the trackpoint and the touchpad." 103 (toggle-touchpad-enable-touchpad) 104 (toggle-touchpad-enable-trackpoint)) 105 106 (defun toggle-touchpad-disable-both () 107 "Disables both the trackpoint and the touchpad." 108 (toggle-touchpad-disable-touchpad) 109 (toggle-touchpad-disable-trackpoint)) 110 111 ;;;###autoload 112 (defun toggle-touchpad (&optional arg) 113 "Toggles both the trackpoint and the touchpad. 114 115 With prefix arg ARG, use my preferred settings (touchpad disabled 116 and trackpoint enabled)." 117 (interactive "P") 118 (cond 119 (arg (toggle-touchpad-disable-touchpad) 120 (toggle-touchpad-enable-trackpoint)) 121 ((or toggle-touchpad--trackpoint-disabled-p 122 toggle-touchpad--touchpad-disabled-p) 123 (toggle-touchpad-enable-both)) 124 (t (toggle-touchpad-disable-both)))) 125 126 (provide 'toggle-touchpad) 127 128 ;;; toggle-touchpad.el ends here