6 # [WISH-OPTIONS... [-- TRAY-EMBED-OPTIONS... [-- XBATMON-SIMPLE-OPTIONS...]]]
12 proc cmdline {id orientation} {
14 return [concat [list xacpi-simple -into $id] $argv]
17 #----- tooltip generation -----
19 proc tt-invisible {} {
21 applet::tooltip-set {}
26 catch { after cancel $ttafter }
27 catch { unset ttafter }
33 set ttafter [after 500 tt-show]
34 applet::tooltip-set [tt-string]
41 set dir /sys/class/power_supply
42 foreach f [glob -nocomplain -tails -directory $dir *] {
43 debug::debug "TT-INFO $f"
45 set chan [open $dir/$f/uevent]
48 set info "error: $info"
49 debug::debug "$f $errorInfo"
51 lappend lines "$f: $info"
56 lappend lines "error scanning: $emsg"
57 debug::debug "scanning $errorInfo"
59 if {![llength $lines]} {
60 lappend lines "no power information"
62 return [join $lines "\n"]
65 proc compute {power energy factor} {
68 debug::debug "COMPUTE $power $energy $factor"
69 foreach ent {energy NOW} {energy FULL} {energy FULL_DESIGN} {power NOW} {
72 if {![info exists a($kv)]} { return 0 }
73 set q("${pe}_${k}") [expr {$a($kv) * $factor}]
79 while {[gets $chan l] >= 0} {
80 if {[regexp {^POWER_SUPPLY_([A-Z0-9_]+)=(.*)$} $l dummy k v]} {
81 debug::debug " uevent ok $l"
84 debug::debug " uevent unk $l"
88 switch -exact -- $a(TYPE) {
90 switch -exact -- $a(ONLINE) {
91 0 { append o " Offline" }
92 1 { append o " Online" }
93 default { append o " ?$o" }
97 switch -exact -- $a(PRESENT) {
98 0 { append o " Absent"; return $o }
99 1 { append o " Present" }
100 default { apend o " ?$o" }
102 append o " $a(STATUS)"
103 if {[compute POWER ENERGY 1.0] ||
104 [compute CURRENT CHARGE [expr {$a(VOLTAGE_NOW) * 1e-6}]]} {
105 debug::debug "COMPUTE OK"
115 proc mode/normal {} {
116 uplevel #0 source applet.tcl
117 applet::setup-subproc cmdline
118 applet::setup-tooltip tt-show tt-invisible
121 proc mode/-tooltip-string {} {
126 #----- command line parsing -----
130 while {[args::next_special arg]} {
131 switch -exact -- $arg {
133 -tooltip-string { set mode $arg }
134 default { args::badoption }