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.
3 Licensed under GNU General Public License v2
4 * (c) 2018, Uli Schlacter
5 * (c) 2018, Otto Modinos
10 local helpers = require("lain.helpers")
11 local Gio = require("lgi").Gio
12 local focused = require("awful.screen").focused
13 local wibox = require("wibox")
14 local naughty = require("naughty")
17 local tconcat = table.concat
19 local tonumber = tonumber
20 local query_size = Gio.FILE_ATTRIBUTE_FILESYSTEM_SIZE
21 local query_free = Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE
22 local query_used = Gio.FILE_ATTRIBUTE_FILESYSTEM_USED
23 local query = query_size .. "," .. query_free .. "," .. query_used
28 local function factory(args)
30 widget = wibox.widget.textbox(),
32 [1] = "Kb", [2] = "Mb", [3] = "Gb",
33 [4] = "Tb", [5] = "Pb", [6] = "Eb",
34 [7] = "Zb", [8] = "Yb"
39 if not fs.notification then return end
40 naughty.destroy(fs.notification)
44 function fs.show(seconds, scr)
45 fs.hide(); fs.update()
46 fs.notification_preset.screen = fs.followtag and focused() or scr or 1
47 fs.notification = naughty.notify {
48 preset = fs.notification_preset,
49 timeout = type(seconds) == "number" and seconds or 5
53 local args = args or {}
54 local timeout = args.timeout or 600
55 local partition = args.partition
56 local threshold = args.threshold or 99
57 local showpopup = args.showpopup or "on"
58 local settings = args.settings or function() end
60 fs.followtag = args.followtag or false
61 fs.notification_preset = args.notification_preset
63 if not fs.notification_preset then
64 fs.notification_preset = {
65 font = "Monospace 10",
72 local notifytable = { [1] = string.format("%-10s %-5s %s\t%s\t\n", "path", "used", "free", "size") }
77 for _, mount in ipairs(Gio.unix_mounts_get()) do
78 local path = Gio.unix_mount_get_mount_path(mount)
79 local root = Gio.File.new_for_path(path)
80 local info = root:query_filesystem_info(query)
83 local size = info:get_attribute_uint64(query_size)
84 local used = info:get_attribute_uint64(query_used)
85 local free = info:get_attribute_uint64(query_free)
88 local units = math.floor(math.log(size)/math.log(1024))
91 units = fs.units[units],
92 percentage = math.floor(100 * used / size), -- used percentage
93 size = size / math.pow(1024, math.floor(units)),
94 used = used / math.pow(1024, math.floor(units)),
95 free = free / math.pow(1024, math.floor(units))
98 if fs_now[path].percentage > 0 then -- don't notify unused file systems
99 notifytable[#notifytable+1] = string.format("\n%-10s %-3s\t%.2f\t%.2f\t%s", path,
100 math.floor(fs_now[path].percentage) .. "%", fs_now[path].free, fs_now[path].size,
103 if #path > pathlen then
105 maxpathidx = #notifytable
115 if partition and fs_now[partition] and fs_now[partition].percentage >= threshold then
116 if not helpers.get_map(partition) then
118 preset = naughty.config.presets.critical,
120 text = string.format("%s is above %d%% (%d%%)", partition, threshold, fs_now[partition].percentage)
122 helpers.set_map(partition, true)
124 helpers.set_map(partition, false)
128 if pathlen > 10 then -- formatting aesthetics
130 for i = 1, #notifytable do
131 pathspaces = notifytable[i]:match("[ ]+")
132 if i ~= maxpathidx and pathspaces then
133 notifytable[i] = notifytable[i]:gsub(pathspaces, pathspaces .. string.rep(" ", pathlen - 10))
138 fs.notification_preset.text = tconcat(notifytable)
141 if showpopup == "on" then
142 fs.widget:connect_signal('mouse::enter', function () fs.show(0) end)
143 fs.widget:connect_signal('mouse::leave', function () fs.hide() end)
146 helpers.newtimer(partition or "fs", timeout, fs.update)