Better state machine for handling middle mouse button

emulation.
* Clicks shorter than EmulateMidButtonTime are no longer lost.
* The middle button event is generated as soon as both the left and the
  right buttons are pressed. The old code waited until the timeout had
  passed before even checking if both buttons were pressed.
This commit is contained in:
Peter Osterlund
2003-05-02 03:12:39 +02:00
parent efe5015664
commit b41f7dda28
2 changed files with 62 additions and 20 deletions

View File

@@ -514,7 +514,7 @@ ReadInput(LocalDevicePtr local)
double speed, integral;
int change;
int scroll_up, scroll_down, scroll_left, scroll_right;
int double_click;
int double_click, done;
/*
* set blocking to -1 on the first call because we know there is data to
@@ -569,24 +569,58 @@ ReadInput(LocalDevicePtr local)
para->down = down;
/* 3rd button emulation */
if(!left && !right)
{
priv->count_button_delay = priv->count_packet;
priv->third_button = FALSE;
}
else if(DIFF_TIME(priv->count_packet, priv->count_button_delay) < para->emulate_mid_button_time)
{
left = right = FALSE;
}
else if(DIFF_TIME(priv->count_packet, priv->count_button_delay) == para->emulate_mid_button_time)
{
priv->third_button = left && right;
}
if(priv->third_button)
{
mid = TRUE;
left = right = FALSE;
done = FALSE;
while (!done) {
Bool timeout;
switch (priv->mid_emu_state) {
case MBE_OFF:
if (left) {
priv->mid_emu_state = MBE_LEFT;
} else if (right) {
priv->mid_emu_state = MBE_RIGHT;
} else {
priv->count_button_delay = priv->count_packet;
done = TRUE;
}
break;
case MBE_LEFT:
timeout = DIFF_TIME(priv->count_packet, priv->count_button_delay) >=
para->emulate_mid_button_time;
if (!left || timeout) {
left = TRUE;
priv->mid_emu_state = MBE_OFF;
done = TRUE;
} else if (right) {
priv->mid_emu_state = MBE_MID;
} else {
left = FALSE;
done = TRUE;
}
break;
case MBE_RIGHT:
timeout = DIFF_TIME(priv->count_packet, priv->count_button_delay) >=
para->emulate_mid_button_time;
if (!right || timeout) {
right = TRUE;
priv->mid_emu_state = MBE_OFF;
done = TRUE;
} else if (left) {
priv->mid_emu_state = MBE_MID;
} else {
right = FALSE;
done = TRUE;
}
break;
case MBE_MID:
if (!left && !right) {
priv->mid_emu_state = MBE_OFF;
} else {
mid = TRUE;
left = right = FALSE;
done = TRUE;
}
break;
}
}
/* Up/Down-button scrolling or middle/double-click */

View File

@@ -53,6 +53,14 @@ typedef struct _SynapticsMoveHist
int x, y;
} SynapticsMoveHistRec;
enum MidButtonEmulation {
MBE_OFF, /* No button pressed */
MBE_LEFT, /* Left button pressed, waiting for right button or timeout */
MBE_RIGHT, /* Right button pressed, waiting for left button or timeout */
MBE_MID /* Left and right buttons pressed, waiting for both buttons
to be released */
};
typedef struct _SynapticsPrivateRec
{
/* shared memory pointer */
@@ -87,7 +95,7 @@ typedef struct _SynapticsPrivateRec
Bool vert_scroll_on; /* scrolling flag */
Bool horiz_scroll_on; /* scrolling flag */
double frac_x, frac_y; /* absoulte -> relative fraction */
Bool third_button; /* emulated 3rd button */
enum MidButtonEmulation mid_emu_state; /* emulated 3rd button */
OsTimerPtr repeat_timer; /* for up/down-button repeat */
int repeatButtons; /* buttons for repeat */
int lastButtons; /* last State of the buttons */