GajimDBus: gajim2compiz.py

File gajim2compiz.py, 2.8 KB (added by vArDo, 21 months ago)

Python dbus script to glue Gajim and Compiz Fusion together (modified gajim2beryl.py)

Line 
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
10import os
11import gobject
12import string
13import re
14import dbus
15
16if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
17    import dbus.glib
18
19GAJIM_SERVICE = 'org.gajim.dbus'
20GAJIM_OBJ_PATH = '/org/gajim/dbus/RemoteObject'
21GAJIM_INTERFACE = 'org.gajim.dbus.RemoteInterface'
22
23COMPIZ_SERVICE = 'org.freedesktop.compiz'
24COMPIZ_OBJ_PATH = '/org/freedesktop/compiz/water/allscreens/point'
25COMPIZ_INTERFACE = 'org.freedesktop.compiz'
26
27# function to find root window id;
28# we will need to pass that to compiz
29def 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
41def 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
60def 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
68rootid = get_root_window_id()
69systray_x, systray_y = get_systray_icon_position()
70
71# magic starts here
72bus = dbus.SessionBus()
73
74# connect to NewMessage signal from gajim
75gajim_proxy_obj = bus.get_object(GAJIM_SERVICE, GAJIM_OBJ_PATH)
76gajim_dbus_iface = dbus.Interface(gajim_proxy_obj, GAJIM_INTERFACE)
77gajim_dbus_iface.connect_to_signal('NewMessage', new_message)
78
79# prepare compiz dbus connection
80compiz_proxy_obj = bus.get_object(COMPIZ_SERVICE, COMPIZ_OBJ_PATH)
81compiz_dbus_iface = dbus.Interface(compiz_proxy_obj, COMPIZ_INTERFACE)
82# compiz_dbus_iface.get_methods()
83
84# get things going
85mainloop = gobject.MainLoop()
86mainloop.run()