home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- # =====
- # USAGE
- # =====
- # This application can receive two parameters
- # -orientation [horizontal | vertical]
- # Specifies the orientation for the volume slider
- # the default is vertical
- # -image <imagefilename>
- # Specifies an image to be used in the volume button
- # The image must be a gif image.
- # Both parameters are optional. You can use shorhand for the parameters -o -i
- # e.g.
- # mini-volume -o hor -i /root/myimage.gif
- #
- # =======
- # LICENSE
- # =======
- # This program can be used and modified freely and you are welcome to
- # redistribute it under the following terms:
- #
- # - This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- # - Any derived works should be also distributed freely under an all-permisive
- # license. Share the spirit of open source.
- # - The following is not a requirement but a request:
- # If you make changes to the application to fit a particular purpose or
- # feature please share them with me contacting me at (rarsa at yahoo.com)
-
- # the next line restarts using wish \
- exec wish "$0" "$@"
-
- set volcommand {setvol 0 | cut -d" " -f2}
-
- set orient "vert"
- set imagepath "/usr/local/lib/X11/mini-icons/mini-volume.gif"
- set showing "false"
- set bgcolor "gray"
-
- proc setvolume { level } {
- exec setvol 0 $level
- }
-
- proc getvolume { } {
- set volcommand { setvol 0 | cut -d" " -f2 }
- set gain [exec sh -c ($volcommand)]
- }
-
- proc parseParams { params } {
- global orient
- global imagepath
- global bgcolor
-
- for {set i 0} {$i < [llength $params]} {incr i} {
- set arg [lindex $params $i]
- if {[string first "-o" $arg] == 0} {
- incr i;
- if {[string first "h" [lindex $params $i]] == 0} {
- set orient "hor"
- }
- }
- if {[string first "-i" $arg] == 0} {
- incr i;
- set imagepath [lindex $params $i]
- }
- if {[string first "-bg" $arg] == 0} {
- incr i;
- set bgcolor [lindex $params $i]
- }
- }
- }
-
- proc tooltip:show {w arg} {
- global prev
- if {[eval winfo containing [winfo pointerxy .]]!=$w} {return}
- if {[expr abs($prev - [clock clicks -milliseconds])] < 200 } {
- set prev [clock clicks -milliseconds]
- return
- }
- set prev [clock clicks -milliseconds]
-
- set top $w.tooltip
- catch {destroy $top}
- toplevel $top -bd 1 -bg black
- wm overrideredirect $top 1
- pack [message $top.txt -aspect 10000 -bg lightyellow \
- -font fixed -text [concat $arg [ getvolume ]]]
- set wmx [winfo rootx $w]
- set wmy [expr [winfo rooty $w]-[winfo height $w]]
- wm geometry $top \
- [winfo reqwidth $top.txt]x[winfo reqheight $top.txt]+$wmx+$wmy
- raise $top
- }
-
- proc volume:show {w} {
- global gain
- global orient
- global showing
- global bgcolor
-
- set top $w.volume
- catch {destroy $top}
- if { $showing == "true" } {
- set showing "false"
- } else {
- toplevel $top -bd 0 -bg black
- wm overrideredirect $top 1
- set gain [ getvolume ]
-
- set wmx [winfo rootx $w]
- if {$orient == "vert"} {
- pack [scale $top.sv -show no -orient ver -from 100 -to 0 \
- -sliderlength 5 -command { setvolume } \
- -len 70 -bg $bgcolor -var gain]
- set wmy [expr [winfo rooty $w]-75]
- } else {
- pack [scale $top.sv -show no -orient hor \
- -sliderlength 5 -command { setvolume } \
- -len 70 -bg $bgcolor -var gain]
- set wmy [expr [winfo rooty $w]-[winfo height $w]]
- }
- bind $top.sv <Button-4> { volume:up %W }
- bind $top.sv <Button-5> { volume:down %W }
-
- wm geometry $top \
- [winfo reqwidth $top.sv]x[winfo reqheight $top.sv]+$wmx+$wmy
- bind $w.volume <Any-Leave> {after 500 destroy %W
- set showing "false"}
- raise $top
- set showing "true"
- }
- }
-
- proc volume:up { w } {
- global gain
- if { $gain > 98 } {
- set gain 100
- } else {
- set gain [expr $gain + 2]
- }
- setvolume $gain
- after 200 [list tooltip:show $w Volume]
- }
-
- proc volume:down { w } {
- global gain
-
- if { $gain < 2 } {
- set gain 0
- } else {
- set gain [expr $gain - 2]
- }
- setvolume $gain
- after 200 [list tooltip:show $w Volume]
- }
-
- parseParams $argv
-
- set gain [ getvolume ]
- set prev [clock clicks -milliseconds]
-
- image create photo img-mini-vol -file $imagepath
- button .b -text V -image img-mini-vol -bd 0 -bg $bgcolor
- bind .b <ButtonPress-1> { list volume:show %W }
- bind .b <Any-Enter> { after 500 [list tooltip:show %W Volume] }
- bind .b <Any-Leave> { destroy .b.tooltip }
- bind .b <ButtonPress-1> { volume:show %W }
- bind .b <Button-4> { volume:up %W }
- bind .b <Button-5> { volume:down %W }
- pack .b
-