[gtk/wip/matthiasc/popup: 23/63] root: Add a ::focus-widget property



commit 39c44b9d2e2016c8d8c2d559e373e6f2c3aa25f8
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Mar 3 01:34:32 2019 -0500

    root: Add a ::focus-widget property

 gtk/gtkroot.c        | 42 ++++++++++++++++++++++++++----------------
 gtk/gtkroot.h        |  4 ----
 gtk/gtkrootprivate.h |  8 ++++++++
 gtk/gtkwindow.c      | 28 +++++++++-------------------
 4 files changed, 43 insertions(+), 39 deletions(-)
---
diff --git a/gtk/gtkroot.c b/gtk/gtkroot.c
index 3552a85474..249d7405b1 100644
--- a/gtk/gtkroot.c
+++ b/gtk/gtkroot.c
@@ -21,6 +21,8 @@
 
 #include "gtkrootprivate.h"
 #include "gdk/gdk-private.h"
+#include "gtkprivate.h"
+#include "gtkintl.h"
 
 /**
  * SECTION:gtkroot
@@ -59,26 +61,19 @@ gtk_root_default_get_surface_transform (GtkRoot *self,
   *y = 0;
 }
 
-static void
-gtk_root_default_set_focus (GtkRoot   *self,
-                            GtkWidget *focus)
-{
-}
-
-static GtkWidget *
-gtk_root_default_get_focus (GtkRoot *self)
-{
-  return NULL;
-}
-
 static void
 gtk_root_default_init (GtkRootInterface *iface)
 {
   iface->get_display = gtk_root_default_get_display;
   iface->get_renderer = gtk_root_default_get_renderer;
   iface->get_surface_transform = gtk_root_default_get_surface_transform;
-  iface->set_focus = gtk_root_default_set_focus;
-  iface->get_focus = gtk_root_default_get_focus;
+
+  g_object_interface_install_property (iface,
+      g_param_spec_object ("focus-widget",
+                           P_("Focus widget"),
+                           P_("The focus widget"),
+                           GTK_TYPE_WIDGET,
+                           GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
 }
 
 GdkDisplay *
@@ -159,7 +154,7 @@ gtk_root_set_focus (GtkRoot   *self,
   g_return_if_fail (GTK_IS_ROOT (self));
   g_return_if_fail (focus == NULL || GTK_IS_WIDGET (focus));
 
-  GTK_ROOT_GET_IFACE (self)->set_focus (self, focus);
+  g_object_set (self, "focus-widget", focus, NULL);
 }
 
 /**
@@ -179,7 +174,22 @@ gtk_root_set_focus (GtkRoot   *self,
 GtkWidget *
 gtk_root_get_focus (GtkRoot *self)
 {
+  GtkWidget *focus;
+
   g_return_val_if_fail (GTK_IS_ROOT (self), NULL);
 
-  return GTK_ROOT_GET_IFACE (self)->get_focus (self);
+  g_object_get (self, "focus-widget", &focus, NULL);
+
+  if (focus)
+    g_object_unref (focus);
+
+  return focus;
+}
+
+guint
+gtk_root_install_properties (GObjectClass *object_class,
+                             guint         first_prop)
+{
+  g_object_class_override_property (object_class, first_prop + GTK_ROOT_PROP_FOCUS_WIDGET, "focus-widget");
+  return GTK_ROOT_NUM_PROPERTIES;
 }
diff --git a/gtk/gtkroot.h b/gtk/gtkroot.h
index fe4d980d2e..4c7ae89e37 100644
--- a/gtk/gtkroot.h
+++ b/gtk/gtkroot.h
@@ -51,10 +51,6 @@ struct _GtkRootInterface
   void                  (* get_surface_transform)       (GtkRoot                *root,
                                                          int                    *x,
                                                          int                    *y);
-
-  void                  (* set_focus)                   (GtkRoot                *self,
-                                                         GtkWidget              *focus);
-  GtkWidget *           (* get_focus)                   (GtkRoot                *self);
 };
 
 GDK_AVAILABLE_IN_ALL
diff --git a/gtk/gtkrootprivate.h b/gtk/gtkrootprivate.h
index 07ddc380e5..357bc6441f 100644
--- a/gtk/gtkrootprivate.h
+++ b/gtk/gtkrootprivate.h
@@ -11,6 +11,14 @@ GskRenderer *           gtk_root_get_renderer           (GtkRoot
 void                    gtk_root_get_surface_transform  (GtkRoot                *self,
                                                          int                    *x,
                                                          int                    *y);
+enum {
+  GTK_ROOT_PROP_FOCUS_WIDGET,
+  GTK_ROOT_NUM_PROPERTIES
+} GtkRootProperties;
+
+guint gtk_root_install_properties (GObjectClass *object_class,
+                                   guint         first_prop);
+
 G_END_DECLS
 
 #endif /* __GTK_ROOT_PRIVATE_H__ */
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index fa97dcf03e..a4d3bfd4ea 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -1134,6 +1134,7 @@ gtk_window_class_init (GtkWindowClass *klass)
                            GTK_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
 
   g_object_class_install_properties (gobject_class, LAST_ARG, window_props);
+  gtk_root_install_properties (gobject_class, LAST_ARG);
 
   /**
    * GtkWindow:set-focus:
@@ -2111,6 +2112,9 @@ gtk_window_set_property (GObject      *object,
     case PROP_FOCUS_VISIBLE:
       gtk_window_set_focus_visible (window, g_value_get_boolean (value));
       break;
+    case LAST_ARG + GTK_ROOT_PROP_FOCUS_WIDGET:
+      gtk_window_set_focus (window, g_value_get_object (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -2226,6 +2230,9 @@ gtk_window_get_property (GObject      *object,
     case PROP_IS_MAXIMIZED:
       g_value_set_boolean (value, gtk_window_is_maximized (window));
       break;
+    case LAST_ARG + GTK_ROOT_PROP_FOCUS_WIDGET:
+      g_value_set_object (value, gtk_window_get_focus (window));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -2549,31 +2556,12 @@ gtk_window_root_get_surface_transform (GtkRoot *root,
   *y = margin.top + border.top + padding.top;
 }
 
-static void
-gtk_window_root_set_focus (GtkRoot   *root,
-                           GtkWidget *focus)
-{
-  GtkWindow *self = GTK_WINDOW (root);
-
-  gtk_window_set_focus (self, focus);
-}
-
-static GtkWidget *
-gtk_window_root_get_focus (GtkRoot *root)
-{
-  GtkWindow *self = GTK_WINDOW (root);
-
-  return gtk_window_get_focus (self);
-}
-
 static void
 gtk_window_root_interface_init (GtkRootInterface *iface)
 {
   iface->get_display = gtk_window_root_get_display;
   iface->get_renderer = gtk_window_root_get_renderer;
   iface->get_surface_transform = gtk_window_root_get_surface_transform;
-  iface->set_focus = gtk_window_root_set_focus;
-  iface->get_focus = gtk_window_root_get_focus;
 }
 
 /**
@@ -7291,6 +7279,8 @@ gtk_window_real_set_focus (GtkWindow *window,
 
   unset_focus_widget (window);
   set_focus_widget (window, focus);
+
+  g_object_notify (G_OBJECT (window), "focus-widget");
 }
 
 static void


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