[gtk/wip/matthiasc/popup4: 8/57] root: Add an activate_focus api



commit 7793965590c1a748fbf8000b9e32587b53417854
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Mar 16 14:47:11 2019 -0400

    root: Add an activate_focus api
    
    This makes sense to parallel what GtkWindow has,
    and for key bindings.

 gtk/gtkroot.c | 23 +++++++++++++++++++++++
 gtk/gtkroot.h |  2 ++
 2 files changed, 25 insertions(+)
---
diff --git a/gtk/gtkroot.c b/gtk/gtkroot.c
index 2ce455b040..d5f287fc4d 100644
--- a/gtk/gtkroot.c
+++ b/gtk/gtkroot.c
@@ -201,6 +201,29 @@ gtk_root_get_focus (GtkRoot *self)
   return focus;
 }
 
+/**
+ * gtk_root_activate_focus:
+ * @self: a #GtkRoot
+ *
+ * Activates the current focused widget within the root.
+ *
+ * Returns: %TRUE if a widget got activated.
+ **/
+gboolean
+gtk_root_activate_focus (GtkRoot *self)
+{
+  GtkWidget *focus_widget;
+
+  g_return_val_if_fail (GTK_IS_ROOT (self), FALSE);
+
+  focus_widget = gtk_root_get_focus (self);
+
+  if (focus_widget && gtk_widget_is_sensitive (focus_widget))
+    return gtk_widget_activate (focus_widget);
+
+  return FALSE;
+}
+
 /**
  * gtk_root_set_default:
  * @self: a #GtkRoot
diff --git a/gtk/gtkroot.h b/gtk/gtkroot.h
index e4b0b96a71..a3935efff1 100644
--- a/gtk/gtkroot.h
+++ b/gtk/gtkroot.h
@@ -62,6 +62,8 @@ void        gtk_root_set_focus (GtkRoot   *self,
                                 GtkWidget *focus);
 GDK_AVAILABLE_IN_ALL
 GtkWidget * gtk_root_get_focus (GtkRoot   *self);
+GDK_AVAILABLE_IN_ALL
+gboolean    gtk_root_activate_focus (GtkRoot *self);
 
 GDK_AVAILABLE_IN_ALL
 void        gtk_root_set_default (GtkRoot   *self,


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