mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-20 22:16:49 +01:00
X11: Fixed high mouse buttons mappings and horizontal wheels (thanks, Daniel!).
Fixes Bugzilla #2472.
This commit is contained in:
parent
870df8adab
commit
e58a5c43c4
@ -173,14 +173,15 @@ static Bool X11_IsWheelCheckIfEvent(Display *display, XEvent *chkev,
|
|||||||
XEvent *event = (XEvent *) arg;
|
XEvent *event = (XEvent *) arg;
|
||||||
/* we only handle buttons 4 and 5 - false positive avoidance */
|
/* we only handle buttons 4 and 5 - false positive avoidance */
|
||||||
if (chkev->type == ButtonRelease &&
|
if (chkev->type == ButtonRelease &&
|
||||||
(event->xbutton.button == Button4 || event->xbutton.button == Button5) &&
|
(event->xbutton.button == Button4 || event->xbutton.button == Button5 ||
|
||||||
|
event->xbutton.button == 6 || event->xbutton.button == 7) &&
|
||||||
chkev->xbutton.button == event->xbutton.button &&
|
chkev->xbutton.button == event->xbutton.button &&
|
||||||
chkev->xbutton.time == event->xbutton.time)
|
chkev->xbutton.time == event->xbutton.time)
|
||||||
return True;
|
return True;
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_bool X11_IsWheelEvent(Display * display,XEvent * event,int * ticks)
|
static SDL_bool X11_IsWheelEvent(Display * display,XEvent * event,int * xticks,int * yticks)
|
||||||
{
|
{
|
||||||
XEvent relevent;
|
XEvent relevent;
|
||||||
if (X11_XPending(display)) {
|
if (X11_XPending(display)) {
|
||||||
@ -198,12 +199,19 @@ static SDL_bool X11_IsWheelEvent(Display * display,XEvent * event,int * ticks)
|
|||||||
(XPointer) event)) {
|
(XPointer) event)) {
|
||||||
|
|
||||||
/* by default, X11 only knows 5 buttons. on most 3 button + wheel mouse,
|
/* by default, X11 only knows 5 buttons. on most 3 button + wheel mouse,
|
||||||
Button4 maps to wheel up, Button5 maps to wheel down. */
|
Button4 maps to (vertical) wheel up, Button5 maps to wheel down.
|
||||||
|
Horizontal scrolling usually maps to 6 and 7 which have no name */
|
||||||
if (event->xbutton.button == Button4) {
|
if (event->xbutton.button == Button4) {
|
||||||
*ticks = 1;
|
*yticks = 1;
|
||||||
}
|
}
|
||||||
else if (event->xbutton.button == Button5) {
|
else if (event->xbutton.button == Button5) {
|
||||||
*ticks = -1;
|
*yticks = -1;
|
||||||
|
}
|
||||||
|
else if (event->xbutton.button == 6) {
|
||||||
|
*xticks = 1;
|
||||||
|
}
|
||||||
|
else if (event->xbutton.button == 7) {
|
||||||
|
*xticks = -1;
|
||||||
}
|
}
|
||||||
return SDL_TRUE;
|
return SDL_TRUE;
|
||||||
}
|
}
|
||||||
@ -1023,22 +1031,33 @@ X11_DispatchEvent(_THIS)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ButtonPress:{
|
case ButtonPress:{
|
||||||
int ticks = 0;
|
int xticks = 0, yticks = 0;
|
||||||
if (X11_IsWheelEvent(display,&xevent,&ticks)) {
|
if (X11_IsWheelEvent(display,&xevent,&xticks, &yticks)) {
|
||||||
SDL_SendMouseWheel(data->window, 0, 0, ticks, SDL_MOUSEWHEEL_NORMAL);
|
SDL_SendMouseWheel(data->window, 0, xticks, yticks, SDL_MOUSEWHEEL_NORMAL);
|
||||||
} else {
|
} else {
|
||||||
if(xevent.xbutton.button == Button1) {
|
int button = xevent.xbutton.button;
|
||||||
|
if(button == Button1) {
|
||||||
if (ProcessHitTest(_this, data, &xevent)) {
|
if (ProcessHitTest(_this, data, &xevent)) {
|
||||||
break; /* don't pass this event on to app. */
|
break; /* don't pass this event on to app. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDL_SendMouseButton(data->window, 0, SDL_PRESSED, xevent.xbutton.button);
|
else if(button > 7) {
|
||||||
|
/* X button values 4-7 are used for scrolling, so X1 is 8, X2 is 9, ...
|
||||||
|
=> subtract (8-SDL_BUTTON_X1) to get value SDL expects */
|
||||||
|
button -= (8-SDL_BUTTON_X1);
|
||||||
|
}
|
||||||
|
SDL_SendMouseButton(data->window, 0, SDL_PRESSED, button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ButtonRelease:{
|
case ButtonRelease:{
|
||||||
SDL_SendMouseButton(data->window, 0, SDL_RELEASED, xevent.xbutton.button);
|
int button = xevent.xbutton.button;
|
||||||
|
if (button > 7) {
|
||||||
|
/* see explanation at case ButtonPress */
|
||||||
|
button -= (8-SDL_BUTTON_X1);
|
||||||
|
}
|
||||||
|
SDL_SendMouseButton(data->window, 0, SDL_RELEASED, button);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user