[Xfce4-commits] [apps/xfce4-screenshooter] 01/02: Refactor take_screenshot methods (Bug #14604)

noreply at xfce.org noreply at xfce.org
Tue Aug 28 04:19:53 CEST 2018


This is an automated email from the git hooks/post-receive script.

a   n   d   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-screenshooter.

commit 4476a87b84b2e3ef6896dee273619f56389776fd
Author: Andre Miranda <andreldm at xfce.org>
Date:   Mon Aug 27 23:17:53 2018 -0300

    Refactor take_screenshot methods (Bug #14604)
---
 lib/screenshooter-actions.c         | 78 ++++++++++++++++++++++++++-----------
 lib/screenshooter-actions.h         |  8 +---
 lib/screenshooter-capture.c         | 24 ++++++------
 lib/screenshooter-capture.h         |  8 ++--
 panel-plugin/screenshooter-plugin.c |  4 +-
 src/main.c                          | 32 +--------------
 6 files changed, 78 insertions(+), 76 deletions(-)

diff --git a/lib/screenshooter-actions.c b/lib/screenshooter-actions.c
index 260e546..5a66b2e 100644
--- a/lib/screenshooter-actions.c
+++ b/lib/screenshooter-actions.c
@@ -18,8 +18,11 @@
  * */
 
 #include "screenshooter-actions.h"
-
-
+#include "screenshooter-utils.h"
+#include "screenshooter-capture.h"
+#include "screenshooter-global.h"
+#include "screenshooter-dialogs.h"
+#include "screenshooter-imgur.h"
 
 static void
 cb_help_response (GtkWidget *dialog, gint response, gpointer unused)
@@ -33,26 +36,8 @@ cb_help_response (GtkWidget *dialog, gint response, gpointer unused)
 
 
 
-/* Public */
-
-
-
-gboolean screenshooter_take_screenshot_idle (ScreenshotData *sd)
-{
-  sd->screenshot = screenshooter_take_screenshot (sd->region,
-                                                  sd->delay,
-                                                  sd->show_mouse,
-                                                  sd->plugin);
-
-  if (sd->screenshot != NULL)
-    g_idle_add ((GSourceFunc) screenshooter_action_idle, sd);
-  else if (!sd->plugin)
-    gtk_main_quit ();
-
-  return FALSE;
-}
-
-gboolean screenshooter_action_idle (ScreenshotData *sd)
+gboolean
+action_idle (ScreenshotData *sd)
 {
   if (!sd->action_specified)
     {
@@ -138,3 +123,52 @@ gboolean screenshooter_action_idle (ScreenshotData *sd)
   return FALSE;
 }
 
+
+
+static gboolean
+take_screenshot_idle (ScreenshotData *sd)
+{
+  sd->screenshot = screenshooter_capture_screenshot (sd->region,
+                                                  sd->delay,
+                                                  sd->show_mouse,
+                                                  sd->plugin);
+
+  if (sd->screenshot != NULL)
+    g_idle_add ((GSourceFunc) action_idle, sd);
+  else if (!sd->plugin)
+    gtk_main_quit ();
+
+  return FALSE;
+}
+
+
+
+/* Public */
+
+
+
+void
+screenshooter_take_screenshot (ScreenshotData *sd, gboolean immediate)
+{
+  if (sd->region == SELECT)
+    {
+      /* The delay will be applied after the rectangle selection */
+      g_idle_add ((GSourceFunc) take_screenshot_idle, sd);
+      return;
+    }
+
+  if (sd->delay == 0 && immediate)
+    {
+      /* If delay is zero and the region was passed as an argument (from cli
+       * or panel plugin), thus the first dialog was not shown, we will take
+       * the screenshot immediately without a minimal delay */
+      g_idle_add ((GSourceFunc) take_screenshot_idle, sd);
+      return;
+    }
+
+  /* Await the amount of the time specified by the user before capturing the
+   * screenshot, but not less than 200ms, otherwise the first dialog might
+   * appear on the screenshot. */
+  gint delay = sd->delay == 0 ? 200 : sd->delay * 1000;
+  g_timeout_add (delay, (GSourceFunc) take_screenshot_idle, sd);
+}
diff --git a/lib/screenshooter-actions.h b/lib/screenshooter-actions.h
index c09f9df..123fe32 100644
--- a/lib/screenshooter-actions.h
+++ b/lib/screenshooter-actions.h
@@ -20,13 +20,9 @@
 #ifndef __HAVE_ACTIONS_H__
 #define __HAVE_ACTIONS_H__
 
-#include "screenshooter-utils.h"
-#include "screenshooter-capture.h"
 #include "screenshooter-global.h"
-#include "screenshooter-dialogs.h"
-#include "screenshooter-imgur.h"
 
-gboolean screenshooter_take_screenshot_idle (ScreenshotData *sd);
-gboolean screenshooter_action_idle          (ScreenshotData *sd);
+void screenshooter_take_screenshot      (ScreenshotData *sd,
+                                         gboolean immediate);
 
 #endif
diff --git a/lib/screenshooter-capture.c b/lib/screenshooter-capture.c
index c610750..2ba25ab 100644
--- a/lib/screenshooter-capture.c
+++ b/lib/screenshooter-capture.c
@@ -343,7 +343,7 @@ static GdkPixbuf
   if (y_orig + height > gdk_screen_height ())
     height = gdk_screen_height () - y_orig;
 
-  /* Take the screenshot from the root GdkWindow, to grab things such as
+  /* Capture the screenshot from the root GdkWindow, to grab things such as
    * menus. */
 
   TRACE ("Grab the screenshot");
@@ -1265,29 +1265,29 @@ static GdkPixbuf
 
 
 /**
- * screenshooter_take_screenshot:
+ * screenshooter_capture_screenshot:
  * @region: the region to be screenshoted. It can be FULLSCREEN,
  *          ACTIVE_WINDOW or SELECT.
- * @delay: the delay before the screenshot is taken, in seconds.
+ * @delay: the delay before the screenshot is captured, in seconds.
  * @mouse: whether the mouse pointer should be displayed on the screenshot.
  *
- * Takes a screenshot with the given options. If @region is FULLSCREEN,
- * the screenshot is taken after @delay seconds. If @region is
+ * Captures a screenshot with the given options. If @region is FULLSCREEN,
+ * the screenshot is capture after @delay seconds. If @region is
  * ACTIVE_WINDOW, a delay of @delay seconds elapses, then the active
  * window is detected and captured. If @region is SELECT, the user will
  * have to select a portion of the screen with the mouse. Then a delay of
- * @delay seconds elapses, and a screenshot is taken.
+ * @delay seconds elapses, and a screenshot is captured.
  *
- * @show_mouse is only taken into account when @region is FULLSCREEN
+ * @show_mouse is only captured into account when @region is FULLSCREEN
  * or ACTIVE_WINDOW.
  *
  * 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,
-                                          gboolean plugin)
+GdkPixbuf *screenshooter_capture_screenshot (gint     region,
+                                             gint     delay,
+                                             gboolean show_mouse,
+                                             gboolean plugin)
 {
   GdkPixbuf *screenshot = NULL;
   GdkWindow *window = NULL;
@@ -1300,7 +1300,7 @@ GdkPixbuf *screenshooter_take_screenshot (gint     region,
    * window has been grabbed. */
   gboolean needs_unref = TRUE;
 
-  /* Get the screen on which the screenshot should be taken */
+  /* Get the screen on which the screenshot should be captured */
   screen = gdk_screen_get_default ();
 
   /* Sync the display */
diff --git a/lib/screenshooter-capture.h b/lib/screenshooter-capture.h
index 7f6cd75..2af4a01 100644
--- a/lib/screenshooter-capture.h
+++ b/lib/screenshooter-capture.h
@@ -41,9 +41,9 @@
 
 
 GdkPixbuf
-*screenshooter_take_screenshot   (gint     region,
-                                  gint     delay,
-                                  gboolean show_mouse,
-                                  gboolean plugin);
+*screenshooter_capture_screenshot (gint     region,
+                                   gint     delay,
+                                   gboolean show_mouse,
+                                   gboolean plugin);
 
 #endif
diff --git a/panel-plugin/screenshooter-plugin.c b/panel-plugin/screenshooter-plugin.c
index 22d9a25..a4de277 100644
--- a/panel-plugin/screenshooter-plugin.c
+++ b/panel-plugin/screenshooter-plugin.c
@@ -183,12 +183,12 @@ static void
 cb_button_clicked (GtkWidget *button, PluginData *pd)
 {
   /* Make the button unclickable so that the user does not press it while
-	another screenshot is in progress */
+  another screenshot is in progress */
   gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
 
   TRACE ("Start taking the screenshot");
 
-  screenshooter_take_screenshot_idle (pd->sd);
+  screenshooter_take_screenshot (pd->sd, TRUE);
 
   /* Make the panel button clickable */
   gtk_widget_set_sensitive (GTK_WIDGET (button), TRUE);
diff --git a/src/main.c b/src/main.c
index d6a02af..cca7bf0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -106,34 +106,6 @@ static GOptionEntry entries[] =
 
 
 static void
-take_screenshot (ScreenshotData *sd, gboolean from_cli)
-{
-  if (sd->region == SELECT)
-    {
-      /* The delay will be applied after the rectangle selection */
-      g_idle_add ((GSourceFunc) screenshooter_take_screenshot_idle, sd);
-      return;
-    }
-
-  if (sd->delay == 0 && from_cli)
-    {
-      /* If delay is zero and the region was passed as an argument, thus the
-       * first dialog was not shown, we will take the screenshot immediately
-       * without a minimal delay */
-      g_idle_add ((GSourceFunc) screenshooter_take_screenshot_idle, sd);
-      return;
-    }
-
-  /* Await the amount of the time specified by the user before capturing the
-   * screenshot, but not less than 200ms, otherwise the first dialog might
-   * appear on the screenshot. */
-  gint delay = sd->delay == 0 ? 200 : sd->delay * 1000;
-  g_timeout_add (delay, (GSourceFunc) screenshooter_take_screenshot_idle, sd);
-}
-
-
-
-static void
 cb_dialog_response (GtkWidget *dialog, gint response, ScreenshotData *sd)
 {
   if (response == GTK_RESPONSE_HELP)
@@ -144,7 +116,7 @@ cb_dialog_response (GtkWidget *dialog, gint response, ScreenshotData *sd)
   else if (response == GTK_RESPONSE_OK)
     {
       gtk_widget_destroy (dialog);
-      take_screenshot (sd, FALSE);
+      screenshooter_take_screenshot (sd, FALSE);
     }
   else
     {
@@ -345,7 +317,7 @@ int main (int argc, char **argv)
           g_free (screenshot_dir);
         }
 
-      take_screenshot (sd, TRUE);
+      screenshooter_take_screenshot (sd, TRUE);
     }
   /* Else we show a dialog which allows to set the screenshot options */
   else

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list