[Xfce4-commits] [apps/xfce4-screenshooter] 01/01: Allow and remember 0sec delay for all regions (Bug #13763)
noreply at xfce.org
noreply at xfce.org
Tue May 1 20:34:54 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 d789db863a4824567fde1fbe388e9615b7b5ecfb
Author: Andre Miranda <andreldm at xfce.org>
Date: Tue May 1 15:27:49 2018 -0300
Allow and remember 0sec delay for all regions (Bug #13763)
This changeset also permits the user to define a delay for the
"Select a region" mode via UI.
Note: if the first dialog is shown, i.e. a region was not passed
as an argument, a minimal delay of 200ms will be used to avoid
that dialog to appear on the screenshot. The same minimal delay
is also used for "Select a region" mode if no delay is defined.
---
lib/screenshooter-capture.c | 24 +++++++++++-------------
lib/screenshooter-dialogs.c | 3 ---
src/main.c | 36 ++++++++++++++++++++++++++++++------
3 files changed, 41 insertions(+), 22 deletions(-)
diff --git a/lib/screenshooter-capture.c b/lib/screenshooter-capture.c
index 8333c70..c610750 100644
--- a/lib/screenshooter-capture.c
+++ b/lib/screenshooter-capture.c
@@ -764,7 +764,7 @@ static gboolean cb_motion_notify (GtkWidget *widget,
static GdkPixbuf
-*capture_rectangle_screenshot (gint x, gint y, gint w, gint h)
+*capture_rectangle_screenshot (gint x, gint y, gint w, gint h, gint delay)
{
GdkWindow *root;
int root_width, root_height;
@@ -787,6 +787,12 @@ static GdkPixbuf
if (y + h > root_height)
h = root_height - y;
+ /* Await the specified delay, but not less than 200ms */
+ if (delay == 0)
+ g_usleep (200000);
+ else
+ sleep (delay);
+
return gdk_pixbuf_get_from_window (root, x, y, w, h);
}
@@ -906,12 +912,11 @@ static GdkPixbuf
/* Grab the screenshot on the main window */
root = gdk_get_default_root_window ();
- sleep (delay);
-
screenshot = capture_rectangle_screenshot (rbdata.rectangle_root.x,
rbdata.rectangle_root.y,
rbdata.rectangle.width,
- rbdata.rectangle.height);
+ rbdata.rectangle.height,
+ delay);
cleanup:
/* Ungrab the mouse and the keyboard */
@@ -1238,12 +1243,11 @@ static GdkPixbuf
{
TRACE ("Get the pixbuf for the screenshot");
- sleep(delay);
-
screenshot = capture_rectangle_screenshot (rbdata.rectangle.x,
rbdata.rectangle.y,
rbdata.rectangle.width,
- rbdata.rectangle.height);
+ rbdata.rectangle.height,
+ delay);
}
if (G_LIKELY (gc != NULL))
@@ -1305,12 +1309,6 @@ GdkPixbuf *screenshooter_take_screenshot (gint region,
gdk_window_process_all_updates ();
- /* wait for n=delay seconds */
- if (region == SELECT)
- delay = 1;
- else
- sleep (delay);
-
/* Get the window/desktop we want to screenshot*/
if (region == FULLSCREEN)
{
diff --git a/lib/screenshooter-dialogs.c b/lib/screenshooter-dialogs.c
index bc4e5c5..af69b6a 100644
--- a/lib/screenshooter-dialogs.c
+++ b/lib/screenshooter-dialogs.c
@@ -868,7 +868,6 @@ GtkWidget *screenshooter_region_dialog_new (ScreenshotData *sd, gboolean plugin)
delay_spinner = gtk_spin_button_new_with_range(0.0, 60.0, 1.0);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (delay_spinner), sd->delay);
- gtk_widget_set_sensitive (delay_spinner, (sd->region != SELECT));
gtk_widget_set_tooltip_text (delay_spinner,
_("Delay in seconds before the screenshot is taken"));
gtk_box_pack_start (GTK_BOX (delay_spinner_box), delay_spinner, FALSE, FALSE, 0);
@@ -877,8 +876,6 @@ GtkWidget *screenshooter_region_dialog_new (ScreenshotData *sd, gboolean plugin)
gtk_box_pack_start (GTK_BOX (delay_spinner_box), seconds_label, FALSE, FALSE, 0);
g_signal_connect (G_OBJECT (delay_spinner), "value-changed",
G_CALLBACK (cb_delay_spinner_changed), sd);
- g_signal_connect (G_OBJECT (rectangle_button), "toggled",
- G_CALLBACK (cb_toggle_set_insensi), delay_spinner);
gtk_widget_show_all (gtk_dialog_get_content_area (GTK_DIALOG (dlg)));
diff --git a/src/main.c b/src/main.c
index beee718..011803d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -106,6 +106,34 @@ 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)
@@ -116,7 +144,7 @@ cb_dialog_response (GtkWidget *dialog, gint response, ScreenshotData *sd)
else if (response == GTK_RESPONSE_OK)
{
gtk_widget_destroy (dialog);
- g_idle_add ((GSourceFunc) screenshooter_take_screenshot_idle, sd);
+ take_screenshot (sd, FALSE);
}
else
{
@@ -313,17 +341,13 @@ int main (int argc, char **argv)
g_free (screenshot_dir);
}
- g_idle_add ((GSourceFunc) screenshooter_take_screenshot_idle, sd);
+ take_screenshot (sd, TRUE);
}
/* Else we show a dialog which allows to set the screenshot options */
else
{
GtkWidget *dialog;
- /* Use 1 as the minimal delay, 0 may show corrupted windows */
- if (sd->delay == 0)
- sd->delay = 1;
-
/* Set the dialog up */
dialog = screenshooter_region_dialog_new (sd, FALSE);
g_signal_connect (dialog, "response",
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list