From 98c6971ced389996a99335e1b926b56c1c1e5911 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Guelfucci?= <jeromeg@xfce.org>
Date: Mon, 3 Aug 2009 11:57:13 +0200
Subject: [PATCH] Reenable the old active window workaround.

In some cases, the WM/X server does not update the active window
quickly enough. When running the application and taking a screenshot
of the active window this can create a corrupted screenshot. Adding
a one second delay in that case fixes this issue.
---
 ChangeLog                   |  9 +++++++++
 lib/screenshooter-actions.c |  6 ++++--
 lib/screenshooter-capture.c | 12 ++++++++++--
 lib/screenshooter-capture.h |  7 ++++---
 4 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a2e66a8a..1311baba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,15 @@ Updated Italian and Galician documentation translation.
 
 2009-08-03 jeromeg
 
+Reenable the old active window workaround.
+
+In some cases, the WM/X server does not update the active window
+quickly enough. When running the application and taking a screenshot
+of the active window this can create a corrupted screenshot. Adding
+a one second delay in that case fixes this issue.
+
+2009-08-03 jeromeg
+
 Improve the creation of the save dialog's thumbnail.
 
 The thumbnail's width and height now have a maximum of 150 pixels, if
diff --git a/lib/screenshooter-actions.c b/lib/screenshooter-actions.c
index 744fe4ab..d744e224 100644
--- a/lib/screenshooter-actions.c
+++ b/lib/screenshooter-actions.c
@@ -29,8 +29,10 @@ gboolean screenshooter_take_and_output_screenshot (ScreenshotData *sd)
 {
   GdkPixbuf *screenshot;
 
-  screenshot =
-    screenshooter_take_screenshot (sd->region, sd->delay, sd->show_mouse);
+  screenshot = screenshooter_take_screenshot (sd->region,
+                                              sd->delay,
+                                              sd->show_mouse,
+                                              sd->plugin);
 
   g_return_val_if_fail (screenshot != NULL, FALSE);
 
diff --git a/lib/screenshooter-capture.c b/lib/screenshooter-capture.c
index 9f35d040..131c7287 100644
--- a/lib/screenshooter-capture.c
+++ b/lib/screenshooter-capture.c
@@ -442,7 +442,7 @@ static GdkPixbuf
  * Return value: a #GdkPixbuf containing the screenshot or %NULL (if @region is SELECT,
  * the user can cancel the operation).
  **/
-GdkPixbuf *screenshooter_take_screenshot (gint region, gint delay, gboolean show_mouse)
+GdkPixbuf *screenshooter_take_screenshot (gint region, gint delay, gboolean show_mouse, gboolean plugin)
 {
   GdkPixbuf *screenshot = NULL;
   GdkWindow *window = NULL;
@@ -462,8 +462,16 @@ GdkPixbuf *screenshooter_take_screenshot (gint region, gint delay, gboolean show
   gdk_display_sync (display);
 
   /* wait for n=delay seconds */
+  /* Workaround: sleep at least one second to make sure the
+   * WM/X server hast time to select the new active window after
+   * the dialog is closed */
   if (region != SELECT)
-    sleep (delay);
+    {
+      if (region == ACTIVE_WINDOW && !plugin)
+        delay ? sleep (delay): sleep (1);
+      else
+        sleep (delay);
+    }
 
   /* Get the window/desktop we want to screenshot*/
   if (region == FULLSCREEN)
diff --git a/lib/screenshooter-capture.h b/lib/screenshooter-capture.h
index 52086e72..c229d62f 100644
--- a/lib/screenshooter-capture.h
+++ b/lib/screenshooter-capture.h
@@ -36,8 +36,9 @@
 
 
 GdkPixbuf
-*screenshooter_take_screenshot   (gint                  region,
-                                  gint                  delay,
-                                  gboolean              show_mouse);
+*screenshooter_take_screenshot   (gint     region,
+                                  gint     delay,
+                                  gboolean show_mouse,
+                                  gboolean plugin);
 
 #endif
-- 
GitLab