| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
import os |
|---|
| 8 |
import gobject |
|---|
| 9 |
import string |
|---|
| 10 |
import re |
|---|
| 11 |
import dbus |
|---|
| 12 |
|
|---|
| 13 |
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0): |
|---|
| 14 |
import dbus.glib |
|---|
| 15 |
|
|---|
| 16 |
GAJIM_SERVICE = 'org.gajim.dbus' |
|---|
| 17 |
GAJIM_OBJ_PATH = '/org/gajim/dbus/RemoteObject' |
|---|
| 18 |
GAJIM_INTERFACE = 'org.gajim.dbus.RemoteInterface' |
|---|
| 19 |
|
|---|
| 20 |
BERYL_SERVICE = 'org.freedesktop.beryl' |
|---|
| 21 |
BERYL_OBJ_PATH = '/org/freedesktop/beryl/water/allscreens/point' |
|---|
| 22 |
BERYL_INTERFACE = 'org.freedesktop.beryl.activate' |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
def get_root_window_id(): |
|---|
| 27 |
rootid = 0 |
|---|
| 28 |
idline = os.popen('xwininfo -root | grep "id:"').readlines()[0] |
|---|
| 29 |
idmatch = re.search('id: ([^ ]*)', idline) |
|---|
| 30 |
if (idmatch): |
|---|
| 31 |
rootid = int(idmatch.group(1), 16) |
|---|
| 32 |
return rootid |
|---|
| 33 |
else: |
|---|
| 34 |
raise 'Can not find window id of root window' |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
def get_systray_icon_position(): |
|---|
| 39 |
|
|---|
| 40 |
cmd = 'xwininfo -root -tree | grep gajim' |
|---|
| 41 |
posregex = re.compile('(\d+)x(\d+)\+\d+\+\d+\s*\+(\d+)\+(\d+)') |
|---|
| 42 |
|
|---|
| 43 |
for line in os.popen(cmd).readlines(): |
|---|
| 44 |
posmatch = posregex.search(line) |
|---|
| 45 |
if (posmatch): |
|---|
| 46 |
width = int(posmatch.group(1)) |
|---|
| 47 |
height = int(posmatch.group(2)) |
|---|
| 48 |
x = int(posmatch.group(3)) |
|---|
| 49 |
y = int(posmatch.group(4)) |
|---|
| 50 |
if (width >= 15 and width <= 30 and height >= 15 and height < 30): |
|---|
| 51 |
|
|---|
| 52 |
return x + (width / 2), y |
|---|
| 53 |
|
|---|
| 54 |
raise 'Can not find gajim systray icon' |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
def new_message(details): |
|---|
| 58 |
|
|---|
| 59 |
beryl_dbus_iface.activate('root', rootid, |
|---|
| 60 |
'amplitude', 1, |
|---|
| 61 |
'x', systray_x, |
|---|
| 62 |
'y', systray_y, |
|---|
| 63 |
reply_handler=(lambda *args: None), |
|---|
| 64 |
error_handler=(lambda *args: None)) |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
rootid = get_root_window_id() |
|---|
| 68 |
systray_x, systray_y = get_systray_icon_position() |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
bus = dbus.SessionBus() |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
gajim_proxy_obj = bus.get_object(GAJIM_SERVICE, GAJIM_OBJ_PATH) |
|---|
| 75 |
gajim_dbus_iface = dbus.Interface(gajim_proxy_obj, GAJIM_INTERFACE) |
|---|
| 76 |
gajim_dbus_iface.connect_to_signal('NewMessage', new_message) |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
beryl_proxy_obj = bus.get_object(BERYL_SERVICE, BERYL_OBJ_PATH) |
|---|
| 80 |
beryl_dbus_iface = dbus.Interface(beryl_proxy_obj, BERYL_INTERFACE) |
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
mainloop = gobject.MainLoop() |
|---|
| 84 |
mainloop.run() |
|---|