My configuration files for Debian/Ubuntu applications
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

55 行
1.7 KiB

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