Xinput: units of the coordinates in motion-events?
Christophe Lohr <christophe.lohr-vHHsQtDGzY/[email protected]> Thu, 25 Oct 2018 17:28:13 +0200
| Newsgroups | gmane.comp.freedesktop.xcb |
|---|---|
| Message-ID | <[email protected]> |
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
_______________________________________________
Xcb mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/xcb
pointer.c
(text/x-csrc, 1.6 KB)
#include <stdio.h>
#include <xcb/xcb.h>
#include <xcb/xinput.h>
#include <inttypes.h>
#include <stdlib.h>
int main () {
xcb_connection_t *c;
xcb_screen_t *screen;
c = xcb_connect(NULL, NULL);
screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
/* Piece of witchery from https://gist.github.com/LemonBoy/dfe1d7ea428794c65b3d */
{
struct {
xcb_input_event_mask_t head;
xcb_input_xi_event_mask_t mask;
} xi_mask;
xi_mask.head.deviceid = XCB_INPUT_DEVICE_ALL;
xi_mask.head.mask_len = sizeof(xi_mask.mask) / sizeof(uint32_t);
xi_mask.mask = XCB_INPUT_XI_EVENT_MASK_MOTION | XCB_INPUT_XI_EVENT_MASK_KEY_PRESS;
// Grab the input events non-invasively using XInput
xcb_input_xi_select_events(c, screen->root, 1, &xi_mask.head);
}
xcb_flush(c);
xcb_generic_event_t *event;
xcb_input_motion_event_t *mot;
while ((event = xcb_wait_for_event(c))) {
switch (event->response_type & ~0x80) {
case XCB_GE_GENERIC: {
switch ( ( (xcb_ge_event_t *)event)->event_type ) {
case XCB_INPUT_MOTION:
mot = (xcb_input_motion_event_t *)event;
printf("x:%f\ty:%f\n", (double)(mot->root_x) / 65535.0 , (double)(mot->root_y) / 65535.0);
//printf("x:%d.%06d\ty:%d.%06d\n", (mot->root_x>>16), (mot->root_x & 0xFFFF), (mot->root_y>>16), (mot->root_y & 0xFFFF));
break;
case XCB_INPUT_KEY_PRESS:
goto end;
break;
default:
break;
}
break;
}
default:
break;
}
free(event);
}
end:
xcb_disconnect(c);
exit(EXIT_SUCCESS);
}