const Gtk = imports.gi.Gtk;

Gtk.init(null);

let w = new Gtk.Window();
w.set_default_size (200, 200);

function size_allocate(window) {
    let allocation = window.get_allocation();
    print('allocated to ' + allocation.width + 'x' + allocation.height);
}

w.connect('size-allocate', size_allocate);

let header = new Gtk.HeaderBar();
header.set_title("Maximize Me!");
header.show();
w.set_titlebar (header);

let da = new Gtk.DrawingArea();
da.show();
w.add(da);

function draw_contents(drawing_area, context) {
    print('paint');
    let allocation = drawing_area.get_allocation();
    context.setSourceRGB(1, 0, 0);
    context.moveTo(0,0);
    context.lineTo(allocation.width, allocation.height);
    context.stroke();
}

da.connect('draw', draw_contents);

w.show();

Gtk.main();
