Skip to content

Commit

Permalink
MCAbber xscreensaver watcher.
Browse files Browse the repository at this point in the history
  • Loading branch information
geektophe committed Oct 21, 2013
1 parent acf4a01 commit 17f8a42
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Xsession
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export GPG_AGENT_INFO
/usr/bin/parcellite &
/usr/bin/dropboxd &
/usr/bin/xscreensaver -no-splash &
~/.config/awesome/bin/gajim-watch-xscreensaver &
~/.config/awesome/bin/mcabber-watch-xscreensaver &

# Starts polkit server
/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 &
Expand Down
84 changes: 84 additions & 0 deletions bin/mcabber-watch-xscreensaver
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env python

###############################################################################
#
# IMPORTS
#
###############################################################################

import subprocess
import re
import os


###############################################################################
#
# PARAMETERS AND CONSTANTS
#
###############################################################################

FIFO = "%s/.mcabber/mcabber.fifo" % os.environ["HOME"]


###############################################################################
#
# CLASSES
#
###############################################################################

class GajimProxy(object):
"""
Empathy account manager proxy class
"""

def fifo_write(self, command):
"""
Sets status away
Saves current status to be restored by back method.
"""
if not os.path.isfile(FIFO):
return
f = open(FIFO, "w")
f.write("/%s\n" % command)
f.close()

def online(self):
"""
Sets status online
"""
self.fifo_write("back")

def away(self):
"""
Sets status away
"""
self.fifo_write("away")


###############################################################################
#
# MAIN
#
###############################################################################

if __name__ == '__main__':
proxy = GajimProxy()

watcher = subprocess.Popen(
['xscreensaver-command', '-watch'],
stdout=subprocess.PIPE)

try:
while True:
row = watcher.stdout.readline()

if re.match('^(BLANK|LOCK)', row):
proxy.away()
elif re.match('^UNBLANK', row):
proxy.online()

watcher.stdout.flush()

except KeyboardInterrupt:
pass

0 comments on commit 17f8a42

Please sign in to comment.