[gnome-control-center/nightlight-infobar-ui-tweaks: 31/32] display: Show Night Light Unavailable message when running on a VM




commit 6c10461b4510fdf17eaaf988ee8534d2be1c61be
Author: Felipe Borges <felipeborges gnome org>
Date:   Wed Aug 17 10:53:36 2022 +0200

    display: Show Night Light Unavailable message when running on a VM
    
    See #2020

 panels/display/cc-night-light-page.c  | 51 +++++++++++++++++++++++++++++++++++
 panels/display/cc-night-light-page.ui |  2 +-
 2 files changed, 52 insertions(+), 1 deletion(-)
---
diff --git a/panels/display/cc-night-light-page.c b/panels/display/cc-night-light-page.c
index 4b7b112fe..60c166703 100644
--- a/panels/display/cc-night-light-page.c
+++ b/panels/display/cc-night-light-page.c
@@ -40,6 +40,7 @@ struct _CcNightLightPage {
   GtkButton           *button_to_am;
   GtkButton           *button_to_pm;
   GtkWidget           *infobar_unsupported;
+  GtkWidget           *infobar_unsupported_description;
   GtkWidget           *infobar_disabled;
   GtkListBox          *listbox;
   GtkWidget           *scale_color_temperature;
@@ -125,6 +126,49 @@ dialog_adjustments_set_frac_hours (CcNightLightPage *self,
   gtk_stack_set_visible_child (stack, is_pm ? GTK_WIDGET (button_pm) : GTK_WIDGET (button_am));
 }
 
+static gboolean
+is_virtualized ()
+{
+  g_autoptr(GDBusConnection) connection = NULL;
+  g_autoptr(GError) error = NULL;
+  g_autoptr(GVariant) variant = NULL;
+  g_autoptr(GVariant) chassis_variant = NULL;
+  const gchar *chassis_type;
+
+  connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+  if (!connection)
+    {
+      g_warning ("System bus not available: %s", error->message);
+
+      return FALSE;
+    }
+
+  variant = g_dbus_connection_call_sync (connection,
+                                         "org.freedesktop.hostname1",
+                                         "/org/freedesktop/hostname1",
+                                         "org.freedesktop.DBus.Properties",
+                                         "Get",
+                                         g_variant_new ("(ss)",
+                                                        "org.freedesktop.hostname1",
+                                                        "Chassis"),
+                                         NULL,
+                                         G_DBUS_CALL_FLAGS_NONE,
+                                         -1,
+                                         NULL,
+                                         &error);
+  if (!variant)
+   {
+     g_warning ("Cannot get org.freedesktop.hostname1.Chassis: %s", error->message);
+
+     return FALSE;
+   }
+
+   g_variant_get (variant, "(v)", &chassis_variant);
+   chassis_type = g_variant_get_string (chassis_variant, NULL);
+
+   return (g_strcmp0 (chassis_type, "vm") == 0);
+}
+
 static void
 dialog_update_state (CcNightLightPage *self)
 {
@@ -218,6 +262,12 @@ dialog_update_state (CcNightLightPage *self)
       gtk_widget_set_visible (self->infobar_unsupported, TRUE);
       gtk_widget_set_visible (self->infobar_disabled, FALSE);
       gtk_widget_set_sensitive (self->night_light_settings, FALSE);
+
+      if (is_virtualized ())
+        {
+          gtk_label_set_text (GTK_LABEL (self->infobar_unsupported_description),
+                              _("Night Light cannot be used from a virtual machine."));
+        }
     }
 }
 
@@ -612,6 +662,7 @@ cc_night_light_page_class_init (CcNightLightPageClass *klass)
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_to_am);
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, button_to_pm);
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, infobar_unsupported);
+  gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, infobar_unsupported_description);
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, infobar_disabled);
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, listbox);
   gtk_widget_class_bind_template_child (widget_class, CcNightLightPage, night_light_toggle_switch);
diff --git a/panels/display/cc-night-light-page.ui b/panels/display/cc-night-light-page.ui
index e2548b4f1..b105c9493 100644
--- a/panels/display/cc-night-light-page.ui
+++ b/panels/display/cc-night-light-page.ui
@@ -29,7 +29,7 @@
                   </object>
                 </child>
                 <child>
-                  <object class="GtkLabel">
+                  <object class="GtkLabel" id="infobar_unsupported_description">
                     <property name="halign">start</property>
                     <property name="hexpand">False</property>
                     <property name="label" translatable="yes">This could be the result of the graphics 
driver being used, or the desktop being used remotely</property>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]