From b51821368c23ee017317ae9fe16e797662e1a1ba Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 3 Apr 2014 01:06:47 +0200 Subject: add multi-display support when listing moditors and getting icc profile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blueshift_iccprofile.c | 12 +++++++----- src/blueshift_idcrtc.c | 12 +++++++----- src/icc.py | 14 ++++++++++---- src/monitor.py | 22 ++++++++++++++-------- 4 files changed, 38 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/blueshift_iccprofile.c b/src/blueshift_iccprofile.c index fb2aa7b..b96e682 100644 --- a/src/blueshift_iccprofile.c +++ b/src/blueshift_iccprofile.c @@ -45,14 +45,12 @@ static xcb_generic_error_t* error; */ int main(int argc, char** argv) { + char* display = NULL; xcb_screen_iterator_t iter; int screen_count; xcb_screen_t* screens; int screen_i; - (void) argc; - (void) argv; - /* To get all ICC profiles, which are binary encoded, we have to connect to the display and for each screen look for @@ -71,8 +69,12 @@ int main(int argc, char** argv) /* This acquires a connection to the X display indicated by the DISPLAY - environ variable. */ - connection = xcb_connect(NULL, NULL); + environ variable, or as indicated + by the first command line argument + if existent. */ + if (argc > 1) + display = *(argv + 1); + connection = xcb_connect(display, NULL); /* Get screen information */ diff --git a/src/blueshift_idcrtc.c b/src/blueshift_idcrtc.c index 67ead56..c1f73b6 100644 --- a/src/blueshift_idcrtc.c +++ b/src/blueshift_idcrtc.c @@ -58,6 +58,7 @@ static xcb_generic_error_t* error; */ int main(int argc, char** argv) { + char* display = NULL; xcb_randr_query_version_cookie_t version_cookie; xcb_randr_query_version_reply_t* randr_version; xcb_screen_iterator_t iter; @@ -66,16 +67,17 @@ int main(int argc, char** argv) int screen_i; int i; - (void) argc; - (void) argv; - /* Get X connection */ /* This acquires a connection to the X display indicated by the DISPLAY - environ variable. */ - connection = xcb_connect(NULL, NULL); + environ variable, or as indicated + by the first command line argument + if existent. */ + if (argc > 1) + display = *(argv + 1); + connection = xcb_connect(display, NULL); /* Check RandR protocol version */ diff --git a/src/icc.py b/src/icc.py index 507c347..685c722 100644 --- a/src/icc.py +++ b/src/icc.py @@ -42,23 +42,29 @@ def load_icc(pathname): return parse_icc(file.read()) -def get_current_icc(): +def get_current_icc(display = None): ''' Get all currently applied ICC profiles as profile applying functions + @param display:str? The display to use, `None` for the current one @return list<(screen:int, monitor:int, profile:()→void)> List of used profiles ''' - return [(screen, monitor, parse_icc(profile)) for screen, monitor, profile in get_current_icc_raw()] + return [(screen, monitor, parse_icc(profile)) for screen, monitor, profile in get_current_icc_raw(display)] -def get_current_icc_raw(): +def get_current_icc_raw(display = None): ''' Get all currently applied ICC profiles as raw profile data + @param display:str? The display to use, `None` for the current one @return list<(screen:int, monitor:int, profile:bytes())> List of used profiles ''' + # Generate command line arguments to execute + command = [LIBEXECDIR + os.sep + 'blueshift_iccprofile'] + if display is not None: + command.append(display) # Spawn the libexec blueshift_iccprofile - process = Popen([LIBEXECDIR + os.sep + 'blueshift_iccprofile'], stdout = PIPE) + process = Popen(command, stdout = PIPE) # Wait for the child process to exit and gather its output to stdout lines = process.communicate()[0].decode('utf-8', 'error').split('\n') # Ensure the tha process has exited diff --git a/src/monitor.py b/src/monitor.py index 36f9235..d115d40 100644 --- a/src/monitor.py +++ b/src/monitor.py @@ -500,27 +500,33 @@ class Output: return '[Name: %s, Connected: %s, Width: %s, Height: %s, CRTC: %s, Screen: %s, EDID: %s]' % rc -def list_screens(method = 'randr'): +def list_screens(method = 'randr', display = None): ''' Retrieve informantion about all screens, outputs and CRTC:s - @param method:str The listing method: 'randr' for RandR (under X), + @param method:str The listing method: 'randr' for RandR (under X), 'drm' for DRM (under TTY) - @return :Screens An instance of a datastructure with the relevant information + @param display:str? The display to use, `None` for the current one + @return :Screens An instance of a datastructure with the relevant information ''' - if method == 'randr': return list_screens_randr() + if method == 'randr': return list_screens_randr(display = display) if method == 'drm': return list_screens_drm() raise Exception('Invalid method: %s' % method) -def list_screens_randr(): +def list_screens_randr(display = None): ''' Retrieve informantion about all screens, outputs and CRTC:s, using RandR - @return :Screens An instance of a datastructure with the relevant information + @param display:str? The display to use, `None` for the current one + @return :Screens An instance of a datastructure with the relevant information ''' - # Spawn the executeable library blueshift_idcrtc - process = Popen([LIBEXECDIR + os.sep + 'blueshift_idcrtc'], stdout = PIPE) + # Generate command line arguments to execute + command = [LIBEXECDIR + os.sep + 'blueshift_idcrtc'] + if display is not None: + command.append(display) + # Spawn the executable library blueshift_idcrtc + process = Popen(command, stdout = PIPE) # Wait for the child process to exit and gather its output to stdout lines = process.communicate()[0].decode('utf-8', 'error').split('\n') # Ensure that the child process has exited -- cgit v1.2.3-70-g09d2