Skip to content

Instantly share code, notes, and snippets.

@funivan
Created March 27, 2015 08:07
Show Gist options
  • Select an option

  • Save funivan/d50cc9b6a4d325065f5d to your computer and use it in GitHub Desktop.

Select an option

Save funivan/d50cc9b6a4d325065f5d to your computer and use it in GitHub Desktop.
Move chat to top
#!/usr/bin/env python
#
# Remember you need dbus session to run this program.
# export DBUS_SESSION_BUS_ADDRESS=`cat /proc/$(pidof gnome-session)/environ | tr '\\0' '\\n' | grep DBUS_SESSION_BUS_ADDRESS | cut -d '=' -f2-`;
#
import socket
import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop
import os
import sys
def print_help():
print "This script move pidgin conversation window to top without focus"
print "After you read message window goes to normal state"
print "./pidgin.py -h - show help"
print "./pidgin.py - perform all work "
if (len(sys.argv) >=2 and sys.argv[1] == '-h'):
print_help()
sys.exit(1)
def MoveUp():
os.system("wmctrl -i -r `wmctrl -l -x | grep Pidgin.Pidgin | grep -v Buddy | awk '{print $1}'` -b toggle,above")
print "Move up";
def MoveDown():
print "MoveDown"
os.system("wmctrl -i -r `wmctrl -l -x | grep Pidgin.Pidgin | grep -v Buddy | awk '{print $1}'` -b remove,above")
def ReceivedImMsg(account, sender, message, conversation, flags):
if bus.pidginbus.PurpleConversationHasFocus(conversation) == 0:
config['skip']+=1;
MoveUp()
def SentImMsg(account, receiver, message):
MoveDown()
def DeletingConversation(conversation):
MoveDown()
def ConversationUpdated(conversation, type):
if type != 4:
return
if config['skip'] == 0:
MoveDown()
else:
config['skip']-=1
config = {}
config['skip'] = 0;
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
bus.pidginbus = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
bus.add_signal_receiver(ReceivedImMsg, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="ReceivedImMsg")
bus.add_signal_receiver(DeletingConversation, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="DeletingConversation")
bus.add_signal_receiver(ConversationUpdated, dbus_interface="im.pidgin.purple.PurpleInterface", signal_name="ConversationUpdated")
loop = gobject.MainLoop()
loop.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment