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

some cpu usage improvements
authorcopycat-killer <dada@archlinux.info>
Thu, 3 Mar 2016 11:40:49 +0000 (12:40 +0100)
committercopycat-killer <dada@archlinux.info>
Thu, 3 Mar 2016 11:40:49 +0000 (12:40 +0100)
widgets/abase.lua
widgets/alsa.lua
widgets/alsabar.lua
widgets/base.lua
widgets/borderbox.lua
widgets/cpu.lua
widgets/net.lua
widgets/temp.lua

index 98f7818d844fe2b2c7c004b2ed39a9abacd91eb9..fb20d768222e974e83f6af9b2360c05a5290eaf5 100644 (file)
@@ -28,8 +28,11 @@ local function worker(args)
     function abase.update()
         async.request(cmd, function(f)
             output = f
-            widget = abase.widget
-            settings()
+            if output ~= abase.prev then
+                widget = abase.widget
+                settings()
+                abase.prev = output
+            end
         end)
     end
 
index 85d53114e132a683fe2af8af9f86908af61b8f39..bb549428601ca5cc4a3b913781d88fc639e3095e 100644 (file)
@@ -19,7 +19,7 @@ local setmetatable    = setmetatable
 
 -- ALSA volume
 -- lain.widgets.alsa
-local alsa = {}
+local alsa = { last_level = "0", last_status = "off" }
 
 local function worker(args)
     local args     = args or {}
@@ -28,34 +28,20 @@ local function worker(args)
 
     alsa.cmd     = args.cmd or "amixer"
     alsa.channel = args.channel or "Master"
-
-    alsa.widget = wibox.widget.textbox('')
+    alsa.widget  = wibox.widget.textbox('')
 
     function alsa.update()
-        local mixer = read_pipe(string.format("%s get %s", alsa.cmd, alsa.channel))
-
-        volume_now = {}
+        mixer = read_pipe(string.format("%s get %s", alsa.cmd, alsa.channel))
+        l, s = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
 
-        volume_now.level, volume_now.status = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
+        if alsa.last_level ~= l or alsa.last_status ~= s then
+            volume_now = { level = l, status = s }
+            alsa.last_level = l
+            alsa.last_status = s
 
-        if volume_now.level == nil
-        then
-            volume_now.level  = "0"
-            volume_now.status = "off"
+            widget = alsa.widget
+            settings()
         end
-
-        if volume_now.status == ""
-        then
-            if volume_now.level == "0"
-            then
-                volume_now.status = "off"
-            else
-                volume_now.status = "on"
-            end
-        end
-
-        widget = alsa.widget
-        settings()
     end
 
     timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel)
index c7498d2e6be2bf31fdac43ba8288e25e8d9eadfe..7e8cd5a4bd09b277d2c692f98931d86a1fdecbdd 100644 (file)
@@ -127,28 +127,26 @@ local function worker(args)
         -- Capture mixer control state:          [5%] ... ... [on]
         local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
 
-        if volu == nil then
-            volu = 0
-            mute = "off"
-        end
-
-        alsabar._current_level = tonumber(volu)
-        alsabar.bar:set_value(alsabar._current_level / 100)
-        if not mute and tonumber(volu) == 0 or mute == "off"
+        if tonumber(volu) ~= alsabar._current_level or string.match(mute, "on") ~= alsabar._muted
         then
-            alsabar._muted = true
-            alsabar.tooltip:set_text (" [Muted] ")
-            alsabar.bar:set_color(alsabar.colors.mute)
-        else
-            alsabar._muted = false
-            alsabar.tooltip:set_text(string.format(" %s:%s ", alsabar.channel, volu))
-            alsabar.bar:set_color(alsabar.colors.unmute)
+            alsabar._current_level = tonumber(volu)
+            alsabar.bar:set_value(alsabar._current_level / 100)
+            if not mute and tonumber(volu) == 0 or mute == "off"
+            then
+                alsabar._muted = true
+                alsabar.tooltip:set_text (" [Muted] ")
+                alsabar.bar:set_color(alsabar.colors.mute)
+            else
+                alsabar._muted = false
+                alsabar.tooltip:set_text(string.format(" %s:%s ", alsabar.channel, volu))
+                alsabar.bar:set_color(alsabar.colors.unmute)
+            end
+
+            volume_now = {}
+            volume_now.level = tonumber(volu)
+            volume_now.status = mute
+            settings()
         end
-
-        volume_now = {}
-        volume_now.level = tonumber(volu)
-        volume_now.status = mute
-        settings()
     end
 
     alsabar.bar:buttons (awful.util.table.join (
index 2f377f78bb4ccd552bf01f5299476719f21e2d53..272163c067f22d1e517a8ba27507a3cafb785b3a 100644 (file)
@@ -26,9 +26,12 @@ local function worker(args)
     base.widget = wibox.widget.textbox('')
 
     function base.update()
-        output = read_pipe(cmd)
-        widget = base.widget
-        settings()
+        if output ~= abase.prev then
+            output = read_pipe(cmd)
+            widget = base.widget
+            settings()
+            abase.prev = output
+        end
     end
 
     newtimer(cmd, timeout, base.update)
index cce8517e1caa9802ff8399dae47cd52349445b60..fb992de8975c26374e0bd4826a41fafa6c12bcb5 100644 (file)
@@ -7,8 +7,7 @@
                                                   
 --]]
 
-local wibox        = require("awful.wibox")
-
+local wibox = require("awful.wibox")
 local setmetatable = setmetatable
 
 -- Creates a thin wibox at a position relative to another wibox
index ec84101f6d0be1bf1ed07b8b6dfe015f4b916208..6019f3257e07d10d891070caa352eda2d5655bc0 100644 (file)
@@ -21,10 +21,7 @@ local setmetatable = setmetatable
 
 -- CPU usage
 -- lain.widgets.cpu
-local cpu = {
-    last_total = 0,
-    last_active = 0
-}
+local cpu = { last_total = 0, last_active = 0 }
 
 local function worker(args)
     local args     = args or {}
@@ -53,20 +50,22 @@ local function worker(args)
             at = at + 1
         end
         local active = total - idle
+        
+        if cpu.last_active ~= active or cpu.last_total ~= total then
+            -- Read current data and calculate relative values.
+            local dactive = active - cpu.last_active
+            local dtotal = total - cpu.last_total
 
-        -- Read current data and calculate relative values.
-        local dactive = active - cpu.last_active
-        local dtotal = total - cpu.last_total
+            cpu_now = {}
+            cpu_now.usage = tostring(math.ceil((dactive / dtotal) * 100))
 
-        cpu_now = {}
-        cpu_now.usage = tostring(math.ceil((dactive / dtotal) * 100))
+            widget = cpu.widget
+            settings()
 
-        widget = cpu.widget
-        settings()
-
-        -- Save current data for the next run.
-        cpu.last_active = active
-        cpu.last_total = total
+            -- Save current data for the next run.
+            cpu.last_active = active
+            cpu.last_total = total
+        end
     end
 
     newtimer("cpu", timeout, update)
index af823a824e1eaa48e8e5bd05025365c7d46f261a..a4b1097b1b52616cbb02793de1c4c81dca1ed8be 100644 (file)
@@ -8,8 +8,6 @@
 --]]
 
 local helpers      = require("lain.helpers")
-
-local notify_fg    = require("beautiful").fg_focus
 local naughty      = require("naughty")
 local wibox        = require("wibox")
 
@@ -28,11 +26,8 @@ local function worker(args)
     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
+        if ws  then return ws:match("(%w+):")
+        else return "network off" end
     end
 
     local args     = args or {}
@@ -55,38 +50,33 @@ local function worker(args)
             iface = net.get_device()
         end
 
-        net_now.carrier = helpers.first_line('/sys/class/net/' .. iface ..
-                                           '/carrier') or "0"
-        net_now.state = helpers.first_line('/sys/class/net/' .. iface ..
-                                           '/operstate') or "down"
-        local now_t = helpers.first_line('/sys/class/net/' .. iface ..
-                                           '/statistics/tx_bytes') or 0
-        local now_r = helpers.first_line('/sys/class/net/' .. iface ..
-                                           '/statistics/rx_bytes') or 0
+        net_now.carrier  = helpers.first_line(string.format('/sys/class/net/%s/carrier', iface)) or '0'
+        net_now.state    = helpers.first_line(string.format('/sys/class/net/%s/operstate', iface)) or 'down'
 
-        net_now.sent = (now_t - net.last_t) / timeout / units
-        net_now.sent = string.gsub(string.format('%.1f', net_now.sent), ",", ".")
+        local now_t      = helpers.first_line(string.format('/sys/class/net/%s/statistics/tx_bytes', iface)) or 0
+        local now_r      = helpers.first_line(string.format('/sys/class/net/%s/statistics/rx_bytes', iface)) or 0
 
-        net_now.received = (now_r - net.last_r) / timeout / units
-        net_now.received = string.gsub(string.format('%.1f', net_now.received), ",", ".")
+        if now_t ~= net.last_t or now_r ~= net.last_r then  
+            net_now.sent     = (now_t - net.last_t) / timeout / units
+            net_now.sent     = string.gsub(string.format('%.1f', net_now.sent), ',', '.')
+            net_now.received = (now_r - net.last_r) / timeout / units
+            net_now.received = string.gsub(string.format('%.1f', net_now.received), ',', '.')
 
-        widget = net.widget
-        settings()
+            widget = net.widget
+            settings()
 
-        net.last_t = now_t
-        net.last_r = now_r
+            net.last_t = now_t
+            net.last_r = now_r
+        end
 
-        if net_now.carrier ~= "1" and notify == "on"
+        if not string.match(net_now.carrier, "1") and notify == "on"
         then
             if helpers.get_map(iface)
             then
                 naughty.notify({
                     title    = iface,
                     text     = "no carrier",
-                    timeout  = 7,
-                    position = "top_left",
                     icon     = helpers.icons_dir .. "no_net.png",
-                    fg       = notify_fg or "#FFFFFF",
                     screen   = screen
                 })
                 helpers.set_map(iface, false)
index 67c94560b9a58e67fa15ef340c8862f4b473e020..a857e71e3de7f80167df6c67817c9f24d9290b8f 100644 (file)
@@ -42,6 +42,7 @@ local function worker(args)
     end
 
     newtimer("coretemp", timeout, update)
+
     return temp.widget
 end