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