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 modify the title to indicate the error.

Unfortunately we don't currently get the reason in a way that we could
translate it. Ideally we would special case common error scenarios and
present the user with a better explanation or even correct the mistake.

See https://bugzilla.gnome.org/show_bug.cgi?id=790891 for the related
mutter bug.

https://bugzilla.gnome.org/show_bug.cgi?id=790792
This commit is contained in:
Benjamin Berg 2017-11-24 15:39:38 +01:00
parent d918b02c1f
commit adf5a42f01

View file

@ -87,6 +87,8 @@ struct _CcDisplayPanelPrivate
GtkWidget *main_titlebar;
GtkWidget *apply_titlebar;
GtkWidget *apply_titlebar_apply;
GtkWidget *apply_titlebar_warning;
};
typedef struct
@ -283,6 +285,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
@ -2590,47 +2594,59 @@ 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;
GtkSizeGroup *size_group;
if (priv->apply_titlebar)
return;
if (!priv->apply_titlebar)
{
GtkWidget *header, *button, *toplevel;
priv->apply_titlebar = header = gtk_header_bar_new ();
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);
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);
g_object_ref (priv->apply_titlebar_apply);
}
gtk_window_set_titlebar (GTK_WINDOW (toplevel), priv->apply_titlebar);
g_object_ref (priv->apply_titlebar);
if (is_applicable)
{
gtk_header_bar_set_title (GTK_HEADER_BAR (priv->apply_titlebar), _("Apply Changes?"));
gtk_header_bar_set_subtitle (GTK_HEADER_BAR (priv->apply_titlebar), NULL);
}
else
{
gtk_header_bar_set_title (GTK_HEADER_BAR (priv->apply_titlebar), _("Changes Cannot be Applied"));
gtk_header_bar_set_subtitle (GTK_HEADER_BAR (priv->apply_titlebar), _("This could be due to hardware limitations."));
}
gtk_widget_set_sensitive (priv->apply_titlebar_apply, is_applicable);
}
static void
@ -2640,12 +2656,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,
@ -2655,7 +2665,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