summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2014-09-17 11:09:52 -0400
committerMatthias Clasen <mclasen@redhat.com>2014-09-17 11:10:41 -0400
commit6e0960197fcdb69f8c522437b2a5df51ecd75588 (patch)
tree144a4ba1a52b97fb19605981d91a1424d4a3d131 /tests
parentc104c6443624f2064e0fcef5ab33548c29f4bac5 (diff)
downloadgtk+-6e0960197fcdb69f8c522437b2a5df51ecd75588.tar.gz
Add a quick subsurface tests
Just to have some code that uses subsurfaces inside a widget tree, and not like a 'pseudo-toplevel'.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/subsurface.c110
2 files changed, 111 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 374fddb2a5..f4b84c8a25 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -25,6 +25,7 @@ testsocket_programs = testsocket testsocket_child
endif
noinst_PROGRAMS = $(TEST_PROGS) \
+ subsurface \
animated-resizing \
motion-compression \
scrolling-performance \
diff --git a/tests/subsurface.c b/tests/subsurface.c
new file mode 100644
index 0000000000..bfd0ea79d8
--- /dev/null
+++ b/tests/subsurface.c
@@ -0,0 +1,110 @@
+#include <gtk/gtk.h>
+
+
+static void da_realize (GtkWidget *widget);
+static void da_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+static gboolean da_draw (GtkWidget *widget,
+ cairo_t *cr);
+
+typedef GtkDrawingArea DArea;
+typedef GtkDrawingAreaClass DAreaClass;
+
+G_DEFINE_TYPE (DArea, da, GTK_TYPE_WIDGET)
+
+static void
+da_class_init (DAreaClass *class)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+ widget_class->realize = da_realize;
+ widget_class->size_allocate = da_size_allocate;
+ widget_class->draw = da_draw;
+}
+
+static void
+da_init (DArea *darea)
+{
+ gtk_widget_set_has_window (GTK_WIDGET (darea), TRUE);
+}
+
+GtkWidget*
+da_new (void)
+{
+ return g_object_new (da_get_type (), NULL);
+}
+
+static void
+da_realize (GtkWidget *widget)
+{
+ GtkAllocation allocation;
+ GdkWindow *window;
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+
+ gtk_widget_set_realized (widget, TRUE);
+
+ gtk_widget_get_allocation (widget, &allocation);
+
+ attributes.window_type = GDK_WINDOW_SUBSURFACE;
+ attributes.x = allocation.x;
+ attributes.y = allocation.y;
+ attributes.width = allocation.width;
+ attributes.height = allocation.height;
+ attributes.wclass = GDK_INPUT_OUTPUT;
+ attributes.visual = gtk_widget_get_visual (widget);
+ attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
+
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
+
+ window = gdk_window_new (gtk_widget_get_parent_window (widget),
+ &attributes, attributes_mask);
+ gtk_widget_register_window (widget, window);
+ gtk_widget_set_window (widget, window);
+}
+
+static void
+da_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ gtk_widget_set_allocation (widget, allocation);
+
+ if (gtk_widget_get_realized (widget))
+ gdk_window_move_resize (gtk_widget_get_window (widget),
+ allocation->x, allocation->y,
+ allocation->width, allocation->height);
+}
+
+static gboolean
+da_draw (GtkWidget *widget,
+ cairo_t *cr)
+{
+ cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
+ cairo_paint (cr);
+
+ return TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+ GtkWidget *window, *label, *box, *widget;
+
+ gtk_init (NULL, NULL);
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_resizable (GTK_WINDOW (window), TRUE);
+ box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+
+ gtk_container_add (GTK_CONTAINER (window), box);
+ label = gtk_label_new ("Test test");
+ gtk_container_add (GTK_CONTAINER (box), label);
+ widget = da_new ();
+ gtk_widget_set_size_request (widget, 100, 100);
+ gtk_container_add (GTK_CONTAINER (box), widget);
+ gtk_widget_show_all (window);
+
+ gtk_main ();
+
+ return 0;
+}