Cocoa : activate multitouch trackpad features only on equipped macbooks
authorDamien Plisson <damien.plisson@yahoo.fr>
Tue, 12 Jan 2010 14:12:44 +0000 (14:12 +0000)
committerDamien Plisson <damien.plisson@yahoo.fr>
Tue, 12 Jan 2010 14:12:44 +0000 (14:12 +0000)
intern/ghost/intern/GHOST_SystemCocoa.h
intern/ghost/intern/GHOST_SystemCocoa.mm

index 5b78f9b8fa3ef9fbf59a3a22626444e653e6a5d4..23a945f4b76a839306147f974c259022f68de64f 100644 (file)
@@ -277,6 +277,9 @@ protected:
         * Needed because cocoa event delta cursor move takes setCursorPosition changes too.
         */
        GHOST_TInt32 m_cursorDelta_x, m_cursorDelta_y;
+       
+       /** Multitouch trackpad availability */
+       bool m_hasMultiTouchTrackpad;
 };
 
 #endif // _GHOST_SYSTEM_COCOA_H_
index 735efcda3958df6c74a0c41128d09e237305e670..128ef8a6edfe2fbacafe60fee8f35e2fad326949 100644 (file)
@@ -509,6 +509,11 @@ int cocoa_request_qtcodec_settings(bContext *C, wmOperator *op)
 
 GHOST_SystemCocoa::GHOST_SystemCocoa()
 {
+       int mib[2];
+       struct timeval boottime;
+       size_t len;
+       char *rstring = NULL;
+       
        m_modifierMask =0;
        m_pressedMouseButtons =0;
        m_cursorDelta_x=0;
@@ -519,10 +524,6 @@ GHOST_SystemCocoa::GHOST_SystemCocoa()
        m_displayManager->initialize();
 
        //NSEvent timeStamp is given in system uptime, state start date is boot time
-       int mib[2];
-       struct timeval boottime;
-       size_t len;
-       
        mib[0] = CTL_KERN;
        mib[1] = KERN_BOOTTIME;
        len = sizeof(struct timeval);
@@ -530,6 +531,22 @@ GHOST_SystemCocoa::GHOST_SystemCocoa()
        sysctl(mib, 2, &boottime, &len, NULL, 0);
        m_start_time = ((boottime.tv_sec*1000)+(boottime.tv_usec/1000));
        
+       //Detect multitouch trackpad
+       mib[0] = CTL_HW;
+       mib[1] = HW_MODEL;
+       sysctl( mib, 2, NULL, &len, NULL, 0 );
+       rstring = (char*)malloc( len );
+       sysctl( mib, 2, rstring, &len, NULL, 0 );
+       
+       //Hack on MacBook revision, as multitouch avail. function missing
+       if (strstr(rstring,"MacBookAir") ||
+               (strstr(rstring,"MacBook") && (rstring[strlen(rstring)-3]>='5') && (rstring[strlen(rstring)-3]<='9')))
+               m_hasMultiTouchTrackpad = true;
+       else m_hasMultiTouchTrackpad = false;
+       
+       free( rstring );
+       rstring = NULL;
+       
        m_ignoreWindowSizedMessages = false;
 }
 
@@ -1336,7 +1353,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
                case NSScrollWheel:
                        {
                                /* Send Wheel event if sent from the mouse, trackpad event otherwise */
-                               if ([event subtype] == NSMouseEventSubtype) {
+                               if (!m_hasMultiTouchTrackpad || ([event subtype] == NSMouseEventSubtype)) {
                                        GHOST_TInt32 delta;
                                        
                                        double deltaF = [event deltaY];