[gtk/wip/matthiasc/focus2: 4/4] color chooser: Prevent focus leaks
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/focus2: 4/4] color chooser: Prevent focus leaks
- Date: Sun, 3 Mar 2019 05:54:01 +0000 (UTC)
commit fed932e1d5f9985cfdc73a2b3bde27eafb2f3848
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Mar 3 00:50:51 2019 -0500
color chooser: Prevent focus leaks
The color chooser switches from the palette to
the editor by just showing and hiding. Use
child-focusable to ensure that focus does not
wander off into the hidden parts.
gtk/gtkcolorchooserwidget.c | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkcolorchooserwidget.c b/gtk/gtkcolorchooserwidget.c
index 9f2d286017..3d2ce5a71d 100644
--- a/gtk/gtkcolorchooserwidget.c
+++ b/gtk/gtkcolorchooserwidget.c
@@ -129,6 +129,22 @@ swatch_activate (GtkColorSwatch *swatch,
_gtk_color_chooser_color_activated (GTK_COLOR_CHOOSER (cc), &color);
}
+static void
+show_editor (GtkColorChooserWidget *cc,
+ gboolean show)
+{
+ gtk_widget_set_visible (cc->priv->palette, !show);
+ gtk_widget_set_visible (cc->priv->editor, show);
+ gtk_widget_set_child_focusable (cc->priv->palette, !show);
+ gtk_widget_set_child_focusable (cc->priv->editor, show);
+ if (show)
+ gtk_widget_child_focus (cc->priv->editor, GTK_DIR_TAB_FORWARD);
+ else
+ gtk_widget_child_focus (cc->priv->palette, GTK_DIR_TAB_FORWARD);
+
+ g_object_notify (G_OBJECT (cc), "show-editor");
+}
+
static void
swatch_customize (GtkColorSwatch *swatch,
GtkColorChooserWidget *cc)
@@ -138,9 +154,7 @@ swatch_customize (GtkColorSwatch *swatch,
gtk_color_swatch_get_rgba (swatch, &color);
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc->priv->editor), &color);
- gtk_widget_hide (cc->priv->palette);
- gtk_widget_show (cc->priv->editor);
- g_object_notify (G_OBJECT (cc), "show-editor");
+ show_editor (cc, TRUE);
}
static void
@@ -174,9 +188,7 @@ button_activate (GtkColorSwatch *swatch,
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc->priv->editor), &color);
- gtk_widget_hide (cc->priv->palette);
- gtk_widget_show (cc->priv->editor);
- g_object_notify (G_OBJECT (cc), "show-editor");
+ show_editor (cc, TRUE);
}
static void
@@ -260,9 +272,9 @@ gtk_color_chooser_widget_set_use_alpha (GtkColorChooserWidget *cc,
static void
gtk_color_chooser_widget_set_show_editor (GtkColorChooserWidget *cc,
- gboolean show_editor)
+ gboolean show)
{
- if (show_editor)
+ if (show)
{
GdkRGBA color = { 0.75, 0.25, 0.25, 1.0 };
@@ -271,8 +283,7 @@ gtk_color_chooser_widget_set_show_editor (GtkColorChooserWidget *cc,
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc->priv->editor), &color);
}
- gtk_widget_set_visible (cc->priv->editor, show_editor);
- gtk_widget_set_visible (cc->priv->palette, !show_editor);
+ show_editor (cc, show);
}
static void
@@ -592,6 +603,7 @@ gtk_color_chooser_widget_init (GtkColorChooserWidget *cc)
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (cc), &color);
gtk_widget_hide (GTK_WIDGET (cc->priv->editor));
+ gtk_widget_set_child_focusable (GTK_WIDGET (cc->priv->editor), FALSE);
cc->priv->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_size_group_add_widget (cc->priv->size_group, cc->priv->palette);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]