Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the mouse cursor drawn faster than applications?

One of the things that I've noticed (at least on Windows anyway), is that the mouse cursor is drawn with much less latency than even standard Windows elements.

A good example of this would be to start dragging on the desktop. You can easily notice that the drag rectangle is lagging significantly behind the cursor.

My first question is: why is this the case?

I can't imagine drawing a rectangle being so much more expensive than drawing the cursor. Certainly not by a frame or two.

And my second question is, would it ever be possible to match one's application rendering 1:1 with cursor input?

A good use case for this would be either this selection rectangle, or drag previews for draggable items. Both of which lag behind quite significantly from the OS mouse pointer (independent of any framework or library used).

like image 702
Riho Avatar asked Jan 31 '26 04:01

Riho


1 Answers

Selecting icons on the desktop with the selection rectangle is not that slow on my system (DWM on), it is lagging a little bit but not enough for me to really care.

The "Show Window Contents while Dragging" option has always been rather slow which is why it was not on by default in older Windows versions.

The mouse cursor on the other hand can be rendered directly by your hardware. That is, Windows sends the cursor image to your graphics card and after that Windows only has to tell the graphics card the cursor position and this is much faster than all the messages and user/kernel context switches involved when you resize and paint a window. The mouse driver probably uses hardware interrupts/timers with a higher priority than your normal software as well.

You can try to disable hardware cursors with a registry hack but the HID/mouse driver and the raw input thread in win32k will still have a higher priority than your application.

like image 191
Anders Avatar answered Feb 03 '26 06:02

Anders