Skip to content

Commit

Permalink
[X11] Support for mouse buttons 4 and 5
Browse files Browse the repository at this point in the history
Support added for extra mouse buttons. Since these buttons were
not returned by XQueryPointer(), some additional logic was needed
which fit best to scroll wheel handling.
  • Loading branch information
zoltanvb committed Jun 20, 2024
1 parent e3bb6b7 commit 9b79348
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
9 changes: 9 additions & 0 deletions gfx/common/x11_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ bool x11_alive(void *data)
case 5: /* Scroll down */
case 6: /* Scroll wheel left */
case 7: /* Scroll wheel right */
case 8: /* Mouse button 4 */
case 9: /* Mouse button 5 */
x_input_poll_wheel(&event.xbutton, true);
break;
}
Expand All @@ -683,6 +685,13 @@ bool x11_alive(void *data)
break;

case ButtonRelease:
switch (event.xbutton.button)
{
case 8: /* Mouse button 4 - not handled as click */
case 9: /* Mouse button 5 - not handled as click */
x_input_poll_wheel(&event.xbutton, true);
break;
}
break;

case KeyRelease:
Expand Down
37 changes: 36 additions & 1 deletion input/common/input_x11_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ enum x11_mouse_btn_flags
X11_MOUSE_WU_BTN = (1 << 0),
X11_MOUSE_WD_BTN = (1 << 1),
X11_MOUSE_HWU_BTN = (1 << 2),
X11_MOUSE_HWD_BTN = (1 << 3)
X11_MOUSE_HWD_BTN = (1 << 3),
X11_MOUSE_BTN_4 = (1 << 4),
X11_MOUSE_BTN_5 = (1 << 5)
};

/* TODO/FIXME - static globals */
Expand Down Expand Up @@ -51,6 +53,13 @@ int16_t x_mouse_state_wheel(unsigned id)
ret = (g_x11_mouse_flags & X11_MOUSE_HWD_BTN);
g_x11_mouse_flags &= ~X11_MOUSE_HWD_BTN;
break;
case RETRO_DEVICE_ID_MOUSE_BUTTON_4:
ret = (g_x11_mouse_flags & X11_MOUSE_BTN_4);
break;
case RETRO_DEVICE_ID_MOUSE_BUTTON_5:
ret = (g_x11_mouse_flags & X11_MOUSE_BTN_5);
break;

}

return ret;
Expand All @@ -74,5 +83,31 @@ void x_input_poll_wheel(XButtonEvent *event, bool latch)
/* Scroll wheel right == HORIZ_WHEELUP */
g_x11_mouse_flags |= X11_MOUSE_HWU_BTN;
break;
case 8:
/* Extra buttons are regular press-release events,
* while scroll wheels do not stay pressed. */
/* Mouse button 4 */
switch (event->type)
{
case ButtonPress:
g_x11_mouse_flags |= X11_MOUSE_BTN_4;
break;
case ButtonRelease:
g_x11_mouse_flags &= ~X11_MOUSE_BTN_4;
break;
}
break;
case 9:
/* Mouse button 5 */
switch (event->type)
{
case ButtonPress:
g_x11_mouse_flags |= X11_MOUSE_BTN_5;
break;
case ButtonRelease:
g_x11_mouse_flags &= ~X11_MOUSE_BTN_5;
break;
}
break;
}
}
9 changes: 4 additions & 5 deletions input/drivers/x11_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,8 @@ static bool x_mouse_button_pressed(
return x11->mouse_r;
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
return x11->mouse_m;
#if 0
case RETRO_DEVICE_ID_MOUSE_BUTTON_4:
return x11->mouse_b4;
case RETRO_DEVICE_ID_MOUSE_BUTTON_5:
return x11->mouse_b5;
#endif
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP:
Expand Down Expand Up @@ -266,6 +262,8 @@ static int16_t x_input_state(
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP:
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN:
case RETRO_DEVICE_ID_MOUSE_BUTTON_4:
case RETRO_DEVICE_ID_MOUSE_BUTTON_5:
return x_mouse_state_wheel(id);
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
return x11->mouse_m;
Expand Down Expand Up @@ -489,7 +487,8 @@ static void x_input_poll(void *data)
x11->mouse_l = mask & Button1Mask;
x11->mouse_m = mask & Button2Mask;
x11->mouse_r = mask & Button3Mask;

/* Buttons 4 and 5 are not returned here, so they are handled elsewhere. */

/* > Mouse pointer */
if (!x11->mouse_grabbed)
{
Expand Down

0 comments on commit 9b79348

Please sign in to comment.