Is there a function that finds which Emacs window within a frame the mouse pointer is over without clicking or moving the mouse? I know that (mouse-position)
includes the frame the mouse is over, but I can't find a function that gives the window. Searching the web, stackexchange, etc, hasn't brought up any possibilities, either.
1 Answer
This should do it:
(window-at (cadr (mouse-position))
(cddr (mouse-position))
(car (mouse-position)))
See the Elisp manual section (elisp) Coordinates and Windows for more details.
-
@Drew It does work now, if you set the optional FRAME property. Very confusing testing this with a desktop with "focus follows mouse"!– TylerApr 7, 2016 at 21:23
-
@Drew Well, I'm doing it now and it's working. I've got two different frames open, and if the mouse is over one, which is open to an Info page, this expression returns
#<window 235 on *info*>
Moving the mouse over the other frame, over a window displaying the messages window, I get:#<window 168 on *Messages*>
.– TylerApr 7, 2016 at 21:50 -
I think this should work for me. If the mouse is over a different frame, I think I can do
(select-frame-set-input-focus (car (mouse-position)))
first. Apr 8, 2016 at 0:36 -
My bad.
mouse-position
does return the right frame in its return value, even if that frame is not selected. Thx.– DrewApr 8, 2016 at 2:04