From 547570439aa623b2f46197c3362e65f0af93dec1 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Mon, 9 Apr 2018 21:18:37 +0900 Subject: [PATCH] display: find the correct output To find a primary output, we have to check the connection status first. If there is no connected output, this function will return the first output. Change-Id: If386dcabc6524ce81a1f08c87082342a259278f3 --- src/tdm_display.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/tdm_display.c b/src/tdm_display.c index 9f66167..45ccdf2 100644 --- a/src/tdm_display.c +++ b/src/tdm_display.c @@ -634,18 +634,50 @@ tdm_display_find_output(tdm_display *dpy, const char *name, tdm_error *error) { tdm_private_module *private_module = NULL; tdm_private_output *private_output = NULL; + tdm_private_output *mode_setted_output = NULL; + tdm_private_output *connected_output = NULL; + unsigned int find_primary = 0; DISPLAY_FUNC_ENTRY_ERROR(); - if (!strncasecmp(name, "primary", 7) || !strncasecmp(name, "default", 7)) { - return tdm_display_get_output(dpy, 0, error); - } + if (!strncasecmp(name, "primary", 7) || !strncasecmp(name, "default", 7)) + find_primary = 1; _pthread_mutex_lock(&private_display->lock); if (error) *error = TDM_ERROR_NONE; + if (find_primary) { + LIST_FOR_EACH_ENTRY(private_module, &private_display->module_list, link) { + LIST_FOR_EACH_ENTRY(private_output, &private_module->output_list, link) { + if (private_output->caps.status == TDM_OUTPUT_CONN_STATUS_CONNECTED && !connected_output) + connected_output = private_output; + else if (private_output->caps.status == TDM_OUTPUT_CONN_STATUS_MODE_SETTED && !mode_setted_output) + mode_setted_output = private_output; + } + } + + if (mode_setted_output) { + _pthread_mutex_unlock(&private_display->lock); + return mode_setted_output; + } + + if (connected_output) { + _pthread_mutex_unlock(&private_display->lock); + return connected_output; + } + + LIST_FOR_EACH_ENTRY(private_module, &private_display->module_list, link) { + LIST_FOR_EACH_ENTRY(private_output, &private_module->output_list, link) { + if (private_output->index == 0) { + _pthread_mutex_unlock(&private_display->lock); + return private_output; + } + } + } + } + LIST_FOR_EACH_ENTRY(private_module, &private_display->module_list, link) { LIST_FOR_EACH_ENTRY(private_output, &private_module->output_list, link) { if (strncmp(private_output->caps.model, name, TDM_NAME_LEN)) -- 2.7.4