#!/usr/bin/python

from gi.repository import Gtk, GLib, GdkPixbuf

def get_child_position(overlay, widget, allocation, user_data=None):
    # Match the parent allocation
    overlay_allocation = overlay.get_allocation()

    print("Parent allocation: %dx%d@%d,%d" % (overlay_allocation.width, overlay_allocation.height,
        overlay_allocation.x, overlay_allocation.y))
    allocation.x = 0
    allocation.y = 0
    allocation.width = overlay_allocation.width
    allocation.height = overlay_allocation.height

    return True

def size_alloc(widget, alloc, user_data=None):
    print("Alloc: %dx%d@%d,%d" % (alloc.width,alloc.height,alloc.x,alloc.y))

def on_button_clicked(button, overlay):
    overlay_img = Gtk.Image.new_from_icon_name("weather-storm-symbolic", Gtk.IconSize.DIALOG)
    overlay_img.connect("size-allocate", size_alloc)
    overlay_img.show_all()
    overlay.add_overlay(overlay_img)

window = Gtk.Window()
overlay = Gtk.Overlay()
overlay_button  = Gtk.Button(label="Activate overlay")
overlay_button.connect("clicked", on_button_clicked, overlay)
overlay.add(overlay_button)
overlay.connect("get-child-position", get_child_position)
window.add(overlay)

window.set_default_size(300, 300)

window.show_all()
window.connect("delete-event", Gtk.main_quit)

Gtk.main()
