evdev: Use the EvdevPost...Event() functions in the emulation code.

This is similar to commit 1f641d75ed.

It provides the same functionality of queuing the (in this case
emulated) events and waiting until an EV_SYN synchronization event is
received before posting them to the server.

This preserves the order of events (both real and emulated) and ensures
that MotionNotify events will always be posted first. It also unifies
the event posting into a few small functions which improves
maintainability.

From this point on, you should never use the xf86Post...Event()
functions in new code, but rather the EvdevPost...Event() versions.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
master
Oliver McFadden 17 years ago committed by Peter Hutterer
parent 6f4634111a
commit 69d6ff3e01
  1. 2
      src/draglock.c
  2. 6
      src/emuMB.c
  3. 7
      src/emuWheel.c
  4. 33
      src/evdev.c
  5. 9
      src/evdev.h

@ -158,7 +158,7 @@ EvdevDragLockLockButton(InputInfoPtr pInfo, unsigned int button)
state = pEvdev->dragLock.lock_state[button - 1] ? FALSE : TRUE; state = pEvdev->dragLock.lock_state[button - 1] ? FALSE : TRUE;
pEvdev->dragLock.lock_state[button - 1] = state; pEvdev->dragLock.lock_state[button - 1] = state;
xf86PostButtonEvent(pInfo->dev, 0, button, state, 0, 0); EvdevPostButtonEvent(pInfo, button, state);
} }
/* Filter button presses looking for either a meta button or the /* Filter button presses looking for either a meta button or the

@ -198,7 +198,7 @@ EvdevMBEmuTimer(InputInfoPtr pInfo)
pEvdev->emulateMB.pending = FALSE; pEvdev->emulateMB.pending = FALSE;
if ((id = stateTab[pEvdev->emulateMB.state][4][0]) != 0) { if ((id = stateTab[pEvdev->emulateMB.state][4][0]) != 0) {
xf86PostButtonEvent(pInfo->dev, 0, abs(id), (id >= 0), 0, 0); EvdevPostButtonEvent(pInfo, abs(id), (id >= 0));
pEvdev->emulateMB.state = pEvdev->emulateMB.state =
stateTab[pEvdev->emulateMB.state][4][2]; stateTab[pEvdev->emulateMB.state][4][2];
} else { } else {
@ -248,12 +248,12 @@ EvdevMBEmuFilterEvent(InputInfoPtr pInfo, int button, BOOL press)
if ((id = stateTab[pEvdev->emulateMB.state][*btstate][0]) != 0) if ((id = stateTab[pEvdev->emulateMB.state][*btstate][0]) != 0)
{ {
xf86PostButtonEvent(pInfo->dev, 0, abs(id), (id >= 0), 0, 0); EvdevPostButtonEvent(pInfo, abs(id), (id >= 0));
ret = TRUE; ret = TRUE;
} }
if ((id = stateTab[pEvdev->emulateMB.state][*btstate][1]) != 0) if ((id = stateTab[pEvdev->emulateMB.state][*btstate][1]) != 0)
{ {
xf86PostButtonEvent(pInfo->dev, 0, abs(id), (id >= 0), 0, 0); EvdevPostButtonEvent(pInfo, abs(id), (id >= 0));
ret = TRUE; ret = TRUE;
} }

@ -82,8 +82,7 @@ EvdevWheelEmuFilterButton(InputInfoPtr pInfo, unsigned int button, int value)
* If the button is released early enough emit the button * If the button is released early enough emit the button
* press/release events * press/release events
*/ */
xf86PostButtonEvent(pInfo->dev, 0, button, 1, 0, 0); EvdevPostButtonClicks(pInfo, button, 1);
xf86PostButtonEvent(pInfo->dev, 0, button, 0, 0, 0);
} }
} }
@ -163,10 +162,8 @@ EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value)
/* Produce button press events for wheel motion */ /* Produce button press events for wheel motion */
while(abs(axis->traveled_distance) > pEvdev->emulateWheel.inertia) { while(abs(axis->traveled_distance) > pEvdev->emulateWheel.inertia) {
axis->traveled_distance -= inertia; axis->traveled_distance -= inertia;
xf86PostButtonEvent(pInfo->dev, 0, button, 1, 0, 0); EvdevPostButtonClicks(pInfo, button, 1);
xf86PostButtonEvent(pInfo->dev, 0, button, 0, 0, 0);
} }
} }

@ -24,6 +24,7 @@
* Kristian Høgsberg (krh@redhat.com) * Kristian Høgsberg (krh@redhat.com)
* Adam Jackson (ajax@redhat.com) * Adam Jackson (ajax@redhat.com)
* Peter Hutterer (peter.hutterer@redhat.com) * Peter Hutterer (peter.hutterer@redhat.com)
* Oliver McFadden (oliver.mcfadden@nokia.com)
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
@ -248,8 +249,8 @@ static int wheel_down_button = 5;
static int wheel_left_button = 6; static int wheel_left_button = 6;
static int wheel_right_button = 7; static int wheel_right_button = 7;
static void void
PostKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value) EvdevPostKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value)
{ {
int code = ev->code + MIN_KEYCODE; int code = ev->code + MIN_KEYCODE;
static char warned[KEY_CNT]; static char warned[KEY_CNT];
@ -296,8 +297,8 @@ PostKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value)
pEvdev->num_queue++; pEvdev->num_queue++;
} }
static void void
PostButtonEvent(InputInfoPtr pInfo, int button, int value) EvdevPostButtonEvent(InputInfoPtr pInfo, int button, int value)
{ {
EventQueuePtr pQueue; EventQueuePtr pQueue;
EvdevPtr pEvdev = pInfo->private; EvdevPtr pEvdev = pInfo->private;
@ -315,14 +316,14 @@ PostButtonEvent(InputInfoPtr pInfo, int button, int value)
pEvdev->num_queue++; pEvdev->num_queue++;
} }
static void void
PostButtonClicks(InputInfoPtr pInfo, int button, int count) EvdevPostButtonClicks(InputInfoPtr pInfo, int button, int count)
{ {
int i; int i;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
PostButtonEvent(pInfo, button, 1); EvdevPostButtonEvent(pInfo, button, 1);
PostButtonEvent(pInfo, button, 0); EvdevPostButtonEvent(pInfo, button, 0);
} }
} }
@ -506,9 +507,9 @@ EvdevProcessButtonEvent(InputInfoPtr pInfo, struct input_event *ev)
return; return;
if (button) if (button)
PostButtonEvent(pInfo, button, value); EvdevPostButtonEvent(pInfo, button, value);
else else
PostKbdEvent(pInfo, ev, value); EvdevPostKbdEvent(pInfo, ev, value);
} }
/** /**
@ -536,17 +537,17 @@ EvdevProcessRelativeMotionEvent(InputInfoPtr pInfo, struct input_event *ev)
switch (ev->code) { switch (ev->code) {
case REL_WHEEL: case REL_WHEEL:
if (value > 0) if (value > 0)
PostButtonClicks(pInfo, wheel_up_button, value); EvdevPostButtonClicks(pInfo, wheel_up_button, value);
else if (value < 0) else if (value < 0)
PostButtonClicks(pInfo, wheel_down_button, -value); EvdevPostButtonClicks(pInfo, wheel_down_button, -value);
break; break;
case REL_DIAL: case REL_DIAL:
case REL_HWHEEL: case REL_HWHEEL:
if (value > 0) if (value > 0)
PostButtonClicks(pInfo, wheel_right_button, value); EvdevPostButtonClicks(pInfo, wheel_right_button, value);
else if (value < 0) else if (value < 0)
PostButtonClicks(pInfo, wheel_left_button, -value); EvdevPostButtonClicks(pInfo, wheel_left_button, -value);
break; break;
/* We don't post wheel events as axis motion. */ /* We don't post wheel events as axis motion. */
@ -628,7 +629,7 @@ EvdevProcessKeyEvent(InputInfoPtr pInfo, struct input_event *ev)
/** /**
* Post the relative motion events. * Post the relative motion events.
*/ */
static void void
EvdevPostRelativeMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v, EvdevPostRelativeMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v,
int v[MAX_VALUATORS]) int v[MAX_VALUATORS])
{ {
@ -642,7 +643,7 @@ EvdevPostRelativeMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v,
/** /**
* Post the absolute motion events. * Post the absolute motion events.
*/ */
static void void
EvdevPostAbsoluteMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v, EvdevPostAbsoluteMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v,
int v[MAX_VALUATORS]) int v[MAX_VALUATORS])
{ {

@ -25,6 +25,7 @@
* Kristian Høgsberg (krh@redhat.com) * Kristian Høgsberg (krh@redhat.com)
* Adam Jackson (ajax@redhat.com) * Adam Jackson (ajax@redhat.com)
* Peter Hutterer (peter@cs.unisa.edu.au) * Peter Hutterer (peter@cs.unisa.edu.au)
* Oliver McFadden (oliver.mcfadden@nokia.com)
*/ */
#ifndef EVDEV_H #ifndef EVDEV_H
@ -179,6 +180,14 @@ typedef struct {
EventQueueRec queue[EVDEV_MAXQUEUE]; EventQueueRec queue[EVDEV_MAXQUEUE];
} EvdevRec, *EvdevPtr; } EvdevRec, *EvdevPtr;
/* Event posting functions */
void EvdevPostKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value);
void EvdevPostButtonEvent(InputInfoPtr pInfo, int button, int value);
void EvdevPostButtonClicks(InputInfoPtr pInfo, int button, int count);
void EvdevPostRelativeMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v,
int v[MAX_VALUATORS]);
void EvdevPostAbsoluteMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v,
int v[MAX_VALUATORS]);
unsigned int EvdevUtilButtonEventToButtonNumber(EvdevPtr pEvdev, int code); unsigned int EvdevUtilButtonEventToButtonNumber(EvdevPtr pEvdev, int code);
/* Middle Button emulation */ /* Middle Button emulation */

Loading…
Cancel
Save