kov changed libgksu/branches/libgksu2/libgksu/ChangeLog, libgksu/branches/libgksu2/libgksu/libgksu.c

Gustavo Noronha kov at costa.debian.org
Sun Apr 23 15:23:10 UTC 2006


Mensagem de log: 
only print password when on debug mode


-----


Modified: libgksu/branches/libgksu2/libgksu/ChangeLog
===================================================================
--- libgksu/branches/libgksu2/libgksu/ChangeLog	2006-04-23 15:16:02 UTC (rev 552)
+++ libgksu/branches/libgksu2/libgksu/ChangeLog	2006-04-23 15:23:09 UTC (rev 553)
@@ -1,6 +1,9 @@
 2006-04-23  Gustavo Noronha Silva  <kov at debian.org>
 
 	* libgksu.c:
+	- only print the password when on debug mode
+
+	* libgksu.c:
 	- init sn_context with NULL, so non-SN-supporting users will
 	  not segfault when we check for the value
 

Modified: libgksu/branches/libgksu2/libgksu/libgksu.c
===================================================================
--- libgksu/branches/libgksu2/libgksu/libgksu.c	2006-04-23 15:16:02 UTC (rev 552)
+++ libgksu/branches/libgksu2/libgksu/libgksu.c	2006-04-23 15:23:09 UTC (rev 553)
@@ -146,6 +146,324 @@
    return FD;
 }
 
+/*
+ * code 'stolen' from gnome-session's logout.c
+ *
+ * Written by Owen Taylor <otaylor at redhat.com>
+ * Copyright (C) Red Hat
+ */
+typedef struct {
+  GdkScreen    *screen;
+  int           monitor;
+  GdkRectangle  area;
+  int           rowstride;
+  GdkWindow    *root_window;
+  GdkWindow    *draw_window;
+  GdkPixbuf    *start_pb, *end_pb, *frame;
+  guchar       *start_p, *end_p, *frame_p;
+  GTimeVal      start_time;
+  GdkGC        *gc;
+} FadeoutData;
+
+FadeoutData *fade_data = NULL;
+static GList *fadeout_windows = NULL;
+
+#define FADE_DURATION 500.0
+
+int
+gsm_screen_get_width (GdkScreen *screen,
+		      int        monitor)
+{
+	GdkRectangle geometry;
+
+	gdk_screen_get_monitor_geometry (screen, monitor, &geometry);
+
+	return geometry.width;
+}
+
+int
+gsm_screen_get_height (GdkScreen *screen,
+		       int        monitor)
+{
+	GdkRectangle geometry;
+
+	gdk_screen_get_monitor_geometry (screen, monitor, &geometry);
+
+	return geometry.height;
+}
+
+int
+gsm_screen_get_x (GdkScreen *screen,
+		  int        monitor)
+{
+	GdkRectangle geometry;
+
+	gdk_screen_get_monitor_geometry (screen, monitor, &geometry);
+
+	return geometry.x;
+}
+
+int
+gsm_screen_get_y (GdkScreen *screen,
+		  int        monitor)
+{
+	GdkRectangle geometry;
+
+	gdk_screen_get_monitor_geometry (screen, monitor, &geometry);
+
+	return geometry.y;
+}
+
+static void
+get_current_frame (FadeoutData *fadeout,
+		   double    sat)
+{
+  guchar *sp, *ep, *fp;
+  int i, j, width, offset;
+
+  width = fadeout->area.width * 3;
+  offset = 0;
+
+  for (i = 0; i < fadeout->area.height; i++)
+    {
+      sp = fadeout->start_p + offset;
+      ep = fadeout->end_p   + offset;
+      fp = fadeout->frame_p + offset;
+
+      for (j = 0; j < width; j += 3)
+	{
+	  guchar r = abs (*(sp++) - ep[0]);
+	  guchar g = abs (*(sp++) - ep[1]);
+	  guchar b = abs (*(sp++) - ep[2]);
+
+	  *(fp++) = *(ep++) + r * sat;
+	  *(fp++) = *(ep++) + g * sat;
+	  *(fp++) = *(ep++) + b * sat;
+	}
+
+      offset += fadeout->rowstride;
+    }
+}
+
+static void
+darken_pixbuf (GdkPixbuf *pb)
+{
+  int width, height, rowstride;
+  int i, j;
+  guchar *p, *pixels;
+
+  width     = gdk_pixbuf_get_width (pb) * 3;
+  height    = gdk_pixbuf_get_height (pb);
+  rowstride = gdk_pixbuf_get_rowstride (pb);
+  pixels    = gdk_pixbuf_get_pixels (pb);
+
+  for (i = 0; i < height; i++)
+    {
+      p = pixels + (i * rowstride);
+      for (j = 0; j < width; j++)
+	p [j] >>= 1;
+    }
+}
+
+static gboolean
+fadeout_callback (FadeoutData *fadeout)
+{
+  GTimeVal current_time;
+  double elapsed, percent;
+
+  g_get_current_time (&current_time);
+  elapsed = ((((double)current_time.tv_sec - fadeout->start_time.tv_sec) * G_USEC_PER_SEC +
+	      (current_time.tv_usec - fadeout->start_time.tv_usec))) / 1000.0;
+
+  if (elapsed < 0)
+    {
+      g_warning ("System clock seemed to go backwards?");
+      elapsed = G_MAXDOUBLE;
+    }
+
+  if (elapsed > FADE_DURATION)
+    {
+      gdk_draw_pixbuf (fadeout->draw_window,
+		       fadeout->gc,
+		       fadeout->end_pb,
+		       0, 0,
+		       0, 0,
+		       fadeout->area.width,
+		       fadeout->area.height,
+		       GDK_RGB_DITHER_NONE,
+		       0, 0);
+
+      return FALSE;
+    }
+
+  percent = elapsed / FADE_DURATION;
+
+  get_current_frame (fadeout, 1.0 - percent);
+  gdk_draw_pixbuf (fadeout->draw_window,
+		   fadeout->gc,
+		   fadeout->frame,
+		   0, 0,
+		   0, 0,
+		   fadeout->area.width,
+		   fadeout->area.height,
+		   GDK_RGB_DITHER_NONE,
+		   0, 0);
+
+  gdk_flush ();
+
+  return TRUE;
+}
+
+static void
+hide_fadeout_windows (void)
+{
+  GList *l;
+
+  for (l = fadeout_windows; l; l = l->next)
+    {
+      gdk_window_hide (GDK_WINDOW (l->data));
+      g_object_unref (l->data);
+    }
+
+  g_list_free (fadeout_windows);
+  fadeout_windows = NULL;
+}
+
+static gboolean
+fadein_callback (FadeoutData *fadeout)
+{
+  GTimeVal current_time;
+  double elapsed, percent;
+
+  g_get_current_time (&current_time);
+  elapsed = ((((double)current_time.tv_sec - fadeout->start_time.tv_sec) * G_USEC_PER_SEC +
+	      (current_time.tv_usec - fadeout->start_time.tv_usec))) / 1000.0;
+
+  if (elapsed < 0)
+    {
+      g_warning ("System clock seemed to go backwards?");
+      elapsed = G_MAXDOUBLE;
+    }
+
+  if (elapsed > FADE_DURATION)
+    {
+      gdk_draw_pixbuf (fadeout->draw_window,
+		       fadeout->gc,
+		       fadeout->end_pb,
+		       0, 0,
+		       0, 0,
+		       fadeout->area.width,
+		       fadeout->area.height,
+		       GDK_RGB_DITHER_NONE,
+		       0, 0);
+
+      g_object_unref (fadeout->gc);
+      g_object_unref (fadeout->start_pb);
+      g_object_unref (fadeout->end_pb);
+      g_object_unref (fadeout->frame);
+
+      g_free (fadeout);
+
+      hide_fadeout_windows ();
+
+      return FALSE;
+    }
+
+  percent = elapsed / FADE_DURATION;
+
+  get_current_frame (fadeout, percent);
+  gdk_draw_pixbuf (fadeout->draw_window,
+		   fadeout->gc,
+		   fadeout->frame,
+		   0, 0,
+		   0, 0,
+		   fadeout->area.width,
+		   fadeout->area.height,
+		   GDK_RGB_DITHER_NONE,
+		   0, 0);
+
+  gdk_flush ();
+
+  return TRUE;
+}
+
+static void
+fadeout_screen (GdkScreen *screen,
+		int        monitor)
+{
+  GdkWindowAttr attr;
+  int attr_mask;
+  GdkGCValues values;
+  FadeoutData *fadeout;
+
+  fadeout = g_new (FadeoutData, 1);
+
+  fadeout->screen = screen;
+  fadeout->monitor = monitor;
+
+  fadeout->area.x = gsm_screen_get_x (screen, monitor);
+  fadeout->area.y = gsm_screen_get_y (screen, monitor);
+  fadeout->area.width = gsm_screen_get_width (screen, monitor);
+  fadeout->area.height = gsm_screen_get_height (screen, monitor);
+
+  fadeout->root_window = gdk_screen_get_root_window (screen);
+  attr.window_type = GDK_WINDOW_CHILD;
+  attr.x = fadeout->area.x;
+  attr.y = fadeout->area.y;
+  attr.width = fadeout->area.width;
+  attr.height = fadeout->area.height;
+  attr.wclass = GDK_INPUT_OUTPUT;
+  attr.visual = gdk_screen_get_system_visual (fadeout->screen);
+  attr.colormap = gdk_screen_get_default_colormap (fadeout->screen);
+  attr.override_redirect = TRUE;
+  attr_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP | GDK_WA_NOREDIR;
+
+  fadeout->draw_window = gdk_window_new (fadeout->root_window, &attr, attr_mask);
+  fadeout_windows = g_list_prepend (fadeout_windows, fadeout->draw_window);
+
+  fadeout->start_pb = gdk_pixbuf_get_from_drawable (NULL,
+						    fadeout->root_window,
+						    NULL,
+						    fadeout->area.x,
+						    fadeout->area.y,
+						    0, 0,
+						    fadeout->area.width,
+						    fadeout->area.height);
+
+  fadeout->end_pb = gdk_pixbuf_copy (fadeout->start_pb);
+  darken_pixbuf (fadeout->end_pb);
+
+  fadeout->frame = gdk_pixbuf_copy (fadeout->start_pb);
+  fadeout->rowstride = gdk_pixbuf_get_rowstride (fadeout->start_pb);
+
+  fadeout->start_p = gdk_pixbuf_get_pixels (fadeout->start_pb);
+  fadeout->end_p   = gdk_pixbuf_get_pixels (fadeout->end_pb);
+  fadeout->frame_p = gdk_pixbuf_get_pixels (fadeout->frame);
+
+  values.subwindow_mode = GDK_INCLUDE_INFERIORS;
+
+  fadeout->gc = gdk_gc_new_with_values (fadeout->root_window, &values, GDK_GC_SUBWINDOW);
+
+  gdk_window_set_back_pixmap (fadeout->draw_window, NULL, FALSE);
+  gdk_window_show (fadeout->draw_window);
+  gdk_draw_pixbuf (fadeout->draw_window,
+		   fadeout->gc,
+		   fadeout->frame,
+		   0, 0,
+		   0, 0,
+		   fadeout->area.width,
+		   fadeout->area.height,
+		   GDK_RGB_DITHER_NONE,
+		   0, 0);
+
+  g_get_current_time (&fadeout->start_time);
+  g_idle_add ((GSourceFunc) fadeout_callback, fadeout);
+
+  fade_data = fadeout;
+}
+
+/* End of 'stolen' code */
+
 #define GRAB_TRIES	16
 #define GRAB_WAIT	250 /* milliseconds */
 
@@ -218,6 +536,7 @@
     g_warning ("Unable to create lock file.");
   g_free (fname);
 
+  fadeout_screen (gdk_screen_get_default (), 0);
   gtk_widget_show_all (dialog);
 
   /* reset cursor */
@@ -233,6 +552,8 @@
       if (++grab_tries > GRAB_TRIES)
 	{
 	  gtk_widget_hide (dialog);
+	  g_get_current_time (&fade_data->start_time);
+	  while (fadein_callback (fade_data) != FALSE);
 	  report_failed_grab (FAILED_GRAB_MOUSE);
 	  exit (1);
 	  break;
@@ -251,6 +572,8 @@
       if (++grab_tries > GRAB_TRIES)
 	{
 	  gtk_widget_hide (dialog);
+	  g_get_current_time (&fade_data->start_time);
+	  while (fadein_callback (fade_data) != FALSE);
 	  report_failed_grab (FAILED_GRAB_KEYBOARD);
 	  exit (1);
 	  break;
@@ -277,6 +600,9 @@
   gdk_keyboard_ungrab(GDK_CURRENT_TIME);
   gdk_flush();
 
+  g_get_current_time (&fade_data->start_time);
+  while (fadein_callback (fade_data) != FALSE);
+
   close(lock);
 }
 
@@ -1279,7 +1605,8 @@
 
 	      /* try to get the password from the GNOME Keyring first */
 	      tmp = get_gnome_keyring_password (context);
-	      fprintf (stderr, "tmp: %s\n", tmp);
+	      if (context->debug)
+		fprintf (stderr, "tmp: %s\n", tmp);
 	      if (tmp == NULL)
 		tmp = ask_pass (context, buf, ask_pass_data, error);
 




More information about the gksu-commits mailing list