2012-02-14 19:33:56 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
#include <cogl/cogl.h>
|
|
|
|
#include <meta/display.h>
|
|
|
|
#include <meta/util.h>
|
|
|
|
#include <meta/meta-plugin.h>
|
|
|
|
#include <meta/meta-shaped-texture.h>
|
2013-08-14 08:48:45 +00:00
|
|
|
#include <meta/meta-cursor-tracker.h>
|
2019-03-12 21:41:18 +00:00
|
|
|
#include <st/st.h>
|
2012-02-14 19:33:56 +00:00
|
|
|
|
|
|
|
#include "shell-global.h"
|
|
|
|
#include "shell-screenshot.h"
|
2016-08-19 02:47:57 +00:00
|
|
|
#include "shell-util.h"
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2015-09-24 18:07:44 +00:00
|
|
|
typedef struct _ShellScreenshotPrivate ShellScreenshotPrivate;
|
2012-02-14 19:33:56 +00:00
|
|
|
|
|
|
|
struct _ShellScreenshot
|
|
|
|
{
|
|
|
|
GObject parent_instance;
|
|
|
|
|
2014-09-27 11:35:22 +00:00
|
|
|
ShellScreenshotPrivate *priv;
|
2012-02-14 19:33:56 +00:00
|
|
|
};
|
|
|
|
|
2014-09-27 11:35:22 +00:00
|
|
|
struct _ShellScreenshotPrivate
|
|
|
|
{
|
|
|
|
ShellGlobal *global;
|
2012-02-14 19:33:56 +00:00
|
|
|
|
|
|
|
char *filename;
|
2012-12-10 14:03:49 +00:00
|
|
|
char *filename_used;
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2017-11-17 12:02:06 +00:00
|
|
|
GDateTime *datetime;
|
|
|
|
|
2012-02-14 19:33:56 +00:00
|
|
|
cairo_surface_t *image;
|
|
|
|
cairo_rectangle_int_t screenshot_area;
|
|
|
|
|
|
|
|
gboolean include_cursor;
|
2014-12-04 14:38:28 +00:00
|
|
|
gboolean include_frame;
|
2014-09-27 11:35:22 +00:00
|
|
|
};
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2019-02-13 01:23:41 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
SHELL_SCREENSHOT_SCREEN,
|
|
|
|
SHELL_SCREENSHOT_WINDOW,
|
|
|
|
SHELL_SCREENSHOT_AREA,
|
|
|
|
} ShellScreenshotMode;
|
|
|
|
|
2014-09-27 11:35:22 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (ShellScreenshot, shell_screenshot, G_TYPE_OBJECT);
|
2012-02-14 19:33:56 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
shell_screenshot_class_init (ShellScreenshotClass *screenshot_class)
|
|
|
|
{
|
2012-03-25 14:49:38 +00:00
|
|
|
(void) screenshot_class;
|
2012-02-14 19:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_screenshot_init (ShellScreenshot *screenshot)
|
|
|
|
{
|
2014-09-27 11:35:22 +00:00
|
|
|
screenshot->priv = shell_screenshot_get_instance_private (screenshot);
|
|
|
|
screenshot->priv->global = shell_global_get ();
|
2012-02-14 19:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-09-25 18:09:11 +00:00
|
|
|
on_screenshot_written (GObject *source,
|
2018-07-19 13:54:33 +00:00
|
|
|
GAsyncResult *task,
|
2015-09-25 18:09:11 +00:00
|
|
|
gpointer user_data)
|
2012-02-14 19:33:56 +00:00
|
|
|
{
|
2014-09-27 11:35:22 +00:00
|
|
|
ShellScreenshot *screenshot = SHELL_SCREENSHOT (source);
|
|
|
|
ShellScreenshotPrivate *priv = screenshot->priv;
|
2018-07-19 13:54:33 +00:00
|
|
|
GTask *result = user_data;
|
2014-09-27 11:35:22 +00:00
|
|
|
|
2018-07-19 13:54:33 +00:00
|
|
|
g_task_return_boolean (result, g_task_propagate_boolean (G_TASK (task), NULL));
|
|
|
|
g_object_unref (result);
|
2014-09-27 11:35:22 +00:00
|
|
|
|
|
|
|
g_clear_pointer (&priv->image, cairo_surface_destroy);
|
|
|
|
g_clear_pointer (&priv->filename, g_free);
|
|
|
|
g_clear_pointer (&priv->filename_used, g_free);
|
2017-11-17 12:02:06 +00:00
|
|
|
g_clear_pointer (&priv->datetime, g_date_time_unref);
|
2014-12-04 14:38:28 +00:00
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
meta_enable_unredirect_for_display (shell_global_get_display (priv->global));
|
2012-02-14 19:33:56 +00:00
|
|
|
}
|
|
|
|
|
2012-11-09 18:02:01 +00:00
|
|
|
/* called in an I/O thread */
|
|
|
|
static GOutputStream *
|
2013-01-02 17:58:07 +00:00
|
|
|
get_stream_for_unique_path (const gchar *path,
|
|
|
|
const gchar *filename,
|
|
|
|
gchar **filename_used)
|
2012-11-09 18:02:01 +00:00
|
|
|
{
|
|
|
|
GOutputStream *stream;
|
|
|
|
GFile *file;
|
|
|
|
gchar *real_path, *real_filename, *name, *ptr;
|
2013-01-02 17:58:07 +00:00
|
|
|
gint idx;
|
2012-11-09 18:02:01 +00:00
|
|
|
|
|
|
|
ptr = g_strrstr (filename, ".png");
|
|
|
|
|
|
|
|
if (ptr != NULL)
|
|
|
|
real_filename = g_strndup (filename, ptr - filename);
|
|
|
|
else
|
|
|
|
real_filename = g_strdup (filename);
|
|
|
|
|
2013-01-02 17:58:07 +00:00
|
|
|
idx = 0;
|
|
|
|
real_path = NULL;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (idx == 0)
|
|
|
|
name = g_strdup_printf ("%s.png", real_filename);
|
|
|
|
else
|
|
|
|
name = g_strdup_printf ("%s - %d.png", real_filename, idx);
|
|
|
|
|
|
|
|
real_path = g_build_filename (path, name, NULL);
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
file = g_file_new_for_path (real_path);
|
|
|
|
stream = G_OUTPUT_STREAM (g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL));
|
|
|
|
g_object_unref (file);
|
2012-11-09 18:02:01 +00:00
|
|
|
|
2013-01-02 17:58:07 +00:00
|
|
|
if (stream != NULL)
|
|
|
|
*filename_used = real_path;
|
|
|
|
else
|
|
|
|
g_free (real_path);
|
2012-11-09 18:02:01 +00:00
|
|
|
|
2013-01-02 17:58:07 +00:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
while (stream == NULL);
|
|
|
|
|
|
|
|
g_free (real_filename);
|
2012-12-10 14:03:49 +00:00
|
|
|
|
2012-11-09 18:02:01 +00:00
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* called in an I/O thread */
|
|
|
|
static GOutputStream *
|
2012-12-10 14:03:49 +00:00
|
|
|
get_stream_for_filename (const gchar *filename,
|
|
|
|
gchar **filename_used)
|
2012-11-09 18:02:01 +00:00
|
|
|
{
|
|
|
|
const gchar *path;
|
|
|
|
|
|
|
|
path = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
|
|
|
|
if (!g_file_test (path, G_FILE_TEST_EXISTS))
|
|
|
|
{
|
|
|
|
path = g_get_home_dir ();
|
|
|
|
if (!g_file_test (path, G_FILE_TEST_EXISTS))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-01-02 17:58:07 +00:00
|
|
|
return get_stream_for_unique_path (path, filename, filename_used);
|
2012-11-09 18:02:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GOutputStream *
|
2012-12-10 14:03:49 +00:00
|
|
|
prepare_write_stream (const gchar *filename,
|
|
|
|
gchar **filename_used)
|
2012-11-09 18:02:01 +00:00
|
|
|
{
|
|
|
|
GOutputStream *stream;
|
|
|
|
GFile *file;
|
|
|
|
|
|
|
|
if (g_path_is_absolute (filename))
|
|
|
|
{
|
|
|
|
file = g_file_new_for_path (filename);
|
2012-12-10 14:03:49 +00:00
|
|
|
*filename_used = g_strdup (filename);
|
2013-01-03 14:02:00 +00:00
|
|
|
stream = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL));
|
2012-11-09 18:02:01 +00:00
|
|
|
g_object_unref (file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-10 14:03:49 +00:00
|
|
|
stream = get_stream_for_filename (filename, filename_used);
|
2012-11-09 18:02:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2012-02-14 19:33:56 +00:00
|
|
|
static void
|
2015-09-25 18:09:11 +00:00
|
|
|
write_screenshot_thread (GTask *result,
|
|
|
|
gpointer object,
|
|
|
|
gpointer task_data,
|
2012-02-14 19:33:56 +00:00
|
|
|
GCancellable *cancellable)
|
|
|
|
{
|
|
|
|
cairo_status_t status;
|
2012-11-09 18:02:01 +00:00
|
|
|
GOutputStream *stream;
|
2014-09-27 11:35:22 +00:00
|
|
|
ShellScreenshot *screenshot = SHELL_SCREENSHOT (object);
|
|
|
|
ShellScreenshotPrivate *priv;
|
2017-11-17 12:02:06 +00:00
|
|
|
char *creation_time;
|
2014-09-27 11:35:22 +00:00
|
|
|
|
|
|
|
g_assert (screenshot != NULL);
|
2012-11-09 18:02:01 +00:00
|
|
|
|
2014-09-27 11:35:22 +00:00
|
|
|
priv = screenshot->priv;
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2014-09-27 11:35:22 +00:00
|
|
|
stream = prepare_write_stream (priv->filename,
|
|
|
|
&priv->filename_used);
|
2012-11-09 18:02:01 +00:00
|
|
|
|
|
|
|
if (stream == NULL)
|
|
|
|
status = CAIRO_STATUS_FILE_NOT_FOUND;
|
|
|
|
else
|
2013-02-14 17:22:24 +00:00
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf;
|
2013-02-16 02:50:28 +00:00
|
|
|
|
2014-09-27 11:35:22 +00:00
|
|
|
pixbuf = gdk_pixbuf_get_from_surface (priv->image,
|
2013-02-16 02:50:28 +00:00
|
|
|
0, 0,
|
2014-09-27 11:35:22 +00:00
|
|
|
cairo_image_surface_get_width (priv->image),
|
|
|
|
cairo_image_surface_get_height (priv->image));
|
2017-11-17 12:02:06 +00:00
|
|
|
creation_time = g_date_time_format (priv->datetime, "%c");
|
2013-02-16 02:50:28 +00:00
|
|
|
|
2019-04-01 16:06:49 +00:00
|
|
|
if (!creation_time)
|
|
|
|
creation_time = g_date_time_format (priv->datetime, "%FT%T%z");
|
|
|
|
|
2013-02-14 17:22:24 +00:00
|
|
|
if (gdk_pixbuf_save_to_stream (pixbuf, stream, "png", NULL, NULL,
|
2017-11-17 12:02:06 +00:00
|
|
|
"tEXt::Software", "gnome-screenshot",
|
|
|
|
"tEXt::Creation Time", creation_time,
|
|
|
|
NULL))
|
2013-02-14 17:22:24 +00:00
|
|
|
status = CAIRO_STATUS_SUCCESS;
|
|
|
|
else
|
|
|
|
status = CAIRO_STATUS_WRITE_ERROR;
|
|
|
|
|
2013-02-16 02:50:28 +00:00
|
|
|
g_object_unref (pixbuf);
|
2017-11-17 12:02:06 +00:00
|
|
|
g_free (creation_time);
|
2013-02-14 17:22:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-09 18:02:01 +00:00
|
|
|
|
2015-09-25 18:09:11 +00:00
|
|
|
g_task_return_boolean (result, status == CAIRO_STATUS_SUCCESS);
|
2012-11-09 18:02:01 +00:00
|
|
|
|
|
|
|
g_clear_object (&stream);
|
2012-02-14 19:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-09-27 11:35:22 +00:00
|
|
|
do_grab_screenshot (ShellScreenshot *screenshot,
|
2016-06-27 07:57:28 +00:00
|
|
|
ClutterStage *stage,
|
2012-02-14 19:33:56 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
2014-09-27 11:35:22 +00:00
|
|
|
ShellScreenshotPrivate *priv = screenshot->priv;
|
2017-12-23 03:54:48 +00:00
|
|
|
cairo_rectangle_int_t screenshot_rect = { x, y, width, height };
|
2016-06-27 07:57:28 +00:00
|
|
|
ClutterCapture *captures;
|
|
|
|
int n_captures;
|
|
|
|
int i;
|
|
|
|
|
2017-12-23 03:54:48 +00:00
|
|
|
if (!clutter_stage_capture (stage, FALSE,
|
|
|
|
&screenshot_rect,
|
|
|
|
&captures,
|
|
|
|
&n_captures))
|
2016-06-27 07:57:28 +00:00
|
|
|
return;
|
2017-12-23 03:54:48 +00:00
|
|
|
|
|
|
|
if (n_captures == 1)
|
2016-08-19 02:47:57 +00:00
|
|
|
priv->image = cairo_surface_reference (captures[0].image);
|
|
|
|
else
|
2017-12-23 03:54:48 +00:00
|
|
|
{
|
|
|
|
float target_scale;
|
|
|
|
|
|
|
|
clutter_stage_get_capture_final_size (stage, &screenshot_rect,
|
|
|
|
&width, &height, &target_scale);
|
|
|
|
priv->image = shell_util_composite_capture_images (captures,
|
|
|
|
n_captures,
|
|
|
|
x, y,
|
|
|
|
width, height,
|
|
|
|
target_scale);
|
|
|
|
}
|
|
|
|
|
2017-11-17 12:02:06 +00:00
|
|
|
priv->datetime = g_date_time_new_now_local ();
|
2016-06-27 07:57:28 +00:00
|
|
|
|
2016-08-19 02:47:57 +00:00
|
|
|
for (i = 0; i < n_captures; i++)
|
2016-06-27 07:57:28 +00:00
|
|
|
cairo_surface_destroy (captures[i].image);
|
|
|
|
|
|
|
|
g_free (captures);
|
2012-02-14 19:33:56 +00:00
|
|
|
}
|
|
|
|
|
2019-02-13 01:13:47 +00:00
|
|
|
static gboolean
|
2019-02-13 01:23:41 +00:00
|
|
|
should_draw_cursor_image (ShellScreenshotMode mode)
|
2019-02-13 01:13:47 +00:00
|
|
|
{
|
2019-02-13 01:23:41 +00:00
|
|
|
if (mode == SHELL_SCREENSHOT_WINDOW || !meta_is_wayland_compositor ())
|
|
|
|
{
|
2019-03-12 21:41:18 +00:00
|
|
|
StSettings *settings = st_settings_get ();
|
|
|
|
gboolean magnifier_active = FALSE;
|
|
|
|
|
|
|
|
g_object_get (settings, "magnifier-active", &magnifier_active, NULL);
|
2019-02-13 01:13:47 +00:00
|
|
|
|
2019-03-12 21:41:18 +00:00
|
|
|
if (!magnifier_active)
|
2019-02-13 01:23:41 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2019-02-13 01:13:47 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-08-14 08:48:45 +00:00
|
|
|
static void
|
2019-02-13 01:01:03 +00:00
|
|
|
draw_cursor_image (cairo_surface_t *surface,
|
|
|
|
cairo_rectangle_int_t area)
|
2013-08-14 08:48:45 +00:00
|
|
|
{
|
|
|
|
CoglTexture *texture;
|
|
|
|
int width, height;
|
|
|
|
int stride;
|
|
|
|
guint8 *data;
|
2019-02-13 01:01:03 +00:00
|
|
|
MetaDisplay *display;
|
|
|
|
MetaCursorTracker *tracker;
|
2012-02-14 19:33:56 +00:00
|
|
|
cairo_surface_t *cursor_surface;
|
|
|
|
cairo_region_t *screenshot_region;
|
|
|
|
cairo_t *cr;
|
2013-08-14 08:48:45 +00:00
|
|
|
int x, y;
|
|
|
|
int xhot, yhot;
|
2019-02-13 01:01:03 +00:00
|
|
|
double xscale, yscale;
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2019-02-13 01:01:03 +00:00
|
|
|
display = shell_global_get_display (shell_global_get ());
|
|
|
|
tracker = meta_cursor_tracker_get_for_display (display);
|
2016-09-19 13:34:03 +00:00
|
|
|
texture = meta_cursor_tracker_get_sprite (tracker);
|
2019-02-13 01:01:03 +00:00
|
|
|
|
2016-09-19 13:34:03 +00:00
|
|
|
if (!texture)
|
|
|
|
return;
|
|
|
|
|
2012-02-14 19:33:56 +00:00
|
|
|
screenshot_region = cairo_region_create_rectangle (&area);
|
2015-02-11 08:58:42 +00:00
|
|
|
meta_cursor_tracker_get_pointer (tracker, &x, &y, NULL);
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2013-08-14 08:48:45 +00:00
|
|
|
if (!cairo_region_contains_point (screenshot_region, x, y))
|
2012-02-14 19:33:56 +00:00
|
|
|
{
|
2013-08-14 08:48:45 +00:00
|
|
|
cairo_region_destroy (screenshot_region);
|
|
|
|
return;
|
2012-02-14 19:33:56 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 08:48:45 +00:00
|
|
|
meta_cursor_tracker_get_hot (tracker, &xhot, &yhot);
|
|
|
|
width = cogl_texture_get_width (texture);
|
|
|
|
height = cogl_texture_get_height (texture);
|
|
|
|
stride = 4 * width;
|
|
|
|
data = g_new (guint8, stride * height);
|
|
|
|
cogl_texture_get_data (texture, CLUTTER_CAIRO_FORMAT_ARGB32, stride, data);
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2013-08-14 08:48:45 +00:00
|
|
|
/* FIXME: cairo-gl? */
|
|
|
|
cursor_surface = cairo_image_surface_create_for_data (data,
|
|
|
|
CAIRO_FORMAT_ARGB32,
|
|
|
|
width, height,
|
|
|
|
stride);
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2019-02-13 01:30:28 +00:00
|
|
|
cairo_surface_get_device_scale (surface, &xscale, &yscale);
|
|
|
|
|
|
|
|
if (xscale != 1.0 || yscale != 1.0)
|
|
|
|
{
|
|
|
|
int monitor;
|
|
|
|
float monitor_scale;
|
|
|
|
MetaRectangle cursor_rect = {
|
|
|
|
.x = x, .y = y, .width = width, .height = height
|
|
|
|
};
|
|
|
|
|
|
|
|
monitor = meta_display_get_monitor_index_for_rect (display, &cursor_rect);
|
|
|
|
monitor_scale = meta_display_get_monitor_scale (display, monitor);
|
|
|
|
|
|
|
|
cairo_surface_set_device_scale (cursor_surface, monitor_scale, monitor_scale);
|
|
|
|
}
|
|
|
|
|
2012-02-14 19:33:56 +00:00
|
|
|
cr = cairo_create (surface);
|
|
|
|
cairo_set_source_surface (cr,
|
|
|
|
cursor_surface,
|
2013-08-14 08:48:45 +00:00
|
|
|
x - xhot - area.x,
|
|
|
|
y - yhot - area.y);
|
2012-02-14 19:33:56 +00:00
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
cairo_surface_destroy (cursor_surface);
|
|
|
|
cairo_region_destroy (screenshot_region);
|
2013-08-14 08:48:45 +00:00
|
|
|
g_free (data);
|
2012-02-14 19:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
grab_screenshot (ClutterActor *stage,
|
2018-07-19 13:54:33 +00:00
|
|
|
GTask *result)
|
2012-02-14 19:33:56 +00:00
|
|
|
{
|
2018-01-03 07:55:38 +00:00
|
|
|
MetaDisplay *display;
|
2012-02-14 19:33:56 +00:00
|
|
|
int width, height;
|
2018-07-19 13:54:33 +00:00
|
|
|
ShellScreenshot *screenshot = g_task_get_source_object (result);
|
2014-09-27 11:35:22 +00:00
|
|
|
ShellScreenshotPrivate *priv = screenshot->priv;
|
2018-07-19 13:54:33 +00:00
|
|
|
GTask *task;
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
display = shell_global_get_display (priv->global);
|
|
|
|
meta_display_get_size (display, &width, &height);
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2016-06-27 07:57:28 +00:00
|
|
|
do_grab_screenshot (screenshot, CLUTTER_STAGE (stage), 0, 0, width, height);
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
if (meta_display_get_n_monitors (display) > 1)
|
2012-02-14 19:33:56 +00:00
|
|
|
{
|
|
|
|
cairo_region_t *screen_region = cairo_region_create ();
|
|
|
|
cairo_region_t *stage_region;
|
|
|
|
MetaRectangle monitor_rect;
|
|
|
|
cairo_rectangle_int_t stage_rect;
|
|
|
|
int i;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
for (i = meta_display_get_n_monitors (display) - 1; i >= 0; i--)
|
2012-02-14 19:33:56 +00:00
|
|
|
{
|
2018-01-03 07:55:38 +00:00
|
|
|
meta_display_get_monitor_geometry (display, i, &monitor_rect);
|
|
|
|
cairo_region_union_rectangle (screen_region,
|
|
|
|
(const cairo_rectangle_int_t *) &monitor_rect);
|
2012-02-14 19:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stage_rect.x = 0;
|
|
|
|
stage_rect.y = 0;
|
|
|
|
stage_rect.width = width;
|
|
|
|
stage_rect.height = height;
|
|
|
|
|
|
|
|
stage_region = cairo_region_create_rectangle ((const cairo_rectangle_int_t *) &stage_rect);
|
|
|
|
cairo_region_xor (stage_region, screen_region);
|
|
|
|
cairo_region_destroy (screen_region);
|
|
|
|
|
2014-09-27 11:35:22 +00:00
|
|
|
cr = cairo_create (priv->image);
|
2012-02-14 19:33:56 +00:00
|
|
|
|
|
|
|
for (i = 0; i < cairo_region_num_rectangles (stage_region); i++)
|
|
|
|
{
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
cairo_region_get_rectangle (stage_region, i, &rect);
|
|
|
|
cairo_rectangle (cr, (double) rect.x, (double) rect.y, (double) rect.width, (double) rect.height);
|
|
|
|
cairo_fill (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
cairo_region_destroy (stage_region);
|
|
|
|
}
|
|
|
|
|
2014-09-27 11:35:22 +00:00
|
|
|
priv->screenshot_area.x = 0;
|
|
|
|
priv->screenshot_area.y = 0;
|
|
|
|
priv->screenshot_area.width = width;
|
|
|
|
priv->screenshot_area.height = height;
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2019-02-13 01:13:47 +00:00
|
|
|
if (priv->include_cursor)
|
2019-02-13 01:01:03 +00:00
|
|
|
draw_cursor_image (priv->image, priv->screenshot_area);
|
|
|
|
|
2018-07-19 13:54:33 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (stage, grab_screenshot, result);
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2018-07-19 13:54:33 +00:00
|
|
|
task = g_task_new (screenshot, NULL, on_screenshot_written, result);
|
|
|
|
g_task_run_in_thread (task, write_screenshot_thread);
|
|
|
|
g_object_unref (task);
|
2012-02-14 19:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
grab_area_screenshot (ClutterActor *stage,
|
2018-07-19 13:54:33 +00:00
|
|
|
GTask *result)
|
2012-02-14 19:33:56 +00:00
|
|
|
{
|
2018-07-19 13:54:33 +00:00
|
|
|
ShellScreenshot *screenshot = g_task_get_source_object (result);
|
2014-09-27 11:35:22 +00:00
|
|
|
ShellScreenshotPrivate *priv = screenshot->priv;
|
2018-07-19 13:54:33 +00:00
|
|
|
GTask *task;
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2014-09-27 11:35:22 +00:00
|
|
|
do_grab_screenshot (screenshot,
|
2016-06-27 07:57:28 +00:00
|
|
|
CLUTTER_STAGE (stage),
|
2014-09-27 11:35:22 +00:00
|
|
|
priv->screenshot_area.x,
|
|
|
|
priv->screenshot_area.y,
|
|
|
|
priv->screenshot_area.width,
|
|
|
|
priv->screenshot_area.height);
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2018-07-19 13:54:33 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (stage, grab_area_screenshot, result);
|
|
|
|
task = g_task_new (screenshot, NULL, on_screenshot_written, result);
|
|
|
|
g_task_run_in_thread (task, write_screenshot_thread);
|
|
|
|
g_object_unref (task);
|
2012-02-14 19:33:56 +00:00
|
|
|
}
|
|
|
|
|
2014-12-04 14:38:28 +00:00
|
|
|
static void
|
|
|
|
grab_window_screenshot (ClutterActor *stage,
|
2018-07-19 13:54:33 +00:00
|
|
|
GTask *result)
|
2014-12-04 14:38:28 +00:00
|
|
|
{
|
2018-07-19 13:54:33 +00:00
|
|
|
ShellScreenshot *screenshot = g_task_get_source_object (result);
|
2014-12-04 14:38:28 +00:00
|
|
|
ShellScreenshotPrivate *priv = screenshot->priv;
|
2018-07-19 13:54:33 +00:00
|
|
|
GTask *task;
|
2018-01-03 07:55:38 +00:00
|
|
|
MetaDisplay *display = shell_global_get_display (priv->global);
|
2014-12-04 14:38:28 +00:00
|
|
|
MetaWindow *window = meta_display_get_focus_window (display);
|
|
|
|
ClutterActor *window_actor;
|
|
|
|
gfloat actor_x, actor_y;
|
|
|
|
MetaShapedTexture *stex;
|
|
|
|
MetaRectangle rect;
|
|
|
|
cairo_rectangle_int_t clip;
|
|
|
|
|
|
|
|
window_actor = CLUTTER_ACTOR (meta_window_get_compositor_private (window));
|
|
|
|
clutter_actor_get_position (window_actor, &actor_x, &actor_y);
|
|
|
|
|
|
|
|
meta_window_get_frame_rect (window, &rect);
|
|
|
|
|
|
|
|
if (!priv->include_frame)
|
|
|
|
meta_window_frame_rect_to_client_rect (window, &rect, &rect);
|
|
|
|
|
|
|
|
priv->screenshot_area.x = rect.x;
|
|
|
|
priv->screenshot_area.y = rect.y;
|
|
|
|
clip.x = rect.x - (gint) actor_x;
|
|
|
|
clip.y = rect.y - (gint) actor_y;
|
|
|
|
|
|
|
|
clip.width = priv->screenshot_area.width = rect.width;
|
|
|
|
clip.height = priv->screenshot_area.height = rect.height;
|
|
|
|
|
|
|
|
stex = META_SHAPED_TEXTURE (meta_window_actor_get_texture (META_WINDOW_ACTOR (window_actor)));
|
|
|
|
priv->image = meta_shaped_texture_get_image (stex, &clip);
|
2017-11-17 12:02:06 +00:00
|
|
|
priv->datetime = g_date_time_new_now_local ();
|
2014-12-04 14:38:28 +00:00
|
|
|
|
2019-02-13 01:13:47 +00:00
|
|
|
if (priv->include_cursor)
|
2019-02-13 01:30:28 +00:00
|
|
|
{
|
|
|
|
if (meta_window_get_client_type (window) == META_WINDOW_CLIENT_TYPE_WAYLAND)
|
|
|
|
{
|
|
|
|
float resource_scale;
|
|
|
|
if (!clutter_actor_get_resource_scale (window_actor, &resource_scale))
|
|
|
|
resource_scale = 1.0f;
|
|
|
|
|
|
|
|
cairo_surface_set_device_scale (priv->image, resource_scale, resource_scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_cursor_image (priv->image, priv->screenshot_area);
|
|
|
|
}
|
2019-02-13 01:01:03 +00:00
|
|
|
|
2018-07-19 13:54:33 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (stage, grab_window_screenshot, result);
|
|
|
|
task = g_task_new (screenshot, NULL, on_screenshot_written, result);
|
|
|
|
g_task_run_in_thread (task, write_screenshot_thread);
|
|
|
|
g_object_unref (task);
|
|
|
|
}
|
|
|
|
|
2018-07-19 12:50:49 +00:00
|
|
|
static void
|
|
|
|
grab_pixel (ClutterActor *stage,
|
|
|
|
GTask *result)
|
|
|
|
{
|
|
|
|
ShellScreenshot *screenshot = g_task_get_source_object (result);
|
|
|
|
ShellScreenshotPrivate *priv = screenshot->priv;
|
|
|
|
|
|
|
|
do_grab_screenshot (screenshot,
|
|
|
|
CLUTTER_STAGE (stage),
|
|
|
|
priv->screenshot_area.x,
|
|
|
|
priv->screenshot_area.y,
|
|
|
|
1,
|
|
|
|
1);
|
|
|
|
|
|
|
|
meta_enable_unredirect_for_display (shell_global_get_display (priv->global));
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func (stage, grab_pixel, result);
|
|
|
|
g_task_return_boolean (result, TRUE);
|
|
|
|
g_object_unref (result);
|
|
|
|
}
|
|
|
|
|
2018-07-19 13:54:33 +00:00
|
|
|
static gboolean
|
|
|
|
finish_screenshot (ShellScreenshot *screenshot,
|
|
|
|
GAsyncResult *result,
|
|
|
|
cairo_rectangle_int_t **area,
|
|
|
|
const char **filename_used,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
ShellScreenshotPrivate *priv = screenshot->priv;
|
|
|
|
|
|
|
|
if (!g_task_propagate_boolean (G_TASK (result), error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (area)
|
|
|
|
*area = &priv->screenshot_area;
|
|
|
|
|
|
|
|
if (filename_used)
|
|
|
|
*filename_used = priv->filename_used;
|
|
|
|
|
|
|
|
return TRUE;
|
2014-12-04 14:38:28 +00:00
|
|
|
}
|
|
|
|
|
2012-02-14 19:33:56 +00:00
|
|
|
/**
|
|
|
|
* shell_screenshot_screenshot:
|
|
|
|
* @screenshot: the #ShellScreenshot
|
|
|
|
* @include_cursor: Whether to include the cursor or not
|
|
|
|
* @filename: The filename for the screenshot
|
|
|
|
* @callback: (scope async): function to call returning success or failure
|
|
|
|
* of the async grabbing
|
2018-07-19 13:54:33 +00:00
|
|
|
* @user_data: the data to pass to callback function
|
2012-02-14 19:33:56 +00:00
|
|
|
*
|
|
|
|
* Takes a screenshot of the whole screen
|
|
|
|
* in @filename as png image.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
2018-07-19 13:54:33 +00:00
|
|
|
shell_screenshot_screenshot (ShellScreenshot *screenshot,
|
|
|
|
gboolean include_cursor,
|
|
|
|
const char *filename,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-02-14 19:33:56 +00:00
|
|
|
{
|
|
|
|
ClutterActor *stage;
|
2014-09-27 11:35:22 +00:00
|
|
|
ShellScreenshotPrivate *priv = screenshot->priv;
|
2019-02-13 01:23:41 +00:00
|
|
|
const char *paint_signal;
|
2018-07-19 13:54:33 +00:00
|
|
|
GTask *result;
|
2014-09-27 11:35:22 +00:00
|
|
|
|
|
|
|
if (priv->filename != NULL) {
|
|
|
|
if (callback)
|
2018-07-19 13:54:33 +00:00
|
|
|
g_task_report_new_error (screenshot,
|
|
|
|
callback,
|
|
|
|
user_data,
|
|
|
|
shell_screenshot_screenshot,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_PENDING,
|
|
|
|
"Only one screenshot operation at a time "
|
|
|
|
"is permitted");
|
2014-09-27 11:35:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2018-07-19 13:54:33 +00:00
|
|
|
result = g_task_new (screenshot, NULL, callback, user_data);
|
|
|
|
g_task_set_source_tag (result, shell_screenshot_screenshot);
|
|
|
|
|
2014-09-27 11:35:22 +00:00
|
|
|
priv->filename = g_strdup (filename);
|
2019-02-13 01:23:41 +00:00
|
|
|
priv->include_cursor = FALSE;
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2014-09-27 11:35:22 +00:00
|
|
|
stage = CLUTTER_ACTOR (shell_global_get_stage (priv->global));
|
2019-02-13 01:23:41 +00:00
|
|
|
paint_signal = "actors-painted";
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
meta_disable_unredirect_for_display (shell_global_get_display (priv->global));
|
2014-12-04 14:38:28 +00:00
|
|
|
|
2019-02-13 01:23:41 +00:00
|
|
|
if (include_cursor)
|
|
|
|
{
|
|
|
|
if (should_draw_cursor_image (SHELL_SCREENSHOT_SCREEN))
|
|
|
|
priv->include_cursor = TRUE;
|
|
|
|
else
|
|
|
|
paint_signal = "paint";
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect_after (stage, paint_signal, G_CALLBACK (grab_screenshot), result);
|
2012-02-14 19:33:56 +00:00
|
|
|
|
|
|
|
clutter_actor_queue_redraw (stage);
|
|
|
|
}
|
|
|
|
|
2018-07-19 13:54:33 +00:00
|
|
|
/**
|
|
|
|
* shell_screenshot_screenshot_finish:
|
|
|
|
* @screenshot: the #ShellScreenshot
|
|
|
|
* @result: the #GAsyncResult that was provided to the callback
|
|
|
|
* @area: (out) (transfer none): the area that was grabbed in screen coordinates
|
|
|
|
* @filename_used: (out) (transfer none): the name of the file the screenshot
|
|
|
|
* was written to
|
|
|
|
* @error: #GError for error reporting
|
|
|
|
*
|
|
|
|
* Finish the asynchronous operation started by shell_screenshot_screenshot()
|
|
|
|
* and obtain its result.
|
|
|
|
*
|
|
|
|
* Returns: whether the operation was successful
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
shell_screenshot_screenshot_finish (ShellScreenshot *screenshot,
|
|
|
|
GAsyncResult *result,
|
|
|
|
cairo_rectangle_int_t **area,
|
|
|
|
const char **filename_used,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (g_async_result_is_tagged (result,
|
|
|
|
shell_screenshot_screenshot),
|
|
|
|
FALSE);
|
|
|
|
return finish_screenshot (screenshot, result, area, filename_used, error);
|
|
|
|
}
|
|
|
|
|
2012-02-14 19:33:56 +00:00
|
|
|
/**
|
|
|
|
* shell_screenshot_screenshot_area:
|
|
|
|
* @screenshot: the #ShellScreenshot
|
|
|
|
* @x: The X coordinate of the area
|
|
|
|
* @y: The Y coordinate of the area
|
|
|
|
* @width: The width of the area
|
|
|
|
* @height: The height of the area
|
|
|
|
* @filename: The filename for the screenshot
|
|
|
|
* @callback: (scope async): function to call returning success or failure
|
|
|
|
* of the async grabbing
|
2018-07-19 13:54:33 +00:00
|
|
|
* @user_data: the data to pass to callback function
|
2012-02-14 19:33:56 +00:00
|
|
|
*
|
|
|
|
* Takes a screenshot of the passed in area and saves it
|
|
|
|
* in @filename as png image.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
2018-07-19 13:54:33 +00:00
|
|
|
shell_screenshot_screenshot_area (ShellScreenshot *screenshot,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
const char *filename,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-02-14 19:33:56 +00:00
|
|
|
{
|
|
|
|
ClutterActor *stage;
|
2014-09-27 11:35:22 +00:00
|
|
|
ShellScreenshotPrivate *priv = screenshot->priv;
|
2018-07-19 13:54:33 +00:00
|
|
|
GTask *result;
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2014-09-27 11:35:22 +00:00
|
|
|
if (priv->filename != NULL) {
|
|
|
|
if (callback)
|
2018-07-19 13:54:33 +00:00
|
|
|
g_task_report_new_error (screenshot,
|
|
|
|
callback,
|
|
|
|
NULL,
|
|
|
|
shell_screenshot_screenshot_area,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_PENDING,
|
|
|
|
"Only one screenshot operation at a time "
|
|
|
|
"is permitted");
|
2014-09-27 11:35:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2018-07-19 13:54:33 +00:00
|
|
|
result = g_task_new (screenshot, NULL, callback, user_data);
|
|
|
|
g_task_set_source_tag (result, shell_screenshot_screenshot_area);
|
|
|
|
|
2014-09-27 11:35:22 +00:00
|
|
|
priv->filename = g_strdup (filename);
|
|
|
|
priv->screenshot_area.x = x;
|
|
|
|
priv->screenshot_area.y = y;
|
|
|
|
priv->screenshot_area.width = width;
|
|
|
|
priv->screenshot_area.height = height;
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2014-09-27 11:35:22 +00:00
|
|
|
stage = CLUTTER_ACTOR (shell_global_get_stage (priv->global));
|
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
meta_disable_unredirect_for_display (shell_global_get_display (shell_global_get ()));
|
2014-12-04 14:38:28 +00:00
|
|
|
|
2019-02-13 01:25:26 +00:00
|
|
|
g_signal_connect_after (stage, "actors-painted", G_CALLBACK (grab_area_screenshot), result);
|
2012-02-14 19:33:56 +00:00
|
|
|
|
|
|
|
clutter_actor_queue_redraw (stage);
|
|
|
|
}
|
|
|
|
|
2018-07-19 13:54:33 +00:00
|
|
|
/**
|
|
|
|
* shell_screenshot_screenshot_area_finish:
|
|
|
|
* @screenshot: the #ShellScreenshot
|
|
|
|
* @result: the #GAsyncResult that was provided to the callback
|
|
|
|
* @area: (out) (transfer none): the area that was grabbed in screen coordinates
|
|
|
|
* @filename_used: (out) (transfer none): the name of the file the screenshot
|
|
|
|
* was written to
|
|
|
|
* @error: #GError for error reporting
|
|
|
|
*
|
|
|
|
* Finish the asynchronous operation started by shell_screenshot_screenshot_area()
|
|
|
|
* and obtain its result.
|
|
|
|
*
|
|
|
|
* Returns: whether the operation was successful
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
shell_screenshot_screenshot_area_finish (ShellScreenshot *screenshot,
|
|
|
|
GAsyncResult *result,
|
|
|
|
cairo_rectangle_int_t **area,
|
|
|
|
const char **filename_used,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (g_async_result_is_tagged (result,
|
|
|
|
shell_screenshot_screenshot_area),
|
|
|
|
FALSE);
|
|
|
|
return finish_screenshot (screenshot, result, area, filename_used, error);
|
|
|
|
}
|
|
|
|
|
2012-02-14 19:33:56 +00:00
|
|
|
/**
|
|
|
|
* shell_screenshot_screenshot_window:
|
|
|
|
* @screenshot: the #ShellScreenshot
|
|
|
|
* @include_frame: Whether to include the frame or not
|
|
|
|
* @include_cursor: Whether to include the cursor or not
|
|
|
|
* @filename: The filename for the screenshot
|
|
|
|
* @callback: (scope async): function to call returning success or failure
|
|
|
|
* of the async grabbing
|
2018-07-19 13:54:33 +00:00
|
|
|
* @user_data: the data to pass to callback function
|
2012-02-14 19:33:56 +00:00
|
|
|
*
|
|
|
|
* Takes a screenshot of the focused window (optionally omitting the frame)
|
|
|
|
* in @filename as png image.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
2018-07-19 13:54:33 +00:00
|
|
|
shell_screenshot_screenshot_window (ShellScreenshot *screenshot,
|
|
|
|
gboolean include_frame,
|
|
|
|
gboolean include_cursor,
|
|
|
|
const char *filename,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-02-14 19:33:56 +00:00
|
|
|
{
|
2014-09-27 11:35:22 +00:00
|
|
|
ShellScreenshotPrivate *priv = screenshot->priv;
|
2018-01-03 07:55:38 +00:00
|
|
|
MetaDisplay *display = shell_global_get_display (priv->global);
|
2014-12-04 14:38:28 +00:00
|
|
|
ClutterActor *stage;
|
2012-02-14 19:33:56 +00:00
|
|
|
MetaWindow *window = meta_display_get_focus_window (display);
|
2018-07-19 13:54:33 +00:00
|
|
|
GTask *result;
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2014-09-27 11:35:22 +00:00
|
|
|
if (priv->filename != NULL || !window) {
|
|
|
|
if (callback)
|
2018-07-19 13:54:33 +00:00
|
|
|
g_task_report_new_error (screenshot,
|
|
|
|
callback,
|
|
|
|
NULL,
|
|
|
|
shell_screenshot_screenshot_window,
|
|
|
|
G_IO_ERROR,
|
|
|
|
G_IO_ERROR_PENDING,
|
|
|
|
"Only one screenshot operation at a time "
|
|
|
|
"is permitted");
|
2014-09-27 11:35:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-05-19 10:26:49 +00:00
|
|
|
|
2018-07-19 13:54:33 +00:00
|
|
|
result = g_task_new (screenshot, NULL, callback, user_data);
|
|
|
|
g_task_set_source_tag (result, shell_screenshot_screenshot_window);
|
|
|
|
|
2014-09-27 11:35:22 +00:00
|
|
|
priv->filename = g_strdup (filename);
|
2014-12-04 14:38:28 +00:00
|
|
|
priv->include_frame = include_frame;
|
2019-02-13 01:23:41 +00:00
|
|
|
priv->include_cursor = include_cursor &&
|
|
|
|
should_draw_cursor_image (SHELL_SCREENSHOT_WINDOW);
|
2013-05-19 10:26:49 +00:00
|
|
|
|
2014-12-04 14:38:28 +00:00
|
|
|
stage = CLUTTER_ACTOR (shell_global_get_stage (priv->global));
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
meta_disable_unredirect_for_display (shell_global_get_display (shell_global_get ()));
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2019-02-13 01:25:26 +00:00
|
|
|
g_signal_connect_after (stage, "actors-painted", G_CALLBACK (grab_window_screenshot), result);
|
2012-02-14 19:33:56 +00:00
|
|
|
|
2014-12-04 14:38:28 +00:00
|
|
|
clutter_actor_queue_redraw (stage);
|
2012-02-14 19:33:56 +00:00
|
|
|
}
|
2012-02-14 20:57:34 +00:00
|
|
|
|
2018-07-19 13:54:33 +00:00
|
|
|
/**
|
|
|
|
* shell_screenshot_screenshot_window_finish:
|
|
|
|
* @screenshot: the #ShellScreenshot
|
|
|
|
* @result: the #GAsyncResult that was provided to the callback
|
|
|
|
* @area: (out) (transfer none): the area that was grabbed in screen coordinates
|
|
|
|
* @filename_used: (out) (transfer none): the name of the file the screenshot
|
|
|
|
* was written to
|
|
|
|
* @error: #GError for error reporting
|
|
|
|
*
|
|
|
|
* Finish the asynchronous operation started by shell_screenshot_screenshot_window()
|
|
|
|
* and obtain its result.
|
|
|
|
*
|
|
|
|
* Returns: whether the operation was successful
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
shell_screenshot_screenshot_window_finish (ShellScreenshot *screenshot,
|
|
|
|
GAsyncResult *result,
|
|
|
|
cairo_rectangle_int_t **area,
|
|
|
|
const char **filename_used,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (g_async_result_is_tagged (result,
|
|
|
|
shell_screenshot_screenshot_window),
|
|
|
|
FALSE);
|
|
|
|
return finish_screenshot (screenshot, result, area, filename_used, error);
|
|
|
|
}
|
|
|
|
|
2018-07-19 12:50:49 +00:00
|
|
|
/**
|
|
|
|
* shell_screenshot_pick_color:
|
|
|
|
* @screenshot: the #ShellScreenshot
|
|
|
|
* @x: The X coordinate to pick
|
|
|
|
* @y: The Y coordinate to pick
|
|
|
|
* @callback: (scope async): function to call returning success or failure
|
|
|
|
* of the async grabbing
|
|
|
|
*
|
|
|
|
* Picks the pixel at @x, @y and returns its color as #ClutterColor.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
shell_screenshot_pick_color (ShellScreenshot *screenshot,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
ShellScreenshotPrivate *priv = screenshot->priv;
|
|
|
|
MetaDisplay *display = shell_global_get_display (priv->global);
|
|
|
|
ClutterActor *stage;
|
|
|
|
GTask *result;
|
|
|
|
|
|
|
|
result = g_task_new (screenshot, NULL, callback, user_data);
|
|
|
|
g_task_set_source_tag (result, shell_screenshot_pick_color);
|
|
|
|
|
|
|
|
priv->screenshot_area.x = x;
|
|
|
|
priv->screenshot_area.y = y;
|
|
|
|
priv->screenshot_area.width = 1;
|
|
|
|
priv->screenshot_area.height = 1;
|
|
|
|
|
|
|
|
stage = CLUTTER_ACTOR (shell_global_get_stage (priv->global));
|
|
|
|
|
|
|
|
meta_disable_unredirect_for_display (display);
|
|
|
|
|
2019-02-13 01:25:26 +00:00
|
|
|
g_signal_connect_after (stage, "actors-painted", G_CALLBACK (grab_pixel), result);
|
2018-07-19 12:50:49 +00:00
|
|
|
|
|
|
|
clutter_actor_queue_redraw (stage);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
|
|
#define INDEX_A 3
|
|
|
|
#define INDEX_R 2
|
|
|
|
#define INDEX_G 1
|
|
|
|
#define INDEX_B 0
|
|
|
|
#else
|
|
|
|
#define INDEX_A 0
|
|
|
|
#define INDEX_R 1
|
|
|
|
#define INDEX_G 2
|
|
|
|
#define INDEX_B 3
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* shell_screenshot_pick_color_finish:
|
|
|
|
* @screenshot: the #ShellScreenshot
|
|
|
|
* @result: the #GAsyncResult that was provided to the callback
|
|
|
|
* @color: (out caller-allocates): the picked color
|
|
|
|
* @error: #GError for error reporting
|
|
|
|
*
|
|
|
|
* Finish the asynchronous operation started by shell_screenshot_pick_color()
|
|
|
|
* and obtain its result.
|
|
|
|
*
|
|
|
|
* Returns: whether the operation was successful
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
shell_screenshot_pick_color_finish (ShellScreenshot *screenshot,
|
|
|
|
GAsyncResult *result,
|
|
|
|
ClutterColor *color,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
ShellScreenshotPrivate *priv = screenshot->priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_async_result_is_tagged (result,
|
|
|
|
shell_screenshot_pick_color),
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
if (!g_task_propagate_boolean (G_TASK (result), error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* protect against mutter changing the format used for stage captures */
|
|
|
|
g_assert (cairo_image_surface_get_format (priv->image) == CAIRO_FORMAT_ARGB32);
|
|
|
|
|
|
|
|
if (color)
|
|
|
|
{
|
|
|
|
uint8_t *data = cairo_image_surface_get_data (priv->image);
|
|
|
|
|
|
|
|
color->alpha = data[INDEX_A];
|
|
|
|
color->red = data[INDEX_R];
|
|
|
|
color->green = data[INDEX_G];
|
|
|
|
color->blue = data[INDEX_B];
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef INDEX_A
|
|
|
|
#undef INDEX_R
|
|
|
|
#undef INDEX_G
|
|
|
|
#undef INDEX_B
|
|
|
|
|
2012-02-14 20:57:34 +00:00
|
|
|
ShellScreenshot *
|
|
|
|
shell_screenshot_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (SHELL_TYPE_SCREENSHOT, NULL);
|
|
|
|
}
|