Added hints SDL_HINT_MOUSE_DOUBLE_CLICK_TIME and SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS to allow tuning double-click sensitivity. Also increased the default double-click radius to 32 pixels to be more forgiving for touch interfaces
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 07a9113..3f6653b 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -263,6 +263,16 @@ extern "C" {
#define SDL_HINT_GRAB_KEYBOARD "SDL_GRAB_KEYBOARD"
/**
+ * \brief A variable setting the double click time, in milliseconds.
+ */
+#define SDL_HINT_MOUSE_DOUBLE_CLICK_TIME "SDL_MOUSE_DOUBLE_CLICK_TIME"
+
+/**
+ * \brief A variable setting the double click radius, in pixels.
+ */
+#define SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS "SDL_MOUSE_DOUBLE_CLICK_RADIUS"
+
+/**
* \brief A variable setting the speed scale for mouse motion, in floating point, when the mouse is not in relative mode
*/
#define SDL_HINT_MOUSE_NORMAL_SPEED_SCALE "SDL_MOUSE_NORMAL_SPEED_SCALE"
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index 55d248e..ff23c5e 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -33,13 +33,39 @@
/* The mouse state */
static SDL_Mouse SDL_mouse;
-static Uint32 SDL_double_click_time = 500;
-static int SDL_double_click_radius = 1;
static int
SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y);
static void SDLCALL
+SDL_MouseDoubleClickTimeChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+ SDL_Mouse *mouse = (SDL_Mouse *)userdata;
+
+ if (hint && *hint) {
+ mouse->double_click_time = SDL_atoi(hint);
+ } else {
+#ifdef __WIN32__
+ mouse->double_click_time = GetDoubleClickTime();
+#else
+ mouse->double_click_time = 500;
+#endif
+ }
+}
+
+static void SDLCALL
+SDL_MouseDoubleClickRadiusChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+ SDL_Mouse *mouse = (SDL_Mouse *)userdata;
+
+ if (hint && *hint) {
+ mouse->double_click_radius = SDL_atoi(hint);
+ } else {
+ mouse->double_click_radius = 32; /* 32 pixels seems about right for touch interfaces */
+ }
+}
+
+static void SDLCALL
SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
SDL_Mouse *mouse = (SDL_Mouse *)userdata;
@@ -83,6 +109,12 @@ SDL_MouseInit(void)
SDL_zerop(mouse);
+ SDL_AddHintCallback(SDL_HINT_MOUSE_DOUBLE_CLICK_TIME,
+ SDL_MouseDoubleClickTimeChanged, mouse);
+
+ SDL_AddHintCallback(SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS,
+ SDL_MouseDoubleClickRadiusChanged, mouse);
+
SDL_AddHintCallback(SDL_HINT_MOUSE_NORMAL_SPEED_SCALE,
SDL_MouseNormalSpeedScaleChanged, mouse);
@@ -114,12 +146,6 @@ SDL_GetMouse(void)
return &SDL_mouse;
}
-void
-SDL_SetDoubleClickTime(Uint32 interval)
-{
- SDL_double_click_time = interval;
-}
-
SDL_Window *
SDL_GetMouseFocus(void)
{
@@ -454,9 +480,9 @@ SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state
if (state == SDL_PRESSED) {
Uint32 now = SDL_GetTicks();
- if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + SDL_double_click_time) ||
- SDL_abs(mouse->x - clickstate->last_x) > SDL_double_click_radius ||
- SDL_abs(mouse->y - clickstate->last_y) > SDL_double_click_radius) {
+ if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + mouse->double_click_time) ||
+ SDL_abs(mouse->x - clickstate->last_x) > mouse->double_click_radius ||
+ SDL_abs(mouse->y - clickstate->last_y) > mouse->double_click_radius) {
clickstate->click_count = 0;
}
clickstate->last_timestamp = now;
diff --git a/src/events/SDL_mouse_c.h b/src/events/SDL_mouse_c.h
index 28089e0..ad44492 100644
--- a/src/events/SDL_mouse_c.h
+++ b/src/events/SDL_mouse_c.h
@@ -90,6 +90,8 @@ typedef struct
float relative_speed_scale;
float scale_accum_x;
float scale_accum_y;
+ Uint32 double_click_time;
+ int double_click_radius;
SDL_bool touch_mouse_events;
/* Data for double-click tracking */
@@ -112,9 +114,6 @@ extern int SDL_MouseInit(void);
/* Get the mouse state structure */
SDL_Mouse *SDL_GetMouse(void);
-/* Set the default double-click interval */
-extern void SDL_SetDoubleClickTime(Uint32 interval);
-
/* Set the default mouse cursor */
extern void SDL_SetDefaultCursor(SDL_Cursor * cursor);
diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c
index 1ddeae2..eff3160 100644
--- a/src/video/windows/SDL_windowsmouse.c
+++ b/src/video/windows/SDL_windowsmouse.c
@@ -304,8 +304,6 @@ WIN_InitMouse(_THIS)
mouse->GetGlobalMouseState = WIN_GetGlobalMouseState;
SDL_SetDefaultCursor(WIN_CreateDefaultCursor());
-
- SDL_SetDoubleClickTime(GetDoubleClickTime());
}
void