From e6955f3fb7cfbfb288fced60b6395bbf4e4a5c1f Mon Sep 17 00:00:00 2001 From: kostix Date: Thu, 22 Jan 2009 01:50:53 +0000 Subject: urgent/urgent.tcl: * Checking of tabbed UI mode is moved to finload hook. * Implemented cleanup of xwinids on closing of chat windows. * Misc. renaming and rearranging of functions. * Failure to parse `xwininfo` output now triggers an error. * Changed getting of X Window id for chat windows in non-tabbed UI mode. Now it doesn't pick up the root window but the id anyway seems wrong. git-svn-id: http://svn.xmpp.ru/repos/tkabber-3rd-party/trunk/plugins/urgent@167 cc602e41-bd33-0410-9637-a208f32f1443 --- urgent.tcl | 66 +++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/urgent.tcl b/urgent.tcl index af59ecc..aecf9d9 100644 --- a/urgent.tcl +++ b/urgent.tcl @@ -1,6 +1,8 @@ # $Id$ namespace eval urgent { + variable options + custom::defgroup Urgent [::msgcat::mc "Urgency hinting."] -group Plugins custom::defvar options(enabled) 1 \ @@ -38,18 +40,18 @@ proc urgent::chat_message_notify {chatid from type body extras} { groupchat { if {[string equal [chat::get_jid $chatid] $from]} { if {$options(handle_server_messages)} { - notify $chatid + set_urgency_hint $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 + set_urgency_hint $chatid } } else { if {$options(handle_normal_messages)} { - notify $chatid + set_urgency_hint $chatid } } } @@ -66,42 +68,49 @@ proc urgent::chat_message_notify {chatid from type body extras} { } if {$from == "" && $options(handle_server_messages)} { - notify $chatid + set_urgency_hint $chatid } elseif {$options(handle_personal_messages)} { - notify $chatid + set_urgency_hint $chatid } } } } -proc urgent::notify {chatid} { - variable options - variable xwinids - - exec $options(program) -set $xwinids($chatid) -} - -proc urgent::xwinid {win} { +proc urgent::xclientwinid {tkwin} { # Parent window id: 0x2e0001e "Tkabber" - set data [exec xwininfo -children -id [winfo id $win]] + set data [exec xwininfo -children -id [winfo id $tkwin]] if {[regexp {Parent window id: (\S+)} $data -> id]} { return $id } else { - return "" + error [format "Failed to parse `xwininfo` output\ + for Tk window \"%s\"" $tkwin] } } -proc urgent::root_winid {xwinid _chatid} { +proc urgent::root_xwinid {xwinid _chatid} { return $xwinid } -proc urgent::chat_winid {chatid} { - xwinid [winfo id [chat::winid $chatid]] +proc urgent::chat_xwinid {chatid} { + #xclientwinid [chat::winid $chatid] + winfo id [chat::winid $chatid] } proc urgent::record_xwinid {chatid _type} { variable xwinids - set xwinids($chatid) [winid $chatid] + set xwinids($chatid) [xwinid $chatid] +} + +proc urgent::forget_xwinid {chatid} { + variable xwinids + unset xwinids($chatid) +} + +proc urgent::set_urgency_hint {chatid} { + variable options + variable xwinids + + exec $options(program) -set $xwinids($chatid) } proc urgent::clear_urgency_hint {winid} { @@ -122,21 +131,24 @@ namespace eval 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.\ + is not available or not executable 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 finload_hook [namespace code { + if {$::ifacetk::options(use_tabbar)} { + interp alias {} [namespace current]::xwinid \ + {} [namespace current]::root_xwinid [xclientwinid .] + } else { + interp alias {} [namespace current]::xwinid \ + {} [namespace current]::chat_xwinid + } + }] hook::add open_chat_post_hook [namespace current]::record_xwinid 40 + hook::add close_chat_post_hook [namespace current]::forget_xwinid hook::add draw_message_hook [namespace current]::chat_message_notify 19 hook::add got_focus_hook [namespace current]::clear_urgency_hint } -- cgit v1.2.3