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

helpers.newtimer: added stoppable option
authorcopycat-killer <dada@archlinux.info>
Tue, 24 Jan 2017 15:15:40 +0000 (16:15 +0100)
committercopycat-killer <dada@archlinux.info>
Tue, 24 Jan 2017 15:15:40 +0000 (16:15 +0100)
12 files changed:
helpers.lua
widgets/abase.lua
widgets/base.lua
widgets/contrib/gpmdp.lua
widgets/contrib/moc.lua
widgets/contrib/tpbat/smapi.lua
widgets/imap.lua
widgets/maildir.lua
widgets/mpd.lua
widgets/net.lua
widgets/weather.lua
wiki

index 9755dc0405e072980b6e937d8e47acb8206c0432..7c446480c0cf6955698f8b5fd5835cd44ac8db3c 100644 (file)
@@ -92,8 +92,9 @@ end
 
 helpers.timer_table = {}
 
 
 helpers.timer_table = {}
 
-function helpers.newtimer(_name, timeout, fun, nostart)
-    local name = timeout
+function helpers.newtimer(name, timeout, fun, nostart, stoppable)
+    if not name or #name == 0 then return end
+    name = (stoppable and name) or timeout
     if not helpers.timer_table[name] then
         helpers.timer_table[name] = timer({ timeout = timeout })
         helpers.timer_table[name]:start()
     if not helpers.timer_table[name] then
         helpers.timer_table[name] = timer({ timeout = timeout })
         helpers.timer_table[name]:start()
@@ -102,6 +103,7 @@ function helpers.newtimer(_name, timeout, fun, nostart)
     if not nostart then
         helpers.timer_table[name]:emit_signal("timeout")
     end
     if not nostart then
         helpers.timer_table[name]:emit_signal("timeout")
     end
+    return stoppable and helpers.timer_table[name]
 end
 
 -- }}}
 end
 
 -- }}}
@@ -175,9 +177,9 @@ function helpers.spairs(t)
     end
 end
 
     end
 end
 
--- create a lain textbox widget
+-- create a textbox with no spacing issues
 function helpers.make_widget_textbox()
 function helpers.make_widget_textbox()
-    local w = wibox.widget.textbox('')
+    local w = wibox.widget.textbox()
     local t = wibox.widget.base.make_widget(w)
     t.widget = w
     return t
     local t = wibox.widget.base.make_widget(w)
     t.widget = w
     return t
index a176cf1fed7d9296ab194361816c4062a9d7a361..7eef754d5732033eed4a6f1f75f058af771318a1 100644 (file)
@@ -14,13 +14,13 @@ local setmetatable = setmetatable
 -- lain.widgets.abase
 
 local function worker(args)
 -- lain.widgets.abase
 
 local function worker(args)
-    local abase    = {}
-    local args     = args or {}
-    local timeout  = args.timeout or 5
-    local cmd      = args.cmd or ""
-    local settings = args.settings or function() end
-
-    abase.widget = wibox.widget.textbox()
+    local abase     = helpers.make_widget_textbox()
+    local args      = args or {}
+    local timeout   = args.timeout or 5
+    local nostart   = args.nostart or false
+    local stoppable = args.stoppable or false
+    local cmd       = args.cmd or ""
+    local settings  = args.settings or function() end
 
     function abase.update()
         helpers.async(cmd, function(f)
 
     function abase.update()
         helpers.async(cmd, function(f)
@@ -33,7 +33,7 @@ local function worker(args)
         end)
     end
 
         end)
     end
 
-    helpers.newtimer(cmd, timeout, abase.update)
+    abase.timer = helpers.newtimer(cmd, timeout, abase.update, nostart, stoppable)
 
     return setmetatable(abase, { __index = abase.widget })
 end
 
     return setmetatable(abase, { __index = abase.widget })
 end
index 94ee58fa606e348357748de230b447a4bca19066..87b0c8522cdec56b407e0f157d329010b6e8588a 100644 (file)
@@ -6,8 +6,7 @@
                                                   
 --]]
 
                                                   
 --]]
 
-local newtimer     = require("lain.helpers").newtimer
-local read_pipe    = require("lain.helpers").read_pipe
+local helpers      = require("lain.helpers")
 local wibox        = require("wibox")
 local setmetatable = setmetatable
 
 local wibox        = require("wibox")
 local setmetatable = setmetatable
 
@@ -15,16 +14,18 @@ local setmetatable = setmetatable
 -- lain.widgets.base
 
 local function worker(args)
 -- lain.widgets.base
 
 local function worker(args)
-    local base     = {}
-    local args     = args or {}
-    local timeout  = args.timeout or 5
-    local cmd      = args.cmd or ""
-    local settings = args.settings or function() end
+    local base      = helpers.make_widget_textbox()
+    local args      = args or {}
+    local timeout   = args.timeout or 5
+    local nostart   = args.nostart or false
+    local stoppable = args.stoppable or false
+    local cmd       = args.cmd or ""
+    local settings  = args.settings or function() end
 
     base.widget = wibox.widget.textbox()
 
     function base.update()
 
     base.widget = wibox.widget.textbox()
 
     function base.update()
-        output = read_pipe(cmd)
+        output = helpers.read_pipe(cmd)
         if output ~= base.prev then
             widget = base.widget
             settings()
         if output ~= base.prev then
             widget = base.widget
             settings()
@@ -32,7 +33,7 @@ local function worker(args)
         end
     end
 
         end
     end
 
-    newtimer(cmd, timeout, base.update)
+    base.timer = helpers.newtimer(cmd, timeout, base.update, nostart, stoppable)
 
     return setmetatable(base, { __index = base.widget })
 end
 
     return setmetatable(base, { __index = base.widget })
 end
index 811d1f6a3493c0dd17a11dda2d51f5458dab4202..21776ac9b0ee87c84fd130f3b0eba3c82cfa5dfe 100644 (file)
@@ -67,23 +67,24 @@ local function worker(args)
         if gpm_now.playing then
             if notify == "on" and gpm_now.title ~= helpers.get_map("gpmdp_current") then
                 helpers.set_map("gpmdp_current", gpm_now.title)
         if gpm_now.playing then
             if notify == "on" and gpm_now.title ~= helpers.get_map("gpmdp_current") then
                 helpers.set_map("gpmdp_current", gpm_now.title)
-                os.execute(string.format("curl %d -o /tmp/gpmcover.png", gpm_now.cover_url))
 
                 if followtag then gpmdp_notification_preset.screen = focused() end
 
 
                 if followtag then gpmdp_notification_preset.screen = focused() end
 
-                gpmdp.id = naughty.notify({
-                    preset = gpmdp_notification_preset,
-                    icon = "/tmp/gpmcover.png",
-                    replaces_id = gpmdp.id,
-                }).id
+                helpers.async(string.format("curl %d -o /tmp/gpmcover.png", gpm_now.cover_url),
+                function(f)
+                    gpmdp.id = naughty.notify({
+                        preset = gpmdp_notification_preset,
+                        icon = "/tmp/gpmcover.png",
+                        replaces_id = gpmdp.id
+                    }).id
+                end)
             end
             end
-        elseif not gpm_now.running
-        then
+        elseif not gpm_now.running then
             helpers.set_map("gpmdp_current", nil)
         end
     end
 
             helpers.set_map("gpmdp_current", nil)
         end
     end
 
-    helpers.newtimer("gpmdp", timeout, gpmdp.update)
+    gpmdp.timer = helpers.newtimer("gpmdp", timeout, gpmdp.update, true, true)
 
     return setmetatable(gpmdp, { __index = gpmdp.widget })
 end
 
     return setmetatable(gpmdp, { __index = gpmdp.widget })
 end
index d2f544f6b4f7a3c12c44922b0ad5962ab6d59f7a..6190f5f5935e176523f860d5a37da1229a6771a2 100644 (file)
@@ -91,7 +91,7 @@ local function worker(args)
         end)
     end
 
         end)
     end
 
-    helpers.newtimer("moc", timeout, moc.update)
+    moc.timer = helpers.newtimer("moc", timeout, moc.update, true, true)
 
     return setmetatable(moc, { __index = moc.widget })
 end
 
     return setmetatable(moc, { __index = moc.widget })
 end
index 271d9c2d4c721223ddaef53729140708ab2808c5..9002585d69e55a9169ce3e2f6c4f9c70c1232218 100644 (file)
@@ -81,13 +81,11 @@ function smapi:battery(name)
         local time_val = bat_now.status == 'discharging' and 'remaining_running_time' or 'remaining_charging_time'
         local mins_left = self:get(time_val)
 
         local time_val = bat_now.status == 'discharging' and 'remaining_running_time' or 'remaining_charging_time'
         local mins_left = self:get(time_val)
 
-        if mins_left:find("^%d+") == nil
-        then
-            return "N/A"
-        end
+        if not mins_left:find("^%d+") then return "N/A" end
 
         local hrs = math.floor(mins_left / 60)
         local min = mins_left % 60
 
         local hrs = math.floor(mins_left / 60)
         local min = mins_left % 60
+
         return string.format("%02d:%02d", hrs, min)
     end
 
         return string.format("%02d:%02d", hrs, min)
     end
 
index e00be5ba307b65eca5af9a962ba4562c7f78b519..5896ae11b764fa639628769ba63356511895c9ac 100644 (file)
@@ -74,7 +74,7 @@ local function worker(args                           )
 
     end
 
 
     end
 
-    helpers.newtimer(mail, timeout, update)
+    imap.timer = helpers.newtimer(mail, timeout, update, true, true)
 
     return setmetatable(imap, { __index = imap.widget })
 end
 
     return setmetatable(imap, { __index = imap.widget })
 end
index bef09f4a4527d22d2033064c6dd759b7933f64ad..1f4cd455a2fe1dc413c2a3ea2b87efe0bab86158 100644 (file)
@@ -30,7 +30,7 @@ local function worker(args)
 
     maildir.widget = wibox.widget.textbox()
 
 
     maildir.widget = wibox.widget.textbox()
 
-    function update()
+    function maildir.update()
         if ext_mail_cmd then awful.spawn(ext_mail_cmd) end
 
         -- Find pathes to mailboxes.
         if ext_mail_cmd then awful.spawn(ext_mail_cmd) end
 
         -- Find pathes to mailboxes.
@@ -76,7 +76,7 @@ local function worker(args)
         settings()
     end
 
         settings()
     end
 
-    helpers.newtimer(mailpath, timeout, update, true)
+    maildir.timer = helpers.newtimer(mailpath, timeout, maildir.update, true, true)
 
     return setmetatable(maildir, { __index = maildir.widget })
 end
 
     return setmetatable(maildir, { __index = maildir.widget })
 end
index 02b56808972f12ed52f98fe1238871fdabaef9c4..ac4fd5f459e2d31ef8e831bff5488180e9fd44a3 100644 (file)
@@ -126,7 +126,7 @@ local function worker(args)
         end)
     end
 
         end)
     end
 
-    helpers.newtimer("mpd", timeout, mpd.update)
+    mpd.timer = helpers.newtimer("mpd", timeout, mpd.update, true, true)
 
     return mpd
 end
 
     return mpd
 end
index 983ec7ae2e12813d9a508003844f45d6293fee52..a6cb3b6ab31b3f307123c29931cbfa8b46898a20 100644 (file)
@@ -12,6 +12,7 @@ local naughty      = require("naughty")
 local wibox        = require("wibox")
 local string       = { format = string.format,
                        match  = string.match }
 local wibox        = require("wibox")
 local string       = { format = string.format,
                        match  = string.match }
+local tostring     = tostring
 local setmetatable = setmetatable
 
 -- Network infos
 local setmetatable = setmetatable
 
 -- Network infos
@@ -116,7 +117,7 @@ local function worker(args)
         settings()
     end
 
         settings()
     end
 
-    helpers.newtimer(net.iface, timeout, update)
+    helpers.newtimer("net-" .. tostring(net.iface), timeout, update)
 
     return net
 end
 
     return net
 end
index 32e306560c6f6292ad8246a124043c9baa29101b..ff86d7ef5fb16b511dd136840b2198fb4f96f05e 100644 (file)
@@ -160,8 +160,8 @@ local function worker(args)
 
     weather.attach(weather.widget)
 
 
     weather.attach(weather.widget)
 
-    newtimer("weather-" .. city_id, timeout, weather.update)
-    newtimer("weather_forecast-" .. city_id, timeout, weather.forecast_update)
+    weather.timer = newtimer("weather-" .. city_id, timeout, weather.update, false, true)
+    weather.timer_forecast = newtimer("weather_forecast-" .. city_id, timeout, weather.forecast_update, false, true)
 
     return setmetatable(weather, { __index = weather.widget })
 end
 
     return setmetatable(weather, { __index = weather.widget })
 end
diff --git a/wiki b/wiki
index 991e3bb813a650a6d6bcd27a9563a746fe489716..df5dd684ec35c1fc8e044fb5fd0bdb76f7f568fa 160000 (submodule)
--- a/wiki
+++ b/wiki
@@ -1 +1 @@
-Subproject commit 991e3bb813a650a6d6bcd27a9563a746fe489716
+Subproject commit df5dd684ec35c1fc8e044fb5fd0bdb76f7f568fa