Commit 073354cf authored by Cosimo Cecchi's avatar Cosimo Cecchi

screenshot: use GNOME Shell DBus screenshot interface if available

If we're running under GNOME Shell, use its interface to get a
screenshot instead of poking X directly.

https://bugzilla.gnome.org/show_bug.cgi?id=657330
parent 0ebad762
......@@ -13,6 +13,7 @@ bin_PROGRAMS = \
gnome_screenshot_SOURCES = \
gnome-screenshot.c \
gnome-screenshot.h \
cheese-flash.c \
cheese-flash.h \
screenshot-area-selection.c \
......
......@@ -41,6 +41,7 @@
#include <X11/Xutil.h>
#include <canberra-gtk.h>
#include "gnome-screenshot.h"
#include "screenshot-area-selection.h"
#include "screenshot-config.h"
#include "screenshot-filename-builder.h"
......@@ -58,7 +59,6 @@ static GdkPixbuf *screenshot = NULL;
/* Global variables*/
static CheeseFlash *flash = NULL;
static GDBusConnection *connection = NULL;
static gchar *icc_profile_base64 = NULL;
static void
......@@ -616,6 +616,8 @@ init_dbus_session (void)
GError *error = NULL;
gboolean retval = TRUE;
g_assert (connection == NULL);
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
if (error != NULL)
......
/* gnome-screenshot.c - Take screenshots
*
* Copyright (C) 2001 Jonathan Blandford <jrb@alum.mit.edu>
* Copyright (C) 2006 Emmanuele Bassi <ebassi@gnome.org>
* Copyright (C) 2008-2011 Cosimo Cecchi <cosimoc@gnome.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifndef __GNOME_SCREENSHOT_H__
#define __GNOME_SCREENSHOT_H__
/* DBus session connection */
GDBusConnection *connection;
#endif /* __GNOME_SCREENSHOT_H__ */
......@@ -28,6 +28,7 @@
#include <X11/extensions/shape.h>
#endif
#include "gnome-screenshot.h"
#include "screenshot-config.h"
#include "screenshot-utils.h"
......@@ -348,19 +349,9 @@ screenshot_get_window_rect_coords (GdkWindow *window,
}
}
void
screenshot_get_window_rect (GdkWindow *window,
GdkRectangle *rect)
{
screenshot_get_window_rect_coords (window,
screenshot_config->include_border,
NULL,
rect);
}
GdkPixbuf *
screenshot_get_pixbuf (GdkWindow *window,
GdkRectangle *rectangle)
static GdkPixbuf *
screenshot_get_pixbuf_fallback (GdkWindow *window,
GdkRectangle *rectangle)
{
GdkWindow *root, *wm_window = NULL;
GdkPixbuf *screenshot;
......@@ -556,6 +547,91 @@ screenshot_get_pixbuf (GdkWindow *window,
return screenshot;
}
void
screenshot_get_window_rect (GdkWindow *window,
GdkRectangle *rect)
{
screenshot_get_window_rect_coords (window,
screenshot_config->include_border,
NULL,
rect);
}
GdkPixbuf *
screenshot_get_pixbuf (GdkWindow *window,
GdkRectangle *rectangle)
{
GdkPixbuf *screenshot;
gchar *path, *filename;
const gchar *method_name;
GVariant *method_params;
GError *error = NULL;
path = g_build_filename (g_get_user_cache_dir (), "gnome-screenshot", NULL);
g_mkdir_with_parents (path, 0700);
filename = g_build_filename (path, "tmp.png", NULL);
if (screenshot_config->take_window_shot)
{
method_name = "ScreenshotWindow";
method_params = g_variant_new ("(bs)",
screenshot_config->include_border,
filename);
}
else if (rectangle != NULL)
{
method_name = "ScreenshotArea";
method_params = g_variant_new ("(iiiis)",
rectangle->x, rectangle->y,
rectangle->width, rectangle->height,
filename);
}
else
{
method_name = "Screenshot";
method_params = g_variant_new ("(s)", filename);
}
g_dbus_connection_call_sync (connection,
"org.gnome.Shell",
"/org/gnome/Shell",
"org.gnome.Shell",
method_name,
method_params,
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
if (error != NULL)
{
g_warning ("Unable to use GNOME Shell's builtin screenshot interface, "
"resorting to fallback X11. Error: %s", error->message);
g_error_free (error);
screenshot = screenshot_get_pixbuf_fallback (window, rectangle);
}
else
{
screenshot = gdk_pixbuf_new_from_file (filename, &error);
if (error != NULL)
{
g_warning ("Unable to load GNOME Shell's builtin screenshot result, "
"resorting to fallback X11. Error: %s", error->message);
g_error_free (error);
screenshot = screenshot_get_pixbuf_fallback (window, rectangle);
}
}
g_free (path);
g_free (filename);
return screenshot;
}
void
screenshot_show_error_dialog (GtkWindow *parent,
const gchar *message,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment