Home » Developing U++ » U++ Developers corner » Using Pen with U++
Re: Using Pen with U++ [message #56714 is a reply to message #56713] |
Sun, 04 April 2021 23:15 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
Tom1 wrote on Sun, 04 April 2021 22:02I agree that 'EnablePenSupport' is a bad name for it. 'DisableMouse' is not any better. In fact it should be something like 'DisableEmulatedMouseEventsForPen'.
But, as practically always, you are right: I can do everything related to 'supports_pen' flag at client side. I just add this to my Pen enabled widget:
virtual Image MouseEvent(int event, Point p, int zdelta, dword keyflags) override {
if(keyflags&K_PEN) return CursorImage(p, keyflags);
return Ctrl::MouseEvent(event, p, zdelta, keyflags);
}
In this case, I would drop everything in CtrlCore having something to do with 'supports_pen'.
So the last question is: Do you really want to get rid of 'supports_pen' flag? Both ways are fine with me.
Best regards,
Tom
Occam's razor...
Mirek
|
|
|
|
Re: Using Pen with U++ [message #56717 is a reply to message #56715] |
Mon, 05 April 2021 12:59 |
Tom1
Messages: 1212 Registered: March 2007
|
Senior Contributor |
|
|
Hi Mirek,
Next I will improve pen support in my app and if everything goes smoothly, then we need to look at the Linux side. (I see that K_PEN is missing and barrel is not detected, but there's no hurry with it right now.)
Thanks and best regards,
Tom
|
|
|
Re: Using Pen with U++ [message #56725 is a reply to message #56717] |
Wed, 07 April 2021 11:04 |
Tom1
Messages: 1212 Registered: March 2007
|
Senior Contributor |
|
|
Mirek,
Otherwise it's going just fine, but we need to remove the following from WindowProc():
case WM_TABLET_QUERYSYSTEMGESTURESTATUS:
return TABLET_DISABLE_PRESSANDHOLD; // For clean press and hold behavior
The problem is that barrel to right mouse button mapping does not work correctly in non-pen enabled applications. (E.g. a barrel-tap on ArrayCtrl does not show associated context menus, but instead behaves as left click.)
EDIT: Another improvement to barrel -> right mouse button mapping is here in the same file Win32Proc.cpp line 57:
bool GetMouseRight() { return Ctrl::GetPenInfo().barrel || !!(GetKeyStateSafe(VK_RBUTTON) & 0x8000); }
Best regards,
Tom
[Updated on: Wed, 07 April 2021 15:16] Report message to a moderator
|
|
|
|
Re: Using Pen with U++ [message #56737 is a reply to message #56726] |
Thu, 08 April 2021 17:36 |
Tom1
Messages: 1212 Registered: March 2007
|
Senior Contributor |
|
|
Hi Mirek,
Here's a fix for missing barrel button detection in Linux (GTK). In GtkEvent.cpp Ctrl::AddEvent():
...
e.event = NULL;
GdkDevice *d = gdk_event_get_source_device(event);
if(d && gdk_device_get_source(d) == GDK_SOURCE_PEN) {
e.pen = true;
e.pen_barrel = (bool)(MouseState & GDK_BUTTON3_MASK); // Add barrel button detection
...
Best regards,
Tom
|
|
|
|
Re: Using Pen with U++ [message #56741 is a reply to message #56739] |
Fri, 09 April 2021 10:00 |
Tom1
Messages: 1212 Registered: March 2007
|
Senior Contributor |
|
|
mirek wrote on Fri, 09 April 2021 10:18Tom1 wrote on Wed, 07 April 2021 11:04
bool GetMouseRight() { return Ctrl::GetPenInfo().barrel || !!(GetKeyStateSafe(VK_RBUTTON) & 0x8000); }
Should not there at least be some sort of Ctrl::IsPen() test mixed in?
(Other patches applied).
Mirek
Well, I think not. As GetMouseRight() can be called from anywhere at any time, there is no forced association to specific pen or mouse event. So, we just get the info if right mouse button or barrel is pressed or not. I'm merely trying to make both mouse and pen behave the same way in apps and this helps towards this target. Obviously, we do not want mixed blinking response from GetMouseRight() depending on which pointing device has more recently updated its button status.
Best regards,
Tom
|
|
|
|
|
Re: Using Pen with U++ [message #56752 is a reply to message #56751] |
Fri, 09 April 2021 20:15 |
Tom1
Messages: 1212 Registered: March 2007
|
Senior Contributor |
|
|
Hi Mirek,
It seems routing Pen() to ctrl in GLPane fixes the Pen() in GLCtrl:
#ifdef PLATFORM_WIN32
struct GLPane : DHCtrl {
friend class GLCtrl;
GLCtrl *ctrl;
void DoGLPaint();
public:
GLPane() { NoWantFocus(); }
virtual void State(int reason);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual Image MouseEvent(int event, Point p, int zdelta, dword keyflags);
virtual void Pen(Point p, const PenInfo& pen, dword keyflags) { if(ctrl) ctrl->Pen(p, pen, keyflags); } // ADD THIS FOR ROUTING PEN
void Init();
void Destroy();
void ActivateContext();
void ExecuteGL(HDC hdc, Event<> paint, bool swap_buffers);
void ExecuteGL(Event<> paint, bool swap_buffers);
};
#endif
However, I have a funny feeling this is not the full story. E.g. how does mouseTarget fit into this picture?
Best regards,
Tom
|
|
|
Re: Using Pen with U++ [message #56757 is a reply to message #56752] |
Mon, 12 April 2021 00:27 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
Tom1 wrote on Fri, 09 April 2021 20:15Hi Mirek,
It seems routing Pen() to ctrl in GLPane fixes the Pen() in GLCtrl:
#ifdef PLATFORM_WIN32
struct GLPane : DHCtrl {
friend class GLCtrl;
GLCtrl *ctrl;
void DoGLPaint();
public:
GLPane() { NoWantFocus(); }
virtual void State(int reason);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual Image MouseEvent(int event, Point p, int zdelta, dword keyflags);
virtual void Pen(Point p, const PenInfo& pen, dword keyflags) { if(ctrl) ctrl->Pen(p, pen, keyflags); } // ADD THIS FOR ROUTING PEN
void Init();
void Destroy();
void ActivateContext();
void ExecuteGL(HDC hdc, Event<> paint, bool swap_buffers);
void ExecuteGL(Event<> paint, bool swap_buffers);
};
#endif
However, I have a funny feeling this is not the full story. E.g. how does mouseTarget fit into this picture?
Best regards,
Tom
Applied, hopefully including the mouseTarget issue.
|
|
|
|
Re: Using Pen with U++ [message #56883 is a reply to message #56761] |
Sun, 25 April 2021 23:20 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
It unfortunately looks like I am not getting any history with GTK. I think this should log them:
CtrlCore/GtkEvent.cpp:283
#if GTK_CHECK_VERSION(3, 22, 0)
static guint32 prev_time;
if(event) {
GdkDevice *d = gdk_event_get_source_device(event);
if(d && gdk_device_get_source(d) == GDK_SOURCE_PEN) {
e.pen = true;
e.pen_barrel = MouseState & GDK_BUTTON3_MASK;
double *axes = NULL;
if(event->type == GDK_MOTION_NOTIFY) {
GdkEventMotion *mevent = (GdkEventMotion *)event;
axes = mevent->axes;
GdkTimeCoord **events;
int n_events;
if(gdk_device_get_history(d, mevent->window, prev_time, mevent->time, &events, &n_events)) {
DLOG("=====");
DDUMP(e.mousepos);
for(int i = 0; i < n_events; i++) {
double x = 0, y = 0, pressure = 0.5;
gdk_device_get_axis (d, events[i]->axes, GDK_AXIS_X, &x);
gdk_device_get_axis (d, events[i]->axes, GDK_AXIS_Y, &y);
gdk_device_get_axis (d, events[i]->axes, GDK_AXIS_PRESSURE, &pressure);
DDUMP(x);
DDUMP(y);
DDUMP(pressure);
}
gdk_device_free_history (events, n_events);
}
prev_time = gdk_event_get_time(event);
}
if(findarg(event->type, GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS, GDK_3BUTTON_PRESS, GDK_BUTTON_RELEASE) >= 0)
axes = ((GdkEventButton *)event)->axes;
if(axes) {
double h;
if(axes && gdk_device_get_axis(d, axes, GDK_AXIS_PRESSURE, &h))
e.pen_pressure = h;
if(axes && gdk_device_get_axis(d, axes, GDK_AXIS_ROTATION, &h))
e.pen_rotation = h;
if(axes && gdk_device_get_axis(d, axes, GDK_AXIS_XTILT, &h))
e.pen_tilt.x = h;
if(axes && gdk_device_get_axis(d, axes, GDK_AXIS_YTILT, &h))
e.pen_tilt.y = h;
}
}
}
#endif
[Updated on: Sun, 25 April 2021 23:20] Report message to a moderator
|
|
|
|
|
Re: Using Pen with U++ [message #56889 is a reply to message #56888] |
Mon, 26 April 2021 16:33 |
Tom1
Messages: 1212 Registered: March 2007
|
Senior Contributor |
|
|
Hi,
The gdk_window_set_event_compression() does not help here either. Drawing is not working when using that either.
I tested Wacom pen with GIMP and it works as fast as I can possibly draw. (And it is not smoothing my strokes either, because a stupid super fast zig-zag looks just like that.) So there must be something we are missing here...
Best regards,
Tom
|
|
|
Re: Using Pen with U++ [message #56890 is a reply to message #56889] |
Mon, 26 April 2021 17:13 |
Tom1
Messages: 1212 Registered: March 2007
|
Senior Contributor |
|
|
Mirek,
Does GIMP source file gimp-master/app/display/gimpdisplayshell-tool-events.c (possibly around line 860) give you any hint what they could be doing differently with gdk_device_get_history()?
Also on line 553 they seem to activate gdk_window_set_event_compression(w, FALSE); when the button goes down and then inactivate again when button is released.
Best regards,
Tom
|
|
|
Re: Using Pen with U++ [message #56902 is a reply to message #56890] |
Wed, 28 April 2021 12:00 |
Tom1
Messages: 1212 Registered: March 2007
|
Senior Contributor |
|
|
Hi Mirek,
More bad news: It seems that on Ubuntu 2021.4 U++ Pen does not work. Or rather, it works in mouse emulation without any pen specific features.
In Ubuntu settings there is a page for Wacom and there the tablet and pen is configurable and it works (including pressure) in the test-canvas provided by the settings page.
The pen also works in Krita with pressure and all. (I do not know if Krita works on top of Wayland directly or via Xwayland.)
In GIMP, the pen also works correctly. Therein it is configured through Edit > Input Devices. It seems to come in via "xwayland-tablet stylus" device on the list.
Best regards,
Tom
EDIT: In Ubuntu 2021.4 pen is reported as source device called GDK_SOURCE_TOUCHSCREEN instead of GDK_SOURCE_PEN. Pressure can be detected here.
[Updated on: Wed, 28 April 2021 12:39] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Sun Apr 28 23:33:05 CEST 2024
Total time taken to generate the page: 0.03247 seconds
|