implemented ndof 'dead zone' around home position, fixed X11 active window determinat...
authorMike Erwin <significant.bit@gmail.com>
Fri, 1 Jul 2011 21:51:44 +0000 (21:51 +0000)
committerMike Erwin <significant.bit@gmail.com>
Fri, 1 Jul 2011 21:51:44 +0000 (21:51 +0000)
intern/ghost/intern/GHOST_NDOFManager.cpp
intern/ghost/intern/GHOST_SystemX11.cpp
intern/ghost/intern/GHOST_SystemX11.h
source/blender/windowmanager/intern/wm_operators.c

index 54192c0d669edd6c4627270a8e8c9fe7259fc4f9..4d2f06f8191a78024d90816c3af5a4a2611e4fc2 100644 (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;
        }
index 5e59ac91809798e803bcf2c270517ed7b91d92f1..4c62e5e62b4cd0dd997c18eb5a610365833bae6a 100644 (file)
 #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:
index e551b5fb2fe049e7b020beaf4a13a4f2dfcf88fe..f70f67dec184fcdf376974ade86797004aba8326 100644 (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,
index 7d6a50043b5a6ef9637ea3cbf1049f5c8b1b8201..6fb6a8dcf1fdb53eca2c96d5ff916dc7118a862c 100644 (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