gtkoverlay: Remove per-child windows

They are no longer necessary to do child positioning nor input
handling.
This commit is contained in:
Carlos Garnacho 2017-04-06 13:56:36 +02:00
parent e2c38ddc22
commit fe40abc636

View File

@ -64,7 +64,6 @@ typedef struct _GtkOverlayChild GtkOverlayChild;
struct _GtkOverlayChild struct _GtkOverlayChild
{ {
GtkWidget *widget; GtkWidget *widget;
GdkWindow *window;
gboolean pass_through; gboolean pass_through;
}; };
@ -91,11 +90,9 @@ G_DEFINE_TYPE_WITH_CODE (GtkOverlay, gtk_overlay, GTK_TYPE_BIN,
static void static void
gtk_overlay_compute_child_allocation (GtkOverlay *overlay, gtk_overlay_compute_child_allocation (GtkOverlay *overlay,
GtkOverlayChild *child, GtkOverlayChild *child,
GtkAllocation *window_allocation, GtkAllocation *widget_allocation)
GtkAllocation *widget_allocation)
{ {
gint left, right, top, bottom;
GtkAllocation allocation, overlay_allocation; GtkAllocation allocation, overlay_allocation;
gboolean result; gboolean result;
@ -107,51 +104,10 @@ gtk_overlay_compute_child_allocation (GtkOverlay *overlay,
allocation.x += overlay_allocation.x; allocation.x += overlay_allocation.x;
allocation.y += overlay_allocation.y; allocation.y += overlay_allocation.y;
/* put the margins outside the window; also arrange things widget_allocation->x = allocation.x;
* so that the adjusted child allocation still ends up at 0, 0 widget_allocation->y = allocation.y;
*/ widget_allocation->width = allocation.width;
left = gtk_widget_get_margin_start (child->widget); widget_allocation->height = allocation.height;
right = gtk_widget_get_margin_end (child->widget);
top = gtk_widget_get_margin_top (child->widget);
bottom = gtk_widget_get_margin_bottom (child->widget);
if (widget_allocation)
{
widget_allocation->x = - left;
widget_allocation->y = - top;
widget_allocation->width = allocation.width;
widget_allocation->height = allocation.height;
}
if (window_allocation)
{
window_allocation->x = allocation.x + left;
window_allocation->y = allocation.y + top;
window_allocation->width = allocation.width - (left + right);
window_allocation->height = allocation.height - (top + bottom);
}
}
static GdkWindow *
gtk_overlay_create_child_window (GtkOverlay *overlay,
GtkOverlayChild *child)
{
GtkWidget *widget = GTK_WIDGET (overlay);
GtkAllocation allocation;
GdkWindow *window;
gtk_overlay_compute_child_allocation (overlay, child, &allocation, NULL);
window = gdk_window_new_child (gtk_widget_get_window (widget),
GDK_ALL_EVENTS_MASK,
&allocation);
gtk_widget_register_window (widget, window);
gdk_window_set_pass_through (window, child->pass_through);
gtk_widget_set_parent_window (child->widget, window);
return window;
} }
static GtkAlign static GtkAlign
@ -281,30 +237,14 @@ static void
gtk_overlay_child_allocate (GtkOverlay *overlay, gtk_overlay_child_allocate (GtkOverlay *overlay,
GtkOverlayChild *child) GtkOverlayChild *child)
{ {
GtkAllocation window_allocation, child_allocation; GtkAllocation child_allocation;
if (gtk_widget_get_mapped (GTK_WIDGET (overlay)))
{
/* Note: This calls show every size allocation, which makes
* us keep the z-order of the chilren, as gdk_window_show()
* does an implicit raise. */
if (gtk_widget_get_visible (child->widget))
gdk_window_show (child->window);
else if (gdk_window_is_visible (child->window))
gdk_window_hide (child->window);
}
if (!gtk_widget_get_visible (child->widget)) if (!gtk_widget_get_visible (child->widget))
return; return;
gtk_overlay_compute_child_allocation (overlay, child, &window_allocation, &child_allocation); gtk_overlay_compute_child_allocation (overlay, child, &child_allocation);
if (child->window) gtk_overlay_child_update_style_classes (overlay, child->widget, &child_allocation);
gdk_window_move_resize (child->window,
window_allocation.x, window_allocation.y,
window_allocation.width, window_allocation.height);
gtk_overlay_child_update_style_classes (overlay, child->widget, &window_allocation);
gtk_widget_size_allocate (child->widget, &child_allocation); gtk_widget_size_allocate (child->widget, &child_allocation);
} }
@ -392,87 +332,6 @@ gtk_overlay_get_child_position (GtkOverlay *overlay,
return TRUE; return TRUE;
} }
static void
gtk_overlay_realize (GtkWidget *widget)
{
GtkOverlay *overlay = GTK_OVERLAY (widget);
GtkOverlayPrivate *priv = overlay->priv;
GtkOverlayChild *child;
GSList *children;
GTK_WIDGET_CLASS (gtk_overlay_parent_class)->realize (widget);
for (children = priv->children; children; children = children->next)
{
child = children->data;
if (child->window == NULL)
child->window = gtk_overlay_create_child_window (overlay, child);
}
}
static void
gtk_overlay_unrealize (GtkWidget *widget)
{
GtkOverlay *overlay = GTK_OVERLAY (widget);
GtkOverlayPrivate *priv = overlay->priv;
GtkOverlayChild *child;
GSList *children;
for (children = priv->children; children; children = children->next)
{
child = children->data;
gtk_widget_set_parent_window (child->widget, NULL);
gtk_widget_unregister_window (widget, child->window);
gdk_window_destroy (child->window);
child->window = NULL;
}
GTK_WIDGET_CLASS (gtk_overlay_parent_class)->unrealize (widget);
}
static void
gtk_overlay_map (GtkWidget *widget)
{
GtkOverlay *overlay = GTK_OVERLAY (widget);
GtkOverlayPrivate *priv = overlay->priv;
GtkOverlayChild *child;
GSList *children;
GTK_WIDGET_CLASS (gtk_overlay_parent_class)->map (widget);
for (children = priv->children; children; children = children->next)
{
child = children->data;
if (child->window != NULL &&
gtk_widget_get_visible (child->widget) &&
gtk_widget_get_child_visible (child->widget))
gdk_window_show (child->window);
}
}
static void
gtk_overlay_unmap (GtkWidget *widget)
{
GtkOverlay *overlay = GTK_OVERLAY (widget);
GtkOverlayPrivate *priv = overlay->priv;
GtkOverlayChild *child;
GSList *children;
for (children = priv->children; children; children = children->next)
{
child = children->data;
if (child->window != NULL &&
gdk_window_is_visible (child->window))
gdk_window_hide (child->window);
}
GTK_WIDGET_CLASS (gtk_overlay_parent_class)->unmap (widget);
}
static void static void
gtk_overlay_remove (GtkContainer *container, gtk_overlay_remove (GtkContainer *container,
GtkWidget *widget) GtkWidget *widget)
@ -490,12 +349,6 @@ gtk_overlay_remove (GtkContainer *container,
if (child->widget == widget) if (child->widget == widget)
{ {
if (child->window != NULL)
{
gtk_widget_unregister_window (GTK_WIDGET (container), child->window);
gdk_window_destroy (child->window);
}
gtk_widget_unparent (widget); gtk_widget_unparent (widget);
priv->children = g_slist_delete_link (priv->children, children); priv->children = g_slist_delete_link (priv->children, children);
@ -670,8 +523,7 @@ gtk_overlay_set_child_property (GtkContainer *container,
if (g_value_get_boolean (value) != child_info->pass_through) if (g_value_get_boolean (value) != child_info->pass_through)
{ {
child_info->pass_through = g_value_get_boolean (value); child_info->pass_through = g_value_get_boolean (value);
if (child_info->window) gtk_widget_set_pass_through (child, child_info->pass_through);
gdk_window_set_pass_through (child_info->window, child_info->pass_through);
gtk_container_child_notify (container, child, "pass-through"); gtk_container_child_notify (container, child, "pass-through");
} }
} }
@ -740,10 +592,6 @@ gtk_overlay_class_init (GtkOverlayClass *klass)
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass); GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
widget_class->size_allocate = gtk_overlay_size_allocate; widget_class->size_allocate = gtk_overlay_size_allocate;
widget_class->realize = gtk_overlay_realize;
widget_class->unrealize = gtk_overlay_unrealize;
widget_class->map = gtk_overlay_map;
widget_class->unmap = gtk_overlay_unmap;
container_class->remove = gtk_overlay_remove; container_class->remove = gtk_overlay_remove;
container_class->forall = gtk_overlay_forall; container_class->forall = gtk_overlay_forall;
@ -893,9 +741,6 @@ gtk_overlay_add_overlay (GtkOverlay *overlay,
priv->children = g_slist_append (priv->children, child); priv->children = g_slist_append (priv->children, child);
if (gtk_widget_get_realized (GTK_WIDGET (overlay)))
child->window = gtk_overlay_create_child_window (overlay, child);
gtk_widget_insert_before (widget, GTK_WIDGET (overlay), NULL); gtk_widget_insert_before (widget, GTK_WIDGET (overlay), NULL);
gtk_widget_child_notify (widget, "index"); gtk_widget_child_notify (widget, "index");