From 33391f4246ee802392e55f0f61a35eecdde71048 Mon Sep 17 00:00:00 2001
From: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date: Wed, 26 Jun 2019 13:33:50 +0300
Subject: [PATCH] simple-policy: select by default the first non-loopback
 device

This is a bit of a hack, temporarily needed for AGL.
---
 modules/module-simple-policy.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/modules/module-simple-policy.c b/modules/module-simple-policy.c
index 9aa5bea7..768e3e72 100644
--- a/modules/module-simple-policy.c
+++ b/modules/module-simple-policy.c
@@ -164,6 +164,21 @@ simple_policy_endpoint_added (WpPolicy *policy, WpEndpoint *ep)
 
   if (!self->selected[direction]) {
     select_endpoint (self, direction, ep, control_id);
+  } else {
+    /* we already have a selected endpoint, but maybe this one is better... */
+    const gchar *new_name = wp_endpoint_get_name (ep);
+    const gchar *old_name = wp_endpoint_get_name (self->selected[direction]);
+
+    /* FIXME: this is a crude way of searching for properties;
+     * we should have an API here */
+    if ((strstr (new_name, "hw:0,0") && !strstr(new_name, "Loopback")) ||
+        (strstr (old_name, "Loopback") && strstr (new_name, "hw:1,0")))
+    {
+      wp_endpoint_set_control_value (self->selected[direction],
+          self->selected_ctl_id[direction],
+          g_variant_new_boolean (FALSE));
+      select_endpoint (self, direction, ep, control_id);
+    }
   }
 }
 
-- 
GitLab