[gnome-control-center/wip/benzea/display: 1/7] display: Show insensitive apply button for invalid configurations



commit b63d2be72f32c097b75ec98d0932749d71c5a8ac
Author: Benjamin Berg <bberg redhat com>
Date:   Fri Nov 24 15:39:38 2017 +0100

    display: Show insensitive apply button for invalid configurations
    
    When the user creates temporary invalid configurations the dialog used
    to hide the apply button as if no change had been done so far. Change
    this to show the normal "Apply"/"Cancel" titlebar but make the "Apply"
    button insensitive and add a symbolic warning icon with an explanation.
    
    Unfortunately we don't see to get the reason in a way that we could
    translate it, so the explanation is static suggestion some possible
    reasons (monitors not adjacent/overlaping and hardware limitations).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=790792

 panels/display/cc-display-panel.c |   87 ++++++++++++++++++++----------------
 1 files changed, 48 insertions(+), 39 deletions(-)
---
diff --git a/panels/display/cc-display-panel.c b/panels/display/cc-display-panel.c
index 256fc86..97619cb 100644
--- a/panels/display/cc-display-panel.c
+++ b/panels/display/cc-display-panel.c
@@ -87,6 +87,8 @@ struct _CcDisplayPanelPrivate
 
   GtkWidget *main_titlebar;
   GtkWidget *apply_titlebar;
+  GtkWidget *apply_titlebar_apply;
+  GtkWidget *apply_titlebar_warning;
 };
 
 typedef struct
@@ -280,6 +282,8 @@ reset_titlebar (CcDisplayPanel *self)
     }
 
   g_clear_object (&priv->apply_titlebar);
+  g_clear_object (&priv->apply_titlebar_apply);
+  g_clear_object (&priv->apply_titlebar_warning);
 }
 
 static void
@@ -2577,47 +2581,58 @@ on_toplevel_key_press (GtkWidget   *button,
 }
 
 static void
-show_apply_titlebar (CcDisplayPanel *panel)
+show_apply_titlebar (CcDisplayPanel *panel, gboolean is_applicable)
 {
   CcDisplayPanelPrivate *priv = panel->priv;
-  GtkWidget *header, *button, *toplevel;
+  GtkWidget *header, *button, *toplevel, *icon;
   GtkSizeGroup *size_group;
 
-  if (priv->apply_titlebar)
-    return;
+  if (!priv->apply_titlebar)
+    {
+      priv->apply_titlebar = header = gtk_header_bar_new ();
+      gtk_header_bar_set_title (GTK_HEADER_BAR (header), _("Apply Changes?"));
 
-  priv->apply_titlebar = header = gtk_header_bar_new ();
-  gtk_header_bar_set_title (GTK_HEADER_BAR (header), _("Apply Changes?"));
+      size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
 
-  size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
+      button = gtk_button_new_with_mnemonic (_("_Cancel"));
+      gtk_header_bar_pack_start (GTK_HEADER_BAR (header), button);
+      gtk_size_group_add_widget (size_group, button);
+      g_signal_connect_object (button, "clicked", G_CALLBACK (on_screen_changed),
+                               panel, G_CONNECT_SWAPPED);
 
-  button = gtk_button_new_with_mnemonic (_("_Cancel"));
-  gtk_header_bar_pack_start (GTK_HEADER_BAR (header), button);
-  gtk_size_group_add_widget (size_group, button);
-  g_signal_connect_object (button, "clicked", G_CALLBACK (on_screen_changed),
-                           panel, G_CONNECT_SWAPPED);
+      toplevel = cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (panel)));
+      g_signal_connect_object (toplevel, "key-press-event", G_CALLBACK (on_toplevel_key_press),
+                               button, G_CONNECT_SWAPPED);
 
-  toplevel = cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (panel)));
-  g_signal_connect_object (toplevel, "key-press-event", G_CALLBACK (on_toplevel_key_press),
-                           button, G_CONNECT_SWAPPED);
+      priv->apply_titlebar_apply = button = gtk_button_new_with_mnemonic (_("_Apply"));
+      gtk_header_bar_pack_end (GTK_HEADER_BAR (header), button);
+      gtk_size_group_add_widget (size_group, button);
+      g_signal_connect_object (button, "clicked", G_CALLBACK (apply_current_configuration),
+                               panel, G_CONNECT_SWAPPED);
+      gtk_style_context_add_class (gtk_widget_get_style_context (button),
+                                   GTK_STYLE_CLASS_SUGGESTED_ACTION);
 
-  button = gtk_button_new_with_mnemonic (_("_Apply"));
-  gtk_header_bar_pack_end (GTK_HEADER_BAR (header), button);
-  gtk_size_group_add_widget (size_group, button);
-  g_signal_connect_object (button, "clicked", G_CALLBACK (apply_current_configuration),
-                           panel, G_CONNECT_SWAPPED);
-  gtk_style_context_add_class (gtk_widget_get_style_context (button),
-                               GTK_STYLE_CLASS_SUGGESTED_ACTION);
+      priv->apply_titlebar_warning = icon = gtk_image_new_from_icon_name ("dialog-warning-symbolic", 
GTK_ICON_SIZE_BUTTON);
+      gtk_widget_set_tooltip_text (icon, _("The current display configuration is invalid and cannot be 
applied.\nThe most likely reason is that the monitors either overlap or are not adjacent to each other. Other 
reasons may include hardware limitations."));
+      gtk_header_bar_pack_end (GTK_HEADER_BAR (header), icon);
+      gtk_style_context_add_class (gtk_widget_get_style_context (icon),
+                                   GTK_STYLE_CLASS_WARNING);
 
-  gtk_widget_show_all (header);
-  g_object_unref (size_group);
+      gtk_widget_show_all (header);
+      g_object_unref (size_group);
 
-  header = gtk_window_get_titlebar (GTK_WINDOW (toplevel));
-  if (header)
-    priv->main_titlebar = g_object_ref (header);
+      header = gtk_window_get_titlebar (GTK_WINDOW (toplevel));
+      if (header)
+        priv->main_titlebar = g_object_ref (header);
 
-  gtk_window_set_titlebar (GTK_WINDOW (toplevel), priv->apply_titlebar);
-  g_object_ref (priv->apply_titlebar);
+      gtk_window_set_titlebar (GTK_WINDOW (toplevel), priv->apply_titlebar);
+      g_object_ref (priv->apply_titlebar);
+      g_object_ref (priv->apply_titlebar_apply);
+      g_object_ref (priv->apply_titlebar_warning);
+    }
+
+  gtk_widget_set_sensitive (priv->apply_titlebar_apply, is_applicable);
+  gtk_widget_set_visible (priv->apply_titlebar_warning, !is_applicable);
 }
 
 static void
@@ -2627,12 +2642,6 @@ update_apply_button (CcDisplayPanel *panel)
   gboolean config_equal;
   CcDisplayConfig *applied_config;
 
-  if (!cc_display_config_is_applicable (priv->current_config))
-    {
-      reset_titlebar (panel);
-      return;
-    }
-
   applied_config = cc_display_config_manager_get_current (priv->manager);
 
   config_equal = cc_display_config_equal (priv->current_config,
@@ -2642,7 +2651,7 @@ update_apply_button (CcDisplayPanel *panel)
   if (config_equal)
     reset_titlebar (panel);
   else
-    show_apply_titlebar (panel);
+    show_apply_titlebar (panel, cc_display_config_is_applicable (priv->current_config));
 }
 
 static void


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