summaryrefslogtreecommitdiff
path: root/bin
diff options
authorTaihsiang Ho <taihsiang.ho@canonical.com>2014-05-27 19:17:06 +0800
committerTaihsiang Ho <taihsiang.ho@canonical.com>2014-05-27 19:17:06 +0800
commit5b141915ffb9908631097206571176a2808b6141 (patch)
tree01b2b628f18d12d34b93163b11f4715b8d64ba14 /bin
parent553305c59e4f6bec3342f5bae360036980e46ffe (diff)
add different method to detect the screen lock status on 14.04 which its screensaver mechanism is different from previous Ubuntu distributions
Diffstat (limited to 'bin')
-rwxr-xr-xbin/lock_screen_watcher45
1 files changed, 38 insertions, 7 deletions
diff --git a/bin/lock_screen_watcher b/bin/lock_screen_watcher
index 1ba9779..c12921f 100755
--- a/bin/lock_screen_watcher
+++ b/bin/lock_screen_watcher
@@ -19,14 +19,45 @@ class SceenSaverStatusHelper(threading.Thread):
self._loop = loop
self.quit = False
+ def getDistributor(self):
+ return self.getLSBReleaseProcess("-i")
+
+ def getCodename(self):
+ return self.getLSBReleaseProcess("-c")
+
+ def getLSBReleaseProcess(self,option):
+ """
+ use the command "lsb_release" to get the distribution-specific information.
+ This method should work on Debian and Ubuntu.
+ """
+ p = subprocess.Popen(["lsb_release", option],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ stdout = p.communicate()[0]
+ return stdout.decode().split("\t")[-1][0:-1]
+
def query(self):
- p = subprocess.Popen(["gnome-screensaver-command", "-q"], stdout=subprocess.PIPE)
- stdout, stderr = p.communicate()
- # parse the stdout string from the command "gnome-screensaver-command -q"
- # the result should be "active" or "inactive"
- if "active" == stdout.decode().split(" ")[-1][0:-1] :
- print("the screensaver is active")
- self._loop.quit()
+ if (self.getDistributor() == "Ubuntu"):
+ if (self.getCodename() == "trusty"):
+ # trusty uses login screen as screen saver
+ process_ps = subprocess.Popen(["ps", "aux"], stdout=subprocess.PIPE)
+ process_grep = subprocess.Popen(["grep",
+ "/usr/lib/unity/unity-panel-service --lockscreen-mode"],
+ stdin=process_ps.stdout,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ process_ps.stdout.close()
+ stdout = process_grep.communicate()[0]
+ if (len(stdout.decode().split("\n")) == 3):
+ print("the screensaver is active")
+ self._loop.quit()
+ p = subprocess.Popen(["gnome-screensaver-command", "-q"], stdout=subprocess.PIPE)
+ stdout, stderr = p.communicate()
+ # parse the stdout string from the command "gnome-screensaver-command -q"
+ # the result should be "active" or "inactive"
+ if "active" == stdout.decode().split(" ")[-1][0:-1] :
+ print("the screensaver is active")
+ self._loop.quit()
def run(self):
while not self.quit: