summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TODO2
-rw-r--r--examples/comprehensive63
-rw-r--r--src/blueshift_randr.pyx6
-rw-r--r--src/blueshift_vidmode.pyx6
-rw-r--r--src/monitor.py8
5 files changed, 69 insertions, 16 deletions
diff --git a/TODO b/TODO
index 9d943f5..c618ad1 100644
--- a/TODO
+++ b/TODO
@@ -2,7 +2,7 @@ High priority:
Add support for monitor hotplugging
Add models for calculating fade and refresh rate parameters
Test with multiple X screens
- Test and demo multi-display support
+ Fix multi-display support
Medium priority:
Add a section in manual for information on which order
diff --git a/examples/comprehensive b/examples/comprehensive
index 96e3d96..41b0137 100644
--- a/examples/comprehensive
+++ b/examples/comprehensive
@@ -89,11 +89,64 @@ download_command = None
# download_command = lambda url : ['wget', url, '-O', '-']
-# Method for applying colour curves.
-apply_curves = randr
-#apply_curves = vidmode
-if ttymode:
- apply_curves = drm
+# Method for applying colour curves in X.
+apply_curves_x = randr
+#apply_curves_x = vidmode
+
+# Method for applying colour curves in TTY.
+apply_curves_tty_ = drm
+
+# X's RandR and DRM which is used in TTY, does not
+# necessarily give the CRTC:s the same indices.
+# Specifically, RandR reorders them so that the
+# primary monitor have CRTC 0. Fill in this table
+# so that the indices give by DRM are mapped to
+# those given by RandR. In this example, 0 is mapped
+# to 1 and 1 is mapped to 0, this is how it should
+# be if your primary monitor is given index 1 by
+# DRM and you have two monitors.
+tty_to_x_crtc_mapping = {0 : 1, 1 : 0}
+
+def apply_curves_tty(*crtcs, screen = 0, display = None):
+ '''
+ Wrapping for `apply_curves_tty_` that remaps the CRTC:s
+ indices, to match those in RandR.
+
+ @param crtcs:*int The CRT controllers to use, all are used if none are specified
+ @param screen:int The graphics card to which the monitors belong,
+ named `screen` for compatibility with `randr` and `vidmode`
+ @param display:str? Dummy parameter for compatibility with `randr` and `vidmode`
+ '''
+ mapping = tty_to_x_crtc_mapping
+ crtcs_ = [(mapping[c] if c in mapping else c) for c in crtcs]
+ apply_curves_tty_(*crtcs_, screen = screen, display = display)
+
+def apply_curves(*crtcs, screen = 0):
+ '''
+ Applies colour curves
+
+ This wrapper is used to allow multi-display and multi-server support
+
+ @param crtcs:*int The CRT controllers to use, all are used if none are specified
+ @param screen:int The screen to which the monitors belong
+ '''
+ # Single display and single server, variant:
+ #(apply_curves_tty if ttymode apply_curves_x)(*crtcs, screen = screen)
+
+ # Variant for TTY and all X display:
+ #apply_curves_tty(*crtcs, screen = screen)
+ #for display_socket in os.listdir('/tmp/.X11-unix'):
+ # if display_socket.startswith('X'):
+ # try:
+ # display = ':%i' % int(display_socket[1:])
+ # apply_curves_x(*crtcs, screen = screen, display = display)
+ # except:
+ # pass
+
+ # Variant for TTY and selected X displays:
+ apply_curves_tty(*crtcs, screen = screen)
+ for display in [None, ':1']: # Current and :1
+ apply_curves_x(*crtcs, screen = screen, display = display)
# Keep uncomment to use solar position.
diff --git a/src/blueshift_randr.pyx b/src/blueshift_randr.pyx
index 756ea73..e845f65 100644
--- a/src/blueshift_randr.pyx
+++ b/src/blueshift_randr.pyx
@@ -44,9 +44,9 @@ def randr_open(int use_screen, display):
'''
Start stage of colour curve control
- @param use_screen The screen to use
- @param display:str? The display to use, `None` for the current
- @return :int Zero on success
+ @param use_screen The screen to use
+ @param display:bytes? The display to use, `None` for the current
+ @return :int Zero on success
'''
cdef char* display_ = NULL
if display is not None:
diff --git a/src/blueshift_vidmode.pyx b/src/blueshift_vidmode.pyx
index e4262d7..7ad7a4c 100644
--- a/src/blueshift_vidmode.pyx
+++ b/src/blueshift_vidmode.pyx
@@ -50,9 +50,9 @@ def vidmode_open(int use_screen, display):
'''
Start stage of colour curve control
- @param use_screen The screen to use
- @param display:str? The display to use, `None` for the current
- @return :bool Whether call was successful
+ @param use_screen The screen to use
+ @param display:bytes? The display to use, `None` for the current
+ @return :bool Whether call was successful
'''
global vidmode_gamma_size
cdef char* display_ = NULL
diff --git a/src/monitor.py b/src/monitor.py
index 84be9c9..e58836b 100644
--- a/src/monitor.py
+++ b/src/monitor.py
@@ -93,7 +93,7 @@ def randr_get(crtc = 0, screen = 0, display = None):
if randr_opened is not None:
randr_close()
# Open RandR connection
- if randr_open(screen, display) == 0:
+ if randr_open(screen, display if display is None else display.encode('utf-8')) == 0:
randr_opened = (screen, display)
else:
raise Exception('Cannot open RandR connection')
@@ -118,7 +118,7 @@ def vidmode_get(crtc = 0, screen = 0, display = None):
if vidmode_opened is not None:
vidmode_close()
# Open vidmode connection
- if vidmode_open(screen, display):
+ if vidmode_open(screen, display if display is None else display.encode('utf-8')):
vidmode_opened = (screen, display)
else:
raise Exception('Cannot open vidmode connection')
@@ -162,7 +162,7 @@ def randr(*crtcs, screen = 0, display = None):
if randr_opened is not None:
randr_close()
# Open RandR connection
- if randr_open(screen, display) == 0:
+ if randr_open(screen, display if display is None else display.encode('utf-8')) == 0:
randr_opened = (screen, display)
else:
raise Exception('Cannot open RandR connection')
@@ -195,7 +195,7 @@ def vidmode(*crtcs, screen = 0, display = None):
if vidmode_opened is not None:
vidmode_close()
# Open vidmode connection
- if vidmode_open(screen, display):
+ if vidmode_open(screen, display if display is None else display.encode('utf-8')):
vidmode_opened = (screen, display)
else:
raise Exception('Cannot open vidmode connection')