3
# i8kui -- User interface for i8kutils
5
# Copyright (C) 2014-2015 Vitor Augusto <vitorafsr@gmail.com>
7
# This program is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by the
9
# Free Software Foundation; either version 2, or (at your option) any
12
# This program is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# General Public License for more details.
19
sysconfig /etc/i8kmon.conf
41
# read system config file
42
if {[file exists $config(sysconfig)]} {
43
source $config(sysconfig)
44
if {$config(verbose) > 0} {
45
puts "reading system config file"
49
# read user config file
50
# as it is read last, the options here have precedence
51
if {$config(use_conf) != 0} {
52
if {[file exists $config(userconfig)]} {
53
source $config(userconfig)
54
if {$config(verbose) > 0} {
55
puts "reading user config file"
61
proc status_timer {} {
64
# Reschedule status timer
65
after [expr $config(timeout)*1000] {status_timer}
76
if {[info command .i8kui] != {}} {
77
# Applet aready existing
81
# Load Tk library (require a Tk version >=8.4)
82
package require Tk 8.4
86
toplevel .i8kui -class I8kui -relief sunken -bd 1
87
wm title .i8kui i8kmon
88
wm command .i8kui i8kmon
89
wm protocol .i8kui WM_DELETE_WINDOW { exit }
91
if {$config(geometry) != {}} {
92
set geometry $config(geometry)
96
if {[lindex [split $geometry x] 1] >= 36} {
101
wm geometry .i8kui $geometry
103
label .i8kui.temp -bd 0 -padx 0 -pady 0 -text "0" -font $font \
104
-highlightthickness 0 -width 3
105
button .i8kui.lfan -bd 1 -padx 0 -pady 0 -text {} -font $font \
106
-highlightthickness 0 -command {toggle_fan left}
107
button .i8kui.rfan -bd 1 -padx 0 -pady 0 -text {} -font $font \
108
-highlightthickness 0 -command {toggle_fan right}
109
bind .i8kui.lfan <Button-2> {toggle_fan left 2}
110
bind .i8kui.lfan <Button-3> {toggle_fan left 0}
111
bind .i8kui.rfan <Button-2> {toggle_fan right 2}
112
bind .i8kui.rfan <Button-3> {toggle_fan right 0}
114
place .i8kui.temp -relx 0.0 -rely 0.0 -relwidth 1.0 -relheight 0.5
115
place .i8kui.lfan -relx 0.0 -rely 0.5 -relwidth 0.5 -relheight 0.5
116
place .i8kui.rfan -relx 0.5 -rely 0.5 -relwidth 0.5 -relheight 0.5
118
# Set $status(lstate) and $status(rstate)
119
set x [eval exec i8kfan]
120
set status(lstate) [lindex $x 0]
121
set status(rstate) [lindex $x 1]
122
if {$status(lstate) < 0} {
123
place forget .i8kui.lfan
124
place .i8kui.rfan -relx 0 -rely 0.5 -relwidth 1 -relheight 0.5
126
if {$status(rstate) < 0} {
127
place forget .i8kui.rfan
128
place .i8kui.lfan -relx 0 -rely 0.5 -relwidth 1 -relheight 0.5
131
set status(bg) [.i8kui.lfan cget -bg]
132
set status(activebg) [.i8kui.lfan cget -activebackground]
135
menu $menu -tearoff 0
136
$menu add check -label "Verbose" -variable config(verbose)
138
$menu add command -label "Reload" -command { read_config; update_ui }
139
$menu add command -label "Exit" -command { exit }
141
bind .i8kui.temp <Button-1> "tk_popup $menu %X %Y"
150
# If applet window is unexpectedly destroyed exit the program
151
if {![winfo exists .i8kui]} {
152
puts stderr "applet window destroyed, exit"
157
set ab $status(activebg)
160
set temp [eval exec "i8kctl temp"]
161
if {$temp >= $config(t_high)} {
166
if {$config(unit) == "F" } {
167
.i8kui.temp config -text [expr (0+$temp)*9/5+32] -fg $fg
169
.i8kui.temp config -text $temp -fg $fg
173
set x [eval exec i8kfan]
174
set status(lstate) [lindex $x 0]
175
set status(rstate) [lindex $x 1]
176
if {$status(lstate) == 0} {
177
.i8kui.lfan config -text {} -bg $bg -activebackground $ab
178
} elseif {$status(lstate) >= 2} {
179
.i8kui.lfan config -text $status(lstate) -bg red -activebackground red
181
.i8kui.lfan config -text $status(lstate) -bg $bg -activebackground $ab
185
if {$status(nfans) < 2} { return }
186
if {$status(rstate) == 0} {
187
.i8kui.rfan config -text {} -bg $bg -activebackground $ab
188
} elseif {$status(rstate) >= 2} {
189
.i8kui.rfan config -text $status(rstate) -bg red -activebackground red
191
.i8kui.rfan config -text $status(rstate) -bg $bg -activebackground $ab
197
proc toggle_fan {fan {speed {}}} {
202
set status($fan) $speed
204
if {$fan == "left"} {
205
set status($fan) $status(lstate)
207
set status($fan) $status(rstate)
209
set status($fan) [expr ($status($fan)+1) % 3]
212
set status($fan) [expr ($status($fan)+1) % 3]
214
if {$fan == "left"} {
215
exec i8kfan $status($fan) "-"
217
exec i8kfan "-" $status($fan)
221
if {$tcl_interactive == 0} {