-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add API for raw touch events (updated) #24610
base: master
Are you sure you want to change the base?
Conversation
a8a1e74
to
a7550a9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for bringing this up to date!
Globally this looks good to me and I'd definitely like to merge it for 3.3.0. I can address the minor comments I left myself, but if you could please do it, it would be even better, of course. I'd just like to ask you to use "fixup" commits (done by git commit --fixup
) instead of force-pushing your changes, as this makes seeing what exactly has been changed more difficult.
The only relatively important question I see here concerns wxTouchEventBase
: I'm just not sure if we really need it at all. It does save a tiny amount of duplication, but I don't think anybody is actually going to use it, i.e. handle gesture and raw touch events as objects of this class. Maybe we should remove it and just add position to wxMultiTouchEvent
itself too?
Thanks again!
samples/touchtest/touchtest.cpp
Outdated
wxMenu *file_menu = new wxMenu; | ||
|
||
file_menu->Append(wxID_EXIT); | ||
|
||
wxMenuBar *menu_bar = new wxMenuBar; | ||
|
||
menu_bar->Append(file_menu, wxT("&File")); | ||
SetMenuBar(menu_bar); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks rather useless and could be just removed IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turned out to be useful to check if the pos is relative to the client rect, not the window rect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe some options can be added later to the menu.
src/gtk/window.cpp
Outdated
event.SetSequenceId(wxTouchSequenceId(gdk_event->sequence)); | ||
event.SetPrimary(gdk_event->emulating_pointer); | ||
|
||
win->GTKProcessEvent(event); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it correct to ignore its return value here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we still call wxEmulateLeftDownEvent
/wxEmulateMotionEvent
/wxEmulateLeftUpEvent
, even if the touch event was handled?
Note that MSW sends synthesized mouse events regardless, so it would be consistent with MSW.
break; | ||
|
||
HandleTouch(wParam, lParam); | ||
// Let DefWindowProc handle the touch events too |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to explain why do we need it to always have them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value of processed
doesn't appear to have any effect here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no good reason to not use the usual logic, I'd stick to it. I.e. just do
processed = HandleTouch(wParam, lParam);
event.SetPosition(pos); | ||
event.SetSequenceId(wxTouchSequenceId(wxUIntToPtr(info[i].dwID + 1))); | ||
event.SetPrimary( (info[i].dwFlags & TOUCHEVENTF_PRIMARY) != 0 ); | ||
HandleWindowEvent(event); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we remember if any of the events were processed and only return true in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also seems to be still relevant.
Makes sense to me. |
While a finger is held for too long on MSW, activating the "right mouse buton" gesture, the OS doesn't synthesizing mouse down/move events. So might need to add a Also in Qt, the primary touch point detection is not available. |
Also in Qt, a |
On my GTK system, the mouse pointer emulation code from #2539 doesn't seem to be needed. If I return Current Could it be that the |
Another question is if the user app has handled the touch event, should we still emit mouse events synthesized by the OS or block them? |
It might be simplest to emit the synthesized mouse events anyway. |
If we return
There's a |
@dsa-t Do you plan to make more changes here? |
Another questions are:
|
What do the different OS provide to us, i.e. what type of coordinates they use?
I'm always in favour of using opaque types if possible. I'm still not sure what exactly is |
Logical pixels == DIPs on wxQt, so it would be most noticable on smartphones.
It's an arbitrary value to identify touch points. On wxMSW it's something like:
on wxQt on Windows it's something like:
On wxGTK, it's a |
Sorry, what I meant was whether it was integer or floating point?
Thanks for the explanation and the examples. If we really can't do anything with it, except comparing them, presumably, it should remain opaque and allow doing just this (and copying). |
on GTK, it's
on Qt, it's
on OSX, it's also a floating point type what wx rounds to int: https://developer.apple.com/documentation/appkit/nstouch/1534031-normalizedposition?language=objc |
In this case I agree that we should use doubles in wx API too. |
Some ports do not support drawing onto a wxClientDC.
Co-authored-by: VZ <vz-github@zeitlins.org>
Allows the user application to distinguish between real mouse events and events synthesized from touch events by the OS.
Some ports may not set this flag.
Changed position type to CI Error in |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates, I think this is pretty close to being merged, but I'd like to understand why do we need to pass the extra
argument everywhere in the MSW code instead of just getting it when needed. Do we really have to complicate things like this?
class wxTouchSequenceId : public wxItemId<void*> | ||
{ | ||
public: | ||
wxTouchSequenceId() : wxItemId<void*>() { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, but why not
wxTouchSequenceId() : wxItemId<void*>() { } | |
wxTouchSequenceId() = default; |
?
explicit wxTouchSequenceId(void* pItem) : wxItemId<void*>(pItem) { } | ||
}; | ||
|
||
class WXDLLIMPEXP_CORE wxMultiTouchEvent : public wxEvent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit surprised that this class is not associated with (e.g. by inheriting from it) wxKeyboardState
. Couldn't we have special handling for some touch events when Control (or Shift or whatever) is pressed etc?
inline wxPoint GetFloor() const; | ||
inline wxPoint GetRounded() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be added to interface/wx/geometry.h
too (which is quite empty, but still not completely useless, I guess...).
@@ -61,10 +61,10 @@ class wxWidgetCocoaNativeKeyDownSuspender | |||
public: | |||
// stops sending keydown events for text inserted into this widget | |||
explicit wxWidgetCocoaNativeKeyDownSuspender(wxWidgetCocoaImpl *target); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be really great to avoid mixing whitespace-only and significant changes. Please configure your editor/IDE to avoid automatically stripping existing whitespace on save.
@@ -368,10 +368,10 @@ class WXDLLIMPEXP_CORE wxWindowMSW : public wxWindowBase | |||
|
|||
bool HandleDropFiles(WXWPARAM wParam); | |||
|
|||
bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags); | |||
bool HandleMouseMove(int x, int y, WXUINT flags); | |||
bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags, WXLPARAM extraInfo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit annoying to pass this extraInfo
everywhere, can't we just call ::GetMessageExtraInfo()
when it's needed?
It's nice to consistently pass just the WPARAM/LPARAM to HandleXXX()
functions.
@@ -2809,7 +2809,7 @@ bool wxTextCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) | |||
int x = GET_X_LPARAM(msgf->lParam), | |||
y = GET_Y_LPARAM(msgf->lParam); | |||
|
|||
HandleMouseEvent(msg, x, y, flags); | |||
HandleMouseEvent(msg, x, y, flags, ::GetMessageExtraInfo()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes could be avoided if we called ::GetMessageExtraInfo()
in HandleMouseEvent()
itself too.
@@ -28,6 +28,7 @@ | |||
#include "wx/private/bmpbndl.h" | |||
|
|||
#include "wx/evtloop.h" | |||
#include "wx/vector.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just use <vector>
on master.
@@ -236,6 +236,27 @@ class GestureFuncs | |||
return ms_pfnSetGestureConfig; | |||
} | |||
|
|||
typedef BOOL (WINAPI *RegisterTouchWindow_t)(HWND,ULONG); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we shouldn't need to load these functions dynamically any longer, they're all available since Windows 7 and we don't support anything earlier (or even it) any longer. If you prefer, we can keep this code as is for this PR, but we could (and should) just remove all this dynamic loading stuff later.
break; | ||
|
||
HandleTouch(wParam, lParam); | ||
// Let DefWindowProc handle the touch events too |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no good reason to not use the usual logic, I'd stick to it. I.e. just do
processed = HandleTouch(wParam, lParam);
event.SetPosition(pos); | ||
event.SetSequenceId(wxTouchSequenceId(wxUIntToPtr(info[i].dwID + 1))); | ||
event.SetPrimary( (info[i].dwFlags & TOUCHEVENTF_PRIMARY) != 0 ); | ||
HandleWindowEvent(event); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also seems to be still relevant.
I guess we could add
Yes, I think it could be nice to add an overload using doubles.
Yes, it was already fixed in master. |
Rebased version of #649
Tested with wxGTK on Linux Mint/X11 and with wxMSW on Windows 11 with a touch panel.
Includes wxMSW patch from https://groups.google.com/g/wx-dev/c/JdeuH95_bGQ/m/tcJCXMZUDgAJ