Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tom1 wrote on Sun, 04 April 2021 22:02
I 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... Smile

Mirek
Re: Using Pen with U++ [message #56715 is a reply to message #56714] Mon, 05 April 2021 12:33 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
OK, this one is 'shaved'. Smile

- 'supports_pen' flag is gone
- Pen interface is now 'virtual void Pen()'

Best regards,

Tom

EDIT: Nevermind... you did it already!

Thanks!

[Updated on: Mon, 05 April 2021 12:45]

Report message to a moderator

Re: Using Pen with U++ [message #56717 is a reply to message #56715] Mon, 05 April 2021 12:59 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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 #56726 is a reply to message #56725] Wed, 07 April 2021 12:00 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Mirek,

One more thing: My 3D view inherited from GLCtrl does not receive Pen() events at all.

Best regards,

Tom
Re: Using Pen with U++ [message #56737 is a reply to message #56726] Thu, 08 April 2021 17:36 Go to previous messageGo to next message
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 #56739 is a reply to message #56725] Fri, 09 April 2021 09:18 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tom1 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
Re: Using Pen with U++ [message #56741 is a reply to message #56739] Fri, 09 April 2021 10:00 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
mirek wrote on Fri, 09 April 2021 10:18
Tom1 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 #56743 is a reply to message #56741] Fri, 09 April 2021 10:24 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK then.

Not sure about what is wrong with GL. Could be related to DHCtrl...
Re: Using Pen with U++ [message #56751 is a reply to message #56743] Fri, 09 April 2021 17:25 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Mirek,

Thanks for applying the changes. Smile

When you have a moment to spare, could you please take a look at the pen history in Gtk? I guess that would complete pen support. (In addition to fixing Pen() for GLCtrl...)

Best regards,

Tom
Re: Using Pen with U++ [message #56752 is a reply to message #56751] Fri, 09 April 2021 20:15 Go to previous messageGo to next message
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 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tom1 wrote on Fri, 09 April 2021 20:15
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


Applied, hopefully including the mouseTarget issue.
Re: Using Pen with U++ [message #56761 is a reply to message #56757] Mon, 12 April 2021 09:10 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Thanks! Smile

BR,

Tom
Re: Using Pen with U++ [message #56883 is a reply to message #56761] Sun, 25 April 2021 23:20 Go to previous messageGo to next message
mirek is currently offline  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 #56887 is a reply to message #56883] Mon, 26 April 2021 15:55 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi Mirek,

Unfortunately, it is the same here. No history: gdk_device_get_history() returns false and that's it. Sad

How to try if this helps:

gdk_window_set_event_compression(win, false);

I mean where to put it and which win to use?

https://developer.gnome.org/gdk3/stable/gdk3-Windows.html#gd k-window-set-event-compression

Best regards,

Tom
Re: Using Pen with U++ [message #56888 is a reply to message #56887] Mon, 26 April 2021 16:06 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tom1 wrote on Mon, 26 April 2021 15:55
Hi Mirek,

Unfortunately, it is the same here. No history: gdk_device_get_history() returns false and that's it. Sad

How to try if this helps:

gdk_window_set_event_compression(win, false);


I already tried as the first option, makes everything stop working (not sure why, tried gdk_device_get_history after that).

Good position to insert it is somewhere around CtrlCore/GtkCreate.cpp:59.

Mirek
Re: Using Pen with U++ [message #56889 is a reply to message #56888] Mon, 26 April 2021 16:33 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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

Re: Using Pen with U++ [message #56903 is a reply to message #56902] Wed, 28 April 2021 15:42 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tom1 wrote on Wed, 28 April 2021 12:00
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.


I suggest ignoring this for 2021.1 release... Hopefully we shall figure that out for the next one.

Mirek
Previous Topic: WString vs Grapheme Cluster idea (with possible flaw)
Next Topic: .gitignore
Goto Forum:
  


Current Time: Fri Mar 29 06:24:52 CET 2024

Total time taken to generate the page: 0.02323 seconds