]> git.madduck.net Git - etc/awesome.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

widgets: no global tables, but one instance per call; closes #336; closes #337
authorLuke Bonham <dada@archlinux.info>
Sun, 2 Apr 2017 17:35:03 +0000 (19:35 +0200)
committerLuke Bonham <dada@archlinux.info>
Sun, 2 Apr 2017 17:35:03 +0000 (19:35 +0200)
12 files changed:
widget/alsabar.lua
widget/contrib/kbdlayout.lua
widget/contrib/moc.lua
widget/cpu.lua
widget/fs.lua
widget/mem.lua
widget/mpd.lua
widget/net.lua
widget/pulseaudio.lua
widget/pulsebar.lua
widget/sysload.lua
widget/temp.lua

index 7aa8835f2a15881277e9ed9498adfc22def6621b..2ad021048a82880e6e79717ce38f2384ff05aab4 100644 (file)
@@ -7,32 +7,31 @@
                                                   
 --]]
 
-local helpers      = require("lain.helpers")
-local awful        = require("awful")
-local naughty      = require("naughty")
-local wibox        = require("wibox")
-local math         = { modf   = math.modf }
-local string       = { format = string.format,
-                       match  = string.match,
-                       rep    = string.rep }
-local type         = type
-local tonumber     = tonumber
-local setmetatable = setmetatable
+local helpers        = require("lain.helpers")
+local awful          = require("awful")
+local naughty        = require("naughty")
+local wibox          = require("wibox")
+local math           = { modf   = math.modf }
+local string         = { format = string.format,
+                         match  = string.match,
+                         rep    = string.rep }
+local type, tonumber = type, tonumber
 
 -- ALSA volume bar
 -- lain.widget.alsabar
-local alsabar = {
-    colors = {
-        background = "#000000",
-        mute       = "#EB8F8F",
-        unmute     = "#A4CE8A"
-    },
-
-    _current_level = 0,
-    _muted         = false
-}
 
 local function factory(args)
+    local alsabar = {
+        colors = {
+            background = "#000000",
+            mute       = "#EB8F8F",
+            unmute     = "#A4CE8A"
+        },
+
+        _current_level = 0,
+        _muted         = false
+    }
+
     local args       = args or {}
     local timeout    = args.timeout or 5
     local settings   = args.settings or function() end
@@ -133,4 +132,4 @@ local function factory(args)
     return alsabar
 end
 
-return setmetatable(alsabar, { __call = function(_, ...) return factory(...) end })
+return factory
index e0fdbc0652dcb53ad8958640feaa8f0fa6bf6064..5964bd77362f9ad3cc310bcc87d0931a4c9cfed9 100644 (file)
@@ -18,7 +18,7 @@ local setmetatable = setmetatable
 -- lain.widget.contrib.kblayout
 
 local function factory(args)
-    local kbdlayout       = { widget = wibox.widget.textbox() }
+    local kbdlayout        = { widget = wibox.widget.textbox() }
     local args             = args or {}
     local layouts          = args.layouts or {}
     local settings         = args.settings or function () end
index f841e31add30a4bed3b5a669d464e917d6907260..83d8aaf86870ef3dda47468fbc3468af992cd487 100644 (file)
@@ -15,13 +15,12 @@ local wibox        = require("wibox")
 local os           = { getenv = os.getenv }
 local string       = { format = string.format,
                        gmatch = string.gmatch }
-local setmetatable = setmetatable
 
 -- MOC audio player
 -- lain.widget.contrib.moc
-local moc = {}
 
 local function factory(args)
+    local moc           = { widget = wibox.widget.textbox() }
     local args          = args or {}
     local timeout       = args.timeout or 2
     local music_dir     = args.music_dir or os.getenv("HOME") .. "/Music"
@@ -31,8 +30,6 @@ local function factory(args)
     local followtag     = args.followtag or false
     local settings      = args.settings or function() end
 
-    moc.widget = wibox.widget.textbox()
-
     moc_notification_preset = { title = "Now playing", timeout = 6 }
 
     helpers.set_map("current moc track", nil)
@@ -98,4 +95,4 @@ local function factory(args)
     return moc
 end
 
-return setmetatable(moc, { __call = function(_, ...) return factory(...) end })
+return factory
index e8a6c9c1bbade3550f884f61a6fd6f5cfdeb498f..9a5a9648f01e679c5cdf7992fd5cb45eb03b3c3e 100644 (file)
@@ -7,25 +7,22 @@
                                                   
 --]]
 
-local helpers      = require("lain.helpers")
-local wibox        = require("wibox")
-local math         = { ceil   = math.ceil }
-local string       = { format = string.format,
-                       gmatch = string.gmatch }
-local tostring     = tostring
-local setmetatable = setmetatable
+local helpers  = require("lain.helpers")
+local wibox    = require("wibox")
+local math     = { ceil   = math.ceil }
+local string   = { format = string.format,
+                   gmatch = string.gmatch }
+local tostring = tostring
 
 -- CPU usage
 -- lain.widget.cpu
-local cpu = { core = {} }
 
 local function factory(args)
+    local cpu      = { core = {}, widget = wibox.widget.textbox() }
     local args     = args or {}
     local timeout  = args.timeout or 2
     local settings = args.settings or function() end
 
-    cpu.widget = wibox.widget.textbox()
-
     function cpu.update()
         -- Read the amount of time the CPUs have spent performing
         -- different kinds of work. Read the first line of /proc/stat
@@ -79,4 +76,4 @@ local function factory(args)
     return cpu
 end
 
-return setmetatable(cpu, { __call = function(_, ...) return factory(...) end })
+return factory
index f1bd648025b488dae0e0f099f9d431a6ae3355d1..473bd33fa77554274b31581f01ea56bf94d3479b 100644 (file)
@@ -6,43 +6,42 @@
                                                   
 --]]
 
-local helpers      = require("lain.helpers")
-local shell        = require("awful.util").shell
-local focused      = require("awful.screen").focused
-local wibox        = require("wibox")
-local naughty      = require("naughty")
-local string       = string
-local tonumber     = tonumber
-local setmetatable = setmetatable
+local helpers  = require("lain.helpers")
+local shell    = require("awful.util").shell
+local focused  = require("awful.screen").focused
+local wibox    = require("wibox")
+local naughty  = require("naughty")
+local string   = string
+local tonumber = tonumber
 
 -- File system disk space usage
 -- lain.widget.fs
-local fs = { unit  = { ["mb"] = 1024, ["gb"] = 1024^2 } }
 
-function fs.hide()
-    if not fs.notification then return end
-    naughty.destroy(fs.notification)
-    fs.notification = nil
-end
+local function factory(args)
+    local fs = { unit  = { ["mb"] = 1024, ["gb"] = 1024^2 }, widget = wibox.widget.textbox() }
 
-function fs.show(seconds, scr)
-    fs.update()
+    function fs.hide()
+        if not fs.notification then return end
+        naughty.destroy(fs.notification)
+        fs.notification = nil
+    end
 
-    fs.hide()
+    function fs.show(seconds, scr)
+        fs.update()
+        fs.hide()
 
-    if fs.followtag then
-        fs.notification_preset.screen = focused()
-    else
-        fs.notification_preset.screen = scr or 1
-    end
+        if fs.followtag then
+            fs.notification_preset.screen = focused()
+        else
+            fs.notification_preset.screen = scr or 1
+        end
 
-    fs.notification = naughty.notify({
-        preset  = fs.notification_preset,
-        timeout = seconds or 5
-    })
-end
+        fs.notification = naughty.notify({
+            preset  = fs.notification_preset,
+            timeout = seconds or 5
+        })
+    end
 
-local function factory(args)
     local args             = args or {}
     local timeout          = args.timeout or 600
     local partition        = args.partition or "/"
@@ -62,8 +61,6 @@ local function factory(args)
         }
     end
 
-    fs.widget = wibox.widget.textbox()
-
     helpers.set_map(partition, false)
 
     function fs.update()
@@ -124,4 +121,4 @@ local function factory(args)
     return fs
 end
 
-return setmetatable(fs, { __call = function(_, ...) return factory(...) end })
+return factory
index cf0d314fe350e08a37430467cd79e522d452b782..50fff3bb7d62f78cd4bbfd6c5cd84987223d1786 100644 (file)
@@ -7,24 +7,19 @@
                                                   
 --]]
 
-local helpers      = require("lain.helpers")
-local wibox        = require("wibox")
-local gmatch       = string.gmatch
-local lines        = io.lines
-local floor        = math.floor
-local setmetatable = setmetatable
+local helpers              = require("lain.helpers")
+local wibox                = require("wibox")
+local gmatch, lines, floor = string.gmatch, io.lines, math.floor
 
 -- Memory usage (ignoring caches)
 -- lain.widget.mem
-local mem = {}
 
 local function factory(args)
+    local mem      = { widget = wibox.widget.textbox() }
     local args     = args or {}
     local timeout  = args.timeout or 2
     local settings = args.settings or function() end
 
-    mem.widget = wibox.widget.textbox()
-
     function mem.update()
         mem_now = {}
         for line in lines("/proc/meminfo") do
@@ -53,4 +48,4 @@ local function factory(args)
     return mem
 end
 
-return setmetatable(mem, { __call = function(_, ...) return factory(...) end })
+return factory
index 88b993711d51bb569df73e51be5e70b66514454f..d0b37d7db0daaef3f3a97fa4ab83912bdd4c52e0 100644 (file)
@@ -17,13 +17,12 @@ local os           = { getenv = os.getenv }
 local string       = { format = string.format,
                        gmatch = string.gmatch,
                        match  = string.match }
-local setmetatable = setmetatable
 
 -- MPD infos
 -- lain.widget.mpd
-local mpd = {}
 
 local function factory(args)
+    local mpd           = { widget = wibox.widget.textbox() }
     local args          = args or {}
     local timeout       = args.timeout or 2
     local password      = (args.password and #args.password > 0 and string.format("password %s\\n", args.password)) or ""
@@ -41,8 +40,6 @@ local function factory(args)
     local echo = string.format("printf \"%sstatus\\ncurrentsong\\nclose\\n\"", password)
     local cmd  = string.format("%s | curl --connect-timeout 1 -fsm 3 %s", echo, mpdh)
 
-    mpd.widget = wibox.widget.textbox()
-
     mpd_notification_preset = { title = "Now playing", timeout = 6 }
 
     helpers.set_map("current mpd track", nil)
@@ -112,7 +109,8 @@ local function factory(args)
 
                     if not string.match(mpd_now.file, "http.*://") then -- local file instead of http stream
                         local path   = string.format("%s/%s", music_dir, string.match(mpd_now.file, ".*/"))
-                        local cover  = string.format("find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'", path:gsub("'", "'\\''"), cover_pattern)
+                        local cover  = string.format("find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'",
+                                       path:gsub("'", "'\\''"), cover_pattern)
                         helpers.async({ shell, "-c", cover }, function(current_icon)
                             common.icon = current_icon:gsub("\n", "")
                             if #common.icon == 0 then common.icon = nil end
@@ -134,4 +132,4 @@ local function factory(args)
     return mpd
 end
 
-return setmetatable(mpd, { __call = function(_, ...) return factory(...) end })
+return factory
index 7e511a394b88868655504999c816dff18326e733..f42ec25d01a52a0f37f24b495a1993f08fce4753 100644 (file)
@@ -16,8 +16,7 @@ local string  = { format = string.format, match = string.match }
 -- lain.widget.net
 
 local function factory(args)
-    local net = { widget  = wibox.widget.textbox(), devices = {} }
-
+    local net      = { widget = wibox.widget.textbox(), devices = {} }
     local args     = args or {}
     local timeout  = args.timeout or 2
     local units    = args.units or 1024 -- KB
index b0946a17c2a6b61f98d33b252e491c478ecbe29c..ed37cb5e96fbd580d70bef55a0b783f3582fdab7 100644 (file)
@@ -17,7 +17,7 @@ local string  = { gmatch = string.gmatch,
 -- lain.widget.pulseaudio
 
 local function factory(args)
-    local pulseaudio = { widget = wibox.widget.textbox() }
+    local pulseaudio  = { widget = wibox.widget.textbox() }
     local args        = args or {}
     local timeout     = args.timeout or 5
     local settings    = args.settings or function() end
index e80a25194820265fc267ebb019aac3dafc892afd..0ab63128b259f13ef8e19f524b9a0c45df29f68f 100644 (file)
@@ -7,33 +7,32 @@
                                                   
 --]]
 
-local helpers      = require("lain.helpers")
-local awful        = require("awful")
-local naughty      = require("naughty")
-local wibox        = require("wibox")
-local math         = { modf   = math.modf }
-local string       = { format = string.format,
-                       gmatch = string.gmatch,
-                       match  = string.match,
-                       rep    = string.rep }
-local type         = type
-local tonumber     = tonumber
-local setmetatable = setmetatable
+local helpers        = require("lain.helpers")
+local awful          = require("awful")
+local naughty        = require("naughty")
+local wibox          = require("wibox")
+local math           = { modf   = math.modf }
+local string         = { format = string.format,
+                         match  = string.match,
+                         gmatch = string.gmatch,
+                         rep    = string.rep }
+local type, tonumber = type, tonumber
 
 -- Pulseaudio volume bar
 -- lain.widget.pulsebar
-local pulsebar = {
-    colors = {
-        background = "#000000",
-        mute       = "#EB8F8F",
-        unmute     = "#A4CE8A"
-    },
-
-    _current_level = 0,
-    _muted         = false
-}
 
 local function factory(args)
+    local pulsebar = {
+        colors = {
+            background = "#000000",
+            mute       = "#EB8F8F",
+            unmute     = "#A4CE8A"
+        },
+
+        _current_level = 0,
+        _muted         = false
+    }
+
     local args       = args or {}
     local timeout    = args.timeout or 5
     local settings   = args.settings or function() end
index d7422d855a8efaba984397af922b5da6f8aa73a6..d35868753135b02b9ad58e41de46d98363757c2f 100644 (file)
@@ -7,29 +7,25 @@
                                                   
 --]]
 
-local helpers      = require("lain.helpers")
-local wibox        = require("wibox")
-local io           = { open = io.open }
-local string       = { match  = string.match }
-local setmetatable = setmetatable
+local helpers     = require("lain.helpers")
+local wibox       = require("wibox")
+local open, match = io.open, string.match
 
 -- System load
 -- lain.widget.sysload
-local sysload = {}
 
 local function factory(args)
+    local sysload  = { widget = wibox.widget.textbox() }
     local args     = args or {}
     local timeout  = args.timeout or 2
     local settings = args.settings or function() end
 
-    sysload.widget = wibox.widget.textbox()
-
     function sysload.update()
-        local f = io.open("/proc/loadavg")
+        local f = open("/proc/loadavg")
         local ret = f:read("*all")
         f:close()
 
-        load_1, load_5, load_15 = string.match(ret, "([^%s]+) ([^%s]+) ([^%s]+)")
+        load_1, load_5, load_15 = match(ret, "([^%s]+) ([^%s]+) ([^%s]+)")
 
         widget = sysload.widget
         settings()
@@ -40,4 +36,4 @@ local function factory(args)
     return sysload
 end
 
-return setmetatable(sysload, { __call = function(_, ...) return factory(...) end })
+return factory
index 8e3bc3c37e11b616dc8f2c2b3e1026b63e3e54f9..efe2ab931dd971af9f39b44889b07ed3b7003030 100644 (file)
@@ -6,26 +6,23 @@
                                                   
 --]]
 
-local helpers      = require("lain.helpers")
-local wibox        = require("wibox")
-local io           = { open = io.open }
-local tonumber     = tonumber
-local setmetatable = setmetatable
+local helpers  = require("lain.helpers")
+local wibox    = require("wibox")
+local open     = io.open
+local tonumber = tonumber
 
 -- coretemp
 -- lain.widget.temp
-local temp = {}
 
 local function factory(args)
+    local temp     = { widget = wibox.widget.textbox() }
     local args     = args or {}
     local timeout  = args.timeout or 2
     local tempfile = args.tempfile or "/sys/class/thermal/thermal_zone0/temp"
     local settings = args.settings or function() end
 
-    temp.widget = wibox.widget.textbox()
-
     function temp.update()
-        local f = io.open(tempfile)
+        local f = open(tempfile)
         if f then
             coretemp_now = tonumber(f:read("*all")) / 1000
             f:close()
@@ -42,4 +39,4 @@ local function factory(args)
     return temp
 end
 
-return setmetatable(temp, { __call = function(_, ...) return factory(...) end })
+return factory