[gnome-shell] screenshot: Add include_cursor parameter
- From: Adel Gadllah <agadllah src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] screenshot: Add include_cursor parameter
- Date: Tue, 14 Feb 2012 20:08:48 +0000 (UTC)
commit b2ec340f9e2770fa91a939a08b61c43763cf5cef
Author: Adel Gadllah <adel gadllah gmail com>
Date: Tue Feb 14 19:24:41 2012 +0100
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
js/ui/shellDBus.js | 15 +++++++--
src/shell-global-private.h | 2 +
src/shell-global.c | 66 ++++++++++++++++++++++++++++++++++++++++++++
src/shell-global.h | 2 +
4 files changed, 81 insertions(+), 4 deletions(-)
---
diff --git a/js/ui/shellDBus.js b/js/ui/shellDBus.js
index f74e822..96c75f1 100644
--- a/js/ui/shellDBus.js
+++ b/js/ui/shellDBus.js
@@ -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));
},
diff --git a/src/shell-global-private.h b/src/shell-global-private.h
index 5f2faf8..27e7829 100644
--- a/src/shell-global-private.h
+++ b/src/shell-global-private.h
@@ -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;
diff --git a/src/shell-global.c b/src/shell-global.c
index 2e7e200..8588f37 100644
--- a/src/shell-global.c
+++ b/src/shell-global.c
@@ -1949,6 +1949,61 @@ do_grab_screenshot (_screenshot_data *screenshot_data,
}
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);
diff --git a/src/shell-global.h b/src/shell-global.h
index 6456c9e..7e83451 100644
--- a/src/shell-global.h
+++ b/src/shell-global.h
@@ -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 {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]