XInput2: getting window-relative coordinates?

Peter Hutterer peter.hutterer at who-t.net
Sun Apr 19 03:45:34 PDT 2009


On Sat, Apr 18, 2009 at 10:54:31AM +0200, Florian Echtler wrote:
> > > However, the second one (controlled by touchpad) reports values in the
> > > range (1472,1408) to (5472,4448). This is also reported in the Xorg.log
> > > by the synaptics driver. How can I map these to screen coordinates? As
> > > the pointer still moves in screen coordinates, the mapping must already
> > > exist somewhere, I assume.. 
> > > I know that this is quite beta still, so I'd be very grateful about some
> > > hints..
> > right, so the rule for coordinates is:
> > event_x,event_y, root_x, root_y are in absolute screen coordinates. or should
> > be anyway.
> Okay, sounds good. However, there seem to be some glitches hidden
> somewhere. I'm running libXi, inputproto, xinput and xorg-server from
> Peter's repo and libXext, libX11, libxcb, xproto, xcb-proto and
> xextproto from master. The rest is from the Gentoo stable distro.
> 
> - for XI_Enter/XI_Leave, this looks as expected, with one exception.
>   Here's what "xinput test-xi2" shows for those events:
> 
>   EVENT type 7
>     windows: root 0x7e event 0x3600001 child 0x0
>     mode: NotifyNormal (detail NotifyAncestor)
>     flags:  [same screen]
>     buttons:
>     modifiers: locked 0x0 latched 0x0 base 0x0
>     group: locked 0x0 latched 0x0 base 0x0
>     root x/y:  134.00 / 243.00
>     event x/y: 133.00 / 133.00
> 
>   Note that event x/y are equal. This is _always_ the case, and always
>   corresponds to the window-local x coordinate. I grepped through libXi,
>   but couldn't find anything obviously wrong. 

test_xi2.c in xinput has a wrong parameter to printf in print_enterleave,
single-character fix :)

> - for XI_Motion, the root x/y and event x/y fields are always (0/0) and
>   (-372/-372), sometimes also (0/0) and (-1/-1). Should these fields be
>   also valid for XI_Motion?

oops, two missing lines in dix/eventconvert.c, fixed locally, will be pushed
soon.
 
> > the data in *valuators OTOH is in device-coordinates. this may be screen
> > coordinates for relative devices, and device coordinates for absolute devices.
> > You need to get the axis information through XIQueryDevice() first, and do the
> > scaling on the client-side if you need it.
> Ah, okay. Does it matter whether I select AllDevices or
> AllMasterDevices? Here's the code which I use to select my events:

yes, it matters quite a bit. AllDevices means _all_ devices, i.e. you will get
every event twice - once from the SD, once from the MD. In virtually all cases
this is not what a client needs. AllMasterDevices means events from master
devices only, which is usally what you want if you want to listen to all
devices but you don't care about what's attached to where.

fwiw, registering core events is an implicit version of AllMasterDevices,
because only MDs can send core events.


> FGAPI void FGAPIENTRY glutRegisterDevices() {
> 
> 	XIDeviceEventMask mask;
> 	unsigned char flags[2] = { 0, 0 };
> 
> 	Display* dpy = fgDisplay.Display;
> 	Window* win = glutGetXWindow();
> 
> 	/* Select for motion events */
> 	mask.deviceid = AllMasterDevices;
> 	mask.mask_len = 2;
> 	mask.mask = flags;
> 
> 	SetBit(mask.mask, XI_Enter);
> 	SetBit(mask.mask, XI_Motion);
> 	SetBit(mask.mask, XI_ButtonPress);
> 	SetBit(mask.mask, XI_ButtonRelease);
> 	SetBit(mask.mask, XI_Leave);
> 
> 	XISelectEvent( dpy, *win, &mask, 1 );
> }
> 
> 
> Did I miss anything here?

nope, that's correct.

Cheers,
  Peter



More information about the xorg mailing list