=================================================================== ChangeSet@xxxx, 2004-08-10 00:53:14-05:00, dtor_core@xxxxxxxxxxxxx Correctly multiplex button events from several mice. gpm.c | 36 ++++++++++++++++++++++++++++++++++-- headers/gpmInt.h | 3 ++- 2 files changed, 36 insertions(+), 3 deletions(-) =================================================================== diff -Nru a/src/gpm.c b/src/gpm.c --- a/src/gpm.c 2004-08-10 01:17:59 -05:00 +++ b/src/gpm.c 2004-08-10 01:17:59 -05:00 @@ -259,6 +259,38 @@ return FD_ISSET(fd, &fdSet); } +static int multiplex_buttons(struct micetab *mouse, int new_buttons) +{ + static int left_btn_clicks, mid_btn_clicks, right_btn_clicks; + int mask; + int muxed_buttons = 0; + + new_buttons = + (mouse->options.sequence[new_buttons & 7] & 7) | (new_buttons & ~7); + mask = new_buttons ^ mouse->buttons; + mouse->buttons = new_buttons; + + if (mask & GPM_B_LEFT) { + if (new_buttons & GPM_B_LEFT) left_btn_clicks++; + else left_btn_clicks--; + } + if (left_btn_clicks) muxed_buttons |= GPM_B_LEFT; + + if (mask & GPM_B_MIDDLE) { + if (new_buttons & GPM_B_MIDDLE) mid_btn_clicks++; + else mid_btn_clicks--; + } + if (mid_btn_clicks) muxed_buttons |= GPM_B_MIDDLE; + + if (mask & GPM_B_RIGHT) { + if (new_buttons & GPM_B_RIGHT) right_btn_clicks++; + else right_btn_clicks--; + } + if (right_btn_clicks) muxed_buttons |= GPM_B_RIGHT; + + return muxed_buttons; +} + /*------------------------------------------------------------------- * call getMouseData to get hardware device data, call mouse device's fun() * to retrieve the hardware independent event data, then optionally repeat @@ -303,8 +335,8 @@ event->modifiers = nEvent.modifiers; /* propagate modifiers */ /* propagate buttons */ - nEvent.buttons = (opt->sequence[nEvent.buttons & 7] & 7) | - (nEvent.buttons & ~7); /* change the order */ + nEvent.buttons = multiplex_buttons(mouse, nEvent.buttons); + if (!i) event->buttons = nEvent.buttons; if (oldB != nEvent.buttons) { diff -Nru a/src/headers/gpmInt.h b/src/headers/gpmInt.h --- a/src/headers/gpmInt.h 2004-08-10 01:17:59 -05:00 +++ b/src/headers/gpmInt.h 2004-08-10 01:17:59 -05:00 @@ -162,7 +162,8 @@ struct miceopt options; Gpm_Type *type; char *device; -}; + int buttons; /* mouse's button state from last read */ +}; struct options { int autodetect; /* -u [aUtodetect..'A' is not available] */ _______________________________________________ gpm mailing list gpm@xxxxxxxxxxxxxx http://lists.linux.it/listinfo/gpm