Initial revision
[wmaker-crm.git] / util / dockit
blobcecd25e165a9085cbd9f2421898e992141f01afc
1 #!/bin/sh
2 # Only run the following line once \
3 exec wish -f $0 $@
5 ##########################################
6 #Copyright 1998 Kenneth W. Persinger Jr. #
7 # Written for WindowMaker #
8 ##########################################
11 # You can add the full path for Xprop here.
12 set xprop xprop
14 ###############################
15 # DO NOT EDIT BELOW THIS LINE #
16 ###############################
17 global xprop;
18 global instance;set instance ""
19 global class;set class ""
20 global command; set command ""
21 global Version;set Version "V1.3"
24 global Version
25 global instance
26 global class
27 global command
28 wm withdraw .
29 wm group . .
31 toplevel .dockit -class Dockit
32 wm group .dockit .dockit
33 wm command .dockit "$argv0 $argv"
34 wm iconname .dockit "Dockit ${Version}"
35 wm protocol .dockit WM_DELETE_WINDOW {exit}
36 wm focusmodel .dockit passive
37 wm title .dockit "Dockit ${Version}"
38 wm geometry .dockit 309x157+440+412
39 wm maxsize .dockit 1265 994
40 wm minsize .dockit 1 1
41 wm overrideredirect .dockit 0
42 wm resizable .dockit 0 0
43 wm deiconify .dockit
45 label .dockit.msgbar \
46 -anchor nw -borderwidth 1 -justify left -relief raised \
47 -text ""
48 label .dockit.instlbl \
49 -borderwidth 1 -relief raised -text Instance
50 label .dockit.cllbl \
51 -borderwidth 1 -relief raised -text Class
52 label .dockit.comlbl \
53 -borderwidth 1 -relief raised -text Command
54 entry .dockit.instent -textvariable instance
55 entry .dockit.clent -textvariable class
56 entry .dockit.coment -textvariable command
57 button .dockit.create \
58 -padx 9 -pady 3 -text {Create Icon} -command {docreate}
59 button .dockit.exit \
60 -padx 9 -pady 3 -text Quit -command exit
61 button .dockit.grab \
62 -padx 9 -pady 3 -text Grab -command {dograb}
63 button .dockit.help \
64 -padx 9 -pady 3 -text Help -command {dohelp}
65 ###################
66 # SETTING GEOMETRY
67 ###################
68 place .dockit.msgbar \
69 -x 5 -y 120 -width 296 -height 33 -anchor nw -bordermode ignore
70 place .dockit.instlbl \
71 -x 5 -y 5 -width 76 -height 23 -anchor nw -bordermode ignore
72 place .dockit.cllbl \
73 -x 5 -y 30 -width 76 -height 23 -anchor nw -bordermode ignore
74 place .dockit.comlbl \
75 -x 5 -y 55 -width 76 -height 23 -anchor nw -bordermode ignore
76 place .dockit.instent \
77 -x 85 -y 5 -width 216 -height 22 -anchor nw -bordermode ignore
78 place .dockit.clent \
79 -x 85 -y 30 -width 216 -height 22 -anchor nw -bordermode ignore
80 place .dockit.coment \
81 -x 85 -y 55 -width 216 -height 22 -anchor nw -bordermode ignore
82 place .dockit.create \
83 -x 5 -y 80 -width 77 -height 36 -anchor nw -bordermode ignore
84 place .dockit.exit \
85 -x 230 -y 80 -width 72 -height 36 -anchor nw -bordermode ignore
86 place .dockit.grab \
87 -x 80 -y 80 -width 77 -height 36 -anchor nw -bordermode ignore
88 place .dockit.help \
89 -x 155 -y 80 -width 77 -height 36 -anchor nw -bordermode ignore
90 ############
91 # Bindings #
92 ############
93 bind all <Leave> {message ""}
94 bind .dockit.instlbl <Enter> {message "Instance name goes here.
95 (the 1st string of WM_CLASS)"}
96 bind .dockit.instent <Enter> {message "Instance name goes here.
97 (the 1st string of WM_CLASS)"}
98 bind .dockit.cllbl <Enter> {message "Class name goes here.
99 (the 2nd string of WM_CLASS)"}
100 bind .dockit.clent <Enter> {message "Class name goes here.
101 (the 2nd string of WM_CLASS)"}
102 bind .dockit.comlbl <Enter> {message "The command to execute goes here.
103 (all of WM_COMMAND)"}
104 bind .dockit.coment <Enter> {message "The command to execute goes here.
105 (all of WM_COMMAND)"}
106 bind .dockit.create <Enter> {message "Create you custom AppIcon."}
107 bind .dockit.exit <Enter> {message "Exit Dockit!"}
108 bind .dockit.help <Enter> {message "Help with creating AppIcons,
109 and for these commands."}
110 bind .dockit.grab <Enter> {message "Grab AppInfo from a running App."}
113 ###################
114 # Actual Code #
115 ###################
117 proc message {message} {
118 .dockit.msgbar configure -text $message
121 proc docreate {} {
122 global Version
123 global instance
124 global class
125 global command
127 if {$command == ""} {
128 tk_dialog .error "DockIt ${Version}: ERROR" \
129 "You must supply a command line. Otherwise your icon would do nothing!" \
130 "" "" "Doh!"
131 } else {
132 set insttmp $instance
133 set classtmp $class
134 set commandtmp $command
136 if {$insttmp == ""} { set insttmp "dockit" }
137 if {$classtmp == ""} { set classtmp "DockedApp" }
139 toplevel .$insttmp -class $classtmp
140 wm command .$insttmp "$commandtmp"
141 wm group .$insttmp .$insttmp
142 label .$insttmp.l1 -text "
143 Great! Your new App-Icon should be finished now.
144 once you have dragged it to the Dock, Click Finish.
145 If your Icon doesn't Dock, or does not appear,
146 Try again. If problems persist, see Dockit's Help."
147 button .$insttmp.b1 -text "Finish" -command "destroy .$insttmp"
148 pack .$insttmp.l1
149 pack .$insttmp.b1
150 wm title .$insttmp "Dockit ${Version}: Confirmation"
154 proc dohelp {} {
155 global Version
157 set HLPTXT { Dockit V1.2
159 General Info:
161 Dockit is a tool designed to provide the ability to Dock
162 poorly coded programs within WindowMaker.
164 This is not a 100% accurate solution. It was not designed to be.
165 It will however, generate a dockable icon 99% of the time.
166 for that other 1%, you will need to edit by hand.
168 Troubleshooting:
170 Error: 'window name starts with an upper-case letter':
172 This is a limitation of Tcl/Tk.
173 window/pathnames cannot start with an uppercase letter.
174 This behavior is most noticable in Netscape's Navigator.
175 It's instance is 'Navigator'
176 A work-around to this limitation, is to double-define your App
177 settings. (ex:'navigator', and 'Navigator')
180 Error: couldn't execute "xprop": no such file or directory
182 This means that /usr/X11R6/bin (or its equivilent)
183 is not defined in your path.
184 You must add this to your path.
188 AppIcon does not appear as it should:
190 This could happen for a number of reasons.
191 A: You have NoAppIcon defined for that particular App.
192 B: One word: El Ni~no
196 App Closes, but Dots do not appear/ Cannot remove Icon from the Dock:
198 This is the result of a VERY poorly coded App.
199 As far as WIndowMaker can tell, the program is still running.
200 The only real fix for this, is CTRL + ALT + BACKSPACE
205 toplevel .userhelp -class Dockit
206 wm group .userhelp .dockit
207 wm iconname .userhelp "Dockit HELP"
208 wm focusmodel .userhelp passive
209 wm geometry .userhelp 456x635
210 wm maxsize .userhelp 1265 1265
211 wm minsize .userhelp 1 1
212 wm overrideredirect .userhelp 0
213 wm resizable .userhelp 1 1
214 wm deiconify .userhelp
215 wm title .userhelp "Dockit ${Version}: HELP"
216 label .userhelp.text \
217 -anchor nw -justify left -borderwidth 1 \
218 -text $HLPTXT
219 place .userhelp.text \
220 -x 0 -y 0 -anchor nw -bordermode ignore
225 proc dograb {} {
226 global xprop
227 global class
228 global instance
229 global command
231 catch "open ~/GNUstep/.AppInfo/xprop1 w+" m1
232 exec ${xprop} >@ $m1
233 seek $m1 0
234 set tmpmsg [read $m1]
235 set tmpmsg [split $tmpmsg \n]
236 close $m1
237 #Make sure we are the leader
238 foreach junk $tmpmsg {
239 if {[string match "WM_TRANSIENT_FOR(WINDOW): window id \# *" $junk]} {
240 dograb+ [lindex $junk 4] NNNN
241 return 1
242 } elseif {[string match "*window id # of group leader: *" $junk]} {
243 dograb+ [lindex $junk 6] NNNN
244 return 1
248 set tclass [lindex $tmpmsg [lsearch -glob $tmpmsg *WM_CLASS*]]
249 set tclass [split $tclass ,]
250 set class [string trim [lindex $tclass 1] \ \"]
251 set instance [string tolower \
252 [string trim [lindex [lindex $tclass 0] 2] \ \"]]
253 set tcom [lindex $tmpmsg [lsearch -glob $tmpmsg *WM_COMMAND*]]
254 set tcom [split [lindex $tcom 2] \,]
255 set tcom [split [join $tcom] \"]
256 set command [join [join $tcom]]
260 proc dograb+ {winid sourcewin} {
261 global xprop
262 global class
263 global instance
264 global command
266 catch "open ~/GNUstep/.AppInfo/xprop1 w+" m1
267 exec ${xprop} -id $winid >@ $m1
268 seek $m1 0
269 set tmpmsg [read $m1]
270 set tmpmsg [split $tmpmsg \n]
272 # Make sure we arent hitting a Loop, where we show ourself as
273 # The group leader.
274 if { ![string match $sourcewin $winid]} {
276 # recurse to the toplevel leader.
277 foreach junk $tmpmsg {
278 if {[string match "WM_TRANSIENT_FOR(WINDOW): window id # *" $junk]} {
279 dograb+ [lindex $junk 4] $winid
280 return 1
281 } elseif {[string match "*window id # of group leader: *" $junk]} {
282 dograb+ [lindex $junk 6] $winid
283 return 1
288 set tclass [lindex $tmpmsg [lsearch -glob $tmpmsg *WM_CLASS*]]
289 set tclass [split $tclass ,]
290 set class [string trim [lindex $tclass 1] \ \"]
291 set instance [string tolower \
292 [string trim [lindex [lindex $tclass 0] 2] \ \"]]
293 set tcom [lindex $tmpmsg [lsearch -glob $tmpmsg *WM_COMMAND*]]
294 set tcom [split [lindex $tcom 2] \,]
295 set tcom [split [join $tcom] \"]
296 set command [join [join $tcom]]
297 close $m1