Ticket #44282: fix-ktimetracker.patch

File fix-ktimetracker.patch, 7.1 KB (added by RJVB (René Bertin), 10 years ago)
  • CMakeLists.txt

    old new  
    11project(ktimetracker)
    22
     3if(NOT Q_WS_MAC)
    34#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")
    712else()
    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")
    914endif()
    1015
    11 add_feature_info("KtimeTracker idle detection" X11_Xscreensaver_FOUND "Measure the screen idle time in KTimeTracker")
    12 
    1316configure_file(config-ktimetracker.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-ktimetracker.h )
    1417
    1518add_subdirectory( support )
     
    6972if(X11_Xscreensaver_LIB)
    7073        target_link_libraries(ktimetracker  ${X11_Xscreensaver_LIB} )
    7174endif()
     75if(Q_WS_MAC)
     76     target_link_libraries(ktimetracker  "-framework ApplicationServices" )
     77endif()
    7278
    7379install( TARGETS karm  ${INSTALL_TARGETS_DEFAULT_ARGS} )
    7480install( TARGETS ktimetracker  ${INSTALL_TARGETS_DEFAULT_ARGS} )
     
    8490if(X11_Xscreensaver_LIB)
    8591    target_link_libraries(kcm_ktimetracker  ${X11_Xscreensaver_LIB} )
    8692endif()
     93if(Q_WS_MAC)
     94     target_link_libraries(kcm_ktimetracker  "-framework ApplicationServices" )
     95endif()
    8796
    8897install(TARGETS kcm_ktimetracker DESTINATION ${PLUGIN_INSTALL_DIR})
    8998
     
    99108if(X11_Xscreensaver_LIB)
    100109        target_link_libraries(ktimetrackerpart  ${X11_Xscreensaver_LIB})
    101110endif()
     111if(Q_WS_MAC)
     112     target_link_libraries(ktimetrackerpart  "-framework ApplicationServices" )
     113endif()
    102114
    103115
    104116install(TARGETS ktimetrackerpart  DESTINATION ${PLUGIN_INSTALL_DIR})
  • idletimedetector.cpp

    old new  
    3939#include <QX11Info>
    4040#endif
    4141
     42#ifdef Q_OS_MAC
     43#    include <ApplicationServices/ApplicationServices.h>
     44#endif
     45
    4246IdleTimeDetector::IdleTimeDetector(int maxIdle)
    4347{
    4448    _maxIdle = maxIdle;
     
    4751    int event_base, error_base;
    4852    if(XScreenSaverQueryExtension(QX11Info::display(), &event_base, &error_base)) _idleDetectionPossible = true;
    4953    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;
    5256#else
    5357    _idleDetectionPossible = false;
    5458#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    }
    5564}
    5665
    5766bool IdleTimeDetector::isIdleDetectionPossible()
     
    5968    return _idleDetectionPossible;
    6069}
    6170
    62 void IdleTimeDetector::check()
     71void IdleTimeDetector::runOnce()
    6372{
    6473    kDebug(5970) << "Entering function";
    6574#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;
    6776    if (_idleDetectionPossible)
    6877    {
    6978        _mit_info = XScreenSaverAllocInfo();
     
    7483        if (idleminutes >= _maxIdle)
    7584        informOverrun();
    7685    }
     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    }
    7792#endif // HAVE_LIBXSS
    7893}
    7994
     
    92107    emit(stopAllTimers(idlestart));
    93108}
    94109
    95 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)
     110#if (defined(HAVE_LIBXSS) && defined(Q_WS_X11)) || defined(Q_OS_MAC)
    96111void IdleTimeDetector::informOverrun()
    97112{
    98113    if (!_overAllIdleDetect)
     
    126141        kDebug(5970) << "Setting WinId " << dialog->winId() << " to deskTop " << KWindowSystem::self()->currentDesktop();
    127142        dialog->show();
    128143}
    129 #endif // HAVE_LIBXSS
     144#endif // HAVE_LIBXSS || Q_OS_MAC
    130145
    131146void IdleTimeDetector::startIdleDetection()
    132147{
    133 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)
    134     if (!_timer->isActive())
     148#if (defined(HAVE_LIBXSS) && defined(Q_WS_X11)) || defined(Q_OS_MAC)
     149  if (!_timer->isActive())
    135150        _timer->start(testInterval);
    136151#endif //HAVE_LIBXSS
    137152}
    138153
    139154void IdleTimeDetector::stopIdleDetection()
    140155{
    141 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)
    142     if (_timer->isActive())
     156#if (defined(HAVE_LIBXSS) && defined(Q_WS_X11)) || defined(Q_OS_MAC)
     157  if (_timer->isActive())
    143158        _timer->stop();
    144159#endif // HAVE_LIBXSS
    145160}
  • idletimedetector.h

    old new  
    5959     Returns true if it is possible to do idle detection.
    6060     Idle detection relys on a feature in the X server, which might not
    6161     always be present.
     62     On OS X, it uses CGEventSourceSecondsSinceLastEventType() from ApplicationServices.framework
    6263  **/
    6364  bool isIdleDetectionPossible();
    6465
    6566Q_SIGNALS:
    6667  /**
    6768     Tells the listener to subtract time from current timing.
    68      The time to subtract is due to the idle time since the dialog wass
     69     The time to subtract is due to the idle time since the dialog was
    6970     shown, and until the user answers the dialog.
    7071     @param minutes Minutes to subtract.
    7172  **/
     
    104105
    105106
    106107protected:
    107 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)
     108#if (defined(HAVE_LIBXSS) && defined(Q_WS_X11)) || defined(Q_OS_MAC)
    108109  void informOverrun();
    109 #endif // HAVE_LIBXSS
     110#endif // HAVE_LIBXSS || Q_OS_MAC
    110111
    111112protected Q_SLOTS:
    112   void check();
     113  void runOnce();
    113114
    114115private:
    115116#if defined(HAVE_LIBXSS) && defined(Q_WS_X11)
  • mainwindow.cpp

    old new  
    7171        // and another one in the plugin. The build system should be fixed.
    7272        //m_part = factory->create<ktimetrackerpart>( this );
    7373
    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 );
    7579           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
    7683
    7784        if (m_part)
    7885        {