summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-02-25 14:33:38 +0100
committerMattias Andrée <maandree@operamail.com>2014-02-25 14:33:38 +0100
commitd7726f624d5d27f0b74f010eab43166debd3ace7 (patch)
tree559af4c7ceb2afa07f552d3a217e339ac7c1fc03
parenttypo (diff)
downloadblueshift-d7726f624d5d27f0b74f010eab43166debd3ace7.tar.gz
blueshift-d7726f624d5d27f0b74f010eab43166debd3ace7.tar.bz2
blueshift-d7726f624d5d27f0b74f010eab43166debd3ace7.tar.xz
buf cause by typo + add example: crtc-searching
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--Makefile2
-rw-r--r--examples/crtc-searching77
-rw-r--r--src/monitor.py4
3 files changed, 80 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index b1d6d51..610714b 100644
--- a/Makefile
+++ b/Makefile
@@ -64,7 +64,7 @@ PYFILES = __main__.py colour.py curve.py monitor.py solar.py icc.py adhoc.py
# Library files
CBINDINGS = $(foreach B,$(SERVER_BINDINGS),blueshift_$(B).so)
# Configuration script example files
-EXAMPLES = comprehensive sleepmode crtc-detection
+EXAMPLES = comprehensive sleepmode crtc-detection crtc-searching
# Build rules
diff --git a/examples/crtc-searching b/examples/crtc-searching
new file mode 100644
index 0000000..9633b2a
--- /dev/null
+++ b/examples/crtc-searching
@@ -0,0 +1,77 @@
+# -*- python -*-
+
+# This example uses option parsing and CRTC searching.
+# `Screens.find_by_crtc` and `Screen.find_by_crtc`, are
+# not used, those are not useful for anything. They can
+# be used for seaching the number of connected monitors,
+# but `Screen.crtc_count` is much more effective.
+
+
+# We want to use the ad-hoc mode options.
+uses_adhoc_opts = True
+
+# Parse gamma option from ad-hoc mode options.
+gamma_ = parser.opts['--gamma']
+if gamma_ is None:
+ gamma_ = [1, 1, 1]
+else:
+ if len(gamma_) > 1:
+ print('--gamma can only be used once')
+ sys.exit(1)
+ gamma_ = [float(x) for x in gamma_[0].split(':')]
+
+# Parse temperature option from ad-hoc mode options.
+temperature_ = parser.opts['--temperature']
+if temperature_ is None:
+ temperature_ = 5000
+else:
+ if len(temperature_) > 1:
+ print('--temperature can only be used once')
+ sys.exit(1)
+ temperature_ = float(temperature_[0])
+
+
+# Read configuration script options.
+parser = ArgParser('Colour temputare controller',
+ '%s [-p] -c %s -- [options]' % (sys.argv[0], conf_opts[0]),
+ 'Example configuration script using option parsing\n'
+ 'and CRTC searching functions.',
+ None, True, ArgParser.standard_abbreviations())
+
+parser.add_argumentless(['-h', '-?', '--help'], 0, 'Print this help information')
+parser.add_argumented(['-n', '--name'], 0, 'NAME', 'Select output by name')
+parser.add_argumented(['-s', '--size'], 0, 'WIDTH_MM:HEIGHT_MM', 'Select output by monitor size')
+
+parser.parse(conf_opts)
+parser.support_alternatives()
+
+if parser.opts['--help'] is not None:
+ parser.help()
+ sys.exit(0)
+
+
+# Find CRTC:s.
+screens = list_screens()
+outputs = []
+
+# Find CRTC:s by name.
+if parser.opts['--name'] is not None:
+ for name in parser.opts['--name']:
+ outputs += screens.find_by_name(name)
+
+# Find CRTC:s by monitor size.
+if parser.opts['--size'] is not None:
+ for size in parser.opts['--size']:
+ outputs += screens.find_by_size(*[int(x) for x in size.split(':')])
+
+
+# Adjust colour curves.
+for output in outputs:
+ # Perform adjustments.
+ start_over()
+ temperature(temperature_, lambda t : divide_by_maximum(cmf_10deg(t)))
+ gamma(*gamma_)
+
+ # Apply adjustments.
+ randr(output.crtc, screen = output.screen)
+
diff --git a/src/monitor.py b/src/monitor.py
index f8a699a..70a86e6 100644
--- a/src/monitor.py
+++ b/src/monitor.py
@@ -322,7 +322,7 @@ class Screen:
rc.append(self.outputs[i])
return rc
- def find_by_size(self, widthmm, heigthmm):
+ def find_by_size(self, widthmm, heightmm):
'''
Find output by physical size
@@ -333,7 +333,7 @@ class Screen:
rc = []
for i in range(len(self.outputs)):
if self.outputs[i].widthmm == widthmm:
- if self.outputs[i].heigthmm == heigthmm:
+ if self.outputs[i].heightmm == heightmm:
rc.append(self.outputs[i])
return rc