From fd7e51927d2c79d0288db4195c2000451d4e300b Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Tue, 13 Aug 2019 16:44:45 +0300 Subject: [PATCH] get_first_output: prefer primary output Used in two cases: - When the pointer location can't be found but some initial container needs to be focused - When moving disabled outputs --- src/randr.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/randr.c b/src/randr.c index fb127ab5..9a0bf5cc 100644 --- a/src/randr.c +++ b/src/randr.c @@ -70,11 +70,22 @@ Output *get_output_by_name(const char *name, const bool require_active) { * */ Output *get_first_output(void) { - Output *output; + Output *output, *result = NULL; - TAILQ_FOREACH(output, &outputs, outputs) - if (output->active) - return output; + TAILQ_FOREACH(output, &outputs, outputs) { + if (output->active) { + if (output->primary) { + return output; + } + if (!result) { + result = output; + } + } + } + + if (result) { + return result; + } die("No usable outputs available.\n"); }