Make sure we don’t set point just because there is a click in an inactive window

This commit is contained in:
Gergely Polonkai 2023-01-31 08:54:28 +01:00
parent 9f95dc62cc
commit 4737acaad0
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
1 changed files with 27 additions and 0 deletions

27
lisp/gp-mouse.el Normal file
View File

@ -0,0 +1,27 @@
;;; gp-mouse --- Extra mouse functionality
;;; Commentary:
;;; Code:
(require 'mouse)
(defun gpolonkai/event-in-current-window-p (event)
"Check if EVENT happened in the current window."
(let ((current-window (selected-window))
(event-window (posn-window (event-start event))))
(eq current-window event-window)))
(defun gpolonkai/mouse-set-point (click &optional promote-to-region)
"Set mouse position.
If CLICK happened in an inactive window, select that window without setting point"
(interactive "e\np")
(if (gpolonkai/event-in-current-window-p click)
(call-interactively 'mouse-set-point)
(call-interactively 'mouse-select-window)))
(global-set-key [mouse-1] 'mouse-select-window-or-set-point)
(global-unset-key [down-mouse-1])
(provide 'gp-mouse)
;;; gp-mouse.el ends here