summaryrefslogtreecommitdiffstats
path: root/src/monitor.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-04-16 00:19:07 +0200
committerMattias Andrée <maandree@operamail.com>2014-04-16 00:19:07 +0200
commit3f20c503c63694b9cecb1ec8d5c558b9413bb689 (patch)
treee351f10bc45797a3f230012d87f68f3a0dbe9ce9 /src/monitor.py
parentupdate todo (diff)
downloadblueshift-3f20c503c63694b9cecb1ec8d5c558b9413bb689.tar.gz
blueshift-3f20c503c63694b9cecb1ec8d5c558b9413bb689.tar.bz2
blueshift-3f20c503c63694b9cecb1ec8d5c558b9413bb689.tar.xz
add python code for quartz
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/monitor.py65
1 files changed, 63 insertions, 2 deletions
diff --git a/src/monitor.py b/src/monitor.py
index 59051ad..93c6d93 100644
--- a/src/monitor.py
+++ b/src/monitor.py
@@ -52,6 +52,13 @@ except:
# Not compiled with W32 GDI support
pass
+## Load Quartz module
+try:
+ from blueshift_quartz import *
+except:
+ # Not compiled with Quartz support
+ pass
+
randr_opened = None
'''
@@ -68,12 +75,17 @@ w32gdi_opened = False
:bool Whether W32 GDI is in use
'''
+quartz_opened = False
+'''
+:bool Whether Quartz is in use
+'''
+
def close_c_bindings():
'''
Close all C bindings and let them free resources and close connections
'''
- global randr_opened, vidmode_opened, w32gdi_opened
+ global randr_opened, vidmode_opened, w32gdi_opened, quartz_opened
if randr_opened is not None:
# Close RandR connection if open
from blueshift_randr import randr_close
@@ -88,6 +100,10 @@ def close_c_bindings():
# Close W32 GDI connection if open
w32gdi_opened = False
w32gdi_close()
+ if quartz_opened:
+ # Close Quartz connection if open
+ quartz_opened = False
+ quartz_close()
# Close DRM connection if open
drm_manager.close()
@@ -176,6 +192,25 @@ def w32gdi_get(crtc = 0, screen = 0, display = None):
return ramps_to_function(*(w32gdi_read(crtc)))
+def quartz_get(crtc = 0, screen = 0, display = None):
+ '''
+ Gets the current colour curves using Quartz
+
+ @param crtc:int The CRTC of the monitor to read from
+ @param screen:int Dummy parameter for compatibility with `randr_get`, `vidmode_get` and `drm_get`
+ @param display:str? Dummy parameter 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
+ '''
+ global quartz_opened
+ # Open Quartz connection if necessary
+ if not quartz_opened:
+ quartz_opened = True
+ if (not quartz_open() == 0):
+ raise Exception("Could not open Quartz connection")
+ # Read current curves and create function
+ return ramps_to_function(*(quartz_read(crtc)))
+
+
def randr(*crtcs, screen = 0, display = None):
'''
Applies colour curves using the X11 extension RandR
@@ -264,7 +299,7 @@ def drm(*crtcs, screen = 0, display = None):
def w32gdi(*crtcs, screen = 0, display = None):
'''
- Applies colour curves using DRM
+ Applies colour curves using W32 GDI
@param crtcs:*int The CRT controllers to use, all are used if none are specified
@param screen:int Dummy parameter for compatibility with `randr`, `vidmode` and `drm`
@@ -288,6 +323,32 @@ def w32gdi(*crtcs, screen = 0, display = None):
pass # Happens on exit by TERM signal
+def quartz(*crtcs, screen = 0, display = None):
+ '''
+ Applies colour curves using Quartz
+
+ @param crtcs:*int The CRT controllers to use, all are used if none are specified
+ @param screen:int Dummy parameter for compatibility with `randr`, `vidmode` and `drm`
+ @param display:str? Dummy parameter for compatibility with `randr` and `vidmode`
+ '''
+ global quartz_opened
+ # Open Quartz connection if necessary
+ if not quartz_opened:
+ quartz_opened = True
+ if (not quartz_open() == 0):
+ raise Exception("Could not open Quartz connection")
+ # Convert curves to [0, 0xFFFF] integer lists
+ (R_curve, G_curve, B_curve) = translate_to_integers()
+ try:
+ # Select all CRTC:s if none have been selected
+ if len(crtcs) == 0:
+ crtcs = range(quartz_crtc_count())
+ # Apply adjustments
+ quartz_apply(list(crtcs), R_curve, G_curve, B_curve)
+ except OverflowError:
+ pass # Happens on exit by TERM signal
+
+
def print_curves(*crtcs, screen = 0, display = None, compact = False):
'''
Prints the curves to stdout