summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorOlivier Fourdan <ofourdan@redhat.com>2015-12-21 14:35:53 +0100
committerOlivier Fourdan <ofourdan@redhat.com>2016-01-08 10:33:26 +0100
commit28f011eb055673d8944cd6e012bc5d84bae41a26 (patch)
treef0e0e977653e30763e19471920f7b656b3b0e15a /tests
parentd85b3fc60dcf09d4703b30bef676af93ef6ed6cd (diff)
downloadgtk+-28f011eb055673d8944cd6e012bc5d84bae41a26.tar.gz
wayland: prefer subsurface when possible
Quite a few applications use GTK_WINDOW_POPUP to create various temporary windows and place then on screen. That works fine on X11 but on Wayland there is no global coordinate system for regular surfaces. If the application is using a gdk temp window and set a parent with gtk_window_transient_for(), the gdk wayland backend has all it needs to create a subsurface that can be placed at will by the application. Bugzilla: https://bugzilla.gnome.org/show_bug.cgi?id=759738
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/testpopup.c68
2 files changed, 69 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f2123d97db..85d06bae6c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -170,6 +170,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
gdkgears \
listmodel \
foreigndrawing \
+ testpopup \
$(NULL)
if USE_X11
diff --git a/tests/testpopup.c b/tests/testpopup.c
new file mode 100644
index 0000000000..cd82468c49
--- /dev/null
+++ b/tests/testpopup.c
@@ -0,0 +1,68 @@
+#include <gtk/gtk.h>
+
+static gboolean
+draw_popup (GtkWidget *widget,
+ cairo_t *cr,
+ gpointer data)
+{
+ cairo_set_source_rgb (cr, 1, 0, 0);
+ cairo_paint (cr);
+
+ return FALSE;
+}
+
+static gboolean
+place_popup (GtkWidget *parent,
+ GdkEvent *event,
+ GtkWidget *popup)
+{
+ GdkEventMotion *ev_motion = (GdkEventMotion *) event;
+ gint width, height;
+
+ gtk_window_get_size (GTK_WINDOW (popup), &width, &height);
+ gtk_window_move (GTK_WINDOW (popup),
+ (int) ev_motion->x_root - width / 2,
+ (int) ev_motion->y_root - height / 2);
+
+ return FALSE;
+}
+
+static gboolean
+on_map_event (GtkWidget *parent,
+ GdkEvent *event,
+ gpointer data)
+{
+ GtkWidget *popup;
+
+ popup = gtk_window_new (GTK_WINDOW_POPUP);
+
+ gtk_widget_set_size_request (GTK_WIDGET (popup), 20, 20);
+ gtk_widget_set_app_paintable (GTK_WIDGET (popup), TRUE);
+ gtk_window_set_transient_for (GTK_WINDOW (popup), GTK_WINDOW (parent));
+ g_signal_connect (popup, "draw", G_CALLBACK (draw_popup), NULL);
+ g_signal_connect (parent, "motion-notify-event", G_CALLBACK (place_popup), popup);
+
+ gtk_widget_show (popup);
+
+ return FALSE;
+}
+
+int
+main (int argc, char *argv[])
+{
+ GtkWidget *window;
+
+ gtk_init (&argc, &argv);
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ gtk_widget_set_events (window, GDK_POINTER_MOTION_MASK);
+ g_signal_connect (window, "destroy", gtk_main_quit, NULL);
+ g_signal_connect (window, "map-event", G_CALLBACK (on_map_event), NULL);
+
+ gtk_widget_show (window);
+
+ gtk_main ();
+
+ return 0;
+}