kov changed libgksu/branches/composited/libgksu/libgksu.c

Gustavo Noronha kov at costa.debian.org
Sun Oct 15 02:49:05 UTC 2006


Mensagem de log: 
initial implementation of composited drawing of the background window hiding
all the desktop


-----


Modified: libgksu/branches/composited/libgksu/libgksu.c
===================================================================
--- libgksu/branches/composited/libgksu/libgksu.c	2006-10-15 01:55:44 UTC (rev 739)
+++ libgksu/branches/composited/libgksu/libgksu.c	2006-10-15 02:49:05 UTC (rev 740)
@@ -52,6 +52,10 @@
 #include "libgksu.h"
 #include "../libgksuui/gksuui-dialog.h"
 
+/* the window that hides the other applications and the
+   background */
+GtkWidget *background_window = NULL;
+
 GType
 gksu_error_get_type (void)
 {
@@ -150,6 +154,25 @@
    return FD;
 }
 
+static gboolean
+is_screen_composited (GdkScreen *screen)
+{
+  static gboolean response_cached = FALSE;
+  static gboolean is_composited = FALSE;
+
+  printf ("(before) Composited: %d\n", is_composited);
+
+  if (response_cached)
+    return is_composited;
+
+  is_composited = gdk_screen_is_composited (screen);
+  response_cached = TRUE;
+
+  printf ("(after) Composited: %d\n", is_composited);
+
+  return is_composited;
+}
+
 /*
  * code 'stolen' from gnome-session's logout.c
  *
@@ -468,6 +491,59 @@
 
 /* End of 'stolen' code */
 
+static gboolean
+expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer userdata)
+{
+  cairo_t *cr = NULL;
+
+  cr = gdk_cairo_create(widget->window);
+
+  cairo_set_source_rgba (cr, 0.8, 0.8, 0.8, 0.7);
+  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+  cairo_paint (cr);
+
+  return TRUE;
+}
+
+static void
+draw_background ()
+{
+  if (background_window == NULL)
+    {
+      GdkScreen *screen;
+
+      background_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+      gtk_window_set_title (GTK_WINDOW(background_window), "");
+      gtk_window_set_decorated(GTK_WINDOW(background_window), FALSE);
+      gtk_window_fullscreen (GTK_WINDOW(background_window));
+      gtk_widget_set_app_paintable (background_window, TRUE);
+      g_signal_connect(G_OBJECT(background_window), "realize",
+		       G_CALLBACK(expose_cb), NULL);
+      g_signal_connect(G_OBJECT(background_window), "expose-event",
+		       G_CALLBACK(expose_cb), NULL);
+
+      screen = gtk_widget_get_screen (background_window);
+      gtk_widget_set_colormap (background_window,
+			       gdk_screen_get_rgba_colormap(screen));
+
+      //gtk_widget_realize (background_window);
+      //expose_cb (background_window, NULL, NULL);
+    }
+
+  gtk_widget_show_all (background_window);
+
+}
+
+static void
+destroy_background ()
+{
+  if (background_window)
+    {
+      gtk_widget_destroy (background_window);
+      background_window = NULL;
+    }
+}
+
 #define GRAB_TRIES	16
 #define GRAB_WAIT	250 /* milliseconds */
 
@@ -544,7 +620,11 @@
     g_warning ("Unable to create lock file.");
   g_free (fname);
 
-  fadeout_screen (gdk_screen_get_default (), 0);
+  if (is_screen_composited (gdk_screen_get_default ()) == FALSE)
+    fadeout_screen (gdk_screen_get_default (), 0);
+  else
+    draw_background ();
+
   gtk_widget_show_all (dialog);
 
   /* reset cursor */
@@ -560,8 +640,13 @@
       if (++grab_tries > GRAB_TRIES)
 	{
 	  gtk_widget_hide (dialog);
-	  g_get_current_time (&fade_data->start_time);
-	  while (fadein_callback (fade_data) != FALSE);
+	  if (is_screen_composited (gdk_screen_get_default ()) == FALSE)
+	    {
+	      g_get_current_time (&fade_data->start_time);
+	      while (fadein_callback (fade_data) != FALSE);
+	    }
+	  else
+	    destroy_background ();
 	  report_failed_grab (FAILED_GRAB_MOUSE);
 	  exit (1);
 	  break;
@@ -580,8 +665,13 @@
       if (++grab_tries > GRAB_TRIES)
 	{
 	  gtk_widget_hide (dialog);
-	  g_get_current_time (&fade_data->start_time);
-	  while (fadein_callback (fade_data) != FALSE);
+	  if (is_screen_composited (gdk_screen_get_default ()) == FALSE)
+	    {
+	      g_get_current_time (&fade_data->start_time);
+	      while (fadein_callback (fade_data) != FALSE);
+	    }
+	  else
+	    destroy_background ();
 	  report_failed_grab (FAILED_GRAB_KEYBOARD);
 	  exit (1);
 	  break;
@@ -608,8 +698,13 @@
   gdk_keyboard_ungrab(GDK_CURRENT_TIME);
   gdk_flush();
 
-  g_get_current_time (&fade_data->start_time);
-  while (fadein_callback (fade_data) != FALSE);
+  if (is_screen_composited (gdk_screen_get_default ()) == FALSE)
+    {
+      g_get_current_time (&fade_data->start_time);
+      while (fadein_callback (fade_data) != FALSE);
+    }
+  else
+    destroy_background ();
 
   close(lock);
 }




More information about the gksu-commits mailing list