Discussion:
[Xcb] Xinput: units of the coordinates in motion-events?
Christophe Lohr
2018-10-25 15:28:13 UTC
Permalink
Hi,
  I'm trying to use xinput to get pointer position (see attached code)

I h'ave a question about the type used to return coordinates. How to
convert this xcb_input_fp1616_t into a float?

According to specification
(https://www.x.org/releases/X11R7.7/doc/inputproto/XI2proto.txt):

FP1616
Fixed point decimal in 16.16 format as one INT16 and one CARD16.
The INT16 contains the integral part, the CARD16 the decimal fraction
shifted by 16.


So, ok the higher 16bits is the coordinate in terms of pixels on the
window (a signed 16bits integer)

But what's about the lower 16bits (an unsigned 16 bits interger)?
This supposes to count fractions. But fractions of what?  Of portions
of  1 / 2^16  pixel ?
Shifted by 16... but 16 bits? to the left? right? to do what?

Simply speaking, how to convert a FP1616 into a float?
(I just have to do  FP1616 / 2^16 )?

Many thanks
Regards
Uli Schlachter
2018-10-25 16:12:33 UTC
Permalink
Hi,
Post by Christophe Lohr
Simply speaking, how to convert a FP1616 into a float?
(I just have to do  FP1616 / 2^16 )?
...yes. Is there any problem with just doing that?

See e.g. https://en.wikipedia.org/wiki/Fixed-point_arithmetic on fixed
point numbers.

In xinput.h, xcb_input_fp1616_t is a typedef for int32_t. So, you can do
the conversion e.g. via:

float f = wire_value / 65536.0

Since the code that you sent already does this: What is your actual problem?

Cheers,
Uli
--
"Why make things difficult, when it is possible to make them cryptic
and totally illogical, with just a little bit more effort?" -- A. P. J.
Christophe Lohr
2018-10-25 19:02:00 UTC
Permalink
Post by Uli Schlachter
Post by Christophe Lohr
Simply speaking, how to convert a FP1616 into a float?
(I just have to do  FP1616 / 2^16 )?
...yes. Is there any problem with just doing that?
See e.g. https://en.wikipedia.org/wiki/Fixed-point_arithmetic on fixed
point numbers.
oups
"fixed point": the specification yet clearly tell it
I didn't catch it ;-) Sorry
Many thanks for your patience

Regards
Christophe Lohr
2018-10-26 09:54:50 UTC
Permalink
Hi,
  May I ask another question on how to manage the scroll wheel with Xinput?
I have noticed that this triggers  XCB_INPUT_MOTION events also (and not
only button events). This is the "Z" axis.

I should get information via the "Valuators", isn't it?
(https://www.x.org/releases/X11R7.7/doc/inputproto/XI2proto.txt)

How to get Valuators that are reported on motion events?

Best regards
Uli Schlachter
2018-10-26 16:44:22 UTC
Permalink
Post by Christophe Lohr
Hi,
Hi again,
Post by Christophe Lohr
  May I ask another question on how to manage the scroll wheel with Xinput?
I have noticed that this triggers  XCB_INPUT_MOTION events also (and not
only button events). This is the "Z" axis.
I should get information via the "Valuators", isn't it?
(https://www.x.org/releases/X11R7.7/doc/inputproto/XI2proto.txt)
How to get Valuators that are reported on motion events?
I do not really know much about xinput. Via Google, I found "xinput
--test-xi2 --root". This prints out events that are received. So, now I
know at least what to look for. :-)

For me, the mouse wheel generates three events: ButtonPress,
ButtonRelease (both with flags: emulated) and a Motion event that looks
like this:

EVENT type 6 (Motion)
device: 2 (10)
detail: 0
flags:
root: 1057.09/539.66
event: 1057.09/539.66
buttons:
modifiers: locked 0x10 latched 0 base 0 effective: 0x10
group: locked 0 latched 0 base 0 effective: 0
valuators:
3: 66570.00
windows: root 0x14d event 0x14d child 0xa002f8

Running "xinput --test-xi2 --root" under xtrace produces the following
output for this:

000:>:0012: Event Generic(35) XInputExtension(131) Motion(6)
deviceid=0x02 time=0x0728377f detail=0x00000000 root=0x0000014d
event=0x0000014d child=0x00a002f8 root_x=1057.087524 root_y=539.655518
event_x=1057.087524 event_y=539.655518 sourceid=0x000a flags=0x00000000
mods={base_mods=0x00000000 latched_mods=0x00000000
locked_mods=0x00000010 effective_mods=0x00000010};
group={base_group=0x00 latched_group=0x00 locked_group=0x00
effective_group=0x00};
buttons=0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000;
valuators=0x00000008,0x00000000; axisvalues=66570.00000000000;

Uhm, yeah...

Okay, so looking at the code that xcb generates for this... First:

typedef xcb_input_button_press_event_t xcb_input_motion_event_t;

And then there are lots of acessor functions. These seem to be the ones
that could be interesting for you:

uint32_t *
xcb_input_button_press_button_mask (const xcb_input_button_press_event_t
*R);

int
xcb_input_button_press_button_mask_length (const
xcb_input_button_press_event_t *R);

uint32_t *
xcb_input_button_press_valuator_mask (const
xcb_input_button_press_event_t *R);

int
xcb_input_button_press_valuator_mask_length (const
xcb_input_button_press_event_t *R);

xcb_input_fp3232_t *
xcb_input_button_press_axisvalues (const xcb_input_button_press_event_t *R);

int
xcb_input_button_press_axisvalues_length (const
xcb_input_button_press_event_t *R);

So, I guess you have to cast your event to
xcb_input_button_press_event_t and then use these accessors to get all
the data you want out of the event.
Does this somehow help you? Could you test if my guess here is right?

Good luck,
Uli
--
"Why make things difficult, when it is possible to make them cryptic
and totally illogical, with just a little bit more effort?" -- A. P. J.
Christophe Lohr
2018-10-27 14:55:47 UTC
Permalink
Hi Uli,
Post by Uli Schlachter
So, I guess you have to cast your event to
xcb_input_button_press_event_t and then use these accessors to get all
the data you want out of the event.
Does this somehow help you? Could you test if my guess here is right?
Many thanks for your guidance. I have a clearer understanding of the API
now.

Note: I think that methods of the form 'xcb_generic_iterator_t 
xcb_input_FOO_BAR_end()' are not really dedicated to programmer, and are
here for internal purpose, to compute the address of the end of a chunk
of data and subsequently point to the next chunk.
The others methods were more useful for me.

See attached code. I'm rather happy with this.
;-)

Best regards
Christophe

Loading...