/* compile with "gcc `pkg-config --cflags --libs gtk+-2.0` gtk-shaped.c" or "gcc `pkg-config --cflags --libs gtk+-3.0` gtk-shaped.c" */

#include <gtk/gtk.h>

int main(int argc, char** argv)
{
	gtk_init(&argc, &argv);

	GtkWidget* window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
	g_signal_connect(G_OBJECT(window),"destroy",G_CALLBACK(gtk_main_quit),NULL);
	gtk_window_set_title(GTK_WINDOW(window),"shaped");

	GtkWidget* entry=gtk_entry_new();
	gtk_container_add(GTK_CONTAINER(window),entry);
	gtk_widget_grab_focus(entry);

	gtk_widget_show_all(window);

	GdkWindow* dw=gtk_widget_get_window(window);
	gtk_widget_realize(window);

	#ifdef GDK_VERSION_3_0
	cairo_region_t* r=cairo_region_create();
	#else
	GdkRegion* r=gdk_region_new();
	#endif

	#ifdef GDK_VERSION_3_0
	cairo_rectangle_int_t rect
	#else
	GdkRectangle rect
	#endif
	={0, 0, gdk_window_get_width(dw)/2, gdk_window_get_height(dw)};

	#ifdef GDK_VERSION_3_0
	cairo_region_union_rectangle(r, &rect);
	#else
	gdk_region_union_with_rect(r, &rect);
	#endif

	gdk_window_shape_combine_region(dw, r, 0, 0);
	#ifdef GDK_VERSION_3_0
	/* uncomment to test input-only shaping under GTK3 */
	/* gdk_window_input_shape_combine_region(dw, r, 0, 0); */
	#endif

	gtk_main();

	return 0;
}
