-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 I don't have the time for a description, just read the commit messages. :P
Cheers - -- "Do you know that books smell like nutmeg or some spice from a foreign land?" -- Faber in Fahrenheit 451 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iQEcBAEBCAAGBQJKdw6VAAoJECLkKOvLj8sGfOUIALZO2RtZQoyt01e1a74L3TrQ GY5e32mltwDXyUbR7yKbqOuDDUqTrSpWKn6aPlbvFvvDhg7MuLtvOcKtECKyxEra YxMfADv6jCVtv3p0V5//Gzsz7xJxItkkeu8sevOfBcaeipgZrgmVYddSXcyh8lnL dQHDI06/HrdghttKo5byxO/CAtE4kTNJIhJ2QXe23bksbhbpcK5VmgqUEv+G7PWO q4NEtv/cwN+yRN9MvRe08Em7gKJEelk0l4NSZL9WX8WBhfHEFXnVZiLOAjlCNMXC SxuGNW3pFnoXDYuJp9azF+sVz6zZbw5Ssa6Uq6yHgtt8YUKpUi8AIJvWoeT3nRA= =Oztg -----END PGP SIGNATURE-----
>From 2d9caf3ed15e2c3b19967f212cdffe9c8aa3f37b Mon Sep 17 00:00:00 2001 From: Uli Schlachter <psyc...@znc.in> Date: Mon, 3 Aug 2009 16:12:00 +0200 Subject: [PATCH 1/4] Move code for getting the wlan strength to lib.wlan Signed-off-by: Uli Schlachter <psyc...@znc.in> --- lib/init.lua | 1 + lib/wlan.lua | 30 ++++++++++++++++++++++++++++++ wlan/init.lua | 30 ++++-------------------------- 3 files changed, 35 insertions(+), 26 deletions(-) create mode 100644 lib/wlan.lua diff --git a/lib/init.lua b/lib/init.lua index 1a67666..b908d48 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -6,6 +6,7 @@ require("obvious.lib.hooks") require("obvious.lib.util") require("obvious.lib.mpd") +require("obvious.lib.wlan") module("obvious.lib") -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=4:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/lib/wlan.lua b/lib/wlan.lua new file mode 100644 index 0000000..802c974 --- /dev/null +++ b/lib/wlan.lua @@ -0,0 +1,30 @@ +-------------------------------- +-- Author: Gregor Best -- +-- Copyright 2009 Gregor Best -- +-------------------------------- + +local tonumber = tonumber +local setmetatable = setmetatable +local io = { + open = io.open +} + +module("obvious.lib.wlan") + +local function get_data(device) + local link + local fd = io.open("/proc/net/wireless") + if not fd then return end + + for line in fd:lines() do + if line:match("^ "..device) then + link = tonumber(line:match(" (%d?%d?%d)")) + break + end + end + fd:close() + + return link +end + +setmetatable(_M, { __call = function (_, ...) return get_data(...) end }) diff --git a/wlan/init.lua b/wlan/init.lua index f5581c8..8dd4420 100644 --- a/wlan/init.lua +++ b/wlan/init.lua @@ -4,11 +4,7 @@ -------------------------------- local setmetatable = setmetatable -local tonumber = tonumber -local io = { - open = io.open -} local string = { format = string.format } @@ -28,34 +24,16 @@ widget = capi.widget({ }) device = "wlan0" -function get_data() - local rv = { } - - local fd = io.open("/proc/net/wireless") - if not fd then return end - - for line in fd:lines() do - if line:match("^ "..device) then - rv.link = tonumber(line:match(" (%d?%d?%d)")) - break - end - end - fd:close() - if not rv.link then return end - - return rv -end - local function update() - local status = get_data() + local link = lib.wlan(device) local color = "#009000" - if status.link < 50 and status.link > 10 then + if link < 50 and link > 10 then color = "#909000" - elseif status.link <= 10 then + elseif link <= 10 then color = "#900000" end - widget.text = lib.util.colour(color,"â¢") .. string.format(" %03d%%", status.link) + widget.text = lib.util.colour(color,"â¢") .. string.format(" %03d%%", link) end update() lib.hooks.timer.register(10, 60, update) -- 1.6.3.3
>From 76ca8650be5d74e2830235d70ee6888a6ba7d89a Mon Sep 17 00:00:00 2001 From: Uli Schlachter <psyc...@znc.in> Date: Mon, 3 Aug 2009 16:47:00 +0200 Subject: [PATCH 2/4] Add a general function for creating widgets This simplifies setting some of the widget's properties Signed-off-by: Uli Schlachter <psyc...@znc.in> --- lib/init.lua | 1 + lib/widgets.lua | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 0 deletions(-) create mode 100644 lib/widgets.lua diff --git a/lib/init.lua b/lib/init.lua index b908d48..31fe374 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -5,6 +5,7 @@ require("obvious.lib.hooks") require("obvious.lib.util") +require("obvious.lib.widgets") require("obvious.lib.mpd") require("obvious.lib.wlan") diff --git a/lib/widgets.lua b/lib/widgets.lua new file mode 100644 index 0000000..40f73c2 --- /dev/null +++ b/lib/widgets.lua @@ -0,0 +1,31 @@ +----------------------------------- +-- Author: Uli Schlachter -- +-- Copyright 2009 Uli Schlachter -- +----------------------------------- + +local beautiful = require("beautiful") +local awful = { + widget = require("awful.widget") +} + +module("obvious.lib.widgets") + +function progressbar(layout) + local theme = beautiful.get() + local width = theme.progressbar_width or theme.widget_width or 8 + local color = theme.progressbar_fg_color or theme.widget_fg_color or theme.fg_normal + local back = theme.progressbar_bg_color or theme.widget_bg_color or theme.bg_normal + local border= theme.progressbar_border or theme.widget_border or theme.border_normal + + local widget = awful.widget.progressbar({ layout = layout }) + widget:set_vertical(true) + + widget:set_width(width) + widget:set_color(color) + widget:set_background_color(back) + widget:set_border_color(border) + + return widget +end + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 -- 1.6.3.3
>From d2118582d53f0285f40d6ebc9623d7093fa816ff Mon Sep 17 00:00:00 2001 From: Uli Schlachter <psyc...@znc.in> Date: Mon, 3 Aug 2009 16:48:29 +0200 Subject: [PATCH 3/4] Add a wlan progressbar widget Signed-off-by: Uli Schlachter <psyc...@znc.in> --- init.lua | 1 + wlan/bar.lua | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 0 deletions(-) create mode 100644 wlan/bar.lua diff --git a/init.lua b/init.lua index c5baa11..2474541 100644 --- a/init.lua +++ b/init.lua @@ -8,6 +8,7 @@ require("obvious.clock") require("obvious.battery") require("obvious.volume_alsa") require("obvious.wlan") +require("obvious.wlan.bar") require("obvious.popup_run_prompt") require("obvious.basic_mpd") diff --git a/wlan/bar.lua b/wlan/bar.lua new file mode 100644 index 0000000..71b265c --- /dev/null +++ b/wlan/bar.lua @@ -0,0 +1,35 @@ +----------------------------------- +-- Author: Uli Schlachter -- +-- Copyright 2009 Uli Schlachter -- +----------------------------------- + +local setmetatable = setmetatable +local lib = require("obvious.lib") + +module("obvious.wlan.bar") + +device = "wlan0" +widget = false + +local function update() + local link = lib.wlan(device) + widget:set_value(link / 100) +end + +function set_device(dev) + device = dev + if widget then update() end +end + +local function get(layout) + if not widget then + -- We must wait until now or beautiful isn't initialized yet + widget = lib.widgets.progressbar(layout) + update() + lib.hooks.timer.register(10, 60, update) + lib.hooks.timer.start(update) + end + return widget +end + +setmetatable(_M, { __call = function (_, ...) return get(...) end }) -- 1.6.3.3
>From 55e32bcebc3eea9e3f71085a578ca1bb88addf97 Mon Sep 17 00:00:00 2001 From: Uli Schlachter <psyc...@znc.in> Date: Mon, 3 Aug 2009 18:16:08 +0200 Subject: [PATCH 4/4] basic_mpd: Fix I use some special lua module which catches some common errors via metatable magic. One of these catch catches reads of undefined global variables. If you look at this patch then you'll see why this is a good idea. ;) Signed-off-by: Uli Schlachter <psyc...@znc.in> --- basic_mpd/init.lua | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/basic_mpd/init.lua b/basic_mpd/init.lua index 6df6727..8be612b 100644 --- a/basic_mpd/init.lua +++ b/basic_mpd/init.lua @@ -45,9 +45,11 @@ local function format_metadata(songinfo) end used_keys = {} + local start, stop start = 1 stop = 1 while start do + local key start, stop = string.find(format, "%$%w+", stop) key = string.match(format, "%$(%w+)", stop) if key then -- 1.6.3.3