This repository has been archived by the owner on Feb 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
init.lua
69 lines (65 loc) · 1.85 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
--- Redshift for Awesome WM
-- author: Ryan Young <ryan .ry. young@gmail. com> (omit spaces)
--
-- https://github.com/YoRyan/awesome-redshift
--
-- standard libraries
local awful = require("awful")
-- variables
local redshift = {}
redshift.redshift = "/usr/bin/redshift" -- binary path
redshift.method = "randr" -- randr or vidmode
redshift.options = "" -- additional redshift command options
redshift.state = 1 -- 1 for screen dimming, 0 for none
redshift.timer = timer({ timeout = 60 })
-- functions
redshift.dim = function()
if redshift.method == "randr"
then
awful.util.spawn(redshift.redshift .. " -m randr -o " .. redshift.options)
elseif redshift.method == "vidmode"
then
local screens = screen.count()
for i = 0, screens - 1
do
awful.util.spawn(redshift.redshift .. " -m vidmode:screen=" .. i ..
" -o " .. redshift.options)
end
end
redshift.state = 1
redshift.timer:start()
end
redshift.timer:connect_signal("timeout", redshift.dim)
redshift.undim = function()
if redshift.method == "randr"
then
awful.util.spawn(redshift.redshift .. " -m randr -x " .. redshift.options)
elseif redshift.method == "vidmode"
then
local screens = screen.count()
for i = 0, screens - 1
do
awful.util.spawn(redshift.redshift .. " -m vidmode:screen=" .. i ..
" -x " .. redshift.options)
end
end
redshift.state = 0
redshift.timer:stop()
end
redshift.toggle = function()
if redshift.state == 1
then
redshift.undim()
else
redshift.dim()
end
end
redshift.init = function(initState)
if initState == 1
then
redshift.dim()
else
redshift.undim()
end
end
return redshift