Fix mouse data buffering

Check remaining buffer size *before* reading a character from the device.  Also
keep extra characters in the static buffer until next invocation.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
This commit is contained in:
Samuel Thibault
2010-09-05 21:20:33 +02:00
parent b9d6d0309a
commit 35f277a718

View File

@@ -86,6 +86,7 @@ OsMouseReadInput(InputInfoPtr pInfo)
{
MouseDevPtr pMse;
static kd_event eventList[NUMEVENTS];
static int remainder = 0;
int n, c;
kd_event *event = eventList;
unsigned char *pBuf;
@@ -94,13 +95,14 @@ OsMouseReadInput(InputInfoPtr pInfo)
XisbBlockDuration(pMse->buffer, -1);
pBuf = (unsigned char *)eventList;
n = 0;
while ((c = XisbRead(pMse->buffer)) >= 0 && n < sizeof(eventList))
n = remainder;
while (n < sizeof(eventList) && (c = XisbRead(pMse->buffer)) >= 0)
pBuf[n++] = (unsigned char)c;
if (n == 0)
if (n == remainder)
return;
remainder = n % sizeof(kd_event);
n /= sizeof(kd_event);
while( n-- ) {
int buttons = pMse->lastButtons;
@@ -126,6 +128,7 @@ OsMouseReadInput(InputInfoPtr pInfo)
pMse->PostEvent(pInfo, buttons, dx, dy, 0, 0);
++event;
}
memcpy(eventList, event, remainder);
return;
}