]> git.madduck.net Git - etc/awesome.git/blob - widgets/fs.lua.orig

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:

c1a3ab7131766d00f0961cd52e802dda65b42adb
[etc/awesome.git] / widgets / fs.lua.orig
1
2 --[[
3                                                       
4      Licensed under GNU General Public License v2     
5       * (c) 2013, Luke Bonham                         
6       * (c) 2010, Adrian C.      <anrxc@sysphere.org> 
7       * (c) 2009, Lucas de Vries <lucas@glacicle.com> 
8                                                       
9 --]]
10
11 local helpers      = require("lain.helpers")
12
13 local beautiful    = require("beautiful")
14 local wibox        = require("wibox")
15 local naughty      = require("naughty")
16
17 local io           = { popen  = io.popen }
18 local pairs        = pairs
19 <<<<<<< HEAD
20 =======
21 local mouse        = mouse
22 >>>>>>> upstream/master
23 local string       = { match  = string.match,
24                        format = string.format }
25 local tonumber     = tonumber
26
27 local setmetatable = setmetatable
28
29 -- File system disk space usage
30 -- lain.widgets.fs
31 local fs = {}
32 <<<<<<< HEAD
33
34 local notification  = nil
35 fs_notification_preset = { fg = beautiful.fg_normal }
36
37 function fs:hide()
38     if notification ~= nil then
39         naughty.destroy(notification)
40         notification = nil
41 =======
42 local fs_notification  = nil
43
44 function fs:hide()
45     if fs_notification ~= nil then
46         naughty.destroy(fs_notification)
47         fs_notification = nil
48 >>>>>>> upstream/master
49     end
50 end
51
52 function fs:show(t_out)
53     fs:hide()
54
55 <<<<<<< HEAD
56     local f = io.popen(helpers.scripts_dir .. "dfs")
57     ws = f:read("*a"):gsub("\n*$", "")
58     f:close()
59
60     notification = naughty.notify({
61         preset = fs_notification_preset,
62         text = ws,
63         timeout = t_out,
64 =======
65     local ws = helpers.read_pipe(helpers.scripts_dir .. "dfs"):gsub("\n*$", "")
66
67     if fs.followmouse then
68         fs.notification_preset.screen = mouse.screen
69     end
70
71     fs_notification = naughty.notify({
72         preset  = fs.notification_preset,
73         text    = ws,
74         timeout = t_out
75 >>>>>>> upstream/master
76     })
77 end
78
79 -- Unit definitions
80 local unit = { ["mb"] = 1024, ["gb"] = 1024^2 }
81
82 local function worker(args)
83 <<<<<<< HEAD
84     local args      = args or {}
85     local timeout   = args.timeout or 600
86     local partition = args.partition or "/"
87     local settings  = args.settings or function() end
88 =======
89     local args             = args or {}
90     local timeout          = args.timeout or 600
91     local partition        = args.partition or "/"
92     local settings         = args.settings or function() end
93
94     fs.followmouse         = args.followmouse or false
95     fs.notification_preset = args.notification_preset or { fg = beautiful.fg_normal }
96 >>>>>>> upstream/master
97
98     fs.widget = wibox.widget.textbox('')
99
100     helpers.set_map(partition, false)
101
102     function update()
103         fs_info = {}
104         fs_now  = {}
105         local f = assert(io.popen("LC_ALL=C df -kP"))
106
107         for line in f:lines() do -- Match: (size) (used)(avail)(use%) (mount)
108             local s     = string.match(line, "^.-[%s]([%d]+)")
109             local u,a,p = string.match(line, "([%d]+)[%D]+([%d]+)[%D]+([%d]+)%%")
110             local m     = string.match(line, "%%[%s]([%p%w]+)")
111
112             if u and m then -- Handle 1st line and broken regexp
113                 fs_info[m .. " size_mb"]  = string.format("%.1f", tonumber(s) / unit["mb"])
114                 fs_info[m .. " size_gb"]  = string.format("%.1f", tonumber(s) / unit["gb"])
115                 fs_info[m .. " used_p"]   = tonumber(p)
116                 fs_info[m .. " avail_p"]  = 100 - tonumber(p)
117             end
118         end
119
120         f:close()
121
122         fs_now.used      = tonumber(fs_info[partition .. " used_p"])  or 0
123         fs_now.available = tonumber(fs_info[partition .. " avail_p"]) or 0
124         fs_now.size_mb   = tonumber(fs_info[partition .. " size_mb"]) or 0
125         fs_now.size_gb   = tonumber(fs_info[partition .. " size_gb"]) or 0
126
127         widget = fs.widget
128         settings()
129
130         if fs_now.used >= 99 and not helpers.get_map(partition)
131         then
132             naughty.notify({
133                 title = "warning",
134                 text = partition .. " ran out!\nmake some room",
135                 timeout = 8,
136                 fg = "#000000",
137                 bg = "#FFFFFF",
138             })
139             helpers.set_map(partition, true)
140         else
141             helpers.set_map(partition, false)
142         end
143     end
144
145     fs.widget:connect_signal('mouse::enter', function () fs:show(0) end)
146     fs.widget:connect_signal('mouse::leave', function () fs:hide() end)
147
148     helpers.newtimer(partition, timeout, update)
149
150     return setmetatable(fs, { __index = fs.widget })
151 end
152
153 return setmetatable(fs, { __call = function(_, ...) return worker(...) end })