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.
4 Licensed under GNU General Public License v2
5 * (c) 2014, blueluke <http://github.com/blueluke>
9 local async = require("lain.helpers").async
10 local awful = require("awful")
11 local execute = os.execute
15 -- lain.widgets.contrib.redshift
16 local redshift = { active = false, pid = nil }
18 function redshift:start()
19 execute("pkill redshift")
20 awful.spawn.with_shell("redshift -x") -- clear adjustments
21 redshift.pid = awful.spawn.with_shell("redshift")
22 redshift.active = true
23 if type(redshift.update_fun) == "function" then
24 redshift.update_fun(redshift.active)
28 function redshift:toggle()
29 async(string.format("%s -c 'ps -p %d -o pid='", awful.util.shell, redshift.pid), function(f)
30 if f and #f > 0 then -- redshift is running
31 -- Sending -USR1 toggles redshift (See project website)
32 execute("pkill -USR1 redshift")
33 redshift.active = not redshift.active
34 else -- not started or killed, (re)start it
37 redshift.update_fun(redshift.active)
42 -- Provides a button which toggles redshift on/off on click
43 -- @param widget: Widget to attach to.
44 -- @param fun: Function to be run each time redshift is toggled (optional).
45 -- Use it to update widget text or icons on status change.
46 function redshift:attach(widget, fun)
47 redshift.update_fun = fun or function() end
48 if not redshift.pid then redshift:start() end
50 widget:buttons(awful.util.table.join(awful.button({}, 1, function () redshift:toggle() end)))