I am using dwm as a window manager for a long time. I hacked a few things into it which I felt were missing back then when I started to use dwm and got used to it so much that I hesitate to switch to awesome or even a newer version of dwm.
Tiled window managing is really a great idea but conflicts with programs which are design to be used in a more “traditional” desktop environment. One of those application is my instant messenger. I gave up using ncurses based messengers due to their lack of drag’n’drop capabilities, so I started using pidgin.
What I always wanted to have is some kind of tray icon which informs me about new incoming messages. The cool thing about pidgin and the whole underlying purple library is their great support for dbus. So instead of ripping off code from awesome to get full freedesktop compliant tray icons I wrote a small python script to add an icon to my dwm status bar.
The dwm status bar reads a string from stdin (passed to it by xinit) and displays it in the upper right corner of the screen. To do that it uses a loop in .xinitrc like this:
while true do date=`date +'%d.%m.%Y %H:%M'` echo $date `pidginProbe.py` sleep 3 done | dwm
OK, so I need a script named pidginProbe.py which is just looking for an incoming message on the libpurple dbus interface, prints out a small notification and then terminates.
Here is how I connect to the purple dbus:
bus = dbus.SessionBus() purple_service = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject") purple = dbus.Interface(purple_service, "im.pidgin.purple.PurpleInterface")
Asking for an incoming message is not possible without installing a callback to a ReceivingChatMessage signal. But there is the option to ask for all active conversations which includes open chat windows and newly received messages.
def incomingMessageExists(purple): convs = purple.PurpleGetConversations() return len(convs) > 0
This function can be used to print [ ]
to the screen when no message was received or [M]
otherwise.
Of course much more is possible, nearly all important features can be used via dbus. See the developer documentation to find out about the other calls and signals.
I also added a notification which informs me about specific people going online (like my girlfriend ^^), here is the code example (that’s the simple version without error handling):
purple = dbus.Interface... myid = # my ICQ/Jabber/... account id contactid = # contact's ICQ/Jabber/... account id myaccount = purple.PurpleAccountsFind(myid, '') buddy = purple.PurpleFindBuddies(myaccount, contactid): if purple.PurpleBuddyIsOnline(buddy[0]) == 1: print contactid, "is online"
I find Pidgin works great in dwm, without a tray icon. Here’s how I do it:
– In rules: { “Pidgin”, NULL, NULL, 1 << 3, False, -1 }
– Disable tray icon and enable urgency hint in Pidgin
Now dwm's tag list will change the colors of tag 4 when you get a message (perfect unobtrusive notification imo), and I just mod-4 to bring up Pidgin (message window and buddy list, tiled)