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)
  (call-process-shell-command "xinput --disable bcm5974"
                              nil "*Shell command output*" t))

(defun turn-on-mouse (&optional frame)
  (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?

up vote 11 down vote accepted

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)

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.