summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2010-09-05 21:20:33 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2010-09-05 21:20:33 +0200
commit35f277a718f2da6a09080af020aaf29ef96fe807 (patch)
tree62c2a34c3a66eb1294bb564097e9507fc222b379
parentb9d6d0309abdec7b384cb1f0958b9bcd60364e60 (diff)
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>
-rw-r--r--src/hurd_mouse.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/hurd_mouse.c b/src/hurd_mouse.c
index 4dac225..3008d28 100644
--- a/src/hurd_mouse.c
+++ b/src/hurd_mouse.c
@@ -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;
}