#!/usr/bin/env python3
# Copyright © 2014, 2015, 2016, 2017 Mattias Andrée (m@maandree.se)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
# This module is deprecated!
import sys
from aux import *
from curve import *
from output import EDID
cached_displays = {}
def get_gamma(crtc = 0, screen = 0, display = None, *, method = None):
'''
Gets the current colour curves
@param crtc:int The CRTC of the monitor to read from
@param screen:int The screen to which the monitors belong
@param display:str? The display to which to connect, `None` for current display
@param method:str? The adjustment method
@return :()→void Function to invoke to apply the curves that was used when this function was invoked
'''
import output
if not get_gamma.warned:
get_gamma.warned = True
print('get_gamma() is deprecated', file = sys.stderr)
if (method, display) not in cached_displays:
cached_displays[(method, display)] = output.get_outputs(method = method, display = display)
crtc = cached_displays[(method, display)].screens[screen].crtcs[crtc]
ramps = crtc.get_gamma()
return ramps_to_function(ramps.red, ramps.green, ramps.blue)
get_gamma.warned = False
def set_gamma(*crtcs, screen = 0, display = None, method = None):
'''
Applies colour curves
@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
@param display:str? The display to which to connect, `None` for current display
@param method:str? The adjustment method
'''
import output
if not set_gamma.warned:
set_gamma.warned = True
print('set_gamma() is deprecated', file = sys.stderr)
if (method, display) not in cached_displays:
cached_displays[(method, display)] = output.get_outputs(method = method, display = display)
screen = cached_displays[(method, display)].screens[screen]
ramps = output.Ramps(None, depth = -1, size = i_size)
ramps.red[:] = r_curve
ramps.green[:] = g_curve
ramps.blue[:] = b_curve
for crtc in range(len(screen.crtcs)) if len(crtcs) == 0 else crtcs:
crtc = screen.crtcs[crtc]
size = (crtc.red_gamma_size, crtc.green_gamma_size, crtc.blue_gamma_size)
crtc.set_gamma(ramps.copy(depth = crtc.gamma_depth, size = size))
set_gamma.warned = False
def randr_get(crtc = 0, screen = 0, display = None):
'''
Gets the current colour curves using the X11 extension RandR
@param crtc:int The CRTC of the monitor to read from
@param screen:int The screen to which the monitors belong
@param display:str? The display to which to connect, `None` for current display
@return :()→void Function to invoke to apply the curves that was used when this function was invoked
'''
if not randr_get.warned:
randr_get.warned = True
print('randr_get() is deprecated', file = sys.stderr)
return get_gamma(crtc, screen, display, method = 'randr')
randr_get.warned = False
def vidmode_get(crtc = 0, screen = 0, display = None):
'''
Gets the current colour curves using the X11 extension VidMode
@param crtc:int The CRTC of the monitor to read from, dummy parameter
@param screen:int The screen to which the monitors belong
@param display:str? The display to which to connect, `None` for current display
@return :()→void Function to invoke to apply the curves that was used when this function was invoked
'''
if not vidmode_get.warned:
vidmode_get.warned = True
print('vidmode_get() is deprecated', file = sys.stderr)
return get_gamma(crtc, screen, display, method = 'vidmode')
vidmode_get.warned = False
def drm_get(crtc = 0, screen = 0, display = None):
'''
Gets the current colour curves using DRM
@param crtc:int The CRTC of the monitor to read from
@param screen:int The graphics card to which the monitors belong, named `screen` for compatibility with `randr_get` and `vidmode_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
'''
if not drm_get.warned:
drm_get.warned = True
print('drm_get() is deprecated', file = sys.stderr)
return get_gamma(crtc, screen, display, method = 'drm')
drm_get.warned = False
def w32gdi_get(crtc = 0, screen = 0, display = None):
'''
Gets the current colour curves using W32 GDI
@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
'''
if not w32gdi_get.warned:
w32gdi_get.warned = True
print('w32gdi_get() is deprecated', file = sys.stderr)
return get_gamma(crtc, screen, display, method = 'w32gdi')
w32gdi_get.warned = False
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
'''
if not quartz_get.warned:
quartz_get.warned = True
print('quartz_get() is deprecated', file = sys.stderr)
return get_gamma(crtc, screen, display, method = 'quartz')
quartz_get.warned = False
def randr(*crtcs, screen = 0, display = None):
'''
Applies colour curves using the X11 extension RandR
@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
@param display:str? The display to which to connect, `None` for current display
'''
if not randr.warned:
randr.warned = True
print('randr() is deprecated', file = sys.stderr)
set_gamma(*crtcs, screen = screen, display = display, method = 'randr')
randr.warned = False
def vidmode(*crtcs, screen = 0, display = None):
'''
Applies colour curves using the X11 extension VidMode
@param crtcs:*int The CRT controllers to use, all are used if none are specified, dummy parameter
@param screen:int The screen to which the monitors belong
@param display:str? The display to which to connect, `None` for current display
'''
if not vidmode.warned:
vidmode.warned = True
print('vidmode() is deprecated', file = sys.stderr)
set_gamma(*crtcs, screen = screen, display = display, method = 'vidmode')
vidmode.warned = False
def drm(*crtcs, screen = 0, display = None):
'''
Applies colour curves using DRM
@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`
'''
if not drm.warned:
drm.warned = True
print('drm() is deprecated', file = sys.stderr)
set_gamma(*crtcs, screen = screen, display = display, method = 'drm')
drm.warned = False
def w32gdi(*crtcs, screen = 0, display = None):
'''
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`
@param display:str? Dummy parameter for compatibility with `randr` and `vidmode`
'''
if not w32gdi.warned:
w32gdi.warned = True
print('w32gdi() is deprecated', file = sys.stderr)
set_gamma(*crtcs, screen = screen, display = display, method = 'w32gdi')
w32gdi.warned = False
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`
'''
if not quartz.warned:
quartz.warned = True
print('quartz() is deprecated', file = sys.stderr)
set_gamma(*crtcs, screen = screen, display = display, method = 'quartz')
quartz.warned = False
def print_curves(*crtcs, screen = 0, display = None, compact = False):
'''
Prints the curves to stdout
@param crtcs:*int Dummy parameter
@param screen:int Dummy parameter
@param display:str? Dummy parameter
@param compact:bool Whether to print in compact form
'''
if not print_curves.warned:
print_curves.warned = True
print('print_curves() is deprecated', file = sys.stderr)
# Convert curves to [0, 0xFFFF] integer lists
(R_curve, G_curve, B_curve) = translate_to_integers()
if compact:
# Print each colour curve with run-length encoding
for curve in (R_curve, G_curve, B_curve):
# Print beginning
print('[', end = '')
last, count = None, 0
for i in range(i_size):
if curve[i] == last:
# Count repetition
count += 1
else:
# Print value
if last is not None:
print('%i {%i}, ' % (last, count), end = '')
# Store new value
last = curve[i]
# Restart counter
count = 1
# Print last value and ending
print('%i {%i}]' % (last, count))
else:
# Print the red colour curve
print(R_curve)
# Print the green colour curve
print(G_curve)
# Print the blue colour curve
print(B_curve)
print_curves.warned = False
class Screens:
'''
Information about all screens
'''
def __init__(self):
'''
Constructor
'''
self.screens = None
def __find(self, f):
'''
Find monitors in each screen
@param f:(Screen)→list