8

I have the below elisp code in my emacs config which disables my touchpad, so it won't annoy me when writing.

;; disable touchpad when on emacs

(defun turn-off-mouse (&optional frame)
  (interactive)
  (call-process-shell-command "xinput --disable bcm5974"
                              nil "*Shell command output*" t))

(defun turn-on-mouse (&optional frame)
  (interactive)
  (call-process-shell-command "xinput --enable bcm5974"
                              nil "*Shell command output*" t))

(add-hook 'focus-in-hook #'turn-off-mouse)
(add-hook 'focus-out-hook #'turn-on-mouse)
(add-hook 'delete-frame-functions #'turn-on-mouse)

(provide 'setup-xinput)

This works fine; the problem is only when quitting Emacs.

If I quit Emacs while on Emacs, it keeps my touchpad disabled. So I need to open a new Terminal with the keyboard, and run xinput --enable bcm5974.

Is there any workaround for this? How could I quit Emacs and when quitting re-enabling my touchpad?

Drew
  • 75,699
  • 9
  • 109
  • 225
seds
  • 183
  • 3

1 Answers1

11

You can use kill-emacs-hook which is run when emacs is quit 'normally'.

Hook run when kill-emacs is called. Since kill-emacs may be invoked when the terminal is disconnected (or in other similar situations), functions placed on this hook should not expect to be able to interact with the user. To ask for confirmation, see kill-emacs-query-functions instead.

Just add turn-on-mouse to kill-emacs-hook like so

(add-hook 'kill-emacs-hook #'turn-on-mouse)
legoscia
  • 6,012
  • 29
  • 54
Iqbal Ansari
  • 7,468
  • 1
  • 28
  • 31