Making X report the mouse position with subpixel precision

Johan Kiviniemi freedesktop.org-xorg at johan.kiviniemi.name
Tue Feb 27 18:11:49 PST 2007


On Mon, Feb 26, 2007 at 09:13:59AM +1030, Peter Hutterer wrote:
> On 24/02/2007, at 08:12 , Johan Kiviniemi wrote:
> >The precision of mice is generally much better than the precision of
> >screens. I'm not very familiar with the internals of X, but AFAIK it
> >only reports the mouse position to clients at the screen's precision.

> One of the problems I see here is that X doesn't just swallow
> precision.  One unit move move reported represents one pixel cursor
> move (+ acceleration).
> To have sub-pixel accuracy you need to introduce something like
> negative acceleration (e.g. 10 units mouse move == 1 pixel), causing
> the user to move the physical device around _a lot_.

First of all, the X server would need to handle mouse coordinates
internally as floating-point numbers, not integers.  The screen can be
thought as if it consisted of X·Y rectangles, all of which are exactly
the size of the corresponding pixel.

On a 1600×1200 screen, the internal coordinates would satisfy 
  0.0 ≤ x < 1600.0
  0.0 ≤ y < 1200.0

Temporarily ignoring acceleration, it would be very simple to assume or
query the DPI value(s) for the mouse/mice and assume or query the DPI
value(s) for the display(s).  As i mentioned earlier, the former is
generally much higher than the latter.

Floating-point movement of the mouse can then be converted to the
floating-point screen coordinates very easily using the DPI ratio.  The
implementation of acceleration on top of that shouldn't be any trouble
either.

Of course, normal X clients (that don't need to care about the floating-
point coordinates) would receive the coordinates rounded to the
"current" pixel's integer coordinates (simple number truncation).

Things like only sending motion notifications when the cursor crosses a
pixel boundary have to be thought about, but they shouldn't be a
problem.

> >On a long page, a single pixel of scrollbar movement may cause the
> >content to scroll a huge amount. The entire design of scrollbars
> >could be better, but even with the current design, subpixel accuracy
> >would make it easier to control the scrolling.

> what is "a single pixel of scrollbar movement"?

When you move a scrollbar one pixel.  It might cause the page to scroll
five or a hundred pixels, depending on its size.

> what happens when you hit down or move the scrollbar is decided at the
> application/toolkit level and X doesn't have anything to do with it.

X is what reports the mouse coordinates to the application.  If the
toolkit were able to know the position at the accuracy of the mouse,
instead of just the accuracy of the screen, the user would have much
finer control of scrolling.

Sincerely,
-- 
Jοhan Kiviniemi  <johan at kiviniemi.name>  http://johan.kiviniemi.name/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.x.org/archives/xorg/attachments/20070228/9c6c4a71/attachment.pgp>


More information about the xorg mailing list