File: taskbar.tcl

package info (click to toggle)
tkabber 0.11.1-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 5,348 kB
  • ctags: 2,447
  • sloc: tcl: 48,540; xml: 3,361; sh: 1,387; makefile: 66
file content (222 lines) | stat: -rw-r--r-- 5,499 bytes parent folder | download | duplicates (2)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# $Id: taskbar.tcl 1488 2008-08-25 10:14:35Z sergei $

# MS Windows taskbar and tray icon support.
# Requires Winico package
# (http://tktable.sourceforge.net/winico/winico.html)

##########################################################################

if {![cequal $::interface tk]} return

if {[catch { package require Winico }]} return

##########################################################################

namespace eval taskbar {
    variable s2p
    array set s2p [list blank       0 \
			available   1 \
			away	    2 \
			chat	    3 \
			dnd	    4 \
			xa	    5 \
		        unavailable 6 \
			invisible   7 \
			browser     8 \
			group       9 \
			browser32   10 \
			group32     11 \
			available32 12 \
			message1    13 \
			message2    14 \
			message3    15]

    variable options

    custom::defvar options(enable) 1 \
	[::msgcat::mc "Enable windows tray icon."] \
	-group Systray -type boolean \
	-command [namespace code enable_disable]
}

##########################################################################
#
# Systray icons
#
##########################################################################

proc taskbar::set_current_theme {} {
    variable icon
    variable s2p
    global userstatus

    set newicon [winico createfrom [pixmaps::get_filename docking/tkabber]]

    if {[info exists icon]} {
	set oldicon $icon
	set icon $newicon

	# Change taskbar icon:
	winico taskbar add $newicon
	# TODO ideally there should be a call to [enable_disable]
	# instead but the latter relies on the existence of some
	# windows (i.e. it's called from finload_hook) while this
	# proc is called for the first time earlier in the loading
	# sequence...
	configure .tray $userstatus

	# Change icons of all mapped toplevels:
	foreach w [wm stackorder .] {
	    win_icon_setup $w
	}

	winico delete $oldicon
    } else {
	set icon $newicon
    }
}

hook::add set_theme_hook [namespace current]::taskbar::set_current_theme

##########################################################################

proc taskbar::enable_disable {args} {
    variable options

    set m .tray

    if {$options(enable) && ![winfo exists $m]} {
	ifacetk::systray::create $m \
	    -createcommand [namespace code create] \
	    -configurecommand [namespace code configure] \
	    -destroycommand [namespace code destroy]
    } elseif {!$options(enable) && [winfo exists $m]} {
	ifacetk::systray::destroy $m
    }
}

hook::add finload_hook [namespace current]::taskbar::enable_disable

##########################################################################

proc taskbar::create {m} {
    variable icon
    variable s2p

    set m [ifacetk::systray::popupmenu .tray]

    winico taskbar add $icon -pos $s2p(unavailable) \
	   -callback [namespace code [list callback $m %m %x %y]] \
	   -text [ifacetk::systray::balloon_text]
}

##########################################################################

proc taskbar::configure {m status} {
    variable icon
    variable s2p

    if {[info exists icon] && ![cequal $icon ""]} {
	winico taskbar modify $icon -pos $s2p($status) \
	       -text [ifacetk::systray::balloon_text]
    }
}

##########################################################################

proc taskbar::destroy {m} {
    variable icon

    if {[info exists icon] && ![cequal $icon ""]} {
	winico taskbar delete $icon
	::destroy $m
    }
}

##########################################################################

proc taskbar::callback {m event x y} {
    switch -- $event {
	WM_LBUTTONUP {
	    ifacetk::systray::restore
	}

	WM_MBUTTONUP {
	    ifacetk::systray::withdraw
	}

	WM_RBUTTONUP {
	    $m post $x $y
	}
    }
}

##########################################################################
#
# Window & taskbar icons
#
##########################################################################

proc taskbar::win_icons {} {
    variable icon
    variable s2p

    winico setwindow . $icon small $s2p(unavailable)
    winico setwindow . $icon big $s2p(available32)

    trace variable ::curuserstatus w [namespace code update]

    bind all <Map> +[namespace code {
	if {[string equal [winfo toplevel %W] %W]} { win_icon_setup %W }
    }]
}

hook::add finload_hook [namespace current]::taskbar::win_icons

##########################################################################

proc taskbar::win_icon_setup {w} {
    variable icon
    variable s2p
    global userstatus

    if {[cequal $icon ""]} return

    # Special case for the main window (which is also the roster
    # window in windowed UI mode) -- it shows the current
    # user status in its window icon:
    if {[string equal $w .]} {
	winico setwindow $w $icon small $s2p($userstatus)
	winico setwindow $w $icon big $s2p(available32)
	return
    }

    switch -- [winfo class $w] {
	Chat {
	    winico setwindow $w $icon small $s2p(group)
	    winico setwindow $w $icon big $s2p(group32)
	}
	JDisco {
	    winico setwindow $w $icon small $s2p(browser)
	    winico setwindow $w $icon big $s2p(browser32)
	}
	default {
	    winico setwindow $w $icon small $s2p(available)
	    winico setwindow $w $icon big $s2p(available32)
	}
    }
}

##########################################################################

proc taskbar::update {name1 {name2 ""} {op ""}} {
    global curuserstatus
    variable icon
    variable s2p

    winico setwindow . $icon small $s2p($curuserstatus)
}

##########################################################################

# vim:ts=8:sw=4:sts=4:noet