[libpanel] focus: pass focus request into desired children



commit a23f842b3aa9ea1d9957b386f41e9b07aa5998c4
Author: Christian Hergert <chergert redhat com>
Date:   Tue Sep 6 15:35:27 2022 -0700

    focus: pass focus request into desired children
    
    This just ensures that a grab focus on things like a dock child will end
    up on the right item within a frame/etc.

 src/panel-dock-child.c     |  8 ++++++++
 src/panel-frame-switcher.c | 15 +++++++++++++++
 src/panel-frame.c          | 13 +++++++++++++
 src/panel-paned.c          | 15 +++++++++++++++
 src/panel-resizer.c        | 12 ++++++++++++
 src/panel-widget.c         | 15 +++++++++++++++
 6 files changed, 78 insertions(+)
---
diff --git a/src/panel-dock-child.c b/src/panel-dock-child.c
index 8ae0317..26941ad 100644
--- a/src/panel-dock-child.c
+++ b/src/panel-dock-child.c
@@ -52,6 +52,12 @@ enum {
 
 static GParamSpec *properties [N_PROPS];
 
+static gboolean
+panel_dock_child_grab_focus (GtkWidget *widget)
+{
+  return gtk_widget_grab_focus (GTK_WIDGET (PANEL_DOCK_CHILD (widget)->resizer));
+}
+
 static void
 panel_dock_child_dispose (GObject *object)
 {
@@ -126,6 +132,8 @@ panel_dock_child_class_init (PanelDockChildClass *klass)
   object_class->get_property = panel_dock_child_get_property;
   object_class->set_property = panel_dock_child_set_property;
 
+  widget_class->grab_focus = panel_dock_child_grab_focus;
+
   properties [PROP_REVEAL_CHILD] =
     g_param_spec_boolean ("reveal-child",
                           "Reveal Child",
diff --git a/src/panel-frame-switcher.c b/src/panel-frame-switcher.c
index 05aa6e4..7714504 100644
--- a/src/panel-frame-switcher.c
+++ b/src/panel-frame-switcher.c
@@ -73,6 +73,20 @@ enum {
   PROP_ORIENTATION,
 };
 
+static gboolean
+panel_frame_switcher_grab_focus (GtkWidget *widget)
+{
+  for (GtkWidget *child = gtk_widget_get_first_child (widget);
+       child != NULL;
+       child = gtk_widget_get_next_sibling (child))
+    {
+      if (gtk_widget_grab_focus (child))
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
 static void
 ensure_indicator (PanelFrameSwitcher *self)
 {
@@ -868,6 +882,7 @@ panel_frame_switcher_class_init (PanelFrameSwitcherClass *class)
   object_class->dispose = panel_frame_switcher_dispose;
   object_class->finalize = panel_frame_switcher_finalize;
 
+  widget_class->grab_focus = panel_frame_switcher_grab_focus;
   widget_class->snapshot = panel_frame_switcher_snapshot;
   widget_class->css_changed = panel_frame_switcher_css_changed;
 
diff --git a/src/panel-frame.c b/src/panel-frame.c
index e35c530..2752012 100644
--- a/src/panel-frame.c
+++ b/src/panel-frame.c
@@ -548,6 +548,18 @@ panel_frame_compute_expand (GtkWidget *widget,
     }
 }
 
+static gboolean
+panel_frame_grab_focus (GtkWidget *widget)
+{
+  PanelFrame *self = PANEL_FRAME (widget);
+  PanelWidget *child = panel_frame_get_visible_child (self);
+
+  if (child != NULL)
+    return gtk_widget_grab_focus (GTK_WIDGET (child));
+
+  return FALSE;
+}
+
 static void
 panel_frame_dispose (GObject *object)
 {
@@ -653,6 +665,7 @@ panel_frame_class_init (PanelFrameClass *klass)
   object_class->get_property = panel_frame_get_property;
   object_class->set_property = panel_frame_set_property;
 
+  widget_class->grab_focus = panel_frame_grab_focus;
   widget_class->root = panel_frame_root;
   widget_class->unroot = panel_frame_unroot;
   widget_class->compute_expand = panel_frame_compute_expand;
diff --git a/src/panel-paned.c b/src/panel-paned.c
index 2aa3efa..8e05b08 100644
--- a/src/panel-paned.c
+++ b/src/panel-paned.c
@@ -311,6 +311,20 @@ panel_paned_size_allocate (GtkWidget *widget,
     }
 }
 
+static gboolean
+panel_paned_grab_focus (GtkWidget *widget)
+{
+  for (GtkWidget *child = gtk_widget_get_first_child (widget);
+       child != NULL;
+       child = gtk_widget_get_next_sibling (child))
+    {
+      if (gtk_widget_grab_focus (child))
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
 static void
 panel_paned_dispose (GObject *object)
 {
@@ -376,6 +390,7 @@ panel_paned_class_init (PanelPanedClass *klass)
   object_class->get_property = panel_paned_get_property;
   object_class->set_property = panel_paned_set_property;
 
+  widget_class->grab_focus = panel_paned_grab_focus;
   widget_class->measure = panel_paned_measure;
   widget_class->size_allocate = panel_paned_size_allocate;
 
diff --git a/src/panel-resizer.c b/src/panel-resizer.c
index 652d014..d13a958 100644
--- a/src/panel-resizer.c
+++ b/src/panel-resizer.c
@@ -345,6 +345,17 @@ panel_resizer_compute_expand (GtkWidget *widget,
     }
 }
 
+static gboolean
+panel_resizer_grab_focus (GtkWidget *widget)
+{
+  PanelResizer *self = PANEL_RESIZER (widget);
+
+  if (self->child != NULL)
+    return gtk_widget_grab_focus (self->child);
+
+  return FALSE;
+}
+
 static void
 panel_resizer_dispose (GObject *object)
 {
@@ -405,6 +416,7 @@ panel_resizer_class_init (PanelResizerClass *klass)
   object_class->set_property = panel_resizer_set_property;
 
   widget_class->compute_expand = panel_resizer_compute_expand;
+  widget_class->grab_focus = panel_resizer_grab_focus;
   widget_class->measure = panel_resizer_measure;
   widget_class->size_allocate = panel_resizer_size_allocate;
 
diff --git a/src/panel-widget.c b/src/panel-widget.c
index b4d4ef0..bcb3efc 100644
--- a/src/panel-widget.c
+++ b/src/panel-widget.c
@@ -293,6 +293,20 @@ panel_widget_size_allocate (GtkWidget *widget,
     gtk_widget_allocate (priv->child, width, height, baseline, NULL);
 }
 
+static gboolean
+panel_widget_grab_focus (GtkWidget *widget)
+{
+  for (GtkWidget *child = gtk_widget_get_first_child (widget);
+       child != NULL;
+       child = gtk_widget_get_next_sibling (child))
+    {
+      if (gtk_widget_grab_focus (child))
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
 static void
 panel_widget_constructed (GObject *object)
 {
@@ -466,6 +480,7 @@ panel_widget_class_init (PanelWidgetClass *klass)
   object_class->get_property = panel_widget_get_property;
   object_class->set_property = panel_widget_set_property;
 
+  widget_class->grab_focus = panel_widget_grab_focus;
   widget_class->measure = panel_widget_measure;
   widget_class->size_allocate = panel_widget_size_allocate;
 


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