[gtk+/layered-windows: 5/10] testwindows: Add code to test layered windows



commit ce532cb45d02660cd3a273a7b9b344185e141a00
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Dec 1 14:09:52 2011 +0100

    testwindows: Add code to test layered windows

 gdk/gdkwindow.h     |    4 +++
 tests/testwindows.c |   67 +++++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 58 insertions(+), 13 deletions(-)
---
diff --git a/gdk/gdkwindow.h b/gdk/gdkwindow.h
index 50779fe..58f98bd 100644
--- a/gdk/gdkwindow.h
+++ b/gdk/gdkwindow.h
@@ -580,6 +580,10 @@ gboolean gdk_window_get_composited (GdkWindow *window);
 void gdk_window_set_composited   (GdkWindow *window,
                                   gboolean   composited);
 
+gboolean gdk_window_get_layered (GdkWindow *window);
+void gdk_window_set_layered     (GdkWindow *window,
+				 gboolean   layered);
+
 /*
  * This routine allows you to merge (ie ADD) child shapes to your
  * own window's shape keeping its current shape and ADDING the child
diff --git a/tests/testwindows.c b/tests/testwindows.c
index a68f3bc..8b98d6c 100644
--- a/tests/testwindows.c
+++ b/tests/testwindows.c
@@ -15,12 +15,12 @@ static GtkWidget *main_window;
 GdkWindow *
 create_window (GdkWindow *parent,
 	       int x, int y, int w, int h,
-	       GdkColor *color)
+	       GdkRGBA *color)
 {
   GdkWindowAttr attributes;
   gint attributes_mask;
   GdkWindow *window;
-  GdkColor *bg;
+  GdkRGBA *bg;
 
   attributes.x = x;
   attributes.y = y;
@@ -41,17 +41,18 @@ create_window (GdkWindow *parent,
   window = gdk_window_new (parent, &attributes, attributes_mask);
   gdk_window_set_user_data (window, darea);
 
-  bg = g_new (GdkColor, 1);
+  bg = g_new (GdkRGBA, 1);
   if (color)
     *bg = *color;
   else
     {
-      bg->red = g_random_int_range (0, 0xffff);
-      bg->blue = g_random_int_range (0, 0xffff);
-      bg->green = g_random_int_range (0, 0xffff);;
+      bg->red = g_random_double ();
+      bg->blue = g_random_double ();
+      bg->green = g_random_double ();
+      bg->alpha = 0.5;
     }
   
-  gdk_window_set_background (window, bg);
+  gdk_window_set_background_rgba (window, bg);
   g_object_set_data_full (G_OBJECT (window), "color", bg, g_free);
   
   gdk_window_show (window);
@@ -238,17 +239,18 @@ save_window (GString *s,
 	     GdkWindow *window)
 {
   gint x, y;
-  GdkColor *color;
+  GdkRGBA *color;
 
   gdk_window_get_position (window, &x, &y);
   color = g_object_get_data (G_OBJECT (window), "color");
   
-  g_string_append_printf (s, "%d,%d %dx%d (%d,%d,%d) %d %d\n",
+  g_string_append_printf (s, "%d,%d %dx%d (%f,%f,%f) %d %d %d\n",
 			  x, y,
                           gdk_window_get_width (window),
                           gdk_window_get_height (window),
 			  color->red, color->green, color->blue,
 			  gdk_window_has_native (window),
+			  gdk_window_get_layered (window),
 			  g_list_length (gdk_window_peek_children (window)));
 
   save_children (s, window);
@@ -330,24 +332,27 @@ destroy_children (GdkWindow *window)
 static char **
 parse_window (GdkWindow *parent, char **lines)
 {
-  int x, y, w, h, r, g, b, native, n_children;
+  int x, y, w, h, native, n_children, layered;
+  double r, g, b;
   GdkWindow *window;
-  GdkColor color;
+  GdkRGBA color;
   int i;
 
   if (*lines == NULL)
     return lines;
   
-  if (sscanf(*lines, "%d,%d %dx%d (%d,%d,%d) %d %d",
-	     &x, &y, &w, &h, &r, &g, &b, &native, &n_children) == 9)
+  if (sscanf(*lines, "%d,%d %dx%d (%lf,%lf,%lf) %d %d %d",
+	     &x, &y, &w, &h, &r, &g, &b, &native, &layered, &n_children) == 10)
     {
       lines++;
       color.red = r;
       color.green = g;
       color.blue = b;
+      color.alpha = 0.5;
       window = create_window (parent, x, y, w, h, &color);
       if (native)
 	gdk_window_ensure_native (window);
+      gdk_window_set_layered (window, layered);
       
       for (i = 0; i < n_children; i++)
 	lines = parse_window (window, lines);
@@ -685,6 +690,28 @@ native_window_clicked (GtkWidget *button,
   update_store ();
 }
 
+static void
+layered_clicked (GtkWidget *button, 
+		 gpointer data)
+{
+  GList *selected, *l;
+  GdkWindow *window;
+
+  selected = get_selected_windows ();
+
+  for (l = selected; l != NULL; l = l->next)
+    {
+      window = l->data;
+      
+      gdk_window_set_layered (window, GPOINTER_TO_INT (data));
+    }
+  
+  g_list_free (selected);
+  
+  update_store ();
+}
+
+
 static gboolean
 darea_button_release_event (GtkWidget *widget,
 			    GdkEventButton *event)
@@ -956,6 +983,20 @@ main (int argc, char **argv)
   gtk_grid_attach (GTK_GRID (grid), button, 3, 2, 1, 1);
   gtk_widget_show (button);
 
+  button = gtk_button_new_with_label ("Layered");
+  g_signal_connect (button, "clicked",
+		    G_CALLBACK (layered_clicked),
+		    GINT_TO_POINTER (1));
+  gtk_grid_attach (GTK_GRID (grid), button, 0, 3, 1, 1);
+  gtk_widget_show (button);
+
+  button = gtk_button_new_with_label ("Non-Layered");
+  g_signal_connect (button, "clicked",
+		    G_CALLBACK (layered_clicked),
+		    GINT_TO_POINTER (0));
+  gtk_grid_attach (GTK_GRID (grid), button, 1, 3, 1, 1);
+  gtk_widget_show (button);
+
   button = gtk_button_new_with_label ("Restack above");
   g_signal_connect (button, "clicked",
 		    G_CALLBACK (restack_clicked),



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]