예제 #1
0
파일: core.py 프로젝트: ashh87/caffeine
    def _detectScreensaverAndPowersavingType(self):
        """This method always runs when the first attempt to inhibit the screensaver and
        powersaving is made. It detects what screensaver/powersaving software is running.
        After detection is complete, it will finish the inhibiting process."""
        logging.info("Attempting to detect screensaver/powersaving type... (" + str(self.dbusDetectionFailures) + " dbus failures so far)")
        bus = dbus.SessionBus()
        
        if  'org.gnome.SessionManager' in bus.list_names() and not utils.isProcessRunning("xscreensaver"):
            self.screensaverAndPowersavingType = "Gnome3"

        elif 'org.freedesktop.ScreenSaver' in bus.list_names() and \
             'org.freedesktop.PowerManagement.Inhibit' in bus.list_names():
            self.screensaverAndPowersavingType = "KDE"
        else:
            self.dbusDetectionFailures += 1
            if self.dbusDetectionFailures <= 3:
                self.dbusDetectionTimer = threading.Timer(10, self._detectScreensaverAndPowersavingType)
                self.dbusDetectionTimer.start()
                return
            else:
                # At this point, all attempts to connect to the relevant dbus interfaces have failed.
                # This user must be using something other than the Gnome or KDE screensaver programs.
                if utils.isProcessRunning("xscreensaver"):
                    self.screensaverAndPowersavingType = "XSS+DPMS"
                else:
                    self.screensaverAndPowersavingType = "DPMS"

        self.attemptingToDetect = False
        self.dbusDetectionFailures = 0
        self.dbusDetectionTimer = None

        logging.info("Successfully detected screensaver and powersaving type: " + str(self.screensaverAndPowersavingType))

        if self.sleepAppearsPrevented != self.sleepIsPrevented:
            self._performTogglingActions()
예제 #2
0
파일: core.py 프로젝트: sql-sith/caffeine
    def _detectDbusType(self):
        """This method always runs when the first attempt to inhibit the screensaver
        and powersaving is made. It detects what dbus service can be used.
        After detection is complete, it will finish the inhibiting process."""
        logging.info("Attempting to detect screensaver/powersaving type... (" + str(self.dbusDetectionFailures) + " dbus failures so far)")
        bus = dbus.SessionBus()

        if utils.isProcessRunning("xscreensaver"):
            self.screensaverType = "XSS"

        for i in xrange(len(self.dbus_service)):
            if self.dbusType == None and self.dbus_service[i] in bus.list_names():
                self.dbusType = i

        if self.dbusType == None:
            self.dbusDetectionFailures += 1
            if self.dbusDetectionFailures <= 3:
                self.dbusDetectionTimer = threading.Timer(10, self._detectDbusType)
                self.dbusDetectionTimer.start()
                return
            else:
                # Was unable to detect necessary dbus service.
                self.self.dbusType = False;

        self.attemptingToDetect = False
        self.dbusDetectionFailures = 0
        self.dbusDetectionTimer = None

        if self.dbusType == False:
            logging.info("Dbus detection was unsuccessful.")
        else:
            logging.info("Successfully detected dbus: " + str(self.dbus_service[self.dbusType]))

        if self.sleepAppearsPrevented != self.sleepIsPrevented:
            self._performTogglingActions()
예제 #3
0
파일: core.py 프로젝트: sql-sith/caffeine
    def _check_for_process(self):
        activate = False
        for proc in self.ProcMan.get_process_list():
            if utils.isProcessRunning(proc):

                activate = True

                if self.preventedForProcess or not self.getActivated():
                    
                    logging.info("Caffeine has detected that the process '" + proc + "' is running, and will auto-activate")

                    self.setActivated(True)

                    self.preventedForProcess = True
                else:

                    logging.info("Caffeine has detected that the process '"+
                    proc + "' is running, but will NOT auto-activate"+
                    " as Caffeine has already been activated for a different"+
                    " reason.")


        ### No process in the list is running, deactivate.
        if not activate and self.preventedForProcess:
            logging.info("Caffeine had previously auto-activated for a process, but that process is no longer running; deactivating...")
            self.setActivated(False)

        return True