@@ -100,6 +100,7 @@ static gboolean interactive_arg = FALSE;
100100static guint delay_arg = 0 ;
101101
102102/* Options */
103+ static gboolean noninteractive_clipboard_arg = FALSE;
103104static gboolean take_window_shot = FALSE;
104105static gboolean take_area_shot = FALSE;
105106static gboolean include_border = FALSE;
@@ -704,6 +705,14 @@ save_done_notification (gpointer data)
704705 }
705706}
706707
708+ static void
709+ save_screenshot_in_clipboard (GdkDisplay * display , GdkPixbuf * screenshot )
710+ {
711+ GtkClipboard * clipboard =
712+ gtk_clipboard_get_for_display (display , GDK_SELECTION_CLIPBOARD );
713+ gtk_clipboard_set_image (clipboard , screenshot );
714+ }
715+
707716static void
708717screenshot_dialog_response_cb (GtkDialog * d ,
709718 gint response_id ,
@@ -741,13 +750,8 @@ screenshot_dialog_response_cb (GtkDialog *d,
741750 }
742751 else if (response_id == SCREENSHOT_RESPONSE_COPY )
743752 {
744- GtkClipboard * clipboard ;
745- GdkPixbuf * screenshot ;
746-
747- clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (d )),
748- GDK_SELECTION_CLIPBOARD );
749- screenshot = screenshot_dialog_get_screenshot (dialog );
750- gtk_clipboard_set_image (clipboard , screenshot );
753+ save_screenshot_in_clipboard (gtk_widget_get_display (GTK_WIDGET (d )),
754+ screenshot_dialog_get_screenshot (dialog ));
751755 }
752756 else /* dialog was canceled */
753757 {
@@ -851,6 +855,14 @@ finish_prepare_screenshot (char *initial_uri, GdkWindow *window, GdkRectangle *r
851855
852856 play_sound_effect (window );
853857
858+ if (noninteractive_clipboard_arg ) {
859+ save_screenshot_in_clipboard (gdk_window_get_display (window ), screenshot );
860+ g_free (initial_uri );
861+ /* Done here: */
862+ gtk_main_quit ();
863+ return ;
864+ }
865+
854866 dialog = screenshot_dialog_new (screenshot , initial_uri , take_window_shot );
855867 g_free (initial_uri );
856868
@@ -1303,6 +1315,7 @@ main (int argc, char *argv[])
13031315 const GOptionEntry entries [] = {
13041316 { "window" , 'w' , 0 , G_OPTION_ARG_NONE , & window_arg , N_ ("Grab a window instead of the entire screen" ), NULL },
13051317 { "area" , 'a' , 0 , G_OPTION_ARG_NONE , & area_arg , N_ ("Grab an area of the screen instead of the entire screen" ), NULL },
1318+ { "clipboard" , 'c' , 0 , G_OPTION_ARG_NONE , & noninteractive_clipboard_arg , N_ ("Send grabbed area directly to the clipboard" ), NULL },
13061319 { "include-border" , 'b' , 0 , G_OPTION_ARG_NONE , & include_border_arg , N_ ("Include the window border with the screenshot" ), NULL },
13071320 { "remove-border" , 'B' , 0 , G_OPTION_ARG_NONE , & disable_border_arg , N_ ("Remove the window border from the screenshot" ), NULL },
13081321 { "delay" , 'd' , 0 , G_OPTION_ARG_INT , & delay_arg , N_ ("Take screenshot after specified delay [in seconds]" ), N_ ("seconds" ) },
@@ -1339,6 +1352,12 @@ main (int argc, char *argv[])
13391352 exit (EXIT_SUCCESS );
13401353 }
13411354
1355+ if (interactive_arg && noninteractive_clipboard_arg ) {
1356+ g_printerr (_ ("Conflicting options: --clipboard and --interactive should not be "
1357+ "used at the same time.\n" ));
1358+ exit (1 );
1359+ }
1360+
13421361 if (window_arg && area_arg ) {
13431362 g_printerr (_ ("Conflicting options: --window and --area should not be "
13441363 "used at the same time.\n" ));
0 commit comments