summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-03-19 23:21:08 +0100
committerMattias Andrée <maandree@operamail.com>2014-03-19 23:21:08 +0100
commitdf04453f6812de75bd8e2d168119f2d64cfbba9d (patch)
tree6bbd9d0f46c6518d43fa9df4d9cb860a39986ed7
parentm doc (diff)
downloadblueshift-df04453f6812de75bd8e2d168119f2d64cfbba9d.tar.gz
blueshift-df04453f6812de75bd8e2d168119f2d64cfbba9d.tar.bz2
blueshift-df04453f6812de75bd8e2d168119f2d64cfbba9d.tar.xz
add backlight support in textconf
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--TODO1
-rw-r--r--examples/textconf48
-rw-r--r--examples/textconf.conf26
3 files changed, 63 insertions, 12 deletions
diff --git a/TODO b/TODO
index b677aec..2e3cf77 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,7 @@
High priority:
Add support for monitor hotplugging
Add models for calculating fade and refresh rate parameters
+ Test backlight in textconf
Medium priority:
Test and demo _ICC_PROFILE
diff --git a/examples/textconf b/examples/textconf
index acddc79..258de91 100644
--- a/examples/textconf
+++ b/examples/textconf
@@ -26,6 +26,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import os
import sys
import time
import subprocess
@@ -104,6 +105,8 @@ adjustments = []
monitors = []
crtc = None
screen = None
+bldev = None
+blmin = 0
def parse_value(value):
@@ -233,6 +236,7 @@ def float6(value):
value.append(q)
return value
+backlight_value = 1
def add_adjustments(adjsections, adjustments):
'''
Add adjustions from a section to a list
@@ -240,7 +244,7 @@ def add_adjustments(adjsections, adjustments):
@param adjsections:list<list<(str, str)>> The sections
@param adjustments:list<(float, float)→void> The list to fill with adjustments
'''
- global location, points, adjustment_method_x, adjustment_method_tty, crtc, screen
+ global location, points, adjustment_method_x, adjustment_method_tty, crtc, screen, bldev, blmin
for section in adjsections:
for (setting, value) in section:
(value, linear, cie, default) = parse_value(value)
@@ -254,6 +258,13 @@ def add_adjustments(adjsections, adjustments):
elif setting == 'crtc': crtc = value
elif setting == 'screen': screen = value
elif setting == 'card': screen = value
+ elif setting == 'backlight-device': bldev = value
+ elif setting == 'backlight-minimum': blmin = int(value[0])
+ elif setting == 'backlight':
+ def f(x):
+ global backlight_value
+ backlight_value *= f
+ new_adjustment = make_f(f, [[float(v)] for v in value], [6500])
elif setting == 'temperature':
f = lambda x : temperature(x, lambda t : divide_by_maximum(cmf_10deg(t)))
new_adjustment = make_f(f, [[float(v)] for v in value], [6500])
@@ -310,7 +321,7 @@ screen_list = None
for section in sections[adjustment_method]:
output_adjustments = []
- crtc, screen = None, None
+ crtc, screen, bldev, blmin = None, None, None, 0
add_adjustments([section], output_adjustments)
if (screen_list is None) and ((crtc is None) or (screen is None)):
screen_list = list_screens(list_method)
@@ -324,7 +335,7 @@ for section in sections[adjustment_method]:
crtcs[s] = [int(c) for c in crtc]
else:
crtcs[s] = list(range(screen_list[s].crtc_count))
- monitors.append((crtcs, screen, output_adjustments))
+ monitors.append((crtcs, screen, bldev, blmin, output_adjustments))
# Get gamma adjustment/reader functions
@@ -336,7 +347,7 @@ set_method = set_method[adjustment_method]
# Save gamma ramps
saved = {}
-for crtcs, screens, _ in monitors:
+for crtcs, screens, _bldev, _blmin, _adj in monitors:
for screen in screens:
if screen not in saved:
saved[screen] = {}
@@ -427,6 +438,24 @@ wait_period = 5
'''
+# Create backlight device connection
+adjbl = False
+if 'PATH' in os.environ:
+ path = os.environ['PATH'].split(os.path.pathsep)
+ sep = os.path.sep
+ for p in path:
+ f = p + sep + 'adjbacklight'
+ if os.path.exists(f):
+ if os.accsss(f, X_OK):
+ adjbl = True
+ break
+makebl = lambda dev, blmin : None if dev == 'none' else Backlight(dev, adjbacklight = adjbl, minimum = blmin)
+monitors = [(crtcs, screens, makebl(dev, blmin), adj) for crtcs, screens, dev, blmin, adj in monitors]
+
+# Save backlight settings
+saved_backlight = [(bl, bl.brightness) for _c, _s, bl, _a in monitors if bl is not None]
+
+
def periodically(year, month, day, hour, minute, second, weekday, fade):
'''
:(int, int, int, int, int, int, int, float?)?→void Place holder for periodically invoked function
@@ -465,29 +494,36 @@ def periodically(year, month, day, hour, minute, second, weekday, fade):
alpha = 1 if fade is None else abs(fade)
timepoint = get_timepoint()
+ backlight_value = 1
for adjustment in adjustments:
adjustment(timepoint, alpha)
stored = store()
- for crtcs, screens, output_adjustments in monitors:
+ stored_backlight_value = backlight_value
+ for crtcs, screens, bldev, output_adjustments in monitors:
restore(stored)
+ backlight_value = stored_backlight_value
for adjustment in output_adjustments:
adjustment(timepoint, alpha)
for screen in screens:
set_method(*(crtcs[screen]), screen = screen)
+ if bldev is not None:
+ bldev.brightness = backlight_value
def reset():
'''
Invoked to reset the displays
'''
- for crtcs, screens, _ in monitors:
+ for crtcs, screens, bldev, _adj in monitors:
for screen in screens:
saved_ = saved[screen]
for crtc in crtcs[screen]:
start_over()
saved_[crtc]()
set_method(crtc, screen = screen)
+ for dev, lvl in saved_backlight:
+ dev.brightness = lvl
diff --git a/examples/textconf.conf b/examples/textconf.conf
index 172217f..4dcee4c 100644
--- a/examples/textconf.conf
+++ b/examples/textconf.conf
@@ -16,11 +16,11 @@
adjustment-method-x = randr ; (default) vidmode is also available
; This is the method used to set and get colour curves for monitors
-; when running in X
+; when running in X.
adjustment-method-tty = drm ; (default)
; This is the method used to set and get colour curves for monitors
-; when running in TTY
+; when running in TTY.
location = 59.3326 18.0652
; Your geographical location as GPS coordinates in decimal form. If you
@@ -148,7 +148,7 @@ temperature = 6500 3600
;limits = 0.1..0.9
; Apply a brightness–contrast correction of 90 % black
; (black is 0; first parameter) and 90 % white (white
-; is 1; second parameter)
+; is 1; second parameter.)
;limits = 0:0.1:0.1..1:0.9:0.9 cie
; Apply a brightness–contrast correction of 90 % black
@@ -156,9 +156,11 @@ temperature = 6500 3600
;icc = /home/user/.config/icc/filter
; Apply an ICC profile with the pathname
-; /home/user/.config/icc/filter
+; ‘/home/user/.config/icc/filter’.
-; TODO it should be possible to control backlight
+;backlight = 1
+; Apply backlight adjustment. This requires that
+; the backlight device has been specified.
; Here begins monitor identification and specific
@@ -173,7 +175,17 @@ gamma = 1.16:1.15:1.11 default
; the adjustments in effect, at which time these adjustments will
; still apply.
-; TODO it should be possible to map to a backlight device
+backlight-device = none
+; Device in ‘/sys/class/backlight/’ used to control the
+; backlight of the monitor. ‘none’ if no controller.
+
+backlight-minimum = 0 ; (default)
+; Artificial minimum backlight value that can be used in
+; ‘/sys/class/backlight/${backlight-device}/brightness’.
+; Some devices freezes at if the value is top low so that
+; the computer needs to be restarted. This can used so
+; that it does not happen.
+
[randr] ; RandR specific information for monitor 0
monitor=0 ; Include [monitor 0]
@@ -195,6 +207,8 @@ card=0 ; on graphics card 0
[monitor 1] ; Adjustment method independent settings for monitor 1
gamma = 1.10:1.16:1.10 default
+backlight-device = none
+backlight-minimum = 0
[randr] ; RandR specific information for monitor 1
monitor=1 ; Include [monitor 1]