---
plugins/cpu.lua | 22 ++++++++++++++++++----
1 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/plugins/cpu.lua b/plugins/cpu.lua
index 353eb16..d8e2a53 100644
--- a/plugins/cpu.lua
+++ b/plugins/cpu.lua
@@ -112,15 +112,29 @@ function update ( new_vol )
local _, cpu
local list = cpu_list()
local space = ""
+ local count = 0
+ local curcpu = ""
for _,cpu in pairs(list) do
local str = create_string(cpu)
- if txt == str then
- txt = "2x " .. txt
+ if curcpu == str then
+ count = count + 1
else
- txt = txt .. create_string(cpu) .. space
+ if count > 1 then
+ txt = txt .. space .. count+1 .. "x " .. curcpu
+ count = 0
+ space = " "
+ else
+ if curcpu ~= "" then
+ txt = txt .. space .. curcpu
+ space = " "
+ end
+ end
+ curcpu = str
end
- space = " "
end
+ if count > 0 then
+ txt = txt .. space .. count+1 .. "x " .. curcpu
+ end
widget:show(txt)
end
--
1.5.3.4
---
plugins/network.lua | 92 ++++++++++++++++++++++++++++++++++++---------------
1 files changed, 65 insertions(+), 27 deletions(-)
diff --git a/plugins/network.lua b/plugins/network.lua
index a918eb3..656bb3a 100644
--- a/plugins/network.lua
+++ b/plugins/network.lua
@@ -8,11 +8,18 @@ network.lua - wmiirc-lua plugin for monitoring network interfaces
=head1 SYNOPSIS
-- in your wmiirc.lua:
- wmii.load_plugin("cpu")
+ wmii.load_plugin("network")
=head1 DESCRIPTION
+For the options you can define something like
+
+wmii.set_conf("network.interfaces", "wlan0,true,eth0,false")
+
+which will show informations about the wireless device wlan0 and
+the non-wireless device eth0
+
=head1 SEE ALSO
L<wmii(1)>, L<lua(1)>
@@ -33,17 +40,17 @@ is NO WARRANTY, to the extent permitted by law.
--]]
local wmii = require("wmii")
-local os = require("os")
-local posix = require("posix")
local io = require("io")
-local type = type
-local error = error
+local string = require("string")
local pairs = pairs
-local tostring = tostring
module("network")
api_version = 0.1
+wmii.set_conf("network.interfaces", "eth0,false")
+
+local devices = { }
+local wireless_devices = { }
-- ------------------------------------------------------------
-- MODULE VARIABLES
local widget = nil
@@ -65,36 +72,67 @@ local function _command ( cmd )
end
end
-function update ( new_vol )
- local txt = ""
- local ssid = "iwconfig wlan0 |grep ESSID | awk -F: '{print $2}'"
- local wlan0ip = "ifconfig wlan0 | awk -F: '/inet addr/ {print $2}' | awk '{print $1}'"
- local eth0ip = "ifconfig eth0 | awk -F: '/inet addr/ {print $2}' | awk '{print $1}'"
- local str_ssid = _command(ssid)
- str_ssid = str_ssid.sub(str_ssid, 2, str_ssid.len(str_ssid)-3)
- local str = _command(wlan0ip)
- str = str.sub(str, 1, str.len(str))
-
- if wlan0ip == "" then
- txt = "wlan0: down eth: "
- else
- txt = "wlan0: " .. str .. "@(" .. str_ssid .. ") eth0: "
- end
+local function create_device_string(device,wireless)
+ local ip = "ifconfig " .. device .. "| awk -F: '/inet addr/ {print $2}' | awk '{print $1}'"
+ local ipstr = _command(ip)
+ if ipstr == "" then
- local str_eth0 = _command(eth0ip)
- str_eth0 = str_eth0.sub(str_eth0, 1, str_eth0.len(str_eth0))
- if str_eth0 == "" then
- txt = txt .. "down"
+ txt = device .. ": down"
else
- txt = txt .. str_eth0
+ ipstr = ipstr.sub(ipstr, 1, ipstr.len(ipstr))
+ txt = device .. ": " .. ipstr
+ if wireless then
+ local ssid = "iwconfig " .. device .. " |grep ESSID | awk -F: '{print $2}'"
+ local str_ssid = _command(ssid)
+ str_ssid = str_ssid.sub(str_ssid, 2, str_ssid.len(str_ssid)-3)
+ txt = txt .. "@(" .. str_ssid .. ")"
+ end
end
+ return txt
+end
+
+local function update ()
+ local txt = ""
+ local space = ""
+ for _,device in pairs(wireless_devices) do
+ txt = txt .. space .. create_device_string(device,true)
+ space = " "
+ end
+ for _,device in pairs(devices) do
+ txt = txt .. space .. create_device_string(device,false)
+ space = " "
+ end
widget:show(txt)
end
+local function generate_lists()
+ local strings = wmii.get_conf("network.interfaces")
+
+ local string_list = { }
+
+ for str in strings:gmatch("%w+") do
+ string_list[#string_list+1] = str
+ end
+
+ local i = 1
+ while i < #string_list do
+ if string_list[i+1] == "true" then
+ wireless_devices[#wireless_devices+1] = string_list[i]
+ else
+ devices[#devices+1] = string_list[i]
+ end
+ i = i + 2
+ end
+end
+
local function network_timer ( timer )
- update(0)
+ if #devices == 0 and #wireless_devices == 0 then
+ generate_lists()
+ end
+ update()
return 60
end
+
timer = wmii.timer:new (network_timer, 1)
--
1.5.3.4
---
plugins/mpd.lua | 27 ++++++++++++++++++++++++---
1 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/plugins/mpd.lua b/plugins/mpd.lua
index f7a8969..d18a1f1 100644
--- a/plugins/mpd.lua
+++ b/plugins/mpd.lua
@@ -8,11 +8,22 @@ mpd.lua - wmiirc-lua plugin for monitoring and controlling mpd (music player dae
=head1 SYNOPSIS
-- in your wmiirc.lua:
- wmii.load_plugin("cpu")
+ mpd = wmii.load_plugin("mpd")
=head1 DESCRIPTION
+For binding the mpd controls to the multimedia keys you could add
+the following keyhandlers to your wmiirc.lua:
+
+wmii.add_key_handler('XF86AudioNext', mpd.next_song())
+
+wmii.add_key_handler('XF86AudioPrev', mpd.prev_song())
+
+wmii.add_key_handler('XF86AudioPlay', mpd.toggle_pause())
+
+wmii.add_key_handler('XF86AudioStop', mpd.stop())
+
=head1 SEE ALSO
L<wmii(1)>, L<lua(1)>
@@ -33,9 +44,7 @@ is NO WARRANTY, to the extent permitted by law.
--]]
local wmii = require("wmii")
local io = require("io")
-local os = require("os")
local string = require("string")
-local tonumber = tonumber
module("mpd")
api_version=0.1
@@ -90,5 +99,17 @@ function stop()
update_mpd_status(0)
end
+function register_action()
+ wmii.add_action_handler ("mpd",
+ function(act,args)
+ local actions = { 'play', 'pause', 'stop', 'next', 'prev' }
+ local act = wmii.menu(actions, "mpd: ")
+ local fn = function_handlers[act]
+ if fn then
+ local r, err = pcall (fn)
+ end
+ end)
+end
+
local timer = wmii.timer:new (update_mpd_status, 1)
--
1.5.3.4
---
plugins/battery.lua | 50 ++++++++++++++++++++++++++++++--------------------
1 files changed, 30 insertions(+), 20 deletions(-)
diff --git a/plugins/battery.lua b/plugins/battery.lua
index e3bcf89..4fc587a 100644
--- a/plugins/battery.lua
+++ b/plugins/battery.lua
@@ -167,6 +167,9 @@ wmii.set_conf ("battery.critical_action", 'echo "Critical battery" | xmessage -
wmii.set_conf ("battery.statefile", "/proc/acpi/battery/%s/state")
wmii.set_conf ("battery.infofile", "/proc/acpi/battery/%s/info")
+wmii.set_conf ("battery.showtime", true)
+wmii.set_conf ("battery.showrate", true)
+
--
-- Local Variables
--
@@ -246,29 +249,36 @@ local function update_single_battery ( battery )
local batt_rate = batt:match('present rate:%s+(%d+)') * 1
- local batt_time = "inf"
- if batt_rate > 0 then
- if batt_state == "^" then
- batt_time = (battinfo:match('last full capacity:%s+(%d+)') - batt:match('remaining capacity:%s+(%d+)')) / batt_rate
- else
- batt_time = batt:match('remaining capacity:%s+(%d+)') / batt_rate
- end
- local hour = string.format("%d",batt_time)
- local min = (batt_time - hour) * 60
-
- if min > 59 then
- min = min - 60
- hour = hour + 1
+ local batt_time = ""
+ if wmii.get_conf(battery.showtime) then
+ batt_time = "inf"
+ if batt_rate > 0 then
+ if batt_state == "^" then
+ batt_time = (battinfo:match('last full capacity:%s+(%d+)') - batt:match('remaining capacity:%s+(%d+)')) / batt_rate
+ else
+ batt_time = batt:match('remaining capacity:%s+(%d+)') / batt_rate
+ end
+ local hour = string.format("%d",batt_time)
+ local min = (batt_time - hour) * 60
+
+ if min > 59 then
+ min = min - 60
+ hour = hour + 1
+ end
+ if min < 0 then
+ min = 0
+ end
+ batt_time = hour .. ':'
+ batt_time = batt_time .. string.format("%.2d",min)
end
- if min < 0 then
- min = 0
- end
- batt_time = hour .. ':'
- batt_time = batt_time .. string.format("%.2d",min)
end
- batt_rate = batt_rate/1000
- printout = string.format("%.2f",batt_rate) .. 'W -> ' .. batt_time .. '(' .. batt_state .. string.format("%.0f",batt_percent) .. batt_state .. ')'
+ local battrate_string = ""
+ if wmii.get_conf(battery.showrate) then
+ batt_rate = batt_rate/1000
+ battrate_string = string.format("%.2f",batt_rate) .. 'W '
+ end
+ printout = battrate_string .. batt_time .. '(' .. batt_state .. string.format("%.0f",batt_percent) .. batt_state .. ')'
battery["widget"]:show(printout, colors)
end
--
1.5.3.4
Good stuff! However, it might be a bit cleaner if you split
wireless/non-wireless out into two config options, rather than passing a
flag that has to be parsed. Perhaps:
wmii.set_conf("network.interfaces.wired", "eth0")
wmii.set_conf("network.interfaces.wireless", "wlan0")
could work?
> +local function create_device_string(device,wireless)
> + local ip = "ifconfig " .. device .. "| awk -F: '/inet addr/ {print $2}' | awk '{print $1}'"
Can you make the awk/grep stuff go away and do the text processing in
lua instead? Bart and I tend to be a bit picky about this. We run wmii
on our laptops, and cutting down on unnecessary fork/exec saves wakeups
and battery time.
Cheers,
Dave
--
Dave O'Neill <d...@roaringpenguin.com> Roaring Penguin Software Inc.
+1 (613) 231-6599 http://www.roaringpenguin.com/
For CanIt technical support, please mail: sup...@roaringpenguin.com
On Fri, Oct 24, 2008 at 11:02:10AM -0400, Dave O'Neill wrote:
> Good stuff! However, it might be a bit cleaner if you split
> wireless/non-wireless out into two config options, rather than passing a
> flag that has to be parsed. Perhaps:
>
> wmii.set_conf("network.interfaces.wired", "eth0")
> wmii.set_conf("network.interfaces.wireless", "wlan0")
>
> could work?
looks fine... I will update it.
> > +local function create_device_string(device,wireless)
> > + local ip = "ifconfig " .. device .. "| awk -F: '/inet addr/ {print $2}' | awk '{print $1}'"
>
> Can you make the awk/grep stuff go away and do the text processing in
> lua instead? Bart and I tend to be a bit picky about this. We run wmii
> on our laptops, and cutting down on unnecessary fork/exec saves wakeups
> and battery time.
yeah already thought about that part, I run wmii on my laptop
too. the problem is that I dont have that much practice in using
lua for text processing, but I will have a look at it.
Regards,
Jan
--
Jan-David Quesel
Carl von Ossietzky Universität Oldenburg
Department of Computing Science
Correct System Design
D-26111 Oldenburg, Germany
Phone: +49 (0)441 798-2376
Fax: +49 (0)441 798-2965