svn merge -r37276:38555 https://svn.blender.org/svnroot/bf-blender/trunk/blender .
[blender-staging.git] / intern / ghost / intern / GHOST_SystemX11.cpp
index f9b365fd62e24e2ab3438c81f159d17aa7a51cf9..ef182a36539cb43422515ebd82ec8fbbd10ec915 100644 (file)
@@ -133,8 +133,9 @@ GHOST_SystemX11(
        if (gettimeofday(&tv,NULL) == -1) {
                GHOST_ASSERT(false,"Could not instantiate timer!");
        }
-
-       m_start_time = GHOST_TUns64(tv.tv_sec*1000 + tv.tv_usec/1000);
+       
+       // Taking care not to overflow the tv.tv_sec*1000
+       m_start_time = GHOST_TUns64(tv.tv_sec)*1000 + tv.tv_usec/1000;
        
        
        /* use detectable autorepeate, mac and windows also do this */
@@ -183,7 +184,8 @@ getMilliSeconds(
                GHOST_ASSERT(false,"Could not compute time!");
        }
 
-       return  GHOST_TUns64(tv.tv_sec*1000 + tv.tv_usec/1000) - m_start_time;
+       // Taking care not to overflow the tv.tv_sec*1000
+       return  GHOST_TUns64(tv.tv_sec)*1000 + tv.tv_usec/1000 - m_start_time;
 }
        
        GHOST_TUns8 
@@ -837,60 +839,28 @@ getModifierKeys(
        // now translate key symobols into keycodes and
        // test with vector.
 
-       const KeyCode shift_l = XKeysymToKeycode(m_display,XK_Shift_L);
-       const KeyCode shift_r = XKeysymToKeycode(m_display,XK_Shift_R);
-       const KeyCode control_l = XKeysymToKeycode(m_display,XK_Control_L);
-       const KeyCode control_r = XKeysymToKeycode(m_display,XK_Control_R);
-       const KeyCode alt_l = XKeysymToKeycode(m_display,XK_Alt_L);
-       const KeyCode alt_r = XKeysymToKeycode(m_display,XK_Alt_R);
-       const KeyCode super_l = XKeysymToKeycode(m_display,XK_Super_L);
-       const KeyCode super_r = XKeysymToKeycode(m_display,XK_Super_R);
-
-       // Shift
-       if ((m_keyboard_vector[shift_l >> 3] >> (shift_l & 7)) & 1) {
-               keys.set(GHOST_kModifierKeyLeftShift,true);
-       } else {
-               keys.set(GHOST_kModifierKeyLeftShift,false);
-       }
-       if ((m_keyboard_vector[shift_r >> 3] >> (shift_r & 7)) & 1) {
-
-               keys.set(GHOST_kModifierKeyRightShift,true);
-       } else {
-               keys.set(GHOST_kModifierKeyRightShift,false);
-       }
-
-       // control (weep)
-       if ((m_keyboard_vector[control_l >> 3] >> (control_l & 7)) & 1) {
-               keys.set(GHOST_kModifierKeyLeftControl,true);
-       } else {
-               keys.set(GHOST_kModifierKeyLeftControl,false);
-       }
-       if ((m_keyboard_vector[control_r >> 3] >> (control_r & 7)) & 1) {
-               keys.set(GHOST_kModifierKeyRightControl,true);
-       } else {
-               keys.set(GHOST_kModifierKeyRightControl,false);
-       }
-
-       // Alt (yawn)
-       if ((m_keyboard_vector[alt_l >> 3] >> (alt_l & 7)) & 1) {
-               keys.set(GHOST_kModifierKeyLeftAlt,true);
-       } else {
-               keys.set(GHOST_kModifierKeyLeftAlt,false);
-       }       
-       if ((m_keyboard_vector[alt_r >> 3] >> (alt_r & 7)) & 1) {
-               keys.set(GHOST_kModifierKeyRightAlt,true);
-       } else {
-               keys.set(GHOST_kModifierKeyRightAlt,false);
-       }
+       const static KeyCode shift_l = XKeysymToKeycode(m_display,XK_Shift_L);
+       const static KeyCode shift_r = XKeysymToKeycode(m_display,XK_Shift_R);
+       const static KeyCode control_l = XKeysymToKeycode(m_display,XK_Control_L);
+       const static KeyCode control_r = XKeysymToKeycode(m_display,XK_Control_R);
+       const static KeyCode alt_l = XKeysymToKeycode(m_display,XK_Alt_L);
+       const static KeyCode alt_r = XKeysymToKeycode(m_display,XK_Alt_R);
+       const static KeyCode super_l = XKeysymToKeycode(m_display,XK_Super_L);
+       const static KeyCode super_r = XKeysymToKeycode(m_display,XK_Super_R);
+
+       // shift
+       keys.set(GHOST_kModifierKeyLeftShift, ((m_keyboard_vector[shift_l >> 3] >> (shift_l & 7)) & 1) != 0);
+       keys.set(GHOST_kModifierKeyRightShift, ((m_keyboard_vector[shift_r >> 3] >> (shift_r & 7)) & 1) != 0);
+       // control
+       keys.set(GHOST_kModifierKeyLeftControl, ((m_keyboard_vector[control_l >> 3] >> (control_l & 7)) & 1) != 0);
+       keys.set(GHOST_kModifierKeyRightControl, ((m_keyboard_vector[control_r >> 3] >> (control_r & 7)) & 1) != 0);
+       // alt
+       keys.set(GHOST_kModifierKeyLeftAlt, ((m_keyboard_vector[alt_l >> 3] >> (alt_l & 7)) & 1) != 0);
+       keys.set(GHOST_kModifierKeyRightAlt, ((m_keyboard_vector[alt_r >> 3] >> (alt_r & 7)) & 1) != 0);
+       // super (windows) - only one GHOST-kModifierKeyOS, so mapping to either
+       keys.set(GHOST_kModifierKeyOS, ( ((m_keyboard_vector[super_l >> 3] >> (super_l & 7)) & 1) ||
+                                        ((m_keyboard_vector[super_r >> 3] >> (super_r & 7)) & 1) ) != 0);
 
-       // Super (Windows) - only one GHOST-kModifierKeyOS, so mapping
-       // to either
-       if ( ((m_keyboard_vector[super_l >> 3] >> (super_l & 7)) & 1) || 
-            ((m_keyboard_vector[super_r >> 3] >> (super_r & 7)) & 1) ) {
-               keys.set(GHOST_kModifierKeyOS,true);
-       } else {
-               keys.set(GHOST_kModifierKeyOS,false);
-       }
        return GHOST_kSuccess;
 }
 
@@ -904,35 +874,20 @@ getButtons(
        int rx,ry,wx,wy;
        unsigned int mask_return;
 
-       if (XQueryPointer(
-               m_display,
-               RootWindow(m_display,DefaultScreen(m_display)),
-               &root_return,
-               &child_return,
-               &rx,&ry,
-               &wx,&wy,
-               &mask_return
-       ) == False) {
+       if (XQueryPointer(m_display,
+                         RootWindow(m_display,DefaultScreen(m_display)),
+                         &root_return,
+                         &child_return,
+                         &rx,&ry,
+                         &wx,&wy,
+                         &mask_return) == True)
+       {
+               buttons.set(GHOST_kButtonMaskLeft,   (mask_return & Button1Mask) != 0);
+               buttons.set(GHOST_kButtonMaskMiddle, (mask_return & Button2Mask) != 0);
+               buttons.set(GHOST_kButtonMaskRight,  (mask_return & Button3Mask) != 0);
+       }
+       else {
                return GHOST_kFailure;
-       } else {
-
-               if (mask_return & Button1Mask) {
-                       buttons.set(GHOST_kButtonMaskLeft,true);
-               } else {
-                       buttons.set(GHOST_kButtonMaskLeft,false);
-               }
-
-               if (mask_return & Button2Mask) {
-                       buttons.set(GHOST_kButtonMaskMiddle,true);
-               } else {
-                       buttons.set(GHOST_kButtonMaskMiddle,false);
-               }
-
-               if (mask_return & Button3Mask) {
-                       buttons.set(GHOST_kButtonMaskRight,true);
-               } else {
-                       buttons.set(GHOST_kButtonMaskRight,false);
-               }
        }       
 
        return GHOST_kSuccess;
@@ -1037,11 +992,9 @@ generateWindowExposeEvents(
 
 #define GXMAP(k,x,y) case x: k = y; break; 
 
-       GHOST_TKey
-GHOST_SystemX11::
-convertXKey(
-       KeySym key
-){
+static GHOST_TKey
+convertXKey(KeySym key)
+{
        GHOST_TKey type;
 
        if ((key >= XK_A) && (key <= XK_Z)) {
@@ -1156,7 +1109,9 @@ convertXKey(
                        GXMAP(type,XF86XK_AudioPrev,    GHOST_kKeyMediaFirst);
                        GXMAP(type,XF86XK_AudioRewind,  GHOST_kKeyMediaFirst);
                        GXMAP(type,XF86XK_AudioNext,    GHOST_kKeyMediaLast);
+#ifdef XF86XK_AudioForward /* Debian lenny's XF86keysym.h has no XF86XK_AudioForward define */
                        GXMAP(type,XF86XK_AudioForward, GHOST_kKeyMediaLast);
+#endif
 #endif
 
                                /* some extra sun cruft (NICE KEYBOARD!) */