+ if (( prop_reply = xcb_get_property_reply ( connection, prop_cookie, NULL ) ))
+ {
+ int len = xcb_get_property_value_length( prop_reply );
+
+ if ( len == 0 )
+ {
+ free(prop_reply);
+ return 0;
+ }
+
+ if ( strcmp( (char *) "Magellan Window", (char *) xcb_get_property_value( prop_reply ) ) != 0 )
+ return 0;
+
+ win = * ( xcb_window_t * ) xcb_get_property_value( prop_reply );
+ }
+
+ free(prop_reply);
+
+ xcbEvent.response_type = XCB_CLIENT_MESSAGE;
+ xcbEvent.format = 16;
+ xcbEvent.sequence = 0;
+ xcbEvent.window = win;
+
+ xcbEvent.data.data16[0] = (short) ((window>>16)&0x0000FFFF);
+ xcbEvent.data.data16[1] = (short) (window&0x0000FFFF);
+ xcbEvent.data.data16[2] = 27695;
+
+ cookie = xcb_send_event( connection, 0, win, 0x0000, (const char *)&xcbEvent );
+
+
+ if (( error = xcb_request_check( connection, cookie )))
+ {
+ if ( error->error_code != BadWindow )
+ {
+ fprintf ( stderr, "SpaceMouse reported error = %d. Exit ... \n", error->error_code);
+ }
+ return 0;
+ }
+
+ xcb_flush(connection);
+
+ return 1;
+}
+
+/*!
+ Close
+*/
+int SVTK_SpaceMouseXCB::close(xcb_connection_t *connection)
+{
+ initialize( connection, (xcb_window_t)InputFocus );
+ spaceMouseOn = 0;
+
+ return 1;
+}
+
+/*!
+ Custom event handler
+*/
+int SVTK_SpaceMouseXCB::translateEvent( xcb_connection_t* connection, xcb_client_message_event_t* xcbEvent, MoveEvent* spaceMouseEvent,
+ double scale, double rScale )
+{
+ if ( !spaceMouseOn )
+ return 0;
+
+ if ( xcbEvent->response_type == XCB_CLIENT_MESSAGE ) {
+ if ( xcbEvent->type == XCBMotionEvent ) {
+ spaceMouseEvent->type = SpaceMouseMove;
+ spaceMouseEvent->data[ x ] =
+ xcbEvent->data.data16[2] * scale;
+ spaceMouseEvent->data[ y ] =
+ xcbEvent->data.data16[3] * scale;
+ spaceMouseEvent->data[ z ] =
+ xcbEvent->data.data16[4] * scale;
+ spaceMouseEvent->data[ a ] =
+ xcbEvent->data.data16[5] * rScale;
+ spaceMouseEvent->data[ b ] =
+ xcbEvent->data.data16[6] * rScale;
+ spaceMouseEvent->data[ c ] =
+ xcbEvent->data.data16[7] * rScale;
+ spaceMouseEvent->period = xcbEvent->data.data16[8];
+ return 1;
+ }
+ else if ( xcbEvent->type == XCBButtonPressEvent ) {
+ spaceMouseEvent->type = SpaceButtonPress;
+ spaceMouseEvent->button = xcbEvent->data.data16[2];
+ return 2;
+ }
+ else if ( xcbEvent->type == XCBButtonReleaseEvent ) {
+ spaceMouseEvent->type = SpaceButtonRelease;
+ spaceMouseEvent->button = xcbEvent->data.data16[2];
+ return 3;
+ }
+ }
+ return (!connection);
+}
+#endif