aboutsummaryrefslogtreecommitdiffstats
path: root/urgent.tcl
diff options
context:
space:
mode:
authorkostix <kostix@cc602e41-bd33-0410-9637-a208f32f1443>2009-01-21 01:31:38 +0000
committerkostix <kostix@cc602e41-bd33-0410-9637-a208f32f1443>2009-01-21 01:31:38 +0000
commitcf928a9b4091b18ecf76aeaa4d2c4baed6364acd (patch)
tree655fa23feca904b9afe6d7edb343f0b3aabf916f /urgent.tcl
downloadurgent-cf928a9b4091b18ecf76aeaa4d2c4baed6364acd.tar.gz
urgent-cf928a9b4091b18ecf76aeaa4d2c4baed6364acd.tar.xz
urgent-cf928a9b4091b18ecf76aeaa4d2c4baed6364acd.zip
Added preliminary implementation of the "urgent" plugin
which controls the X Window "urgency" hint on Tkabber chat windows. See http://www.jabber.ru/bugzilla/show_bug.cgi?id=389 git-svn-id: http://svn.xmpp.ru/repos/tkabber-3rd-party/trunk/plugins/urgent@166 cc602e41-bd33-0410-9637-a208f32f1443
Diffstat (limited to 'urgent.tcl')
-rw-r--r--urgent.tcl144
1 files changed, 144 insertions, 0 deletions
diff --git a/urgent.tcl b/urgent.tcl
new file mode 100644
index 0000000..af59ecc
--- /dev/null
+++ b/urgent.tcl
@@ -0,0 +1,144 @@
+# $Id$
+
+namespace eval urgent {
+ custom::defgroup Urgent [::msgcat::mc "Urgency hinting."] -group Plugins
+
+ custom::defvar options(enabled) 1 \
+ [::msgcat::mc "Set the urgency hint on Tkabber's chat\
+ window when a new message is received."] \
+ -type boolean \
+ -group Urgent
+
+ custom::defvar options(handle_personal_messages) 1 \
+ [::msgcat::mc "React on messages addressed to us."] \
+ -type boolean \
+ -group Urgent
+
+ custom::defvar options(handle_normal_messages) 0 \
+ [::msgcat::mc "React on messages in MUC rooms\
+ which are not addressed to us."] \
+ -type boolean \
+ -group Urgent
+
+ custom::defvar options(handle_server_messages) 0 \
+ [::msgcat::mc "React on messages generated by the server"] \
+ -type boolean \
+ -group Urgent
+}
+
+proc urgent::chat_message_notify {chatid from type body extras} {
+ variable options
+
+ if {!$options(enabled)} return
+
+ set delayed [::xmpp::delay::exists $extras]
+ if {$delayed} return
+
+ switch -- $type {
+ groupchat {
+ if {[string equal [chat::get_jid $chatid] $from]} {
+ if {$options(handle_server_messages)} {
+ notify $chatid
+ }
+ } else {
+ set mynick [chat::get_nick [chat::get_xlib $chatid] \
+ [chat::our_jid $chatid] $type]
+ if {[check_message $mynick $body]} {
+ if {$options(handle_personal_messages)} {
+ notify $chatid
+ }
+ } else {
+ if {$options(handle_normal_messages)} {
+ notify $chatid
+ }
+ }
+ }
+ }
+ chat {
+ foreach xelem $extras {
+ ::xmpp::xml::split $xelem tag xmlns attrs cdata subels
+ # Don't play sound if this 'empty' tag is present. It indicates
+ # messages history in chat window.
+ if {[string equal $tag ""] && \
+ [string equal $xmlns tkabber:x:nolog]} {
+ return
+ }
+ }
+
+ if {$from == "" && $options(handle_server_messages)} {
+ notify $chatid
+ } elseif {$options(handle_personal_messages)} {
+ notify $chatid
+ }
+ }
+ }
+}
+
+proc urgent::notify {chatid} {
+ variable options
+ variable xwinids
+
+ exec $options(program) -set $xwinids($chatid)
+}
+
+proc urgent::xwinid {win} {
+ # Parent window id: 0x2e0001e "Tkabber"
+ set data [exec xwininfo -children -id [winfo id $win]]
+ if {[regexp {Parent window id: (\S+)} $data -> id]} {
+ return $id
+ } else {
+ return ""
+ }
+}
+
+proc urgent::root_winid {xwinid _chatid} {
+ return $xwinid
+}
+
+proc urgent::chat_winid {chatid} {
+ xwinid [winfo id [chat::winid $chatid]]
+}
+
+proc urgent::record_xwinid {chatid _type} {
+ variable xwinids
+ set xwinids($chatid) [winid $chatid]
+}
+
+proc urgent::clear_urgency_hint {winid} {
+ variable options
+ variable xwinids
+
+ set chatid [chat::winid_to_chatid $winid]
+
+ exec $options(program) -clear $xwinids($chatid)
+}
+
+namespace eval urgent {
+ variable options
+
+ if {![info exists options(program)]} {
+ set options(program) [file join \
+ [file dirname [info script]] urgent]
+ }
+ if {![file executable $options(program)]} {
+ puts stderr [::msgcat::mc "Urgency hint setting program \"%s\"\
+ is not available or not executed by the current user.\
+ The \"urgent\" plugin is disabled. Consult its README file."
+ $options(program)]
+ set options(enabled) 0
+ }
+
+ if {$::ifacetk::options(use_tabbar)} {
+ interp alias {} [namespace current]::winid \
+ {} [namespace current]::root_winid [xwinid .]
+ } else {
+ interp alias {} [namespace current]::winid \
+ {} [namespace current]::chat_winid
+ }
+
+ hook::add open_chat_post_hook [namespace current]::record_xwinid 40
+ hook::add draw_message_hook [namespace current]::chat_message_notify 19
+ hook::add got_focus_hook [namespace current]::clear_urgency_hint
+}
+
+# vim:ts=8:sw=4:sts=4:noet