Ticket #44282: fix-ktimetracker.patch
File fix-ktimetracker.patch, 7.1 KB (added by RJVB (René Bertin), 10 years ago) |
---|
-
CMakeLists.txt
old new 1 1 project(ktimetracker) 2 2 3 if(NOT Q_WS_MAC) 3 4 #We check if X11_Xscreensaver was found 4 if(X11_Xscreensaver_FOUND) 5 message(STATUS "Found the X11 screensaver extension") 6 macro_bool_to_01(X11_Xscreensaver_LIB HAVE_LIBXSS) 5 if(X11_Xscreensaver_FOUND) 6 message(STATUS "Found the X11 screensaver extension") 7 macro_bool_to_01(X11_Xscreensaver_LIB HAVE_LIBXSS) 8 else() 9 message(STATUS "The X11 screensaver extension was NOT found.") 10 endif() 11 add_feature_info("KtimeTracker idle detection" X11_Xscreensaver_FOUND "Measure the screen idle time in KTimeTracker") 7 12 else() 8 message(STATUS "The X11 screensaver extension was NOT found.")13 add_feature_info("KtimeTracker idle detection" Q_WS_MAC "Measure the screen idle time in KTimeTracker") 9 14 endif() 10 15 11 add_feature_info("KtimeTracker idle detection" X11_Xscreensaver_FOUND "Measure the screen idle time in KTimeTracker")12 13 16 configure_file(config-ktimetracker.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-ktimetracker.h ) 14 17 15 18 add_subdirectory( support ) … … 69 72 if(X11_Xscreensaver_LIB) 70 73 target_link_libraries(ktimetracker ${X11_Xscreensaver_LIB} ) 71 74 endif() 75 if(Q_WS_MAC) 76 target_link_libraries(ktimetracker "-framework ApplicationServices" ) 77 endif() 72 78 73 79 install( TARGETS karm ${INSTALL_TARGETS_DEFAULT_ARGS} ) 74 80 install( TARGETS ktimetracker ${INSTALL_TARGETS_DEFAULT_ARGS} ) … … 84 90 if(X11_Xscreensaver_LIB) 85 91 target_link_libraries(kcm_ktimetracker ${X11_Xscreensaver_LIB} ) 86 92 endif() 93 if(Q_WS_MAC) 94 target_link_libraries(kcm_ktimetracker "-framework ApplicationServices" ) 95 endif() 87 96 88 97 install(TARGETS kcm_ktimetracker DESTINATION ${PLUGIN_INSTALL_DIR}) 89 98 … … 99 108 if(X11_Xscreensaver_LIB) 100 109 target_link_libraries(ktimetrackerpart ${X11_Xscreensaver_LIB}) 101 110 endif() 111 if(Q_WS_MAC) 112 target_link_libraries(ktimetrackerpart "-framework ApplicationServices" ) 113 endif() 102 114 103 115 104 116 install(TARGETS ktimetrackerpart DESTINATION ${PLUGIN_INSTALL_DIR}) -
idletimedetector.cpp
old new 39 39 #include <QX11Info> 40 40 #endif 41 41 42 #ifdef Q_OS_MAC 43 # include <ApplicationServices/ApplicationServices.h> 44 #endif 45 42 46 IdleTimeDetector::IdleTimeDetector(int maxIdle) 43 47 { 44 48 _maxIdle = maxIdle; … … 47 51 int event_base, error_base; 48 52 if(XScreenSaverQueryExtension(QX11Info::display(), &event_base, &error_base)) _idleDetectionPossible = true; 49 53 else _idleDetectionPossible = false; 50 _timer = new QTimer(this); 51 connect(_timer, SIGNAL(timeout()), this, SLOT(check()));54 #elif defined(Q_OS_MAC) 55 _idleDetectionPossible = true; 52 56 #else 53 57 _idleDetectionPossible = false; 54 58 #endif // HAVE_LIBXSS 59 if( _idleDetectionPossible ){ 60 _timer = new QTimer(this); 61 // the slot was renamed to runOnce() to avoid a macro defined through ApplicationServices.h on OS X 62 connect(_timer, SIGNAL(timeout()), this, SLOT(runOnce())); 63 } 55 64 } 56 65 57 66 bool IdleTimeDetector::isIdleDetectionPossible() … … 59 68 return _idleDetectionPossible; 60 69 } 61 70 62 void IdleTimeDetector:: check()71 void IdleTimeDetector::runOnce() 63 72 { 64 73 kDebug(5970) << "Entering function"; 65 74 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11) 66 kDebug(5970) << " kompiled for libxss and x11, idledetectionpossible is " << _idleDetectionPossible;75 kDebug(5970) << "compiled for libxss and x11, idledetectionpossible is " << _idleDetectionPossible; 67 76 if (_idleDetectionPossible) 68 77 { 69 78 _mit_info = XScreenSaverAllocInfo(); … … 74 83 if (idleminutes >= _maxIdle) 75 84 informOverrun(); 76 85 } 86 #elif defined(Q_OS_MAC) 87 // see http://stackoverflow.com/a/22307622/1460868 88 idleminutes = (int) CGEventSourceSecondsSinceLastEventType( kCGEventSourceStateHIDSystemState, kCGAnyInputEventType ) / secsPerMinute; 89 if( idleminutes >= _maxIdle ){ 90 informOverrun(); 91 } 77 92 #endif // HAVE_LIBXSS 78 93 } 79 94 … … 92 107 emit(stopAllTimers(idlestart)); 93 108 } 94 109 95 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)110 #if (defined(HAVE_LIBXSS) && defined(Q_WS_X11)) || defined(Q_OS_MAC) 96 111 void IdleTimeDetector::informOverrun() 97 112 { 98 113 if (!_overAllIdleDetect) … … 126 141 kDebug(5970) << "Setting WinId " << dialog->winId() << " to deskTop " << KWindowSystem::self()->currentDesktop(); 127 142 dialog->show(); 128 143 } 129 #endif // HAVE_LIBXSS 144 #endif // HAVE_LIBXSS || Q_OS_MAC 130 145 131 146 void IdleTimeDetector::startIdleDetection() 132 147 { 133 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)134 148 #if (defined(HAVE_LIBXSS) && defined(Q_WS_X11)) || defined(Q_OS_MAC) 149 if (!_timer->isActive()) 135 150 _timer->start(testInterval); 136 151 #endif //HAVE_LIBXSS 137 152 } 138 153 139 154 void IdleTimeDetector::stopIdleDetection() 140 155 { 141 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)142 156 #if (defined(HAVE_LIBXSS) && defined(Q_WS_X11)) || defined(Q_OS_MAC) 157 if (_timer->isActive()) 143 158 _timer->stop(); 144 159 #endif // HAVE_LIBXSS 145 160 } -
idletimedetector.h
old new 59 59 Returns true if it is possible to do idle detection. 60 60 Idle detection relys on a feature in the X server, which might not 61 61 always be present. 62 On OS X, it uses CGEventSourceSecondsSinceLastEventType() from ApplicationServices.framework 62 63 **/ 63 64 bool isIdleDetectionPossible(); 64 65 65 66 Q_SIGNALS: 66 67 /** 67 68 Tells the listener to subtract time from current timing. 68 The time to subtract is due to the idle time since the dialog was s69 The time to subtract is due to the idle time since the dialog was 69 70 shown, and until the user answers the dialog. 70 71 @param minutes Minutes to subtract. 71 72 **/ … … 104 105 105 106 106 107 protected: 107 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)108 #if (defined(HAVE_LIBXSS) && defined(Q_WS_X11)) || defined(Q_OS_MAC) 108 109 void informOverrun(); 109 #endif // HAVE_LIBXSS 110 #endif // HAVE_LIBXSS || Q_OS_MAC 110 111 111 112 protected Q_SLOTS: 112 void check();113 void runOnce(); 113 114 114 115 private: 115 116 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11) -
mainwindow.cpp
old new 71 71 // and another one in the plugin. The build system should be fixed. 72 72 //m_part = factory->create<ktimetrackerpart>( this ); 73 73 74 m_part = dynamic_cast<ktimetrackerpart*>( factory->create<KParts::ReadWritePart>( this ) ); 74 #ifdef Q_OS_MAC 75 // not sure if this is really required but this is the code that works for me with g++-mp-4.8 76 static KParts::ReadWritePart *rwp = factory->create<KParts::ReadWritePart>( this ); 77 static ktimetrackerpart *mp = dynamic_cast<ktimetrackerpart*>( rwp ); 78 m_part = dynamic_cast<ktimetrackerpart*>( rwp ); 75 79 kError() << "this=" << this << "; rwp=" << rwp << "; mp=" << mp << "; m_part=" << m_part; 80 #else 81 m_part = dynamic_cast<ktimetrackerpart*>( factory->create<KParts::ReadWritePart>( this ) ); 82 #endif 76 83 77 84 if (m_part) 78 85 {