11

I want to prevent the "first" click on a frame in an inactive X window from having any effect, other than to make the frame active. Specifically, I don't want it to reposition point.

The problem is that I can't seem to detect that he frame was inactive when I get the mouse click. So the following code always shows "y":

;; detect if frame is active when clicking
(defun my/mouse-drag-region (event)
  (interactive "e")
  (mouse-minibuffer-check event)
  (let* ((window (caadr event))
         (frame (window-frame window)))
    (if (eql frame (selected-frame))
        (print "y")
      (print "n"))))
(global-set-key [down-mouse-1] 'my/mouse-drag-region)

How do I detect that the frame was previously inactive?

Or, has someone already achieved what I am trying to do elsewhere?

Note: I am asking for something different than this other question, which is about inactive windows, not inactive frames.

  • You want to modify the keyboard shortcut for mouse-set-point and create your own function to do whatever you want. Do the C-h k mouse click thing and see the two (2) functions that are listed there. – lawlist Jun 1 '15 at 14:17
  • Don't your frames have a title bar and border? Why don't you just click those, instead of clicking in a buffer? – Drew Jun 1 '15 at 16:08
  • @lawlist: I don't think this helps because the up event comes even later. I can't even tell that the frame was inactive during the down event! – edam Jun 1 '15 at 18:00
  • 2
    @Drew: well, I could, but it's fiddley. I'd prefer to just be able to click in the X window, like I can when emacs runs in a terminal. – edam Jun 1 '15 at 18:01
  • This is a very annoying behaviour indeed. I prevent it by not using the mouse at all, ie. using Alt+Tab and co. to switch between frames. – GergelyPolonkai Jun 3 '15 at 0:28
1

I don't think this is possible from within Emacs. The problem is that as soon as you click in the frame, the window manager selects that frame. Emacs thus sees it immediately as the selected frame.

Your own test code shows this. No advising of either mouse-drag-region or mouse-set-point (or any other Emacs function) will make any difference.

(Perhaps there is something you can do at the X11 level - dunno.)

  • Couldn't you track the selected frame via the post-command-hook, record all the point positions and revert them when the selected frame changes? It wouldn't be efficient, but it would work. – PythonNut Jul 23 '15 at 17:48
  • @PythonNut: Ugh. Maybe. Try it. post-command-hook is the last resort of a scoundrel. ;-) We all use it for lots of stuff, but it is a heavy hammer. – Drew Jul 23 '15 at 21:25
1

Not exactly what you're asking for, but this works well for me:

(global-unset-key [down-mouse-1])   ; no dragging nonsense
(global-set-key [mouse-1] 'mouse-select-window)  ; no setting point

This doesn't match your request exactly in that not only is the frame made active but so is the window clicked. But, I find that to be useful. Double click moves the point, single click doesn't.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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