-
Notifications
You must be signed in to change notification settings - Fork 0
/
tkchat_winico.tcl
73 lines (63 loc) · 1.83 KB
/
tkchat_winico.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Windows taskbar support.
# At some point I want to support multiple icons for nochat/chat/alert.
#
# TODO: deal with IncrMessageCOunter and ResetMessageCounter and detach bookmark
if {[tk windowingsystem] ne "win32"} { return }
if {[catch {
package require Winico
}]} {
return
}
namespace eval ::tkchat::winico {
variable version 1.0.0
}
proc ::tkchat::winico::InitHook {} {
variable TaskbarIcon
variable WinicoWmState [wm state .]
set icofile [file join [file dirname [info script]] tkchat.ico]
if {[file exists $icofile]} {
set TaskbarIcon [winico createfrom $icofile]
winico taskbar add $TaskbarIcon \
-pos 0 \
-text [wm title .] \
-callback [list [namespace origin Callback] %m %i]
bind . <Destroy> [namespace origin Cleanup]
}
}
proc ::tkchat::winico::Update {} {
variable ::tkchat::MessageCounter
variable TaskbarIcon
if {[llength [info commands winico]] < 1} { return }
if { $MessageCounter > 0 } {
winico taskbar modify $TaskbarIcon \
-pos 2 \
-text "$MessageCounter - Tcl'ers chat"
} else {
winico taskbar modify $TaskbarIcon \
-pos 0 \
-text "Tcl'ers chat"
}
}
proc ::tkchat::winico::Cleanup {} {
variable TaskbarIcon
winico taskbar delete $TaskbarIcon
}
proc ::tkchat::winico::Callback {msg icn} {
variable WinicoWmState
switch -exact -- $msg {
WM_LBUTTONDOWN {
if { [wm state .] eq "withdrawn" } {
wm state . $WinicoWmState
wm deiconify .
focus .eMsg
} else {
set WinicoWmState [wm state .]
wm withdraw .
}
}
}
}
# -------------------------------------------------------------------------
::tkchat::Hook add init ::tkchat::winico::InitHook
package provide tkchat::winico $::tkchat::winico::version
# -------------------------------------------------------------------------