| 1 | #!/usr/bin/python |
|---|
| 2 | # -*- encoding: utf-8 -*- |
|---|
| 3 | |
|---|
| 4 | # notification about new messages in |
|---|
| 5 | # gajim using the compiz water ripple effect |
|---|
| 6 | # Original written by: Jan Vornberger (jav), xmpp:jav@jabber.de |
|---|
| 7 | # Modified by Mateusz Biliński (vArDo),xmpp:mateusz@bilinski.it |
|---|
| 8 | # to work with Compiz Fusion [June 2008] |
|---|
| 9 | |
|---|
| 10 | import os |
|---|
| 11 | import gobject |
|---|
| 12 | import string |
|---|
| 13 | import re |
|---|
| 14 | import dbus |
|---|
| 15 | |
|---|
| 16 | if getattr(dbus, 'version', (0,0,0)) >= (0,41,0): |
|---|
| 17 | import dbus.glib |
|---|
| 18 | |
|---|
| 19 | GAJIM_SERVICE = 'org.gajim.dbus' |
|---|
| 20 | GAJIM_OBJ_PATH = '/org/gajim/dbus/RemoteObject' |
|---|
| 21 | GAJIM_INTERFACE = 'org.gajim.dbus.RemoteInterface' |
|---|
| 22 | |
|---|
| 23 | COMPIZ_SERVICE = 'org.freedesktop.compiz' |
|---|
| 24 | COMPIZ_OBJ_PATH = '/org/freedesktop/compiz/water/allscreens/point' |
|---|
| 25 | COMPIZ_INTERFACE = 'org.freedesktop.compiz' |
|---|
| 26 | |
|---|
| 27 | # function to find root window id; |
|---|
| 28 | # we will need to pass that to compiz |
|---|
| 29 | def get_root_window_id(): |
|---|
| 30 | rootid = 0 |
|---|
| 31 | idline = os.popen('xwininfo -root | grep "id:"').readlines()[0] |
|---|
| 32 | idmatch = re.search('id: ([^ ]*)', idline) |
|---|
| 33 | if (idmatch): |
|---|
| 34 | rootid = int(idmatch.group(1), 16) |
|---|
| 35 | return rootid |
|---|
| 36 | else: |
|---|
| 37 | raise 'Can not find window id of root window' |
|---|
| 38 | |
|---|
| 39 | # function to find the position of gajim systray icon; |
|---|
| 40 | # we want to ping that position |
|---|
| 41 | def get_systray_icon_position(): |
|---|
| 42 | # find systray icon |
|---|
| 43 | cmd = 'xwininfo -root -tree | grep gajim' |
|---|
| 44 | posregex = re.compile('(\d+)x(\d+)\+\d+\+\d+\s*\+(\d+)\+(\d+)') # match window position info |
|---|
| 45 | |
|---|
| 46 | for line in os.popen(cmd).readlines(): |
|---|
| 47 | posmatch = posregex.search(line) |
|---|
| 48 | if (posmatch): |
|---|
| 49 | width = int(posmatch.group(1)) |
|---|
| 50 | height = int(posmatch.group(2)) |
|---|
| 51 | x = int(posmatch.group(3)) |
|---|
| 52 | y = int(posmatch.group(4)) |
|---|
| 53 | if (width >= 15 and width <= 30 and height >= 15 and height < 30): |
|---|
| 54 | # I guess this is the systray icon |
|---|
| 55 | return x + (width / 2), y |
|---|
| 56 | |
|---|
| 57 | raise 'Can not find gajim systray icon' |
|---|
| 58 | |
|---|
| 59 | # callback function to be informed about new messages in gajim |
|---|
| 60 | def new_message(details): |
|---|
| 61 | # new message -> ripple notification |
|---|
| 62 | compiz_dbus_iface.activate('root', rootid, |
|---|
| 63 | 'amplitude', 1, |
|---|
| 64 | 'x', systray_x, |
|---|
| 65 | 'y', systray_y) |
|---|
| 66 | |
|---|
| 67 | # get root id and systray position for later use |
|---|
| 68 | rootid = get_root_window_id() |
|---|
| 69 | systray_x, systray_y = get_systray_icon_position() |
|---|
| 70 | |
|---|
| 71 | # magic starts here |
|---|
| 72 | bus = dbus.SessionBus() |
|---|
| 73 | |
|---|
| 74 | # connect to NewMessage signal from gajim |
|---|
| 75 | gajim_proxy_obj = bus.get_object(GAJIM_SERVICE, GAJIM_OBJ_PATH) |
|---|
| 76 | gajim_dbus_iface = dbus.Interface(gajim_proxy_obj, GAJIM_INTERFACE) |
|---|
| 77 | gajim_dbus_iface.connect_to_signal('NewMessage', new_message) |
|---|
| 78 | |
|---|
| 79 | # prepare compiz dbus connection |
|---|
| 80 | compiz_proxy_obj = bus.get_object(COMPIZ_SERVICE, COMPIZ_OBJ_PATH) |
|---|
| 81 | compiz_dbus_iface = dbus.Interface(compiz_proxy_obj, COMPIZ_INTERFACE) |
|---|
| 82 | # compiz_dbus_iface.get_methods() |
|---|
| 83 | |
|---|
| 84 | # get things going |
|---|
| 85 | mainloop = gobject.MainLoop() |
|---|
| 86 | mainloop.run() |
|---|