<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ClearChain &#187; MPX</title>
	<atom:link href="http://www.clearchain.com/blog/tags/mpx/feed" rel="self" type="application/rss+xml" />
	<link>http://www.clearchain.com/blog</link>
	<description>-= Daily Happenings =-</description>
	<lastBuildDate>Sun, 25 Jul 2010 15:47:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Xinput 1 -&gt; XInput 2 conversion guide</title>
		<link>http://www.clearchain.com/blog/posts/xinput-1-xinput-2-conversion-guide</link>
		<comments>http://www.clearchain.com/blog/posts/xinput-1-xinput-2-conversion-guide#comments</comments>
		<pubDate>Thu, 30 Jul 2009 01:30:14 +0000</pubDate>
		<dc:creator>Benjamin Close</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[FreeDesktop]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[gtk+]]></category>
		<category><![CDATA[MPX]]></category>
		<category><![CDATA[protocol]]></category>
		<category><![CDATA[toolkit]]></category>
		<category><![CDATA[XI1]]></category>
		<category><![CDATA[XI2]]></category>
		<category><![CDATA[XInput 1.5]]></category>
		<category><![CDATA[XInput1]]></category>
		<category><![CDATA[Xinput2]]></category>

		<guid isPermaLink="false">http://www.clearchain.com/blog/?p=415</guid>
		<description><![CDATA[Details about the API changes between Xinput 1(XI1) and XInput 2 (XI2)]]></description>
			<content:encoded><![CDATA[<p>Recently I was tasked with porting <a href="http://www.gtk.org/">GTK+</a> to support Xinput 2 (XI2), and whilst the port isn&#8217;t finished I quickly discovered just how big the conversion was. This page is designed to help someone who is familiar with XInput 1 switch to XInput 2 &#8211; it&#8217;s certainly is by no means a complete guide and anyone reading this should also take a look at the various <a href="http://who-t.blogspot.com/">Input2 recipies published.</a></p>
<p>XI2 is the first major rewrite of the <a href="http://www.x.org/wiki/XInputSpec">XInput specification</a> in years and with it comes a lot of enhanced functionality, but also a <a href="http://cgit.freedesktop.org/xorg/lib/libXi/tree/man">new API</a>. The API was deliberately designed not to be backward compatible. Why? To prevent both XI1 and XI2 features to be intermingled. XI2 brings with it a new device model and a new input model. Both of these are incompatible with XI1. The decision to break the API was not a light one by <a href="http://who-t.blogspot.com/">Peter Hutterer</a>, the main XI2 developer.  Supporting XI1 would have ment future changes to XI2 would be impossible &#8211; there&#8217;s only so far you can push an out dated protocol and api. The added complexity of trying to maintain 2 code paths was also determined to be too high. XI2 is more than just a api/abi change. It literally change the entire input subsystem of the <a href="http://www.x.org">Xorg</a> Xserver. XI2 supports:</p>
<ul>
<li>Mulitple Independent Master Devices  (MPX)</li>
<li>Subpixel Accuracy for input devices</li>
<li>Support for 32bit key codes</li>
<li>.. lots more See: <a href="http://fedoraproject.org/wiki/Features/XI2">http://fedoraproject.org/wiki/Features/XI2</a> for full details</li>
</ul>
<p>With that in mind, the new XI2 API often leaves someone who&#8217;s been working with the XI1 wondering what the equivilant XI2 API call is.  Most functions have an equivilant in XI2 function though the usage has more often than not, changed dramatically. Below is some examples of how to convert XI1 code to XI2 compatible code and a list of <strong>some</strong> of the changes which have occurred. If you find something missing, please add to the comments.</p>
<h2>Change Overview</h2>
<p>The biggest change that any XI1 developer will notice is the <em><strong>XDevice *</strong></em> type has vanished. All XI2 devices make use of the <em><strong>XID</strong></em> type instead. Under the hoods, in the Xserver and XDevice really equates back to an XID anyway now. The next biggest change XI1 developers will notice is the entire XInput2 API has had shifted namespaces. All XInput2 functions, types, etc are now prefixed with XI (ie XIEventMask). This was designed to force segregation of XI1 -&gt; XI2 code.</p>
<p>The header file you include has also changed. Instead of:</p>
<pre>#include &lt;X11/extensions/XInput.h&gt;</pre>
<p>It&#8217;s now:</p>
<pre>#include &lt;X11/extensions/XInput<span style="text-decoration: underline;"><strong>2</strong></span>.h&gt;</pre>
<h2>Notable Changes</h2>
<ul>
<li>Proximity events are no longer supported, these are now reported as regular events on another axis (ie think of a pressure axis)</li>
<li>Events are  longer use device classes, instead all events are type XIEvent (a type of XEvent). Hence there is no need to pass around an array of integer classes anymore when registering for events, instead a single XIEventMask will do what is needed. The macros XISetMask and XIGetMask help with using the mask.</li>
</ul>
<p>There&#8217;s also been a lot of changes to structures, functions, types and how they are used.</p>
<h2>Event Changes</h2>
<table border="1">
<tbody>
<tr>
<th>XI1 Event</th>
<th>XI2 Event</th>
<th>Notes</th>
</tr>
<tr>
<td>XDeviceKeyEvent,  XDeviceKeyPressedEvent, XDeviceKeyReleasedEvent, XDeviceButtonEvent,  XDeviceButtonPressedEvent,  XDeviceButtonReleasedEvent ,XDeviceMotionEvent</td>
<td>XIDeviceEvent</td>
<td>The various events are now incorporated into the one event type. XIDeviceEvent-&gt;evtype indicates the subtype of event. Ie XIMotion is a motion event for that device.</td>
</tr>
<tr>
<td>XProximityNotifyEvent, XProximityInEvent, XProximityOutEvent</td>
<td>XIDeviceEvent (See Note)</td>
<td>Proximity Events have been replaced with device events. Proximity is represented as a value in the valuator on one of the axes</td>
</tr>
</tbody>
</table>
<h2>Structure/Type Changes</h2>
<table border="1">
<tbody>
<tr>
<th>XI1 Structure/Type</th>
<th>XI2 Structure/Type</th>
<th>Notes</th>
</tr>
<tr>
<td>XDeviceState</td>
<td>XIDeviceInfo</td>
<td>XIDeviceInfo also contains  a name and classes</td>
</tr>
<tr>
<td>XAnyClassPtr</td>
<td>XIAnyClassInfo *</td>
<td></td>
</tr>
<tr>
<td>XValuatorInfo</td>
<td>XIValuatorClassInfo</td>
<td></td>
</tr>
<tr>
<td>XInputClass</td>
<td>XIAnyClassInfo</td>
<td></td>
</tr>
<tr>
<td>XEventClass</td>
<td>XIEventMask</td>
<td>Used for selecting events to be monitored.<br />
One mask is used per device.  Standard usage is:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">XIEventMask mask<span style="color: #339933;">;</span>
mask.<span style="color: #202020;">deviceid</span><span style="color: #339933;">=</span><span style="color: #666666; font-style: italic;">//some device or XIAllDevices for all devices&amp;lt;</span>
mask.<span style="color: #202020;">mask_len</span><span style="color: #339933;">=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
mask.<span style="color: #202020;">mask</span><span style="color: #339933;">=</span>calloc<span style="color: #009900;">&#40;</span>mask.<span style="color: #202020;">mask_len</span><span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
XISetMask<span style="color: #009900;">&#40;</span>mask.<span style="color: #202020;">mask</span><span style="color: #339933;">,</span> XI_ButtonPress<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
..
<span style="color: #202020;">XISelectEvents</span><span style="color: #009900;">&#40;</span>display<span style="color: #339933;">,</span> win<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>mask<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span></pre></div></div>

</td>
</tr>
<tr>
<td>XExtensionVersion</td>
<td>Struct Removed</td>
<td>XIQueryVersion should be used instead</td>
</tr>
<tr>
<td>XDeviceKeyEvent, XDeviceKeyPressedEvent, XDeviceKeyReleasedEvent, XDeviceButtonEvent, XDeviceButtonPressedEvent, XDeviceButtonReleasedEvent,</td>
<td>Structs Removed</td>
<td>XIDeviceEvents are now used instead</td>
</tr>
<tr>
<td>XDeviceFocusChangeEvnet, XDeviceFocusInEvent, XDeviceFocusOutEvent</td>
<td>Structs Removed</td>
<td>XIDeviceEvents are now used</td>
</tr>
<tr>
<td>XProximityNotifyEvent, XProximityInEvent, XProximityOutEvent</td>
<td>Structs Removed</td>
<td>XIDeviceEvents are now used</td>
</tr>
</tbody>
</table>
<h2>Function/Macro Changes</h2>
<table border="1">
<tbody>
<tr>
<th>XI1 Function</th>
<th>XI2 Function</th>
<th>Notes</th>
</tr>
<tr>
<td>XFreeDeviceList</td>
<td>XIFreeDeviceInfo</td>
<td></td>
</tr>
<tr>
<td>XDefineDeviceCursor</td>
<td>XIDefineCursor</td>
<td></td>
</tr>
<tr>
<td>DeviceButton1Motion</p>
<p>DeviceButton2Motion</p>
<p>&#8230;</td>
<td>(No Equivelant)</td>
<td></td>
</tr>
<tr>
<td>XWarpPointer</p>
<p>XWarpDevicePointer</td>
<td>XIWarpPointer</td>
<td>XIWarpPointer makes use of the device id like XWarpDevicePointer (XI1.5).   XWarpPointer is considered obsolete as it has no concept of a device</td>
</tr>
<tr>
<td>XQueryDeviceState</td>
<td>XIQueryDevice</td>
<td>Return type is XIDeviceInfo *, can be called with deviceid = XIAllDevices to query all devices hence the ndevices return</td>
</tr>
<tr>
<td>XFreeDeviceState</td>
<td>XIFreeDeviceInfo</td>
<td></td>
</tr>
<tr>
<td>DeviceGrabButton</td>
<td>XIGrabButton</td>
<td></td>
</tr>
<tr>
<td>XSelectExtensionEvent</td>
<td>XISelectEvents</td>
<td>Instead of a list of classes now a list of XIEventMask is used, one mask per device. XSelectExtensionEvent is still used for other extension events not related to XInput2</td>
</tr>
<tr>
<td>XGetExtensionVersion</td>
<td>XIQueryVersion</td>
<td>If only XI1 is present this will be returned vi the major/minor numbers (ie major = 1)</td>
</tr>
</tbody>
</table>
<h2>Examples</h2>
<p>Below are some examples of how to use some of the new XI2 functions.</p>
<h3>Event Processing &#8211; Registering For Events</h3>
<p>A simple indication how to register for events (XI2 greatly simplifies this)</p>
<ul>
<li><strong>XInput 1 (Taken from: <a href="http://cgit.freedesktop.org/xorg/app/xinput/tree/src/test.c">http://cgit.freedesktop.org/xorg/app/xinput/tree/src/test.c)</a> </strong></li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">static</span> <span style="color: #993333;">int</span>           motion_type <span style="color: #339933;">=</span> INVALID_EVENT_TYPE<span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span>           button_press_type <span style="color: #339933;">=</span> INVALID_EVENT_TYPE<span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span>           button_release_type <span style="color: #339933;">=</span> INVALID_EVENT_TYPE<span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span>           key_press_type <span style="color: #339933;">=</span> INVALID_EVENT_TYPE<span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span>           key_release_type <span style="color: #339933;">=</span> INVALID_EVENT_TYPE<span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span>           proximity_in_type <span style="color: #339933;">=</span> INVALID_EVENT_TYPE<span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span>           proximity_out_type <span style="color: #339933;">=</span> INVALID_EVENT_TYPE<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> register_event<span style="color: #009900;">&#40;</span>Display <span style="color: #339933;">*</span>dpy<span style="color: #339933;">,</span> XDeviceInfo <span style="color: #339933;">*</span>info<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    XEventClass         event_list<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span>                 i<span style="color: #339933;">;</span>
    XDevice             <span style="color: #339933;">*</span>device<span style="color: #339933;">;</span>
    XInputClassInfo     <span style="color: #339933;">*</span>ip<span style="color: #339933;">;</span>
&nbsp;
    device <span style="color: #339933;">=</span> XOpenDevice<span style="color: #009900;">&#40;</span>dpy<span style="color: #339933;">,</span> info<span style="color: #339933;">-&gt;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Check for open error</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>device<span style="color: #339933;">-&gt;</span>num_classes <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>ip <span style="color: #339933;">=</span> device<span style="color: #339933;">-&gt;</span>classes<span style="color: #339933;">,</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>info<span style="color: #339933;">-&gt;</span>num_classes<span style="color: #339933;">;</span> ip<span style="color: #339933;">++,</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>ip<span style="color: #339933;">-&gt;</span>input_class<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">case</span> ButtonClass<span style="color: #339933;">:</span>
                DeviceButtonPress<span style="color: #009900;">&#40;</span>device<span style="color: #339933;">,</span> button_press_type<span style="color: #339933;">,</span> event_list<span style="color: #009900;">&#91;</span>number<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> number<span style="color: #339933;">++;</span>
                DeviceButtonRelease<span style="color: #009900;">&#40;</span>device<span style="color: #339933;">,</span> button_release_type<span style="color: #339933;">,</span> event_list<span style="color: #009900;">&#91;</span>number<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> number<span style="color: #339933;">++;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">case</span> ValuatorClass<span style="color: #339933;">:</span>
                DeviceMotionNotify<span style="color: #009900;">&#40;</span>device<span style="color: #339933;">,</span> motion_type<span style="color: #339933;">,</span> event_list<span style="color: #009900;">&#91;</span>number<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> number<span style="color: #339933;">++;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>handle_proximity<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    ProximityIn<span style="color: #009900;">&#40;</span>device<span style="color: #339933;">,</span> proximity_in_type<span style="color: #339933;">,</span> event_list<span style="color: #009900;">&#91;</span>number<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> number<span style="color: #339933;">++;</span>
                    ProximityOut<span style="color: #009900;">&#40;</span>device<span style="color: #339933;">,</span> proximity_out_type<span style="color: #339933;">,</span> event_list<span style="color: #009900;">&#91;</span>number<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> number<span style="color: #339933;">++;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
                fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;unknown class<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>XSelectExtensionEvent<span style="color: #009900;">&#40;</span>dpy<span style="color: #339933;">,</span> root_win<span style="color: #339933;">,</span> event_list<span style="color: #339933;">,</span> number<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;error selecting extended events<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span></pre></div></div>

<ul>
<li><strong>XInput 2:<br />
(Taken from: <a href="http://who-t.blogspot.com/2009/05/xi2-recipes-part-1.html">http://who-t.blogspot.com/2009/05/xi2-recipes-part-1.html</a>)<br />
</strong></li>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">XIEventMask eventmask<span style="color: #339933;">;</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> mask<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000dd;">0</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* the actual mask */</span>
&nbsp;
eventmask.<span style="color: #202020;">deviceid</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
eventmask.<span style="color: #202020;">mask_len</span> <span style="color: #339933;">=</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>mask<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* always in bytes */</span>
eventmask.<span style="color: #202020;">mask</span> <span style="color: #339933;">=</span> mask<span style="color: #339933;">;</span>
<span style="color: #808080; font-style: italic;">/* now set the mask */</span>
XISetMask<span style="color: #009900;">&#40;</span>mask<span style="color: #339933;">,</span> XI_ButtonPress<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
XISetMask<span style="color: #009900;">&#40;</span>mask<span style="color: #339933;">,</span> XI_Motion<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
XISetMask<span style="color: #009900;">&#40;</span>mask<span style="color: #339933;">,</span> XI_KeyPress<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* select on the window */</span>
XISelectEvents<span style="color: #009900;">&#40;</span>display<span style="color: #339933;">,</span> window<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>eventmask<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</ul>
<h3>Event Processing &#8211; Listening/Processing Events</h3>
<p>A simple indication how to get events from XI1 and XI2</p>
<ul>
<li><strong>XInput 1: </strong>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//setup via other means</span>
<span style="color: #993333;">int</span> motion_type<span style="color: #339933;">,</span> button_press_type<span style="color: #339933;">,</span>button_release_type<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> doEvents<span style="color: #009900;">&#40;</span>Display    <span style="color: #339933;">*</span>dpy<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
 XEvent        Event<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        XNextEvent<span style="color: #009900;">&#40;</span>dpy<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>Event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>Event.<span style="color: #202020;">type</span> <span style="color: #339933;">==</span> motion_type<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            XDeviceMotionEvent <span style="color: #339933;">*</span>motion <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>XDeviceMotionEvent <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>Event<span style="color: #339933;">;</span>
            ...
&nbsp;
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>Event.<span style="color: #202020;">type</span> <span style="color: #339933;">==</span> button_press_type<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span>
                   <span style="color: #009900;">&#40;</span>Event.<span style="color: #202020;">type</span> <span style="color: #339933;">==</span> button_release_type<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                      XDeviceButtonEvent <span style="color: #339933;">*</span>button <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>XDeviceButtonEvent <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>Event<span style="color: #339933;">;</span>
&nbsp;
            ...
        <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>Event.<span style="color: #202020;">type</span><span style="color: #339933;">=</span> .... <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            ...
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</li>
<li><strong>XInput 2 </strong><strong> </strong>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Somewhere else...</span>
&nbsp;
<span style="color: #993333;">int</span> xi_opcode<span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>XQueryExtension<span style="color: #009900;">&#40;</span>display<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;XInputExtension&quot;</span><span style="color: #339933;">,&amp;</span>xi_opcode<span style="color: #339933;">,&amp;</span>event<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>error<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;X Input extension not available.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> EXIT_FAILURE<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong> </strong></p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> doEvents <span style="color: #009900;">&#40;</span>Display <span style="color: #339933;">*</span>dpy <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        XEvent        ev<span style="color: #339933;">;</span>
        XGenericEventCookie <span style="color: #339933;">*</span>cookie <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>ev.<span style="color: #202020;">xcookie</span><span style="color: #339933;">;</span>
        XNextEvent<span style="color: #009900;">&#40;</span>dpy<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>ev<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>XGetEventData<span style="color: #009900;">&#40;</span>dpy<span style="color: #339933;">,</span> cookie<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> cookie<span style="color: #339933;">-&gt;</span>type <span style="color: #339933;">==</span> GenericEvent
            <span style="color: #339933;">&amp;&amp;</span> cookie<span style="color: #339933;">-&gt;</span>extension<span style="color: #339933;">==</span>xi_opcode<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            XIDeviceEvent <span style="color: #339933;">*</span>event <span style="color: #339933;">=</span> cookie<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;EVENT type %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> event<span style="color: #339933;">-&gt;</span>evtype<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>event<span style="color: #339933;">-&gt;</span>evtype<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">//</span>
                <span style="color: #666666; font-style: italic;">// In all below event&gt;deviceid contains the id of the device</span>
                <span style="color: #666666; font-style: italic;">//</span>
                <span style="color: #b1b100;">case</span> XI_DeviceChanged<span style="color: #339933;">:</span>
                    XIDeviceChangedEvent <span style="color: #339933;">*</span>dc <span style="color: #339933;">=</span> cookie<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">;</span>
                    ...
                    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">case</span> XI_HierarchyChanged<span style="color: #339933;">:</span>
                    XIHierarchyEvent <span style="color: #339933;">*</span>he <span style="color: #339933;">=</span> cookie<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">;</span>
                    ...
                    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">case</span> XI_RawEvent<span style="color: #339933;">:</span>
                    XIRawEvent <span style="color: #339933;">*</span>re <span style="color: #339933;">=</span> cookie<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">;</span>
                    ...
                    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">case</span> XI_FocusIn<span style="color: #339933;">:</span>
                <span style="color: #b1b100;">case</span> XI_Enter<span style="color: #339933;">:</span>
                    XIEnterEvent <span style="color: #339933;">*</span>ee <span style="color: #339933;">=</span> cookie<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">;</span>
                    ...
                    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">case</span> XI_FocusOut<span style="color: #339933;">:</span>
                <span style="color: #b1b100;">case</span> XI_Leave<span style="color: #339933;">:</span>
                    XILeaveEvent <span style="color: #339933;">*</span>le <span style="color: #339933;">=</span> cookie<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">;</span>
                    ...
                    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">case</span> XI_PropertyEvent<span style="color: #339933;">:</span>
                    XIPropertyEvent <span style="color: #339933;">*</span>pe <span style="color: #339933;">=</span> cookie<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">;</span>
                    ...
                    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">case</span> XI_Motion<span style="color: #339933;">:</span>
                <span style="color: #b1b100;">case</span> XI_ButtonPress<span style="color: #339933;">:</span>
                <span style="color: #b1b100;">case</span> XI_ButtonRelease<span style="color: #339933;">:</span>
                <span style="color: #b1b100;">case</span> XI_KeyPress<span style="color: #339933;">:</span>
                <span style="color: #b1b100;">case</span> XI_KeyRelease<span style="color: #339933;">:</span>
                    <span style="color: #666666; font-style: italic;">// do something with event (XIDeviceEvent contains data)</span>
                    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.clearchain.com/blog/posts/xinput-1-xinput-2-conversion-guide/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adding Multiple Mice Support to FLTK using MPX</title>
		<link>http://www.clearchain.com/blog/posts/adding-multiple-mice-support-to-fltk-using-mpx</link>
		<comments>http://www.clearchain.com/blog/posts/adding-multiple-mice-support-to-fltk-using-mpx#comments</comments>
		<pubDate>Tue, 25 Nov 2008 06:53:07 +0000</pubDate>
		<dc:creator>Benjamin Close</dc:creator>
				<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[UniSA]]></category>
		<category><![CDATA[fltk]]></category>
		<category><![CDATA[MPX]]></category>
		<category><![CDATA[multiple mice]]></category>
		<category><![CDATA[toolkit]]></category>
		<category><![CDATA[win32]]></category>

		<guid isPermaLink="false">http://www.clearchain.com/blog/?p=146</guid>
		<description><![CDATA[Details about adding multiple mice support to the FLTK toolkit]]></description>
			<content:encoded><![CDATA[<p>For a while now I&#8217;ve been working on modifying <a href="http://fltk.org">FLTK</a> to support multiple Mice. We need this functionality for applications we are working on. FLTK was chosen for a number of reasons. </p>
<ol>
<li>It&#8217;s light weight</li>
<li>It&#8217;s cross platform</li>
<li>It was already in use by the applications being extended.</li>
</ol>
<div>However, FLTK didn&#8217;t support multiple mice out the box. Multiple Mice support exists both under Win32 via the RAWINPUT api and under <a href="http://www.x.org">Xorg</a> via <a href="http://wearables.unisa.edu.au/mpx">MPX</a>.</div>
<div>Though support in the various toolkits is still lacking. Not surprizing considering how recent MPX/RAWINPUT is.</div>
<p><span id="more-146"></span></p>
<div>MPX was the natural choice for the first implementation of multiple choice in a toolkit. </div>
<div>MPX is built into the windowing system hence focus, grabs and cursor rending is all semi transparently delt with where as RAWINPUT has you doing most the work yourself.</div>
<div>Hence I set about modifying FLTK to support Multiple Mice using MPX.</div>
<div>Results so far have been quite good. Due to FLTK internally doing most of it&#8217;s own component hit testing, having to deal with a window per component wasn&#8217;t needed. Instead a simple API extending the existing toolkit has been created.</div>
<div>The patch implementing this API and the relevant glue to use it is available at: <a href="http://wcl.ml.unisa.edu.au/~closebs/downloads/fltk-1.3-mpx.patch">http://wcl.ml.unisa.edu.au/~closebs/downloads/fltk-1.3-mpx.patch</a></div>
<div>This patch against the current 1.3 SVN (rev 6524) development branch and provides the following API extensions:</div>
<div>Creation of FL/Fl_Mouse.H which defines two important types:</div>
<div><strong><span style="text-decoration: underline;">Types:</span></strong></div>
<div>
<ul>
<li>FL_MouseID <span style="white-space:pre"> </span>- A type indicating the id of a mouse</li>
<li>FL_Mouse  <span style="white-space:pre"> </span>- A type that records information about a mouse (ie x, y, button state, etc)</li>
</ul>
<div><span style="text-decoration: underline;"><strong>Functions/Variables</strong></span></div>
</div>
<div>New functions/variarables in FL/Fl.H</div>
<div>
<ul>
<li>FL::e_mouse_id       <span style="white-space:pre"> </span>- The id of the last mouse to cause an event</li>
<li>FL::e_last_mouseid <span style="white-space:pre"> </span>- The id of the last mouse in the system</li>
<li>Fl::grab(Fl_MouseID)- Put a grab on a specific mouse</li>
<li>Fl::get_last_mouseid- Return the ID of the last mouse know to the toolkit</li>
<li>Fl::create_mouse()<span style="white-space:pre"> </span>- Register a new mouse with the toolkit</li>
<li>Fl::event_mouse_id()- Return the id of the mouse that caused the last event</li>
</ul>
<div>There has also been a number of changes to existing functions but all in a way which should be API compatible &#8211; sadly not ABI compatible.</div>
</div>
<div>These changes basically support passing in mouse id&#8217;s or storage of grabs/focus per mouse, etc.</div>
<div>There&#8217;s also been a test application created: test/multiplemice</div>
<div>This application, whilst very simple shows an example use of the MULTIPLE_MICE functionality. In it you can use two mice to drag two FLTK widgets around at the same time. </div>
<h2>I want to try</h2>
<p>If you want to give the FLTK changes a shot it&#8217;s fairly simple all you have to do is:</p>
<p> </p>
<ul>
<li>Build a version of Xorg with MPX support (see <a href="http://wearables.unisa.edu.au/mpx">http://wearables.unisa.edu.au/mpx</a>) for details.</li>
<li>Build a version of xinput with MPX support
<ul>
<li>This will allow you to create multiple mice via<br />
xinput create-master mymouse<br />
xinput list &#8211;short       # Take note of one of the mouse id&#8217;s, lets call it x and mymouse id y <br />
xinput reattach  x y</li>
</ul>
</li>
<li>Grab the latest version of the 1.3 branch of FLTK from SVN (<a href="http://fltk.org/svn.php">http://fltk.org/svn.php)</a></li>
<li>Apply the patch at <a href="http://wcl.ml.unisa.edu.au/~closebs/downloads/fltk-1.3-mpx.patch">http://wcl.ml.unisa.edu.au/~closebs/downloads/fltk-1.3-mpx.patch</a>
<ul>
<li>patch -p0 &lt; fltk-1.3-mpx.patch</li>
</ul>
</li>
<li>Configure with multiple mice support: ./configure &#8211;enable-multiplemice</li>
<li>Build the toolkit: make</li>
<li>Test the multiple mice application: test/multiplemice</li>
</ul>
<p> </p>
<h2>Future</h2>
<p>Win32 support is currently under way with large chunks being already done. Though the lack of native cursor rendering under Win32 is causing greif. Other patches not far around the corner are a custom cursor patch, which allows a custom cursor per mouse as well as the ability to capture input events from the toolkit and inject input events into the toolkit &#8211; great for distributed event reconstruction.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.clearchain.com/blog/posts/adding-multiple-mice-support-to-fltk-using-mpx/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MPX &amp; XTst</title>
		<link>http://www.clearchain.com/blog/posts/mpx-xtst</link>
		<comments>http://www.clearchain.com/blog/posts/mpx-xtst#comments</comments>
		<pubDate>Thu, 13 Nov 2008 13:20:40 +0000</pubDate>
		<dc:creator>Benjamin Close</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[FreeDesktop]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[MPX]]></category>
		<category><![CDATA[multitouch]]></category>
		<category><![CDATA[XTst]]></category>

		<guid isPermaLink="false">http://www.clearchain.com/blog/posts/mpx-xtst</guid>
		<description><![CDATA[MPX is a modification of the Xorg X Windowing system created by Peter Hutterer whilst doing his PHD in the Wearable Computer Lab, at the University of South Australia. It allows independent device control and contains a number of different API enhancements to support these. You can find more about MPX at: http://wearables.unisa.edu.au/mpx/ Some of [...]]]></description>
			<content:encoded><![CDATA[<p><span class="glossary" title="Multi Pointer X Server - http://en.wikipedia.org/wiki/MPX">MPX</span> is a modification of the <a class="external text" title="http://www.x.org" rel="nofollow" href="http://www.x.org/">Xorg</a> X Windowing system created by Peter Hutterer whilst doing his PHD in the <a class="external text" title="http://wearable.unisa.edu.au" rel="nofollow" href="http://wearables.unisa.edu.au/">Wearable Computer Lab</a>, at the University of South Australia.</p>
<p>It allows independent device control and contains a number of different API enhancements to support these.</p>
<p>You can find more about <span class="glossary" title="Multi Pointer X Server - http://en.wikipedia.org/wiki/MPX">MPX</span> at: <a class="external free" title="http://wearables.unisa.edu.au/mpx/" rel="nofollow" href="http://wearables.unisa.edu.au/mpx/">http://wearables.unisa.edu.au/mpx/</a></p>
<p>Some of the new symbols defined are:</p>
<ul>
<li> XTestFakeDeviceButton</li>
<li> XTestFakeDeviceButtonEvent</li>
<li> XTestFakeDeviceMotionEvent</li>
<li> XTestFakeProximityEvent</li>
<li> XtestFakeDeviceKeyEvent.</li>
</ul>
<p>These are in the xtst library: <a class="external free" title="http://cgit.freedesktop.org/xorg/libs/xtst/" rel="nofollow" href="http://cgit.freedesktop.org/xorg/libs/xtst/">http://cgit.freedesktop.org/xorg/libs/xtst/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clearchain.com/blog/posts/mpx-xtst/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
