]> 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:

Merge branch 'master' of https://github.com/copycat-killer/lain
authorQuan Guo <guotsuan@gmail.com>
Fri, 29 Jan 2016 19:42:56 +0000 (20:42 +0100)
committerQuan Guo <guotsuan@gmail.com>
Fri, 29 Jan 2016 19:42:56 +0000 (20:42 +0100)
12 files changed:
asyncshell.lua
helpers.lua
scripts/dfs
widgets/bat.lua
widgets/contrib/kbdlayout.lua
widgets/contrib/moc.lua
widgets/maildir.lua
widgets/mpd.lua
widgets/net.lua
widgets/pulseaudio.lua [new file with mode: 0644]
widgets/weather.lua
wiki

index 827cf4be4b0f500174ba2279429039d5f39516aa..2d6b7e3b116f26106426251385895a556735ae7d 100644 (file)
@@ -14,6 +14,9 @@
 -- Grab environment
 local awful = require('awful')
 
+-- Avoid discrepancies across multiple shells
+awful.util.shell = '/bin/sh'
+
 -- Initialize tables for module
 asyncshell = { request_table = {}, id_counter = 0 }
 
index 70ca0293ea44cd3799e02f8ef2c9e3349c9eb9d6..5e958c3937e6d84fccf1a065a2d953b86f4da044 100644 (file)
@@ -13,6 +13,7 @@ local io     = { open  = io.open,
                  lines = io.lines,
                  popen = io.popen }
 local rawget = rawget
+local table  = { sort   = table.sort }
 
 -- Lain helper functions for internal use
 -- lain.helpers
@@ -113,4 +114,23 @@ end
 
 -- }}}
 
+--{{{ Iterate over table of records sorted by keys
+function helpers.spairs(t)
+    -- collect the keys
+    local keys = {}
+    for k in pairs(t) do keys[#keys+1] = k end
+
+    table.sort(keys)
+
+    -- return the iterator function
+    local i = 0
+    return function()
+        i = i + 1
+        if keys[i] then
+            return keys[i], t[keys[i]]
+        end
+    end
+end
+--}}}
+
 return helpers
index f04b05127597e0d8322b4d35ebafa01795c3c9a1..bc27b816a552fffcc17ff4b716dd2bdf2f129037 100755 (executable)
@@ -212,7 +212,7 @@ echo "$SORTED_FILE_SYSTEMS_INFO" | $AWK_COMMAND -v DEBUG=$DEBUG -v PATTERN=$PATT
                                                         printf ("\n%s", narrow_margin);
                                                 else
                                                         printf ("%-*s", LEFT_COLUMN + 2, "");
-                                        print "                                                     Used    Free     Total ";
+                                        print "                                                    Used     Free       Total ";
                                         if (! NARROW_MODE)
                                                 print "";
                                 }
@@ -352,7 +352,7 @@ $0 ~ PATTERN    {
 #           printf ("stars_number = %d\n", stars_number);
 
                        printf ("|");
-                       for (i = 1; i <= stars_number; i++)
+                       for (i = 1; i <= stars_number && i <= 49; i++)
                        {
                                printf ("%s", "*");
                        }
index 61828ecfe9cb98c164c6526becdd75b4db363cc7..d55be1746def102d4e8db39a96fcc15b160204ab 100644 (file)
@@ -97,17 +97,14 @@ local function worker(args)
 
             bat_now.time = string.format("%02d:%02d", hrs, min)
 
-            bat_now.perc = first_line(bstr .. "/capacity")
-
-            if not bat_now.perc then
-                local perc = (rem / tot) * 100
-                if perc <= 100 then
-                    bat_now.perc = string.format("%d", perc)
-                elseif perc > 100 then
-                    bat_now.perc = "100"
-                elseif perc < 0 then
-                    bat_now.perc = "0"
-                end
+            local perc = tonumber(first_line(bstr .. "/capacity")) or math.floor((rem / tot) * 100)
+
+            if perc <= 100 then
+                bat_now.perc = string.format("%d", perc)
+            elseif perc > 100 then
+                bat_now.perc = "100"
+            elseif perc < 0 then
+                bat_now.perc = "0"
             end
 
             if rate ~= nil and ratev ~= nil then
index 39857afd62acb450d6c2f226d7827291819d5926..64ea6b30fa83b93bd059d5c47f9ad1771abfc1da 100644 (file)
@@ -16,6 +16,9 @@ local string       = { match = string.match }
 
 local setmetatable = setmetatable
 
+-- Keyboard layout switcher
+-- lain.widgets.contrib.kblayout
+
 local function worker (args)
    local kbdlayout    = {}
    kbdlayout.widget   = wibox.widget.textbox('')
@@ -24,9 +27,8 @@ local function worker (args)
    local settings         = args.settings or function () end
    local add_us_secondary = true
    local timeout          = args.timeout or 5
-
    local idx              = 1
-   
+
    if args.add_us_secondary == false then add_us_secondary = false end
 
    -- Mouse bindings
index b818bb6d3bcdeda76fe51acd1e00ca70f98bdf46..b79dbe2034ae44d071ade51ea9c976c606c4735d 100644 (file)
@@ -21,6 +21,8 @@ local string = { format  = string.format,
 
 local setmetatable = setmetatable
 
+-- MOC audio player
+-- lain.widgets.contrib.moc
 local moc = {}
 
 local function worker(args)
index eed613840921ecb955ee427489323be5db989a84..c9937b47e0d2f4d2eb15a00cc945aab6e8920b4b 100644 (file)
@@ -9,9 +9,11 @@
 
 local newtimer        = require("lain.helpers").newtimer
 local read_pipe       = require("lain.helpers").read_pipe
+local spairs          = require("lain.helpers").spairs
 
 local wibox           = require("wibox")
 
+local awful           = require("awful")
 local util            = require("lain.util")
 
 local io              = { popen  = io.popen }
@@ -19,7 +21,6 @@ local os              = { getenv = os.getenv }
 local pairs           = pairs
 local string          = { len    = string.len,
                           match  = string.match }
-local table           = { sort   = table.sort }
 
 local setmetatable    = setmetatable
 
@@ -33,13 +34,19 @@ local function worker(args)
     local mailpath     = args.mailpath or os.getenv("HOME") .. "/Mail"
     local ignore_boxes = args.ignore_boxes or {}
     local settings     = args.settings or function() end
+    local ext_mail_cmd = args.external_mail_cmd
 
     maildir.widget = wibox.widget.textbox('')
 
     function update()
+        if ext_mail_cmd ~= nil
+        then
+            awful.util.spawn(ext_mail_cmd)
+        end
+
         -- Find pathes to mailboxes.
         local p = io.popen("find " .. mailpath ..
-                           " -mindepth 1 -maxdepth 1 -type d" ..
+                           " -mindepth 1 -maxdepth 2 -type d" ..
                            " -not -name .git")
         local boxes = {}
         repeat
@@ -56,7 +63,7 @@ local function worker(args)
                                     "-not -name '.*' -printf a")
 
                 -- Strip off leading mailpath.
-                local box = string.match(line, mailpath .. "/*([^/]+)")
+                local box = string.match(line, mailpath .. "/(.*)")
                 local nummails = string.len(mailstring)
                 if nummails > 0
                 then
@@ -65,14 +72,13 @@ local function worker(args)
             end
         until line == nil
 
-       p:close()
-        table.sort(boxes)
+        p:close()
 
         newmail = "no mail"
         -- Count the total number of mails irrespective of where it was found
         total = 0
 
-        for box, number in pairs(boxes)
+        for box, number in spairs(boxes)
         do
             -- Add this box only if it's not to be ignored.
             if not util.element_in_table(box, ignore_boxes)
index c437347dbc7ffa514fb8600203cfd61b6b0364ea..19720509c8d247a955aad076360974ef22841d92 100644 (file)
@@ -59,6 +59,7 @@ local function worker(args)
             mpd_now = {
                 state   = "N/A",
                 file    = "N/A",
+                name    = "N/A",
                 artist  = "N/A",
                 title   = "N/A",
                 album   = "N/A",
index a578ae4ca9cc405454c4cc57a6b23cd5a9be2a0e..af823a824e1eaa48e8e5bd05025365c7d46f261a 100644 (file)
@@ -21,30 +21,27 @@ local setmetatable = setmetatable
 
 -- Network infos
 -- lain.widgets.net
-local net = {
-    last_t = 0,
-    last_r = 0
-}
-
-function net.get_device()
-    local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9")
-    ws = ws:match("%w+: UP") or ws:match("ppp%w+: UNKNOWN")
-    if ws ~= nil then
-        return ws:match("(%w+):")
-    else
-        return "network off"
-    end
-end
 
 local function worker(args)
-    local args = args or {}
-    local timeout = args.timeout or 2
-    local units = args.units or 1024 --kb
-    local notify = args.notify or "on"
-    local screen = args.screen or 1
-    local settings = args.settings or function() end
+    local net = { last_t = 0, last_r = 0 }
 
-    iface = args.iface or net.get_device()
+    function net.get_device()
+        local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9")
+        ws = ws:match("%w+: UP") or ws:match("ppp%w+: UNKNOWN")
+        if ws ~= nil then
+            return ws:match("(%w+):")
+        else
+            return "network off"
+        end
+    end
+
+    local args     = args or {}
+    local timeout  = args.timeout or 2
+    local units    = args.units or 1024 --kb
+    local notify   = args.notify or "on"
+    local screen   = args.screen or 1
+    local settings = args.settings or function() end
+    local iface    = args.iface or net.get_device()
 
     net.widget = wibox.widget.textbox('')
 
@@ -100,7 +97,8 @@ local function worker(args)
     end
 
     helpers.newtimer(iface, timeout, update)
-    return net.widget
+
+    return setmetatable(net, { __index = net.widget })
 end
 
-return setmetatable(net, { __call = function(_, ...) return worker(...) end })
+return setmetatable({}, { __call = function(_, ...) return worker(...) end })
diff --git a/widgets/pulseaudio.lua b/widgets/pulseaudio.lua
new file mode 100644 (file)
index 0000000..b675276
--- /dev/null
@@ -0,0 +1,48 @@
+
+--[[
+                                                  
+     Licensed under GNU General Public License v2 
+      * (c) 2016, Luke Bonham                     
+                                                  
+--]]
+
+local read_pipe       = require("lain.helpers").read_pipe
+local newtimer        = require("lain.helpers").newtimer
+local wibox           = require("wibox")
+
+local string          = { match  = string.match,
+                          format = string.format }
+
+local setmetatable    = setmetatable
+
+-- PulseAudio volume
+-- lain.widgets.pulseaudio
+local pulseaudio = {}
+
+local function worker(args)
+   local args        = args or {}
+   local timeout     = args.timeout or 5
+   local settings    = args.settings or function() end
+
+   pulseaudio.sink   = args.sink or 0 -- user defined or first one
+   pulseaudio.cmd    = args.cmd or string.format("pacmd list-sinks | grep -e 'index: %d' -e 'volume: front' -e 'muted'", pulseaudio.sink)
+   pulseaudio.widget = wibox.widget.textbox('')
+
+   function pulseaudio.update()
+      local s = read_pipe(pulseaudio.cmd)
+
+      volume_now = {}
+      volume_now.left  = tonumber(string.match(s, "left.-(%d+)%%"))
+      volume_now.right = tonumber(string.match(s, "right.-(%d+)%%"))
+      volume_now.muted = string.match(s, "muted: (%S+)")
+
+      widget = pulseaudio.widget
+      settings()
+   end
+
+   newtimer(string.format("pulseaudio-%s", pulseaudio.sink), timeout, pulseaudio.update)
+
+   return setmetatable(pulseaudio, { __index = pulseaudio.widget })
+end
+
+return setmetatable(pulseaudio, { __call = function(_, ...) return worker(...) end })
index de3163c9602ffb8e27d78329ba14817e2eddad9e..173601a5593178b5ef237bd01ce2b68ce1afd197 100644 (file)
@@ -30,10 +30,11 @@ local setmetatable = setmetatable
 local function worker(args)
     local weather               = {}
     local args                  = args or {}
+    local APPID                 = args.APPID or "3e321f9414eaedbfab34983bda77a66e" -- lain default
     local timeout               = args.timeout or 900   -- 15 min
     local timeout_forecast      = args.timeout or 86400 -- 24 hrs
-    local current_call          = "curl -s 'http://api.openweathermap.org/data/2.5/weather?id=%s&units=%s&lang=%s'"
-    local forecast_call         = "curl -s 'http://api.openweathermap.org/data/2.5/forecast/daily?id=%s&units=%s&lang=%s&cnt=%s'"
+    local current_call          = "curl -s 'http://api.openweathermap.org/data/2.5/weather?id=%s&units=%s&lang=%s&APPID=%s'"
+    local forecast_call         = "curl -s 'http://api.openweathermap.org/data/2.5/forecast/daily?id=%s&units=%s&lang=%s&cnt=%s&APPID=%s'"
     local city_id               = args.city_id or 0 -- placeholder
     local units                 = args.units or "metric"
     local lang                  = args.lang or "en"
@@ -45,11 +46,13 @@ local function worker(args)
                                   function (day, desc, tmin, tmax)
                                       return string.format("<b>%s</b>: %s, %d - %d  ", day, desc, tmin, tmax)
                                   end
+    local weather_na_markup     = args.weather_na_markup or " N/A "
     local followmouse           = args.followmouse or false
     local settings              = args.settings or function() end
 
-    weather.widget = wibox.widget.textbox('')
-    weather.icon   = wibox.widget.imagebox()
+    weather.widget    = wibox.widget.textbox(weather_na_markup)
+    weather.icon_path = icons_path .. "na.png"
+    weather.icon      = wibox.widget.imagebox(weather.icon_path)
 
     function weather.show(t_out)
         weather.hide()
@@ -59,7 +62,8 @@ local function worker(args)
         end
 
         weather.notification = naughty.notify({
-            text    = weather.notification_text,
+            text    = weather.notification_text
+                      or "Waiting for the server to respond...",
             icon    = weather.icon_path,
             timeout = t_out,
             preset  = notification_preset
@@ -83,7 +87,7 @@ local function worker(args)
     end
 
     function weather.forecast_update()
-        local cmd = string.format(forecast_call, city_id, units, lang, cnt)
+        local cmd = string.format(forecast_call, city_id, units, lang, cnt, APPID)
         async.request(cmd, function(f)
             local pos, err
             weather_now, pos, err = json.decode(f, 1, nil)
@@ -105,27 +109,27 @@ local function worker(args)
                     end
                 end
             else
-                weather.icon_path = icons_path .. "na.png"
                 weather.notification_text = "API/connection error or bad/not set city ID"
             end
         end)
     end
 
     function weather.update()
-        local cmd = string.format(current_call, city_id, units, lang)
+        local cmd = string.format(current_call, city_id, units, lang, APPID)
         async.request(cmd, function(f)
             local pos, err
             weather_now, pos, err = json.decode(f, 1, nil)
 
             if not err and weather_now ~= nil and tonumber(weather_now["cod"]) == 200 then
                 weather.icon_path = icons_path .. weather_now["weather"][1]["icon"] .. ".png"
-                weather.icon:set_image(weather.icon_path)
                 widget = weather.widget
                 settings()
             else
-                weather.widget._layout.text = " N/A " -- tries to avoid textbox bugs
-                weather.icon:set_image(icons_path .. "na.png")
+                weather.icon_path = icons_path .. "na.png"
+                weather.widget:set_markup(weather_na_markup)
             end
+
+            weather.icon:set_image(weather.icon_path)
         end)
     end
 
diff --git a/wiki b/wiki
index d7aa1a7b8428211a1c4c71865fd64302e013d62b..dcce6dd58791c7c1d2e2e3f046b4da0d5b9700a7 160000 (submodule)
--- a/wiki
+++ b/wiki
@@ -1 +1 @@
-Subproject commit d7aa1a7b8428211a1c4c71865fd64302e013d62b
+Subproject commit dcce6dd58791c7c1d2e2e3f046b4da0d5b9700a7