Skip to content

Commit

Permalink
Merge pull request #1016 from rjanja/capture-improvements
Browse files Browse the repository at this point in the history
Add improved screenshot functions
  • Loading branch information
clefebvre committed Sep 5, 2012
2 parents 8a876d9 + 5ee3398 commit ed43c97
Show file tree
Hide file tree
Showing 10 changed files with 814 additions and 271 deletions.
63 changes: 51 additions & 12 deletions js/ui/cinnamonDBus.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Lang = imports.lang;

const Config = imports.misc.config;
const ExtensionSystem = imports.ui.extensionSystem;
const Flashspot = imports.ui.flashspot;
const Main = imports.ui.main;

const CinnamonIface = {
Expand All @@ -26,16 +27,21 @@ const CinnamonIface = {
outSignature: 'as'
},
{ name: 'ScreenshotArea',
inSignature: 'iiiis',
outSignature: 'b'
inSignature: 'biiiibs',
outSignature: ''
},
{ name: 'ScreenshotWindow',
inSignature: 'bs',
outSignature: 'b'
inSignature: 'bbbs',
outSignature: ''
},
{ name: 'Screenshot',
inSignature: 's',
outSignature: 'b'
inSignature: 'bbs',
outSignature: ''
},
{
name: 'FlashArea',
inSignature: 'iiii',
outSignature: ''
},
{ name: 'EnableExtension',
inSignature: 's',
Expand Down Expand Up @@ -108,48 +114,81 @@ Cinnamon.prototype = {
return [success, returnValue];
},

_onScreenshotComplete: function(obj, result, area, flash, invocation) {
if (flash) {
let flashspot = new Flashspot.Flashspot(area);
flashspot.fire();
}

let retval = GLib.Variant.new('(b)', [result]);
invocation.return_value(retval);
},

/**
* ScreenshotArea:
* @include_cursor: Whether to include the mouse cursor
* @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
* @flash: Whether to flash the edges of area
* @filename: The filename for the screenshot
*
* Takes a screenshot of the passed in area and saves it
* in @filename as png image, it returns a boolean
* indicating whether the operation was successful or not.
*
*/
ScreenshotAreaAsync : function (x, y, width, height, filename, callback) {
global.screenshot_area (x, y, width, height, filename, function (obj, result) { callback(result); });
ScreenshotAreaAsync : function (params, invocation) {
let [include_cursor, x, y, width, height, flash, filename, callback] = params;
let screenshot = new Cinnamon.Screenshot();
screenshot.screenshot_area (include_cursor, x, y, width, height, filename,
Lang.bind(this, this._onScreenshotComplete,
flash, invocation));
},

/**
* ScreenshotWindow:
* @include_frame: Whether to include the frame or not
* @include_cursor: Whether to include the mouse cursor
* @flash: Whether to flash the edges of the window
* @filename: The filename for the screenshot
*
* Takes a screenshot of the focused window (optionally omitting the frame)
* and saves it in @filename as png image, it returns a boolean
* indicating whether the operation was successful or not.
*
*/
ScreenshotWindow : function (include_frame, filename) {
return global.screenshot_window (include_frame, filename);
ScreenshotWindowAsync : function (params, invocation) {
let [include_frame, include_cursor, flash, filename] = params;
let screenshot = new Cinnamon.Screenshot();
screenshot.screenshot_window (include_frame, include_cursor, filename,
Lang.bind(this, this._onScreenshotComplete,
flash, invocation));
},

/**
* Screenshot:
* @include_cursor: Whether to include the mouse cursor
* @flash: Whether to flash the edges of the screen
* @filename: The filename for the screenshot
*
* Takes a screenshot of the whole screen and saves it
* in @filename as png image, it returns a boolean
* indicating whether the operation was successful or not.
*
*/
ScreenshotAsync : function (filename, callback) {
global.screenshot(filename, function (obj, result) { callback(result); });
ScreenshotAsync : function (params, invocation) {
let [include_cursor, flash, filename] = params;
let screenshot = new Cinnamon.Screenshot();
screenshot.screenshot(include_cursor, filename,
Lang.bind(this, this._onScreenshotComplete,
flash, invocation));
},

FlashArea: function(x, y, width, height) {
let flashspot = new Flashspot.Flashspot({ x : x, y : y, width: width, height: height});
flashspot.fire();
},

ListExtensions: function() {
Expand Down
49 changes: 49 additions & 0 deletions js/ui/flashspot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-

const Lang = imports.lang;

const Lightbox = imports.ui.lightbox;
const Main = imports.ui.main;
const Tweener = imports.ui.tweener;

const FLASHSPOT_ANIMATION_TIME = 0.15; // seconds

function Flashspot(area) {
this._init(area);
}
Flashspot.prototype = {
__proto__: Lightbox.Lightbox.prototype,

_init: function(area) {
Lightbox.Lightbox.prototype._init.call(this, Main.uiGroup, {
inhibitEvents: true,
width: area.width,
height: area.height
});
this.actor.style_class = 'flashspot';
this.actor.set_position(area.x, area.y);
},

fire: function() {
this.actor.opacity = 0;
Tweener.addTween(this.actor,
{ opacity: 255,
time: FLASHSPOT_ANIMATION_TIME,
transition: 'linear',
onComplete: Lang.bind(this, this._onFireShowComplete)
});
this.actor.show();
},

_onFireShowComplete: function() {
Tweener.addTween(this.actor,
{ opacity: 0,
time: FLASHSPOT_ANIMATION_TIME,
transition: 'linear',
onComplete: Lang.bind(this, function() {
this.destroy();
})
});
}
};

4 changes: 4 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ cinnamon_public_headers_h = \
cinnamon-mount-operation.h \
cinnamon-network-agent.h \
cinnamon-perf-log.h \
cinnamon-screenshot.h \
cinnamon-screen-grabber.h \
cinnamon-slicer.h \
cinnamon-stack.h \
cinnamon-tray-icon.h \
Expand Down Expand Up @@ -151,6 +153,8 @@ libcinnamon_la_SOURCES = \
cinnamon-perf-log.c \
cinnamon-polkit-authentication-agent.h \
cinnamon-polkit-authentication-agent.c \
cinnamon-screenshot.c \
cinnamon-screen-grabber.c \
cinnamon-slicer.c \
cinnamon-stack.c \
cinnamon-tray-icon.c \
Expand Down
14 changes: 0 additions & 14 deletions src/cinnamon-global-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,4 @@ GjsContext *_cinnamon_global_get_gjs_context (CinnamonGlobal *global);
gboolean _cinnamon_global_check_xdnd_event (CinnamonGlobal *global,
XEvent *xev);

/* Used for async screenshot grabbing */
typedef struct _screenshot_data {
CinnamonGlobal *global;

char *filename;

int x;
int y;
int width;
int height;

CinnamonGlobalScreenshotCallback callback;
} _screenshot_data;

#endif /* __CINNAMON_GLOBAL_PRIVATE_H__ */
Loading

0 comments on commit ed43c97

Please sign in to comment.