[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Display-relative coordinates
From: |
martin rudalics |
Subject: |
Re: Display-relative coordinates |
Date: |
Fri, 29 Jul 2016 07:54:33 +0200 |
> It would still be useful, I think, to have a function that returns
> directly the screen-relative pixel coordinates (i.e., even though
> that can be got using `window-absolute-pixel-position' and
> `frame-geometry'.)
‘window-absolute-pixel-position’ does that already. Quoting the Elisp
manual:
-- Function: window-absolute-pixel-position &optional position window
If the buffer position POSITION is visible in window WINDOW, this
function returns the display coordinates of the upper/left corner
of the glyph at POSITION. The return value is a cons of the X-
and Y-coordinates of that corner, relative to an origin at (0, 0)
of WINDOW's display. It returns `nil' if POSITION is not visible
in WINDOW.
WINDOW must be a live window and defaults to the selected window.
POSITION defaults to the value of `window-point' of WINDOW.
This means that in order to move the mouse pointer to the position
of point in the selected window, it's sufficient to write:
(let ((position (window-absolute-pixel-position)))
(set-mouse-absolute-pixel-position
(car position) (cdr position)))
Note the example given at the end. ‘set-mouse-absolute-pixel-position’
warps the mouse pointer on your screen without any knowledge of the
existence or position of frames/windows on that screen. You can use
that function as an acid test for your own favorite function's ability
to retrieve precise screen coordiantes.
martin