diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-03-13 20:16:14 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-03-13 20:16:14 +0100 |
commit | 3b283d550eaee8511ccf5ad81cad1a3fd8365a0d (patch) | |
tree | 8524da53b4ae1f209c53059487774ecbf429ceaf | |
parent | update todo (diff) | |
download | blueshift-3b283d550eaee8511ccf5ad81cad1a3fd8365a0d.tar.gz blueshift-3b283d550eaee8511ccf5ad81cad1a3fd8365a0d.tar.bz2 blueshift-3b283d550eaee8511ccf5ad81cad1a3fd8365a0d.tar.xz |
fix and demo drm support
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | examples/comprehensive | 32 | ||||
-rw-r--r-- | examples/crtc-detection | 13 | ||||
-rw-r--r-- | examples/crtc-searching | 7 | ||||
-rw-r--r-- | src/monitor.py | 37 |
6 files changed, 63 insertions, 36 deletions
@@ -65,9 +65,9 @@ These two types of calibrations can be built in to lookup tables, which ICC profiles normally uses, in other software if it is done manually. -- (Currently being implemented) Blueshift can modify the -colour curves for monitors without a display server like -X or Wayland. This is done by using Direct Rendering Manager. +- Blueshift can modify the colour curves for monitors +without a display server like X or Wayland. This is done +by using Direct Rendering Manager. Installing @@ -2,11 +2,11 @@ High priority: Add example that parses text-based conf file Add support for monitor hotplugging Add models for calculating fade and refresh rate parameters - Test, demo and document DRM support + Document DRM support Medium priority: Fix errors caused by SIGUSR2 - Test, demo and document, _ICC_PROFILE + Test, demo and document _ICC_PROFILE Low priority: Add wayland support diff --git a/examples/comprehensive b/examples/comprehensive index ef8376d..380bf39 100644 --- a/examples/comprehensive +++ b/examples/comprehensive @@ -9,6 +9,8 @@ # nor does it parse options other than -r from ad-hoc settigns, or # use monitor identifiation. +import os + # Geographical coodinates. # (KTH building D computer laboratories in this example.) @@ -41,6 +43,16 @@ def by_time(): return 1 # Error in `time_alpha` (probably) +# Check if we are in X or TTY. +ttymode = not (('DISPLAY' in os.environ) and (':' in os.environ['DISPLAY'])) + +# Method for applying colour curves. +apply_curves = randr +#apply_curves = vidmode +if ttymode: + apply_curves = drm + + # Keep uncomment to use solar position. get_dayness = lambda : sun(latitude, longitude) # Uncomment to use time of day. @@ -132,9 +144,13 @@ icc_calibration_profile = [None] # -p (--panicgate) is used. current_calibration = [None] if not panicgate: - calib_get = None - #calib_get = randr_get - #calib_get = vidmode_get + if not ttymode: + calib_get = None + #calib_get = randr_get + #calib_get = vidmode_get + else: + calib_get = None + #calib_get = drm_get current_calibration = [calib_get] @@ -178,7 +194,7 @@ for i in range(len(current_calibration)): current_calibration[i] = f(m) -monitor_controller = lambda : randr(*monitors) +monitor_controller = lambda : apply_curves(*monitors) ''' :()→void Function used by Blueshift on exit to apply reset colour curves, if using preimplemented `reset` ''' @@ -335,9 +351,9 @@ def periodically(year, month, day, hour, minute, second, weekday, fade): # Flush settings to monitor. if len(monitors) == 0: - randr() + apply_curves() else: - randr(monitors[m % len(monitors)]) + apply_curves(monitors[m % len(monitors)]) # Lets wait only 5 seconds, instead of a minute before running again. wait_period = 5 @@ -372,9 +388,9 @@ def reset(): # Flush settings to monitor. if len(monitors) == 0: - randr() + apply_curves() else: - randr(monitors[m % len(monitors)]) + apply_curves(monitors[m % len(monitors)]) if (get_dayness is not None) and not doreset: diff --git a/examples/crtc-detection b/examples/crtc-detection index 2da0e9d..000dfce 100644 --- a/examples/crtc-detection +++ b/examples/crtc-detection @@ -7,8 +7,11 @@ # The colour temperature to apply. temp = 6500 +# Check if we are in X or TTY. +ttymode = not (('DISPLAY' in os.environ) and (':' in os.environ['DISPLAY'])) + # List all connected outputs. -outputs = list_screens().find_by_connected(True) +outputs = list_screens('drm' if ttymode else 'randr').find_by_connected(True) # EDID of the primary monitors edid_0 = '00ffffffffffff0010ac00504d5730372f0c01030e281e962b0cc9a057479b2712484ca44380a959a94f615971594559c28f31590101863d00c05100304040a013006c231100001e000000fd0030aa1e821d000a202020202020000000fc0044454c4c2050313133300a2020000000ff00364432353232424c3730574d0a00ea' @@ -29,8 +32,10 @@ for output in outputs: monitor_gamma = (1, 1, 1) # Get the correct gamma settings for the monitor. - if (monitor == ('DVI-0', 364, 291, False)) or (edid == edid_0): monitor_gamma = gammas[0] - elif (monitor == ('VGA-0', 364, 291, False)) or (edid == edid_1): monitor_gamma = gammas[1] + if (monitor == ('DVI-0', 364, 291, False)) or (edid == edid_0): monitor_gamma = gammas[0] # using RandR + elif (monitor == ('VGA-0', 364, 291, False)) or (edid == edid_1): monitor_gamma = gammas[1] # using RandR + elif (monitor == ('DVII-0', 400, 300, False)) or (edid == edid_0): monitor_gamma = gammas[0] # using DRM + elif (monitor == ('VGA-0', 400, 300, False)) or (edid == edid_1): monitor_gamma = gammas[1] # using DRM else: print('Warning: unknown monitor at %s at size of %i mm by %i mm' % monitor[:3]) @@ -40,5 +45,5 @@ for output in outputs: gamma(*monitor_gamma) # Apply adjustments. - randr(output.crtc, screen = output.screen) + (drm if ttymode else randr)(output.crtc, screen = output.screen) diff --git a/examples/crtc-searching b/examples/crtc-searching index c7be89f..0539f0e 100644 --- a/examples/crtc-searching +++ b/examples/crtc-searching @@ -7,6 +7,9 @@ # but `Screen.crtc_count` is much more effective. +# Check if we are in X or TTY. +ttymode = not (('DISPLAY' in os.environ) and (':' in os.environ['DISPLAY'])) + # We want to use the ad-hoc mode options. uses_adhoc_opts = True @@ -52,7 +55,7 @@ if parser.opts['--help'] is not None: # Find CRTC:s. -screens = list_screens() +screens = list_screens('drm' if ttymode else 'randr') outputs = [] # Find CRTC:s by name. @@ -79,5 +82,5 @@ for output in outputs: gamma(*gamma_) # Apply adjustments. - randr(output.crtc, screen = output.screen) + (drm if ttymode else randr)(output.crtc, screen = output.screen) diff --git a/src/monitor.py b/src/monitor.py index 3947435..f375156 100644 --- a/src/monitor.py +++ b/src/monitor.py @@ -20,11 +20,6 @@ from subprocess import Popen, PIPE from curve import * -try: - from blueshift_drm import * -except: - pass ## Not compiled with DRM support - # /usr/lib LIBDIR = 'bin' sys.path.append(LIBDIR) @@ -35,6 +30,11 @@ LIBEXECDIR = 'bin' randr_opened = None vidmode_opened = None +try: + from blueshift_drm import * +except: + pass ## Not compiled with DRM support + def translate_to_integers(): ''' @@ -129,15 +129,15 @@ def vidmode_get(crtc = 0, screen = 0): return ramps_to_function(*(vidmode_read(crtc))) -def drm_get(crtc = 0, card = 0): +def drm_get(crtc = 0, screen = 0): ''' Gets the current colour curves using DRM - @param crtc:int The CRTC of the monitor to read from - @param card:int The graphics card that the monitor belong to - @return :()→void Function to invoke to apply the curves that was used when this function was invoked + @param crtc:int The CRTC of the monitor to read from + @param screen:int The graphics card that the monitor belong to, named `screen` for compatibility with randr_get and vidmode_get + @return :()→void Function to invoke to apply the curves that was used when this function was invoked ''' - connection = drm_manager.open_card(card) + connection = drm_manager.open_card(screen) return ramps_to_function(*(drm_get_gamma_ramps(connection, crtc, i_size))) @@ -197,17 +197,20 @@ def vidmode(*crtcs, screen = 0): pass # Happens on exit by TERM signal -def drm(*crtcs, card = 0): +def drm(*crtcs, screen = 0): ''' Applies colour curves using DRM @param crtcs:*int The CRT controllers to use, all are used if none are specified - @param card:int The card that the monitors belong to + @param screen:int The card that the monitors belong to, named `screen` for compatibility with randr_get and vidmode_get ''' - connection = drm_manager.open_card(card) + connection = drm_manager.open_card(screen) (R_curve, G_curve, B_curve) = translate_to_integers() try: - drm_set_gamma_ramps(connection, list(crtcs), i_size, R_curve, G_curve, B_curve) + crtcs = list(crtcs) + if len(crtcs) == 0: + crtcs = list(range(drm_crtc_count(connection))) + drm_set_gamma_ramps(connection, crtcs, i_size, R_curve, G_curve, B_curve) except OverflowError: pass # Happens on exit by TERM signal @@ -582,7 +585,7 @@ class DRMManager: self.connectors = [None] * drm_card_count() if self.cards[card] == -1: self.cards[card] = drm_open_card(card) - drm_update_card(drm_open_card(self.cards[card])) + drm_update_card(self.cards[card]) return self.cards[card] def open_connector(self, card, connector): @@ -641,10 +644,10 @@ class DRMManager: if self.is_open: self.is_open = False if self.cards is not None: - for card in len(self.cards): + for card in range(len(self.cards)): self.close_card(card) self.cards = None - blueshift_drm_close() + drm_close() drm_manager = DRMManager() |