From 4737acaad0c28d02642124c3060317b1283bed16 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 31 Jan 2023 08:54:28 +0100 Subject: [PATCH] =?UTF-8?q?Make=20sure=20we=20don=E2=80=99t=20set=20point?= =?UTF-8?q?=20just=20because=20there=20is=20a=20click=20in=20an=20inactive?= =?UTF-8?q?=20window?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lisp/gp-mouse.el | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 lisp/gp-mouse.el diff --git a/lisp/gp-mouse.el b/lisp/gp-mouse.el new file mode 100644 index 0000000..a943071 --- /dev/null +++ b/lisp/gp-mouse.el @@ -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