implemented ndof 'dead zone' around home position, fixed X11 active window determination, removed old X11 ndof code

This commit is contained in:
Mike Erwin
2011-07-01 21:51:44 +00:00
parent abd4a881db
commit 14c72f379c
4 changed files with 31 additions and 69 deletions

View File

@@ -27,6 +27,7 @@
#include "GHOST_WindowManager.h"
#include <string.h> // for memory functions
#include <stdio.h> // for error/info reporting
#include <math.h>
#ifdef DEBUG_NDOF_BUTTONS
static const char* ndof_button_names[] = {
@@ -301,6 +302,12 @@ void GHOST_NDOFManager::updateButtons(int button_bits, GHOST_TUns64 time)
}
}
static bool atHomePosition(GHOST_TEventNDOFMotionData* ndof, float threshold)
{
#define HOME(foo) (fabsf(ndof->foo) < threshold)
return HOME(tx) && HOME(ty) && HOME(tz) && HOME(rx) && HOME(ry) && HOME(rz);
}
bool GHOST_NDOFManager::sendMotionEvent()
{
if (m_atRest)
@@ -336,9 +343,7 @@ bool GHOST_NDOFManager::sendMotionEvent()
m_system.pushEvent(event);
// 'at rest' test goes at the end so that the first 'rest' event gets sent
m_atRest = m_rotation[0] == 0 && m_rotation[1] == 0 && m_rotation[2] == 0 &&
m_translation[0] == 0 && m_translation[1] == 0 && m_translation[2] == 0;
// this needs to be aware of calibration -- 0.01 0.01 0.03 might be 'rest'
m_atRest = atHomePosition(data, 0.05f);
return true;
}

View File

@@ -75,22 +75,6 @@
#include <stdio.h> // for fprintf only
#include <cstdlib> // for exit
#if 0 // obsolete SpaceNav code
typedef struct NDOFPlatformInfo {
Display *display;
Window window;
volatile GHOST_TEventNDOFData *currValues;
Atom cmdAtom;
Atom motionAtom;
Atom btnPressAtom;
Atom btnRelAtom;
} NDOFPlatformInfo;
static NDOFPlatformInfo sNdofInfo = {NULL, 0, NULL, 0, 0, 0, 0};
#endif
//these are for copy and select copy
static char *txt_cut_buffer= NULL;
static char *txt_select_buffer= NULL;
@@ -612,6 +596,8 @@ GHOST_SystemX11::processEvent(XEvent *xe)
case FocusOut:
{
XFocusChangeEvent &xfe = xe->xfocus;
printf("X: focus %s for window %d\n", xfe.type == FocusIn ? "in" : "out", (int) xfe.window);
// May have to look at the type of event and filter some
// out.
@@ -643,36 +629,6 @@ GHOST_SystemX11::processEvent(XEvent *xe)
} else
#endif
#if 0 // obsolete SpaceNav code
if (sNdofInfo.currValues) {
static GHOST_TEventNDOFData data = {0,0,0,0,0,0,0,0,0,0,0};
if (xcme.message_type == sNdofInfo.motionAtom)
{
data.changed = 1;
data.delta = xcme.data.s[8] - data.time;
data.time = xcme.data.s[8];
data.tx = xcme.data.s[2] >> 2;
data.ty = xcme.data.s[3] >> 2;
data.tz = xcme.data.s[4] >> 2;
data.rx = xcme.data.s[5];
data.ry = xcme.data.s[6];
data.rz =-xcme.data.s[7];
g_event = new GHOST_EventNDOF(getMilliSeconds(),
GHOST_kEventNDOFMotion,
window, data);
} else if (xcme.message_type == sNdofInfo.btnPressAtom) {
data.changed = 2;
data.delta = xcme.data.s[8] - data.time;
data.time = xcme.data.s[8];
data.buttons = xcme.data.s[2];
g_event = new GHOST_EventNDOF(getMilliSeconds(),
GHOST_kEventNDOFButton,
window, data);
}
#endif
if (((Atom)xcme.data.l[0]) == m_wm_take_focus) {
XWindowAttributes attr;
Window fwin;
@@ -730,6 +686,14 @@ GHOST_SystemX11::processEvent(XEvent *xe)
xce.y_root
);
}
printf("X: %s window %d\n", xce.type == EnterNotify ? "entering" : "leaving", (int) xce.window);
if (xce.type == EnterNotify)
m_windowManager->setActiveWindow(window);
else
m_windowManager->setWindowInactive(window);
break;
}
case MapNotify:

View File

@@ -203,15 +203,6 @@ public:
return m_display;
}
#if 0 // obsolete SpaceNav code
void *
prepareNdofInfo(
volatile GHOST_TEventNDOFData *current_values
);
#endif
/* Helped function for get data from the clipboard. */
void getClipboard_xcout(XEvent evt, Atom sel, Atom target,
unsigned char **txt, unsigned long *len,

View File

@@ -1376,6 +1376,7 @@ static void WM_OT_search_menu(wmOperatorType *ot)
// BEGIN ndof menu -- experimental!
#if 0
static uiBlock* wm_block_ndof_menu_1st(bContext* C, ARegion* ar, void* UNUSED(arg_op))
{
uiBlock* block;
@@ -1448,9 +1449,17 @@ static int wm_ndof_menu_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
puts("ndof: menu exec");
return OPERATOR_FINISHED;
}
#endif
static int wm_ndof_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
{
// uiPupMenuNotice(C, "Hello!"); // <-- this works
// uiPupBlock(C, wm_block_ndof_menu, op); // <-- no luck!
// ui_popup_menu_create(C, NULL, NULL, NULL, NULL, "Hello!"); // <-- this works
uiPopupMenu* pup = uiPupMenuBegin(C,"3D mouse settings",ICON_NDOF_TURN);
uiLayout* layout = uiPupMenuLayout(pup);
printf("ndof: menu invoked in ");
switch (CTX_wm_area(C)->spacetype) // diff spaces can have diff 3d mouse options
@@ -1465,12 +1474,6 @@ static int wm_ndof_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(even
puts("some iNDOFferent area");
}
// uiPupMenuNotice(C, "Hello!"); // <-- this works
// uiPupBlock(C, wm_block_ndof_menu, op); // <-- no luck!
// ui_popup_menu_create(C, NULL, NULL, NULL, NULL, "Hello!"); // <-- this works
uiPopupMenu* pup = uiPupMenuBegin(C,"3D mouse settings",ICON_NDOF_TURN);
uiLayout* layout = uiPupMenuLayout(pup);
//uiBlock* block = uiLayoutGetBlock(layout);
//int foo = 1;
@@ -1495,12 +1498,11 @@ static int wm_ndof_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(even
static void WM_OT_ndof_menu(wmOperatorType *ot)
{
puts("ndof: registering menu operator");
ot->name= "NDOF Menu";
ot->idname= "WM_OT_ndof_menu";
ot->name = "NDOF Menu";
ot->idname = "WM_OT_ndof_menu";
ot->invoke= wm_ndof_menu_invoke;
// ot->exec= wm_ndof_menu_exec;
// ot->poll= wm_ndof_menu_poll;
ot->invoke = wm_ndof_menu_invoke;
}
// END ndof menu