From 4d2c3a547b90578367f949d380042c5a66122e4b Mon Sep 17 00:00:00 2001 From: Quinten Lansu Date: Tue, 17 Apr 2012 13:21:45 +0200 Subject: [PATCH 01/11] Begin adapting touch patch --- README.md | 1 + include/GLFW/glfw3.h | 52 ++++++++++++++++++++++++++++++++++++++++ src/cocoa_window.m | 4 ++++ src/input.c | 45 ++++++++++++++++++++++++++++++++++ src/internal.h | 28 ++++++++++++++++++++++ src/win32_window.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ src/x11_window.c | 4 ++++ tests/events.c | 11 +++++++++ 8 files changed, 202 insertions(+) diff --git a/README.md b/README.md index 0213356e6..1962ffc6a 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ skills. - Cameron King - Peter Knut - Eric Larson + - Quinten Lansu - Robin Leffmann - Glenn Lewis - Shane Liesegang diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 1348785eb..c13c155ce 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -656,6 +656,7 @@ extern "C" { #define GLFW_CURSOR 0x00033001 #define GLFW_STICKY_KEYS 0x00033002 #define GLFW_STICKY_MOUSE_BUTTONS 0x00033003 +#define GLFW_TOUCH 0x00030004 #define GLFW_CURSOR_NORMAL 0x00034001 #define GLFW_CURSOR_HIDDEN 0x00034002 @@ -979,6 +980,27 @@ typedef void (* GLFWcharmodsfun)(GLFWwindow*,unsigned int,int); */ typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**); +/*! @brief The function signature for touch start/end callbacks. + * @param[in] window The window that received the event. + * @param[in] touch The touch that started or ended. + * @param[in] action One of @ref GLFW_PRESS or @ref GLFW_RELEASE. + * @ingroup input + * + * @sa glfwSetTouchCallback + */ +typedef void (* GLFWtouchfun)(GLFWwindow*,int,int); + +/*! @brief The function signature for touch position callbacks. + * @param[in] window The window that received the event. + * @param[in] touch The touch that moved. + * @param[in] xpos The new x-coordinate of the touch. + * @param[in] ypos The new y-coordinate of the touch. + * @ingroup input + * + * @sa glfwSetTouchPosCallback + */ +typedef void (* GLFWtouchposfun)(GLFWwindow*,int,double,double); + /*! @brief The function signature for monitor configuration callbacks. * * This is the function signature for monitor configuration callback functions. @@ -3042,6 +3064,36 @@ GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun cb */ GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun); +/*! @brief Sets the touch start/end callback. + * + * This function sets the touch callback, which is called when a touch is + * started or ended. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new scroll callback, or `NULL` to remove the currently + * set callback. + * @return The previously set callback, or `NULL` if no callback was set or an + * error occurred. + * + * @ingroup input + */ +GLFWAPI GLFWtouchfun glfwSetTouchCallback(GLFWwindow* window, GLFWtouchfun cbfun); + +/*! @brief Sets the touch position callback. + * + * This function sets the touch position callback, which is called when a touch + * moves. + * + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new scroll callback, or `NULL` to remove the currently + * set callback. + * @return The previously set callback, or `NULL` if no callback was set or an + * error occurred. + * + * @ingroup input + */ +GLFWAPI GLFWtouchposfun glfwSetTouchPosCallback(GLFWwindow* window, GLFWtouchposfun cbfun); + /*! @brief Returns whether the specified joystick is present. * * This function returns whether the specified joystick is present. diff --git a/src/cocoa_window.m b/src/cocoa_window.m index a3527e39e..5173ca318 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1162,6 +1162,10 @@ void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos) *ypos = contentRect.size.height - pos.y - 1; } +void _glfwPlatformSetTouchInput(_GLFWwindow* window, int enabled) +{ +} + void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y) { _glfwPlatformSetCursorMode(window, window->cursorMode); diff --git a/src/input.c b/src/input.c index b1aaaa9ea..7997ddac0 100644 --- a/src/input.c +++ b/src/input.c @@ -126,6 +126,18 @@ static void setStickyMouseButtons(_GLFWwindow* window, int enabled) window->stickyMouseButtons = enabled; } +// Set touch input for the specified window +// +static void setTouchInput(_GLFWwindow* window, int enabled) +{ + if (window->touchInput == enabled) + return; + + _glfwPlatformSetTouchInput(window, enabled); + + window->touchInput = enabled; +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW event API ////// @@ -222,6 +234,18 @@ void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths) window->callbacks.drop((GLFWwindow*) window, count, paths); } +void _glfwInputTouch(_GLFWwindow* window, int touch, int action) +{ + if (window->callbacks.touch) + window->callbacks.touch((GLFWwindow*) window, touch, action); +} + +void _glfwInputTouchPos(_GLFWwindow* window, int touch, double xpos, double ypos) +{ + if (window->callbacks.touchPos) + window->callbacks.touchPos((GLFWwindow*) window, touch, xpos, ypos); +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW public API ////// @@ -241,6 +265,8 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* handle, int mode) return window->stickyKeys; case GLFW_STICKY_MOUSE_BUTTONS: return window->stickyMouseButtons; + case GLFW_TOUCH: + return window->touchInput; default: _glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode"); return 0; @@ -264,6 +290,9 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value) case GLFW_STICKY_MOUSE_BUTTONS: setStickyMouseButtons(window, value ? GLFW_TRUE : GLFW_FALSE); break; + case GLFW_TOUCH: + setTouchInput(window, value ? GLFW_TRUE : GLFW_FALSE); + break; default: _glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode"); break; @@ -579,6 +608,22 @@ GLFWAPI const char* glfwGetJoystickName(int joy) return _glfwPlatformGetJoystickName(joy); } +GLFWAPI GLFWtouchfun glfwSetTouchCallback(GLFWwindow* handle, GLFWtouchfun cbfun) +{ + _GLFWwindow* window = (_GLFWwindow*) handle; + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + _GLFW_SWAP_POINTERS(window->callbacks.touch, cbfun); + return cbfun; +} + +GLFWAPI GLFWtouchposfun glfwSetTouchPosCallback(GLFWwindow* handle, GLFWtouchposfun cbfun) +{ + _GLFWwindow* window = (_GLFWwindow*) handle; + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + _GLFW_SWAP_POINTERS(window->callbacks.touchPos, cbfun); + return cbfun; +} + GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string) { _GLFWwindow* window = (_GLFWwindow*) handle; diff --git a/src/internal.h b/src/internal.h index 56647a31c..02bdf40b3 100644 --- a/src/internal.h +++ b/src/internal.h @@ -253,6 +253,7 @@ struct _GLFWwindow // Window input state GLFWbool stickyKeys; GLFWbool stickyMouseButtons; + GLFWbool touchInput; double cursorPosX, cursorPosY; int cursorMode; char mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1]; @@ -289,6 +290,8 @@ struct _GLFWwindow GLFWcharfun character; GLFWcharmodsfun charmods; GLFWdropfun drop; + GLFWtouchfun touch; + GLFWtouchposfun touchPos; } callbacks; // This is defined in the window API's platform.h @@ -406,6 +409,14 @@ void _glfwPlatformTerminate(void); */ const char* _glfwPlatformGetVersionString(void); +/*! @brief Sets whether touch input is enabled for the specified window. + * @param[in] window The window whose touch input status to change. + * @param[in] enabled @c GL_TRUE to enable touch input, or @c GL_FALSE to + * disable it. + * @ingroup platform + */ +void _glfwPlatformSetTouchInput(_GLFWwindow* window, int enabled); + /*! @copydoc glfwGetCursorPos * @ingroup platform */ @@ -774,6 +785,23 @@ void _glfwInputCursorMotion(_GLFWwindow* window, double x, double y); */ void _glfwInputCursorEnter(_GLFWwindow* window, int entered); +/*! @brief Notifies shared code of a touch start/end event. + * @param[in] window The window that received the event. + * @param[in] touch The touch that started or ended. + * @param[in] action One of @c GLFW_PRESS or @c GLFW_RELEASE. + * @ingroup event + */ +void _glfwInputTouch(_GLFWwindow* window, int touch, int action); + +/*! @brief Notifies shared code of a touch movement event. + * @param[in] window The window that received the event. + * @param[in] touch The touch that moved. + * @param[in] xpos The new x-coordinate of the touch. + * @param[in] ypos The new y-coordinate of the touch. + * @ingroup event + */ +void _glfwInputTouchPos(_GLFWwindow* window, int touch, double xpos, double ypos); + /*! @ingroup event */ void _glfwInputMonitorChange(void); diff --git a/src/win32_window.c b/src/win32_window.c index 2f2db36e2..e44d82679 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -584,6 +584,55 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, return 0; } + case WM_TOUCH: + { + TOUCHINPUT* inputs; + UINT count = LOWORD(wParam); + + inputs = (TOUCHINPUT*) malloc(sizeof(TOUCHINPUT) * count); + + if (GetTouchInputInfo((HTOUCHINPUT) lParam, + count, inputs, sizeof(TOUCHINPUT))) + { + int i, width, height; + + _glfwPlatformGetWindowSize(window, &width, &height); + + for (i = 0; i < count; i++) + { + POINT pos; + + // Discard any points that lie outside of the client area + + pos.x = TOUCH_COORD_TO_PIXEL(inputs[i].x); + pos.y = TOUCH_COORD_TO_PIXEL(inputs[i].y); + ScreenToClient(window->win32.handle, &pos); + + if (pos.x < 0 || pos.x >= width || + pos.y < 0 || pos.y >= height) + { + continue; + } + + if (inputs[i].dwFlags & TOUCHEVENTF_DOWN) + _glfwInputTouch(window, (int) inputs[i].dwID, GLFW_PRESS); + else if (inputs[i].dwFlags & TOUCHEVENTF_UP) + _glfwInputTouch(window, (int) inputs[i].dwID, GLFW_RELEASE); + else if (inputs[i].dwFlags & TOUCHEVENTF_MOVE) + { + _glfwInputTouchPos(window, (int) inputs[i].dwID, + inputs[i].x / 100.0, + inputs[i].y / 100.0); + } + } + + CloseTouchInputHandle((HTOUCHINPUT) lParam); + } + + free(inputs); + break; + } + case WM_PAINT: { _glfwInputWindowDamage(window); @@ -1138,6 +1187,14 @@ void _glfwPlatformPostEmptyEvent(void) PostMessage(window->win32.handle, WM_NULL, 0, 0); } +void _glfwPlatformSetTouchInput(_GLFWwindow* window, int enabled) +{ + if (enabled) + RegisterTouchWindow(window->win32.handle, 0); + else + UnregisterTouchWindow(window->win32.handle); +} + void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos) { POINT pos; diff --git a/src/x11_window.c b/src/x11_window.c index 147ef7b64..193ee64dd 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1871,6 +1871,10 @@ void _glfwPlatformPostEmptyEvent(void) XFlush(_glfw.x11.display); } +void _glfwPlatformSetTouchInput(_GLFWwindow* window, int enabled) +{ +} + void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos) { Window root, child; diff --git a/tests/events.c b/tests/events.c index 1da8341b4..94e35a370 100644 --- a/tests/events.c +++ b/tests/events.c @@ -438,6 +438,16 @@ static void monitor_callback(GLFWmonitor* monitor, int event) } } +static void touch_callback(GLFWwindow* window, int touch, int action, double x, double y) +{ + printf("%08x at %0.3f: Touch %i %s at %0.3f %0.3f\n", + counter++, + glfwGetTime(), + touch, + get_action_name(action), + x, y); +} + int main(int argc, char** argv) { Slot* slots; @@ -551,6 +561,7 @@ int main(int argc, char** argv) glfwSetCharCallback(slots[i].window, char_callback); glfwSetCharModsCallback(slots[i].window, char_mods_callback); glfwSetDropCallback(slots[i].window, drop_callback); + glfwSetTouchCallback(slots[i].window, touch_callback); glfwMakeContextCurrent(slots[i].window); gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); From 036d70cdb81c9a428363e6f6252e9b94104ab6e1 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 17 Apr 2012 21:11:31 +0200 Subject: [PATCH 02/11] Add dynamic loading of Win32 touch API --- src/win32_init.c | 16 ++++++++++++++++ src/win32_platform.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/win32_window.c | 19 +++++++++++++------ tests/events.c | 15 ++++++++++++--- 4 files changed, 85 insertions(+), 9 deletions(-) mode change 100644 => 100755 src/win32_platform.h diff --git a/src/win32_init.c b/src/win32_init.c index cd749b40a..da3e14172 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -89,6 +89,22 @@ static GLFWbool initLibraries(void) GetProcAddress(_glfw.win32.user32.instance, "SetProcessDPIAware"); _glfw.win32.user32.ChangeWindowMessageFilterEx = (CHANGEWINDOWMESSAGEFILTEREX_T) GetProcAddress(_glfw.win32.user32.instance, "ChangeWindowMessageFilterEx"); + _glfw.win32.user32.GetTouchInputInfo = (GETTOUCHINPUTINFO_T) + GetProcAddress(_glfw.win32.user32.instance, "GetTouchInputInfo"); + _glfw.win32.user32.CloseTouchInputHandle = (CLOSETOUCHINPUTHANDLE_T) + GetProcAddress(_glfw.win32.user32.instance, "CloseTouchInputHandle"); + _glfw.win32.user32.RegisterTouchWindow = (REGISTERTOUCHWINDOW_T) + GetProcAddress(_glfw.win32.user32.instance, "RegisterTouchWindow"); + _glfw.win32.user32.UnregisterTouchWindow = (UNREGISTERTOUCHWINDOW_T) + GetProcAddress(_glfw.win32.user32.instance, "UnregisterTouchWindow"); + + if (_glfw.win32.user32.GetTouchInputInfo && + _glfw.win32.user32.CloseTouchInputHandle && + _glfw.win32.user32.RegisterTouchWindow && + _glfw.win32.user32.UnregisterTouchWindow) + { + _glfw.win32.touch.available = GLFW_TRUE; + } _glfw.win32.dwmapi.instance = LoadLibraryW(L"dwmapi.dll"); if (_glfw.win32.dwmapi.instance) diff --git a/src/win32_platform.h b/src/win32_platform.h old mode 100644 new mode 100755 index 0068fbe20..d64c21771 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -99,6 +99,34 @@ typedef struct tagCHANGEFILTERSTRUCT #endif #endif /*Windows 7*/ +#if WINVER < 0x0601 + +#define WM_TOUCH 0x0240 + +DECLARE_HANDLE(HTOUCHINPUT); + +typedef struct tagTOUCHINPUT +{ + LONG x; + LONG y; + HANDLE hSource; + DWORD dwID; + DWORD dwFlags; + DWORD dwMask; + DWORD dwTime; + ULONG_PTR dwExtraInfo; + DWORD cxContact; + DWORD cyContext; +} TOUCHINPUT, *PTOUCHINPUT; + +#define TOUCH_COORD_TO_PIXEL(x) ((x) / 100) + +#define TOUCHEVENTF_MOVE 0x0001 +#define TOUCHEVENTF_DOWN 0x0002 +#define TOUCHEVENTF_UP 0x0004 + +#endif /*WINVER < 0x0601*/ + // winmm.dll function pointer typedefs typedef MMRESULT (WINAPI * JOYGETDEVCAPS_T)(UINT,LPJOYCAPS,UINT); typedef MMRESULT (WINAPI * JOYGETPOS_T)(UINT,LPJOYINFO); @@ -112,8 +140,16 @@ typedef DWORD (WINAPI * TIMEGETTIME_T)(void); // user32.dll function pointer typedefs typedef BOOL (WINAPI * SETPROCESSDPIAWARE_T)(void); typedef BOOL (WINAPI * CHANGEWINDOWMESSAGEFILTEREX_T)(HWND,UINT,DWORD,PCHANGEFILTERSTRUCT); +typedef BOOL (WINAPI * GETTOUCHINPUTINFO_T)(HTOUCHINPUT,UINT,PTOUCHINPUT,int); +typedef BOOL (WINAPI * CLOSETOUCHINPUTHANDLE_T)(HTOUCHINPUT); +typedef BOOL (WINAPI * REGISTERTOUCHWINDOW_T)(HWND,LONG); +typedef BOOL (WINAPI * UNREGISTERTOUCHWINDOW_T)(HWND); #define _glfw_SetProcessDPIAware _glfw.win32.user32.SetProcessDPIAware #define _glfw_ChangeWindowMessageFilterEx _glfw.win32.user32.ChangeWindowMessageFilterEx +#define _glfw_GetTouchInputInfo _glfw.win32.user32.GetTouchInputInfo +#define _glfw_CloseTouchInputHandle _glfw.win32.user32.CloseTouchInputHandle +#define _glfw_RegisterTouchWindow _glfw.win32.user32.RegisterTouchWindow +#define _glfw_UnregisterTouchWindow _glfw.win32.user32.UnregisterTouchWindow // dwmapi.dll function pointer typedefs typedef HRESULT (WINAPI * DWMISCOMPOSITIONENABLED_T)(BOOL*); @@ -186,8 +222,16 @@ typedef struct _GLFWlibraryWin32 HINSTANCE instance; SETPROCESSDPIAWARE_T SetProcessDPIAware; CHANGEWINDOWMESSAGEFILTEREX_T ChangeWindowMessageFilterEx; + GETTOUCHINPUTINFO_T GetTouchInputInfo; + CLOSETOUCHINPUTHANDLE_T CloseTouchInputHandle; + REGISTERTOUCHWINDOW_T RegisterTouchWindow; + UNREGISTERTOUCHWINDOW_T UnregisterTouchWindow; } user32; + struct { + GLFWbool available; + } touch; + // dwmapi.dll struct { HINSTANCE instance; diff --git a/src/win32_window.c b/src/win32_window.c index e44d82679..26b67229a 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -589,12 +589,16 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, TOUCHINPUT* inputs; UINT count = LOWORD(wParam); + if (!_glfw.win32.touch.available) + return 0; + inputs = (TOUCHINPUT*) malloc(sizeof(TOUCHINPUT) * count); - if (GetTouchInputInfo((HTOUCHINPUT) lParam, - count, inputs, sizeof(TOUCHINPUT))) + if (_glfw_GetTouchInputInfo((HTOUCHINPUT) lParam, + count, inputs, sizeof(TOUCHINPUT))) { - int i, width, height; + UINT i; + int width, height; _glfwPlatformGetWindowSize(window, &width, &height); @@ -626,7 +630,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, } } - CloseTouchInputHandle((HTOUCHINPUT) lParam); + _glfw_CloseTouchInputHandle((HTOUCHINPUT) lParam); } free(inputs); @@ -1189,10 +1193,13 @@ void _glfwPlatformPostEmptyEvent(void) void _glfwPlatformSetTouchInput(_GLFWwindow* window, int enabled) { + if (!_glfw.win32.touch.available) + return; + if (enabled) - RegisterTouchWindow(window->win32.handle, 0); + _glfw_RegisterTouchWindow(window->win32.handle, 0); else - UnregisterTouchWindow(window->win32.handle); + _glfw_UnregisterTouchWindow(window->win32.handle); } void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos) diff --git a/tests/events.c b/tests/events.c index 94e35a370..e63606bcf 100644 --- a/tests/events.c +++ b/tests/events.c @@ -438,13 +438,21 @@ static void monitor_callback(GLFWmonitor* monitor, int event) } } -static void touch_callback(GLFWwindow* window, int touch, int action, double x, double y) +static void touch_callback(GLFWwindow* window, int touch, int action) { - printf("%08x at %0.3f: Touch %i %s at %0.3f %0.3f\n", + printf("%08x at %0.3f: Touch %i %s\n", + counter++, + glfwGetTime(), + touch, + get_action_name(action)); +} + +static void touch_pos_callback(GLFWwindow* window, int touch, double x, double y) +{ + printf("%08x at %0.3f: Touch %i position: %0.3f %0.3f\n", counter++, glfwGetTime(), touch, - get_action_name(action), x, y); } @@ -562,6 +570,7 @@ int main(int argc, char** argv) glfwSetCharModsCallback(slots[i].window, char_mods_callback); glfwSetDropCallback(slots[i].window, drop_callback); glfwSetTouchCallback(slots[i].window, touch_callback); + glfwSetTouchPosCallback(slots[i].window, touch_pos_callback); glfwMakeContextCurrent(slots[i].window); gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); From b3e015d212354231441b4bbb106bc734d56440ea Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 18 Apr 2012 12:45:01 +0200 Subject: [PATCH 03/11] Add touch input toggling to events test --- tests/events.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/events.c b/tests/events.c index e63606bcf..bf7fe962e 100644 --- a/tests/events.c +++ b/tests/events.c @@ -50,6 +50,7 @@ typedef struct GLFWwindow* window; int number; int closeable; + int touch; } Slot; static void usage(void) @@ -372,6 +373,15 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action, switch (key) { + case GLFW_KEY_T: + { + slot->touch = !slot->touch; + glfwSetInputMode(window, GLFW_TOUCH, slot->touch); + + printf("(( touch %s ))\n", slot->touch ? "enabled" : "disabled"); + break; + } + case GLFW_KEY_C: { slot->closeable = !slot->closeable; @@ -526,6 +536,7 @@ int main(int argc, char** argv) char title[128]; slots[i].closeable = GLFW_TRUE; + slots[i].touch = GLFW_FALSE; slots[i].number = i + 1; sprintf(title, "Event Linter (Window %i)", slots[i].number); From b55db82f09b5aebde0b4c878915a0a8b67cce728 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 25 Apr 2012 23:56:21 +0200 Subject: [PATCH 04/11] Fix translation of Win32 touch positions --- src/win32_window.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/win32_window.c b/src/win32_window.c index 26b67229a..348764040 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -598,20 +598,18 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, count, inputs, sizeof(TOUCHINPUT))) { UINT i; - int width, height; + int width, height, xpos, ypos; _glfwPlatformGetWindowSize(window, &width, &height); + _glfwPlatformGetWindowPos(window, &xpos, &ypos); for (i = 0; i < count; i++) { POINT pos; + pos.x = TOUCH_COORD_TO_PIXEL(inputs[i].x) - xpos; + pos.y = TOUCH_COORD_TO_PIXEL(inputs[i].y) - ypos; // Discard any points that lie outside of the client area - - pos.x = TOUCH_COORD_TO_PIXEL(inputs[i].x); - pos.y = TOUCH_COORD_TO_PIXEL(inputs[i].y); - ScreenToClient(window->win32.handle, &pos); - if (pos.x < 0 || pos.x >= width || pos.y < 0 || pos.y >= height) { @@ -625,8 +623,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, else if (inputs[i].dwFlags & TOUCHEVENTF_MOVE) { _glfwInputTouchPos(window, (int) inputs[i].dwID, - inputs[i].x / 100.0, - inputs[i].y / 100.0); + inputs[i].x / 100.0 - xpos, + inputs[i].y / 100.0 - ypos); } } From 9301f33d6fc0191589a9f7aa62701f78bf56bc73 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 25 Apr 2012 23:56:56 +0200 Subject: [PATCH 05/11] Add position to touch press and release events --- src/win32_window.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/win32_window.c b/src/win32_window.c index 348764040..264895783 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -618,14 +618,18 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, if (inputs[i].dwFlags & TOUCHEVENTF_DOWN) _glfwInputTouch(window, (int) inputs[i].dwID, GLFW_PRESS); - else if (inputs[i].dwFlags & TOUCHEVENTF_UP) - _glfwInputTouch(window, (int) inputs[i].dwID, GLFW_RELEASE); - else if (inputs[i].dwFlags & TOUCHEVENTF_MOVE) + + if (inputs[i].dwFlags & TOUCHEVENTF_DOWN || + inputs[i].dwFlags & TOUCHEVENTF_UP || + inputs[i].dwFlags & TOUCHEVENTF_MOVE) { _glfwInputTouchPos(window, (int) inputs[i].dwID, inputs[i].x / 100.0 - xpos, inputs[i].y / 100.0 - ypos); } + + if (inputs[i].dwFlags & TOUCHEVENTF_UP) + _glfwInputTouch(window, (int) inputs[i].dwID, GLFW_RELEASE); } _glfw_CloseTouchInputHandle((HTOUCHINPUT) lParam); From 2687622e8dadf6abd67281de9eba9a83dda820e8 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 24 Feb 2013 17:54:35 +0100 Subject: [PATCH 06/11] Simplify touch API --- include/GLFW/glfw3.h | 52 ++++++++++++++------------------------------ src/input.c | 20 +++-------------- src/internal.h | 12 ++-------- src/win32_window.c | 23 ++++++++++---------- tests/events.c | 17 +++++---------- 5 files changed, 37 insertions(+), 87 deletions(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index c13c155ce..886544bbc 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -232,18 +232,18 @@ extern "C" { #define GLFW_FALSE 0 /*! @} */ -/*! @name Key and button actions +/*! @name Key, button and touch actions * @{ */ -/*! @brief The key or mouse button was released. +/*! @brief The key or button was released or the touch ended. * - * The key or mouse button was released. + * The key or button was released or the touch ended. * * @ingroup input */ #define GLFW_RELEASE 0 -/*! @brief The key or mouse button was pressed. +/*! @brief The key or button was pressed or the touch started. * - * The key or mouse button was pressed. + * The key or button was pressed or the touch started. * * @ingroup input */ @@ -255,6 +255,10 @@ extern "C" { * @ingroup input */ #define GLFW_REPEAT 2 +/*! @brief The touch was moved. + * @ingroup input + */ +#define GLFW_MOVE 3 /*! @} */ /*! @defgroup keys Keyboard keys @@ -980,26 +984,17 @@ typedef void (* GLFWcharmodsfun)(GLFWwindow*,unsigned int,int); */ typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**); -/*! @brief The function signature for touch start/end callbacks. +/*! @brief The function signature for touch callbacks. * @param[in] window The window that received the event. - * @param[in] touch The touch that started or ended. - * @param[in] action One of @ref GLFW_PRESS or @ref GLFW_RELEASE. - * @ingroup input - * - * @sa glfwSetTouchCallback - */ -typedef void (* GLFWtouchfun)(GLFWwindow*,int,int); - -/*! @brief The function signature for touch position callbacks. - * @param[in] window The window that received the event. - * @param[in] touch The touch that moved. + * @param[in] touch The touch that triggered the event. + * @param[in] action One of @ref GLFW_PRESS, @c GLFW_MOVE or @ref GLFW_RELEASE. * @param[in] xpos The new x-coordinate of the touch. * @param[in] ypos The new y-coordinate of the touch. * @ingroup input * - * @sa glfwSetTouchPosCallback + * @sa glfwSetTouchCallback */ -typedef void (* GLFWtouchposfun)(GLFWwindow*,int,double,double); +typedef void (* GLFWtouchfun)(GLFWwindow*,int,int,double,double); /*! @brief The function signature for monitor configuration callbacks. * @@ -3064,10 +3059,10 @@ GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun cb */ GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun); -/*! @brief Sets the touch start/end callback. +/*! @brief Sets the touch callback. * * This function sets the touch callback, which is called when a touch is - * started or ended. + * started, ended or moved. * * @param[in] window The window whose callback to set. * @param[in] cbfun The new scroll callback, or `NULL` to remove the currently @@ -3079,21 +3074,6 @@ GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun); */ GLFWAPI GLFWtouchfun glfwSetTouchCallback(GLFWwindow* window, GLFWtouchfun cbfun); -/*! @brief Sets the touch position callback. - * - * This function sets the touch position callback, which is called when a touch - * moves. - * - * @param[in] window The window whose callback to set. - * @param[in] cbfun The new scroll callback, or `NULL` to remove the currently - * set callback. - * @return The previously set callback, or `NULL` if no callback was set or an - * error occurred. - * - * @ingroup input - */ -GLFWAPI GLFWtouchposfun glfwSetTouchPosCallback(GLFWwindow* window, GLFWtouchposfun cbfun); - /*! @brief Returns whether the specified joystick is present. * * This function returns whether the specified joystick is present. diff --git a/src/input.c b/src/input.c index 7997ddac0..8773e2f2f 100644 --- a/src/input.c +++ b/src/input.c @@ -33,7 +33,7 @@ #endif // Internal key state used for sticky keys -#define _GLFW_STICK 3 +#define _GLFW_STICK 4 // Sets the cursor mode for the specified window @@ -234,16 +234,10 @@ void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths) window->callbacks.drop((GLFWwindow*) window, count, paths); } -void _glfwInputTouch(_GLFWwindow* window, int touch, int action) +void _glfwInputTouch(_GLFWwindow* window, int touch, int action, double xpos, double ypos) { if (window->callbacks.touch) - window->callbacks.touch((GLFWwindow*) window, touch, action); -} - -void _glfwInputTouchPos(_GLFWwindow* window, int touch, double xpos, double ypos) -{ - if (window->callbacks.touchPos) - window->callbacks.touchPos((GLFWwindow*) window, touch, xpos, ypos); + window->callbacks.touch((GLFWwindow*) window, touch, action, xpos, ypos); } @@ -616,14 +610,6 @@ GLFWAPI GLFWtouchfun glfwSetTouchCallback(GLFWwindow* handle, GLFWtouchfun cbfun return cbfun; } -GLFWAPI GLFWtouchposfun glfwSetTouchPosCallback(GLFWwindow* handle, GLFWtouchposfun cbfun) -{ - _GLFWwindow* window = (_GLFWwindow*) handle; - _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - _GLFW_SWAP_POINTERS(window->callbacks.touchPos, cbfun); - return cbfun; -} - GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string) { _GLFWwindow* window = (_GLFWwindow*) handle; diff --git a/src/internal.h b/src/internal.h index 02bdf40b3..6ca494eca 100644 --- a/src/internal.h +++ b/src/internal.h @@ -291,7 +291,6 @@ struct _GLFWwindow GLFWcharmodsfun charmods; GLFWdropfun drop; GLFWtouchfun touch; - GLFWtouchposfun touchPos; } callbacks; // This is defined in the window API's platform.h @@ -788,19 +787,12 @@ void _glfwInputCursorEnter(_GLFWwindow* window, int entered); /*! @brief Notifies shared code of a touch start/end event. * @param[in] window The window that received the event. * @param[in] touch The touch that started or ended. - * @param[in] action One of @c GLFW_PRESS or @c GLFW_RELEASE. - * @ingroup event - */ -void _glfwInputTouch(_GLFWwindow* window, int touch, int action); - -/*! @brief Notifies shared code of a touch movement event. - * @param[in] window The window that received the event. - * @param[in] touch The touch that moved. + * @param[in] action One of @c GLFW_PRESS, @c GLFW_MOVE or @c GLFW_RELEASE. * @param[in] xpos The new x-coordinate of the touch. * @param[in] ypos The new y-coordinate of the touch. * @ingroup event */ -void _glfwInputTouchPos(_GLFWwindow* window, int touch, double xpos, double ypos); +void _glfwInputTouch(_GLFWwindow* window, int touch, int action, double xpos, double ypos); /*! @ingroup event */ diff --git a/src/win32_window.c b/src/win32_window.c index 264895783..6c3a7cbb7 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -605,7 +605,9 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, for (i = 0; i < count; i++) { + int action; POINT pos; + pos.x = TOUCH_COORD_TO_PIXEL(inputs[i].x) - xpos; pos.y = TOUCH_COORD_TO_PIXEL(inputs[i].y) - ypos; @@ -617,19 +619,16 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, } if (inputs[i].dwFlags & TOUCHEVENTF_DOWN) - _glfwInputTouch(window, (int) inputs[i].dwID, GLFW_PRESS); + action = GLFW_PRESS; + else if (inputs[i].dwFlags & TOUCHEVENTF_UP) + action = GLFW_RELEASE; + else + action = GLFW_MOVE; - if (inputs[i].dwFlags & TOUCHEVENTF_DOWN || - inputs[i].dwFlags & TOUCHEVENTF_UP || - inputs[i].dwFlags & TOUCHEVENTF_MOVE) - { - _glfwInputTouchPos(window, (int) inputs[i].dwID, - inputs[i].x / 100.0 - xpos, - inputs[i].y / 100.0 - ypos); - } - - if (inputs[i].dwFlags & TOUCHEVENTF_UP) - _glfwInputTouch(window, (int) inputs[i].dwID, GLFW_RELEASE); + _glfwInputTouch(window, + (int) inputs[i].dwID, action, + inputs[i].x / 100.0 - xpos, + inputs[i].y / 100.0 - ypos); } _glfw_CloseTouchInputHandle((HTOUCHINPUT) lParam); diff --git a/tests/events.c b/tests/events.c index bf7fe962e..0324ef373 100644 --- a/tests/events.c +++ b/tests/events.c @@ -204,6 +204,8 @@ static const char* get_action_name(int action) return "released"; case GLFW_REPEAT: return "repeated"; + case GLFW_MOVE: + return "moved"; } return "caused unknown action"; @@ -448,21 +450,13 @@ static void monitor_callback(GLFWmonitor* monitor, int event) } } -static void touch_callback(GLFWwindow* window, int touch, int action) +static void touch_callback(GLFWwindow* window, int touch, int action, double x, double y) { - printf("%08x at %0.3f: Touch %i %s\n", - counter++, - glfwGetTime(), - touch, - get_action_name(action)); -} - -static void touch_pos_callback(GLFWwindow* window, int touch, double x, double y) -{ - printf("%08x at %0.3f: Touch %i position: %0.3f %0.3f\n", + printf("%08x at %0.3f: Touch %i %s at position %0.3f %0.3f\n", counter++, glfwGetTime(), touch, + get_action_name(action), x, y); } @@ -581,7 +575,6 @@ int main(int argc, char** argv) glfwSetCharModsCallback(slots[i].window, char_mods_callback); glfwSetDropCallback(slots[i].window, drop_callback); glfwSetTouchCallback(slots[i].window, touch_callback); - glfwSetTouchPosCallback(slots[i].window, touch_pos_callback); glfwMakeContextCurrent(slots[i].window); gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); From 14a18c8288c3c4f78e5013877340b74eb1ae50d5 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 18 Oct 2015 21:23:22 +0200 Subject: [PATCH 07/11] Apply bananas --- src/win32_window.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/win32_window.c b/src/win32_window.c index 6c3a7cbb7..bce141164 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -391,6 +391,13 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, { const int mods = getKeyMods(); + if (window->touchInput) + { + // Skip emulated button events when touch input is enabled + if ((GetMessageExtraInfo() & 0xffffff00) == 0xff515700) + break; + } + SetCapture(hWnd); if (uMsg == WM_LBUTTONDOWN) @@ -419,6 +426,13 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, { const int mods = getKeyMods(); + if (window->touchInput) + { + // Skip emulated button events when touch input is enabled + if ((GetMessageExtraInfo() & 0xffffff00) == 0xff515700) + break; + } + ReleaseCapture(); if (uMsg == WM_LBUTTONUP) @@ -473,7 +487,9 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, _glfwInputCursorEnter(window, GLFW_TRUE); } - return 0; + // NOTE: WM_MOUSEMOVE messages must be passed on to DefWindowProc + // for WM_TOUCH messages to be emitted + break; } case WM_MOUSELEAVE: From 99da7e171b0956abd7678edcb02cfd53af470ad6 Mon Sep 17 00:00:00 2001 From: eriksunden Date: Wed, 22 Feb 2017 19:35:47 +0100 Subject: [PATCH 08/11] Start on bundling touch points to only perform one callback per touch event. --- include/GLFW/glfw3.h | 28 +++++++++++++++++++++++++++- src/input.c | 8 +++++--- src/internal.h | 16 ++++++++-------- src/win32_window.c | 24 +++++++++++++++++++++--- tests/events.c | 4 ++-- 5 files changed, 63 insertions(+), 17 deletions(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index eeef38bb2..de22ee2e1 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -1103,7 +1103,33 @@ typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**); * * @sa glfwSetTouchCallback */ -typedef void (* GLFWtouchfun)(GLFWwindow*,int,int,double,double); +typedef void (* GLFWtouchfun)(GLFWwindow*, int, int, double, double); + +/*! @brief Touch point info. +* +* This describes the touch point info. +* +* @sa @ref touch +* +* @since Added in version 3.2.1 (touch branch) +* +* @ingroup touch +*/ +typedef struct GLFWtouch +{ + /*! Touch id + */ + int id; + /*! Touch action + */ + int action; + /*! X position + */ + double x; + /*! Y position + */ + double y; +} GLFWtouch; /*! @brief The function signature for monitor configuration callbacks. * diff --git a/src/input.c b/src/input.c index 47851e10b..e9fc3792f 100644 --- a/src/input.c +++ b/src/input.c @@ -135,11 +135,12 @@ void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths) window->callbacks.drop((GLFWwindow*) window, count, paths); } -void _glfwInputTouch(_GLFWwindow* window, int touch, int action, double xpos, double ypos) +void _glfwInputTouch(_GLFWwindow* window, int id, int action, double xpos, double ypos) { - if (window->callbacks.touch) - window->callbacks.touch((GLFWwindow*) window, touch, action, xpos, ypos); + if (window->callbacks.touch) + window->callbacks.touch((GLFWwindow*)window, id, action, xpos, ypos); } + void _glfwInputJoystickChange(int joy, int event) { if (_glfw.callbacks.joystick) @@ -621,6 +622,7 @@ GLFWAPI GLFWtouchfun glfwSetTouchCallback(GLFWwindow* handle, GLFWtouchfun cbfun _GLFWwindow* window = (_GLFWwindow*) handle; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.touch, cbfun); + setTouchInput(window, 1); return cbfun; } diff --git a/src/internal.h b/src/internal.h index 357894fe5..6a3c23406 100644 --- a/src/internal.h +++ b/src/internal.h @@ -926,14 +926,14 @@ void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos); void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered); /*! @brief Notifies shared code of a touch start/end event. - * @param[in] window The window that received the event. - * @param[in] touch The touch that started or ended. - * @param[in] action One of @c GLFW_PRESS, @c GLFW_MOVE or @c GLFW_RELEASE. - * @param[in] xpos The new x-coordinate of the touch. - * @param[in] ypos The new y-coordinate of the touch. - * @ingroup event - */ -void _glfwInputTouch(_GLFWwindow* window, int touch, int action, double xpos, double ypos); +* @param[in] window The window that received the event. +* @param[in] id Touch point id +* @param[in] action One of @c GLFW_PRESS, @c GLFW_MOVE or @c GLFW_RELEASE. +* @param[in] xpos The new x-coordinate of the touch. +* @param[in] ypos The new y-coordinate of the touch. +* @ingroup event +*/ +void _glfwInputTouch(_GLFWwindow* window, int id, int action, double xpos, double ypos); /*! @ingroup event */ diff --git a/src/win32_window.c b/src/win32_window.c index b4cd662a0..cd0b5f517 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -837,6 +837,12 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, _glfwPlatformGetWindowSize(window, &width, &height); _glfwPlatformGetWindowPos(window, &xpos, &ypos); + //Create storage + GLFWtouch* touchPoints = calloc(count, sizeof(GLFWtouch)); + + //Count valid points + int valid_count = 0; + for (i = 0; i < count; i++) { int action; @@ -856,16 +862,28 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, action = GLFW_PRESS; else if (inputs[i].dwFlags & TOUCHEVENTF_UP) action = GLFW_RELEASE; - else - action = GLFW_MOVE; + else if (inputs[i].dwFlags & TOUCHEVENTF_MOVE) + action = GLFW_MOVE; + else + action = GLFW_REPEAT; + + touchPoints[valid_count].id = (int)inputs[i].dwID; + touchPoints[valid_count].action = action; + touchPoints[valid_count].x = inputs[i].x / 100.0 - xpos; + touchPoints[valid_count].y = inputs[i].y / 100.0 - ypos; + + valid_count++; _glfwInputTouch(window, - (int) inputs[i].dwID, action, + (int) inputs[i].dwID, + action, inputs[i].x / 100.0 - xpos, inputs[i].y / 100.0 - ypos); } _glfw_CloseTouchInputHandle((HTOUCHINPUT) lParam); + + free(touchPoints); } free(inputs); diff --git a/tests/events.c b/tests/events.c index 0b3caa82a..621914dcb 100644 --- a/tests/events.c +++ b/tests/events.c @@ -486,12 +486,12 @@ static void joystick_callback(int joy, int event) } } -static void touch_callback(GLFWwindow* window, int touch, int action, double x, double y) +static void touch_callback(GLFWwindow* window, int id, int action, double x, double y) { printf("%08x at %0.3f: Touch %i %s at position %0.3f %0.3f\n", counter++, glfwGetTime(), - touch, + id, get_action_name(action), x, y); } From 685b3a91701e53e5fe466a42b197f7e7ca66c56c Mon Sep 17 00:00:00 2001 From: eriksunden Date: Wed, 22 Feb 2017 20:23:45 +0100 Subject: [PATCH 09/11] Bundling of touch points for one callback complete. --- include/GLFW/glfw3.h | 22 ++++++++++------------ src/input.c | 4 ++-- src/internal.h | 8 +++----- src/win32_window.c | 21 +++++++++------------ tests/events.c | 17 ++++++++++------- 5 files changed, 34 insertions(+), 38 deletions(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index de22ee2e1..f0fa13403 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -1093,18 +1093,6 @@ typedef void (* GLFWcharmodsfun)(GLFWwindow*,unsigned int,int); */ typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**); -/*! @brief The function signature for touch callbacks. - * @param[in] window The window that received the event. - * @param[in] touch The touch that triggered the event. - * @param[in] action One of @ref GLFW_PRESS, @c GLFW_MOVE or @ref GLFW_RELEASE. - * @param[in] xpos The new x-coordinate of the touch. - * @param[in] ypos The new y-coordinate of the touch. - * @ingroup input - * - * @sa glfwSetTouchCallback - */ -typedef void (* GLFWtouchfun)(GLFWwindow*, int, int, double, double); - /*! @brief Touch point info. * * This describes the touch point info. @@ -1131,6 +1119,16 @@ typedef struct GLFWtouch double y; } GLFWtouch; +/*! @brief The function signature for touch callbacks. +* @param[in] window The window that received the event. +* @param[in] touchPoints All valid touch points +* @param[in] count The number of valid touch points +* @ingroup event +* +* @sa glfwSetTouchCallback +*/ +typedef void(*GLFWtouchfun)(GLFWwindow*, GLFWtouch*, int); + /*! @brief The function signature for monitor configuration callbacks. * * This is the function signature for monitor configuration callback functions. diff --git a/src/input.c b/src/input.c index e9fc3792f..9f2d5bcca 100644 --- a/src/input.c +++ b/src/input.c @@ -135,10 +135,10 @@ void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths) window->callbacks.drop((GLFWwindow*) window, count, paths); } -void _glfwInputTouch(_GLFWwindow* window, int id, int action, double xpos, double ypos) +void _glfwInputTouch(_GLFWwindow* window, GLFWtouch* touchPoints, int count) { if (window->callbacks.touch) - window->callbacks.touch((GLFWwindow*)window, id, action, xpos, ypos); + window->callbacks.touch((GLFWwindow*)window, touchPoints, count); } void _glfwInputJoystickChange(int joy, int event) diff --git a/src/internal.h b/src/internal.h index 6a3c23406..726ad1409 100644 --- a/src/internal.h +++ b/src/internal.h @@ -927,13 +927,11 @@ void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered); /*! @brief Notifies shared code of a touch start/end event. * @param[in] window The window that received the event. -* @param[in] id Touch point id -* @param[in] action One of @c GLFW_PRESS, @c GLFW_MOVE or @c GLFW_RELEASE. -* @param[in] xpos The new x-coordinate of the touch. -* @param[in] ypos The new y-coordinate of the touch. +* @param[in] touchPoints All valid touch points +* @param[in] count The numer of valid touch points * @ingroup event */ -void _glfwInputTouch(_GLFWwindow* window, int id, int action, double xpos, double ypos); +void _glfwInputTouch(_GLFWwindow* window, GLFWtouch* touchPoints, int count); /*! @ingroup event */ diff --git a/src/win32_window.c b/src/win32_window.c index cd0b5f517..2549f8f18 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -841,7 +841,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, GLFWtouch* touchPoints = calloc(count, sizeof(GLFWtouch)); //Count valid points - int valid_count = 0; + int validCount = 0; for (i = 0; i < count; i++) { @@ -867,20 +867,17 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, else action = GLFW_REPEAT; - touchPoints[valid_count].id = (int)inputs[i].dwID; - touchPoints[valid_count].action = action; - touchPoints[valid_count].x = inputs[i].x / 100.0 - xpos; - touchPoints[valid_count].y = inputs[i].y / 100.0 - ypos; + touchPoints[validCount].id = (int)inputs[i].dwID; + touchPoints[validCount].action = action; + touchPoints[validCount].x = inputs[i].x / 100.0 - xpos; + touchPoints[validCount].y = inputs[i].y / 100.0 - ypos; - valid_count++; - - _glfwInputTouch(window, - (int) inputs[i].dwID, - action, - inputs[i].x / 100.0 - xpos, - inputs[i].y / 100.0 - ypos); + validCount++; } + if(validCount > 0) + _glfwInputTouch(window, touchPoints, validCount); + _glfw_CloseTouchInputHandle((HTOUCHINPUT) lParam); free(touchPoints); diff --git a/tests/events.c b/tests/events.c index 621914dcb..7e495305a 100644 --- a/tests/events.c +++ b/tests/events.c @@ -486,14 +486,17 @@ static void joystick_callback(int joy, int event) } } -static void touch_callback(GLFWwindow* window, int id, int action, double x, double y) +static void touch_callback(GLFWwindow* window, GLFWtouch* touchPoints, int count) { - printf("%08x at %0.3f: Touch %i %s at position %0.3f %0.3f\n", - counter++, - glfwGetTime(), - id, - get_action_name(action), - x, y); + printf("Priting info about all touch points"); + for (int i = 0; i < count; ++i) { + printf("%08x at %0.3f: Touch %i %s at position %0.3f %0.3f\n", + counter++, + glfwGetTime(), + touchPoints[i].id, + get_action_name(touchPoints[i].action), + touchPoints[i].x, touchPoints[i].y); + } } int main(int argc, char** argv) From a04232b3a14dae1e255eabac5ba98e957adb730c Mon Sep 17 00:00:00 2001 From: eriksunden Date: Thu, 23 Feb 2017 23:31:37 +0100 Subject: [PATCH 10/11] Before C99 fix. --- tests/events.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/events.c b/tests/events.c index 7e495305a..474a04795 100644 --- a/tests/events.c +++ b/tests/events.c @@ -489,7 +489,8 @@ static void joystick_callback(int joy, int event) static void touch_callback(GLFWwindow* window, GLFWtouch* touchPoints, int count) { printf("Priting info about all touch points"); - for (int i = 0; i < count; ++i) { + int i; + for (i = 0; i < count; ++i) { printf("%08x at %0.3f: Touch %i %s at position %0.3f %0.3f\n", counter++, glfwGetTime(), From 384d007326246a3ac2be7c1ee2e2cc991f549756 Mon Sep 17 00:00:00 2001 From: eriksunden Date: Fri, 18 May 2018 14:48:54 +0200 Subject: [PATCH 11/11] Added Wayland / MIR / Null window declaration of _glfwPlatformSetTouchInput --- src/mir_window.c | 4 ++++ src/null_window.c | 4 ++++ src/wl_window.c | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/mir_window.c b/src/mir_window.c index a0d17db2e..81ec0a091 100644 --- a/src/mir_window.c +++ b/src/mir_window.c @@ -713,6 +713,10 @@ void _glfwPlatformPostEmptyEvent(void) { } +void _glfwPlatformSetTouchInput(_GLFWwindow* window, int enabled) +{ +} + void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height) { if (width) diff --git a/src/null_window.c b/src/null_window.c index 6a54cfe56..6e9713754 100644 --- a/src/null_window.c +++ b/src/null_window.c @@ -248,6 +248,10 @@ void _glfwPlatformPostEmptyEvent(void) { } +void _glfwPlatformSetTouchInput(_GLFWwindow* window, int enabled) +{ +} + void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos) { } diff --git a/src/wl_window.c b/src/wl_window.c index c165ba73a..8212ca644 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1194,6 +1194,10 @@ void _glfwPlatformPostEmptyEvent(void) wl_display_sync(_glfw.wl.display); } +void _glfwPlatformSetTouchInput(_GLFWwindow* window, int enabled) +{ +} + void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos) { if (xpos)