From 287b821705b5418cd14d5a31fda3f167ac4ddf72 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 1 Jun 2009 11:57:59 +0200 Subject: [PATCH] Rename gdk_window_set_has_native to gdk_window_ensure_native This also removes the (unimplemented) possibility to change a window to non-native. This seems generally not very useful, and there are some problems with it, for instance if two "users" need a window to be native and then one of the "users" doesn't need it anymore it can't change it back, because it is unaware of the other reason the window is native. --- docs/reference/gdk/tmpl/events.sgml | 1 + docs/reference/gdk/tmpl/windows.sgml | 1 + gdk/gdkwindow.c | 155 ++++++++++++--------------- gdk/x11/gdkdrawable-x11.c | 2 +- gdk/x11/gdkmain-x11.c | 2 +- gdk/x11/gdkwindow-x11.c | 4 +- tests/testwindows.c | 4 +- 7 files changed, 76 insertions(+), 93 deletions(-) diff --git a/docs/reference/gdk/tmpl/events.sgml b/docs/reference/gdk/tmpl/events.sgml index b4dff1b5ef..2c39b5ef66 100644 --- a/docs/reference/gdk/tmpl/events.sgml +++ b/docs/reference/gdk/tmpl/events.sgml @@ -94,6 +94,7 @@ for the possible window states was added in 2.8. @GDK_DAMAGE: the content of the window has been changed. This event type was added in 2.14. +@GDK_EVENT_LAST: diff --git a/docs/reference/gdk/tmpl/windows.sgml b/docs/reference/gdk/tmpl/windows.sgml index 195aabb6a4..2ecae48d1f 100644 --- a/docs/reference/gdk/tmpl/windows.sgml +++ b/docs/reference/gdk/tmpl/windows.sgml @@ -200,6 +200,7 @@ Describes the kind of window. @GDK_WINDOW_DIALOG: useless/deprecated compatibility type @GDK_WINDOW_TEMP: override redirect temporary window (used to implement #GtkMenu) @GDK_WINDOW_FOREIGN: foreign window (see gdk_window_foreign_new()) +@GDK_WINDOW_OFFSCREEN: diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c index b20cf69502..1c4d625ab3 100644 --- a/gdk/gdkwindow.c +++ b/gdk/gdkwindow.c @@ -1220,7 +1220,7 @@ gdk_window_reparent (GdkWindow *window, /* Reparenting to toplevel. Ensure we have a native window so this can work */ if (new_parent_private->window_type == GDK_WINDOW_ROOT || new_parent_private->window_type == GDK_WINDOW_FOREIGN) - gdk_window_set_has_native (window, TRUE); + gdk_window_ensure_native (window); do_reparent_to_impl = FALSE; if (gdk_window_has_impl (private)) @@ -1330,20 +1330,22 @@ gdk_window_reparent (GdkWindow *window, } /** - * gdk_window_set_has_native: + * gdk_window_ensure_native: * @window: a #GdkWindow - * @has_native: whethe the window should have a native window * - * Tries to create or remove a window-system native window for this - * GdkWindow. This may fail in some situations. For instance: + * Tries to ensure that there is a window-system native window for this + * GdkWindow. This may fail in some situations, returning %FALSE. * - * Toplevel and foreign windows must have a native window. * Offscreen window and children of them can never have native windows. + * * Some backends may not support native child windows. - * + * + * Returns: %TRUE if the window has a native window, %FALSE otherwise + * + * Since: 2.18 **/ -void -gdk_window_set_has_native (GdkWindow *window, gboolean has_native) +gboolean +gdk_window_ensure_native (GdkWindow *window) { GdkWindowObject *private; GdkWindowObject *impl_window; @@ -1358,87 +1360,66 @@ gdk_window_set_has_native (GdkWindow *window, gboolean has_native) if (GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT || GDK_WINDOW_DESTROYED (window)) - return; + return FALSE; private = (GdkWindowObject *) window; - - if (has_native) + + impl_window = gdk_window_get_impl_window (private); + + if (impl_window->window_type == GDK_WINDOW_OFFSCREEN) + return FALSE; /* native in offscreens not supported */ + + if (impl_window == private) + /* Already has an impl, and its not offscreen . */ + return TRUE; + + /* Need to create a native window */ + + screen = gdk_drawable_get_screen (window); + visual = gdk_drawable_get_visual (window); + + attributes.colormap = gdk_drawable_get_colormap (window); + + old_impl = private->impl; + _gdk_window_impl_new (window, (GdkWindow *)private->parent, screen, visual, + get_native_event_mask (private), &attributes, GDK_WA_COLORMAP); + new_impl = private->impl; + + private->impl = old_impl; + change_impl (private, private, new_impl); + + /* Native window creation will put the native window topmost in the + * native parent, which may be wrong wrt other native windows in the + * non-native hierarchy, so restack */ + above = find_native_sibling_above (private->parent, private); + if (above) { - /* Create native window */ - - if (gdk_window_has_impl (private)) - /* Already has an impl, either native (ok) or - offscreen (not supported). Bail. */ - return; - - impl_window = gdk_window_get_impl_window (private); - if (impl_window->window_type == GDK_WINDOW_OFFSCREEN) - return; /* native in offscreens not supported */ - - screen = gdk_drawable_get_screen (window); - visual = gdk_drawable_get_visual (window); - - attributes.colormap = gdk_drawable_get_colormap (window); - - old_impl = private->impl; - _gdk_window_impl_new (window, (GdkWindow *)private->parent, screen, visual, - get_native_event_mask (private), &attributes, GDK_WA_COLORMAP); - new_impl = private->impl; - - private->impl = old_impl; - change_impl (private, private, new_impl); - - /* Native window creation will put the native window topmost in the - * native parent, which may be wrong wrt other native windows in the - * non-native hierarchy, so restack */ - above = find_native_sibling_above (private->parent, private); - if (above) - { - listhead.data = window; - listhead.prev = NULL; - listhead.next = NULL; - GDK_WINDOW_IMPL_GET_IFACE (private->impl)->restack_under ((GdkWindow *)above, - &listhead); - } - - recompute_visible_regions (private, FALSE, FALSE); - - /* The shape may not have been set, as the clip region doesn't actually - change, so do it here manually */ - GDK_WINDOW_IMPL_GET_IFACE (private->impl)->shape_combine_region ((GdkWindow *)private, private->clip_region, 0, 0); - - reparent_to_impl (private); - - if (!private->input_only) - { - GDK_WINDOW_IMPL_GET_IFACE (private->impl)->set_background (window, &private->bg_color); - if (private->bg_pixmap != NULL) - GDK_WINDOW_IMPL_GET_IFACE (private->impl)->set_back_pixmap (window, private->bg_pixmap); - } - - GDK_WINDOW_IMPL_GET_IFACE (private->impl)->input_shape_combine_region ((GdkWindow *)private, private->input_shape, 0, 0); - - if (gdk_window_is_viewable (window)) - GDK_WINDOW_IMPL_GET_IFACE (private->impl)->show (window); + listhead.data = window; + listhead.prev = NULL; + listhead.next = NULL; + GDK_WINDOW_IMPL_GET_IFACE (private->impl)->restack_under ((GdkWindow *)above, + &listhead); } - else + + recompute_visible_regions (private, FALSE, FALSE); + + /* The shape may not have been set, as the clip region doesn't actually + change, so do it here manually */ + GDK_WINDOW_IMPL_GET_IFACE (private->impl)->shape_combine_region ((GdkWindow *)private, private->clip_region, 0, 0); + + reparent_to_impl (private); + + if (!private->input_only) { - /* Remove native window */ - - if (!gdk_window_has_impl (private)) - return; /* Not native, can't remove */ - - if (private->window_type == GDK_WINDOW_OFFSCREEN) - return; /* Not native, can't remove */ - - if (private->parent == NULL || - GDK_WINDOW_TYPE (private->parent) == GDK_WINDOW_ROOT) - return; /* toplevel, must be native */ - - g_warning ("Tried to turn native window to client side window, this is not supported yet."); - - /* TODO: remove native */ + GDK_WINDOW_IMPL_GET_IFACE (private->impl)->set_background (window, &private->bg_color); + if (private->bg_pixmap != NULL) + GDK_WINDOW_IMPL_GET_IFACE (private->impl)->set_back_pixmap (window, private->bg_pixmap); } + + GDK_WINDOW_IMPL_GET_IFACE (private->impl)->input_shape_combine_region ((GdkWindow *)private, private->input_shape, 0, 0); + + if (gdk_window_is_viewable (window)) + GDK_WINDOW_IMPL_GET_IFACE (private->impl)->show (window); } static void @@ -1891,7 +1872,7 @@ gdk_window_add_filter (GdkWindow *window, /* Filters are for the native events on the native window, so ensure there is a native window. */ if (window) - gdk_window_set_has_native (window, TRUE); + gdk_window_ensure_native (window); if (private) tmp_list = private->filters; @@ -4348,7 +4329,7 @@ gdk_window_real_set_colormap (GdkDrawable *drawable, /* different colormap than parent, requires native window */ if (!private->input_only && cmap != gdk_drawable_get_colormap ((GdkDrawable *)(private->parent))) - gdk_window_set_has_native ((GdkWindow *)drawable, TRUE); + gdk_window_ensure_native ((GdkWindow *)drawable); gdk_drawable_set_colormap (private->impl, cmap); } @@ -7560,7 +7541,7 @@ gdk_window_set_composited (GdkWindow *window, return; if (composited) - gdk_window_set_has_native (window, TRUE); + gdk_window_ensure_native (window); display = gdk_drawable_get_display (GDK_DRAWABLE (window)); diff --git a/gdk/x11/gdkdrawable-x11.c b/gdk/x11/gdkdrawable-x11.c index 90d5c9e8a1..2b9b1d2c4e 100644 --- a/gdk/x11/gdkdrawable-x11.c +++ b/gdk/x11/gdkdrawable-x11.c @@ -915,7 +915,7 @@ gdk_x11_drawable_get_xid (GdkDrawable *drawable) /* Try to ensure the window has a native window */ if (!_gdk_window_has_impl (window)) { - gdk_window_set_has_native (window, TRUE); + gdk_window_ensure_native (window); /* We sync here to ensure the window is created in the Xserver when * this function returns. This is required because the returned XID diff --git a/gdk/x11/gdkmain-x11.c b/gdk/x11/gdkmain-x11.c index 08c7cffb4f..1e7d04b6f7 100644 --- a/gdk/x11/gdkmain-x11.c +++ b/gdk/x11/gdkmain-x11.c @@ -206,7 +206,7 @@ gdk_pointer_grab (GdkWindow * window, /* We need a native window for confine to to work, ensure we have one */ if (confine_to) - gdk_window_set_has_native (confine_to, TRUE); + gdk_window_ensure_native (confine_to, TRUE); /* TODO: What do we do for offscreens and their children? We need to proxy the grab somehow */ if (!GDK_IS_WINDOW_IMPL_X11 (GDK_WINDOW_OBJECT (native)->impl)) diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c index 4d38fcbc47..afe65f3cf6 100644 --- a/gdk/x11/gdkwindow-x11.c +++ b/gdk/x11/gdkwindow-x11.c @@ -5366,8 +5366,8 @@ gdk_window_enable_synchronized_configure (GdkWindow *window) { /* This basically means you want to do fancy X specific stuff, so ensure we have a native window */ - gdk_window_set_has_native (window, TRUE); - + gdk_window_ensure_native (window, TRUE); + impl->use_synchronized_configure = TRUE; ensure_sync_counter (window); } diff --git a/tests/testwindows.c b/tests/testwindows.c index 37bd74049a..c6543c6596 100644 --- a/tests/testwindows.c +++ b/tests/testwindows.c @@ -368,7 +368,7 @@ parse_window (GdkWindow *parent, char **lines) color.blue = b; window = create_window (parent, x, y, w, h, &color); if (native) - gdk_window_set_has_native (window, TRUE); + gdk_window_ensure_native (window); for (i = 0; i < n_children; i++) lines = parse_window (window, lines); @@ -692,7 +692,7 @@ native_window_clicked (GtkWidget *button, { window = l->data; - gdk_window_set_has_native (window, TRUE); + gdk_window_ensure_native (window, TRUE); } g_list_free (selected);