<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://jogamp.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.2"
          urlbase="https://jogamp.org/bugzilla/"
          
          maintainer="sgothel@jausoft.com"
>

    <bug>
          <bug_id>1348</bug_id>
          
          <creation_ts>2016-11-17 13:25:53 +0100</creation_ts>
          <short_desc>Add X11 Touch Event Support to Generate NEWT Mouse/Pointer Events</short_desc>
          <delta_ts>2019-03-28 18:37:58 +0100</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>3</classification_id>
          <classification>JogAmp</classification>
          <product>Newt</product>
          <component>x11</component>
          <version>2.4.0</version>
          <rep_platform>All</rep_platform>
          <op_sys>linux</op_sys>
          <bug_status>VERIFIED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P4</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>danny.koernig</reporter>
          <assigned_to name="Sven Gothel">sgothel</assigned_to>
          <cc>gouessej</cc>
          
          <cf_type>FEATURE</cf_type>
          <cf_scm_refs>jogl 92006e4baef57f1f3fb647dd307aed5989fd4c8d
jogl 746383476aa449e9cab4a25df27be85b61aa074b
jogl b32541efc1bef773c4f1bbd06d0885ee79821865
jogl ec4721c5b81ca39355f660294bf45edc0a1584da</cf_scm_refs>
          <cf_workaround>---</cf_workaround>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>6002</commentid>
    <comment_count>0</comment_count>
    <who name="">danny.koernig</who>
    <bug_when>2016-11-17 13:25:53 +0100</bug_when>
    <thetext>X11 server API supports touch events, which could be supported by NEWT
to generate NEWT&apos;s Mouse/Pointer events.

More Information can be found here: http://www.x.org/wiki/Development/Documentation/Multitouch/

I&apos;ve patched this into the jogl version 2.3.2 already. I will make a branch on github for my changes and send a pull request.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6003</commentid>
    <comment_count>1</comment_count>
    <who name="">danny.koernig</who>
    <bug_when>2016-11-17 14:50:31 +0100</bug_when>
    <thetext>Here is my pull request: https://github.com/sgothel/jogl/pull/102</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6005</commentid>
    <comment_count>2</comment_count>
    <who name="Julien Gouesse">gouessej</who>
    <bug_when>2016-11-23 17:15:21 +0100</bug_when>
    <thetext>Very good job and your pull request is quite clean :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6104</commentid>
    <comment_count>3</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-03-27 00:09:57 +0100</bug_when>
    <thetext>Thank you Danny, reviewing your pull request.
Excellent work.

The only issue I have is the usage of the static &apos;touch_coordinates&apos; array,
which may lead to threading issues having multiple EDT threads on different X11 Displays running?

I will pull and merge your work and may add a fix to this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6105</commentid>
    <comment_count>4</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-03-27 03:12:41 +0100</bug_when>
    <thetext>commit 746383476aa449e9cab4a25df27be85b61aa074b

(Note to Danny: I cannot test this now - please re-test and/or review)
    
X11Common::JavaWindow
- Owns XI extension&apos;s xiOpcode, selected xiTouchDeviceId and tracked XITouchPosition array
    
X11Window::CreateWindow
- Query XI extension only once @ window creation and earmark xiOpcode in JavaWindow instance
    
- Fix: Device selection code was &quot;class-&gt;type != XITouchClass&quot;,
  but shouldn&apos;t it be &apos;XITouchClass == class-&gt;type&apos; (as patched here)
    
- Fix: Free XIQueryDevice returned XIDeviceInfo array via XIFreeDeviceInfo
    
- Earmark deviceid in JavaWindow instance
    
X11Display
- Moved global static touch_coordinates to JavaWindow::xiTouchCoords instance
    
X11Display::DispatchMessage
- Changed event handling structure similar to https://keithp.com/blogs/Cursor_tracking/
    
- Fix: Free XGetEventData&apos;s optional memory allocation via XFreeEventData
    
- Reuse JavaWindow&apos;s queried xiOpcode
    
- Fix: Don&apos;t overrise windowPointer, instead validate and require a match. JavaWindow must match!
    
- Fix: Also validate chosen deviceid with JavaWindow&apos;s registered device
    
Newt Build:
- Added libXi in build recipe and doc</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6106</commentid>
    <comment_count>5</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-03-27 03:45:32 +0100</bug_when>
    <thetext>Add more verbose DBG_PRINT
- @ CreateWindow: extension, scanning device/class, registered deviceid
- @ DispatchMessage: XI_TouchBegin, XI_TouchUpdate and XI_TouchEnd
    
On my test machine w/o a touchscreen I correctly:
- detected extension
- detected no XITouchClass device, hence no deviceid registered

This needs validation with a touchscreen now :)

X11: [CreateWindow]: XI: Window 0x6600016, Extension 131
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[1/13].class[1/7]: type 1 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[1/13].class[2/7]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[1/13].class[3/7]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[1/13].class[4/7]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[1/13].class[5/7]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[1/13].class[6/7]: type 3 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[1/13].class[7/7]: type 3 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[2/13].class[1/1]: type 0 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[3/13].class[1/3]: type 1 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[3/13].class[2/3]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[3/13].class[3/3]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[4/13].class[1/1]: type 0 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[5/13].class[1/1]: type 0 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[6/13].class[1/1]: type 0 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[7/13].class[1/1]: type 0 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[8/13].class[1/7]: type 1 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[8/13].class[2/7]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[8/13].class[3/7]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[8/13].class[4/7]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[8/13].class[5/7]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[8/13].class[6/7]: type 3 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[8/13].class[7/7]: type 3 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[9/13].class[1/7]: type 1 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[9/13].class[2/7]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[9/13].class[3/7]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[9/13].class[4/7]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[9/13].class[5/7]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[9/13].class[6/7]: type 3 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[9/13].class[7/7]: type 3 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[10/13].class[1/1]: type 0 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[11/13].class[1/1]: type 0 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[12/13].class[1/7]: type 1 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[12/13].class[2/7]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[12/13].class[3/7]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[12/13].class[4/7]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[12/13].class[5/7]: type 2 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[12/13].class[6/7]: type 3 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[12/13].class[7/7]: type 3 (is XITouchClass 0)
X11: [CreateWindow]: XI: Scan Window 0x6600016, device[13/13].class[1/1]: type 0 (is XITouchClass 0)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6111</commentid>
    <comment_count>6</comment_count>
    <who name="">danny.koernig</who>
    <bug_when>2019-03-27 07:44:54 +0100</bug_when>
    <thetext>Sven, thanks for the review and improvements.

I tested your changes and unfortunately it didn&apos;t work.

I got following warning:
Warning: NEWT X11 DisplayDispatch 0x7fba740018f0, Couldn&apos;t handle event 35 for X11 window 0x1300000083

I will take a deeper look to the problem in the next days.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6112</commentid>
    <comment_count>7</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-03-27 18:56:49 +0100</bug_when>
    <thetext>Fix X11 XI Multitouch
    
I got access to a touchscreen laptop w/ Debian 9, hence I could fix and test the implementation.
    
X11 DisplayDriver.java:
- Store and pass through xi_opcode of XI extension, queried at initialization stage
    
X11Window.c Fixes:
- Initialize JavaWindow&apos;s xiTouchCoords[].id w/ -1, as required to track the pointer
    
- Pass through xi_opcode as stored in X11 DisplayDriver
    
X11Display.c Fixes:
- sendTouchScreenEvent: Throw RuntimeException if 0 &gt; actionId (Internal Error: based on xiTouchCoords[].id tracking)
    
- DispatchMessages&apos;s windowPointer determination:
-- Query potenial XI Event first: IF XI Event, must use XIDeviceEvent&apos;s event Window
-- Only IF not an XI Event, we can use evt.xany.window as the event window
    
- DispatchMessages&apos;s XI Event Handling:
-- Always break deviceid search loop if id found, preserving index and time spend
    
Works on my Debian 9 device, tested w/ com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT:
- One pointer (finger) press, drag and release (click)
- PinchToZoomGesture works
- DoubleTabScrollGesture works
    
+++ 
    
Potential Issues:
    
JavaWindow&apos;s xiTouchCoords[].id accuracy is crucial to pointer tracking
during XI_TouchBegin -&gt; XI_TouchUpdate -&gt; XI_TouchEnd.
    
In the normal course of action:
- XI_TouchBegin sets the id, assuming it is yet set 
- XI_TouchUpdate assumes it is set 
- XI_TouchEnd clears the id, assuming it is set 
    
This field in the JavaWindow array only gets reset to -1 once at native window
creation. We may need to figure out when to reset this field to -1. 
    
If the XI_TouchEnd events would get lost for whatever reason,
the above tracking state would be broken.

+++

In case there are issues left and/or a good preemptive solution for above
potential issue is found: reopen and add the fix before 2.4.0 release.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6113</commentid>
    <comment_count>8</comment_count>
    <who name="">danny.koernig</who>
    <bug_when>2019-03-28 07:50:14 +0100</bug_when>
    <thetext>Works for me too. Thank you!

In my opinion the potential issue is not so great. The implementation supports 10 finger multitouch. If one XI_TouchEnd is lost (because of a bug of X11 or the display driver?) there still stay 9 fingers ;)

Possible solution:
* struct XITouchPosition gets a new field which is set with the current timestamp on every XI_TouchBegin and XI_TouchUpdate event
* on every new event we check the stored timestamps. At timestamps older than 30 seconds we can assume the XI_TouchEnd event was lost and we reset the id to -1 (also we send EVENT_MOUSE_RELEASED to the application?)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6114</commentid>
    <comment_count>9</comment_count>
    <who name="Julien Gouesse">gouessej</who>
    <bug_when>2019-03-28 12:43:39 +0100</bug_when>
    <thetext>(In reply to danny.koernig from comment #8)
&gt; Works for me too. Thank you!
&gt; 
&gt; In my opinion the potential issue is not so great. The implementation
&gt; supports 10 finger multitouch. If one XI_TouchEnd is lost (because of a bug
&gt; of X11 or the display driver?) there still stay 9 fingers ;)
&gt; 
&gt; Possible solution:
&gt; * struct XITouchPosition gets a new field which is set with the current
&gt; timestamp on every XI_TouchBegin and XI_TouchUpdate event
&gt; * on every new event we check the stored timestamps. At timestamps older
&gt; than 30 seconds we can assume the XI_TouchEnd event was lost and we reset
&gt; the id to -1 (also we send EVENT_MOUSE_RELEASED to the application?)

Personally, I&apos;d prefer leaving the source code as it is right now as we&apos;re not sure that this problem will really occur and the suggested fix is messy. I think that the time stamp is already stored elsewhere.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6115</commentid>
    <comment_count>10</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-03-28 17:19:41 +0100</bug_when>
    <thetext>(In reply to Julien Gouesse from comment #9)
&gt; (In reply to danny.koernig from comment #8)
&gt; &gt; Works for me too. Thank you!
&gt; &gt; 
&gt; &gt; In my opinion the potential issue is not so great. The implementation
&gt; &gt; supports 10 finger multitouch. If one XI_TouchEnd is lost (because of a bug
&gt; &gt; of X11 or the display driver?) there still stay 9 fingers ;)
&gt; &gt; 
&gt; &gt; Possible solution:
&gt; &gt; * struct XITouchPosition gets a new field which is set with the current
&gt; &gt; timestamp on every XI_TouchBegin and XI_TouchUpdate event
&gt; &gt; * on every new event we check the stored timestamps. At timestamps older
&gt; &gt; than 30 seconds we can assume the XI_TouchEnd event was lost and we reset
&gt; &gt; the id to -1 (also we send EVENT_MOUSE_RELEASED to the application?)
&gt; 
&gt; Personally, I&apos;d prefer leaving the source code as it is right now as we&apos;re
&gt; not sure that this problem will really occur and the suggested fix is messy.
&gt; I think that the time stamp is already stored elsewhere.

Agreed. We could handle this from the Java side and in case we need to reset the touch IDs issue a native call to X11Window.c.

Will let this idea keep floating around for a while .. 2.4.0 release is not yet due anyways.

Great we have this feature finally supported on X11 now,
thank you for your initial &apos;wall breaking&apos; contribution!</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>