[gtk/new-style-menu: 37/48] popover bar: Implement focus
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/new-style-menu: 37/48] popover bar: Implement focus
- Date: Sun, 9 Jun 2019 17:46:06 +0000 (UTC)
commit 18fd512c8011858f6e260d61550a18888a41d1d3
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jun 9 02:23:47 2019 +0000
popover bar: Implement focus
This is the proper way to do focus.
We want to cycle around for left/right arrows.
gtk/gtkpopoverbar.c | 42 ++++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)
---
diff --git a/gtk/gtkpopoverbar.c b/gtk/gtkpopoverbar.c
index f702abf6e6..90e252015c 100644
--- a/gtk/gtkpopoverbar.c
+++ b/gtk/gtkpopoverbar.c
@@ -163,29 +163,35 @@ enter_cb (GtkEventController *controller,
}
static gboolean
-key_pressed_cb (GtkEventController *controller,
- guint keyval,
- guint keycode,
- GdkModifierType state,
- gpointer data)
+gtk_popover_bar_focus (GtkWidget *widget,
+ GtkDirectionType direction)
{
- GtkWidget *target;
- GtkPopoverBar *bar;
+ GtkPopoverBar *bar = GTK_POPOVER_BAR (widget);
GtkWidget *next;
+ if (bar->active_item &&
+ gtk_widget_get_mapped (GTK_WIDGET (bar->active_item->popover)))
+ {
+ if (gtk_widget_child_focus (GTK_WIDGET (bar->active_item->popover), direction))
+ return TRUE;
+ }
- target = gtk_event_controller_get_widget (controller);
-
- bar = GTK_POPOVER_BAR (gtk_widget_get_ancestor (target, GTK_TYPE_POPOVER_BAR));
-
- if (keyval == GDK_KEY_Left)
+ if (direction == GTK_DIR_LEFT)
{
- next = gtk_widget_get_prev_sibling (target);
+ if (bar->active_item)
+ next = gtk_widget_get_prev_sibling (GTK_WIDGET (bar->active_item));
+ else
+ next = NULL;
+
if (next == NULL)
next = gtk_widget_get_last_child (GTK_WIDGET (bar->box));
}
- else if (keyval == GDK_KEY_Right)
+ else if (direction == GTK_DIR_RIGHT)
{
- next = gtk_widget_get_next_sibling (target);
+ if (bar->active_item)
+ next = gtk_widget_get_next_sibling (GTK_WIDGET (bar->active_item));
+ else
+ next = NULL;
+
if (next == NULL)
next = gtk_widget_get_first_child (GTK_WIDGET (bar->box));
}
@@ -217,11 +223,6 @@ gtk_popover_bar_item_init (GtkPopoverBarItem *item)
gtk_event_controller_set_propagation_limit (controller, GTK_LIMIT_NONE);
g_signal_connect (controller, "enter", G_CALLBACK (enter_cb), NULL);
gtk_widget_add_controller (GTK_WIDGET (item), controller);
-
- controller = gtk_event_controller_key_new ();
- gtk_event_controller_set_propagation_limit (controller, GTK_LIMIT_NONE);
- g_signal_connect (controller, "key-pressed", G_CALLBACK (key_pressed_cb), NULL);
- gtk_widget_add_controller (GTK_WIDGET (item), controller);
}
static void
@@ -517,6 +518,7 @@ gtk_popover_bar_class_init (GtkPopoverBarClass *klass)
widget_class->measure = gtk_popover_bar_measure;
widget_class->size_allocate = gtk_popover_bar_size_allocate;
+ widget_class->focus = gtk_popover_bar_focus;
bar_props[PROP_MENU_MODEL] =
g_param_spec_object ("menu-model",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]