summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2014-06-04 06:18:03 -0400
committerMatthias Clasen <mclasen@redhat.com>2014-06-04 06:24:05 -0400
commit872fbfacd3315f4e28849b8852bc5678f63a791e (patch)
treee4a31499be74a2ab03f34b168aaaeb608274b43a
parentd467850af069cdbc7f0659399deed609c373b31b (diff)
downloadgtk+-872fbfacd3315f4e28849b8852bc5678f63a791e.tar.gz
Split GtkWindowGroup into its own file
gtkwindow.c is too big and too messy. This is a small step towards making it better.
-rw-r--r--gtk/Makefile.am4
-rw-r--r--gtk/gtk.h1
-rw-r--r--gtk/gtkentrycompletion.c1
-rw-r--r--gtk/gtkfilechooserwidget.c1
-rw-r--r--gtk/gtkmain.c1
-rw-r--r--gtk/gtkprintoperation.c1
-rw-r--r--gtk/gtkrecentchooserdefault.c1
-rw-r--r--gtk/gtkwindow.c369
-rw-r--r--gtk/gtkwindow.h47
-rw-r--r--gtk/gtkwindowgroup.c396
-rw-r--r--gtk/gtkwindowgroup.h89
-rw-r--r--gtk/gtkwindowprivate.h7
12 files changed, 507 insertions, 411 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 45086bbd3a..b696816fb1 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -471,7 +471,8 @@ gtk_public_h_sources = \
gtkvolumebutton.h \
gtkwidget.h \
gtkwidgetpath.h \
- gtkwindow.h
+ gtkwindow.h \
+ gtkwindowgroup.h
if OS_UNIX
gtk_unix_print_public_h_sources = \
@@ -1075,6 +1076,7 @@ gtk_base_c_sources = \
gtkwidget.c \
gtkwidgetpath.c \
gtkwindow.c \
+ gtkwindowgroup.c \
gtkwin32theme.c \
$(gtk_clipboard_dnd_c_sources)
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 5eb0aeefb6..a6ec45fdae 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -229,6 +229,7 @@
#include <gtk/gtkwidget.h>
#include <gtk/gtkwidgetpath.h>
#include <gtk/gtkwindow.h>
+#include <gtk/gtkwindowgroup.h>
#ifndef GTK_DISABLE_DEPRECATED
#include <gtk/deprecated/gtkarrow.h>
diff --git a/gtk/gtkentrycompletion.c b/gtk/gtkentrycompletion.c
index 7151080651..ff6ceba4d2 100644
--- a/gtk/gtkentrycompletion.c
+++ b/gtk/gtkentrycompletion.c
@@ -79,6 +79,7 @@
#include "gtksizerequest.h"
#include "gtkbox.h"
#include "gtkwindow.h"
+#include "gtkwindowgroup.h"
#include "gtkentry.h"
#include "gtkmain.h"
#include "gtkmarshalers.h"
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index bbb0e43bd2..0a229970ad 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -76,6 +76,7 @@
#include "gtktreeselection.h"
#include "gtkbox.h"
#include "gtkorientable.h"
+#include "gtkwindowgroup.h"
#include "gtkintl.h"
#include <cairo-gobject.h>
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index 78692357bb..18d8130ae4 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -127,6 +127,7 @@
#include "gtkversion.h"
#include "gtkwidgetprivate.h"
#include "gtkwindowprivate.h"
+#include "gtkwindowgroup.h"
#include "a11y/gtkaccessibility.h"
diff --git a/gtk/gtkprintoperation.c b/gtk/gtkprintoperation.c
index a7aa2d7802..e2a8e5ef22 100644
--- a/gtk/gtkprintoperation.c
+++ b/gtk/gtkprintoperation.c
@@ -30,6 +30,7 @@
#include "gtkintl.h"
#include "gtkprivate.h"
#include "gtkmessagedialog.h"
+#include "gtkwindowgroup.h"
#include "gtktypebuiltins.h"
/**
diff --git a/gtk/gtkrecentchooserdefault.c b/gtk/gtkrecentchooserdefault.c
index 61f04ab4a2..d8fb378f6f 100644
--- a/gtk/gtkrecentchooserdefault.c
+++ b/gtk/gtkrecentchooserdefault.c
@@ -60,6 +60,7 @@
#include "gtktooltip.h"
#include "gtktypebuiltins.h"
#include "gtkorientable.h"
+#include "gtkwindowgroup.h"
#include "deprecated/gtkactivatable.h"
#include "gtkrecentmanager.h"
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 06c7592633..eae93a8e25 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -120,7 +120,6 @@
#define MNEMONICS_DELAY 300 /* ms */
-typedef struct _GtkDeviceGrabInfo GtkDeviceGrabInfo;
typedef struct _GtkWindowPopover GtkWindowPopover;
struct _GtkWindowPopover
@@ -372,19 +371,6 @@ struct _GtkWindowGeometryInfo
};
-struct _GtkDeviceGrabInfo
-{
- GtkWidget *widget;
- GdkDevice *device;
- guint block_others : 1;
-};
-
-struct _GtkWindowGroupPrivate
-{
- GSList *grabs;
- GSList *device_grabs;
-};
-
static GObject *gtk_window_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
@@ -10645,190 +10631,6 @@ gtk_window_has_toplevel_focus (GtkWindow *window)
return window->priv->has_toplevel_focus;
}
-
-/**
- * SECTION:gtkwindowgroup
- * @Short_description: Limit the effect of grabs
- * @Title: GtkWindowGroup
- *
- * #GtkWindowGroup objects are referenced by each window in the group,
- * so once you have added all windows to a #GtkWindowGroup, you can drop
- * the initial reference to the window group with g_object_unref(). If the
- * windows in the window group are subsequently destroyed, then they will
- * be removed from the window group and drop their references on the window
- * group; when all window have been removed, the window group will be
- * freed.
- */
-
-G_DEFINE_TYPE_WITH_PRIVATE (GtkWindowGroup, gtk_window_group, G_TYPE_OBJECT)
-
-static void
-gtk_window_group_init (GtkWindowGroup *group)
-{
- group->priv = gtk_window_group_get_instance_private (group);
-}
-
-static void
-gtk_window_group_class_init (GtkWindowGroupClass *klass)
-{
-}
-
-/**
- * gtk_window_group_new:
- *
- * Creates a new #GtkWindowGroup object. Grabs added with
- * gtk_grab_add() only affect windows within the same #GtkWindowGroup.
- *
- * Returns: a new #GtkWindowGroup.
- **/
-GtkWindowGroup *
-gtk_window_group_new (void)
-{
- return g_object_new (GTK_TYPE_WINDOW_GROUP, NULL);
-}
-
-static void
-window_group_cleanup_grabs (GtkWindowGroup *group,
- GtkWindow *window)
-{
- GtkWindowGroupPrivate *priv;
- GtkDeviceGrabInfo *info;
- GSList *tmp_list;
- GSList *to_remove = NULL;
-
- priv = group->priv;
-
- tmp_list = priv->grabs;
- while (tmp_list)
- {
- if (gtk_widget_get_toplevel (tmp_list->data) == (GtkWidget*) window)
- to_remove = g_slist_prepend (to_remove, g_object_ref (tmp_list->data));
- tmp_list = tmp_list->next;
- }
-
- while (to_remove)
- {
- gtk_grab_remove (to_remove->data);
- g_object_unref (to_remove->data);
- to_remove = g_slist_delete_link (to_remove, to_remove);
- }
-
- tmp_list = priv->device_grabs;
-
- while (tmp_list)
- {
- info = tmp_list->data;
-
- if (gtk_widget_get_toplevel (info->widget) == (GtkWidget *) window)
- to_remove = g_slist_prepend (to_remove, info);
-
- tmp_list = tmp_list->next;
- }
-
- while (to_remove)
- {
- info = to_remove->data;
-
- gtk_device_grab_remove (info->widget, info->device);
- to_remove = g_slist_delete_link (to_remove, to_remove);
- }
-}
-
-/**
- * gtk_window_group_add_window:
- * @window_group: a #GtkWindowGroup
- * @window: the #GtkWindow to add
- *
- * Adds a window to a #GtkWindowGroup.
- **/
-void
-gtk_window_group_add_window (GtkWindowGroup *window_group,
- GtkWindow *window)
-{
- GtkWindowPrivate *priv;
-
- g_return_if_fail (GTK_IS_WINDOW_GROUP (window_group));
- g_return_if_fail (GTK_IS_WINDOW (window));
-
- priv = window->priv;
-
- if (priv->group != window_group)
- {
- g_object_ref (window);
- g_object_ref (window_group);
-
- if (priv->group)
- gtk_window_group_remove_window (priv->group, window);
- else
- window_group_cleanup_grabs (gtk_window_get_group (NULL), window);
-
- priv->group = window_group;
-
- g_object_unref (window);
- }
-}
-
-/**
- * gtk_window_group_remove_window:
- * @window_group: a #GtkWindowGroup
- * @window: the #GtkWindow to remove
- *
- * Removes a window from a #GtkWindowGroup.
- **/
-void
-gtk_window_group_remove_window (GtkWindowGroup *window_group,
- GtkWindow *window)
-{
- GtkWindowPrivate *priv;
-
- g_return_if_fail (GTK_IS_WINDOW_GROUP (window_group));
- g_return_if_fail (GTK_IS_WINDOW (window));
- priv = window->priv;
- g_return_if_fail (priv->group == window_group);
-
- g_object_ref (window);
-
- window_group_cleanup_grabs (window_group, window);
- priv->group = NULL;
-
- g_object_unref (window_group);
- g_object_unref (window);
-}
-
-/**
- * gtk_window_group_list_windows:
- * @window_group: a #GtkWindowGroup
- *
- * Returns a list of the #GtkWindows that belong to @window_group.
- *
- * Returns: (element-type GtkWindow) (transfer container): A
- * newly-allocated list of windows inside the group.
- *
- * Since: 2.14
- **/
-GList *
-gtk_window_group_list_windows (GtkWindowGroup *window_group)
-{
- GList *toplevels, *toplevel, *group_windows;
-
- g_return_val_if_fail (GTK_IS_WINDOW_GROUP (window_group), NULL);
-
- group_windows = NULL;
- toplevels = gtk_window_list_toplevels ();
-
- for (toplevel = toplevels; toplevel; toplevel = toplevel->next)
- {
- GtkWindow *window = toplevel->data;
-
- if (window_group == window->priv->group)
- group_windows = g_list_prepend (group_windows, window);
- }
-
- g_list_free (toplevels);
-
- return g_list_reverse (group_windows);
-}
-
/**
* gtk_window_get_group:
* @window: (allow-none): a #GtkWindow, or %NULL
@@ -10875,176 +10677,17 @@ gtk_window_has_group (GtkWindow *window)
return window->priv->group != NULL;
}
-/**
- * gtk_window_group_get_current_grab:
- * @window_group: a #GtkWindowGroup
- *
- * Gets the current grab widget of the given group,
- * see gtk_grab_add().
- *
- * Returns: (transfer none): the current grab widget of the group
- *
- * Since: 2.22
- */
-GtkWidget *
-gtk_window_group_get_current_grab (GtkWindowGroup *window_group)
-{
- g_return_val_if_fail (GTK_IS_WINDOW_GROUP (window_group), NULL);
-
- if (window_group->priv->grabs)
- return GTK_WIDGET (window_group->priv->grabs->data);
- return NULL;
-}
-
-void
-_gtk_window_group_add_grab (GtkWindowGroup *window_group,
- GtkWidget *widget)
-{
- GtkWindowGroupPrivate *priv;
-
- priv = window_group->priv;
- priv->grabs = g_slist_prepend (priv->grabs, widget);
-}
-
-void
-_gtk_window_group_remove_grab (GtkWindowGroup *window_group,
- GtkWidget *widget)
-{
- GtkWindowGroupPrivate *priv;
-
- priv = window_group->priv;
- priv->grabs = g_slist_remove (priv->grabs, widget);
-}
-
-
-void
-_gtk_window_group_add_device_grab (GtkWindowGroup *window_group,
- GtkWidget *widget,
- GdkDevice *device,
- gboolean block_others)
+GtkWindowGroup *
+_gtk_window_get_window_group (GtkWindow *window)
{
- GtkWindowGroupPrivate *priv;
- GtkDeviceGrabInfo *info;
-
- priv = window_group->priv;
-
- info = g_slice_new0 (GtkDeviceGrabInfo);
- info->widget = widget;
- info->device = device;
- info->block_others = block_others;
-
- priv->device_grabs = g_slist_prepend (priv->device_grabs, info);
+ return window->priv->group;
}
void
-_gtk_window_group_remove_device_grab (GtkWindowGroup *window_group,
- GtkWidget *widget,
- GdkDevice *device)
+_gtk_window_set_window_group (GtkWindow *window,
+ GtkWindowGroup *group)
{
- GtkWindowGroupPrivate *priv;
- GtkDeviceGrabInfo *info;
- GSList *list, *node = NULL;
- GdkDevice *other_device;
-
- priv = window_group->priv;
- other_device = gdk_device_get_associated_device (device);
- list = priv->device_grabs;
-
- while (list)
- {
- info = list->data;
-
- if (info->widget == widget &&
- (info->device == device ||
- info->device == other_device))
- {
- node = list;
- break;
- }
-
- list = list->next;
- }
-
- if (node)
- {
- info = node->data;
-
- priv->device_grabs = g_slist_delete_link (priv->device_grabs, node);
- g_slice_free (GtkDeviceGrabInfo, info);
- }
-}
-
-/**
- * gtk_window_group_get_current_device_grab:
- * @window_group: a #GtkWindowGroup
- * @device: a #GdkDevice
- *
- * Returns the current grab widget for @device, or %NULL if none.
- *
- * Returns: (transfer none): The grab widget, or %NULL
- *
- * Since: 3.0
- */
-GtkWidget *
-gtk_window_group_get_current_device_grab (GtkWindowGroup *window_group,
- GdkDevice *device)
-{
- GtkWindowGroupPrivate *priv;
- GtkDeviceGrabInfo *info;
- GdkDevice *other_device;
- GSList *list;
-
- g_return_val_if_fail (GTK_IS_WINDOW_GROUP (window_group), NULL);
- g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
-
- priv = window_group->priv;
- list = priv->device_grabs;
- other_device = gdk_device_get_associated_device (device);
-
- while (list)
- {
- info = list->data;
- list = list->next;
-
- if (info->device == device ||
- info->device == other_device)
- return info->widget;
- }
-
- return NULL;
-}
-
-gboolean
-_gtk_window_group_widget_is_blocked_for_device (GtkWindowGroup *window_group,
- GtkWidget *widget,
- GdkDevice *device)
-{
- GtkWindowGroupPrivate *priv;
- GtkDeviceGrabInfo *info;
- GdkDevice *other_device;
- GSList *list;
-
- priv = window_group->priv;
- other_device = gdk_device_get_associated_device (device);
- list = priv->device_grabs;
-
- while (list)
- {
- info = list->data;
- list = list->next;
-
- /* Look for blocking grabs on other device pairs
- * that have the passed widget within the GTK+ grab.
- */
- if (info->block_others &&
- info->device != device &&
- info->device != other_device &&
- (info->widget == widget ||
- gtk_widget_is_ancestor (widget, info->widget)))
- return TRUE;
- }
-
- return FALSE;
+ window->priv->group = group;
}
/*
diff --git a/gtk/gtkwindow.h b/gtk/gtkwindow.h
index 7e43c847be..f6fef87943 100644
--- a/gtk/gtkwindow.h
+++ b/gtk/gtkwindow.h
@@ -90,32 +90,6 @@ struct _GtkWindowClass
void (*_gtk_reserved3) (void);
};
-#define GTK_TYPE_WINDOW_GROUP (gtk_window_group_get_type ())
-#define GTK_WINDOW_GROUP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GTK_TYPE_WINDOW_GROUP, GtkWindowGroup))
-#define GTK_WINDOW_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WINDOW_GROUP, GtkWindowGroupClass))
-#define GTK_IS_WINDOW_GROUP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GTK_TYPE_WINDOW_GROUP))
-#define GTK_IS_WINDOW_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WINDOW_GROUP))
-#define GTK_WINDOW_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WINDOW_GROUP, GtkWindowGroupClass))
-
-struct _GtkWindowGroup
-{
- GObject parent_instance;
-
- GtkWindowGroupPrivate *priv;
-};
-
-struct _GtkWindowGroupClass
-{
- GObjectClass parent_class;
-
- /* Padding for future expansion */
- void (*_gtk_reserved1) (void);
- void (*_gtk_reserved2) (void);
- void (*_gtk_reserved3) (void);
- void (*_gtk_reserved4) (void);
-};
-
-
/**
* GtkWindowType:
* @GTK_WINDOW_TOPLEVEL: A regular window, such as a dialog.
@@ -483,27 +457,6 @@ void gtk_window_reshow_with_initial_size (GtkWindow *window);
GDK_AVAILABLE_IN_ALL
GtkWindowType gtk_window_get_window_type (GtkWindow *window);
-/* Window groups
- */
-GDK_AVAILABLE_IN_ALL
-GType gtk_window_group_get_type (void) G_GNUC_CONST;
-
-GDK_AVAILABLE_IN_ALL
-GtkWindowGroup * gtk_window_group_new (void);
-GDK_AVAILABLE_IN_ALL
-void gtk_window_group_add_window (GtkWindowGroup *window_group,
- GtkWindow *window);
-GDK_AVAILABLE_IN_ALL
-void gtk_window_group_remove_window (GtkWindowGroup *window_group,
- GtkWindow *window);
-GDK_AVAILABLE_IN_ALL
-GList * gtk_window_group_list_windows (GtkWindowGroup *window_group);
-
-GDK_AVAILABLE_IN_ALL
-GtkWidget * gtk_window_group_get_current_grab (GtkWindowGroup *window_group);
-GDK_AVAILABLE_IN_ALL
-GtkWidget * gtk_window_group_get_current_device_grab (GtkWindowGroup *window_group,
- GdkDevice *device);
GDK_AVAILABLE_IN_ALL
GtkApplication *gtk_window_get_application (GtkWindow *window);
diff --git a/gtk/gtkwindowgroup.c b/gtk/gtkwindowgroup.c
new file mode 100644
index 0000000000..2a9cd1e92a
--- /dev/null
+++ b/gtk/gtkwindowgroup.c
@@ -0,0 +1,396 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * 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/>.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GTK+ Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#include "config.h"
+
+#include "gtkmain.h"
+#include "gtkwindowprivate.h"
+#include "gtkwindowgroup.h"
+
+
+/**
+ * SECTION:gtkwindowgroup
+ * @Short_description: Limit the effect of grabs
+ * @Title: GtkWindowGroup
+ *
+ * #GtkWindowGroup objects are referenced by each window in the group,
+ * so once you have added all windows to a #GtkWindowGroup, you can drop
+ * the initial reference to the window group with g_object_unref(). If the
+ * windows in the window group are subsequently destroyed, then they will
+ * be removed from the window group and drop their references on the window
+ * group; when all window have been removed, the window group will be
+ * freed.
+ */
+
+typedef struct _GtkDeviceGrabInfo GtkDeviceGrabInfo;
+struct _GtkDeviceGrabInfo
+{
+ GtkWidget *widget;
+ GdkDevice *device;
+ guint block_others : 1;
+};
+
+struct _GtkWindowGroupPrivate
+{
+ GSList *grabs;
+ GSList *device_grabs;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GtkWindowGroup, gtk_window_group, G_TYPE_OBJECT)
+
+static void
+gtk_window_group_init (GtkWindowGroup *group)
+{
+ group->priv = gtk_window_group_get_instance_private (group);
+}
+
+static void
+gtk_window_group_class_init (GtkWindowGroupClass *klass)
+{
+}
+
+
+/**
+ * gtk_window_group_new:
+ *
+ * Creates a new #GtkWindowGroup object. Grabs added with
+ * gtk_grab_add() only affect windows within the same #GtkWindowGroup.
+ *
+ * Returns: a new #GtkWindowGroup.
+ **/
+GtkWindowGroup *
+gtk_window_group_new (void)
+{
+ return g_object_new (GTK_TYPE_WINDOW_GROUP, NULL);
+}
+
+static void
+window_group_cleanup_grabs (GtkWindowGroup *group,
+ GtkWindow *window)
+{
+ GtkWindowGroupPrivate *priv;
+ GtkDeviceGrabInfo *info;
+ GSList *tmp_list;
+ GSList *to_remove = NULL;
+
+ priv = group->priv;
+
+ tmp_list = priv->grabs;
+ while (tmp_list)
+ {
+ if (gtk_widget_get_toplevel (tmp_list->data) == (GtkWidget*) window)
+ to_remove = g_slist_prepend (to_remove, g_object_ref (tmp_list->data));
+ tmp_list = tmp_list->next;
+ }
+
+ while (to_remove)
+ {
+ gtk_grab_remove (to_remove->data);
+ g_object_unref (to_remove->data);
+ to_remove = g_slist_delete_link (to_remove, to_remove);
+ }
+
+ tmp_list = priv->device_grabs;
+
+ while (tmp_list)
+ {
+ info = tmp_list->data;
+
+ if (gtk_widget_get_toplevel (info->widget) == (GtkWidget *) window)
+ to_remove = g_slist_prepend (to_remove, info);
+
+ tmp_list = tmp_list->next;
+ }
+
+ while (to_remove)
+ {
+ info = to_remove->data;
+
+ gtk_device_grab_remove (info->widget, info->device);
+ to_remove = g_slist_delete_link (to_remove, to_remove);
+ }
+}
+
+/**
+ * gtk_window_group_add_window:
+ * @window_group: a #GtkWindowGroup
+ * @window: the #GtkWindow to add
+ *
+ * Adds a window to a #GtkWindowGroup.
+ **/
+void
+gtk_window_group_add_window (GtkWindowGroup *window_group,
+ GtkWindow *window)
+{
+ GtkWindowGroup *old_group;
+
+ g_return_if_fail (GTK_IS_WINDOW_GROUP (window_group));
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
+ old_group = _gtk_window_get_window_group (window);
+
+ if (old_group != window_group)
+ {
+ g_object_ref (window);
+ g_object_ref (window_group);
+
+ if (old_group)
+ gtk_window_group_remove_window (old_group, window);
+ else
+ window_group_cleanup_grabs (gtk_window_get_group (NULL), window);
+
+ _gtk_window_set_window_group (window, window_group);
+
+ g_object_unref (window);
+ }
+}
+
+/**
+ * gtk_window_group_remove_window:
+ * @window_group: a #GtkWindowGroup
+ * @window: the #GtkWindow to remove
+ *
+ * Removes a window from a #GtkWindowGroup.
+ **/
+void
+gtk_window_group_remove_window (GtkWindowGroup *window_group,
+ GtkWindow *window)
+{
+ g_return_if_fail (GTK_IS_WINDOW_GROUP (window_group));
+ g_return_if_fail (GTK_IS_WINDOW (window));
+ g_return_if_fail (_gtk_window_get_window_group (window) == window_group);
+
+ g_object_ref (window);
+
+ window_group_cleanup_grabs (window_group, window);
+ _gtk_window_set_window_group (window, NULL);
+
+ g_object_unref (window_group);
+ g_object_unref (window);
+}
+
+/**
+ * gtk_window_group_list_windows:
+ * @window_group: a #GtkWindowGroup
+ *
+ * Returns a list of the #GtkWindows that belong to @window_group.
+ *
+ * Returns: (element-type GtkWindow) (transfer container): A
+ * newly-allocated list of windows inside the group.
+ *
+ * Since: 2.14
+ **/
+GList *
+gtk_window_group_list_windows (GtkWindowGroup *window_group)
+{
+ GList *toplevels, *toplevel, *group_windows;
+
+ g_return_val_if_fail (GTK_IS_WINDOW_GROUP (window_group), NULL);
+
+ group_windows = NULL;
+ toplevels = gtk_window_list_toplevels ();
+
+ for (toplevel = toplevels; toplevel; toplevel = toplevel->next)
+ {
+ GtkWindow *window = toplevel->data;
+
+ if (window_group == _gtk_window_get_window_group (window))
+ group_windows = g_list_prepend (group_windows, window);
+ }
+
+ g_list_free (toplevels);
+
+ return g_list_reverse (group_windows);
+}
+
+/**
+ * gtk_window_group_get_current_grab:
+ * @window_group: a #GtkWindowGroup
+ *
+ * Gets the current grab widget of the given group,
+ * see gtk_grab_add().
+ *
+ * Returns: (transfer none): the current grab widget of the group
+ *
+ * Since: 2.22
+ */
+GtkWidget *
+gtk_window_group_get_current_grab (GtkWindowGroup *window_group)
+{
+ g_return_val_if_fail (GTK_IS_WINDOW_GROUP (window_group), NULL);
+
+ if (window_group->priv->grabs)
+ return GTK_WIDGET (window_group->priv->grabs->data);
+ return NULL;
+}
+
+void
+_gtk_window_group_add_grab (GtkWindowGroup *window_group,
+ GtkWidget *widget)
+{
+ GtkWindowGroupPrivate *priv;
+
+ priv = window_group->priv;
+ priv->grabs = g_slist_prepend (priv->grabs, widget);
+}
+
+void
+_gtk_window_group_remove_grab (GtkWindowGroup *window_group,
+ GtkWidget *widget)
+{
+ GtkWindowGroupPrivate *priv;
+
+ priv = window_group->priv;
+ priv->grabs = g_slist_remove (priv->grabs, widget);
+}
+
+void
+_gtk_window_group_add_device_grab (GtkWindowGroup *window_group,
+ GtkWidget *widget,
+ GdkDevice *device,
+ gboolean block_others)
+{
+ GtkWindowGroupPrivate *priv;
+ GtkDeviceGrabInfo *info;
+
+ priv = window_group->priv;
+
+ info = g_slice_new0 (GtkDeviceGrabInfo);
+ info->widget = widget;
+ info->device = device;
+ info->block_others = block_others;
+
+ priv->device_grabs = g_slist_prepend (priv->device_grabs, info);
+}
+
+void
+_gtk_window_group_remove_device_grab (GtkWindowGroup *window_group,
+ GtkWidget *widget,
+ GdkDevice *device)
+{
+ GtkWindowGroupPrivate *priv;
+ GtkDeviceGrabInfo *info;
+ GSList *list, *node = NULL;
+ GdkDevice *other_device;
+
+ priv = window_group->priv;
+ other_device = gdk_device_get_associated_device (device);
+ list = priv->device_grabs;
+
+ while (list)
+ {
+ info = list->data;
+
+ if (info->widget == widget &&
+ (info->device == device ||
+ info->device == other_device))
+ {
+ node = list;
+ break;
+ }
+
+ list = list->next;
+ }
+
+ if (node)
+ {
+ info = node->data;
+
+ priv->device_grabs = g_slist_delete_link (priv->device_grabs, node);
+ g_slice_free (GtkDeviceGrabInfo, info);
+ }
+}
+
+/**
+ * gtk_window_group_get_current_device_grab:
+ * @window_group: a #GtkWindowGroup
+ * @device: a #GdkDevice
+ *
+ * Returns the current grab widget for @device, or %NULL if none.
+ *
+ * Returns: (transfer none): The grab widget, or %NULL
+ *
+ * Since: 3.0
+ */
+GtkWidget *
+gtk_window_group_get_current_device_grab (GtkWindowGroup *window_group,
+ GdkDevice *device)
+{
+ GtkWindowGroupPrivate *priv;
+ GtkDeviceGrabInfo *info;
+ GdkDevice *other_device;
+ GSList *list;
+
+ g_return_val_if_fail (GTK_IS_WINDOW_GROUP (window_group), NULL);
+ g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
+
+ priv = window_group->priv;
+ list = priv->device_grabs;
+ other_device = gdk_device_get_associated_device (device);
+
+ while (list)
+ {
+ info = list->data;
+ list = list->next;
+
+ if (info->device == device ||
+ info->device == other_device)
+ return info->widget;
+ }
+
+ return NULL;
+}
+
+gboolean
+_gtk_window_group_widget_is_blocked_for_device (GtkWindowGroup *window_group,
+ GtkWidget *widget,
+ GdkDevice *device)
+{
+ GtkWindowGroupPrivate *priv;
+ GtkDeviceGrabInfo *info;
+ GdkDevice *other_device;
+ GSList *list;
+
+ priv = window_group->priv;
+ other_device = gdk_device_get_associated_device (device);
+ list = priv->device_grabs;
+
+ while (list)
+ {
+ info = list->data;
+ list = list->next;
+
+ /* Look for blocking grabs on other device pairs
+ * that have the passed widget within the GTK+ grab.
+ */
+ if (info->block_others &&
+ info->device != device &&
+ info->device != other_device &&
+ (info->widget == widget ||
+ gtk_widget_is_ancestor (widget, info->widget)))
+ return TRUE;
+ }
+
+ return FALSE;
+}
diff --git a/gtk/gtkwindowgroup.h b/gtk/gtkwindowgroup.h
new file mode 100644
index 0000000000..a7c53f0c35
--- /dev/null
+++ b/gtk/gtkwindowgroup.h
@@ -0,0 +1,89 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * 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/>.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GTK+ Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#ifndef __GTK_WINDOW_GROUP_H__
+#define __GTK_WINDOW_GROUP_H__
+
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include "gtkwindow.h"
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_WINDOW_GROUP (gtk_window_group_get_type ())
+#define GTK_WINDOW_GROUP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GTK_TYPE_WINDOW_GROUP, GtkWindowGroup))
+#define GTK_WINDOW_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WINDOW_GROUP, GtkWindowGroupClass))
+#define GTK_IS_WINDOW_GROUP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GTK_TYPE_WINDOW_GROUP))
+#define GTK_IS_WINDOW_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WINDOW_GROUP))
+#define GTK_WINDOW_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WINDOW_GROUP, GtkWindowGroupClass))
+
+struct _GtkWindowGroup
+{
+ GObject parent_instance;
+
+ GtkWindowGroupPrivate *priv;
+};
+
+struct _GtkWindowGroupClass
+{
+ GObjectClass parent_class;
+
+ /* Padding for future expansion */
+ void (*_gtk_reserved1) (void);
+ void (*_gtk_reserved2) (void);
+ void (*_gtk_reserved3) (void);
+ void (*_gtk_reserved4) (void);
+};
+
+
+/* Window groups
+ */
+GDK_AVAILABLE_IN_ALL
+GType gtk_window_group_get_type (void) G_GNUC_CONST;
+
+GDK_AVAILABLE_IN_ALL
+GtkWindowGroup * gtk_window_group_new (void);
+GDK_AVAILABLE_IN_ALL
+void gtk_window_group_add_window (GtkWindowGroup *window_group,
+ GtkWindow *window);
+GDK_AVAILABLE_IN_ALL
+void gtk_window_group_remove_window (GtkWindowGroup *window_group,
+ GtkWindow *window);
+GDK_AVAILABLE_IN_ALL
+GList * gtk_window_group_list_windows (GtkWindowGroup *window_group);
+
+GDK_AVAILABLE_IN_ALL
+GtkWidget * gtk_window_group_get_current_grab (GtkWindowGroup *window_group);
+GDK_AVAILABLE_IN_ALL
+GtkWidget * gtk_window_group_get_current_device_grab (GtkWindowGroup *window_group,
+ GdkDevice *device);
+
+
+G_END_DECLS
+
+#endif /* __GTK_WINDOW_GROUP_H__ */
+
diff --git a/gtk/gtkwindowprivate.h b/gtk/gtkwindowprivate.h
index 704026d001..eb827f5cbc 100644
--- a/gtk/gtkwindowprivate.h
+++ b/gtk/gtkwindowprivate.h
@@ -93,6 +93,13 @@ void _gtk_window_get_shadow_width (GtkWindow *window,
void _gtk_window_toggle_maximized (GtkWindow *window);
+/* Window groups */
+
+GtkWindowGroup *_gtk_window_get_window_group (GtkWindow *window);
+
+void _gtk_window_set_window_group (GtkWindow *window,
+ GtkWindowGroup *group);
+
/* Popovers */
void _gtk_window_add_popover (GtkWindow *window,
GtkWidget *popover);