Skip to content

Commit

Permalink
Handle buttons as scroll wheels
Browse files Browse the repository at this point in the history
  • Loading branch information
zoltanvb committed Jun 20, 2024
1 parent c1a35bf commit 59ed49e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 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;
}
}
20 changes: 4 additions & 16 deletions input/drivers/x11_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ typedef struct x11_input
bool mouse_l;
bool mouse_r;
bool mouse_m;
bool mouse_b4;
bool mouse_b5;
} x11_input_t;

/* Public global variable */
Expand Down Expand Up @@ -89,9 +87,7 @@ static bool x_mouse_button_pressed(
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
return x11->mouse_m;
case RETRO_DEVICE_ID_MOUSE_BUTTON_4:
return x11->mouse_b4;
case RETRO_DEVICE_ID_MOUSE_BUTTON_5:
return x11->mouse_b5;
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP:
Expand Down Expand Up @@ -266,14 +262,11 @@ 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;
case RETRO_DEVICE_ID_MOUSE_BUTTON_4:
return x11->mouse_b4;
case RETRO_DEVICE_ID_MOUSE_BUTTON_5:
return x11->mouse_b5;

}
break;
case RETRO_DEVICE_POINTER:
Expand Down Expand Up @@ -463,8 +456,6 @@ static void x_input_poll(void *data)
x11->mouse_l = 0;
x11->mouse_m = 0;
x11->mouse_r = 0;
x11->mouse_b4 = 0;
x11->mouse_b5 = 0;
return;
}

Expand All @@ -480,8 +471,6 @@ static void x_input_poll(void *data)
x11->mouse_l = 0;
x11->mouse_m = 0;
x11->mouse_r = 0;
x11->mouse_b4 = 0;
x11->mouse_b5 = 0;
return;
}

Expand All @@ -498,9 +487,8 @@ static void x_input_poll(void *data)
x11->mouse_l = mask & Button1Mask;
x11->mouse_m = mask & Button2Mask;
x11->mouse_r = mask & Button3Mask;
x11->mouse_b4 = mask & Button4Mask;
x11->mouse_b5 = mask & Button5Mask;

/* 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 59ed49e

Please sign in to comment.