From 671efca852ff4aefe653579136ee9b43dbc88324 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 17 Jul 2016 16:42:49 +0200 Subject: Continue restructure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/crtc-server/server.c | 29 +++++++++++++++++++++++++++++ src/crtc-server/server.h | 13 ++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) (limited to 'src/crtc-server') diff --git a/src/crtc-server/server.c b/src/crtc-server/server.c index 6c16cee..6ce6560 100644 --- a/src/crtc-server/server.c +++ b/src/crtc-server/server.c @@ -57,3 +57,32 @@ int handle_enumerate_crtcs(size_t conn, const char* restrict message_id) return send_message(conn, buf, n); } + +/** + * Get the name of a CRTC + * + * @param info Information about the CRTC + * @param crtc libgamma's state for the CRTC + * @return The name of the CRTC, `NULL` on error + */ +char* get_crtc_name(const libgamma_crtc_information_t* restrict info, + const libgamma_crtc_state_t* restrict crtc) +{ + if ((info->edid_error == 0) && (info->edid != NULL)) + return libgamma_behex_edid(info->edid, info->edid_length); + else if ((info->connector_name_error == 0) && (info->connector_name != NULL)) + { + char* name = malloc(3 * sizeof(size_t) + strlen(info->connector_name) + 2); + if (name != NULL) + sprintf(name, "%zu.%s", crtc->partition->partition, info->connector_name); + return name; + } + else + { + char* name = malloc(2 * 3 * sizeof(size_t) + 2); + if (name != NULL) + sprintf(name, "%zu.%zu", crtc->partition->partition, crtc->crtc); + return name; + } +} + diff --git a/src/crtc-server/server.h b/src/crtc-server/server.h index ffe4f64..bc9ecf8 100644 --- a/src/crtc-server/server.h +++ b/src/crtc-server/server.h @@ -19,7 +19,7 @@ #define CRTC_SERVER_SERVER_H -#include +#include @@ -44,6 +44,17 @@ GCC_ONLY(__attribute__((nonnull))) int handle_enumerate_crtcs(size_t conn, const char* restrict message_id); +/** + * Get the name of a CRTC + * + * @param info Information about the CRTC + * @param crtc libgamma's state for the CRTC + * @return The name of the CRTC, `NULL` on error + */ +GCC_ONLY(__attribute__((nonnull))) +char* get_crtc_name(const libgamma_crtc_information_t* restrict info, + const libgamma_crtc_state_t* restrict crtc); + #endif -- cgit v1.2.3-70-g09d2