[Goodies-commits] r6295 - in xfce4-screenshooter-plugin/trunk: . lib panel-plugin
Jerome Guelfucci
jeromeg at xfce.org
Sat Dec 13 13:55:43 CET 2008
Author: jeromeg
Date: 2008-12-13 12:55:43 +0000 (Sat, 13 Dec 2008)
New Revision: 6295
Modified:
xfce4-screenshooter-plugin/trunk/ChangeLog
xfce4-screenshooter-plugin/trunk/NEWS
xfce4-screenshooter-plugin/trunk/lib/screenshooter-dialogs.c
xfce4-screenshooter-plugin/trunk/lib/screenshooter-utils.c
xfce4-screenshooter-plugin/trunk/lib/screenshooter-utils.h
xfce4-screenshooter-plugin/trunk/panel-plugin/screenshooter-plugin.c
Log:
* lib/screenshooter-utils.{c,h}: add RECTANGLE mode, based on David
Collins patch.
* lib/screenshooter-dialogs.c: update the dialog for the new mode,
patch by David Collins.
* panel-plugin/screenshooter-plugin.c: update the tooltips for the new
mode.
* NEWS: updated.
Modified: xfce4-screenshooter-plugin/trunk/ChangeLog
===================================================================
--- xfce4-screenshooter-plugin/trunk/ChangeLog 2008-12-12 17:52:48 UTC (rev 6294)
+++ xfce4-screenshooter-plugin/trunk/ChangeLog 2008-12-13 12:55:43 UTC (rev 6295)
@@ -1,3 +1,13 @@
+2008-12-13 jeromeg
+
+ * lib/screenshooter-utils.{c,h}: add RECTANGLE mode, based on David
+ Collins patch.
+ * lib/screenshooter-dialogs.c: update the dialog for the new mode,
+ patch by David Collins.
+ * panel-plugin/screenshooter-plugin.c: update the tooltips for the new
+ mode.
+ * NEWS: updated.
+
2008-12-12 jeromeg
* lib/screenshooter-dialogs.c: change a string and add a subtitle for
Modified: xfce4-screenshooter-plugin/trunk/NEWS
===================================================================
--- xfce4-screenshooter-plugin/trunk/NEWS 2008-12-12 17:52:48 UTC (rev 6294)
+++ xfce4-screenshooter-plugin/trunk/NEWS 2008-12-13 12:55:43 UTC (rev 6295)
@@ -14,11 +14,13 @@
- Use -V for the version CLI option.
- Add possibility to copy the screenshot to the clipboard, thanks to
David Collins.
+ - Add possibility to define a rectangular region to be captured
+ using the mouse, thanks to David Collins.
- The dialog for the plugin preferences and the application has been
totally rewritten to improve the user interface: it should look
cleaner and tooltips have been added. Work started by David
Collins.
- - when using delay, detect the area to screenshot after the delay,
+ - When using delay, detect the area to screenshot after the delay,
and not before, as it caused weird results in some cases.
=== Version 1.4.0 ===
Modified: xfce4-screenshooter-plugin/trunk/lib/screenshooter-dialogs.c
===================================================================
--- xfce4-screenshooter-plugin/trunk/lib/screenshooter-dialogs.c 2008-12-12 17:52:48 UTC (rev 6294)
+++ xfce4-screenshooter-plugin/trunk/lib/screenshooter-dialogs.c 2008-12-13 12:55:43 UTC (rev 6295)
@@ -32,6 +32,9 @@
static void
cb_save_toggled (GtkToggleButton *tb,
ScreenshotData *sd);
+static void
+cb_rectangle_toggled (GtkToggleButton *tb,
+ ScreenshotData *sd);
#ifdef HAVE_GIO
static void
cb_open_toggled (GtkToggleButton *tb,
@@ -42,8 +45,11 @@
ScreenshotData *sd);
static void
cb_toggle_set_sensi (GtkToggleButton *tb,
- GtkWidget *widget);
+ GtkWidget *widget);
static void
+cb_toggle_set_insensi (GtkToggleButton *tb,
+ GtkWidget *widget);
+static void
cb_show_save_dialog_toggled (GtkToggleButton *tb,
ScreenshotData *sd);
static void
@@ -74,7 +80,7 @@
-/* Set the mode when the button is toggled */
+/* Set the captured area when the button is toggled */
static void cb_fullscreen_screen_toggled (GtkToggleButton *tb,
ScreenshotData *sd)
{
@@ -90,7 +96,7 @@
-/* Set the mode when the button is toggled */
+/* Set the captured area when the button is toggled */
static void cb_active_window_toggled (GtkToggleButton *tb,
ScreenshotData *sd)
{
@@ -98,9 +104,17 @@
{
sd->mode = ACTIVE_WINDOW;
}
- else
+}
+
+
+
+/* Set the captured when the button is toggled */
+static void cb_rectangle_toggled (GtkToggleButton *tb,
+ ScreenshotData *sd)
+{
+ if (gtk_toggle_button_get_active (tb))
{
- sd->mode = FULLSCREEN;
+ sd->mode = RECTANGLE;
}
}
@@ -126,6 +140,15 @@
+/* Set the widget active if the toggle button is inactive */
+static void
+cb_toggle_set_insensi (GtkToggleButton *tb, GtkWidget *widget)
+{
+ gtk_widget_set_sensitive (widget, !gtk_toggle_button_get_active (tb));
+}
+
+
+
#ifdef HAVE_GIO
/* Set the action when the button is toggled */
static void cb_open_toggled (GtkToggleButton *tb, ScreenshotData *sd)
@@ -423,7 +446,9 @@
GtkWidget *vbox;
GtkWidget *area_box, *area_label, *area_alignment;
- GtkWidget *active_window_button, *fullscreen_button;
+ GtkWidget *active_window_button,
+ *fullscreen_button,
+ *rectangle_button;
GtkWidget *delay_box, *delay_label, *delay_alignment;
GtkWidget *delay_spinner_box, *delay_spinner, *seconds_label;
@@ -494,7 +519,7 @@
/* Create area label */
area_label = gtk_label_new ("");
gtk_label_set_markup (GTK_LABEL (area_label),
- _("<span weight=\"bold\" stretch=\"semiexpanded\">Area to capture</span>"));
+ _("<span weight=\"bold\" stretch=\"semiexpanded\">Region to capture</span>"));
gtk_misc_set_alignment (GTK_MISC (area_label), 0, 0);
gtk_widget_show (area_label);
@@ -522,6 +547,7 @@
/* Create radio buttons for areas to screenshot */
+ /* Fullscreen */
fullscreen_button =
gtk_radio_button_new_with_mnemonic (NULL,
_("Entire screen"));
@@ -544,6 +570,7 @@
gtk_widget_show (fullscreen_button);
+ /* Active window */
active_window_button =
gtk_radio_button_new_with_mnemonic (
gtk_radio_button_get_group (GTK_RADIO_BUTTON (fullscreen_button)),
@@ -567,6 +594,30 @@
gtk_widget_show (active_window_button);
+ /* Rectangle */
+ rectangle_button =
+ gtk_radio_button_new_with_mnemonic (
+ gtk_radio_button_get_group (GTK_RADIO_BUTTON (fullscreen_button)),
+ _("Select a rectangle"));
+
+ gtk_box_pack_start (GTK_BOX (area_box),
+ rectangle_button, FALSE,
+ FALSE, 0);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rectangle_button),
+ (sd->mode == RECTANGLE));
+
+ #if GTK_CHECK_VERSION(2,12,0)
+ gtk_widget_set_tooltip_text (rectangle_button,
+ _("Select a region to be captured"));
+ #endif
+
+ g_signal_connect (G_OBJECT (rectangle_button), "toggled",
+ G_CALLBACK (cb_rectangle_toggled),
+ sd);
+
+ gtk_widget_show (rectangle_button);
+
/* Create delay label */
delay_label = gtk_label_new ("");
@@ -635,6 +686,14 @@
g_signal_connect (G_OBJECT (delay_spinner), "value-changed",
G_CALLBACK (cb_delay_spinner_changed), sd);
+
+ /* Set the delay box as inactive when we capture rectangles */
+ g_signal_connect (G_OBJECT (rectangle_button), "toggled",
+ G_CALLBACK (cb_toggle_set_insensi), delay_box);
+
+ /* Set the default state */
+ cb_toggle_set_insensi (GTK_TOGGLE_BUTTON (rectangle_button),
+ delay_box);
/* Create actions label */
@@ -832,11 +891,14 @@
/* Open with box*/
open_with_box = gtk_hbox_new (FALSE, 12);
+
gtk_container_add (GTK_CONTAINER (open_with_alignment),
open_with_box);
+
gtk_container_set_border_width (GTK_CONTAINER (open_with_box), 0);
+
gtk_widget_show (open_with_box);
-
+
g_signal_connect (G_OBJECT (open_with_radio_button), "toggled",
G_CALLBACK (cb_toggle_set_sensi), open_with_box);
Modified: xfce4-screenshooter-plugin/trunk/lib/screenshooter-utils.c
===================================================================
--- xfce4-screenshooter-plugin/trunk/lib/screenshooter-utils.c 2008-12-12 17:52:48 UTC (rev 6294)
+++ xfce4-screenshooter-plugin/trunk/lib/screenshooter-utils.c 2008-12-13 12:55:43 UTC (rev 6295)
@@ -30,8 +30,11 @@
static GdkPixbuf
*get_window_screenshot (GdkWindow *window);
+static GdkPixbuf
+*get_rectangle_screenshot ();
+
static GdkWindow
*get_active_window (GdkScreen *screen, gboolean *needs_unref)
{
@@ -121,6 +124,157 @@
+static GdkPixbuf
+*get_rectangle_screenshot ()
+{
+ GdkPixbuf *screenshot=NULL;
+
+ /* Get display and root window */
+ GdkDisplay *display = gdk_display_get_default ();
+ GdkWindow *root_window = gdk_get_default_root_window ();
+
+ GdkGCValues gc_values;
+ GdkGC *gc;
+ GdkGrabStatus grabstatus;
+
+ GdkGCValuesMask values_mask =
+ GDK_GC_FUNCTION | GDK_GC_FILL | GDK_GC_CLIP_MASK |
+ GDK_GC_SUBWINDOW | GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN |
+ GDK_GC_EXPOSURES | GDK_GC_LINE_WIDTH | GDK_GC_LINE_STYLE |
+ GDK_GC_CAP_STYLE | GDK_GC_JOIN_STYLE;
+
+ GdkColor gc_white = {0, 65535, 65535, 65535};
+ GdkColor gc_black = {0, 0, 0, 0};
+
+ GdkEventMask mask =
+ GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK |
+ GDK_BUTTON_RELEASE_MASK;
+ GdkCursor *xhair_cursor = gdk_cursor_new (GDK_CROSSHAIR);
+
+ gboolean pressed = FALSE;
+ gboolean done = FALSE;
+ gint x, y, w, h;
+
+ /*Set up graphics context for a XOR rectangle that will be drawn as
+ * the user drags the mouse */
+ gc_values.function = GDK_XOR;
+ gc_values.line_width = 0;
+ gc_values.line_style = GDK_LINE_SOLID;
+ gc_values.fill = GDK_SOLID;
+ gc_values.cap_style = GDK_CAP_BUTT;
+ gc_values.join_style = GDK_JOIN_MITER;
+ gc_values.graphics_exposures = FALSE;
+ gc_values.clip_x_origin = 0;
+ gc_values.clip_y_origin = 0;
+ gc_values.clip_mask = None;
+ gc_values.subwindow_mode = GDK_INCLUDE_INFERIORS;
+
+ gc = gdk_gc_new_with_values (root_window, &gc_values, values_mask);
+ gdk_gc_set_rgb_fg_color (gc, &gc_white);
+ gdk_gc_set_rgb_bg_color (gc, &gc_black);
+
+ /* Change cursor to cross-hair */
+ grabstatus = gdk_pointer_grab (root_window, FALSE, mask,
+ NULL, xhair_cursor, GDK_CURRENT_TIME);
+
+ while (!done && grabstatus == GDK_GRAB_SUCCESS)
+ {
+ gint x1, y1, x2, y2;
+ GdkEvent *event;
+
+ event = gdk_event_get ();
+
+ if (event == NULL)
+ continue;
+
+ switch (event->type)
+ {
+ /* Start dragging the rectangle out */
+ case GDK_BUTTON_PRESS:
+ x = x2 = x1 = event->button.x;
+ y = y2 = y1 = event->button.y;
+ w = 0; h = 0;
+ pressed = TRUE;
+ break;
+
+ /* Finish dragging the rectangle out */
+ case GDK_BUTTON_RELEASE:
+ if (pressed)
+ {
+ if (w > 0 && h > 0)
+ {
+ /* Remove the rectangle drawn previously */
+ gdk_draw_rectangle (root_window,
+ gc,
+ FALSE,
+ x, y, w, h);
+ done = TRUE;
+ }
+ else
+ {
+ /* The user has not dragged the mouse, start again */
+
+ pressed = FALSE;
+ }
+ }
+ break;
+
+ /* The user is moving the mouse */
+ case GDK_MOTION_NOTIFY:
+ if (pressed)
+ {
+ if (w > 0 && h > 0)
+
+ /* Remove the rectangle drawn previously */
+ gdk_draw_rectangle (root_window,
+ gc,
+ FALSE,
+ x, y, w, h);
+
+ x2 = event->motion.x;
+ y2 = event->motion.y;
+
+ x = MIN (x1, x2);
+ y = MIN (y1, y2);
+ w = ABS (x2 - x1);
+ h = ABS (y2 - y1);
+
+ /* Draw the rectangle as the user drags the mouse */
+ if (w > 0 && h > 0)
+ gdk_draw_rectangle (root_window,
+ gc,
+ FALSE,
+ x, y, w, h);
+
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ gdk_event_free (event);
+ }
+
+ if (grabstatus == GDK_GRAB_SUCCESS)
+ {
+ gdk_pointer_ungrab(GDK_CURRENT_TIME);
+ }
+
+ /* Get the screenshot's pixbuf */
+ screenshot = gdk_pixbuf_get_from_drawable (NULL, root_window, NULL,
+ x, y, 0, 0, w, h);
+
+ if (gc!=NULL)
+ g_object_unref (gc);
+
+ gdk_cursor_unref (xhair_cursor);
+
+ return screenshot;
+}
+
+
+
/* Public */
@@ -144,7 +298,8 @@
screen = gdk_screen_get_default ();
/* wait for n=delay seconds */
- sleep (delay);
+ if (mode != RECTANGLE)
+ sleep (delay);
/* Get the window/desktop we want to screenshot*/
if (mode == FULLSCREEN)
@@ -156,14 +311,19 @@
{
window = get_active_window (screen, &needs_unref);
}
-
+
if (mode == FULLSCREEN || mode == ACTIVE_WINDOW)
{
screenshot = get_window_screenshot (window);
+
+ if (needs_unref)
+ g_object_unref (window);
}
-
- if (needs_unref)
- g_object_unref (window);
+ else if (mode == RECTANGLE)
+ {
+ screenshot = get_rectangle_screenshot ();
+ }
+
return screenshot;
}
Modified: xfce4-screenshooter-plugin/trunk/lib/screenshooter-utils.h
===================================================================
--- xfce4-screenshooter-plugin/trunk/lib/screenshooter-utils.h 2008-12-12 17:52:48 UTC (rev 6294)
+++ xfce4-screenshooter-plugin/trunk/lib/screenshooter-utils.h 2008-12-13 12:55:43 UTC (rev 6295)
@@ -42,6 +42,7 @@
MODE_0,
FULLSCREEN,
ACTIVE_WINDOW,
+ RECTANGLE,
};
Modified: xfce4-screenshooter-plugin/trunk/panel-plugin/screenshooter-plugin.c
===================================================================
--- xfce4-screenshooter-plugin/trunk/panel-plugin/screenshooter-plugin.c 2008-12-12 17:52:48 UTC (rev 6294)
+++ xfce4-screenshooter-plugin/trunk/panel-plugin/screenshooter-plugin.c 2008-12-13 12:55:43 UTC (rev 6295)
@@ -226,11 +226,16 @@
gtk_widget_set_tooltip_text (GTK_WIDGET (pd->button),
_("Take a screenshot of the entire screen"));
}
- else
+ else if (pd->sd->mode == ACTIVE_WINDOW)
{
gtk_widget_set_tooltip_text (GTK_WIDGET (pd->button),
_("Take a screenshot of the active window"));
}
+ else if (pd->sd->mode == RECTANGLE)
+ {
+ gtk_widget_set_tooltip_text (GTK_WIDGET (pd->button),
+ _("Select a region to be captured"));
+ }
#endif
/* Unblock the menu and save options */
@@ -305,15 +310,20 @@
/* Set the tooltips if available */
#if GTK_CHECK_VERSION(2,12,0)
if (pd->sd->mode == FULLSCREEN)
- {
- gtk_widget_set_tooltip_text (GTK_WIDGET (pd->button),
- _("Take a screenshot of the entire screen"));
- }
- else
- {
- gtk_widget_set_tooltip_text (GTK_WIDGET (pd->button),
- _("Take a screenshot of the active window"));
- }
+ {
+ gtk_widget_set_tooltip_text (GTK_WIDGET (pd->button),
+ _("Take a screenshot of the entire screen"));
+ }
+ else if (pd->sd->mode == ACTIVE_WINDOW)
+ {
+ gtk_widget_set_tooltip_text (GTK_WIDGET (pd->button),
+ _("Take a screenshot of the active window"));
+ }
+ else if (pd->sd->mode == RECTANGLE)
+ {
+ gtk_widget_set_tooltip_text (GTK_WIDGET (pd->button),
+ _("Select a region to be captured"));
+ }
#endif
gtk_widget_show_all (pd->button);
More information about the Goodies-commits
mailing list