From 63a9c89770f158fdd1296e7a5d8b60ba21abf3f0 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 24 May 2014 03:59:46 +0200 Subject: gamma-x-randr: get_output_name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/gamma-x-randr.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'src/gamma-x-randr.c') diff --git a/src/gamma-x-randr.c b/src/gamma-x-randr.c index a0e269f..88afd6b 100644 --- a/src/gamma-x-randr.c +++ b/src/gamma-x-randr.c @@ -458,6 +458,45 @@ static int get_connector_type(libgamma_crtc_information_t* restrict this) } +/** + * Get the output name of a CRTC + * + * @param this Instance of a data structure to fill with the information about the CRTC + * @param output The CRTC's output's information + * @return Non-zero on error + */ +static int get_output_name(libgamma_crtc_information_t* restrict out, xcb_randr_get_output_info_reply_t* restrict output) +{ + char* store; + uint8_t* name; + uint16_t length; + size_t i; + + name = xcb_randr_get_output_info_name(output); + length = output->name_len; /* There is no NUL-termination. */ + if (name == NULL) + { + out->connector_name_error = LIBGAMMA_REPLY_VALUE_EXTRACTION_FAILED; + return -1; + } + + store = malloc(((size_t)length + 1) * sizeof(char)); + if (store == NULL) + { + out->connector_name_error = errno; + return -1; + } + + /* char is guaranteed to be (u)int_least8_t, but it is only guaranteed to be (u)int8_t + * on POSIX, so to be truly portable we will not assume that char is (u)int8_t. */ + for (i = 0; i < (size_t)length; i++) + store[i] = (char)(name[i]); + store[length] = '\0'; + + return 0; +} + + /** * Read information about a CRTC * @@ -494,7 +533,7 @@ int libgamma_x_randr_get_crtc_information(libgamma_crtc_information_t* restrict /* FIXME output */ - e |= this->connector_name_error = -1; /* FIXME */ + e |= get_output_name(this, output); if ((fields & CRTC_INFO_CONNECTOR_TYPE)) e |= get_connector_type(this); e |= read_output_data(this, output); @@ -510,7 +549,7 @@ int libgamma_x_randr_get_crtc_information(libgamma_crtc_information_t* restrict = this->height_mm_edid_error = LIBGAMMA_NOT_CONNECTED; goto cont; } - e |= get_edid(output, this); /* FIXME */ + e |= get_edid(this, output); /* FIXME */ if (this->edid == NULL) { this->gamma_error = this->width_mm_edid_error = this->height_mm_edid_error = this->edid_error; -- cgit v1.2.3-70-g09d2