]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkwindow.c
filechooserbutton: Update the button's state only on programmatic changes to the...
[~andy/gtk] / gtk / gtkwindow.c
index 5fa4e351a8f7a603c108ebd2b98a689547c3692f..99bab056658c3ea5bcecfee84dbb48b1a11b09d6 100644 (file)
@@ -12,9 +12,7 @@
  * 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, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
  */
 
 #include "config.h"
+
+#include "gtkwindow.h"
+
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <limits.h>
-#include "gdk/gdk.h"
-#include "gdk/gdkkeysyms.h"
-
-#include "gtkintl.h"
 
 #include "gtkprivate.h"
-#include "gtkrc.h"
-#include "gtkwindow.h"
-#include "gtkwindow-decorate.h"
+#include "gtkwindowprivate.h"
+#include "gtkaccelgroupprivate.h"
 #include "gtkbindings.h"
 #include "gtkkeyhash.h"
 #include "gtkmain.h"
 #include "gtkmarshalers.h"
 #include "gtkplug.h"
 #include "gtkbuildable.h"
-#include "gtksizerequest.h"
+#include "gtkwidgetprivate.h"
+#include "gtkcontainerprivate.h"
+#include "gtkintl.h"
+#include "gtkstylecontextprivate.h"
+#include "gtktypebuiltins.h"
+#include "a11y/gtkwindowaccessible.h"
+
+#include "deprecated/gtkstyle.h"
 
 #ifdef GDK_WINDOWING_X11
 #include "x11/gdkx.h"
  * @title: GtkWindow
  * @short_description: Toplevel which can contain other widgets
  *
+ * A GtkWindow is a toplevel window which can contain other widgets.
+ * Windows normally have decorations that are under the control
+ * of the windowing system and allow the user to manipulate the window
+ * (resize it, move it, close it,...).
+ *
+ * GTK+ also allows windows to have a resize grip (a small area in the lower
+ * right or left corner) which can be clicked to reszie the window. To
+ * control whether a window has a resize grip, use
+ * gtk_window_set_has_resize_grip().
+ *
  * <refsect2 id="GtkWindow-BUILDER-UI">
  * <title>GtkWindow as GtkBuildable</title>
  * <para>
  * </example>
  * </refsect2>
  */
+
+#define AUTO_MNEMONICS_DELAY 300 /* ms */
+
+typedef struct _GtkDeviceGrabInfo GtkDeviceGrabInfo;
+
+struct _GtkWindowPrivate
+{
+  GtkMnemonicHash       *mnemonic_hash;
+
+  GtkWidget             *attach_widget;
+  GtkWidget             *default_widget;
+  GtkWidget             *focus_widget;
+  GtkWindow             *transient_parent;
+  GtkWindowGeometryInfo *geometry_info;
+  GtkWindowGroup        *group;
+  GdkScreen             *screen;
+  GtkApplication        *application;
+
+  GdkModifierType        mnemonic_modifier;
+  GdkWindowTypeHint      gdk_type_hint;
+
+  GdkWindow *grip_window;
+
+  gchar   *startup_id;
+  gchar   *title;
+  gchar   *wmclass_class;
+  gchar   *wmclass_name;
+  gchar   *wm_role;
+
+  guint    keys_changed_handler;
+
+  guint32  initial_timestamp;
+
+  guint16  configure_request_count;
+
+  guint    auto_mnemonics_timeout_id;
+
+  /* The following flags are initially TRUE (before a window is mapped).
+   * They cause us to compute a configure request that involves
+   * default-only parameters. Once mapped, we set them to FALSE.
+   * Then we set them to TRUE again on unmap (for position)
+   * and on unrealize (for size).
+   */
+  guint    need_default_position     : 1;
+  guint    need_default_size         : 1;
+
+  guint    above_initially           : 1;
+  guint    accept_focus              : 1;
+  guint    below_initially           : 1;
+  guint    builder_visible           : 1;
+  guint    configure_notify_received : 1;
+  guint    decorated                 : 1;
+  guint    deletable                 : 1;
+  guint    destroy_with_parent       : 1;
+  guint    focus_on_map              : 1;
+  guint    fullscreen_initially      : 1;
+  guint    has_focus                 : 1;
+  guint    has_user_ref_count        : 1;
+  guint    has_toplevel_focus        : 1;
+  guint    hide_titlebar_when_maximized : 1;
+  guint    iconify_initially         : 1; /* gtk_window_iconify() called before realization */
+  guint    is_active                 : 1;
+  guint    maximize_initially        : 1;
+  guint    mnemonics_visible         : 1;
+  guint    mnemonics_visible_set     : 1;
+  guint    focus_visible             : 1;
+  guint    modal                     : 1;
+  guint    position                  : 3;
+  guint    reset_type_hint           : 1;
+  guint    resizable                 : 1;
+  guint    skips_pager               : 1;
+  guint    skips_taskbar             : 1;
+  guint    stick_initially           : 1;
+  guint    transient_parent_group    : 1;
+  guint    type                      : 4; /* GtkWindowType */
+  guint    type_hint                 : 3; /* GdkWindowTypeHint if the hint is
+                                           * one of the original eight. If not,
+                                           * then it contains
+                                           * GDK_WINDOW_TYPE_HINT_NORMAL
+                                           */
+  guint    urgent                    : 1;
+  guint    has_resize_grip           : 1;
+  guint    resize_grip_visible       : 1;  /* don't use, just for "resize-
+                                            * grip-visible" notification
+                                            */
+  guint    gravity                   : 5; /* GdkGravity */
+
+};
+
 enum {
   SET_FOCUS,
   FRAME_EVENT,
@@ -102,14 +204,13 @@ enum {
   /* Normal Props */
   PROP_TITLE,
   PROP_ROLE,
-  PROP_ALLOW_SHRINK,
-  PROP_ALLOW_GROW,
   PROP_RESIZABLE,
   PROP_MODAL,
   PROP_WIN_POS,
   PROP_DEFAULT_WIDTH,
   PROP_DEFAULT_HEIGHT,
   PROP_DESTROY_WITH_PARENT,
+  PROP_HIDE_TITLEBAR_WHEN_MAXIMIZED,
   PROP_ICON,
   PROP_ICON_NAME,
   PROP_SCREEN,
@@ -123,16 +224,19 @@ enum {
   PROP_DELETABLE,
   PROP_GRAVITY,
   PROP_TRANSIENT_FOR,
-  PROP_OPACITY,
-  
+  PROP_ATTACHED_TO,
+  PROP_HAS_RESIZE_GRIP,
+  PROP_RESIZE_GRIP_VISIBLE,
+  PROP_APPLICATION,
   /* Readonly properties */
   PROP_IS_ACTIVE,
   PROP_HAS_TOPLEVEL_FOCUS,
-  
+
   /* Writeonly properties */
   PROP_STARTUP_ID,
-  
+
   PROP_MNEMONICS_VISIBLE,
+  PROP_FOCUS_VISIBLE,
 
   LAST_ARG
 };
@@ -140,8 +244,6 @@ enum {
 typedef struct
 {
   GList     *icon_list;
-  GdkPixmap *icon_pixmap;
-  GdkPixmap *icon_mask;
   gchar     *icon_name;
   guint      realized : 1;
   guint      using_default_icon : 1;
@@ -186,51 +288,19 @@ struct _GtkWindowGeometryInfo
    */
   guint          position_constraints_changed : 1;
 
-  /* if true, default_width, height come from gtk_window_parse_geometry,
-   * and thus should be multiplied by the increments and affect the
-   * geometry widget only
+  /* if true, default_width, height should be multiplied by the
+   * increments and affect the geometry widget only
    */
   guint          default_is_geometry : 1;
-  
-  GtkWindowLastGeometryInfo last;
-};
-
-#define GTK_WINDOW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_WINDOW, GtkWindowPrivate))
-#define GTK_WINDOW_GROUP_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_WINDOW_GROUP, GtkWindowGroupPrivate))
-
-typedef struct _GtkWindowPrivate GtkWindowPrivate;
 
-struct _GtkWindowPrivate
-{
-  GtkMnemonicHash *mnemonic_hash;
+  /* if true, resize_width, height should be multiplied by the
+   * increments and affect the geometry widget only
+   */
+  guint          resize_is_geometry : 1;
   
-  guint above_initially : 1;
-  guint below_initially : 1;
-  guint fullscreen_initially : 1;
-  guint skips_taskbar : 1;
-  guint skips_pager : 1;
-  guint urgent : 1;
-  guint accept_focus : 1;
-  guint focus_on_map : 1;
-  guint deletable : 1;
-  guint transient_parent_group : 1;
-
-  guint reset_type_hint : 1;
-  guint opacity_set : 1;
-  guint builder_visible : 1;
-
-  guint mnemonics_visible : 1;
-  guint mnemonics_visible_set : 1;
-
-  GdkWindowTypeHint type_hint;
-
-  gdouble opacity;
-
-  gchar *startup_id;
+  GtkWindowLastGeometryInfo last;
 };
 
-typedef struct _GtkDeviceGrabInfo GtkDeviceGrabInfo;
-typedef struct _GtkWindowGroupPrivate GtkWindowGroupPrivate;
 
 struct _GtkDeviceGrabInfo
 {
@@ -241,12 +311,13 @@ struct _GtkDeviceGrabInfo
 
 struct _GtkWindowGroupPrivate
 {
+  GSList *grabs;
   GSList *device_grabs;
 };
 
 static void gtk_window_dispose            (GObject           *object);
-static void gtk_window_destroy            (GtkObject         *object);
 static void gtk_window_finalize           (GObject           *object);
+static void gtk_window_destroy            (GtkWidget         *widget);
 static void gtk_window_show               (GtkWidget         *widget);
 static void gtk_window_hide               (GtkWidget         *widget);
 static void gtk_window_map                (GtkWidget         *widget);
@@ -255,18 +326,16 @@ static void gtk_window_realize            (GtkWidget         *widget);
 static void gtk_window_unrealize          (GtkWidget         *widget);
 static void gtk_window_size_allocate      (GtkWidget         *widget,
                                           GtkAllocation     *allocation);
-static gint gtk_window_event              (GtkWidget *widget,
-                                          GdkEvent *event);
 static gboolean gtk_window_map_event      (GtkWidget         *widget,
                                            GdkEventAny       *event);
-static gboolean gtk_window_frame_event    (GtkWindow *window,
-                                          GdkEvent *event);
 static gint gtk_window_configure_event    (GtkWidget         *widget,
                                           GdkEventConfigure *event);
 static gint gtk_window_key_press_event    (GtkWidget         *widget,
                                           GdkEventKey       *event);
 static gint gtk_window_key_release_event  (GtkWidget         *widget,
                                           GdkEventKey       *event);
+static gint gtk_window_button_press_event (GtkWidget         *widget,
+                                           GdkEventButton    *event);
 static gint gtk_window_enter_notify_event (GtkWidget         *widget,
                                           GdkEventCrossing  *event);
 static gint gtk_window_leave_notify_event (GtkWidget         *widget,
@@ -275,23 +344,26 @@ static gint gtk_window_focus_in_event     (GtkWidget         *widget,
                                           GdkEventFocus     *event);
 static gint gtk_window_focus_out_event    (GtkWidget         *widget,
                                           GdkEventFocus     *event);
-static gint gtk_window_client_event      (GtkWidget         *widget,
-                                          GdkEventClient    *event);
+static void gtk_window_style_updated      (GtkWidget         *widget);
+static gboolean gtk_window_state_event    (GtkWidget          *widget,
+                                           GdkEventWindowState *event);
 static void gtk_window_check_resize       (GtkContainer      *container);
 static gint gtk_window_focus              (GtkWidget        *widget,
                                           GtkDirectionType  direction);
+static void gtk_window_move_focus         (GtkWidget         *widget,
+                                           GtkDirectionType   dir);
 static void gtk_window_real_set_focus     (GtkWindow         *window,
                                           GtkWidget         *focus);
+static void gtk_window_direction_changed  (GtkWidget         *widget,
+                                           GtkTextDirection   prev_dir);
+static void gtk_window_state_changed      (GtkWidget         *widget,
+                                           GtkStateType       previous_state);
 
 static void gtk_window_real_activate_default (GtkWindow         *window);
 static void gtk_window_real_activate_focus   (GtkWindow         *window);
-static void gtk_window_move_focus            (GtkWindow         *window,
-                                              GtkDirectionType   dir);
 static void gtk_window_keys_changed          (GtkWindow         *window);
-static void gtk_window_paint                 (GtkWidget         *widget,
-                                             GdkRectangle      *area);
-static gint gtk_window_expose                (GtkWidget         *widget,
-                                             GdkEventExpose    *event);
+static gint gtk_window_draw                  (GtkWidget         *widget,
+                                             cairo_t           *cr);
 static void gtk_window_unset_transient_for         (GtkWindow  *window);
 static void gtk_window_transient_parent_realized   (GtkWidget  *parent,
                                                    GtkWidget  *window);
@@ -341,12 +413,21 @@ static GList   *icon_list_from_theme                  (GtkWidget    *widget,
                                                       const gchar  *name);
 static void     gtk_window_realize_icon               (GtkWindow    *window);
 static void     gtk_window_unrealize_icon             (GtkWindow    *window);
+static void     resize_grip_create_window             (GtkWindow    *window);
+static void     resize_grip_destroy_window            (GtkWindow    *window);
+static void     update_grip_visibility                (GtkWindow    *window);
 
 static void        gtk_window_notify_keys_changed (GtkWindow   *window);
 static GtkKeyHash *gtk_window_get_key_hash        (GtkWindow   *window);
 static void        gtk_window_free_key_hash       (GtkWindow   *window);
 static void       gtk_window_on_composited_changed (GdkScreen *screen,
                                                     GtkWindow *window);
+#ifdef GDK_WINDOWING_X11
+static void        gtk_window_on_theme_variant_changed (GtkSettings *settings,
+                                                        GParamSpec  *pspec,
+                                                        GtkWindow   *window);
+#endif
+static void        gtk_window_set_theme_variant         (GtkWindow  *window);
 
 static GSList      *toplevel_list = NULL;
 static guint        window_signals[LAST_SIGNAL] = { 0 };
@@ -358,7 +439,6 @@ static gboolean     sent_startup_notification = FALSE;
 
 static GQuark       quark_gtk_embedded = 0;
 static GQuark       quark_gtk_window_key_hash = 0;
-static GQuark       quark_gtk_window_default_icon_pixmap = 0;
 static GQuark       quark_gtk_window_icon_info = 0;
 static GQuark       quark_gtk_buildable_accels = 0;
 
@@ -393,30 +473,21 @@ static void gtk_window_buildable_custom_finished (GtkBuildable  *buildable,
                                                      const gchar   *tagname,
                                                      gpointer       user_data);
 
-
-static void gtk_window_size_request_init      (GtkSizeRequestIface *iface);
-static void gtk_window_get_width              (GtkSizeRequest      *widget,
-                                              gint                *minimum_size,
-                                              gint                *natural_size);
-static void gtk_window_get_height             (GtkSizeRequest      *widget,
-                                              gint                *minimum_size,
-                                              gint                *natural_size);
+static void ensure_state_flag_backdrop (GtkWidget *widget);
 
 G_DEFINE_TYPE_WITH_CODE (GtkWindow, gtk_window, GTK_TYPE_BIN,
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
-                                               gtk_window_buildable_interface_init)
-                        G_IMPLEMENT_INTERFACE (GTK_TYPE_SIZE_REQUEST,
-                                               gtk_window_size_request_init))
+                                               gtk_window_buildable_interface_init))
 
 static void
 add_tab_bindings (GtkBindingSet    *binding_set,
                  GdkModifierType   modifiers,
                  GtkDirectionType  direction)
 {
-  gtk_binding_entry_add_signal (binding_set, GDK_Tab, modifiers,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
                                 "move-focus", 1,
                                 GTK_TYPE_DIRECTION_TYPE, direction);
-  gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, modifiers,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
                                 "move-focus", 1,
                                 GTK_TYPE_DIRECTION_TYPE, direction);
 }
@@ -426,7 +497,7 @@ add_arrow_bindings (GtkBindingSet    *binding_set,
                    guint             keysym,
                    GtkDirectionType  direction)
 {
-  guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
+  guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
   
   gtk_binding_entry_add_signal (binding_set, keysym, 0,
                                 "move-focus", 1,
@@ -456,9 +527,10 @@ extract_time_from_startup_id (const gchar* startup_id)
       /* Skip past the "_TIME" part */
       timestr += 5;
 
+      end = NULL;
       errno = 0;
-      timestamp = strtoul (timestr, &end, 0);
-      if (end != timestr && errno == 0)
+      timestamp = g_ascii_strtoull (timestr, &end, 0);
+      if (errno == 0 && end != timestr)
         retval = timestamp;
     }
 
@@ -475,18 +547,15 @@ static void
 gtk_window_class_init (GtkWindowClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-  GtkObjectClass *object_class;
   GtkWidgetClass *widget_class;
   GtkContainerClass *container_class;
   GtkBindingSet *binding_set;
-  
-  object_class = (GtkObjectClass*) klass;
+
   widget_class = (GtkWidgetClass*) klass;
   container_class = (GtkContainerClass*) klass;
   
   quark_gtk_embedded = g_quark_from_static_string ("gtk-embedded");
   quark_gtk_window_key_hash = g_quark_from_static_string ("gtk-window-key-hash");
-  quark_gtk_window_default_icon_pixmap = g_quark_from_static_string ("gtk-window-default-icon-pixmap");
   quark_gtk_window_icon_info = g_quark_from_static_string ("gtk-window-icon-info");
   quark_gtk_buildable_accels = g_quark_from_static_string ("gtk-window-buildable-accels");
 
@@ -495,9 +564,8 @@ gtk_window_class_init (GtkWindowClass *klass)
 
   gobject_class->set_property = gtk_window_set_property;
   gobject_class->get_property = gtk_window_get_property;
-  
-  object_class->destroy = gtk_window_destroy;
 
+  widget_class->destroy = gtk_window_destroy;
   widget_class->show = gtk_window_show;
   widget_class->hide = gtk_window_hide;
   widget_class->map = gtk_window_map;
@@ -512,23 +580,26 @@ gtk_window_class_init (GtkWindowClass *klass)
   widget_class->enter_notify_event = gtk_window_enter_notify_event;
   widget_class->leave_notify_event = gtk_window_leave_notify_event;
   widget_class->focus_in_event = gtk_window_focus_in_event;
+  widget_class->button_press_event = gtk_window_button_press_event;
   widget_class->focus_out_event = gtk_window_focus_out_event;
-  widget_class->client_event = gtk_window_client_event;
   widget_class->focus = gtk_window_focus;
-  widget_class->expose_event = gtk_window_expose;
+  widget_class->move_focus = gtk_window_move_focus;
+  widget_class->draw = gtk_window_draw;
+  widget_class->window_state_event = gtk_window_state_event;
+  widget_class->direction_changed = gtk_window_direction_changed;
+  widget_class->state_changed = gtk_window_state_changed;
+  widget_class->style_updated = gtk_window_style_updated;
 
   container_class->check_resize = gtk_window_check_resize;
 
   klass->set_focus = gtk_window_real_set_focus;
-  klass->frame_event = gtk_window_frame_event;
 
   klass->activate_default = gtk_window_real_activate_default;
   klass->activate_focus = gtk_window_real_activate_focus;
-  klass->move_focus = gtk_window_move_focus;
   klass->keys_changed = gtk_window_keys_changed;
-  
+
   g_type_class_add_private (gobject_class, sizeof (GtkWindowPrivate));
-  
+
   /* Construct */
   g_object_class_install_property (gobject_class,
                                    PROP_TYPE,
@@ -625,6 +696,21 @@ gtk_window_class_init (GtkWindowClass *klass)
                                                          FALSE,
                                                         GTK_PARAM_READWRITE));
 
+  /**
+   * GtkWindow:hide-titlebar-when-maximized:
+   *
+   * Whether the titlebar should be hidden during maximization.
+   *
+   * Since: 3.4
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_HIDE_TITLEBAR_WHEN_MAXIMIZED,
+                                   g_param_spec_boolean ("hide-titlebar-when-maximized",
+                                                        P_("Hide the titlebar during maximization"),
+                                                        P_("If this window's titlebar should be hidden when the window is maximized"),
+                                                         FALSE,
+                                                        GTK_PARAM_READWRITE));
+
   g_object_class_install_property (gobject_class,
                                    PROP_ICON,
                                    g_param_spec_object ("icon",
@@ -632,6 +718,18 @@ gtk_window_class_init (GtkWindowClass *klass)
                                                         P_("Icon for this window"),
                                                         GDK_TYPE_PIXBUF,
                                                         GTK_PARAM_READWRITE));
+
+  /**
+   * GtkWindow:mnemonics-visible:
+   *
+   * Whether mnemonics are currently visible in this window.
+   *
+   * This property is maintained by GTK+ based on the
+   * #GtkSettings:gtk-auto-mnemonics setting and user input,
+   * and should not be set by applications.
+   *
+   * Since: 2.20
+   */
   g_object_class_install_property (gobject_class,
                                    PROP_MNEMONICS_VISIBLE,
                                    g_param_spec_boolean ("mnemonics-visible",
@@ -639,6 +737,25 @@ gtk_window_class_init (GtkWindowClass *klass)
                                                          P_("Whether mnemonics are currently visible in this window"),
                                                          TRUE,
                                                          GTK_PARAM_READWRITE));
+
+  /**
+   * GtkWindow:focus-visible:
+   *
+   * Whether 'focus rectangles' are currently visible in this window.
+   *
+   * This property is maintained by GTK+ based on the
+   * #GtkSettings:gtk-visible-focus setting and user input
+   * and should not be set by applications.
+   *
+   * Since: 2.20
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_FOCUS_VISIBLE,
+                                   g_param_spec_boolean ("focus-visible",
+                                                         P_("Focus Visible"),
+                                                         P_("Whether focus rectangles are currently visible in this window"),
+                                                         TRUE,
+                                                         GTK_PARAM_READWRITE));
   
   /**
    * GtkWindow:icon-name:
@@ -773,6 +890,41 @@ gtk_window_class_init (GtkWindowClass *klass)
                                                         TRUE,
                                                         GTK_PARAM_READWRITE));
 
+  /**
+   * GtkWindow:has-resize-grip:
+   *
+   * Whether the window has a corner resize grip.
+   *
+   * Note that the resize grip is only shown if the window is
+   * actually resizable and not maximized. Use
+   * #GtkWindow:resize-grip-visible to find out if the resize
+   * grip is currently shown.
+   *
+   * Since: 3.0
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_HAS_RESIZE_GRIP,
+                                   g_param_spec_boolean ("has-resize-grip",
+                                                         P_("Resize grip"),
+                                                         P_("Specifies whether the window should have a resize grip"),
+                                                         TRUE,
+                                                         GTK_PARAM_READWRITE));
+
+  /**
+   * GtkWindow:resize-grip-visible:
+   *
+   * Whether a corner resize grip is currently shown.
+   *
+   * Since: 3.0
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_RESIZE_GRIP_VISIBLE,
+                                   g_param_spec_boolean ("resize-grip-visible",
+                                                         P_("Resize grip is visible"),
+                                                         P_("Specifies whether the window's resize grip is visible."),
+                                                         FALSE,
+                                                         GTK_PARAM_READABLE));
+
 
   /**
    * GtkWindow:gravity:
@@ -809,22 +961,63 @@ gtk_window_class_init (GtkWindowClass *klass)
                                                        GTK_PARAM_READWRITE| G_PARAM_CONSTRUCT));
 
   /**
-   * GtkWindow:opacity:
+   * GtkWindow:attached-to:
    *
-   * The requested opacity of the window. See gtk_window_set_opacity() for
-   * more details about window opacity.
+   * The widget to which this window is attached.
+   * See gtk_window_set_attached_to().
    *
-   * Since: 2.12
+   * Examples of places where specifying this relation is useful are
+   * for instance a #GtkMenu created by a #GtkComboBox, a completion
+   * popup window created by #GtkEntry or a typeahead search entry
+   * created by #GtkTreeView.
+   *
+   * Since: 3.4
    */
   g_object_class_install_property (gobject_class,
-                                  PROP_OPACITY,
-                                  g_param_spec_double ("opacity",
-                                                       P_("Opacity for Window"),
-                                                       P_("The opacity of the window, from 0 to 1"),
-                                                       0.0,
-                                                       1.0,
-                                                       1.0,
-                                                       GTK_PARAM_READWRITE));
+                                   PROP_ATTACHED_TO,
+                                   g_param_spec_object ("attached-to",
+                                                        P_("Attached to Widget"),
+                                                        P_("The widget where the window is attached"),
+                                                        GTK_TYPE_WIDGET,
+                                                        GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  /* Style properties.
+   */
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_int ("resize-grip-width",
+                                                             P_("Width of resize grip"),
+                                                             P_("Width of resize grip"),
+                                                             0, G_MAXINT, 16, GTK_PARAM_READWRITE));
+
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_int ("resize-grip-height",
+                                                             P_("Height of resize grip"),
+                                                             P_("Height of resize grip"),
+                                                             0, G_MAXINT, 16, GTK_PARAM_READWRITE));
+
+
+  /**
+   * GtkWindow:application:
+   *
+   * The #GtkApplication associated with the window.
+   *
+   * The application will be kept alive for at least as long as it
+   * has any windows associated with it (see g_application_hold()
+   * for a way to keep it alive without windows).
+   *
+   * Normally, the connection between the application and the window
+   * will remain until the window is destroyed, but you can explicitly
+   * remove it by setting the ::application property to %NULL.
+   *
+   * Since: 3.0
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_APPLICATION,
+                                   g_param_spec_object ("application",
+                                                        P_("GtkApplication"),
+                                                        P_("The GtkApplication for the window"),
+                                                        GTK_TYPE_APPLICATION,
+                                                        GTK_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   window_signals[SET_FOCUS] =
     g_signal_new (I_("set-focus"),
@@ -835,16 +1028,6 @@ gtk_window_class_init (GtkWindowClass *klass)
                   _gtk_marshal_VOID__OBJECT,
                   G_TYPE_NONE, 1,
                   GTK_TYPE_WIDGET);
-  
-  window_signals[FRAME_EVENT] =
-    g_signal_new (I_("frame-event"),
-                  G_TYPE_FROM_CLASS (gobject_class),
-                  G_SIGNAL_RUN_LAST,
-                  G_STRUCT_OFFSET(GtkWindowClass, frame_event),
-                  _gtk_boolean_handled_accumulator, NULL,
-                  _gtk_marshal_BOOLEAN__BOXED,
-                  G_TYPE_BOOLEAN, 1,
-                  GDK_TYPE_EVENT);
 
   /**
    * GtkWindow::activate-focus:
@@ -907,89 +1090,96 @@ gtk_window_class_init (GtkWindowClass *klass)
 
   binding_set = gtk_binding_set_by_class (klass);
 
-  gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
                                 "activate-focus", 0);
-  gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
                                 "activate-focus", 0);
   
-  gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
                                 "activate-default", 0);
-  gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
                                 "activate-default", 0);
-  gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
                                 "activate-default", 0);
 
-  add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
-  add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
-  add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
-  add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
+  add_arrow_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP);
+  add_arrow_bindings (binding_set, GDK_KEY_Down, GTK_DIR_DOWN);
+  add_arrow_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT);
+  add_arrow_bindings (binding_set, GDK_KEY_Right, GTK_DIR_RIGHT);
 
   add_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
   add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
   add_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
   add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
+
+  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_WINDOW_ACCESSIBLE);
 }
 
 static void
 gtk_window_init (GtkWindow *window)
 {
-  GdkColormap *colormap;
-  GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (window);
+  GtkStyleContext *context;
+  GtkWindowPrivate *priv;
+
+  window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
+                                              GTK_TYPE_WINDOW,
+                                              GtkWindowPrivate);
+  priv = window->priv;
   
   gtk_widget_set_has_window (GTK_WIDGET (window), TRUE);
   _gtk_widget_set_is_toplevel (GTK_WIDGET (window), TRUE);
 
-  GTK_PRIVATE_SET_FLAG (window, GTK_ANCHORED);
+  _gtk_widget_set_anchored (GTK_WIDGET (window), TRUE);
 
   gtk_container_set_resize_mode (GTK_CONTAINER (window), GTK_RESIZE_QUEUE);
 
-  window->title = NULL;
-  window->wmclass_name = g_strdup (g_get_prgname ());
-  window->wmclass_class = g_strdup (gdk_get_program_class ());
-  window->wm_role = NULL;
-  window->geometry_info = NULL;
-  window->type = GTK_WINDOW_TOPLEVEL;
-  window->focus_widget = NULL;
-  window->default_widget = NULL;
-  window->configure_request_count = 0;
-  window->resizable = TRUE;
-  window->configure_notify_received = FALSE;
-  window->position = GTK_WIN_POS_NONE;
-  window->need_default_size = TRUE;
-  window->need_default_position = TRUE;
-  window->modal = FALSE;
-  window->frame = NULL;
-  window->has_frame = FALSE;
-  window->frame_left = 0;
-  window->frame_right = 0;
-  window->frame_top = 0;
-  window->frame_bottom = 0;
-  window->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
-  window->gravity = GDK_GRAVITY_NORTH_WEST;
-  window->decorated = TRUE;
-  window->mnemonic_modifier = GDK_MOD1_MASK;
-  window->screen = gdk_screen_get_default ();
+  priv->title = NULL;
+  priv->wmclass_name = g_strdup (g_get_prgname ());
+  priv->wmclass_class = g_strdup (gdk_get_program_class ());
+  priv->wm_role = NULL;
+  priv->geometry_info = NULL;
+  priv->type = GTK_WINDOW_TOPLEVEL;
+  priv->focus_widget = NULL;
+  priv->default_widget = NULL;
+  priv->configure_request_count = 0;
+  priv->resizable = TRUE;
+  priv->configure_notify_received = FALSE;
+  priv->position = GTK_WIN_POS_NONE;
+  priv->need_default_size = TRUE;
+  priv->need_default_position = TRUE;
+  priv->modal = FALSE;
+  priv->gdk_type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
+  priv->gravity = GDK_GRAVITY_NORTH_WEST;
+  priv->decorated = TRUE;
+  priv->mnemonic_modifier = GDK_MOD1_MASK;
+  priv->screen = gdk_screen_get_default ();
 
   priv->accept_focus = TRUE;
   priv->focus_on_map = TRUE;
   priv->deletable = TRUE;
   priv->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
-  priv->opacity = 1.0;
   priv->startup_id = NULL;
+  priv->initial_timestamp = GDK_CURRENT_TIME;
+  priv->has_resize_grip = TRUE;
   priv->mnemonics_visible = TRUE;
+  priv->focus_visible = TRUE;
 
-  colormap = _gtk_widget_peek_colormap ();
-  if (colormap)
-    gtk_widget_set_colormap (GTK_WIDGET (window), colormap);
-  
   g_object_ref_sink (window);
-  window->has_user_ref_count = TRUE;
+  priv->has_user_ref_count = TRUE;
   toplevel_list = g_slist_prepend (toplevel_list, window);
 
-  gtk_decorated_window_init (window);
+  if (priv->screen)
+    g_signal_connect (priv->screen, "composited-changed",
+                      G_CALLBACK (gtk_window_on_composited_changed), window);
+
+#ifdef GDK_WINDOWING_X11
+  g_signal_connect (gtk_settings_get_for_screen (priv->screen),
+                    "notify::gtk-application-prefer-dark-theme",
+                    G_CALLBACK (gtk_window_on_theme_variant_changed), window);
+#endif
 
-  g_signal_connect (window->screen, "composited-changed",
-                   G_CALLBACK (gtk_window_on_composited_changed), window);
+  context = gtk_widget_get_style_context (GTK_WIDGET (window));
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_BACKGROUND);
 }
 
 static void
@@ -998,17 +1188,13 @@ gtk_window_set_property (GObject      *object,
                         const GValue *value,
                         GParamSpec   *pspec)
 {
-  GtkWindow  *window;
-  GtkWindowPrivate *priv;
-  
-  window = GTK_WINDOW (object);
-
-  priv = GTK_WINDOW_GET_PRIVATE (window);
+  GtkWindow  *window = GTK_WINDOW (object);
+  GtkWindowPrivate *priv = window->priv;
 
   switch (prop_id)
     {
     case PROP_TYPE:
-      window->type = g_value_get_enum (value);
+      priv->type = g_value_get_enum (value);
       break;
     case PROP_TITLE:
       gtk_window_set_title (window, g_value_get_string (value));
@@ -1018,10 +1204,9 @@ gtk_window_set_property (GObject      *object,
       break;
     case PROP_STARTUP_ID:
       gtk_window_set_startup_id (window, g_value_get_string (value));
-      break; 
+      break;
     case PROP_RESIZABLE:
-      window->resizable = g_value_get_boolean (value);
-      gtk_widget_queue_resize (GTK_WIDGET (window));
+      gtk_window_set_resizable (window, g_value_get_boolean (value));
       break;
     case PROP_MODAL:
       gtk_window_set_modal (window, g_value_get_boolean (value));
@@ -1042,6 +1227,9 @@ gtk_window_set_property (GObject      *object,
     case PROP_DESTROY_WITH_PARENT:
       gtk_window_set_destroy_with_parent (window, g_value_get_boolean (value));
       break;
+    case PROP_HIDE_TITLEBAR_WHEN_MAXIMIZED:
+      gtk_window_set_hide_titlebar_when_maximized (window, g_value_get_boolean (value));
+      break;
     case PROP_ICON:
       gtk_window_set_icon (window,
                            g_value_get_object (value));
@@ -1088,12 +1276,21 @@ gtk_window_set_property (GObject      *object,
     case PROP_TRANSIENT_FOR:
       gtk_window_set_transient_for (window, g_value_get_object (value));
       break;
-    case PROP_OPACITY:
-      gtk_window_set_opacity (window, g_value_get_double (value));
+    case PROP_ATTACHED_TO:
+      gtk_window_set_attached_to (window, g_value_get_object (value));
+      break;
+    case PROP_HAS_RESIZE_GRIP:
+      gtk_window_set_has_resize_grip (window, g_value_get_boolean (value));
+      break;
+    case PROP_APPLICATION:
+      gtk_window_set_application (window, g_value_get_object (value));
       break;
     case PROP_MNEMONICS_VISIBLE:
       gtk_window_set_mnemonics_visible (window, g_value_get_boolean (value));
       break;
+    case PROP_FOCUS_VISIBLE:
+      gtk_window_set_focus_visible (window, g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1106,32 +1303,29 @@ gtk_window_get_property (GObject      *object,
                         GValue       *value,
                         GParamSpec   *pspec)
 {
-  GtkWindow  *window;
-  GtkWindowPrivate *priv;
+  GtkWindow  *window = GTK_WINDOW (object);
+  GtkWindowPrivate *priv = window->priv;
 
-  window = GTK_WINDOW (object);
-  priv = GTK_WINDOW_GET_PRIVATE (window);
-  
   switch (prop_id)
     {
       GtkWindowGeometryInfo *info;
     case PROP_TYPE:
-      g_value_set_enum (value, window->type);
+      g_value_set_enum (value, priv->type);
       break;
     case PROP_ROLE:
-      g_value_set_string (value, window->wm_role);
+      g_value_set_string (value, priv->wm_role);
       break;
     case PROP_TITLE:
-      g_value_set_string (value, window->title);
+      g_value_set_string (value, priv->title);
       break;
     case PROP_RESIZABLE:
-      g_value_set_boolean (value, window->resizable);
+      g_value_set_boolean (value, priv->resizable);
       break;
     case PROP_MODAL:
-      g_value_set_boolean (value, window->modal);
+      g_value_set_boolean (value, priv->modal);
       break;
     case PROP_WIN_POS:
-      g_value_set_enum (value, window->position);
+      g_value_set_enum (value, priv->position);
       break;
     case PROP_DEFAULT_WIDTH:
       info = gtk_window_get_geometry_info (window, FALSE);
@@ -1148,7 +1342,10 @@ gtk_window_get_property (GObject      *object,
        g_value_set_int (value, info->default_height);
       break;
     case PROP_DESTROY_WITH_PARENT:
-      g_value_set_boolean (value, window->destroy_with_parent);
+      g_value_set_boolean (value, priv->destroy_with_parent);
+      break;
+    case PROP_HIDE_TITLEBAR_WHEN_MAXIMIZED:
+      g_value_set_boolean (value, priv->hide_titlebar_when_maximized);
       break;
     case PROP_ICON:
       g_value_set_object (value, gtk_window_get_icon (window));
@@ -1157,13 +1354,13 @@ gtk_window_get_property (GObject      *object,
       g_value_set_string (value, gtk_window_get_icon_name (window));
       break;
     case PROP_SCREEN:
-      g_value_set_object (value, window->screen);
+      g_value_set_object (value, priv->screen);
       break;
     case PROP_IS_ACTIVE:
-      g_value_set_boolean (value, window->is_active);
+      g_value_set_boolean (value, priv->is_active);
       break;
     case PROP_HAS_TOPLEVEL_FOCUS:
-      g_value_set_boolean (value, window->has_toplevel_focus);
+      g_value_set_boolean (value, priv->has_toplevel_focus);
       break;
     case PROP_TYPE_HINT:
       g_value_set_enum (value, priv->type_hint);
@@ -1200,12 +1397,24 @@ gtk_window_get_property (GObject      *object,
     case PROP_TRANSIENT_FOR:
       g_value_set_object (value, gtk_window_get_transient_for (window));
       break;
-    case PROP_OPACITY:
-      g_value_set_double (value, gtk_window_get_opacity (window));
+    case PROP_ATTACHED_TO:
+      g_value_set_object (value, gtk_window_get_attached_to (window));
+      break;
+    case PROP_HAS_RESIZE_GRIP:
+      g_value_set_boolean (value, priv->has_resize_grip);
+      break;
+    case PROP_RESIZE_GRIP_VISIBLE:
+      g_value_set_boolean (value, gtk_window_resize_grip_is_visible (window));
+      break;
+    case PROP_APPLICATION:
+      g_value_set_object (value, gtk_window_get_application (window));
       break;
     case PROP_MNEMONICS_VISIBLE:
       g_value_set_boolean (value, priv->mnemonics_visible);
       break;
+    case PROP_FOCUS_VISIBLE:
+      g_value_set_boolean (value, priv->focus_visible);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1228,7 +1437,8 @@ gtk_window_buildable_set_buildable_property (GtkBuildable        *buildable,
                                             const gchar         *name,
                                             const GValue        *value)
 {
-  GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (buildable);
+  GtkWindow *window = GTK_WINDOW (buildable);
+  GtkWindowPrivate *priv = window->priv;
 
   if (strcmp (name, "visible") == 0 && g_value_get_boolean (value))
     priv->builder_visible = TRUE;
@@ -1240,7 +1450,8 @@ static void
 gtk_window_buildable_parser_finished (GtkBuildable *buildable,
                                      GtkBuilder   *builder)
 {
-  GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (buildable);
+  GtkWindow *window = GTK_WINDOW (buildable);
+  GtkWindowPrivate *priv = window->priv;
   GObject *object;
   GSList *accels, *l;
 
@@ -1377,13 +1588,15 @@ gtk_window_buildable_custom_finished (GtkBuildable  *buildable,
 GtkWidget*
 gtk_window_new (GtkWindowType type)
 {
+  GtkWindowPrivate *priv;
   GtkWindow *window;
 
   g_return_val_if_fail (type >= GTK_WINDOW_TOPLEVEL && type <= GTK_WINDOW_POPUP, NULL);
 
   window = g_object_new (GTK_TYPE_WINDOW, NULL);
+  priv = window->priv;
 
-  window->type = type;
+  priv->type = type;
 
   return GTK_WIDGET (window);
 }
@@ -1407,19 +1620,23 @@ void
 gtk_window_set_title (GtkWindow   *window,
                      const gchar *title)
 {
+  GtkWindowPrivate *priv;
+  GtkWidget *widget;
   char *new_title;
   
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
+  widget = GTK_WIDGET (window);
+
   new_title = g_strdup (title);
-  g_free (window->title);
-  window->title = new_title;
+  g_free (priv->title);
+  priv->title = new_title;
 
-  if (gtk_widget_get_realized (GTK_WIDGET (window)))
+  if (gtk_widget_get_realized (widget))
     {
-      gdk_window_set_title (GTK_WIDGET (window)->window, window->title);
-
-      gtk_decorated_window_set_title (window, title);
+      gdk_window_set_title (gtk_widget_get_window (widget),
+                            priv->title);
     }
 
   g_object_notify (G_OBJECT (window), "title");
@@ -1435,12 +1652,12 @@ gtk_window_set_title (GtkWindow   *window,
  *    been set explicitely. The returned string is owned by the widget
  *    and must not be modified or freed.
  **/
-G_CONST_RETURN gchar *
+const gchar *
 gtk_window_get_title (GtkWindow *window)
 {
   g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
 
-  return window->title;
+  return window->priv->title;
 }
 
 /**
@@ -1464,13 +1681,17 @@ gtk_window_set_wmclass (GtkWindow *window,
                        const gchar *wmclass_name,
                        const gchar *wmclass_class)
 {
+  GtkWindowPrivate *priv;
+
   g_return_if_fail (GTK_IS_WINDOW (window));
 
-  g_free (window->wmclass_name);
-  window->wmclass_name = g_strdup (wmclass_name);
+  priv = window->priv;
 
-  g_free (window->wmclass_class);
-  window->wmclass_class = g_strdup (wmclass_class);
+  g_free (priv->wmclass_name);
+  priv->wmclass_name = g_strdup (wmclass_name);
+
+  g_free (priv->wmclass_class);
+  priv->wmclass_class = g_strdup (wmclass_class);
 
   if (gtk_widget_get_realized (GTK_WIDGET (window)))
     g_warning ("gtk_window_set_wmclass: shouldn't set wmclass after window is realized!\n");
@@ -1499,16 +1720,20 @@ void
 gtk_window_set_role (GtkWindow   *window,
                      const gchar *role)
 {
+  GtkWindowPrivate *priv;
   char *new_role;
   
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
+
   new_role = g_strdup (role);
-  g_free (window->wm_role);
-  window->wm_role = new_role;
+  g_free (priv->wm_role);
+  priv->wm_role = new_role;
 
   if (gtk_widget_get_realized (GTK_WIDGET (window)))
-    gdk_window_set_role (GTK_WIDGET (window)->window, window->wm_role);
+    gdk_window_set_role (gtk_widget_get_window (GTK_WIDGET (window)),
+                         priv->wm_role);
 
   g_object_notify (G_OBJECT (window), "role");
 }
@@ -1536,21 +1761,26 @@ gtk_window_set_startup_id (GtkWindow   *window,
                            const gchar *startup_id)
 {
   GtkWindowPrivate *priv;
+  GtkWidget *widget;
 
   g_return_if_fail (GTK_IS_WINDOW (window));
 
-  priv = GTK_WINDOW_GET_PRIVATE (window);
-  
+  priv = window->priv;
+  widget = GTK_WIDGET (window);
+
   g_free (priv->startup_id);
   priv->startup_id = g_strdup (startup_id);
 
-  if (gtk_widget_get_realized (GTK_WIDGET (window)))
+  if (gtk_widget_get_realized (widget))
     {
+      GdkWindow *gdk_window;
       guint32 timestamp = extract_time_from_startup_id (priv->startup_id);
 
+      gdk_window = gtk_widget_get_window (widget);
+
 #ifdef GDK_WINDOWING_X11
-      if (timestamp != GDK_CURRENT_TIME)
-       gdk_x11_window_set_user_time (GTK_WIDGET (window)->window, timestamp);
+      if (timestamp != GDK_CURRENT_TIME && GDK_IS_X11_WINDOW(gdk_window))
+       gdk_x11_window_set_user_time (gdk_window, timestamp);
 #endif
 
       /* Here we differentiate real and "fake" startup notification IDs,
@@ -1560,11 +1790,11 @@ gtk_window_set_startup_id (GtkWindow   *window,
        gtk_window_present_with_time (window, timestamp);
       else 
         {
-          gdk_window_set_startup_id (GTK_WIDGET (window)->window,
+          gdk_window_set_startup_id (gdk_window,
                                      priv->startup_id);
           
           /* If window is mapped, terminate the startup-notification too */
-          if (gtk_widget_get_mapped (GTK_WIDGET (window)) &&
+          if (gtk_widget_get_mapped (widget) &&
               !disable_startup_notification)
             gdk_notify_startup_complete_with_id (priv->startup_id);
         }
@@ -1584,12 +1814,12 @@ gtk_window_set_startup_id (GtkWindow   *window,
  *   returned is owned by the widget and must not be modified
  *   or freed.
  **/
-G_CONST_RETURN gchar *
+const gchar *
 gtk_window_get_role (GtkWindow *window)
 {
   g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
 
-  return window->wm_role;
+  return window->priv->wm_role;
 }
 
 /**
@@ -1608,7 +1838,13 @@ void
 gtk_window_set_focus (GtkWindow *window,
                      GtkWidget *focus)
 {
+  GtkWindowPrivate *priv;
+  GtkWidget *parent;
+
   g_return_if_fail (GTK_IS_WINDOW (window));
+
+  priv = window->priv;
+
   if (focus)
     {
       g_return_if_fail (GTK_IS_WIDGET (focus));
@@ -1622,12 +1858,12 @@ gtk_window_set_focus (GtkWindow *window,
       /* Clear the existing focus chain, so that when we focus into
        * the window again, we start at the beginnning.
        */
-      GtkWidget *widget = window->focus_widget;
+      GtkWidget *widget = priv->focus_widget;
       if (widget)
        {
-         while (widget->parent)
+         while ((parent = gtk_widget_get_parent (widget)))
            {
-             widget = widget->parent;
+             widget = parent;
              gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
            }
        }
@@ -1640,9 +1876,13 @@ void
 _gtk_window_internal_set_focus (GtkWindow *window,
                                GtkWidget *focus)
 {
+  GtkWindowPrivate *priv;
+
   g_return_if_fail (GTK_IS_WINDOW (window));
 
-  if ((window->focus_widget != focus) ||
+  priv = window->priv;
+
+  if ((priv->focus_widget != focus) ||
       (focus && !gtk_widget_has_focus (focus)))
     g_signal_emit (window, window_signals[SET_FOCUS], 0, focus);
 }
@@ -1658,43 +1898,49 @@ _gtk_window_internal_set_focus (GtkWindow *window,
  * unsets the default widget for a #GtkWindow about. When setting
  * (rather than unsetting) the default widget it's generally easier to
  * call gtk_widget_grab_focus() on the widget. Before making a widget
- * the default widget, you must set the #GTK_CAN_DEFAULT flag on the
- * widget you'd like to make the default using GTK_WIDGET_SET_FLAGS().
+ * the default widget, you must call gtk_widget_set_can_default() on the
+ * widget you'd like to make the default.
  **/
 void
 gtk_window_set_default (GtkWindow *window,
                        GtkWidget *default_widget)
 {
+  GtkWindowPrivate *priv;
+
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
+
   if (default_widget)
     g_return_if_fail (gtk_widget_get_can_default (default_widget));
-  
-  if (window->default_widget != default_widget)
+
+  if (priv->default_widget != default_widget)
     {
       GtkWidget *old_default_widget = NULL;
       
       if (default_widget)
        g_object_ref (default_widget);
-      
-      if (window->default_widget)
+
+      if (priv->default_widget)
        {
-         old_default_widget = window->default_widget;
-         
-         if (window->focus_widget != window->default_widget ||
-             !gtk_widget_get_receives_default (window->default_widget))
-            _gtk_widget_set_has_default (window->default_widget, FALSE);
-         gtk_widget_queue_draw (window->default_widget);
+          old_default_widget = priv->default_widget;
+
+          if (priv->focus_widget != priv->default_widget ||
+              !gtk_widget_get_receives_default (priv->default_widget))
+            _gtk_widget_set_has_default (priv->default_widget, FALSE);
+
+          gtk_widget_queue_draw (priv->default_widget);
        }
 
-      window->default_widget = default_widget;
+      priv->default_widget = default_widget;
 
-      if (window->default_widget)
+      if (priv->default_widget)
        {
-         if (window->focus_widget == NULL ||
-             !gtk_widget_get_receives_default (window->focus_widget))
-            _gtk_widget_set_has_default (window->default_widget, TRUE);
-         gtk_widget_queue_draw (window->default_widget);
+          if (priv->focus_widget == NULL ||
+              !gtk_widget_get_receives_default (priv->focus_widget))
+            _gtk_widget_set_has_default (priv->default_widget, TRUE);
+
+          gtk_widget_queue_draw (priv->default_widget);
        }
 
       if (old_default_widget)
@@ -1715,7 +1961,7 @@ gtk_window_set_default (GtkWindow *window,
  * Returns the default widget for @window. See gtk_window_set_default()
  * for more details.
  *
- * Returns: the default widget, or %NULL if there is none.
+ * Returns: (transfer none): the default widget, or %NULL if there is none.
  *
  * Since: 2.14
  **/
@@ -1724,20 +1970,19 @@ gtk_window_get_default_widget (GtkWindow *window)
 {
   g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
 
-  return window->default_widget;
+  return window->priv->default_widget;
 }
 
 static gboolean
 handle_keys_changed (gpointer data)
 {
-  GtkWindow *window;
-
-  window = GTK_WINDOW (data);
+  GtkWindow *window = GTK_WINDOW (data);
+  GtkWindowPrivate *priv = window->priv;
 
-  if (window->keys_changed_handler)
+  if (priv->keys_changed_handler)
     {
-      g_source_remove (window->keys_changed_handler);
-      window->keys_changed_handler = 0;
+      g_source_remove (priv->keys_changed_handler);
+      priv->keys_changed_handler = 0;
     }
 
   g_signal_emit (window, window_signals[KEYS_CHANGED], 0);
@@ -1748,8 +1993,10 @@ handle_keys_changed (gpointer data)
 static void
 gtk_window_notify_keys_changed (GtkWindow *window)
 {
-  if (!window->keys_changed_handler)
-    window->keys_changed_handler = gdk_threads_add_idle (handle_keys_changed, window);
+  GtkWindowPrivate *priv = window->priv;
+
+  if (!priv->keys_changed_handler)
+    priv->keys_changed_handler = gdk_threads_add_idle (handle_keys_changed, window);
 }
 
 /**
@@ -1800,10 +2047,11 @@ static GtkMnemonicHash *
 gtk_window_get_mnemonic_hash (GtkWindow *window,
                              gboolean   create)
 {
-  GtkWindowPrivate *private = GTK_WINDOW_GET_PRIVATE (window);
+  GtkWindowPrivate *private = window->priv;
+
   if (!private->mnemonic_hash && create)
     private->mnemonic_hash = _gtk_mnemonic_hash_new ();
-  
+
   return private->mnemonic_hash;
 }
 
@@ -1853,19 +2101,24 @@ gtk_window_remove_mnemonic (GtkWindow *window,
  * gtk_window_mnemonic_activate:
  * @window: a #GtkWindow
  * @keyval: the mnemonic
- * @modifier: the modifiers 
- * @returns: %TRUE if the activation is done. 
- * 
+ * @modifier: the modifiers
+ *
  * Activates the targets associated with the mnemonic.
+ *
+ * Returns: %TRUE if the activation is done.
  */
 gboolean
 gtk_window_mnemonic_activate (GtkWindow      *window,
                              guint           keyval,
                              GdkModifierType modifier)
 {
+  GtkWindowPrivate *priv;
+
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
 
-  if (window->mnemonic_modifier == (modifier & gtk_accelerator_get_default_mod_mask ()))
+  priv = window->priv;
+
+  if (priv->mnemonic_modifier == (modifier & gtk_accelerator_get_default_mod_mask ()))
       {
        GtkMnemonicHash *mnemonic_hash = gtk_window_get_mnemonic_hash (window, FALSE);
        if (mnemonic_hash)
@@ -1887,10 +2140,14 @@ void
 gtk_window_set_mnemonic_modifier (GtkWindow      *window,
                                  GdkModifierType modifier)
 {
+  GtkWindowPrivate *priv;
+
   g_return_if_fail (GTK_IS_WINDOW (window));
   g_return_if_fail ((modifier & ~GDK_MODIFIER_MASK) == 0);
 
-  window->mnemonic_modifier = modifier;
+  priv = window->priv;
+
+  priv->mnemonic_modifier = modifier;
   gtk_window_notify_keys_changed (window);
 }
 
@@ -1909,7 +2166,7 @@ gtk_window_get_mnemonic_modifier (GtkWindow *window)
 {
   g_return_val_if_fail (GTK_IS_WINDOW (window), 0);
 
-  return window->mnemonic_modifier;
+  return window->priv->mnemonic_modifier;
 }
 
 /**
@@ -1925,10 +2182,14 @@ void
 gtk_window_set_position (GtkWindow         *window,
                         GtkWindowPosition  position)
 {
+  GtkWindowPrivate *priv;
+
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
+
   if (position == GTK_WIN_POS_CENTER_ALWAYS ||
-      window->position == GTK_WIN_POS_CENTER_ALWAYS)
+      priv->position == GTK_WIN_POS_CENTER_ALWAYS)
     {
       GtkWindowGeometryInfo *info;
 
@@ -1943,7 +2204,7 @@ gtk_window_set_position (GtkWindow         *window,
       gtk_widget_queue_resize_no_redraw (GTK_WIDGET (window));
     }
 
-  window->position = position;
+  priv->position = position;
   
   g_object_notify (G_OBJECT (window), "window-position");
 }
@@ -1959,10 +2220,14 @@ gtk_window_set_position (GtkWindow         *window,
 gboolean 
 gtk_window_activate_focus (GtkWindow *window)
 {
+  GtkWindowPrivate *priv;
+
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
 
-  if (window->focus_widget && gtk_widget_is_sensitive (window->focus_widget))
-    return gtk_widget_activate (window->focus_widget);
+  priv = window->priv;
+
+  if (priv->focus_widget && gtk_widget_is_sensitive (priv->focus_widget))
+    return gtk_widget_activate (priv->focus_widget);
 
   return FALSE;
 }
@@ -1984,7 +2249,7 @@ gtk_window_get_focus (GtkWindow *window)
 {
   g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
 
-  return window->focus_widget;
+  return window->priv->focus_widget;
 }
 
 /**
@@ -2001,13 +2266,17 @@ gtk_window_get_focus (GtkWindow *window)
 gboolean
 gtk_window_activate_default (GtkWindow *window)
 {
+  GtkWindowPrivate *priv;
+
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
 
-  if (window->default_widget && gtk_widget_is_sensitive (window->default_widget) &&
-      (!window->focus_widget || !gtk_widget_get_receives_default (window->focus_widget)))
-    return gtk_widget_activate (window->default_widget);
-  else if (window->focus_widget && gtk_widget_is_sensitive (window->focus_widget))
-    return gtk_widget_activate (window->focus_widget);
+  priv = window->priv;
+
+  if (priv->default_widget && gtk_widget_is_sensitive (priv->default_widget) &&
+      (!priv->focus_widget || !gtk_widget_get_receives_default (priv->focus_widget)))
+    return gtk_widget_activate (priv->default_widget);
+  else if (priv->focus_widget && gtk_widget_is_sensitive (priv->focus_widget))
+    return gtk_widget_activate (priv->focus_widget);
 
   return FALSE;
 }
@@ -2030,29 +2299,32 @@ void
 gtk_window_set_modal (GtkWindow *window,
                      gboolean   modal)
 {
+  GtkWindowPrivate *priv;
   GtkWidget *widget;
 
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
+
   modal = modal != FALSE;
-  if (window->modal == modal)
+  if (priv->modal == modal)
     return;
-  
-  window->modal = modal;
+
+  priv->modal = modal;
   widget = GTK_WIDGET (window);
   
   /* adjust desired modality state */
   if (gtk_widget_get_realized (widget))
     {
-      if (window->modal)
-       gdk_window_set_modal_hint (widget->window, TRUE);
+      if (priv->modal)
+       gdk_window_set_modal_hint (gtk_widget_get_window (widget), TRUE);
       else
-       gdk_window_set_modal_hint (widget->window, FALSE);
+       gdk_window_set_modal_hint (gtk_widget_get_window (widget), FALSE);
     }
 
   if (gtk_widget_get_visible (widget))
     {
-      if (window->modal)
+      if (priv->modal)
        gtk_grab_add (widget);
       else
        gtk_grab_remove (widget);
@@ -2075,7 +2347,7 @@ gtk_window_get_modal (GtkWindow *window)
 {
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
 
-  return window->modal;
+  return window->priv->modal;
 }
 
 /**
@@ -2102,58 +2374,18 @@ gtk_window_list_toplevels (void)
   return list;
 }
 
-void
-gtk_window_add_embedded_xid (GtkWindow *window, GdkNativeWindow xid)
-{
-  GList *embedded_windows;
-
-  g_return_if_fail (GTK_IS_WINDOW (window));
-
-  embedded_windows = g_object_get_qdata (G_OBJECT (window), quark_gtk_embedded);
-  if (embedded_windows)
-    g_object_steal_qdata (G_OBJECT (window), quark_gtk_embedded);
-  embedded_windows = g_list_prepend (embedded_windows,
-                                    GUINT_TO_POINTER (xid));
-
-  g_object_set_qdata_full (G_OBJECT (window), quark_gtk_embedded, 
-                          embedded_windows,
-                          embedded_windows ?
-                          (GDestroyNotify) g_list_free : NULL);
-}
-
-void
-gtk_window_remove_embedded_xid (GtkWindow *window, GdkNativeWindow xid)
+static void
+remove_attach_widget (GtkWindow *window)
 {
-  GList *embedded_windows;
-  GList *node;
-
-  g_return_if_fail (GTK_IS_WINDOW (window));
-  
-  embedded_windows = g_object_get_qdata (G_OBJECT (window), quark_gtk_embedded);
-  if (embedded_windows)
-    g_object_steal_qdata (G_OBJECT (window), quark_gtk_embedded);
+  GtkWindowPrivate *priv = window->priv;
 
-  node = g_list_find (embedded_windows, GUINT_TO_POINTER (xid));
-  if (node)
+  if (priv->attach_widget)
     {
-      embedded_windows = g_list_remove_link (embedded_windows, node);
-      g_list_free_1 (node);
-    }
-  
-  g_object_set_qdata_full (G_OBJECT (window), quark_gtk_embedded,
-                          embedded_windows,
-                          embedded_windows ?
-                          (GDestroyNotify) g_list_free : NULL);
-}
-
-void       
-_gtk_window_reposition (GtkWindow *window,
-                       gint       x,
-                       gint       y)
-{
-  g_return_if_fail (GTK_IS_WINDOW (window));
+      _gtk_widget_remove_attached_window (priv->attach_widget, window);
 
-  gtk_window_move (window, x, y);
+      g_object_unref (priv->attach_widget);
+      priv->attach_widget = NULL;
+    }
 }
 
 static void
@@ -2164,6 +2396,8 @@ gtk_window_dispose (GObject *object)
   gtk_window_set_focus (window, NULL);
   gtk_window_set_default (window, NULL);
 
+  remove_attach_widget (GTK_WINDOW (object));
+
   G_OBJECT_CLASS (gtk_window_parent_class)->dispose (object);
 }
 
@@ -2176,9 +2410,11 @@ parent_destroyed_callback (GtkWindow *parent, GtkWindow *child)
 static void
 connect_parent_destroyed (GtkWindow *window)
 {
-  if (window->transient_parent)
+  GtkWindowPrivate *priv = window->priv;
+
+  if (priv->transient_parent)
     {
-      g_signal_connect (window->transient_parent,
+      g_signal_connect (priv->transient_parent,
                         "destroy",
                         G_CALLBACK (parent_destroyed_callback),
                         window);
@@ -2188,9 +2424,11 @@ connect_parent_destroyed (GtkWindow *window)
 static void
 disconnect_parent_destroyed (GtkWindow *window)
 {
-  if (window->transient_parent)
+  GtkWindowPrivate *priv = window->priv;
+
+  if (priv->transient_parent)
     {
-      g_signal_handlers_disconnect_by_func (window->transient_parent,
+      g_signal_handlers_disconnect_by_func (priv->transient_parent,
                                            parent_destroyed_callback,
                                            window);
     }
@@ -2200,16 +2438,17 @@ static void
 gtk_window_transient_parent_realized (GtkWidget *parent,
                                      GtkWidget *window)
 {
-  if (gtk_widget_get_realized (GTK_WIDGET (window)))
-    gdk_window_set_transient_for (window->window, parent->window);
+  if (gtk_widget_get_realized (window))
+    gdk_window_set_transient_for (gtk_widget_get_window (window),
+                                  gtk_widget_get_window (parent));
 }
 
 static void
 gtk_window_transient_parent_unrealized (GtkWidget *parent,
                                        GtkWidget *window)
 {
-  if (gtk_widget_get_realized (GTK_WIDGET (window)))
-    gdk_property_delete (window->window, 
+  if (gtk_widget_get_realized (window))
+    gdk_property_delete (gtk_widget_get_window (window),
                         gdk_atom_intern_static_string ("WM_TRANSIENT_FOR"));
 }
 
@@ -2218,38 +2457,38 @@ gtk_window_transient_parent_screen_changed (GtkWindow   *parent,
                                            GParamSpec  *pspec,
                                            GtkWindow   *window)
 {
-  gtk_window_set_screen (window, parent->screen);
+  gtk_window_set_screen (window, parent->priv->screen);
 }
 
 static void       
 gtk_window_unset_transient_for  (GtkWindow *window)
 {
-  GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (window);
-  
-  if (window->transient_parent)
+  GtkWindowPrivate *priv = window->priv;
+
+  if (priv->transient_parent)
     {
-      g_signal_handlers_disconnect_by_func (window->transient_parent,
+      g_signal_handlers_disconnect_by_func (priv->transient_parent,
                                            gtk_window_transient_parent_realized,
                                            window);
-      g_signal_handlers_disconnect_by_func (window->transient_parent,
+      g_signal_handlers_disconnect_by_func (priv->transient_parent,
                                            gtk_window_transient_parent_unrealized,
                                            window);
-      g_signal_handlers_disconnect_by_func (window->transient_parent,
+      g_signal_handlers_disconnect_by_func (priv->transient_parent,
                                            gtk_window_transient_parent_screen_changed,
                                            window);
-      g_signal_handlers_disconnect_by_func (window->transient_parent,
+      g_signal_handlers_disconnect_by_func (priv->transient_parent,
                                            gtk_widget_destroyed,
-                                           &window->transient_parent);
+                                           &priv->transient_parent);
 
-      if (window->destroy_with_parent)
+      if (priv->destroy_with_parent)
         disconnect_parent_destroyed (window);
-      
-      window->transient_parent = NULL;
+
+      priv->transient_parent = NULL;
 
       if (priv->transient_parent_group)
        {
          priv->transient_parent_group = FALSE;
-         gtk_window_group_remove_window (window->group,
+         gtk_window_group_remove_window (priv->group,
                                          window);
        }
     }
@@ -2278,31 +2517,31 @@ gtk_window_set_transient_for  (GtkWindow *window,
                               GtkWindow *parent)
 {
   GtkWindowPrivate *priv;
-  
+
   g_return_if_fail (GTK_IS_WINDOW (window));
   g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
   g_return_if_fail (window != parent);
 
-  priv = GTK_WINDOW_GET_PRIVATE (window);
+  priv = window->priv;
 
-  if (window->transient_parent)
+  if (priv->transient_parent)
     {
       if (gtk_widget_get_realized (GTK_WIDGET (window)) &&
-          gtk_widget_get_realized (GTK_WIDGET (window->transient_parent)) &&
+          gtk_widget_get_realized (GTK_WIDGET (priv->transient_parent)) &&
           (!parent || !gtk_widget_get_realized (GTK_WIDGET (parent))))
-       gtk_window_transient_parent_unrealized (GTK_WIDGET (window->transient_parent),
+       gtk_window_transient_parent_unrealized (GTK_WIDGET (priv->transient_parent),
                                                GTK_WIDGET (window));
 
       gtk_window_unset_transient_for (window);
     }
 
-  window->transient_parent = parent;
-  
+  priv->transient_parent = parent;
+
   if (parent)
     {
       g_signal_connect (parent, "destroy",
                        G_CALLBACK (gtk_widget_destroyed),
-                       &window->transient_parent);
+                       &priv->transient_parent);
       g_signal_connect (parent, "realize",
                        G_CALLBACK (gtk_window_transient_parent_realized),
                        window);
@@ -2312,10 +2551,10 @@ gtk_window_set_transient_for  (GtkWindow *window,
       g_signal_connect (parent, "notify::screen",
                        G_CALLBACK (gtk_window_transient_parent_screen_changed),
                        window);
-      
-      gtk_window_set_screen (window, parent->screen);
 
-      if (window->destroy_with_parent)
+      gtk_window_set_screen (window, parent->priv->screen);
+
+      if (priv->destroy_with_parent)
         connect_parent_destroyed (window);
       
       if (gtk_widget_get_realized (GTK_WIDGET (window)) &&
@@ -2323,9 +2562,9 @@ gtk_window_set_transient_for  (GtkWindow *window,
        gtk_window_transient_parent_realized (GTK_WIDGET (parent),
                                              GTK_WIDGET (window));
 
-      if (parent->group)
+      if (parent->priv->group)
        {
-         gtk_window_group_add_window (parent->group, window);
+         gtk_window_group_add_window (parent->priv->group, window);
          priv->transient_parent_group = TRUE;
        }
     }
@@ -2346,46 +2585,108 @@ gtk_window_get_transient_for (GtkWindow *window)
 {
   g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
 
-  return window->transient_parent;
+  return window->priv->transient_parent;
 }
 
 /**
- * gtk_window_set_opacity:
+ * gtk_window_set_attached_to:
  * @window: a #GtkWindow
- * @opacity: desired opacity, between 0 and 1
+ * @attach_widget: (allow-none): a #GtkWidget, or %NULL
  *
- * Request the windowing system to make @window partially transparent,
- * with opacity 0 being fully transparent and 1 fully opaque. (Values
- * of the opacity parameter are clamped to the [0,1] range.) On X11
- * this has any effect only on X screens with a compositing manager
- * running. See gtk_widget_is_composited(). On Windows it should work
- * always.
- * 
- * Note that setting a window's opacity after the window has been
- * shown causes it to flicker once on Windows.
+ * Marks @window as attached to @attach_widget. This creates a logical binding
+ * between the window and the widget it belongs to, which is used by GTK+ to
+ * propagate information such as styling or accessibility to @window as if it
+ * was a children of @attach_widget.
  *
- * Since: 2.12
+ * Examples of places where specifying this relation is useful are for instance
+ * a #GtkMenu created by a #GtkComboBox, a completion popup window
+ * created by #GtkEntry or a typeahead search entry created by #GtkTreeView.
+ *
+ * Note that this function should not be confused with
+ * gtk_window_set_transient_for(), which specifies a window manager relation
+ * between two toplevels instead.
+ *
+ * Passing %NULL for @attach_widget detaches the window.
+ *
+ * Since: 3.4
  **/
-void       
-gtk_window_set_opacity  (GtkWindow *window, 
-                        gdouble    opacity)
+void
+gtk_window_set_attached_to (GtkWindow *window,
+                            GtkWidget *attach_widget)
 {
+  GtkStyleContext *context;
   GtkWindowPrivate *priv;
-  
+
   g_return_if_fail (GTK_IS_WINDOW (window));
+  g_return_if_fail (GTK_WIDGET (window) != attach_widget);
 
-  priv = GTK_WINDOW_GET_PRIVATE (window); 
+  priv = window->priv;
 
-  if (opacity < 0.0)
-    opacity = 0.0;
-  else if (opacity > 1.0)
-    opacity = 1.0;
+  if (priv->attach_widget == attach_widget)
+    return;
 
-  priv->opacity_set = TRUE;
-  priv->opacity = opacity;
+  remove_attach_widget (window);
 
-  if (gtk_widget_get_realized (GTK_WIDGET (window)))
-    gdk_window_set_opacity (GTK_WIDGET (window)->window, priv->opacity);
+  priv->attach_widget = attach_widget;
+
+  if (priv->attach_widget)
+    {
+      _gtk_widget_add_attached_window (priv->attach_widget, window);
+
+      g_object_ref (priv->attach_widget);
+    }
+
+  /* Update the style, as the widget path might change. */
+  context = gtk_widget_get_style_context (GTK_WIDGET (window));
+  if (priv->attach_widget)
+    gtk_style_context_set_parent (context, gtk_widget_get_style_context (priv->attach_widget));
+  else
+    gtk_style_context_set_parent (context, NULL);
+}
+
+/**
+ * gtk_window_get_attached_to:
+ * @window: a #GtkWindow
+ *
+ * Fetches the attach widget for this window. See
+ * gtk_window_set_attached_to().
+ *
+ * Return value: (transfer none): the widget where the window is attached,
+ *   or %NULL if the window is not attached to any widget.
+ *
+ * Since: 3.4
+ **/
+GtkWidget *
+gtk_window_get_attached_to (GtkWindow *window)
+{
+  g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
+
+  return window->priv->attach_widget;
+}
+
+/**
+ * gtk_window_set_opacity:
+ * @window: a #GtkWindow
+ * @opacity: desired opacity, between 0 and 1
+ *
+ * Request the windowing system to make @window partially transparent,
+ * with opacity 0 being fully transparent and 1 fully opaque. (Values
+ * of the opacity parameter are clamped to the [0,1] range.) On X11
+ * this has any effect only on X screens with a compositing manager
+ * running. See gtk_widget_is_composited(). On Windows it should work
+ * always.
+ * 
+ * Note that setting a window's opacity after the window has been
+ * shown causes it to flicker once on Windows.
+ *
+ * Since: 2.12
+ * Deprecated: 3.8: Use gtk_widget_set_opacity instead.
+ **/
+void       
+gtk_window_set_opacity  (GtkWindow *window, 
+                        gdouble    opacity)
+{
+  gtk_widget_set_opacity (GTK_WIDGET (window), opacity);
 }
 
 /**
@@ -2398,17 +2699,89 @@ gtk_window_set_opacity  (GtkWindow *window,
  * Return value: the requested opacity for this window.
  *
  * Since: 2.12
+ * Deprecated: 3.8: Use gtk_widget_get_opacity instead.
  **/
 gdouble
 gtk_window_get_opacity (GtkWindow *window)
 {
-  GtkWindowPrivate *priv;
-  
   g_return_val_if_fail (GTK_IS_WINDOW (window), 0.0);
 
-  priv = GTK_WINDOW_GET_PRIVATE (window); 
+  return gtk_widget_get_opacity (GTK_WIDGET (window));
+}
+
+/**
+ * gtk_window_get_application:
+ * @window: a #GtkWindow
+ *
+ * Gets the #GtkApplication associated with the window (if any).
+ *
+ * Return value: (transfer none): a #GtkApplication, or %NULL
+ *
+ * Since: 3.0
+ **/
+GtkApplication *
+gtk_window_get_application (GtkWindow *window)
+{
+  g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
+
+  return window->priv->application;
+}
+
+static void
+gtk_window_release_application (GtkWindow *window)
+{
+  if (window->priv->application)
+    {
+      GtkApplication *application;
+
+      /* steal reference into temp variable */
+      application = window->priv->application;
+      window->priv->application = NULL;
+
+      gtk_application_remove_window (application, window);
+      g_object_unref (application);
+    }
+}
+
+/**
+ * gtk_window_set_application:
+ * @window: a #GtkWindow
+ * @application: (allow-none): a #GtkApplication, or %NULL
+ *
+ * Sets or unsets the #GtkApplication associated with the window.
+ *
+ * The application will be kept alive for at least as long as the window
+ * is open.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_window_set_application (GtkWindow      *window,
+                            GtkApplication *application)
+{
+  GtkWindowPrivate *priv;
+
+  g_return_if_fail (GTK_IS_WINDOW (window));
+
+  priv = window->priv;
+  if (priv->application != application)
+    {
+      gtk_window_release_application (window);
+
+      priv->application = application;
+
+      if (priv->application != NULL)
+        {
+          g_object_ref (priv->application);
+
+          gtk_application_add_window (priv->application, window);
+        }
+
+      /* don't use a normal cast: application may be NULL */
+      gtk_widget_insert_action_group (GTK_WIDGET (window), "app", (GActionGroup *) application);
 
-  return priv->opacity;
+      g_object_notify (G_OBJECT (window), "application");
+    }
 }
 
 /**
@@ -2435,15 +2808,15 @@ gtk_window_set_type_hint (GtkWindow           *window,
   g_return_if_fail (GTK_IS_WINDOW (window));
   g_return_if_fail (!gtk_widget_get_mapped (GTK_WIDGET (window)));
 
-  priv = GTK_WINDOW_GET_PRIVATE (window);
+  priv = window->priv;
 
   if (hint < GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU)
-    window->type_hint = hint;
+    priv->type_hint = hint;
   else
-    window->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
+    priv->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
 
   priv->reset_type_hint = TRUE;
-  priv->type_hint = hint;
+  priv->gdk_type_hint = hint;
 }
 
 /**
@@ -2457,13 +2830,9 @@ gtk_window_set_type_hint (GtkWindow           *window,
 GdkWindowTypeHint
 gtk_window_get_type_hint (GtkWindow *window)
 {
-  GtkWindowPrivate *priv;
-  
   g_return_val_if_fail (GTK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
 
-  priv = GTK_WINDOW_GET_PRIVATE (window);
-  
-  return priv->type_hint;
+  return window->priv->gdk_type_hint;
 }
 
 /**
@@ -2483,8 +2852,8 @@ gtk_window_set_skip_taskbar_hint (GtkWindow *window,
   GtkWindowPrivate *priv;
 
   g_return_if_fail (GTK_IS_WINDOW (window));
-  
-  priv = GTK_WINDOW_GET_PRIVATE (window);
+
+  priv = window->priv;
 
   setting = setting != FALSE;
 
@@ -2492,7 +2861,7 @@ gtk_window_set_skip_taskbar_hint (GtkWindow *window,
     {
       priv->skips_taskbar = setting;
       if (gtk_widget_get_realized (GTK_WIDGET (window)))
-        gdk_window_set_skip_taskbar_hint (GTK_WIDGET (window)->window,
+        gdk_window_set_skip_taskbar_hint (gtk_widget_get_window (GTK_WIDGET (window)),
                                           priv->skips_taskbar);
       g_object_notify (G_OBJECT (window), "skip-taskbar-hint");
     }
@@ -2511,13 +2880,9 @@ gtk_window_set_skip_taskbar_hint (GtkWindow *window,
 gboolean
 gtk_window_get_skip_taskbar_hint (GtkWindow *window)
 {
-  GtkWindowPrivate *priv;
-
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
-  
-  priv = GTK_WINDOW_GET_PRIVATE (window);
 
-  return priv->skips_taskbar;
+  return window->priv->skips_taskbar;
 }
 
 /**
@@ -2540,8 +2905,8 @@ gtk_window_set_skip_pager_hint (GtkWindow *window,
   GtkWindowPrivate *priv;
 
   g_return_if_fail (GTK_IS_WINDOW (window));
-  
-  priv = GTK_WINDOW_GET_PRIVATE (window);
+
+  priv = window->priv;
 
   setting = setting != FALSE;
 
@@ -2549,7 +2914,7 @@ gtk_window_set_skip_pager_hint (GtkWindow *window,
     {
       priv->skips_pager = setting;
       if (gtk_widget_get_realized (GTK_WIDGET (window)))
-        gdk_window_set_skip_pager_hint (GTK_WIDGET (window)->window,
+        gdk_window_set_skip_pager_hint (gtk_widget_get_window (GTK_WIDGET (window)),
                                         priv->skips_pager);
       g_object_notify (G_OBJECT (window), "skip-pager-hint");
     }
@@ -2568,13 +2933,9 @@ gtk_window_set_skip_pager_hint (GtkWindow *window,
 gboolean
 gtk_window_get_skip_pager_hint (GtkWindow *window)
 {
-  GtkWindowPrivate *priv;
-
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
-  
-  priv = GTK_WINDOW_GET_PRIVATE (window);
 
-  return priv->skips_pager;
+  return window->priv->skips_pager;
 }
 
 /**
@@ -2594,8 +2955,8 @@ gtk_window_set_urgency_hint (GtkWindow *window,
   GtkWindowPrivate *priv;
 
   g_return_if_fail (GTK_IS_WINDOW (window));
-  
-  priv = GTK_WINDOW_GET_PRIVATE (window);
+
+  priv = window->priv;
 
   setting = setting != FALSE;
 
@@ -2603,7 +2964,7 @@ gtk_window_set_urgency_hint (GtkWindow *window,
     {
       priv->urgent = setting;
       if (gtk_widget_get_realized (GTK_WIDGET (window)))
-        gdk_window_set_urgency_hint (GTK_WIDGET (window)->window,
+        gdk_window_set_urgency_hint (gtk_widget_get_window (GTK_WIDGET (window)),
                                     priv->urgent);
       g_object_notify (G_OBJECT (window), "urgency-hint");
     }
@@ -2622,13 +2983,9 @@ gtk_window_set_urgency_hint (GtkWindow *window,
 gboolean
 gtk_window_get_urgency_hint (GtkWindow *window)
 {
-  GtkWindowPrivate *priv;
-
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
-  
-  priv = GTK_WINDOW_GET_PRIVATE (window);
 
-  return priv->urgent;
+  return window->priv->urgent;
 }
 
 /**
@@ -2648,8 +3005,8 @@ gtk_window_set_accept_focus (GtkWindow *window,
   GtkWindowPrivate *priv;
 
   g_return_if_fail (GTK_IS_WINDOW (window));
-  
-  priv = GTK_WINDOW_GET_PRIVATE (window);
+
+  priv = window->priv;
 
   setting = setting != FALSE;
 
@@ -2657,7 +3014,7 @@ gtk_window_set_accept_focus (GtkWindow *window,
     {
       priv->accept_focus = setting;
       if (gtk_widget_get_realized (GTK_WIDGET (window)))
-        gdk_window_set_accept_focus (GTK_WIDGET (window)->window,
+        gdk_window_set_accept_focus (gtk_widget_get_window (GTK_WIDGET (window)),
                                     priv->accept_focus);
       g_object_notify (G_OBJECT (window), "accept-focus");
     }
@@ -2676,13 +3033,9 @@ gtk_window_set_accept_focus (GtkWindow *window,
 gboolean
 gtk_window_get_accept_focus (GtkWindow *window)
 {
-  GtkWindowPrivate *priv;
-
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
-  
-  priv = GTK_WINDOW_GET_PRIVATE (window);
 
-  return priv->accept_focus;
+  return window->priv->accept_focus;
 }
 
 /**
@@ -2703,8 +3056,8 @@ gtk_window_set_focus_on_map (GtkWindow *window,
   GtkWindowPrivate *priv;
 
   g_return_if_fail (GTK_IS_WINDOW (window));
-  
-  priv = GTK_WINDOW_GET_PRIVATE (window);
+
+  priv = window->priv;
 
   setting = setting != FALSE;
 
@@ -2712,7 +3065,7 @@ gtk_window_set_focus_on_map (GtkWindow *window,
     {
       priv->focus_on_map = setting;
       if (gtk_widget_get_realized (GTK_WIDGET (window)))
-        gdk_window_set_focus_on_map (GTK_WIDGET (window)->window,
+        gdk_window_set_focus_on_map (gtk_widget_get_window (GTK_WIDGET (window)),
                                     priv->focus_on_map);
       g_object_notify (G_OBJECT (window), "focus-on-map");
     }
@@ -2732,13 +3085,9 @@ gtk_window_set_focus_on_map (GtkWindow *window,
 gboolean
 gtk_window_get_focus_on_map (GtkWindow *window)
 {
-  GtkWindowPrivate *priv;
-
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
-  
-  priv = GTK_WINDOW_GET_PRIVATE (window);
 
-  return priv->focus_on_map;
+  return window->priv->focus_on_map;
 }
 
 /**
@@ -2755,12 +3104,16 @@ void
 gtk_window_set_destroy_with_parent  (GtkWindow *window,
                                      gboolean   setting)
 {
+  GtkWindowPrivate *priv;
+
   g_return_if_fail (GTK_IS_WINDOW (window));
 
-  if (window->destroy_with_parent == (setting != FALSE))
+  priv = window->priv;
+
+  if (priv->destroy_with_parent == (setting != FALSE))
     return;
 
-  if (window->destroy_with_parent)
+  if (priv->destroy_with_parent)
     {
       disconnect_parent_destroyed (window);
     }
@@ -2768,8 +3121,8 @@ gtk_window_set_destroy_with_parent  (GtkWindow *window,
     {
       connect_parent_destroyed (window);
     }
-  
-  window->destroy_with_parent = setting;
+
+  priv->destroy_with_parent = setting;
 
   g_object_notify (G_OBJECT (window), "destroy-with-parent");
 }
@@ -2788,16 +3141,72 @@ gtk_window_get_destroy_with_parent (GtkWindow *window)
 {
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
 
-  return window->destroy_with_parent;
+  return window->priv->destroy_with_parent;
+}
+
+/**
+ * gtk_window_set_hide_titlebar_when_maximized:
+ * @window: a #GtkWindow
+ * @setting: whether to hide the titlebar when @window is maximized
+ *
+ * If @setting is %TRUE, then @window will request that it's titlebar
+ * should be hidden when maximized.
+ * This is useful for windows that don't convey any information other
+ * than the application name in the titlebar, to put the available
+ * screen space to better use. If the underlying window system does not
+ * support the request, the setting will not have any effect.
+ *
+ * Since: 3.4
+ **/
+void
+gtk_window_set_hide_titlebar_when_maximized (GtkWindow *window,
+                                             gboolean   setting)
+{
+  g_return_if_fail (GTK_IS_WINDOW (window));
+
+#ifdef GDK_WINDOWING_X11
+  {
+    GdkWindow *gdk_window;
+
+    gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+
+    if (GDK_IS_X11_WINDOW (gdk_window))
+      gdk_x11_window_set_hide_titlebar_when_maximized (gdk_window, setting);
+  }
+#endif
+
+  window->priv->hide_titlebar_when_maximized = setting;
+  g_object_notify (G_OBJECT (window), "hide-titlebar-when-maximized");
+}
+
+/**
+ * gtk_window_get_hide_titlebar_when_maximized:
+ * @window: a #GtkWindow
+ *
+ * Returns whether the window has requested to have its titlebar hidden
+ * when maximized. See gtk_window_set_hide_titlebar_when_maximized ().
+ *
+ * Return value: %TRUE if the window has requested to have its titlebar
+ *               hidden when maximized
+ *
+ * Since: 3.4
+ **/
+gboolean
+gtk_window_get_hide_titlebar_when_maximized (GtkWindow *window)
+{
+  g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
+
+  return window->priv->hide_titlebar_when_maximized;
 }
 
 static GtkWindowGeometryInfo*
 gtk_window_get_geometry_info (GtkWindow *window,
                              gboolean   create)
 {
+  GtkWindowPrivate *priv = window->priv;
   GtkWindowGeometryInfo *info;
 
-  info = window->geometry_info;
+  info = priv->geometry_info;
   if (!info && create)
     {
       info = g_new0 (GtkWindowGeometryInfo, 1);
@@ -2817,7 +3226,7 @@ gtk_window_get_geometry_info (GtkWindow *window,
       info->last.configure_request.height = -1;
       info->widget = NULL;
       info->mask = 0;
-      window->geometry_info = info;
+      priv->geometry_info = info;
     }
 
   return info;
@@ -2863,14 +3272,14 @@ gtk_window_set_geometry_hints (GtkWindow       *window,
   if (geometry)
     info->geometry = *geometry;
 
-  /* We store gravity in window->gravity not in the hints. */
+  /* We store gravity in priv->gravity not in the hints. */
   info->mask = geom_mask & ~(GDK_HINT_WIN_GRAVITY);
 
   if (geom_mask & GDK_HINT_WIN_GRAVITY)
     {
       gtk_window_set_gravity (window, geometry->win_gravity);
     }
-  
+
   gtk_widget_queue_resize_no_redraw (GTK_WIDGET (window));
 }
 
@@ -2886,7 +3295,7 @@ gtk_window_set_geometry_hints (GtkWindow       *window,
  * using this function, GTK+ will do its best to convince the window
  * manager not to decorate the window. Depending on the system, this
  * function may not have any effect when called on a window that is
- * already visible, so you should call it before calling gtk_window_show().
+ * already visible, so you should call it before calling gtk_widget_show().
  *
  * On Windows, this function always works, since there's no window manager
  * policy involved.
@@ -2896,22 +3305,28 @@ void
 gtk_window_set_decorated (GtkWindow *window,
                           gboolean   setting)
 {
+  GtkWindowPrivate *priv;
+  GdkWindow *gdk_window;
+
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
+
   setting = setting != FALSE;
 
-  if (setting == window->decorated)
+  if (setting == priv->decorated)
     return;
 
-  window->decorated = setting;
-  
-  if (GTK_WIDGET (window)->window)
+  priv->decorated = setting;
+
+  gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+  if (gdk_window)
     {
-      if (window->decorated)
-        gdk_window_set_decorations (GTK_WIDGET (window)->window,
+      if (priv->decorated)
+        gdk_window_set_decorations (gdk_window,
                                     GDK_DECOR_ALL);
       else
-        gdk_window_set_decorations (GTK_WIDGET (window)->window,
+        gdk_window_set_decorations (gdk_window,
                                     0);
     }
 
@@ -2932,7 +3347,7 @@ gtk_window_get_decorated (GtkWindow *window)
 {
   g_return_val_if_fail (GTK_IS_WINDOW (window), TRUE);
 
-  return window->decorated;
+  return window->priv->decorated;
 }
 
 /**
@@ -2946,7 +3361,7 @@ gtk_window_get_decorated (GtkWindow *window)
  * using this function, GTK+ will do its best to convince the window
  * manager not to show a close button. Depending on the system, this
  * function may not have any effect when called on a window that is
- * already visible, so you should call it before calling gtk_window_show().
+ * already visible, so you should call it before calling gtk_widget_show().
  *
  * On Windows, this function always works, since there's no window manager
  * policy involved.
@@ -2958,10 +3373,11 @@ gtk_window_set_deletable (GtkWindow *window,
                          gboolean   setting)
 {
   GtkWindowPrivate *priv;
+  GdkWindow *gdk_window;
 
   g_return_if_fail (GTK_IS_WINDOW (window));
 
-  priv = GTK_WINDOW_GET_PRIVATE (window);
+  priv = window->priv;
 
   setting = setting != FALSE;
 
@@ -2969,14 +3385,15 @@ gtk_window_set_deletable (GtkWindow *window,
     return;
 
   priv->deletable = setting;
-  
-  if (GTK_WIDGET (window)->window)
+
+  gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+  if (gdk_window)
     {
       if (priv->deletable)
-        gdk_window_set_functions (GTK_WIDGET (window)->window,
+        gdk_window_set_functions (gdk_window,
                                  GDK_FUNC_ALL);
       else
-        gdk_window_set_functions (GTK_WIDGET (window)->window,
+        gdk_window_set_functions (gdk_window,
                                  GDK_FUNC_ALL | GDK_FUNC_CLOSE);
     }
 
@@ -2997,13 +3414,9 @@ gtk_window_set_deletable (GtkWindow *window,
 gboolean
 gtk_window_get_deletable (GtkWindow *window)
 {
-  GtkWindowPrivate *priv;
-
   g_return_val_if_fail (GTK_IS_WINDOW (window), TRUE);
 
-  priv = GTK_WINDOW_GET_PRIVATE (window);
-
-  return priv->deletable;
+  return window->priv->deletable;
 }
 
 static GtkWindowIconInfo*
@@ -3039,157 +3452,6 @@ ensure_icon_info (GtkWindow *window)
   return info;
 }
 
-typedef struct {
-  guint serial;
-  GdkPixmap *pixmap;
-  GdkPixmap *mask;
-} ScreenIconInfo;
-
-static ScreenIconInfo *
-get_screen_icon_info (GdkScreen *screen)
-{
-  ScreenIconInfo *info = g_object_get_qdata (G_OBJECT (screen), 
-                                            quark_gtk_window_default_icon_pixmap);
-  if (!info)
-    {
-      info = g_slice_new0 (ScreenIconInfo);
-      g_object_set_qdata (G_OBJECT (screen), 
-                         quark_gtk_window_default_icon_pixmap, info);
-    }
-
-  if (info->serial != default_icon_serial)
-    {
-      if (info->pixmap)
-       {
-         g_object_remove_weak_pointer (G_OBJECT (info->pixmap), (gpointer*)&info->pixmap);
-         info->pixmap = NULL;
-       }
-         
-      if (info->mask)
-       {
-         g_object_remove_weak_pointer (G_OBJECT (info->mask), (gpointer*)&info->mask);
-         info->mask = NULL;
-       }
-
-      info->serial = default_icon_serial;
-    }
-  
-  return info;
-}
-
-static void
-get_pixmap_and_mask (GdkWindow         *window,
-                    GtkWindowIconInfo  *parent_info,
-                     gboolean            is_default_list,
-                     GList              *icon_list,
-                     GdkPixmap         **pmap_return,
-                     GdkBitmap         **mask_return)
-{
-  GdkScreen *screen = gdk_drawable_get_screen (window);
-  ScreenIconInfo *default_icon_info = get_screen_icon_info (screen);
-  GdkPixbuf *best_icon;
-  GList *tmp_list;
-  int best_size;
-  
-  *pmap_return = NULL;
-  *mask_return = NULL;
-  
-  if (is_default_list &&
-      default_icon_info->pixmap != NULL)
-    {
-      /* Use shared icon pixmap for all windows on this screen.
-       */
-      if (default_icon_info->pixmap)
-        g_object_ref (default_icon_info->pixmap);
-      if (default_icon_info->mask)
-        g_object_ref (default_icon_info->mask);
-
-      *pmap_return = default_icon_info->pixmap;
-      *mask_return = default_icon_info->mask;
-    }
-  else if (parent_info && parent_info->icon_pixmap)
-    {
-      if (parent_info->icon_pixmap)
-        g_object_ref (parent_info->icon_pixmap);
-      if (parent_info->icon_mask)
-        g_object_ref (parent_info->icon_mask);
-      
-      *pmap_return = parent_info->icon_pixmap;
-      *mask_return = parent_info->icon_mask;
-    }
-  else
-    {
-#define IDEAL_SIZE 48
-  
-      best_size = G_MAXINT;
-      best_icon = NULL;
-      tmp_list = icon_list;
-      while (tmp_list != NULL)
-        {
-          GdkPixbuf *pixbuf = tmp_list->data;
-          int this;
-      
-          /* average width and height - if someone passes in a rectangular
-           * icon they deserve what they get.
-           */
-          this = gdk_pixbuf_get_width (pixbuf) + gdk_pixbuf_get_height (pixbuf);
-          this /= 2;
-      
-          if (best_icon == NULL)
-            {
-              best_icon = pixbuf;
-              best_size = this;
-            }
-          else
-            {
-              /* icon is better if it's 32 pixels or larger, and closer to
-               * the ideal size than the current best.
-               */
-              if (this >= 32 &&
-                  (ABS (best_size - IDEAL_SIZE) <
-                   ABS (this - IDEAL_SIZE)))
-                {
-                  best_icon = pixbuf;
-                  best_size = this;
-                }
-            }
-
-          tmp_list = tmp_list->next;
-        }
-
-      if (best_icon)
-        gdk_pixbuf_render_pixmap_and_mask_for_colormap (best_icon,
-                                                       gdk_screen_get_system_colormap (screen),
-                                                       pmap_return,
-                                                       mask_return,
-                                                       128);
-
-      /* Save pmap/mask for others to use if appropriate */
-      if (parent_info)
-        {
-          parent_info->icon_pixmap = *pmap_return;
-          parent_info->icon_mask = *mask_return;
-
-          if (parent_info->icon_pixmap)
-            g_object_ref (parent_info->icon_pixmap);
-          if (parent_info->icon_mask)
-            g_object_ref (parent_info->icon_mask);
-        }
-      else if (is_default_list)
-        {
-          default_icon_info->pixmap = *pmap_return;
-          default_icon_info->mask = *mask_return;
-
-          if (default_icon_info->pixmap)
-           g_object_add_weak_pointer (G_OBJECT (default_icon_info->pixmap),
-                                      (gpointer*)&default_icon_info->pixmap);
-          if (default_icon_info->mask) 
-           g_object_add_weak_pointer (G_OBJECT (default_icon_info->mask),
-                                      (gpointer*)&default_icon_info->mask);
-        }
-    }
-}
-
 static GList *
 icon_list_from_theme (GtkWidget    *widget,
                      const gchar  *name)
@@ -3232,16 +3494,19 @@ icon_list_from_theme (GtkWidget    *widget,
 static void
 gtk_window_realize_icon (GtkWindow *window)
 {
+  GtkWindowPrivate *priv = window->priv;
   GtkWidget *widget;
   GtkWindowIconInfo *info;
+  GdkWindow *gdk_window;
   GList *icon_list;
 
   widget = GTK_WIDGET (window);
+  gdk_window = gtk_widget_get_window (widget);
 
-  g_return_if_fail (widget->window != NULL);
+  g_return_if_fail (gdk_window != NULL);
 
   /* no point setting an icon on override-redirect */
-  if (window->type == GTK_WINDOW_POPUP)
+  if (priv->type == GTK_WINDOW_POPUP)
     return;
 
   icon_list = NULL;
@@ -3251,9 +3516,6 @@ gtk_window_realize_icon (GtkWindow *window)
   if (info->realized)
     return;
 
-  g_return_if_fail (info->icon_pixmap == NULL);
-  g_return_if_fail (info->icon_mask == NULL);
-  
   info->using_default_icon = FALSE;
   info->using_parent_icon = FALSE;
   info->using_themed_icon = FALSE;
@@ -3269,9 +3531,9 @@ gtk_window_realize_icon (GtkWindow *window)
     }
 
   /* Inherit from transient parent */
-  if (icon_list == NULL && window->transient_parent)
+  if (icon_list == NULL && priv->transient_parent)
     {
-      icon_list = ensure_icon_info (window->transient_parent)->icon_list;
+      icon_list = ensure_icon_info (priv->transient_parent)->icon_list;
       if (icon_list)
         info->using_parent_icon = TRUE;
     }      
@@ -3291,32 +3553,16 @@ gtk_window_realize_icon (GtkWindow *window)
       info->using_default_icon = TRUE;
       info->using_themed_icon = TRUE;  
     }
-  
-  gdk_window_set_icon_list (widget->window, icon_list);
-
-  get_pixmap_and_mask (widget->window,
-                      info->using_parent_icon ? ensure_icon_info (window->transient_parent) : NULL,
-                       info->using_default_icon,
-                       icon_list,
-                       &info->icon_pixmap,
-                       &info->icon_mask);
-  
-  /* This is a slight ICCCM violation since it's a color pixmap not
-   * a bitmap, but everyone does it.
-   */
-  gdk_window_set_icon (widget->window,
-                       NULL,
-                       info->icon_pixmap,
-                       info->icon_mask);
 
   info->realized = TRUE;
+
+  gdk_window_set_icon_list (gtk_widget_get_window (widget), icon_list);
   
   if (info->using_themed_icon) 
     {
       GtkIconTheme *icon_theme;
 
-      g_list_foreach (icon_list, (GFunc) g_object_unref, NULL);
-      g_list_free (icon_list);
+      g_list_free_full (icon_list, g_object_unref);
  
       icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window)));
       g_signal_connect (icon_theme, "changed",
@@ -3334,15 +3580,6 @@ gtk_window_unrealize_icon (GtkWindow *window)
   if (info == NULL)
     return;
   
-  if (info->icon_pixmap)
-    g_object_unref (info->icon_pixmap);
-
-  if (info->icon_mask)
-    g_object_unref (info->icon_mask);
-
-  info->icon_pixmap = NULL;
-  info->icon_mask = NULL;
-
   if (info->using_themed_icon)
     {
       GtkIconTheme *icon_theme;
@@ -3363,7 +3600,7 @@ gtk_window_unrealize_icon (GtkWindow *window)
 /**
  * gtk_window_set_icon_list:
  * @window: a #GtkWindow
- * @list: (element-type GdkPixbuf) (transfer container): list of #GdkPixbuf
+ * @list: (element-type GdkPixbuf): list of #GdkPixbuf
  *
  * Sets up the icon representing a #GtkWindow. The icon is used when
  * the window is minimized (also known as iconified).  Some window
@@ -3406,10 +3643,7 @@ gtk_window_set_icon_list (GtkWindow  *window,
   g_list_foreach (list,
                   (GFunc) g_object_ref, NULL);
 
-  g_list_foreach (info->icon_list,
-                  (GFunc) g_object_unref, NULL);
-
-  g_list_free (info->icon_list);
+  g_list_free_full (info->icon_list, g_object_unref);
 
   info->icon_list = g_list_copy (list);
 
@@ -3537,8 +3771,7 @@ gtk_window_set_icon_name (GtkWindow   *window,
   info->icon_name = g_strdup (name);
   g_free (tmp);
 
-  g_list_foreach (info->icon_list, (GFunc) g_object_unref, NULL);
-  g_list_free (info->icon_list);
+  g_list_free_full (info->icon_list, g_object_unref);
   info->icon_list = NULL;
   
   update_themed_icon (NULL, window);
@@ -3623,7 +3856,7 @@ load_pixbuf_verbosely (const char *filename,
 /**
  * gtk_window_set_icon_from_file:
  * @window: a #GtkWindow
- * @filename: location of icon file
+ * @filename: (type filename): location of icon file
  * @err: (allow-none): location to store error, or %NULL.
  *
  * Sets the icon for @window.  
@@ -3681,10 +3914,7 @@ gtk_window_set_default_icon_list (GList *list)
   g_list_foreach (list,
                   (GFunc) g_object_ref, NULL);
 
-  g_list_foreach (default_icon_list,
-                  (GFunc) g_object_unref, NULL);
-
-  g_list_free (default_icon_list);
+  g_list_free_full (default_icon_list, g_object_unref);
 
   default_icon_list = g_list_copy (list);
   
@@ -3753,10 +3983,7 @@ gtk_window_set_default_icon_name (const gchar *name)
   g_free (default_icon_name);
   default_icon_name = g_strdup (name);
 
-  g_list_foreach (default_icon_list,
-                  (GFunc) g_object_unref, NULL);
-
-  g_list_free (default_icon_list);
+  g_list_free_full (default_icon_list, g_object_unref);
   default_icon_list = NULL;
   
   /* Update all toplevels */
@@ -3801,7 +4028,7 @@ gtk_window_get_default_icon_name (void)
 
 /**
  * gtk_window_set_default_icon_from_file:
- * @filename: location of icon file
+ * @filename: (type filename): location of icon file
  * @err: (allow-none): location to store error, or %NULL.
  *
  * Sets an icon to be used as fallback for windows that haven't
@@ -3942,6 +4169,30 @@ gtk_window_set_default_size (GtkWindow   *window,
   gtk_window_set_default_size_internal (window, TRUE, width, TRUE, height, FALSE);
 }
 
+/**
+ * gtk_window_set_default_geometry:
+ * @window: a #GtkWindow
+ * @width: width in resize increments, or -1 to unset the default width
+ * @height: height in resize increments, or -1 to unset the default height
+ *
+ * Like gtk_window_set_default_size(), but @width and @height are interpreted
+ * in terms of the base size and increment set with
+ * gtk_window_set_geometry_hints.
+ *
+ * Since: 3.0
+ */
+void
+gtk_window_set_default_geometry (GtkWindow *window,
+                                gint       width,
+                                gint       height)
+{
+  g_return_if_fail (GTK_IS_WINDOW (window));
+  g_return_if_fail (width >= -1);
+  g_return_if_fail (height >= -1);
+
+  gtk_window_set_default_size_internal (window, TRUE, width, TRUE, height, TRUE);
+}
+
 /**
  * gtk_window_get_default_size:
  * @window: a #GtkWindow
@@ -4006,17 +4257,50 @@ gtk_window_resize (GtkWindow *window,
 
   info->resize_width = width;
   info->resize_height = height;
+  info->resize_is_geometry = FALSE;
 
   gtk_widget_queue_resize_no_redraw (GTK_WIDGET (window));
 }
 
 /**
- * gtk_window_get_size:
+ * gtk_window_resize_to_geometry:
  * @window: a #GtkWindow
- * @width: (out) (allow-none): return location for width, or %NULL
- * @height: (out) (allow-none): return location for height, or %NULL
+ * @width: width in resize increments to resize the window to
+ * @height: height in resize increments to resize the window to
  *
- * Obtains the current size of @window. If @window is not onscreen,
+ * Like gtk_window_resize(), but @width and @height are interpreted
+ * in terms of the base size and increment set with
+ * gtk_window_set_geometry_hints.
+ *
+ * Since: 3.0
+ */
+void
+gtk_window_resize_to_geometry (GtkWindow *window,
+                              gint       width,
+                              gint       height)
+{
+  GtkWindowGeometryInfo *info;
+
+  g_return_if_fail (GTK_IS_WINDOW (window));
+  g_return_if_fail (width > 0);
+  g_return_if_fail (height > 0);
+
+  info = gtk_window_get_geometry_info (window, TRUE);
+
+  info->resize_width = width;
+  info->resize_height = height;
+  info->resize_is_geometry = TRUE;
+
+  gtk_widget_queue_resize_no_redraw (GTK_WIDGET (window));
+}
+
+/**
+ * gtk_window_get_size:
+ * @window: a #GtkWindow
+ * @width: (out) (allow-none): return location for width, or %NULL
+ * @height: (out) (allow-none): return location for height, or %NULL
+ *
+ * Obtains the current size of @window. If @window is not onscreen,
  * it returns the size GTK+ will suggest to the <link
  * linkend="gtk-X11-arch">window manager</link> for the initial window
  * size (but this is not reliably the same as the size the window
@@ -4076,8 +4360,8 @@ gtk_window_get_size (GtkWindow *window,
 
   if (gtk_widget_get_mapped (GTK_WIDGET (window)))
     {
-      gdk_drawable_get_size (GTK_WIDGET (window)->window,
-                             &w, &h);
+      w = gdk_window_get_width (gtk_widget_get_window (GTK_WIDGET (window)));
+      h = gdk_window_get_height (gtk_widget_get_window (GTK_WIDGET (window)));
     }
   else
     {
@@ -4132,9 +4416,9 @@ gtk_window_get_size (GtkWindow *window,
  * gdk_screen_height () - window_height)</literal> (note that this
  * example does not take multi-head scenarios into account).
  *
- * The Extended Window Manager Hints specification at <ulink 
+ * The Extended Window Manager Hints specification at <ulink
  * url="http://www.freedesktop.org/Standards/wm-spec">
- * http://www.freedesktop.org/Standards/wm-spec</ulink> has a 
+ * http://www.freedesktop.org/Standards/wm-spec</ulink> has a
  * nice table of gravities in the "implementation notes" section.
  *
  * The gtk_window_get_position() documentation may also be relevant.
@@ -4146,15 +4430,19 @@ gtk_window_move (GtkWindow *window,
 {
   GtkWindowGeometryInfo *info;
   GtkWidget *widget;
-  
+
   g_return_if_fail (GTK_IS_WINDOW (window));
 
   widget = GTK_WIDGET (window);
 
   info = gtk_window_get_geometry_info (window, TRUE);  
-  
+
   if (gtk_widget_get_mapped (widget))
     {
+      GtkAllocation allocation;
+
+      gtk_widget_get_allocation (widget, &allocation);
+
       /* we have now sent a request with this position
        * with currently-active constraints, so toggle flag.
        */
@@ -4169,10 +4457,9 @@ gtk_window_move (GtkWindow *window,
        * then show the window, your move() will work.
        */
       gtk_window_constrain_position (window,
-                                     widget->allocation.width,
-                                     widget->allocation.height,
+                                     allocation.width, allocation.height,
                                      &x, &y);
-      
+
       /* Note that this request doesn't go through our standard request
        * framework, e.g. doesn't increment configure_request_count,
        * doesn't set info->last, etc.; that's because
@@ -4183,15 +4470,7 @@ gtk_window_move (GtkWindow *window,
        * the same as the position being changed by the window
        * manager.
        */
-      
-      /* FIXME are we handling gravity properly for framed windows? */
-      if (window->frame)
-        gdk_window_move (window->frame,
-                         x - window->frame_left,
-                         y - window->frame_top);
-      else
-        gdk_window_move (GTK_WIDGET (window)->window,
-                         x, y);
+      gdk_window_move (gtk_widget_get_window (GTK_WIDGET (window)), x, y);
     }
   else
     {
@@ -4205,14 +4484,16 @@ gtk_window_move (GtkWindow *window,
 /**
  * gtk_window_get_position:
  * @window: a #GtkWindow
- * @root_x: (out): return location for X coordinate of gravity-determined reference point
- * @root_y: (out): return location for Y coordinate of gravity-determined reference point
+ * @root_x: (out) (allow-none): return location for X coordinate of
+ *     gravity-determined reference point, or %NULL
+ * @root_y: (out) (allow-none): return location for Y coordinate of
+ *     gravity-determined reference point, or %NULL
  *
  * This function returns the position you need to pass to
- * gtk_window_move() to keep @window in its current position.  This
- * means that the meaning of the returned value varies with window
- * gravity. See gtk_window_move() for more details.
- * 
+ * gtk_window_move() to keep @window in its current position.
+ * This means that the meaning of the returned value varies with
+ * window gravity. See gtk_window_move() for more details.
+ *
  * If you haven't changed the window gravity, its gravity will be
  * #GDK_GRAVITY_NORTH_WEST. This means that gtk_window_get_position()
  * gets the position of the top-left corner of the window manager
@@ -4252,13 +4533,17 @@ gtk_window_get_position (GtkWindow *window,
                          gint      *root_x,
                          gint      *root_y)
 {
+  GtkWindowPrivate *priv;
   GtkWidget *widget;
+  GdkWindow *gdk_window;
 
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
   widget = GTK_WIDGET (window);
-  
-  if (window->gravity == GDK_GRAVITY_STATIC)
+  gdk_window = gtk_widget_get_window (widget);
+
+  if (priv->gravity == GDK_GRAVITY_STATIC)
     {
       if (gtk_widget_get_mapped (widget))
         {
@@ -4269,7 +4554,7 @@ gtk_window_get_position (GtkWindow *window,
            * do. We should likely be consistent about whether we get
            * the client-side info or the server-side info.
            */
-          gdk_window_get_origin (widget->window, root_x, root_y);
+          gdk_window_get_origin (gdk_window, root_x, root_y);
         }
       else
         {
@@ -4292,10 +4577,7 @@ gtk_window_get_position (GtkWindow *window,
       
       if (gtk_widget_get_mapped (widget))
         {
-         if (window->frame)
-           gdk_window_get_frame_extents (window->frame, &frame_extents);
-         else
-           gdk_window_get_frame_extents (widget->window, &frame_extents);
+          gdk_window_get_frame_extents (gdk_window, &frame_extents);
           x = frame_extents.x;
           y = frame_extents.y;
           gtk_window_get_size (window, &w, &h);
@@ -4304,7 +4586,7 @@ gtk_window_get_position (GtkWindow *window,
         {
           /* We just say the frame has 0 size on all sides.
            * Not sure what else to do.
-           */             
+           */
           gtk_window_compute_configure_request (window,
                                                 &frame_extents,
                                                 NULL, NULL);
@@ -4314,7 +4596,7 @@ gtk_window_get_position (GtkWindow *window,
           h = frame_extents.height;
         }
       
-      switch (window->gravity)
+      switch (priv->gravity)
         {
         case GDK_GRAVITY_NORTH:
         case GDK_GRAVITY_CENTER:
@@ -4337,7 +4619,7 @@ gtk_window_get_position (GtkWindow *window,
           break;
         }
 
-      switch (window->gravity)
+      switch (priv->gravity)
         {
         case GDK_GRAVITY_WEST:
         case GDK_GRAVITY_CENTER:
@@ -4389,69 +4671,87 @@ gtk_window_reshow_with_initial_size (GtkWindow *window)
 }
 
 static void
-gtk_window_destroy (GtkObject *object)
+gtk_window_destroy (GtkWidget *widget)
 {
-  GtkWindow *window = GTK_WINDOW (object);
-  
+  GtkWindow *window = GTK_WINDOW (widget);
+  GtkWindowPrivate *priv = window->priv;
+
+  gtk_window_release_application (window);
+
   toplevel_list = g_slist_remove (toplevel_list, window);
 
-  if (window->transient_parent)
+  if (priv->transient_parent)
     gtk_window_set_transient_for (window, NULL);
 
+  remove_attach_widget (GTK_WINDOW (widget));
+
   /* frees the icons */
   gtk_window_set_icon_list (window, NULL);
-  
-  if (window->has_user_ref_count)
+
+  if (priv->has_user_ref_count)
     {
-      window->has_user_ref_count = FALSE;
+      priv->has_user_ref_count = FALSE;
       g_object_unref (window);
     }
 
-  if (window->group)
-    gtk_window_group_remove_window (window->group, window);
+  if (priv->group)
+    gtk_window_group_remove_window (priv->group, window);
 
    gtk_window_free_key_hash (window);
 
-   GTK_OBJECT_CLASS (gtk_window_parent_class)->destroy (object);
+  GTK_WIDGET_CLASS (gtk_window_parent_class)->destroy (widget);
 }
 
 static void
 gtk_window_finalize (GObject *object)
 {
   GtkWindow *window = GTK_WINDOW (object);
-  GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (window);
+  GtkWindowPrivate *priv = window->priv;
   GtkMnemonicHash *mnemonic_hash;
 
-  g_free (window->title);
-  g_free (window->wmclass_name);
-  g_free (window->wmclass_class);
-  g_free (window->wm_role);
+  g_free (priv->title);
+  g_free (priv->wmclass_name);
+  g_free (priv->wmclass_class);
+  g_free (priv->wm_role);
+  gtk_window_release_application (window);
 
   mnemonic_hash = gtk_window_get_mnemonic_hash (window, FALSE);
   if (mnemonic_hash)
     _gtk_mnemonic_hash_free (mnemonic_hash);
 
-  if (window->geometry_info)
+  if (priv->geometry_info)
     {
-      if (window->geometry_info->widget)
-       g_signal_handlers_disconnect_by_func (window->geometry_info->widget,
+      if (priv->geometry_info->widget)
+       g_signal_handlers_disconnect_by_func (priv->geometry_info->widget,
                                              gtk_widget_destroyed,
-                                             &window->geometry_info->widget);
-      g_free (window->geometry_info);
+                                             &priv->geometry_info->widget);
+      g_free (priv->geometry_info);
     }
 
-  if (window->keys_changed_handler)
+  if (priv->keys_changed_handler)
     {
-      g_source_remove (window->keys_changed_handler);
-      window->keys_changed_handler = 0;
+      g_source_remove (priv->keys_changed_handler);
+      priv->keys_changed_handler = 0;
     }
 
-  if (window->screen)
-    g_signal_handlers_disconnect_by_func (window->screen,
+  if (priv->screen)
+    g_signal_handlers_disconnect_by_func (priv->screen,
                                           gtk_window_on_composited_changed, window);
 
   g_free (priv->startup_id);
 
+  if (priv->auto_mnemonics_timeout_id)
+    {
+      g_source_remove (priv->auto_mnemonics_timeout_id);
+      priv->auto_mnemonics_timeout_id = 0;
+    }
+
+#ifdef GDK_WINDOWING_X11
+  g_signal_handlers_disconnect_by_func (gtk_settings_get_default (),
+                                        gtk_window_on_theme_variant_changed,
+                                        window);
+#endif
+
   G_OBJECT_CLASS (gtk_window_parent_class)->finalize (object);
 }
 
@@ -4459,13 +4759,28 @@ static void
 gtk_window_show (GtkWidget *widget)
 {
   GtkWindow *window = GTK_WINDOW (widget);
+  GtkWindowPrivate *priv = window->priv;
   GtkContainer *container = GTK_CONTAINER (window);
+  GtkBitmask *empty;
   gboolean need_resize;
+  gboolean is_plug;
+
+  if (!gtk_widget_is_toplevel (GTK_WIDGET (widget)))
+    {
+      GTK_WIDGET_CLASS (gtk_window_parent_class)->show (widget);
+      return;
+    }
 
-  GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
+  _gtk_widget_set_visible_flag (widget, TRUE);
 
-  need_resize = _gtk_container_get_need_resize (container) || !gtk_widget_get_realized (widget);
-  _gtk_container_set_need_resize (container, FALSE);
+  need_resize = _gtk_widget_get_alloc_needed (widget) || !gtk_widget_get_realized (widget);
+
+  empty = _gtk_bitmask_new ();
+  _gtk_style_context_validate (gtk_widget_get_style_context (widget),
+                               g_get_monotonic_time (),
+                               0,
+                               empty);
+  _gtk_bitmask_free (empty);
 
   if (need_resize)
     {
@@ -4508,17 +4823,12 @@ gtk_window_show (GtkWidget *widget)
          was_realized = TRUE;
        }
 
-      /* Must be done after the windows are realized,
-       * so that the decorations can be read
-       */
-      gtk_decorated_window_calculate_frame_size (window);
-
       /* We only send configure request if we didn't just finish
        * creating the window; if we just created the window
        * then we created it with widget->allocation anyhow.
        */
       if (!was_realized)
-       gdk_window_move_resize (widget->window,
+        gdk_window_move_resize (gtk_widget_get_window (widget),
                                configure_request.x,
                                configure_request.y,
                                configure_request.width,
@@ -4531,10 +4841,16 @@ gtk_window_show (GtkWidget *widget)
 
   /* Try to make sure that we have some focused widget
    */
-  if (!window->focus_widget && !GTK_IS_PLUG (window))
-    gtk_window_move_focus (window, GTK_DIR_TAB_FORWARD);
+#ifdef GDK_WINDOWING_X11
+  is_plug = GDK_IS_X11_WINDOW (gtk_widget_get_window (widget)) &&
+    GTK_IS_PLUG (window);
+#else
+  is_plug = FALSE;
+#endif
+  if (!priv->focus_widget && !is_plug)
+    gtk_window_move_focus (widget, GTK_DIR_TAB_FORWARD);
   
-  if (window->modal)
+  if (priv->modal)
     gtk_grab_add (widget);
 }
 
@@ -4542,11 +4858,18 @@ static void
 gtk_window_hide (GtkWidget *widget)
 {
   GtkWindow *window = GTK_WINDOW (widget);
+  GtkWindowPrivate *priv = window->priv;
 
-  GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
+  if (!gtk_widget_is_toplevel (GTK_WIDGET (widget)))
+    {
+      GTK_WIDGET_CLASS (gtk_window_parent_class)->hide (widget);
+      return;
+    }
+
+  _gtk_widget_set_visible_flag (widget, FALSE);
   gtk_widget_unmap (widget);
 
-  if (window->modal)
+  if (priv->modal)
     gtk_grab_remove (widget);
 }
 
@@ -4555,9 +4878,16 @@ gtk_window_map (GtkWidget *widget)
 {
   GtkWidget *child;
   GtkWindow *window = GTK_WINDOW (widget);
-  GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (window);
-  GdkWindow *toplevel;
+  GtkWindowPrivate *priv = window->priv;
+  GdkWindow *gdk_window;
   gboolean auto_mnemonics;
+  GtkPolicyType visible_focus;
+
+  if (!gtk_widget_is_toplevel (widget))
+    {
+      GTK_WIDGET_CLASS (gtk_window_parent_class)->map (widget);
+      return;
+    }
 
   gtk_widget_set_mapped (widget, TRUE);
 
@@ -4567,39 +4897,43 @@ gtk_window_map (GtkWidget *widget)
       !gtk_widget_get_mapped (child))
     gtk_widget_map (child);
 
-  if (window->frame)
-    toplevel = window->frame;
-  else
-    toplevel = widget->window;
-  
-  if (window->maximize_initially)
-    gdk_window_maximize (toplevel);
+  gdk_window = gtk_widget_get_window (widget);
+
+  if (priv->maximize_initially)
+    gdk_window_maximize (gdk_window);
   else
-    gdk_window_unmaximize (toplevel);
-  
-  if (window->stick_initially)
-    gdk_window_stick (toplevel);
+    gdk_window_unmaximize (gdk_window);
+
+  if (priv->stick_initially)
+    gdk_window_stick (gdk_window);
   else
-    gdk_window_unstick (toplevel);
-  
-  if (window->iconify_initially)
-    gdk_window_iconify (toplevel);
+    gdk_window_unstick (gdk_window);
+
+  if (priv->iconify_initially)
+    gdk_window_iconify (gdk_window);
   else
-    gdk_window_deiconify (toplevel);
+    gdk_window_deiconify (gdk_window);
 
   if (priv->fullscreen_initially)
-    gdk_window_fullscreen (toplevel);
+    gdk_window_fullscreen (gdk_window);
   else
-    gdk_window_unfullscreen (toplevel);
-  
-  gdk_window_set_keep_above (toplevel, priv->above_initially);
+    gdk_window_unfullscreen (gdk_window);
+
+  gdk_window_set_keep_above (gdk_window, priv->above_initially);
 
-  gdk_window_set_keep_below (toplevel, priv->below_initially);
+  gdk_window_set_keep_below (gdk_window, priv->below_initially);
+
+  if (priv->type == GTK_WINDOW_TOPLEVEL)
+    {
+      gtk_window_set_theme_variant (window);
+      gtk_window_set_hide_titlebar_when_maximized (window,
+                                                   priv->hide_titlebar_when_maximized);
+    }
 
   /* No longer use the default settings */
-  window->need_default_size = FALSE;
-  window->need_default_position = FALSE;
-  
+  priv->need_default_size = FALSE;
+  priv->need_default_position = FALSE;
+
   if (priv->reset_type_hint)
     {
       /* We should only reset the type hint when the application
@@ -4607,14 +4941,14 @@ gtk_window_map (GtkWidget *widget)
        * Some applications use X directly to change the properties;
        * in that case, we shouldn't overwrite what they did.
        */
-      gdk_window_set_type_hint (widget->window, priv->type_hint);
+      gdk_window_set_type_hint (gdk_window, priv->gdk_type_hint);
       priv->reset_type_hint = FALSE;
     }
 
-  gdk_window_show (widget->window);
+  gdk_window_show (gdk_window);
 
-  if (window->frame)
-    gdk_window_show (window->frame);
+  if (priv->grip_window)
+    gdk_window_show (priv->grip_window);
 
   if (!disable_startup_notification)
     {
@@ -4622,7 +4956,7 @@ gtk_window_map (GtkWidget *widget)
       if (priv->startup_id != NULL)
         {
           /* Make sure we have a "real" id */
-          if (!startup_id_is_fake (priv->startup_id)) 
+          if (!startup_id_is_fake (priv->startup_id))
             gdk_notify_startup_complete_with_id (priv->startup_id);
 
           g_free (priv->startup_id);
@@ -4638,10 +4972,21 @@ gtk_window_map (GtkWidget *widget)
   /* if auto-mnemonics is enabled and mnemonics visible is not already set
    * (as in the case of popup menus), then hide mnemonics initially
    */
-  g_object_get (gtk_widget_get_settings (widget), "gtk-auto-mnemonics",
-                &auto_mnemonics, NULL);
+  g_object_get (gtk_widget_get_settings (widget),
+                "gtk-auto-mnemonics", &auto_mnemonics,
+                "gtk-visible-focus", &visible_focus,
+                NULL);
+
   if (auto_mnemonics && !priv->mnemonics_visible_set)
     gtk_window_set_mnemonics_visible (window, FALSE);
+
+  /* inherit from transient parent, so that a dialog that is
+   * opened via keynav shows focus initially
+   */
+  if (priv->transient_parent)
+    gtk_window_set_focus_visible (window, gtk_window_get_focus_visible (priv->transient_parent));
+  else
+    gtk_window_set_focus_visible (window, visible_focus == GTK_POLICY_ALWAYS);
 }
 
 static gboolean
@@ -4657,7 +5002,7 @@ gtk_window_map_event (GtkWidget   *widget,
        * the window being unmapped. more details can be found in:
        *   http://bugzilla.gnome.org/show_bug.cgi?id=316180
        */
-      gdk_window_hide (widget->window);
+      gdk_window_hide (gtk_widget_get_window (widget));
     }
   return FALSE;
 }
@@ -4666,24 +5011,31 @@ static void
 gtk_window_unmap (GtkWidget *widget)
 {
   GtkWindow *window = GTK_WINDOW (widget);
-  GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (widget);
-  GtkWindowGeometryInfo *info;    
+  GtkWindowPrivate *priv = window->priv;
+  GtkWidget *child;
+  GtkWindowGeometryInfo *info;
+  GdkWindow *gdk_window;
   GdkWindowState state;
 
+  if (!gtk_widget_is_toplevel (GTK_WIDGET (widget)))
+    {
+      GTK_WIDGET_CLASS (gtk_window_parent_class)->unmap (widget);
+      return;
+    }
+
+  gdk_window = gtk_widget_get_window (widget);
+
   gtk_widget_set_mapped (widget, FALSE);
-  if (window->frame)
-    gdk_window_withdraw (window->frame);
-  else 
-    gdk_window_withdraw (widget->window);
-  
-  window->configure_request_count = 0;
-  window->configure_notify_received = FALSE;
+  gdk_window_withdraw (gdk_window);
+
+  priv->configure_request_count = 0;
+  priv->configure_notify_received = FALSE;
 
   /* on unmap, we reset the default positioning of the window,
    * so it's placed again, but we don't reset the default
    * size of the window, so it's remembered.
    */
-  window->need_default_position = TRUE;
+  priv->need_default_position = TRUE;
 
   info = gtk_window_get_geometry_info (window, FALSE);
   if (info)
@@ -4692,41 +5044,149 @@ gtk_window_unmap (GtkWidget *widget)
       info->position_constraints_changed = FALSE;
     }
 
-  state = gdk_window_get_state (widget->window);
-  window->iconify_initially = (state & GDK_WINDOW_STATE_ICONIFIED) != 0;
-  window->maximize_initially = (state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
-  window->stick_initially = (state & GDK_WINDOW_STATE_STICKY) != 0;
+  state = gdk_window_get_state (gdk_window);
+  priv->iconify_initially = (state & GDK_WINDOW_STATE_ICONIFIED) != 0;
+  priv->maximize_initially = (state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
+  priv->stick_initially = (state & GDK_WINDOW_STATE_STICKY) != 0;
   priv->above_initially = (state & GDK_WINDOW_STATE_ABOVE) != 0;
   priv->below_initially = (state & GDK_WINDOW_STATE_BELOW) != 0;
+
+  child = gtk_bin_get_child (&(window->bin));
+  if (child)
+    gtk_widget_unmap (child);
+}
+
+/* (Note: Replace "size" with "width" or "height". Also, the request
+ * mode is honoured.)
+ * For selecting the default window size, the following conditions
+ * should hold (in order of importance):
+ * - the size is not below the minimum size
+ *   Windows cannot be resized below their minimum size, so we must
+ *   ensure we don't do that either.
+ * - the size is not above the natural size
+ *   It seems weird to allocate more than this in an initial guess.
+ * - the size does not exceed that of a maximized window
+ *   We want to see the whole window after all.
+ *   (Note that this may not be possible to achieve due to imperfect
+ *    information from the windowing system.)
+ */
+
+/* We use these for now to not make windows too big by accident. Note
+ * that we still clamp these numbers by screen size. Also note that
+ * minimum size still overrides this. So keep your windows small! :)
+ */
+#define MAX_DEFAULT_WINDOW_WIDTH 640
+#define MAX_DEFAULT_WINDOW_HEIGHT 480
+
+static void
+gtk_window_guess_default_size (GtkWindow *window,
+                               gint      *width,
+                               gint      *height)
+{
+  GtkWidget *widget = GTK_WIDGET (window);
+  GdkScreen *screen;
+  int minimum, natural;
+
+  screen = gtk_widget_get_screen (widget);
+
+  *width = gdk_screen_get_width (screen);
+  *height = gdk_screen_get_height (screen);
+
+  if (*width >= *height)
+    {
+      /* landscape */
+      *width = MIN (*width, MAX_DEFAULT_WINDOW_WIDTH);
+      *height = MIN (*height, MAX_DEFAULT_WINDOW_HEIGHT);
+    }
+  else
+    {
+      /* portrait */
+      *width = MIN (*width, MAX_DEFAULT_WINDOW_HEIGHT);
+      *height = MIN (*height, MAX_DEFAULT_WINDOW_WIDTH);
+    }
+
+  if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT)
+    {
+      gtk_widget_get_preferred_height (widget, &minimum, &natural);
+      *height = MAX (minimum, MIN (*height, natural));
+
+      gtk_widget_get_preferred_width_for_height (widget, *height, &minimum, &natural);
+      *width = MAX (minimum, MIN (*width, natural));
+    }
+  else /* GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH or CONSTANT_SIZE */
+    {
+      gtk_widget_get_preferred_width (widget, &minimum, &natural);
+      *width = MAX (minimum, MIN (*width, natural));
+
+      gtk_widget_get_preferred_height_for_width (widget, *width, &minimum, &natural);
+      *height = MAX (minimum, MIN (*height, natural));
+    }
 }
 
 static void
 gtk_window_realize (GtkWidget *widget)
 {
+  GtkAllocation allocation;
   GtkWindow *window;
   GdkWindow *parent_window;
+  GdkWindow *gdk_window;
   GdkWindowAttr attributes;
   gint attributes_mask;
   GtkWindowPrivate *priv;
-  
+  GtkStyleContext *context;
+
   window = GTK_WINDOW (widget);
-  priv = GTK_WINDOW_GET_PRIVATE (window);
+  priv = window->priv;
+
+  gtk_widget_get_allocation (widget, &allocation);
+
+  if (gtk_widget_get_parent_window (widget))
+    {
+      gtk_container_set_resize_mode (GTK_CONTAINER (widget), GTK_RESIZE_PARENT);
+
+      gtk_widget_set_realized (widget, TRUE);
+
+      attributes.x = allocation.x;
+      attributes.y = allocation.y;
+      attributes.width = allocation.width;
+      attributes.height = allocation.height;
+      attributes.window_type = GDK_WINDOW_CHILD;
+
+      attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK | GDK_STRUCTURE_MASK;
+
+      attributes.visual = gtk_widget_get_visual (widget);
+      attributes.wclass = GDK_INPUT_OUTPUT;
+
+      attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
+
+      gdk_window = gdk_window_new (gtk_widget_get_parent_window (widget),
+                                  &attributes, attributes_mask);
+      gtk_widget_set_window (widget, gdk_window);
+      gtk_widget_register_window (widget, gdk_window);
+
+      gtk_style_context_set_background (gtk_widget_get_style_context (widget), gdk_window);
+
+      return;
+    }
+
+  gtk_container_set_resize_mode (GTK_CONTAINER (window), GTK_RESIZE_QUEUE);
 
   /* ensure widget tree is properly size allocated */
-  if (widget->allocation.x == -1 &&
-      widget->allocation.y == -1 &&
-      widget->allocation.width == 1 &&
-      widget->allocation.height == 1)
+  if (allocation.x == -1 &&
+      allocation.y == -1 &&
+      allocation.width == 1 &&
+      allocation.height == 1)
     {
-      GtkRequisition requisition;
-      GtkAllocation allocation = { 0, 0, 200, 200 };
 
-      gtk_widget_size_request (widget, &requisition);
-      if (requisition.width || requisition.height)
+      allocation.x = 0;
+      allocation.y = 0;
+
+      gtk_window_guess_default_size (window, &allocation.width, &allocation.height);
+      if (allocation.width == 0 || allocation.height == 0)
        {
          /* non-empty window */
-         allocation.width = requisition.width;
-         allocation.height = requisition.height;
+         allocation.width = 200;
+         allocation.height = 200;
        }
       gtk_widget_size_allocate (widget, &allocation);
       
@@ -4737,7 +5197,7 @@ gtk_window_realize (GtkWidget *widget)
   
   gtk_widget_set_realized (widget, TRUE);
   
-  switch (window->type)
+  switch (priv->type)
     {
     case GTK_WINDOW_TOPLEVEL:
       attributes.window_type = GDK_WINDOW_TOPLEVEL;
@@ -4746,63 +5206,22 @@ gtk_window_realize (GtkWidget *widget)
       attributes.window_type = GDK_WINDOW_TEMP;
       break;
     default:
-      g_warning (G_STRLOC": Unknown window type %d!", window->type);
+      g_warning (G_STRLOC": Unknown window type %d!", priv->type);
       break;
     }
-   
-  attributes.title = window->title;
-  attributes.wmclass_name = window->wmclass_name;
-  attributes.wmclass_class = window->wmclass_class;
+
+  attributes.title = priv->title;
+  attributes.wmclass_name = priv->wmclass_name;
+  attributes.wmclass_class = priv->wmclass_class;
   attributes.wclass = GDK_INPUT_OUTPUT;
   attributes.visual = gtk_widget_get_visual (widget);
-  attributes.colormap = gtk_widget_get_colormap (widget);
-
-  if (window->has_frame)
-    {
-      attributes.width = widget->allocation.width + window->frame_left + window->frame_right;
-      attributes.height = widget->allocation.height + window->frame_top + window->frame_bottom;
-      attributes.event_mask = (GDK_EXPOSURE_MASK |
-                              GDK_KEY_PRESS_MASK |
-                              GDK_ENTER_NOTIFY_MASK |
-                              GDK_LEAVE_NOTIFY_MASK |
-                              GDK_FOCUS_CHANGE_MASK |
-                              GDK_STRUCTURE_MASK |
-                              GDK_BUTTON_MOTION_MASK |
-                              GDK_POINTER_MOTION_HINT_MASK |
-                              GDK_BUTTON_PRESS_MASK |
-                              GDK_BUTTON_RELEASE_MASK);
-      
-      attributes_mask = GDK_WA_VISUAL | GDK_WA_COLORMAP;
-      
-      window->frame = gdk_window_new (gtk_widget_get_root_window (widget),
-                                     &attributes, attributes_mask);
-                                                
-      if (priv->opacity_set)
-       gdk_window_set_opacity (window->frame, priv->opacity);
-
-      gdk_window_set_user_data (window->frame, widget);
-      
-      attributes.window_type = GDK_WINDOW_CHILD;
-      attributes.x = window->frame_left;
-      attributes.y = window->frame_top;
-    
-      attributes_mask = GDK_WA_X | GDK_WA_Y;
 
-      parent_window = window->frame;
+  attributes_mask = 0;
+  parent_window = gtk_widget_get_root_window (widget);
 
-      g_signal_connect (window,
-                       "event",
-                       G_CALLBACK (gtk_window_event),
-                       NULL);
-    }
-  else
-    {
-      attributes_mask = 0;
-      parent_window = gtk_widget_get_root_window (widget);
-    }
-  
-  attributes.width = widget->allocation.width;
-  attributes.height = widget->allocation.height;
+  gtk_widget_get_allocation (widget, &allocation);
+  attributes.width = allocation.width;
+  attributes.height = allocation.height;
   attributes.event_mask = gtk_widget_get_events (widget);
   attributes.event_mask |= (GDK_EXPOSURE_MASK |
                            GDK_KEY_PRESS_MASK |
@@ -4813,92 +5232,97 @@ gtk_window_realize (GtkWidget *widget)
                            GDK_STRUCTURE_MASK);
   attributes.type_hint = priv->type_hint;
 
-  attributes_mask |= GDK_WA_VISUAL | GDK_WA_COLORMAP | GDK_WA_TYPE_HINT;
-  attributes_mask |= (window->title ? GDK_WA_TITLE : 0);
-  attributes_mask |= (window->wmclass_name ? GDK_WA_WMCLASS : 0);
-  
-  widget->window = gdk_window_new (parent_window, &attributes, attributes_mask);
+  attributes_mask |= GDK_WA_VISUAL | GDK_WA_TYPE_HINT;
+  attributes_mask |= (priv->title ? GDK_WA_TITLE : 0);
+  attributes_mask |= (priv->wmclass_name ? GDK_WA_WMCLASS : 0);
 
-  if (!window->has_frame && priv->opacity_set)
-    gdk_window_set_opacity (widget->window, priv->opacity);
+  gdk_window = gdk_window_new (parent_window, &attributes, attributes_mask);
+  gtk_widget_set_window (widget, gdk_window);
 
-  gdk_window_enable_synchronized_configure (widget->window);
-    
-  gdk_window_set_user_data (widget->window, window);
-      
-  widget->style = gtk_style_attach (widget->style, widget->window);
-  gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
-  if (window->frame)
-    gtk_style_set_background (widget->style, window->frame, GTK_STATE_NORMAL);
+  gtk_widget_register_window (widget, gdk_window);
 
-  /* This is a bad hack to set the window background. */
-  gtk_window_paint (widget, NULL);
-  
-  if (window->transient_parent &&
-      gtk_widget_get_realized (GTK_WIDGET (window->transient_parent)))
-    gdk_window_set_transient_for (widget->window,
-                                 GTK_WIDGET (window->transient_parent)->window);
+  context = gtk_widget_get_style_context (widget);
+  gtk_style_context_set_background (context, gdk_window);
 
-  if (window->wm_role)
-    gdk_window_set_role (widget->window, window->wm_role);
-  
-  if (!window->decorated)
-    gdk_window_set_decorations (widget->window, 0);
 
-  if (!priv->deletable)
-    gdk_window_set_functions (widget->window, GDK_FUNC_ALL | GDK_FUNC_CLOSE);
+  if (priv->transient_parent &&
+      gtk_widget_get_realized (GTK_WIDGET (priv->transient_parent)))
+    gdk_window_set_transient_for (gdk_window,
+                                  gtk_widget_get_window (GTK_WIDGET (priv->transient_parent)));
 
+  if (priv->wm_role)
+    gdk_window_set_role (gdk_window, priv->wm_role);
+  
+  if (!priv->decorated)
+    gdk_window_set_decorations (gdk_window, 0);
+  
+  if (!priv->deletable)
+    gdk_window_set_functions (gdk_window, GDK_FUNC_ALL | GDK_FUNC_CLOSE);
+  
   if (gtk_window_get_skip_pager_hint (window))
-    gdk_window_set_skip_pager_hint (widget->window, TRUE);
-
+    gdk_window_set_skip_pager_hint (gdk_window, TRUE);
+  
   if (gtk_window_get_skip_taskbar_hint (window))
-    gdk_window_set_skip_taskbar_hint (widget->window, TRUE);
-
+    gdk_window_set_skip_taskbar_hint (gdk_window, TRUE);
+  
   if (gtk_window_get_accept_focus (window))
-    gdk_window_set_accept_focus (widget->window, TRUE);
+    gdk_window_set_accept_focus (gdk_window, TRUE);
   else
-    gdk_window_set_accept_focus (widget->window, FALSE);
-
+    gdk_window_set_accept_focus (gdk_window, FALSE);
+  
   if (gtk_window_get_focus_on_map (window))
-    gdk_window_set_focus_on_map (widget->window, TRUE);
+    gdk_window_set_focus_on_map (gdk_window, TRUE);
   else
-    gdk_window_set_focus_on_map (widget->window, FALSE);
+    gdk_window_set_focus_on_map (gdk_window, FALSE);
   
-  if (window->modal)
-    gdk_window_set_modal_hint (widget->window, TRUE);
+  if (priv->modal)
+    gdk_window_set_modal_hint (gdk_window, TRUE);
   else
-    gdk_window_set_modal_hint (widget->window, FALSE);
-    
+    gdk_window_set_modal_hint (gdk_window, FALSE);
+
   if (priv->startup_id)
     {
 #ifdef GDK_WINDOWING_X11
-      guint32 timestamp = extract_time_from_startup_id (priv->startup_id);
-      if (timestamp != GDK_CURRENT_TIME)
-        gdk_x11_window_set_user_time (widget->window, timestamp);
+      if (GDK_IS_X11_WINDOW (gdk_window))
+        {
+          guint32 timestamp = extract_time_from_startup_id (priv->startup_id);
+          if (timestamp != GDK_CURRENT_TIME)
+            gdk_x11_window_set_user_time (gdk_window, timestamp);
+        }
 #endif
-      if (!startup_id_is_fake (priv->startup_id)) 
-        gdk_window_set_startup_id (widget->window, priv->startup_id);
+      if (!startup_id_is_fake (priv->startup_id))
+        gdk_window_set_startup_id (gdk_window, priv->startup_id);
+    }
+
+#ifdef GDK_WINDOWING_X11
+  if (priv->initial_timestamp != GDK_CURRENT_TIME)
+    {
+      if (GDK_IS_X11_WINDOW (gdk_window))
+        gdk_x11_window_set_user_time (gdk_window, priv->initial_timestamp);
     }
+#endif
 
   /* Icons */
   gtk_window_realize_icon (window);
+  
+  if (priv->has_resize_grip)
+    resize_grip_create_window (window);
 }
 
 static void
 gtk_window_unrealize (GtkWidget *widget)
 {
-  GtkWindow *window;
+  GtkWindow *window = GTK_WINDOW (widget);
+  GtkWindowPrivate *priv = window->priv;
   GtkWindowGeometryInfo *info;
 
-  window = GTK_WINDOW (widget);
-
   /* On unrealize, we reset the size of the window such
    * that we will re-apply the default sizing stuff
    * next time we show the window.
    *
    * Default positioning is reset on unmap, instead of unrealize.
    */
-  window->need_default_size = TRUE;
+  priv->need_default_size = TRUE;
   info = gtk_window_get_geometry_info (window, FALSE);
   if (info)
     {
@@ -4911,136 +5335,269 @@ gtk_window_unrealize (GtkWidget *widget)
       /* be sure we reset geom hints on re-realize */
       info->last.flags = 0;
     }
-  
-  if (window->frame)
-    {
-      gdk_window_set_user_data (window->frame, NULL);
-      gdk_window_destroy (window->frame);
-      window->frame = NULL;
-    }
 
   /* Icons */
   gtk_window_unrealize_icon (window);
 
+  if (priv->grip_window != NULL)
+    resize_grip_destroy_window (window);
+
   GTK_WIDGET_CLASS (gtk_window_parent_class)->unrealize (widget);
 }
 
-static void
-gtk_window_size_allocate (GtkWidget     *widget,
-                         GtkAllocation *allocation)
+static GtkJunctionSides
+get_grip_junction (GtkWidget *widget)
 {
-  GtkWindow *window;
-  GtkAllocation child_allocation;
-  GtkWidget *child;
-  guint border_width;
+  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
+    return GTK_JUNCTION_CORNER_BOTTOMRIGHT;
+  else
+    return GTK_JUNCTION_CORNER_BOTTOMLEFT;
+}
 
-  window = GTK_WINDOW (widget);
-  widget->allocation = *allocation;
+static gboolean
+get_drag_edge (GtkWidget     *widget,
+               GdkWindowEdge *edge)
+{
+  GtkWindowPrivate *priv = GTK_WINDOW (widget)->priv;
+  gboolean hresizable;
+  gboolean vresizable;
+  GtkTextDirection dir;
+  GtkWindowGeometryInfo *info;
 
-  child = gtk_bin_get_child (&(window->bin));
-  if (child && gtk_widget_get_visible (child))
+  hresizable = TRUE;
+  vresizable = TRUE;
+
+  info = priv->geometry_info;
+  if (info)
     {
-      border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
-      child_allocation.x = border_width;
-      child_allocation.y = border_width;
-      child_allocation.width =
-       MAX (1, (gint)allocation->width - child_allocation.x * 2);
-      child_allocation.height =
-       MAX (1, (gint)allocation->height - child_allocation.y * 2);
+      GdkWindowHints flags = info->last.flags;
+      GdkGeometry *geometry = &info->last.geometry;
 
-      gtk_widget_size_allocate (child, &child_allocation);
+      if ((flags & GDK_HINT_MIN_SIZE) && (flags & GDK_HINT_MAX_SIZE))
+        {
+          hresizable = geometry->min_width < geometry->max_width;
+          vresizable = geometry->min_height < geometry->max_height;
+        }
     }
 
-  if (gtk_widget_get_realized (widget) && window->frame)
-    {
-      gdk_window_resize (window->frame,
-                        allocation->width + window->frame_left + window->frame_right,
-                        allocation->height + window->frame_top + window->frame_bottom);
-    }
+  dir = gtk_widget_get_direction (widget);
+
+  if (hresizable && vresizable)
+    *edge = dir == GTK_TEXT_DIR_LTR ? GDK_WINDOW_EDGE_SOUTH_EAST : GDK_WINDOW_EDGE_SOUTH_WEST;
+  else if (hresizable)
+    *edge = dir == GTK_TEXT_DIR_LTR ? GDK_WINDOW_EDGE_EAST : GDK_WINDOW_EDGE_WEST;
+  else if (vresizable)
+    *edge = GDK_WINDOW_EDGE_SOUTH;
+  else
+    return FALSE;
+
+  return TRUE;
 }
 
-static gint
-gtk_window_event (GtkWidget *widget, GdkEvent *event)
+static void
+set_grip_cursor (GtkWindow *window)
 {
-  GtkWindow *window;
-  gboolean return_val;
+  GtkWidget *widget = GTK_WIDGET (window);
+  GtkWindowPrivate *priv = window->priv;
 
-  window = GTK_WINDOW (widget);
+  if (priv->grip_window == NULL)
+    return;
 
-  if (window->frame && (event->any.window == window->frame))
+  if (gtk_widget_is_sensitive (widget))
     {
-      if ((event->type != GDK_KEY_PRESS) &&
-         (event->type != GDK_KEY_RELEASE) &&
-         (event->type != GDK_FOCUS_CHANGE))
-       {
-         g_signal_stop_emission_by_name (widget, "event");
-         return_val = FALSE;
-         g_signal_emit (widget, window_signals[FRAME_EVENT], 0, event, &return_val);
-         return TRUE;
-       }
-      else
-       {
-         g_object_unref (event->any.window);
-         event->any.window = g_object_ref (widget->window);
-       }
-    }
+      GdkWindowEdge edge;
+      GdkDisplay *display;
+      GdkCursorType cursor_type;
+      GdkCursor *cursor;
 
-  return FALSE;
-}
+      cursor_type = GDK_LEFT_PTR;
 
-static gboolean
-gtk_window_frame_event (GtkWindow *window, GdkEvent *event)
-{
-  GdkEventConfigure *configure_event;
-  GdkRectangle rect;
+      if (get_drag_edge (widget, &edge))
+        {
+          switch (edge)
+            {
+            case GDK_WINDOW_EDGE_EAST:
+              cursor_type = GDK_RIGHT_SIDE;
+              break;
+            case GDK_WINDOW_EDGE_SOUTH_EAST:
+              cursor_type = GDK_BOTTOM_RIGHT_CORNER;
+              break;
+            case GDK_WINDOW_EDGE_SOUTH:
+              cursor_type = GDK_BOTTOM_SIDE;
+              break;
+            case GDK_WINDOW_EDGE_SOUTH_WEST:
+              cursor_type = GDK_BOTTOM_LEFT_CORNER;
+              break;
+            case GDK_WINDOW_EDGE_WEST:
+              cursor_type = GDK_LEFT_SIDE;
+              break;
+            default: ;
+            }
+        }
 
-  switch (event->type)
-    {
-    case GDK_CONFIGURE:
-      configure_event = (GdkEventConfigure *)event;
-      
-      /* Invalidate the decorations */
-      rect.x = 0;
-      rect.y = 0;
-      rect.width = configure_event->width;
-      rect.height = configure_event->height;
-      
-      gdk_window_invalidate_rect (window->frame, &rect, FALSE);
+      display = gtk_widget_get_display (widget);
+      cursor = gdk_cursor_new_for_display (display, cursor_type);
+      gdk_window_set_cursor (priv->grip_window, cursor);
+      g_object_unref (cursor);
+    }
+  else
+    gdk_window_set_cursor (priv->grip_window, NULL);
+}
 
-      /* Pass on the (modified) configure event */
-      configure_event->width -= window->frame_left + window->frame_right;
-      configure_event->height -= window->frame_top + window->frame_bottom;
-      return gtk_window_configure_event (GTK_WIDGET (window), configure_event);
-      break;
-    default:
-      break;
+static void
+set_grip_shape (GtkWindow *window)
+{
+  GtkWindowPrivate *priv = window->priv;
+  cairo_region_t *region;
+  cairo_surface_t *surface;
+  cairo_t *cr;
+  double width, height;
+
+  if (priv->grip_window == NULL)
+    return;
+
+  width = gdk_window_get_width (priv->grip_window);
+  height = gdk_window_get_height (priv->grip_window);
+  surface = cairo_image_surface_create (CAIRO_FORMAT_A1, width, height);
+
+  cr = cairo_create (surface);
+  cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
+  cairo_paint (cr);
+  cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
+  if (get_grip_junction (GTK_WIDGET (window)) & GTK_JUNCTION_CORNER_BOTTOMRIGHT)
+    {
+      cairo_move_to (cr, width, 0.0);
+      cairo_line_to (cr, width, height);
+      cairo_line_to (cr, 0.0, height);
+    }
+  else
+    {
+      cairo_move_to (cr, 0.0, 0.0);
+      cairo_line_to (cr, width, height);
+      cairo_line_to (cr, 0.0, height);
+    }
+  cairo_close_path (cr);
+  cairo_fill (cr);
+  cairo_destroy (cr);
+  region = gdk_cairo_region_create_from_surface (surface);
+  cairo_surface_destroy (surface);
+
+  gdk_window_shape_combine_region (priv->grip_window, region, 0, 0);
+  cairo_region_destroy (region);
+}
+
+static void
+set_grip_position (GtkWindow *window)
+{
+  GtkWindowPrivate *priv = window->priv;
+  GdkRectangle rect;
+
+  if (priv->grip_window == NULL)
+    return;
+
+  gtk_window_get_resize_grip_area (window, &rect);
+  gdk_window_raise (priv->grip_window);
+  gdk_window_move_resize (priv->grip_window,
+                          rect.x, rect.y,
+                          rect.width, rect.height);
+}
+
+/* _gtk_window_set_allocation:
+ * @window: a #GtkWindow
+ * @allocation: the new allocation
+ *
+ * This function is like gtk_widget_set_allocation()
+ * but does the necessary extra work to update
+ * the resize grip positioning, etc.
+ *
+ * Call this instead of gtk_widget_set_allocation()
+ * when overriding ::size_allocate in a GtkWindow
+ * subclass without chaining up.
+ */
+void
+_gtk_window_set_allocation (GtkWindow     *window,
+                            GtkAllocation *allocation)
+{
+  GtkWidget *widget = (GtkWidget *)window;
+
+  gtk_widget_set_allocation (widget, allocation);
+
+  if (gtk_widget_get_realized (widget))
+    {
+      /* If it's not a toplevel we're embedded, we need to resize
+       * the window's window and skip the grip.
+       */
+      if (!gtk_widget_is_toplevel (widget))
+        {
+          gdk_window_move_resize (gtk_widget_get_window (widget),
+                                  allocation->x, allocation->y,
+                                  allocation->width, allocation->height);
+        }
+      else
+        {
+          update_grip_visibility (window);
+          set_grip_position (window);
+        }
+    }
+}
+
+static void
+gtk_window_size_allocate (GtkWidget     *widget,
+                          GtkAllocation *allocation)
+{
+  GtkWindow *window = GTK_WINDOW (widget);
+  GtkAllocation child_allocation;
+  GtkWidget *child;
+  guint border_width;
+
+  _gtk_window_set_allocation (window, allocation);
+
+  child = gtk_bin_get_child (&(window->bin));
+  if (child && gtk_widget_get_visible (child))
+    {
+      border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
+      child_allocation.x = border_width;
+      child_allocation.y = border_width;
+      child_allocation.width = MAX (1, allocation->width - border_width * 2);
+      child_allocation.height = MAX (1, allocation->height - border_width * 2);
+
+      gtk_widget_size_allocate (child, &child_allocation);
     }
-  return FALSE;
 }
 
 static gint
 gtk_window_configure_event (GtkWidget         *widget,
                            GdkEventConfigure *event)
 {
+  GtkAllocation allocation;
   GtkWindow *window = GTK_WINDOW (widget);
-  gboolean expected_reply = window->configure_request_count > 0;
+  GtkWindowPrivate *priv = window->priv;
+  gboolean expected_reply = priv->configure_request_count > 0;
+
+  if (!gtk_widget_is_toplevel (GTK_WIDGET (widget)))
+    {
+      if (GTK_WIDGET_CLASS (gtk_window_parent_class)->configure_event)
+       return GTK_WIDGET_CLASS (gtk_window_parent_class)->configure_event (widget, event);
+
+      return FALSE;
+    }
 
-  /* window->configure_request_count incremented for each 
+  /* priv->configure_request_count incremented for each
    * configure request, and decremented to a min of 0 for
    * each configure notify.
    *
    * All it means is that we know we will get at least
-   * window->configure_request_count more configure notifies.
+   * priv->configure_request_count more configure notifies.
    * We could get more configure notifies than that; some
    * of the configure notifies we get may be unrelated to
    * the configure requests. But we will get at least
-   * window->configure_request_count notifies.
+   * priv->configure_request_count notifies.
    */
 
-  if (window->configure_request_count > 0)
+  if (priv->configure_request_count > 0)
     {
-      window->configure_request_count -= 1;
-      gdk_window_thaw_toplevel_updates_libgtk_only (widget->window);
+      priv->configure_request_count -= 1;
+      gdk_window_thaw_toplevel_updates_libgtk_only (gtk_widget_get_window (widget));
     }
   
   /* As an optimization, we avoid a resize when possible.
@@ -5050,18 +5607,16 @@ gtk_window_configure_event (GtkWidget         *widget,
    *   - we know we have made more requests and so will get more
    *     notifies and can wait to resize when we get them
    */
-  
+  gtk_widget_get_allocation (widget, &allocation);
   if (!expected_reply &&
-      (widget->allocation.width == event->width &&
-       widget->allocation.height == event->height))
+      (allocation.width == event->width &&
+       allocation.height == event->height))
     {
-      gdk_window_configure_finished (widget->window);
       return TRUE;
     }
 
   /*
    * If we do need to resize, we do that by:
-   *   - filling in widget->allocation with the new size
    *   - setting configure_notify_received to TRUE
    *     for use in gtk_window_move_resize()
    *   - queueing a resize, leading to invocation of
@@ -5069,16 +5624,307 @@ gtk_window_configure_event (GtkWidget         *widget,
    *
    */
   
-  window->configure_notify_received = TRUE;
-  
-  widget->allocation.width = event->width;
-  widget->allocation.height = event->height;
-  
+  priv->configure_notify_received = TRUE;
+
+  gdk_window_invalidate_rect (gtk_widget_get_window (widget), NULL, FALSE); // XXX - What was this for again?
+
   _gtk_container_queue_resize (GTK_CONTAINER (widget));
   
   return TRUE;
 }
 
+static gboolean
+gtk_window_state_event (GtkWidget           *widget,
+                        GdkEventWindowState *event)
+{
+  update_grip_visibility (GTK_WINDOW (widget));
+
+  if (event->changed_mask & GDK_WINDOW_STATE_FOCUSED)
+    ensure_state_flag_backdrop (widget);
+
+  return FALSE;
+}
+
+static void
+gtk_window_direction_changed (GtkWidget        *widget,
+                              GtkTextDirection  prev_dir)
+{
+  GtkWindow *window = GTK_WINDOW (widget);
+
+  set_grip_cursor (window);
+  set_grip_position (window);
+  set_grip_shape (window);
+}
+
+static void
+gtk_window_state_changed (GtkWidget    *widget,
+                          GtkStateType  previous_state)
+{
+  GtkWindow *window = GTK_WINDOW (widget);
+
+  update_grip_visibility (window);
+}
+
+static void
+gtk_window_style_updated (GtkWidget *widget)
+{
+  GtkWindow *window = GTK_WINDOW (widget);
+  GtkWindowPrivate *priv = window->priv;
+  GdkRectangle rect;
+
+  GTK_WIDGET_CLASS (gtk_window_parent_class)->style_updated (widget);
+
+  if (priv->grip_window != NULL && gtk_window_get_resize_grip_area (window, &rect))
+    {
+      gdk_window_move_resize (priv->grip_window,
+                              rect.x, rect.y,
+                              rect.width, rect.height);
+
+      set_grip_shape (window);
+    }
+}
+
+static void
+resize_grip_create_window (GtkWindow *window)
+{
+  GtkWidget *widget;
+  GtkWindowPrivate *priv;
+  GdkWindowAttr attributes;
+  gint attributes_mask;
+  GdkRectangle rect;
+  GdkRGBA transparent = {0, 0, 0, 0};
+
+  priv = window->priv;
+  widget = GTK_WIDGET (window);
+
+  g_return_if_fail (gtk_widget_get_realized (widget));
+  g_return_if_fail (priv->grip_window == NULL);
+
+  gtk_window_get_resize_grip_area (window, &rect);
+
+  attributes.x = rect.x;
+  attributes.y = rect.y;
+  attributes.width = rect.width;
+  attributes.height = rect.height;
+  attributes.window_type = GDK_WINDOW_CHILD;
+  attributes.wclass = GDK_INPUT_OUTPUT;
+  attributes.event_mask = gtk_widget_get_events (widget) |
+                          GDK_EXPOSURE_MASK |
+                          GDK_BUTTON_PRESS_MASK;
+
+  attributes_mask = GDK_WA_X | GDK_WA_Y;
+
+  priv->grip_window = gdk_window_new (gtk_widget_get_window (widget),
+                                      &attributes,
+                                      attributes_mask);
+  gdk_window_set_background_rgba (priv->grip_window, &transparent);
+
+  gtk_widget_register_window (widget, priv->grip_window);
+
+  gdk_window_raise (priv->grip_window);
+
+  set_grip_shape (window);
+  update_grip_visibility (window);
+}
+
+static void
+resize_grip_destroy_window (GtkWindow *window)
+{
+  GtkWindowPrivate *priv = window->priv;
+
+  gtk_widget_unregister_window (GTK_WIDGET (window), priv->grip_window);
+  gdk_window_destroy (priv->grip_window);
+  priv->grip_window = NULL;
+  update_grip_visibility (window);
+}
+
+/**
+ * gtk_window_set_has_resize_grip:
+ * @window: a #GtkWindow
+ * @value: %TRUE to allow a resize grip
+ *
+ * Sets whether @window has a corner resize grip.
+ *
+ * Note that the resize grip is only shown if the window
+ * is actually resizable and not maximized. Use
+ * gtk_window_resize_grip_is_visible() to find out if the
+ * resize grip is currently shown.
+ *
+ * Since: 3.0
+ */
+void
+gtk_window_set_has_resize_grip (GtkWindow *window,
+                                gboolean   value)
+{
+  GtkWidget *widget = GTK_WIDGET (window);
+  GtkWindowPrivate *priv = window->priv;
+
+  value = value != FALSE;
+
+  if (value != priv->has_resize_grip)
+    {
+      priv->has_resize_grip = value;
+      gtk_widget_queue_draw (widget);
+
+      if (gtk_widget_get_realized (widget) && 
+         gtk_widget_is_toplevel (GTK_WIDGET (widget)))
+        {
+          if (priv->has_resize_grip && priv->grip_window == NULL)
+            resize_grip_create_window (window);
+          else if (!priv->has_resize_grip && priv->grip_window != NULL)
+            resize_grip_destroy_window (window);
+        }
+
+      g_object_notify (G_OBJECT (window), "has-resize-grip");
+    }
+}
+
+static void
+update_grip_visibility (GtkWindow *window)
+{
+  GtkWindowPrivate *priv = window->priv;
+  gboolean val;
+
+  val = gtk_window_resize_grip_is_visible (window);
+
+  if (priv->grip_window != NULL)
+    {
+      if (val)
+        {
+          gdk_window_show (priv->grip_window);
+          set_grip_cursor (window);
+        }
+      else
+        {
+          gdk_window_hide (priv->grip_window);
+        }
+    }
+
+  if (priv->resize_grip_visible != val)
+    {
+      priv->resize_grip_visible = val;
+
+      g_object_notify (G_OBJECT (window), "resize-grip-visible");
+    }
+}
+
+/**
+ * gtk_window_resize_grip_is_visible:
+ * @window: a #GtkWindow
+ *
+ * Determines whether a resize grip is visible for the specified window.
+ *
+ * Returns: %TRUE if a resize grip exists and is visible
+ *
+ * Since: 3.0
+ */
+gboolean
+gtk_window_resize_grip_is_visible (GtkWindow *window)
+{
+  GtkWidget *widget;
+  GtkWindowPrivate *priv;
+  GdkWindowEdge edge;
+
+  g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
+
+  priv = window->priv;
+  widget = GTK_WIDGET (window);
+
+  if (priv->type == GTK_WINDOW_POPUP)
+    return FALSE;
+
+  if (!priv->resizable)
+    return FALSE;
+
+  if (!gtk_widget_is_toplevel (GTK_WIDGET (widget)))
+    return FALSE;
+
+  if (gtk_widget_get_realized (widget))
+    {
+      GdkWindowState state;
+
+      state = gdk_window_get_state (gtk_widget_get_window (widget));
+
+      if (state & GDK_WINDOW_STATE_MAXIMIZED || state & GDK_WINDOW_STATE_FULLSCREEN)
+        return FALSE;
+    }
+
+  if (!get_drag_edge (widget, &edge))
+    return FALSE;
+
+  return window->priv->has_resize_grip;
+}
+
+/**
+ * gtk_window_get_has_resize_grip:
+ * @window: a #GtkWindow
+ *
+ * Determines whether the window may have a resize grip.
+ *
+ * Returns: %TRUE if the window has a resize grip
+ *
+ * Since: 3.0
+ */
+gboolean
+gtk_window_get_has_resize_grip (GtkWindow *window)
+{
+  g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
+
+  return window->priv->has_resize_grip;
+}
+
+/**
+ * gtk_window_get_resize_grip_area:
+ * @window: a #GtkWindow
+ * @rect: (out): a pointer to a #GdkRectangle which we should store
+ *     the resize grip area
+ *
+ * If a window has a resize grip, this will retrieve the grip
+ * position, width and height into the specified #GdkRectangle.
+ *
+ * Returns: %TRUE if the resize grip's area was retrieved
+ *
+ * Since: 3.0
+ */
+gboolean
+gtk_window_get_resize_grip_area (GtkWindow    *window,
+                                 GdkRectangle *rect)
+{
+  GtkWidget *widget = GTK_WIDGET (window);
+  GtkAllocation allocation;
+  gint grip_width;
+  gint grip_height;
+
+  g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
+
+  if (!window->priv->has_resize_grip)
+    return FALSE;
+
+  gtk_widget_get_allocation (widget, &allocation);
+
+  gtk_widget_style_get (widget,
+                        "resize-grip-width", &grip_width,
+                        "resize-grip-height", &grip_height,
+                        NULL);
+
+  if (grip_width > allocation.width)
+    grip_width = allocation.width;
+
+  if (grip_height > allocation.height)
+    grip_height = allocation.height;
+
+  rect->width = grip_width;
+  rect->height = grip_height;
+  rect->y = allocation.y + allocation.height - grip_height;
+
+  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
+    rect->x = allocation.x + allocation.width - grip_width;
+  else
+    rect->x = allocation.x;
+
+  return TRUE;
+}
+
 /* the accel_key and accel_mods fields of the key have to be setup
  * upon calling this function. it'll then return whether that key
  * is at all used as accelerator, and if so will OR in the
@@ -5089,14 +5935,18 @@ _gtk_window_query_nonaccels (GtkWindow      *window,
                             guint           accel_key,
                             GdkModifierType accel_mods)
 {
+  GtkWindowPrivate *priv;
+
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
 
+  priv = window->priv;
+
   /* movement keys are considered locked accels */
   if (!accel_mods)
     {
       static const guint bindings[] = {
-       GDK_space, GDK_KP_Space, GDK_Return, GDK_ISO_Enter, GDK_KP_Enter, GDK_Up, GDK_KP_Up, GDK_Down, GDK_KP_Down,
-       GDK_Left, GDK_KP_Left, GDK_Right, GDK_KP_Right, GDK_Tab, GDK_KP_Tab, GDK_ISO_Left_Tab,
+       GDK_KEY_space, GDK_KEY_KP_Space, GDK_KEY_Return, GDK_KEY_ISO_Enter, GDK_KEY_KP_Enter, GDK_KEY_Up, GDK_KEY_KP_Up, GDK_KEY_Down, GDK_KEY_KP_Down,
+       GDK_KEY_Left, GDK_KEY_KP_Left, GDK_KEY_Right, GDK_KEY_KP_Right, GDK_KEY_Tab, GDK_KEY_KP_Tab, GDK_KEY_ISO_Left_Tab,
       };
       guint i;
       
@@ -5106,7 +5956,7 @@ _gtk_window_query_nonaccels (GtkWindow      *window,
     }
 
   /* mnemonics are considered locked accels */
-  if (accel_mods == window->mnemonic_modifier)
+  if (accel_mods == priv->mnemonic_modifier)
     {
       GtkMnemonicHash *mnemonic_hash = gtk_window_get_mnemonic_hash (window, FALSE);
       if (mnemonic_hash && _gtk_mnemonic_hash_lookup (mnemonic_hash, accel_key))
@@ -5136,13 +5986,16 @@ gboolean
 gtk_window_propagate_key_event (GtkWindow        *window,
                                 GdkEventKey      *event)
 {
+  GtkWindowPrivate *priv;
   gboolean handled = FALSE;
   GtkWidget *widget, *focus;
 
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
 
+  priv = window->priv;
   widget = GTK_WIDGET (window);
-  focus = window->focus_widget;
+
+  focus = priv->focus_widget;
   if (focus)
     g_object_ref (focus);
   
@@ -5154,8 +6007,8 @@ gtk_window_propagate_key_event (GtkWindow        *window,
       
       if (gtk_widget_is_sensitive (focus))
         handled = gtk_widget_event (focus, (GdkEvent*) event);
-      
-      parent = focus->parent;
+
+      parent = gtk_widget_get_parent (focus);
       if (parent)
         g_object_ref (parent);
       
@@ -5210,6 +6063,30 @@ gtk_window_key_release_event (GtkWidget   *widget,
   return handled;
 }
 
+static gint
+gtk_window_button_press_event (GtkWidget *widget,
+                               GdkEventButton *event)
+{
+  GtkWindowPrivate *priv = GTK_WINDOW (widget)->priv;
+  GdkWindowEdge edge;
+
+  if (event->window == priv->grip_window)
+    {
+      if (get_drag_edge (widget, &edge))
+        gdk_window_begin_resize_drag_for_device (gtk_widget_get_window (widget),
+                                                 edge,
+                                                 gdk_event_get_device ((GdkEvent *) event),
+                                                 event->button,
+                                                 event->x_root,
+                                                 event->y_root,
+                                                 event->time);
+
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
 static void
 gtk_window_real_activate_default (GtkWindow *window)
 {
@@ -5222,16 +6099,6 @@ gtk_window_real_activate_focus (GtkWindow *window)
   gtk_window_activate_focus (window);
 }
 
-static void
-gtk_window_move_focus (GtkWindow       *window,
-                       GtkDirectionType dir)
-{
-  gtk_widget_child_focus (GTK_WIDGET (window), dir);
-  
-  if (!gtk_container_get_focus_child (GTK_CONTAINER (window)))
-    gtk_window_set_focus (window, NULL);
-}
-
 static gint
 gtk_window_enter_notify_event (GtkWidget        *widget,
                               GdkEventCrossing *event)
@@ -5250,6 +6117,7 @@ static void
 do_focus_change (GtkWidget *widget,
                 gboolean   in)
 {
+  GdkWindow *window;
   GdkDeviceManager *device_manager;
   GList *devices, *d;
 
@@ -5265,23 +6133,23 @@ do_focus_change (GtkWidget *widget,
       GdkDevice *dev = d->data;
       GdkEvent *fevent;
 
-      if (dev->source != GDK_SOURCE_KEYBOARD)
+      if (gdk_device_get_source (dev) != GDK_SOURCE_KEYBOARD)
         continue;
 
       /* Skip non-master keyboards that haven't
        * selected for events from this window
        */
+      window = gtk_widget_get_window (widget);
       if (gdk_device_get_device_type (dev) != GDK_DEVICE_TYPE_MASTER &&
-          widget->window &&
-          !gdk_window_get_device_events (widget->window, dev))
+          window && !gdk_window_get_device_events (window, dev))
         continue;
 
       fevent = gdk_event_new (GDK_FOCUS_CHANGE);
 
       fevent->focus_change.type = GDK_FOCUS_CHANGE;
-      fevent->focus_change.window = widget->window;
-      if (widget->window)
-        g_object_ref (widget->window);
+      fevent->focus_change.window = window;
+      if (window)
+        g_object_ref (window);
       fevent->focus_change.in = in;
       gdk_event_set_device (fevent, dev);
 
@@ -5291,7 +6159,37 @@ do_focus_change (GtkWidget *widget,
     }
 
   g_list_free (devices);
-  g_object_unref (widget);
+  g_object_unref (widget);
+}
+
+static void
+maybe_set_mnemonics_visible (GtkWindow *window)
+{
+  GList *devices, *d;
+  GdkDeviceManager *device_manager;
+
+  device_manager = gdk_display_get_device_manager (gtk_widget_get_display (GTK_WIDGET (window)));
+  devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
+
+  for (d = devices; d; d = d->next)
+    {
+      GdkDevice *dev = d->data;
+
+      if (gdk_device_get_source (dev) == GDK_SOURCE_MOUSE)
+        {
+          GdkModifierType mask;
+
+          gdk_device_get_state (dev, gtk_widget_get_window (GTK_WIDGET (window)),
+                                NULL, &mask);
+          if (window->priv->mnemonic_modifier == (mask & gtk_accelerator_get_default_mod_mask ()))
+            {
+              _gtk_window_set_auto_mnemonics_visible (window);
+              break;
+            }
+        }
+    }
+
+  g_list_free (devices);
 }
 
 static gint
@@ -5299,6 +6197,7 @@ gtk_window_focus_in_event (GtkWidget     *widget,
                           GdkEventFocus *event)
 {
   GtkWindow *window = GTK_WINDOW (widget);
+  gboolean auto_mnemonics;
 
   /* It appears spurious focus in events can occur when
    *  the window is hidden. So we'll just check to see if
@@ -5309,8 +6208,13 @@ gtk_window_focus_in_event (GtkWidget     *widget,
     {
       _gtk_window_set_has_toplevel_focus (window, TRUE);
       _gtk_window_set_is_active (window, TRUE);
+
+      g_object_get (gtk_widget_get_settings (widget),
+                    "gtk-auto-mnemonics", &auto_mnemonics, NULL);
+      if (auto_mnemonics)
+        maybe_set_mnemonics_visible (window);
     }
-      
+
   return FALSE;
 }
 
@@ -5333,66 +6237,14 @@ gtk_window_focus_out_event (GtkWidget     *widget,
   return FALSE;
 }
 
-static GdkAtom atom_rcfiles = GDK_NONE;
-static GdkAtom atom_iconthemes = GDK_NONE;
-
-static void
-send_client_message_to_embedded_windows (GtkWidget *widget,
-                                        GdkAtom    message_type)
-{
-  GList *embedded_windows;
-
-  embedded_windows = g_object_get_qdata (G_OBJECT (widget), quark_gtk_embedded);
-  if (embedded_windows)
-    {
-      GdkEvent *send_event = gdk_event_new (GDK_CLIENT_EVENT);
-      int i;
-      
-      for (i = 0; i < 5; i++)
-       send_event->client.data.l[i] = 0;
-      send_event->client.data_format = 32;
-      send_event->client.message_type = message_type;
-      
-      while (embedded_windows)
-       {
-         GdkNativeWindow xid = GDK_GPOINTER_TO_NATIVE_WINDOW(embedded_windows->data);
-         gdk_event_send_client_message_for_display (gtk_widget_get_display (widget), send_event, xid);
-         embedded_windows = embedded_windows->next;
-       }
-
-      gdk_event_free (send_event);
-    }
-}
-
-static gint
-gtk_window_client_event (GtkWidget     *widget,
-                        GdkEventClient *event)
-{
-  if (!atom_rcfiles)
-    {
-      atom_rcfiles = gdk_atom_intern_static_string ("_GTK_READ_RCFILES");
-      atom_iconthemes = gdk_atom_intern_static_string ("_GTK_LOAD_ICONTHEMES");
-    }
-
-  if (event->message_type == atom_rcfiles) 
-    {
-      send_client_message_to_embedded_windows (widget, atom_rcfiles);
-      gtk_rc_reparse_all_for_settings (gtk_widget_get_settings (widget), FALSE);
-    }
-
-  if (event->message_type == atom_iconthemes) 
-    {
-      send_client_message_to_embedded_windows (widget, atom_iconthemes);
-      _gtk_icon_theme_check_reload (gtk_widget_get_display (widget));    
-    }
-
-  return FALSE;
-}
-
 static void
 gtk_window_check_resize (GtkContainer *container)
 {
-  if (gtk_widget_get_visible (GTK_WIDGET (container)))
+  /* If the window is not toplevel anymore than it's embedded somewhere,
+   * so handle it like a normal window */
+  if (!gtk_widget_is_toplevel (GTK_WIDGET (container)))
+    GTK_CONTAINER_CLASS (gtk_window_parent_class)->check_resize (container);
+  else if (gtk_widget_get_visible (GTK_WIDGET (container)))
     gtk_window_move_resize (GTK_WINDOW (container));
 }
 
@@ -5400,6 +6252,7 @@ static gboolean
 gtk_window_focus (GtkWidget        *widget,
                  GtkDirectionType  direction)
 {
+  GtkWindowPrivate *priv;
   GtkBin *bin;
   GtkWindow *window;
   GtkContainer *container;
@@ -5407,8 +6260,12 @@ gtk_window_focus (GtkWidget        *widget,
   GtkWidget *old_focus_child;
   GtkWidget *parent;
 
+  if (!gtk_widget_is_toplevel (GTK_WIDGET (widget)))
+    return GTK_WIDGET_CLASS (gtk_window_parent_class)->focus (widget, direction);
+
   container = GTK_CONTAINER (widget);
   window = GTK_WINDOW (widget);
+  priv = window->priv;
   bin = GTK_BIN (widget);
 
   old_focus_child = gtk_container_get_focus_child (container);
@@ -5423,7 +6280,7 @@ gtk_window_focus (GtkWidget        *widget,
        return TRUE;
     }
 
-  if (window->focus_widget)
+  if (priv->focus_widget)
     {
       if (direction == GTK_DIR_LEFT ||
          direction == GTK_DIR_RIGHT ||
@@ -5434,11 +6291,11 @@ gtk_window_focus (GtkWidget        *widget,
        }
       
       /* Wrapped off the end, clear the focus setting for the toplpevel */
-      parent = window->focus_widget->parent;
+      parent = gtk_widget_get_parent (priv->focus_widget);
       while (parent)
        {
          gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
-         parent = GTK_WIDGET (parent)->parent;
+         parent = gtk_widget_get_parent (parent);
        }
       
       gtk_window_set_focus (GTK_WINDOW (container), NULL);
@@ -5455,11 +6312,28 @@ gtk_window_focus (GtkWidget        *widget,
   return FALSE;
 }
 
+static void
+gtk_window_move_focus (GtkWidget       *widget,
+                       GtkDirectionType dir)
+{
+  if (!gtk_widget_is_toplevel (GTK_WIDGET (widget)))
+    {
+      GTK_WIDGET_CLASS (gtk_window_parent_class)->move_focus (widget, dir);
+      return;
+    }
+
+  gtk_widget_child_focus (widget, dir);
+
+  if (! gtk_container_get_focus_child (GTK_CONTAINER (widget)))
+    gtk_window_set_focus (GTK_WINDOW (widget), NULL);
+}
+
 static void
 gtk_window_real_set_focus (GtkWindow *window,
                           GtkWidget *focus)
 {
-  GtkWidget *old_focus = window->focus_widget;
+  GtkWindowPrivate *priv = window->priv;
+  GtkWidget *old_focus = priv->focus_widget;
   gboolean had_default = FALSE;
   gboolean focus_had_default = FALSE;
   gboolean old_focus_had_default = FALSE;
@@ -5476,25 +6350,25 @@ gtk_window_real_set_focus (GtkWindow *window,
       g_object_freeze_notify (G_OBJECT (focus));
       focus_had_default = gtk_widget_has_default (focus);
     }
-  
-  if (window->default_widget)
-    had_default = gtk_widget_has_default (window->default_widget);
-  
-  if (window->focus_widget)
+
+  if (priv->default_widget)
+    had_default = gtk_widget_has_default (priv->default_widget);
+
+  if (priv->focus_widget)
     {
-      if (gtk_widget_get_receives_default (window->focus_widget) &&
-         (window->focus_widget != window->default_widget))
+      if (gtk_widget_get_receives_default (priv->focus_widget) &&
+         (priv->focus_widget != priv->default_widget))
         {
-          _gtk_widget_set_has_default (window->focus_widget, FALSE);
-         gtk_widget_queue_draw (window->focus_widget);
-         
-         if (window->default_widget)
-            _gtk_widget_set_has_default (window->default_widget, TRUE);
+          _gtk_widget_set_has_default (priv->focus_widget, FALSE);
+         gtk_widget_queue_draw (priv->focus_widget);
+
+         if (priv->default_widget)
+            _gtk_widget_set_has_default (priv->default_widget, TRUE);
        }
 
-      window->focus_widget = NULL;
+      priv->focus_widget = NULL;
 
-      if (window->has_focus)
+      if (priv->has_focus)
        do_focus_change (old_focus, FALSE);
 
       g_object_notify (G_OBJECT (old_focus), "is-focus");
@@ -5503,24 +6377,24 @@ gtk_window_real_set_focus (GtkWindow *window,
   /* The above notifications may have set a new focus widget,
    * if so, we don't want to override it.
    */
-  if (focus && !window->focus_widget)
+  if (focus && !priv->focus_widget)
     {
-      window->focus_widget = focus;
-  
-      if (gtk_widget_get_receives_default (window->focus_widget) &&
-         (window->focus_widget != window->default_widget))
+      priv->focus_widget = focus;
+
+      if (gtk_widget_get_receives_default (priv->focus_widget) &&
+         (priv->focus_widget != priv->default_widget))
        {
-         if (gtk_widget_get_can_default (window->focus_widget))
-            _gtk_widget_set_has_default (window->focus_widget, TRUE);
+         if (gtk_widget_get_can_default (priv->focus_widget))
+            _gtk_widget_set_has_default (priv->focus_widget, TRUE);
 
-         if (window->default_widget)
-            _gtk_widget_set_has_default (window->default_widget, FALSE);
+         if (priv->default_widget)
+            _gtk_widget_set_has_default (priv->default_widget, FALSE);
        }
 
-      if (window->has_focus)
-       do_focus_change (window->focus_widget, TRUE);
+      if (priv->has_focus)
+       do_focus_change (priv->focus_widget, TRUE);
 
-      g_object_notify (G_OBJECT (window->focus_widget), "is-focus");
+      g_object_notify (G_OBJECT (priv->focus_widget), "is-focus");
     }
 
   /* If the default widget changed, a redraw will have been queued
@@ -5529,9 +6403,9 @@ gtk_window_real_set_focus (GtkWindow *window,
    * We'll sometimes queue a draw twice on the new widget but that
    * is harmless.
    */
-  if (window->default_widget &&
-      (had_default != gtk_widget_has_default (window->default_widget)))
-    gtk_widget_queue_draw (window->default_widget);
+  if (priv->default_widget &&
+      (had_default != gtk_widget_has_default (priv->default_widget)))
+    gtk_widget_queue_draw (priv->default_widget);
   
   if (old_focus)
     {
@@ -5551,68 +6425,6 @@ gtk_window_real_set_focus (GtkWindow *window,
     }
 }
 
-
-static void
-gtk_window_size_request_init (GtkSizeRequestIface *iface)
-{
-  iface->get_width  = gtk_window_get_width;
-  iface->get_height = gtk_window_get_height;
-}
-
-
-static void 
-gtk_window_get_width (GtkSizeRequest      *widget,
-                     gint                *minimum_size,
-                     gint                *natural_size)
-{
-  GtkWindow *window;
-  GtkWidget *child;
-  guint border_width;
-
-  window = GTK_WINDOW (widget);
-  child  = gtk_bin_get_child (GTK_BIN (window));
-
-  border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
-  *minimum_size = border_width * 2;
-  *natural_size = border_width * 2;
-
-  if (child && gtk_widget_get_visible (child))
-    {
-      gint child_min, child_nat;
-      gtk_size_request_get_width (GTK_SIZE_REQUEST (child), &child_min, &child_nat);
-
-      *minimum_size += child_min;
-      *natural_size += child_nat;
-    }
-}
-
-static void 
-gtk_window_get_height (GtkSizeRequest      *widget,
-                      gint                *minimum_size,
-                      gint                *natural_size)
-{
-  GtkWindow *window;
-  GtkWidget *child;
-  guint border_width;
-
-  window = GTK_WINDOW (widget);
-  child  = gtk_bin_get_child (GTK_BIN (window));
-
-  border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
-  *minimum_size = border_width * 2;
-  *natural_size = border_width * 2;
-
-  if (child && gtk_widget_get_visible (child))
-    {
-      gint child_min, child_nat;
-      gtk_size_request_get_height (GTK_SIZE_REQUEST (child), &child_min, &child_nat);
-
-      *minimum_size += child_min;
-      *natural_size += child_nat;
-    }
-}
-
-
 /**
  * _gtk_window_unset_focus_and_default:
  * @window: a #GtkWindow
@@ -5626,27 +6438,30 @@ _gtk_window_unset_focus_and_default (GtkWindow *window,
                                     GtkWidget *widget)
 
 {
+  GtkWindowPrivate *priv = window->priv;
   GtkWidget *child;
+  GtkWidget *parent;
 
   g_object_ref (window);
   g_object_ref (widget);
-      
-  if (gtk_container_get_focus_child (GTK_CONTAINER (widget->parent)) == widget)
+
+  parent = gtk_widget_get_parent (widget);
+  if (gtk_container_get_focus_child (GTK_CONTAINER (parent)) == widget)
     {
-      child = window->focus_widget;
+      child = priv->focus_widget;
       
       while (child && child != widget)
-       child = child->parent;
-  
+        child = gtk_widget_get_parent (child);
+
       if (child == widget)
        gtk_window_set_focus (GTK_WINDOW (window), NULL);
     }
       
-  child = window->default_widget;
+  child = priv->default_widget;
       
   while (child && child != widget)
-    child = child->parent;
-      
+    child = gtk_widget_get_parent (child);
+
   if (child == widget)
     gtk_window_set_default (window, NULL);
   
@@ -5658,31 +6473,61 @@ _gtk_window_unset_focus_and_default (GtkWindow *window,
  * Functions related to resizing *
  *********************************/
 
+static void
+geometry_size_to_pixels (GdkGeometry *geometry,
+                        guint        flags,
+                        gint        *width,
+                        gint        *height)
+{
+  gint base_width = 0;
+  gint base_height = 0;
+  gint min_width = 0;
+  gint min_height = 0;
+  gint width_inc = 1;
+  gint height_inc = 1;
+
+  if (flags & GDK_HINT_BASE_SIZE)
+    {
+      base_width = geometry->base_width;
+      base_height = geometry->base_height;
+    }
+  if (flags & GDK_HINT_MIN_SIZE)
+    {
+      min_width = geometry->min_width;
+      min_height = geometry->min_height;
+    }
+  if (flags & GDK_HINT_RESIZE_INC)
+    {
+      width_inc = geometry->width_inc;
+      height_inc = geometry->height_inc;
+    }
+
+  if (width)
+    *width = MAX (*width * width_inc + base_width, min_width);
+  if (height)
+    *height = MAX (*height * height_inc + base_height, min_height);
+}
+
 /* This function doesn't constrain to geometry hints */
 static void 
-gtk_window_compute_configure_request_size (GtkWindow *window,
-                                           guint     *width,
-                                           guint     *height)
+gtk_window_compute_configure_request_size (GtkWindow   *window,
+                                           GdkGeometry *geometry,
+                                           guint        flags,
+                                           gint        *width,
+                                           gint        *height)
 {
-  GtkRequisition requisition;
+  GtkWindowPrivate *priv = window->priv;
   GtkWindowGeometryInfo *info;
-  GtkWidget *widget;
 
   /* Preconditions:
    *  - we've done a size request
    */
   
-  widget = GTK_WIDGET (window);
-
   info = gtk_window_get_geometry_info (window, FALSE);
-  
-  if (window->need_default_size)
-    {
-      gtk_widget_get_child_requisition (widget, &requisition);
 
-      /* Default to requisition */
-      *width = requisition.width;
-      *height = requisition.height;
+  if (priv->need_default_size)
+    {
+      gtk_window_guess_default_size (window, width, height);
 
       /* If window is empty so requests 0, default to random nonzero size */
        if (*width == 0 && *height == 0)
@@ -5691,67 +6536,47 @@ gtk_window_compute_configure_request_size (GtkWindow *window,
            *height = 200;
          }
 
-       /* Override requisition with default size */
+       /* Override with default size */
 
        if (info)
-         {
-          gint base_width = 0;
-          gint base_height = 0;
-          gint min_width = 0;
-          gint min_height = 0;
-          gint width_inc = 1;
-          gint height_inc = 1;
-          
-          if (info->default_is_geometry &&
-              (info->default_width > 0 || info->default_height > 0))
-            {
-              GdkGeometry geometry;
-              guint flags;
-              
-              gtk_window_compute_hints (window, &geometry, &flags);
-
-              if (flags & GDK_HINT_BASE_SIZE)
-                {
-                  base_width = geometry.base_width;
-                  base_height = geometry.base_height;
-                }
-              if (flags & GDK_HINT_MIN_SIZE)
-                {
-                  min_width = geometry.min_width;
-                  min_height = geometry.min_height;
-                }
-              if (flags & GDK_HINT_RESIZE_INC)
-                {
-                  width_inc = geometry.width_inc;
-                  height_inc = geometry.height_inc;
-                }
-            }
-            
+        {
           if (info->default_width > 0)
-            *width = MAX (info->default_width * width_inc + base_width, min_width);
-          
+            *width = info->default_width;
           if (info->default_height > 0)
-            *height = MAX (info->default_height * height_inc + base_height, min_height);
+            *height = info->default_height;
+
+          if (info->default_is_geometry)
+            geometry_size_to_pixels (geometry, flags,
+                                     info->default_width > 0 ? width : NULL,
+                                     info->default_height > 0 ? height : NULL);
          }
     }
   else
     {
+      GtkAllocation allocation;
+
+      gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
+
       /* Default to keeping current size */
-      *width = widget->allocation.width;
-      *height = widget->allocation.height;
+      *width = allocation.width;
+      *height = allocation.height;
     }
 
   /* Override any size with gtk_window_resize() values */
   if (info)
     {
       if (info->resize_width > 0)
-        *width = info->resize_width;
-
+       *width = info->resize_width;
       if (info->resize_height > 0)
-        *height = info->resize_height;
+       *height = info->resize_height;
+
+      if (info->resize_is_geometry)
+       geometry_size_to_pixels (geometry, flags,
+                                info->resize_width > 0 ? width : NULL,
+                                info->resize_height > 0 ? height : NULL);
     }
 
-  /* Don't ever request zero width or height, its not supported by
+  /* Don't ever request zero width or height, it's not supported by
      gdk. The size allocation code will round it to 1 anyway but if
      we do it then the value returned from this function will is
      not comparable to the size allocation read from the GtkWindow. */
@@ -5762,11 +6587,12 @@ gtk_window_compute_configure_request_size (GtkWindow *window,
 static GtkWindowPosition
 get_effective_position (GtkWindow *window)
 {
-  GtkWindowPosition pos = window->position;
+  GtkWindowPrivate *priv = window->priv;
+  GtkWindowPosition pos = priv->position;
 
   if (pos == GTK_WIN_POS_CENTER_ON_PARENT &&
-      (window->transient_parent == NULL ||
-       !gtk_widget_get_mapped (GTK_WIDGET (window->transient_parent))))
+      (priv->transient_parent == NULL ||
+       !gtk_widget_get_mapped (GTK_WIDGET (priv->transient_parent))))
     pos = GTK_WIN_POS_NONE;
 
   return pos;
@@ -5798,9 +6624,9 @@ get_monitor_containing_pointer (GtkWindow *window)
   device_manager = gdk_display_get_device_manager (display);
   pointer = gdk_device_manager_get_client_pointer (device_manager);
 
-  gdk_display_get_device_state (display, pointer,
-                                &pointer_screen,
-                                &px, &py, NULL);
+  gdk_device_get_position (pointer,
+                           &pointer_screen,
+                           &px, &py);
 
   if (pointer_screen == window_screen)
     monitor_num = gdk_screen_get_monitor_at_point (pointer_screen, px, py);
@@ -5821,13 +6647,13 @@ center_window_on_monitor (GtkWindow *window,
   int monitor_num;
 
   monitor_num = get_monitor_containing_pointer (window);
-  
+
   if (monitor_num == -1)
     monitor_num = get_center_monitor_of_window (window);
 
-  gdk_screen_get_monitor_geometry (gtk_window_check_screen (window),
-                                  monitor_num, &monitor);
-  
+  gdk_screen_get_monitor_workarea (gtk_window_check_screen (window),
+                                    monitor_num, &monitor);
+
   *x = (monitor.width - w) / 2 + monitor.x;
   *y = (monitor.height - h) / 2 + monitor.y;
 
@@ -5884,34 +6710,33 @@ gtk_window_compute_configure_request (GtkWindow    *window,
                                       GdkGeometry  *geometry,
                                       guint        *flags)
 {
+  GtkWindowPrivate *priv = window->priv;
   GdkGeometry new_geometry;
   guint new_flags;
   int w, h;
-  GtkWidget *widget;
   GtkWindowPosition pos;
   GtkWidget *parent_widget;
   GtkWindowGeometryInfo *info;
   GdkScreen *screen;
   int x, y;
-  
-  widget = GTK_WIDGET (window);
 
   screen = gtk_window_check_screen (window);
-  
-  gtk_widget_size_request (widget, NULL);
-  gtk_window_compute_configure_request_size (window, (guint *)&w, (guint *)&h);
-  
+
   gtk_window_compute_hints (window, &new_geometry, &new_flags);
+  gtk_window_compute_configure_request_size (window,
+                                             &new_geometry, new_flags,
+                                             &w, &h);
+
   gtk_window_constrain_size (window,
                              &new_geometry, new_flags,
                              w, h,
                              &w, &h);
 
-  parent_widget = (GtkWidget*) window->transient_parent;
-  
+  parent_widget = (GtkWidget*) priv->transient_parent;
+
   pos = get_effective_position (window);
   info = gtk_window_get_geometry_info (window, FALSE);
-  
+
   /* by default, don't change position requested */
   if (info)
     {
@@ -5925,7 +6750,7 @@ gtk_window_compute_configure_request (GtkWindow    *window,
     }
 
 
-  if (window->need_default_position)
+  if (priv->need_default_position)
     {
 
       /* FIXME this all interrelates with window gravity.
@@ -5933,7 +6758,6 @@ gtk_window_compute_configure_request (GtkWindow    *window,
        *
        * Not sure how to go about that.
        */
-      
       switch (pos)
         {
           /* here we are only handling CENTER_ALWAYS
@@ -5944,27 +6768,32 @@ gtk_window_compute_configure_request (GtkWindow    *window,
         case GTK_WIN_POS_CENTER:
           center_window_on_monitor (window, w, h, &x, &y);
           break;
-      
+
         case GTK_WIN_POS_CENTER_ON_PARENT:
           {
+            GtkAllocation allocation;
+            GdkWindow *gdk_window;
             gint monitor_num;
             GdkRectangle monitor;
             gint ox, oy;
-            
+
             g_assert (gtk_widget_get_mapped (parent_widget)); /* established earlier */
 
-            if (parent_widget->window != NULL)
+            gdk_window = gtk_widget_get_window (parent_widget);
+
+            if (gdk_window != NULL)
               monitor_num = gdk_screen_get_monitor_at_window (screen,
-                                                              parent_widget->window);
+                                                              gdk_window);
             else
               monitor_num = -1;
-            
-            gdk_window_get_origin (parent_widget->window,
+
+            gdk_window_get_origin (gdk_window,
                                    &ox, &oy);
-            
-            x = ox + (parent_widget->allocation.width - w) / 2;
-            y = oy + (parent_widget->allocation.height - h) / 2;
-            
+
+            gtk_widget_get_allocation (parent_widget, &allocation);
+            x = ox + (allocation.width - w) / 2;
+            y = oy + (allocation.height - h) / 2;
+
             /* Clamp onto current monitor, ignoring _NET_WM_STRUT and
              * WM decorations. If parent wasn't on a monitor, just
              * give up.
@@ -5981,8 +6810,8 @@ gtk_window_compute_configure_request (GtkWindow    *window,
           {
             gint screen_width = gdk_screen_get_width (screen);
             gint screen_height = gdk_screen_get_height (screen);
-           gint monitor_num;
-           GdkRectangle monitor;
+            gint monitor_num;
+            GdkRectangle monitor;
             GdkDisplay *display;
             GdkDeviceManager *device_manager;
             GdkDevice *pointer;
@@ -5993,15 +6822,15 @@ gtk_window_compute_configure_request (GtkWindow    *window,
             device_manager = gdk_display_get_device_manager (display);
             pointer = gdk_device_manager_get_client_pointer (device_manager);
 
-            gdk_display_get_device_state (display, pointer,
-                                          &pointer_screen,
-                                          &px, &py, NULL);
+            gdk_device_get_position (pointer,
+                                     &pointer_screen,
+                                     &px, &py);
 
             if (pointer_screen == screen)
               monitor_num = gdk_screen_get_monitor_at_point (screen, px, py);
             else
               monitor_num = -1;
-            
+
             x = px - w / 2;
             y = py - h / 2;
             x = CLAMP (x, 0, screen_width - w);
@@ -6022,16 +6851,16 @@ gtk_window_compute_configure_request (GtkWindow    *window,
         default:
           break;
         }
-    } /* if (window->need_default_position) */
+    } /* if (priv->need_default_position) */
 
-  if (window->need_default_position && info &&
+  if (priv->need_default_position && info &&
       info->initial_pos_set)
     {
       x = info->initial_x;
       y = info->initial_y;
       gtk_window_constrain_position (window, w, h, &x, &y);
     }
-  
+
   request->x = x;
   request->y = y;
   request->width = w;
@@ -6050,10 +6879,12 @@ gtk_window_constrain_position (GtkWindow    *window,
                                gint         *x,
                                gint         *y)
 {
+  GtkWindowPrivate *priv = window->priv;
+
   /* See long comments in gtk_window_move_resize()
    * on when it's safe to call this function.
    */
-  if (window->position == GTK_WIN_POS_CENTER_ALWAYS)
+  if (priv->position == GTK_WIN_POS_CENTER_ALWAYS)
     {
       gint center_x, center_y;
 
@@ -6099,10 +6930,13 @@ gtk_window_move_resize (GtkWindow *window)
    *   If GTK_WIN_POS_CENTER_ALWAYS is active, we constrain
    *   the position request to be centered.
    */
+  GtkWindowPrivate *priv = window->priv;
+  GtkAllocation allocation;
   GtkWidget *widget;
   GtkContainer *container;
   GtkWindowGeometryInfo *info;
   GdkGeometry new_geometry;
+  GdkWindow *gdk_window;
   guint new_flags;
   GdkRectangle new_request;
   gboolean configure_request_size_changed;
@@ -6111,6 +6945,8 @@ gtk_window_move_resize (GtkWindow *window)
   GtkWindowLastGeometryInfo saved_last_info;
   
   widget = GTK_WIDGET (window);
+
+  gdk_window = gtk_widget_get_window (widget);
   container = GTK_CONTAINER (widget);
   info = gtk_window_get_geometry_info (window, TRUE);
   
@@ -6207,7 +7043,7 @@ gtk_window_move_resize (GtkWindow *window)
     }
 
 #if 0
-  if (window->type == GTK_WINDOW_TOPLEVEL)
+  if (priv->type == GTK_WINDOW_TOPLEVEL)
     {
       int notify_x, notify_y;
 
@@ -6224,7 +7060,7 @@ gtk_window_move_resize (GtkWindow *window)
                 "configure_notify_received: %d\n"
                 "configure_request_count: %d\n"
                 "position_constraints_changed: %d\n",
-                window->title ? window->title : "(no title)",
+                priv->title ? priv->title : "(no title)",
                 info->last.configure_request.x,
                 info->last.configure_request.y,
                 info->last.configure_request.width,
@@ -6243,8 +7079,8 @@ gtk_window_move_resize (GtkWindow *window)
                 configure_request_pos_changed,
                 configure_request_size_changed,
                 hints_changed,
-                window->configure_notify_received,
-                window->configure_request_count,
+                priv->configure_notify_received,
+                priv->configure_request_count,
                 info->position_constraints_changed);
     }
 #endif
@@ -6271,7 +7107,7 @@ gtk_window_move_resize (GtkWindow *window)
   
   if ((configure_request_pos_changed ||
        info->initial_pos_set ||
-       (window->need_default_position &&
+       (priv->need_default_position &&
         get_effective_position (window) != GTK_WIN_POS_NONE)) &&
       (new_flags & GDK_HINT_POS) == 0)
     {
@@ -6282,16 +7118,19 @@ gtk_window_move_resize (GtkWindow *window)
   /* Set hints if necessary
    */
   if (hints_changed)
-    gdk_window_set_geometry_hints (widget->window,
+    gdk_window_set_geometry_hints (gdk_window,
                                   &new_geometry,
                                   new_flags);
-  
+
+  allocation.x = 0;
+  allocation.y = 0;
+  allocation.width = gdk_window_get_width (gdk_window);
+  allocation.height = gdk_window_get_height (gdk_window);
+
   /* handle resizing/moving and widget tree allocation
    */
-  if (window->configure_notify_received)
+  if (priv->configure_notify_received)
     { 
-      GtkAllocation allocation;
-
       /* If we have received a configure event since
        * the last time in this function, we need to
        * accept our new size and size_allocate child widgets.
@@ -6303,15 +7142,13 @@ gtk_window_move_resize (GtkWindow *window)
        * (one per configure request), as an optimization.
        *
        */
-      window->configure_notify_received = FALSE;
+      priv->configure_notify_received = FALSE;
 
       /* gtk_window_configure_event() filled in widget->allocation */
-      allocation = widget->allocation;
       gtk_widget_size_allocate (widget, &allocation);
 
-      gdk_window_process_updates (widget->window, TRUE);
-      
-      gdk_window_configure_finished (widget->window);
+      set_grip_position (window);
+      update_grip_visibility (window);
 
       /* If the configure request changed, it means that
        * we either:
@@ -6355,8 +7192,7 @@ gtk_window_move_resize (GtkWindow *window)
       return;                  /* Bail out, we didn't really process the move/resize */
     }
   else if ((configure_request_size_changed || hints_changed) &&
-          (widget->allocation.width != new_request.width ||
-           widget->allocation.height != new_request.height))
+           (allocation.width != new_request.width || allocation.height != new_request.height))
 
     {
       /* We are in one of the following situations:
@@ -6376,33 +7212,18 @@ gtk_window_move_resize (GtkWindow *window)
 
       /* Now send the configure request */
       if (configure_request_pos_changed)
-       {
-         if (window->frame)
-           {
-             gdk_window_move_resize (window->frame,
-                                     new_request.x - window->frame_left,
-                                      new_request.y - window->frame_top,
-                                     new_request.width + window->frame_left + window->frame_right,
-                                     new_request.height + window->frame_top + window->frame_bottom);
-             gdk_window_resize (widget->window,
-                                 new_request.width, new_request.height);
-           }
-         else
-           gdk_window_move_resize (widget->window,
-                                   new_request.x, new_request.y,
-                                   new_request.width, new_request.height);
-       }
+        {
+          gdk_window_move_resize (gdk_window,
+                                  new_request.x, new_request.y,
+                                  new_request.width, new_request.height);
+        }
       else  /* only size changed */
-       {
-         if (window->frame)
-           gdk_window_resize (window->frame,
-                              new_request.width + window->frame_left + window->frame_right,
-                              new_request.height + window->frame_top + window->frame_bottom);
-         gdk_window_resize (widget->window,
-                            new_request.width, new_request.height);
-       }
-      
-      if (window->type == GTK_WINDOW_POPUP)
+        {
+          gdk_window_resize (gdk_window,
+                             new_request.width, new_request.height);
+        }
+
+      if (priv->type == GTK_WINDOW_POPUP)
         {
          GtkAllocation allocation;
 
@@ -6414,7 +7235,7 @@ gtk_window_move_resize (GtkWindow *window)
 
          gtk_widget_size_allocate (widget, &allocation);
 
-         gdk_window_process_updates (widget->window, TRUE);
+         gdk_window_process_updates (gdk_window, TRUE);
 
          if (gtk_container_get_resize_mode (container) == GTK_RESIZE_QUEUE)
            gtk_widget_queue_draw (widget);
@@ -6422,8 +7243,8 @@ gtk_window_move_resize (GtkWindow *window)
       else
         {
          /* Increment the number of have-not-yet-received-notify requests */
-         window->configure_request_count += 1;
-         gdk_window_freeze_toplevel_updates_libgtk_only (widget->window);
+         priv->configure_request_count += 1;
+         gdk_window_freeze_toplevel_updates_libgtk_only (gdk_window);
 
          /* for GTK_RESIZE_QUEUE toplevels, we are now awaiting a new
           * configure event in response to our resizing request.
@@ -6452,17 +7273,10 @@ gtk_window_move_resize (GtkWindow *window)
       /* Handle any position changes.
        */
       if (configure_request_pos_changed)
-       {
-         if (window->frame)
-           {
-             gdk_window_move (window->frame,
-                              new_request.x - window->frame_left,
-                              new_request.y - window->frame_top);
-           }
-         else
-           gdk_window_move (widget->window,
-                            new_request.x, new_request.y);
-       }
+        {
+          gdk_window_move (gdk_window,
+                           new_request.x, new_request.y);
+        }
 
       /* And run the resize queue.
        */
@@ -6530,11 +7344,14 @@ _gtk_window_constrain_size (GtkWindow   *window,
                            gint        *new_width,
                            gint        *new_height)
 {
+  GtkWindowPrivate *priv;
   GtkWindowGeometryInfo *info;
 
   g_return_if_fail (GTK_IS_WINDOW (window));
 
-  info = window->geometry_info;
+  priv = window->priv;
+
+  info = priv->geometry_info;
   if (info)
     {
       GdkWindowHints flags = info->last.flags;
@@ -6564,8 +7381,8 @@ gtk_window_constrain_size (GtkWindow   *window,
 }
 
 /* Compute the set of geometry hints and flags for a window
- * based on the application set geometry, and requisiition
- * of the window. gtk_widget_size_request() must have been
+ * based on the application set geometry, and requisition
+ * of the window. gtk_widget_get_preferred_size() must have been
  * called first.
  */
 static void
@@ -6573,6 +7390,7 @@ gtk_window_compute_hints (GtkWindow   *window,
                          GdkGeometry *new_geometry,
                          guint       *new_flags)
 {
+  GtkWindowPrivate *priv = window->priv;
   GtkWidget *widget;
   gint extra_width = 0;
   gint extra_height = 0;
@@ -6580,8 +7398,8 @@ gtk_window_compute_hints (GtkWindow   *window,
   GtkRequisition requisition;
 
   widget = GTK_WIDGET (window);
-  
-  gtk_widget_get_child_requisition (widget, &requisition);
+
+  gtk_widget_get_preferred_size (widget, &requisition, NULL);
   geometry_info = gtk_window_get_geometry_info (GTK_WINDOW (widget), FALSE);
 
   if (geometry_info)
@@ -6596,24 +7414,52 @@ gtk_window_compute_hints (GtkWindow   *window,
   
   if (geometry_info && geometry_info->widget)
     {
-      GtkRequisition child_requisition;
-
-      /* FIXME: This really isn't right. It gets the min size wrong and forces
-       * callers to do horrible hacks like set a huge usize on the child requisition
-       * to get the base size right. We really want to find the answers to:
+      /* If the geometry widget is set, then the hints really apply to that
+       * widget. This is pretty much meaningless unless the window layout
+       * is such that the rest of the window adds fixed size borders to
+       * the geometry widget. Our job is to figure the size of the borders;
+       * We do that by asking how big the toplevel would be if the
+       * geometry widget was *really big*.
        *
-       *  - If the geometry widget was infinitely big, how much extra space
-       *    would be needed for the stuff around it.
+       *  +----------+
+       *  |AAAAAAAAA | At small sizes, the minimum sizes of widgets
+       *  |GGGGG    B| in the border can confuse things
+       *  |GGGGG    B|
+       *  |         B|
+       *  +----------+
        *
-       *  - If the geometry widget was infinitely small, how big would the
-       *    window still have to be.
-       *
-       * Finding these answers would be a bit of a mess here. (Bug #68668)
+       *  +-----------+
+       *  |AAAAAAAAA  | When the geometry widget is large, things are
+       *  |GGGGGGGGGGB| clearer.
+       *  |GGGGGGGGGGB|
+       *  |GGGGGGGGGG |
+       *  +-----------+
        */
-      gtk_widget_get_child_requisition (geometry_info->widget, &child_requisition);
-      
-      extra_width = widget->requisition.width - child_requisition.width;
-      extra_height = widget->requisition.height - child_requisition.height;
+#define TEMPORARY_SIZE 10000 /* 10,000 pixels should be bigger than real widget sizes */
+      GtkRequisition requisition;
+      int current_width, current_height;
+
+      _gtk_widget_override_size_request (geometry_info->widget,
+                                        TEMPORARY_SIZE, TEMPORARY_SIZE,
+                                        &current_width, &current_height);
+      gtk_widget_get_preferred_size (widget,
+                                     &requisition, NULL);
+      _gtk_widget_restore_size_request (geometry_info->widget,
+                                       current_width, current_height);
+
+      extra_width = requisition.width - TEMPORARY_SIZE;
+      extra_height = requisition.height - TEMPORARY_SIZE;
+
+      if (extra_width < 0 || extra_height < 0)
+       {
+         g_warning("Toplevel size doesn't seem to directly depend on the "
+                   "size of the geometry widget from gtk_window_set_geometry_hints(). "
+                   "The geometry widget might not be in the window, or it might not "
+                   "be packed into the window appropriately");
+         extra_width = MAX(extra_width, 0);
+         extra_height = MAX(extra_height, 0);
+       }
+#undef TEMPORARY_SIZE
     }
 
   /* We don't want to set GDK_HINT_POS in here, we just set it
@@ -6626,27 +7472,43 @@ gtk_window_compute_hints (GtkWindow   *window,
       new_geometry->base_width += extra_width;
       new_geometry->base_height += extra_height;
     }
-  else if (!(*new_flags & GDK_HINT_MIN_SIZE) &&
-          (*new_flags & GDK_HINT_RESIZE_INC) &&
-          ((extra_width != 0) || (extra_height != 0)))
+  else
     {
+      /* For simplicity, we always set the base hint, even when we
+       * don't expect it to have any visible effect.
+       * (Note: geometry_size_to_pixels() depends on this.)
+       */
       *new_flags |= GDK_HINT_BASE_SIZE;
-      
+
       new_geometry->base_width = extra_width;
       new_geometry->base_height = extra_height;
+
+      /* As for X, if BASE_SIZE is not set but MIN_SIZE is set, then the
+       * base size is the minimum size */
+      if (*new_flags & GDK_HINT_MIN_SIZE)
+       {
+         if (new_geometry->min_width > 0)
+           new_geometry->base_width += new_geometry->min_width;
+         if (new_geometry->min_height > 0)
+           new_geometry->base_height += new_geometry->min_height;
+       }
     }
-  
+
+  /* Please use a good size for unresizable widgets, not the minimum one. */
+  if (!priv->resizable)
+    gtk_window_guess_default_size (window, &requisition.width, &requisition.height);
+
   if (*new_flags & GDK_HINT_MIN_SIZE)
     {
       if (new_geometry->min_width < 0)
        new_geometry->min_width = requisition.width;
       else
-        new_geometry->min_width += extra_width;
+        new_geometry->min_width = MAX (requisition.width, new_geometry->min_width + extra_width);
 
       if (new_geometry->min_height < 0)
        new_geometry->min_height = requisition.height;
       else
-       new_geometry->min_height += extra_height;
+       new_geometry->min_height = MAX (requisition.height, new_geometry->min_height + extra_height);
     }
   else
     {
@@ -6668,7 +7530,7 @@ gtk_window_compute_hints (GtkWindow   *window,
       else
        new_geometry->max_height += extra_height;
     }
-  else if (!window->resizable)
+  else if (!priv->resizable)
     {
       *new_flags |= GDK_HINT_MAX_SIZE;
       
@@ -6677,132 +7539,55 @@ gtk_window_compute_hints (GtkWindow   *window,
     }
 
   *new_flags |= GDK_HINT_WIN_GRAVITY;
-  new_geometry->win_gravity = window->gravity;
+  new_geometry->win_gravity = priv->gravity;
 }
 
 /***********************
  * Redrawing functions *
  ***********************/
 
-static void
-gtk_window_paint (GtkWidget     *widget,
-                 GdkRectangle *area)
-{
-  gtk_paint_flat_box (widget->style, widget->window, GTK_STATE_NORMAL, 
-                     GTK_SHADOW_NONE, area, widget, "base", 0, 0, -1, -1);
-}
-
-static gint
-gtk_window_expose (GtkWidget      *widget,
-                  GdkEventExpose *event)
-{
-  if (!gtk_widget_get_app_paintable (widget))
-    gtk_window_paint (widget, &event->area);
-  
-  if (GTK_WIDGET_CLASS (gtk_window_parent_class)->expose_event)
-    return GTK_WIDGET_CLASS (gtk_window_parent_class)->expose_event (widget, event);
-
-  return FALSE;
-}
-
-/**
- * gtk_window_set_has_frame:
- * @window: a #GtkWindow
- * @setting: a boolean
- *
- * (Note: this is a special-purpose function for the framebuffer port,
- *  that causes GTK+ to draw its own window border. For most applications,
- *  you want gtk_window_set_decorated() instead, which tells the window
- *  manager whether to draw the window border.)
- * 
- * If this function is called on a window with setting of %TRUE, before
- * it is realized or showed, it will have a "frame" window around
- * @window->window, accessible in @window->frame. Using the signal 
- * frame_event you can receive all events targeted at the frame.
- * 
- * This function is used by the linux-fb port to implement managed
- * windows, but it could conceivably be used by X-programs that
- * want to do their own window decorations.
- *
- **/
-void
-gtk_window_set_has_frame (GtkWindow *window, 
-                         gboolean   setting)
+static gboolean
+gtk_window_draw (GtkWidget *widget,
+                cairo_t   *cr)
 {
-  g_return_if_fail (GTK_IS_WINDOW (window));
-  g_return_if_fail (!gtk_widget_get_realized (GTK_WIDGET (window)));
-
-  window->has_frame = setting != FALSE;
-}
+  GtkWindowPrivate *priv = GTK_WINDOW (widget)->priv;
+  GtkStyleContext *context;
+  gboolean ret = FALSE;
 
-/**
- * gtk_window_get_has_frame:
- * @window: a #GtkWindow
- * 
- * Accessor for whether the window has a frame window exterior to
- * @window->window. Gets the value set by gtk_window_set_has_frame ().
- *
- * Return value: %TRUE if a frame has been added to the window
- *   via gtk_window_set_has_frame().
- **/
-gboolean
-gtk_window_get_has_frame (GtkWindow *window)
-{
-  g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
+  context = gtk_widget_get_style_context (widget);
 
-  return window->has_frame;
-}
+  if (!gtk_widget_get_app_paintable (widget) &&
+      gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
+    {
+      gtk_render_background (context, cr, 0, 0,
+                            gtk_widget_get_allocated_width (widget),
+                            gtk_widget_get_allocated_height (widget));
+    }
 
-/**
- * gtk_window_set_frame_dimensions:
- * @window: a #GtkWindow that has a frame
- * @left: The width of the left border
- * @top: The height of the top border
- * @right: The width of the right border
- * @bottom: The height of the bottom border
- *
- * (Note: this is a special-purpose function intended for the framebuffer
- *  port; see gtk_window_set_has_frame(). It will have no effect on the
- *  window border drawn by the window manager, which is the normal
- *  case when using the X Window system.)
- *
- * For windows with frames (see gtk_window_set_has_frame()) this function
- * can be used to change the size of the frame border.
- **/
-void
-gtk_window_set_frame_dimensions (GtkWindow *window, 
-                                gint       left,
-                                gint       top,
-                                gint       right,
-                                gint       bottom)
-{
-  GtkWidget *widget;
+  if (GTK_WIDGET_CLASS (gtk_window_parent_class)->draw)
+    ret = GTK_WIDGET_CLASS (gtk_window_parent_class)->draw (widget, cr);
 
-  g_return_if_fail (GTK_IS_WINDOW (window));
+  if (priv->grip_window &&
+      gtk_cairo_should_draw_window (cr, priv->grip_window))
+    {
+      GdkRectangle rect;
 
-  widget = GTK_WIDGET (window);
+      gtk_style_context_save (context);
+      cairo_save (cr);
 
-  if (window->frame_left == left &&
-      window->frame_top == top &&
-      window->frame_right == right && 
-      window->frame_bottom == bottom)
-    return;
+      gtk_cairo_transform_to_window (cr, widget, priv->grip_window);
+      gtk_window_get_resize_grip_area (GTK_WINDOW (widget), &rect);
 
-  window->frame_left = left;
-  window->frame_top = top;
-  window->frame_right = right;
-  window->frame_bottom = bottom;
+      gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BACKGROUND);
+      gtk_style_context_add_class (context, GTK_STYLE_CLASS_GRIP);
+      gtk_style_context_set_junction_sides (context, get_grip_junction (widget));
+      gtk_render_handle (context, cr, 0, 0, rect.width, rect.height);
 
-  if (gtk_widget_get_realized (widget) && window->frame)
-    {
-      gint width = widget->allocation.width + left + right;
-      gint height = widget->allocation.height + top + bottom;
-      gdk_window_resize (window->frame, width, height);
-      gtk_decorated_window_move_resize_window (window,
-                                              left, top,
-                                              widget->allocation.width,
-                                              widget->allocation.height);
+      cairo_restore (cr);
+      gtk_style_context_restore (context);
     }
+
+  return ret;
 }
 
 /**
@@ -6849,35 +7634,44 @@ void
 gtk_window_present_with_time (GtkWindow *window,
                              guint32    timestamp)
 {
+  GtkWindowPrivate *priv;
   GtkWidget *widget;
+  GdkWindow *gdk_window;
 
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
   widget = GTK_WIDGET (window);
 
   if (gtk_widget_get_visible (widget))
     {
-      g_assert (widget->window != NULL);
-      
-      gdk_window_show (widget->window);
+      gdk_window = gtk_widget_get_window (widget);
+
+      g_assert (gdk_window != NULL);
+
+      gdk_window_show (gdk_window);
 
       /* Translate a timestamp of GDK_CURRENT_TIME appropriately */
       if (timestamp == GDK_CURRENT_TIME)
         {
 #ifdef GDK_WINDOWING_X11
-          GdkDisplay *display;
+         if (GDK_IS_X11_WINDOW(gdk_window))
+           {
+             GdkDisplay *display;
 
-          display = gtk_widget_get_display (GTK_WIDGET (window));
-          timestamp = gdk_x11_display_get_user_time (display);
-#else
-          timestamp = gtk_get_current_event_time ();
+             display = gtk_widget_get_display (GTK_WIDGET (window));
+             timestamp = gdk_x11_display_get_user_time (display);
+           }
+         else
 #endif
+           timestamp = gtk_get_current_event_time ();
         }
 
-      gdk_window_focus (widget->window, timestamp);
+      gdk_window_focus (gdk_window, timestamp);
     }
   else
     {
+      priv->initial_timestamp = timestamp;
       gtk_widget_show (widget);
     }
 }
@@ -6905,20 +7699,19 @@ gtk_window_present_with_time (GtkWindow *window,
 void
 gtk_window_iconify (GtkWindow *window)
 {
+  GtkWindowPrivate *priv;
   GtkWidget *widget;
   GdkWindow *toplevel;
   
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
   widget = GTK_WIDGET (window);
 
-  window->iconify_initially = TRUE;
+  priv->iconify_initially = TRUE;
+
+  toplevel = gtk_widget_get_window (widget);
 
-  if (window->frame)
-    toplevel = window->frame;
-  else
-    toplevel = widget->window;
-  
   if (toplevel != NULL)
     gdk_window_iconify (toplevel);
 }
@@ -6939,20 +7732,19 @@ gtk_window_iconify (GtkWindow *window)
 void
 gtk_window_deiconify (GtkWindow *window)
 {
+  GtkWindowPrivate *priv;
   GtkWidget *widget;
   GdkWindow *toplevel;
   
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
   widget = GTK_WIDGET (window);
 
-  window->iconify_initially = FALSE;
+  priv->iconify_initially = FALSE;
+
+  toplevel = gtk_widget_get_window (widget);
 
-  if (window->frame)
-    toplevel = window->frame;
-  else
-    toplevel = widget->window;
-  
   if (toplevel != NULL)
     gdk_window_deiconify (toplevel);
 }
@@ -6978,20 +7770,19 @@ gtk_window_deiconify (GtkWindow *window)
 void
 gtk_window_stick (GtkWindow *window)
 {
+  GtkWindowPrivate *priv;
   GtkWidget *widget;
   GdkWindow *toplevel;
   
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
   widget = GTK_WIDGET (window);
 
-  window->stick_initially = TRUE;
+  priv->stick_initially = TRUE;
+
+  toplevel = gtk_widget_get_window (widget);
 
-  if (window->frame)
-    toplevel = window->frame;
-  else
-    toplevel = widget->window;
-  
   if (toplevel != NULL)
     gdk_window_stick (toplevel);
 }
@@ -7014,20 +7805,19 @@ gtk_window_stick (GtkWindow *window)
 void
 gtk_window_unstick (GtkWindow *window)
 {
+  GtkWindowPrivate *priv;
   GtkWidget *widget;
   GdkWindow *toplevel;
   
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
   widget = GTK_WIDGET (window);
 
-  window->stick_initially = FALSE;
+  priv->stick_initially = FALSE;
+
+  toplevel = gtk_widget_get_window (widget);
 
-  if (window->frame)
-    toplevel = window->frame;
-  else
-    toplevel = widget->window;
-  
   if (toplevel != NULL)
     gdk_window_unstick (toplevel);
 }
@@ -7055,20 +7845,19 @@ gtk_window_unstick (GtkWindow *window)
 void
 gtk_window_maximize (GtkWindow *window)
 {
+  GtkWindowPrivate *priv;
   GtkWidget *widget;
   GdkWindow *toplevel;
   
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
   widget = GTK_WIDGET (window);
 
-  window->maximize_initially = TRUE;
+  priv->maximize_initially = TRUE;
+
+  toplevel = gtk_widget_get_window (widget);
 
-  if (window->frame)
-    toplevel = window->frame;
-  else
-    toplevel = widget->window;
-  
   if (toplevel != NULL)
     gdk_window_maximize (toplevel);
 }
@@ -7091,20 +7880,19 @@ gtk_window_maximize (GtkWindow *window)
 void
 gtk_window_unmaximize (GtkWindow *window)
 {
+  GtkWindowPrivate *priv;
   GtkWidget *widget;
   GdkWindow *toplevel;
   
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
   widget = GTK_WIDGET (window);
 
-  window->maximize_initially = FALSE;
+  priv->maximize_initially = FALSE;
+
+  toplevel = gtk_widget_get_window (widget);
 
-  if (window->frame)
-    toplevel = window->frame;
-  else
-    toplevel = widget->window;
-  
   if (toplevel != NULL)
     gdk_window_unmaximize (toplevel);
 }
@@ -7129,22 +7917,19 @@ gtk_window_unmaximize (GtkWindow *window)
 void
 gtk_window_fullscreen (GtkWindow *window)
 {
+  GtkWindowPrivate *priv;
   GtkWidget *widget;
   GdkWindow *toplevel;
-  GtkWindowPrivate *priv;
-  
+
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
   widget = GTK_WIDGET (window);
-  priv = GTK_WINDOW_GET_PRIVATE (window);
-  
+
   priv->fullscreen_initially = TRUE;
 
-  if (window->frame)
-    toplevel = window->frame;
-  else
-    toplevel = widget->window;
-  
+  toplevel = gtk_widget_get_window (widget);
+
   if (toplevel != NULL)
     gdk_window_fullscreen (toplevel);
 }
@@ -7172,19 +7957,16 @@ gtk_window_unfullscreen (GtkWindow *window)
   GtkWidget *widget;
   GdkWindow *toplevel;
   GtkWindowPrivate *priv;
-  
+
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
   widget = GTK_WIDGET (window);
-  priv = GTK_WINDOW_GET_PRIVATE (window);
-  
+
   priv->fullscreen_initially = FALSE;
 
-  if (window->frame)
-    toplevel = window->frame;
-  else
-    toplevel = widget->window;
-  
+  toplevel = gtk_widget_get_window (widget);
+
   if (toplevel != NULL)
     gdk_window_unfullscreen (toplevel);
 }
@@ -7227,17 +8009,14 @@ gtk_window_set_keep_above (GtkWindow *window,
 
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
   widget = GTK_WIDGET (window);
-  priv = GTK_WINDOW_GET_PRIVATE (window);
 
   priv->above_initially = setting != FALSE;
   if (setting)
     priv->below_initially = FALSE;
 
-  if (window->frame)
-    toplevel = window->frame;
-  else
-    toplevel = widget->window;
+  toplevel = gtk_widget_get_window (widget);
 
   if (toplevel != NULL)
     gdk_window_set_keep_above (toplevel, setting);
@@ -7281,17 +8060,14 @@ gtk_window_set_keep_below (GtkWindow *window,
 
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
   widget = GTK_WIDGET (window);
-  priv = GTK_WINDOW_GET_PRIVATE (window);
 
   priv->below_initially = setting != FALSE;
   if (setting)
     priv->above_initially = FALSE;
 
-  if (window->frame)
-    toplevel = window->frame;
-  else
-    toplevel = widget->window;
+  toplevel = gtk_widget_get_window (widget);
 
   if (toplevel != NULL)
     gdk_window_set_keep_below (toplevel, setting);
@@ -7309,13 +8085,24 @@ void
 gtk_window_set_resizable (GtkWindow *window,
                           gboolean   resizable)
 {
+  GtkWindowPrivate *priv;
+
   g_return_if_fail (GTK_IS_WINDOW (window));
 
-  window->resizable = (resizable != FALSE);
+  priv = window->priv;
 
-  g_object_notify (G_OBJECT (window), "resizable");
+  resizable = (resizable != FALSE);
 
-  gtk_widget_queue_resize_no_redraw (GTK_WIDGET (window));
+  if (priv->resizable != resizable)
+    {
+      priv->resizable = resizable;
+
+      update_grip_visibility (window);
+
+      gtk_widget_queue_resize_no_redraw (GTK_WIDGET (window));
+
+      g_object_notify (G_OBJECT (window), "resizable");
+    }
 }
 
 /**
@@ -7331,7 +8118,7 @@ gtk_window_get_resizable (GtkWindow *window)
 {
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
 
-  return window->resizable;
+  return window->priv->resizable;
 }
 
 /**
@@ -7351,11 +8138,15 @@ void
 gtk_window_set_gravity (GtkWindow *window,
                        GdkGravity gravity)
 {
+  GtkWindowPrivate *priv;
+
   g_return_if_fail (GTK_IS_WINDOW (window));
 
-  if (gravity != window->gravity)
+  priv = window->priv;
+
+  if (gravity != priv->gravity)
     {
-      window->gravity = gravity;
+      priv->gravity = gravity;
 
       /* gtk_window_move_resize() will adapt gravity
        */
@@ -7378,7 +8169,7 @@ gtk_window_get_gravity (GtkWindow *window)
 {
   g_return_val_if_fail (GTK_IS_WINDOW (window), 0);
 
-  return window->gravity;
+  return window->priv->gravity;
 }
 
 /**
@@ -7408,60 +8199,19 @@ gtk_window_begin_resize_drag  (GtkWindow    *window,
 {
   GtkWidget *widget;
   GdkWindow *toplevel;
-  
+
   g_return_if_fail (GTK_IS_WINDOW (window));
   widget = GTK_WIDGET (window);
   g_return_if_fail (gtk_widget_get_visible (widget));
-  
-  if (window->frame)
-    toplevel = window->frame;
-  else
-    toplevel = widget->window;
-  
+
+  toplevel = gtk_widget_get_window (widget);
+
   gdk_window_begin_resize_drag (toplevel,
                                 edge, button,
                                 root_x, root_y,
                                 timestamp);
 }
 
-/**
- * gtk_window_get_frame_dimensions:
- * @window: a #GtkWindow
- * @left: (out) (allow-none): location to store the width of the frame at the left, or %NULL
- * @top: (out) (allow-none): location to store the height of the frame at the top, or %NULL
- * @right: (out) (allow-none): location to store the width of the frame at the returns, or %NULL
- * @bottom: (out) (allow-none): location to store the height of the frame at the bottom, or %NULL
- *
- * (Note: this is a special-purpose function intended for the
- *  framebuffer port; see gtk_window_set_has_frame(). It will not
- *  return the size of the window border drawn by the <link
- *  linkend="gtk-X11-arch">window manager</link>, which is the normal
- *  case when using a windowing system.  See
- *  gdk_window_get_frame_extents() to get the standard window border
- *  extents.)
- * 
- * Retrieves the dimensions of the frame window for this toplevel.
- * See gtk_window_set_has_frame(), gtk_window_set_frame_dimensions().
- **/
-void
-gtk_window_get_frame_dimensions (GtkWindow *window,
-                                gint      *left,
-                                gint      *top,
-                                gint      *right,
-                                gint      *bottom)
-{
-  g_return_if_fail (GTK_IS_WINDOW (window));
-
-  if (left)
-    *left = window->frame_left;
-  if (top)
-    *top = window->frame_top;
-  if (right)
-    *right = window->frame_right;
-  if (bottom)
-    *bottom = window->frame_bottom;
-}
-
 /**
  * gtk_window_begin_move_drag:
  * @window: a #GtkWindow
@@ -7487,23 +8237,20 @@ gtk_window_begin_move_drag  (GtkWindow *window,
 {
   GtkWidget *widget;
   GdkWindow *toplevel;
-  
+
   g_return_if_fail (GTK_IS_WINDOW (window));
   widget = GTK_WIDGET (window);
   g_return_if_fail (gtk_widget_get_visible (widget));
-  
-  if (window->frame)
-    toplevel = window->frame;
-  else
-    toplevel = widget->window;
-  
+
+  toplevel = gtk_widget_get_window (widget);
+
   gdk_window_begin_move_drag (toplevel,
                               button,
                               root_x, root_y,
                               timestamp);
 }
 
-/** 
+/**
  * gtk_window_set_screen:
  * @window: a #GtkWindow.
  * @screen: a #GdkScreen.
@@ -7518,36 +8265,51 @@ void
 gtk_window_set_screen (GtkWindow *window,
                       GdkScreen *screen)
 {
+  GtkWindowPrivate *priv;
   GtkWidget *widget;
   GdkScreen *previous_screen;
   gboolean was_mapped;
-  
+
   g_return_if_fail (GTK_IS_WINDOW (window));
   g_return_if_fail (GDK_IS_SCREEN (screen));
 
-  if (screen == window->screen)
+  priv = window->priv;
+
+  if (screen == priv->screen)
     return;
 
   widget = GTK_WIDGET (window);
 
-  previous_screen = window->screen;
+  previous_screen = priv->screen;
   was_mapped = gtk_widget_get_mapped (widget);
 
   if (was_mapped)
     gtk_widget_unmap (widget);
   if (gtk_widget_get_realized (widget))
     gtk_widget_unrealize (widget);
-      
+
   gtk_window_free_key_hash (window);
-  window->screen = screen;
+  priv->screen = screen;
   gtk_widget_reset_rc_styles (widget);
   if (screen != previous_screen)
     {
-      g_signal_handlers_disconnect_by_func (previous_screen,
-                                           gtk_window_on_composited_changed, window);
-      g_signal_connect (screen, "composited-changed", 
-                       G_CALLBACK (gtk_window_on_composited_changed), window);
-      
+      if (previous_screen)
+        {
+          g_signal_handlers_disconnect_by_func (previous_screen,
+                                                gtk_window_on_composited_changed, window);
+#ifdef GDK_WINDOWING_X11
+          g_signal_handlers_disconnect_by_func (gtk_settings_get_for_screen (previous_screen),
+                                                gtk_window_on_theme_variant_changed, window);
+#endif
+        }
+      g_signal_connect (screen, "composited-changed",
+                        G_CALLBACK (gtk_window_on_composited_changed), window);
+#ifdef GDK_WINDOWING_X11
+      g_signal_connect (gtk_settings_get_for_screen (screen),
+                        "notify::gtk-application-prefer-dark-theme",
+                        G_CALLBACK (gtk_window_on_theme_variant_changed), window);
+#endif
+
       _gtk_widget_propagate_screen_changed (widget, previous_screen);
       _gtk_widget_propagate_composited_changed (widget);
     }
@@ -7557,6 +8319,36 @@ gtk_window_set_screen (GtkWindow *window,
     gtk_widget_map (widget);
 }
 
+static void
+gtk_window_set_theme_variant (GtkWindow *window)
+{
+#ifdef GDK_WINDOWING_X11
+  GdkWindow *gdk_window;
+  gboolean   dark_theme_requested;
+
+  g_object_get (gtk_settings_get_for_screen (window->priv->screen),
+                "gtk-application-prefer-dark-theme", &dark_theme_requested,
+                NULL);
+
+  gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+
+  if (GDK_IS_X11_WINDOW (gdk_window))
+    gdk_x11_window_set_theme_variant (gdk_window,
+                                      dark_theme_requested ? "dark" : NULL);
+#endif
+}
+
+#ifdef GDK_WINDOWING_X11
+static void
+gtk_window_on_theme_variant_changed (GtkSettings *settings,
+                                     GParamSpec  *pspec,
+                                     GtkWindow   *window)
+{
+  if (window->priv->type == GTK_WINDOW_TOPLEVEL)
+    gtk_window_set_theme_variant (window);
+}
+#endif
+
 static void
 gtk_window_on_composited_changed (GdkScreen *screen,
                                  GtkWindow *window)
@@ -7569,8 +8361,10 @@ gtk_window_on_composited_changed (GdkScreen *screen,
 static GdkScreen *
 gtk_window_check_screen (GtkWindow *window)
 {
-  if (window->screen)
-    return window->screen;
+  GtkWindowPrivate *priv = window->priv;
+
+  if (priv->screen)
+    return priv->screen;
   else
     {
       g_warning ("Screen for GtkWindow not set; you must always set\n"
@@ -7579,7 +8373,7 @@ gtk_window_check_screen (GtkWindow *window)
     }
 }
 
-/** 
+/**
  * gtk_window_get_screen:
  * @window: a #GtkWindow.
  *
@@ -7593,8 +8387,8 @@ GdkScreen*
 gtk_window_get_screen (GtkWindow *window)
 {
   g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
-   
-  return window->screen;
+
+  return window->priv->screen;
 }
 
 /**
@@ -7618,7 +8412,7 @@ gtk_window_is_active (GtkWindow *window)
 {
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
 
-  return window->is_active;
+  return window->priv->is_active;
 }
 
 /**
@@ -7638,40 +8432,38 @@ gtk_window_has_toplevel_focus (GtkWindow *window)
 {
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
 
-  return window->has_toplevel_focus;
+  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 (GtkWindowGroup, gtk_window_group, G_TYPE_OBJECT)
+
 static void
-gtk_window_group_class_init (GtkWindowGroupClass *klass)
+gtk_window_group_init (GtkWindowGroup *group)
 {
-  g_type_class_add_private (klass, sizeof (GtkWindowGroupPrivate));
+  group->priv = G_TYPE_INSTANCE_GET_PRIVATE (group,
+                                             GTK_TYPE_WINDOW_GROUP,
+                                             GtkWindowGroupPrivate);
 }
 
-GType
-gtk_window_group_get_type (void)
+static void
+gtk_window_group_class_init (GtkWindowGroupClass *klass)
 {
-  static GType window_group_type = 0;
-
-  if (!window_group_type)
-    {
-      const GTypeInfo window_group_info =
-      {
-       sizeof (GtkWindowGroupClass),
-       NULL,           /* base_init */
-       NULL,           /* base_finalize */
-       (GClassInitFunc) gtk_window_group_class_init,
-       NULL,           /* class_finalize */
-       NULL,           /* class_data */
-       sizeof (GtkWindowGroup),
-       0,              /* n_preallocs */
-       (GInstanceInitFunc) NULL,
-      };
-
-      window_group_type = g_type_register_static (G_TYPE_OBJECT, I_("GtkWindowGroup"), 
-                                                 &window_group_info, 0);
-    }
-
-  return window_group_type;
+  g_type_class_add_private (klass, sizeof (GtkWindowGroupPrivate));
 }
 
 /**
@@ -7690,14 +8482,16 @@ gtk_window_group_new (void)
 
 static void
 window_group_cleanup_grabs (GtkWindowGroup *group,
-                           GtkWindow      *window)
+                            GtkWindow      *window)
 {
   GtkWindowGroupPrivate *priv;
   GtkDeviceGrabInfo *info;
   GSList *tmp_list;
   GSList *to_remove = NULL;
 
-  tmp_list = group->grabs;
+  priv = group->priv;
+
+  tmp_list = priv->grabs;
   while (tmp_list)
     {
       if (gtk_widget_get_toplevel (tmp_list->data) == (GtkWidget*) window)
@@ -7712,7 +8506,6 @@ window_group_cleanup_grabs (GtkWindowGroup *group,
       to_remove = g_slist_delete_link (to_remove, to_remove);
     }
 
-  priv = GTK_WINDOW_GROUP_GET_PRIVATE (group);
   tmp_list = priv->device_grabs;
 
   while (tmp_list)
@@ -7745,20 +8538,24 @@ 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));
 
-  if (window->group != window_group)
+  priv = window->priv;
+
+  if (priv->group != window_group)
     {
       g_object_ref (window);
       g_object_ref (window_group);
-      
-      if (window->group)
-       gtk_window_group_remove_window (window->group, window);
+
+      if (priv->group)
+       gtk_window_group_remove_window (priv->group, window);
       else
        window_group_cleanup_grabs (gtk_window_get_group (NULL), window);
 
-      window->group = window_group;
+      priv->group = window_group;
 
       g_object_unref (window);
     }
@@ -7775,15 +8572,18 @@ 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));
-  g_return_if_fail (window->group == window_group);
+  priv = window->priv;
+  g_return_if_fail (priv->group == window_group);
 
   g_object_ref (window);
 
   window_group_cleanup_grabs (window_group, window);
-  window->group = NULL;
-  
+  priv->group = NULL;
+
   g_object_unref (window_group);
   g_object_unref (window);
 }
@@ -7794,8 +8594,8 @@ gtk_window_group_remove_window (GtkWindowGroup *window_group,
  *
  * Returns a list of the #GtkWindows that belong to @window_group.
  *
- * Returns: (element-type GtkWidget) (transfer container): A newly-allocated list of
- *   windows inside the group.
+ * Returns: (element-type GtkWindow) (transfer container): A
+ *   newly-allocated list of windows inside the group.
  *
  * Since: 2.14
  **/
@@ -7813,10 +8613,12 @@ gtk_window_group_list_windows (GtkWindowGroup *window_group)
     {
       GtkWindow *window = toplevel->data;
 
-      if (window_group == window->group)
+      if (window_group == window->priv->group)
        group_windows = g_list_prepend (group_windows, window);
     }
 
+  g_list_free (toplevels);
+
   return g_list_reverse (group_windows);
 }
 
@@ -7835,8 +8637,8 @@ gtk_window_group_list_windows (GtkWindowGroup *window_group)
 GtkWindowGroup *
 gtk_window_get_group (GtkWindow *window)
 {
-  if (window && window->group)
-    return window->group;
+  if (window && window->priv->group)
+    return window->priv->group;
   else
     {
       static GtkWindowGroup *default_group = NULL;
@@ -7863,7 +8665,7 @@ gtk_window_has_group (GtkWindow *window)
 {
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
 
-  return window->group != NULL;
+  return window->priv->group != NULL;
 }
 
 /**
@@ -7873,7 +8675,7 @@ gtk_window_has_group (GtkWindow *window)
  * Gets the current grab widget of the given group,
  * see gtk_grab_add().
  *
- * Returns: the current grab widget of the group
+ * Returns: (transfer none): the current grab widget of the group
  *
  * Since: 2.22
  */
@@ -7882,11 +8684,32 @@ gtk_window_group_get_current_grab (GtkWindowGroup *window_group)
 {
   g_return_val_if_fail (GTK_IS_WINDOW_GROUP (window_group), NULL);
 
-  if (window_group->grabs)
-    return GTK_WIDGET (window_group->grabs->data);
+  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,
@@ -7896,7 +8719,7 @@ _gtk_window_group_add_device_grab (GtkWindowGroup *window_group,
   GtkWindowGroupPrivate *priv;
   GtkDeviceGrabInfo *info;
 
-  priv = GTK_WINDOW_GROUP_GET_PRIVATE (window_group);
+  priv = window_group->priv;
 
   info = g_slice_new0 (GtkDeviceGrabInfo);
   info->widget = widget;
@@ -7916,7 +8739,7 @@ _gtk_window_group_remove_device_grab (GtkWindowGroup *window_group,
   GSList *list, *node = NULL;
   GdkDevice *other_device;
 
-  priv = GTK_WINDOW_GROUP_GET_PRIVATE (window_group);
+  priv = window_group->priv;
   other_device = gdk_device_get_associated_device (device);
   list = priv->device_grabs;
 
@@ -7951,7 +8774,7 @@ _gtk_window_group_remove_device_grab (GtkWindowGroup *window_group,
  *
  * Returns the current grab widget for @device, or %NULL if none.
  *
- * Returns: The grab widget, or %NULL
+ * Returns: (transfer none): The grab widget, or %NULL
  *
  * Since: 3.0
  */
@@ -7967,7 +8790,7 @@ gtk_window_group_get_current_device_grab (GtkWindowGroup *window_group,
   g_return_val_if_fail (GTK_IS_WINDOW_GROUP (window_group), NULL);
   g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
 
-  priv = GTK_WINDOW_GROUP_GET_PRIVATE (window_group);
+  priv = window_group->priv;
   list = priv->device_grabs;
   other_device = gdk_device_get_associated_device (device);
 
@@ -7994,7 +8817,7 @@ _gtk_window_group_widget_is_blocked_for_device (GtkWindowGroup *window_group,
   GdkDevice *other_device;
   GSList *list;
 
-  priv = GTK_WINDOW_GROUP_GET_PRIVATE (window_group);
+  priv = window_group->priv;
   other_device = gdk_device_get_associated_device (device);
   list = priv->device_grabs;
 
@@ -8244,7 +9067,7 @@ gtk_XParseGeometry (const char   *string,
  *   gtk_init (&argc, &argv);
  *   
  *   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- *   vbox = gtk_vbox_new (FALSE, 0);
+ *   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 0);
  *   
  *   gtk_container_add (GTK_CONTAINER (window), vbox);
  *   fill_with_content (vbox);
@@ -8278,6 +9101,7 @@ gtk_window_parse_geometry (GtkWindow   *window,
 {
   gint result, x = 0, y = 0;
   guint w, h;
+  GtkWidget *child;
   GdkGravity grav;
   gboolean size_set, pos_set;
   GdkScreen *screen;
@@ -8285,6 +9109,12 @@ gtk_window_parse_geometry (GtkWindow   *window,
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
   g_return_val_if_fail (geometry != NULL, FALSE);
 
+  child = gtk_bin_get_child (GTK_BIN (window));
+  if (!child || !gtk_widget_get_visible (child))
+    g_warning ("gtk_window_parse_geometry() called on a window with no "
+              "visible children; the window should be set up before "
+              "gtk_window_parse_geometry() is called.");
+
   screen = gtk_window_check_screen (window);
   
   result = gtk_XParseGeometry (geometry, &x, &y, &w, &h);
@@ -8368,7 +9198,7 @@ gtk_window_mnemonic_hash_foreach (guint      keyval,
     gpointer func_data;
   } *info = data;
 
-  (*info->func) (info->window, keyval, info->window->mnemonic_modifier, TRUE, info->func_data);
+  (*info->func) (info->window, keyval, info->window->priv->mnemonic_modifier, TRUE, info->func_data);
 }
 
 void
@@ -8454,8 +9284,8 @@ add_to_key_hash (GtkWindow      *window,
    */
   if (modifiers & GDK_SHIFT_MASK)
     {
-      if (keyval == GDK_Tab)
-       keyval = GDK_ISO_Left_Tab;
+      if (keyval == GDK_KEY_Tab)
+       keyval = GDK_KEY_ISO_Left_Tab;
       else
        keyval = gdk_keyval_to_upper (keyval);
     }
@@ -8578,26 +9408,27 @@ gtk_window_activate_key (GtkWindow   *window,
 static void
 window_update_has_focus (GtkWindow *window)
 {
+  GtkWindowPrivate *priv = window->priv;
   GtkWidget *widget = GTK_WIDGET (window);
-  gboolean has_focus = window->has_toplevel_focus && window->is_active;
-  
-  if (has_focus != window->has_focus)
+  gboolean has_focus = priv->has_toplevel_focus && priv->is_active;
+
+  if (has_focus != priv->has_focus)
     {
-      window->has_focus = has_focus;
-      
+      priv->has_focus = has_focus;
+
       if (has_focus)
        {
-         if (window->focus_widget &&
-             window->focus_widget != widget &&
-             !gtk_widget_has_focus (window->focus_widget))
-           do_focus_change (window->focus_widget, TRUE);       
+         if (priv->focus_widget &&
+             priv->focus_widget != widget &&
+             !gtk_widget_has_focus (priv->focus_widget))
+           do_focus_change (priv->focus_widget, TRUE);
        }
       else
        {
-         if (window->focus_widget &&
-             window->focus_widget != widget &&
-             gtk_widget_has_focus (window->focus_widget))
-           do_focus_change (window->focus_widget, FALSE);
+         if (priv->focus_widget &&
+             priv->focus_widget != widget &&
+             gtk_widget_has_focus (priv->focus_widget))
+           do_focus_change (priv->focus_widget, FALSE);
        }
     }
 }
@@ -8615,13 +9446,17 @@ void
 _gtk_window_set_is_active (GtkWindow *window,
                           gboolean   is_active)
 {
+  GtkWindowPrivate *priv;
+
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
+
   is_active = is_active != FALSE;
 
-  if (is_active != window->is_active)
+  if (is_active != priv->is_active)
     {
-      window->is_active = is_active;
+      priv->is_active = is_active;
       window_update_has_focus (window);
 
       g_object_notify (G_OBJECT (window), "is-active");
@@ -8632,18 +9467,19 @@ _gtk_window_set_is_active (GtkWindow *window,
  * _gtk_window_set_is_toplevel:
  * @window: a #GtkWindow
  * @is_toplevel: %TRUE if the window is still a real toplevel (nominally a
- * parent of the root window); %FALSE if it is not (for example, for an
+ * child of the root window); %FALSE if it is not (for example, for an
  * in-process, parented GtkPlug)
  *
  * Internal function used by #GtkPlug when it gets parented/unparented by a
- * #GtkSocket.  This keeps the @window's #GTK_TOPLEVEL flag in sync with the
- * global list of toplevel windows.
+ * #GtkSocket.  This keeps the @window's #GTK_WINDOW_TOPLEVEL flag in sync
+ * with the global list of toplevel windows.
  */
 void
 _gtk_window_set_is_toplevel (GtkWindow *window,
-                            gboolean   is_toplevel)
+                             gboolean   is_toplevel)
 {
   GtkWidget *widget;
+  GtkWidget *toplevel;
 
   widget = GTK_WIDGET (window);
 
@@ -8657,13 +9493,45 @@ _gtk_window_set_is_toplevel (GtkWindow *window,
 
   if (is_toplevel)
     {
+      /* Pass through regular pathways of an embedded toplevel
+       * to go through unmapping and hiding the widget before
+       * becomming a toplevel again.
+       *
+       * We remain hidden after becomming toplevel in order to
+       * avoid problems during an embedded toplevel's dispose cycle
+       * (When a toplevel window is shown it tries to grab focus again,
+       * this causes problems while disposing).
+       */
+      gtk_widget_hide (widget);
+
+      /* Save the toplevel this widget was previously anchored into before
+       * propagating a hierarchy-changed.
+       *
+       * Usually this happens by way of gtk_widget_unparent() and we are
+       * already unanchored at this point, just adding this clause incase
+       * things happen differently.
+       */
+      toplevel = gtk_widget_get_toplevel (widget);
+      if (!gtk_widget_is_toplevel (toplevel))
+        toplevel = NULL;
+
       _gtk_widget_set_is_toplevel (widget, TRUE);
+
+      /* When a window becomes toplevel after being embedded and anchored
+       * into another window we need to unset its anchored flag so that
+       * the hierarchy changed signal kicks in properly.
+       */
+      _gtk_widget_set_anchored (widget, FALSE);
+      _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
+
       toplevel_list = g_slist_prepend (toplevel_list, window);
     }
   else
     {
       _gtk_widget_set_is_toplevel (widget, FALSE);
       toplevel_list = g_slist_remove (toplevel_list, window);
+
+      _gtk_widget_propagate_hierarchy_changed (widget, widget);
     }
 }
 
@@ -8679,13 +9547,17 @@ void
 _gtk_window_set_has_toplevel_focus (GtkWindow *window,
                                   gboolean   has_toplevel_focus)
 {
+  GtkWindowPrivate *priv;
+
   g_return_if_fail (GTK_IS_WINDOW (window));
-  
+
+  priv = window->priv;
+
   has_toplevel_focus = has_toplevel_focus != FALSE;
 
-  if (has_toplevel_focus != window->has_toplevel_focus)
+  if (has_toplevel_focus != priv->has_toplevel_focus)
     {
-      window->has_toplevel_focus = has_toplevel_focus;
+      priv->has_toplevel_focus = has_toplevel_focus;
       window_update_has_focus (window);
 
       g_object_notify (G_OBJECT (window), "has-toplevel-focus");
@@ -8729,7 +9601,7 @@ gtk_window_get_window_type (GtkWindow *window)
 {
   g_return_val_if_fail (GTK_IS_WINDOW (window), GTK_WINDOW_TOPLEVEL);
 
-  return window->type;
+  return window->priv->type;
 }
 
 /**
@@ -8746,13 +9618,9 @@ gtk_window_get_window_type (GtkWindow *window)
 gboolean
 gtk_window_get_mnemonics_visible (GtkWindow *window)
 {
-  GtkWindowPrivate *priv;
-
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
 
-  priv = GTK_WINDOW_GET_PRIVATE (window);
-
-  return priv->mnemonics_visible;
+  return window->priv->mnemonics_visible;
 }
 
 /**
@@ -8772,7 +9640,7 @@ gtk_window_set_mnemonics_visible (GtkWindow *window,
 
   g_return_if_fail (GTK_IS_WINDOW (window));
 
-  priv = GTK_WINDOW_GET_PRIVATE (window);
+  priv = window->priv;
 
   setting = setting != FALSE;
 
@@ -8782,14 +9650,135 @@ gtk_window_set_mnemonics_visible (GtkWindow *window,
       g_object_notify (G_OBJECT (window), "mnemonics-visible");
     }
 
+  if (priv->auto_mnemonics_timeout_id)
+    {
+      g_source_remove (priv->auto_mnemonics_timeout_id);
+      priv->auto_mnemonics_timeout_id = 0;
+    }
+
   priv->mnemonics_visible_set = TRUE;
 }
 
+static gboolean
+set_auto_mnemonics_visible_cb (gpointer data)
+{
+  GtkWindow *window = data;
+
+  gtk_window_set_mnemonics_visible (window, TRUE);
+
+  window->priv->auto_mnemonics_timeout_id = 0;
+
+  return FALSE;
+}
+
+void
+_gtk_window_set_auto_mnemonics_visible (GtkWindow *window)
+{
+  g_return_if_fail (GTK_IS_WINDOW (window));
+
+  if (window->priv->auto_mnemonics_timeout_id)
+    return;
+
+  window->priv->auto_mnemonics_timeout_id =
+    gdk_threads_add_timeout (AUTO_MNEMONICS_DELAY, set_auto_mnemonics_visible_cb, window);
+}
+
+/**
+ * gtk_window_get_focus_visible:
+ * @window: a #GtkWindow
+ *
+ * Gets the value of the #GtkWindow:focus-visible property.
+ *
+ * Returns: %TRUE if 'focus rectangles' are supposed to be visible
+ *     in this window.
+ *
+ * Since: 3.2
+ */
+gboolean
+gtk_window_get_focus_visible (GtkWindow *window)
+{
+  g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
+
+  return window->priv->focus_visible;
+}
+
+/**
+ * gtk_window_set_focus_visible:
+ * @window: a #GtkWindow
+ * @setting: the new value
+ *
+ * Sets the #GtkWindow:focus-visible property.
+ *
+ * Since: 3.2
+ */
+void
+gtk_window_set_focus_visible (GtkWindow *window,
+                              gboolean   setting)
+{
+  GtkWindowPrivate *priv;
+
+  g_return_if_fail (GTK_IS_WINDOW (window));
+
+  priv = window->priv;
+
+  setting = setting != FALSE;
+
+  if (priv->focus_visible != setting)
+    {
+      priv->focus_visible = setting;
+      g_object_notify (G_OBJECT (window), "focus-visible");
+    }
+}
+
 void
 _gtk_window_get_wmclass (GtkWindow  *window,
                          gchar     **wmclass_name,
                          gchar     **wmclass_class)
 {
-  *wmclass_name = window->wmclass_name;
-  *wmclass_class = window->wmclass_class;
+  GtkWindowPrivate *priv = window->priv;
+
+  *wmclass_name = priv->wmclass_name;
+  *wmclass_class = priv->wmclass_class;
+}
+
+/**
+ * gtk_window_set_has_user_ref_count:
+ * @window: a #GtkWindow
+ * @setting: the new value
+ *
+ * Tells GTK+ whether to drop its extra reference to the window
+ * when gtk_widget_destroy() is called.
+ *
+ * This function is only exported for the benefit of language
+ * bindings which may need to keep the window alive until their
+ * wrapper object is garbage collected. There is no justification
+ * for ever calling this function in an application.
+ *
+ * Since: 3.0
+ */
+void
+gtk_window_set_has_user_ref_count (GtkWindow *window,
+                                   gboolean   setting)
+{
+  g_return_if_fail (GTK_IS_WINDOW (window));
+
+  window->priv->has_user_ref_count = setting;
+}
+
+static void
+ensure_state_flag_backdrop (GtkWidget *widget)
+{
+  GdkWindow *window;
+  gboolean window_focused = TRUE;
+
+  window = gtk_widget_get_window (widget);
+
+  window_focused = gdk_window_get_state (window) & GDK_WINDOW_STATE_FOCUSED;
+
+  if (!window_focused)
+    gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_BACKDROP, FALSE);
+  else
+    gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
+
+  gtk_widget_queue_draw (widget);
 }