screenshot: Add include_cursor parameter
Add a boolean parameter to Screenshot and ScreenshotWindow which draws the cursor on the screenshot when set to true. https://bugzilla.gnome.org/show_bug.cgi?id=670086
This commit is contained in:
parent
570a029f27
commit
b2ec340f9e
@ -39,11 +39,13 @@ const GnomeShellIface = <interface name="org.gnome.Shell">
|
||||
</method>
|
||||
<method name="ScreenshotWindow">
|
||||
<arg type="b" direction="in" name="include_frame"/>
|
||||
<arg type="b" direction="in" name="include_cursor"/>
|
||||
<arg type="b" direction="in" name="flash"/>
|
||||
<arg type="s" direction="in" name="filename"/>
|
||||
<arg type="b" direction="out" name="success"/>
|
||||
</method>
|
||||
<method name="Screenshot">
|
||||
<arg type="b" direction="in" name="include_cursor"/>
|
||||
<arg type="b" direction="in" name="flash"/>
|
||||
<arg type="s" direction="in" name="filename"/>
|
||||
<arg type="b" direction="out" name="success"/>
|
||||
@ -134,6 +136,7 @@ const GnomeShell = new Lang.Class({
|
||||
* @y: The Y coordinate of the area
|
||||
* @width: The width of the area
|
||||
* @height: The height of the area
|
||||
* @flash: Whether to flash the area or not
|
||||
* @filename: The filename for the screenshot
|
||||
*
|
||||
* Takes a screenshot of the passed in area and saves it
|
||||
@ -151,6 +154,8 @@ const GnomeShell = new Lang.Class({
|
||||
/**
|
||||
* ScreenshotWindow:
|
||||
* @include_frame: Whether to include the frame or not
|
||||
* @include_cursor: Whether to include the cursor image or not
|
||||
* @flash: Whether to flash the window area or not
|
||||
* @filename: The filename for the screenshot
|
||||
*
|
||||
* Takes a screenshot of the focused window (optionally omitting the frame)
|
||||
@ -159,8 +164,8 @@ const GnomeShell = new Lang.Class({
|
||||
*
|
||||
*/
|
||||
ScreenshotWindowAsync : function (params, invocation) {
|
||||
let [include_frame, flash, filename] = params;
|
||||
global.screenshot_window (include_frame, filename,
|
||||
let [include_frame, include_cursor, flash, filename] = params;
|
||||
global.screenshot_window (include_frame, include_cursor, filename,
|
||||
Lang.bind(this, this._onScreenshotComplete,
|
||||
flash, invocation));
|
||||
},
|
||||
@ -168,6 +173,8 @@ const GnomeShell = new Lang.Class({
|
||||
/**
|
||||
* Screenshot:
|
||||
* @filename: The filename for the screenshot
|
||||
* @include_cursor: Whether to include the cursor image or not
|
||||
* @flash: Whether to flash the screen or not
|
||||
*
|
||||
* Takes a screenshot of the whole screen and saves it
|
||||
* in @filename as png image, it returns a boolean
|
||||
@ -175,8 +182,8 @@ const GnomeShell = new Lang.Class({
|
||||
*
|
||||
*/
|
||||
ScreenshotAsync : function (params, invocation) {
|
||||
let [flash, filename] = params;
|
||||
global.screenshot(filename,
|
||||
let [include_cursor, flash, filename] = params;
|
||||
global.screenshot(include_cursor, filename,
|
||||
Lang.bind(this, this._onScreenshotComplete,
|
||||
flash, invocation));
|
||||
},
|
||||
|
@ -28,6 +28,8 @@ typedef struct _screenshot_data {
|
||||
cairo_surface_t *image;
|
||||
cairo_rectangle_int_t screenshot_area;
|
||||
|
||||
gboolean include_cursor;
|
||||
|
||||
ShellGlobalScreenshotCallback callback;
|
||||
} _screenshot_data;
|
||||
|
||||
|
@ -1948,6 +1948,61 @@ do_grab_screenshot (_screenshot_data *screenshot_data,
|
||||
data, (cairo_destroy_func_t)g_free);
|
||||
}
|
||||
|
||||
static void
|
||||
_draw_cursor_image (cairo_surface_t *surface,
|
||||
cairo_rectangle_int_t area)
|
||||
{
|
||||
XFixesCursorImage *cursor_image;
|
||||
|
||||
cairo_surface_t *cursor_surface;
|
||||
cairo_region_t *screenshot_region;
|
||||
cairo_t *cr;
|
||||
|
||||
guchar *data;
|
||||
int stride;
|
||||
int i, j;
|
||||
|
||||
cursor_image = XFixesGetCursorImage (clutter_x11_get_default_display ());
|
||||
|
||||
if (!cursor_image)
|
||||
return;
|
||||
|
||||
screenshot_region = cairo_region_create_rectangle (&area);
|
||||
|
||||
if (!cairo_region_contains_point (screenshot_region, cursor_image->x, cursor_image->y))
|
||||
{
|
||||
XFree (cursor_image);
|
||||
cairo_region_destroy (screenshot_region);
|
||||
return;
|
||||
}
|
||||
|
||||
cursor_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, cursor_image->width, cursor_image->height);
|
||||
|
||||
/* The pixel data (in typical Xlib breakage) is longs even on
|
||||
* 64-bit platforms, so we have to data-convert there. For simplicity,
|
||||
* just do it always
|
||||
*/
|
||||
data = cairo_image_surface_get_data (cursor_surface);
|
||||
stride = cairo_image_surface_get_stride (cursor_surface);
|
||||
for (i = 0; i < cursor_image->height; i++)
|
||||
for (j = 0; j < cursor_image->width; j++)
|
||||
*(guint32 *)(data + i * stride + 4 * j) = cursor_image->pixels[i * cursor_image->width + j];
|
||||
|
||||
cairo_surface_mark_dirty (cursor_surface);
|
||||
|
||||
cr = cairo_create (surface);
|
||||
cairo_set_source_surface (cr,
|
||||
cursor_surface,
|
||||
cursor_image->x - cursor_image->xhot - area.x,
|
||||
cursor_image->y - cursor_image->yhot - area.y);
|
||||
cairo_paint (cr);
|
||||
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_destroy (cursor_surface);
|
||||
cairo_region_destroy (screenshot_region);
|
||||
XFree (cursor_image);
|
||||
}
|
||||
|
||||
static void
|
||||
grab_screenshot (ClutterActor *stage,
|
||||
_screenshot_data *screenshot_data)
|
||||
@ -2003,6 +2058,9 @@ grab_screenshot (ClutterActor *stage,
|
||||
screenshot_data->screenshot_area.width = width;
|
||||
screenshot_data->screenshot_area.height = height;
|
||||
|
||||
if (screenshot_data->include_cursor)
|
||||
_draw_cursor_image (screenshot_data->image, screenshot_data->screenshot_area);
|
||||
|
||||
g_signal_handlers_disconnect_by_func (stage, (void *)grab_screenshot, (gpointer)screenshot_data);
|
||||
|
||||
result = g_simple_async_result_new (NULL, on_screenshot_written, (gpointer)screenshot_data, grab_screenshot);
|
||||
@ -2031,6 +2089,7 @@ grab_area_screenshot (ClutterActor *stage,
|
||||
/**
|
||||
* shell_global_screenshot:
|
||||
* @global: the #ShellGlobal
|
||||
* @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
|
||||
@ -2041,6 +2100,7 @@ grab_area_screenshot (ClutterActor *stage,
|
||||
*/
|
||||
void
|
||||
shell_global_screenshot (ShellGlobal *global,
|
||||
gboolean include_cursor,
|
||||
const char *filename,
|
||||
ShellGlobalScreenshotCallback callback)
|
||||
{
|
||||
@ -2050,6 +2110,7 @@ shell_global_screenshot (ShellGlobal *global,
|
||||
data->global = global;
|
||||
data->filename = g_strdup (filename);
|
||||
data->callback = callback;
|
||||
data->include_cursor = include_cursor;
|
||||
|
||||
stage = CLUTTER_ACTOR (meta_plugin_get_stage (global->plugin));
|
||||
|
||||
@ -2104,6 +2165,7 @@ shell_global_screenshot_area (ShellGlobal *global,
|
||||
* shell_global_screenshot_window:
|
||||
* @global: the #ShellGlobal
|
||||
* @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
|
||||
@ -2116,6 +2178,7 @@ shell_global_screenshot_area (ShellGlobal *global,
|
||||
void
|
||||
shell_global_screenshot_window (ShellGlobal *global,
|
||||
gboolean include_frame,
|
||||
gboolean include_cursor,
|
||||
const char *filename,
|
||||
ShellGlobalScreenshotCallback callback)
|
||||
{
|
||||
@ -2166,6 +2229,9 @@ shell_global_screenshot_window (ShellGlobal *global,
|
||||
stex = META_SHAPED_TEXTURE (meta_window_actor_get_texture (META_WINDOW_ACTOR (window_actor)));
|
||||
screenshot_data->image = meta_shaped_texture_get_image (stex, &clip);
|
||||
|
||||
if (include_cursor)
|
||||
_draw_cursor_image (screenshot_data->image, screenshot_data->screenshot_area);
|
||||
|
||||
result = g_simple_async_result_new (NULL, on_screenshot_written, (gpointer)screenshot_data, shell_global_screenshot_window);
|
||||
g_simple_async_result_run_in_thread (result, write_screenshot_thread, G_PRIORITY_DEFAULT, NULL);
|
||||
g_object_unref (result);
|
||||
|
@ -154,10 +154,12 @@ void shell_global_screenshot_area (ShellGlobal *global,
|
||||
|
||||
void shell_global_screenshot_window (ShellGlobal *global,
|
||||
gboolean include_frame,
|
||||
gboolean include_cursor,
|
||||
const char *filename,
|
||||
ShellGlobalScreenshotCallback callback);
|
||||
|
||||
void shell_global_screenshot (ShellGlobal *global,
|
||||
gboolean include_cursor,
|
||||
const char *filename,
|
||||
ShellGlobalScreenshotCallback callback);
|
||||
typedef enum {
|
||||
|
Loading…
Reference in New Issue
Block a user