[gtk+/wip/carlosg/event-delivery: 4/24] gtk: Introduce GtkPointerFocus



commit 7dc1f128619e4c8e4a4ab8be577fa76b8a6f935a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Mar 31 17:22:00 2017 +0200

    gtk: Introduce GtkPointerFocus
    
    These objects (tied to a toplevel) track the focus of a pointer/touchpoint.
    The info in these basically consists of current toplevel coordinates and the
    current target widget.

 gtk/Makefile.am              |    2 +
 gtk/gtkpointerfocus.c        |   98 ++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkpointerfocusprivate.h |   52 ++++++++++++++++++++++
 3 files changed, 152 insertions(+), 0 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index e0124e5..5c9c933 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -513,6 +513,7 @@ gtk_private_h_sources =             \
        gtkplacessidebarprivate.h       \
        gtkplacesviewprivate.h  \
        gtkplacesviewrowprivate.h       \
+       gtkpointerfocusprivate.h        \
        gtkpopoverprivate.h     \
        gtkprintoperation-private.h \
        gtkprintutils.h         \
@@ -830,6 +831,7 @@ gtk_base_c_sources =                \
        gtkprivatetypebuiltins.c \
        gtkprogressbar.c        \
        gtkprogresstracker.c    \
+       gtkpointerfocus.c       \
        gtkpopover.c            \
        gtkpopovermenu.c        \
        gtkradiobutton.c        \
diff --git a/gtk/gtkpointerfocus.c b/gtk/gtkpointerfocus.c
new file mode 100644
index 0000000..7c522a0
--- /dev/null
+++ b/gtk/gtkpointerfocus.c
@@ -0,0 +1,98 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2017 - Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gtkpointerfocusprivate.h"
+#include "gtkprivate.h"
+
+static void
+target_destroyed (gpointer  data,
+                  GObject  *object_location)
+{
+  GtkPointerFocus *focus = data;
+
+  focus->target = NULL;
+  gtk_pointer_focus_repick_target (focus);
+}
+
+GtkPointerFocus *
+gtk_pointer_focus_new (GtkWindow        *toplevel,
+                       GtkWidget        *widget,
+                       GdkDevice        *device,
+                       GdkEventSequence *sequence,
+                       gdouble           x,
+                       gdouble           y)
+{
+  GtkPointerFocus *focus;
+
+  focus = g_new0 (GtkPointerFocus, 1);
+  focus->toplevel = toplevel;
+  focus->device = device;
+  focus->sequence = sequence;
+  gtk_pointer_focus_set_target (focus, widget);
+  gtk_pointer_focus_set_coordinates (focus, x, y);
+
+  return focus;
+}
+
+void
+gtk_pointer_focus_free (GtkPointerFocus *focus)
+{
+  gtk_pointer_focus_set_target (focus, NULL);
+  gtk_pointer_focus_set_implicit_grab (focus, NULL);
+  g_free (focus);
+}
+
+void
+gtk_pointer_focus_set_target (GtkPointerFocus *focus,
+                              GtkWidget       *target)
+{
+  if (focus->target == target)
+    return;
+
+  if (focus->target)
+    g_object_weak_unref (G_OBJECT (focus->target), target_destroyed, focus);
+
+  focus->target = target;
+
+  if (focus->target)
+    g_object_weak_ref (G_OBJECT (focus->target), target_destroyed, focus);
+}
+
+GtkWidget *
+gtk_pointer_focus_get_target (GtkPointerFocus *focus)
+{
+  return focus->target;
+}
+
+void
+gtk_pointer_focus_set_coordinates (GtkPointerFocus *focus,
+                                   gdouble          x,
+                                   gdouble          y)
+{
+  focus->x = x;
+  focus->y = y;
+}
+
+void
+gtk_pointer_focus_repick_target (GtkPointerFocus *focus)
+{
+  GtkWidget *target;
+
+  target = _gtk_toplevel_pick (focus->toplevel, focus->x, focus->y,
+                               NULL, NULL);
+  gtk_pointer_focus_set_target (focus, target);
+}
diff --git a/gtk/gtkpointerfocusprivate.h b/gtk/gtkpointerfocusprivate.h
new file mode 100644
index 0000000..56735d8
--- /dev/null
+++ b/gtk/gtkpointerfocusprivate.h
@@ -0,0 +1,52 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2017 - Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _GTK_POINTER_FOCUS_PRIVATE_H_
+#define _GTK_POINTER_FOCUS_PRIVATE_H_
+
+#include <gtk/gtk.h>
+
+typedef struct _GtkPointerFocus GtkPointerFocus;
+
+struct _GtkPointerFocus
+{
+  GdkDevice *device;
+  GdkEventSequence *sequence;
+  GtkWindow *toplevel;
+  GtkWidget *target; /* Unaffected by the implicit grab */
+  GtkWidget *grab_widget;
+  gdouble x, y; /* In toplevel coordinates */
+};
+
+GtkPointerFocus * gtk_pointer_focus_new  (GtkWindow        *toplevel,
+                                          GtkWidget        *widget,
+                                          GdkDevice        *device,
+                                          GdkEventSequence *sequence,
+                                          gdouble           x,
+                                          gdouble           y);
+void              gtk_pointer_focus_free (GtkPointerFocus *focus);
+
+void              gtk_pointer_focus_set_coordinates (GtkPointerFocus *focus,
+                                                     gdouble          x,
+                                                     gdouble          y);
+void              gtk_pointer_focus_set_target      (GtkPointerFocus *focus,
+                                                     GtkWidget       *target);
+GtkWidget *       gtk_pointer_focus_get_target      (GtkPointerFocus *focus);
+
+void              gtk_pointer_focus_repick_target (GtkPointerFocus *focus);
+
+#endif /* _GTK_POINTER_FOCUS_PRIVATE_H_ */


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