2013-05-06 16:50:31 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Shell = imports.gi.Shell;
|
2013-07-17 19:26:06 +00:00
|
|
|
const Signals = imports.signals;
|
2013-05-06 16:50:31 +00:00
|
|
|
|
|
|
|
const Hash = imports.misc.hash;
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
2013-10-24 21:51:58 +00:00
|
|
|
const ScreencastIface = '<node> \
|
|
|
|
<interface name="org.gnome.Shell.Screencast"> \
|
|
|
|
<method name="Screencast"> \
|
|
|
|
<arg type="s" direction="in" name="file_template"/> \
|
|
|
|
<arg type="a{sv}" direction="in" name="options"/> \
|
|
|
|
<arg type="b" direction="out" name="success"/> \
|
|
|
|
<arg type="s" direction="out" name="filename_used"/> \
|
|
|
|
</method> \
|
|
|
|
<method name="ScreencastArea"> \
|
|
|
|
<arg type="i" direction="in" name="x"/> \
|
|
|
|
<arg type="i" direction="in" name="y"/> \
|
|
|
|
<arg type="i" direction="in" name="width"/> \
|
|
|
|
<arg type="i" direction="in" name="height"/> \
|
|
|
|
<arg type="s" direction="in" name="file_template"/> \
|
|
|
|
<arg type="a{sv}" direction="in" name="options"/> \
|
|
|
|
<arg type="b" direction="out" name="success"/> \
|
|
|
|
<arg type="s" direction="out" name="filename_used"/> \
|
|
|
|
</method> \
|
|
|
|
<method name="StopScreencast"> \
|
|
|
|
<arg type="b" direction="out" name="success"/> \
|
|
|
|
</method> \
|
|
|
|
</interface> \
|
|
|
|
</node>';
|
2013-05-06 16:50:31 +00:00
|
|
|
|
|
|
|
const ScreencastService = new Lang.Class({
|
|
|
|
Name: 'ScreencastService',
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(ScreencastIface, this);
|
|
|
|
this._dbusImpl.export(Gio.DBus.session, '/org/gnome/Shell/Screencast');
|
|
|
|
|
|
|
|
Gio.DBus.session.own_name('org.gnome.Shell.Screencast', Gio.BusNameOwnerFlags.REPLACE, null, null);
|
|
|
|
|
|
|
|
this._recorders = new Hash.Map();
|
|
|
|
|
2013-07-17 19:24:20 +00:00
|
|
|
Main.sessionMode.connect('updated', Lang.bind(this, this._sessionUpdated));
|
2013-05-06 16:50:31 +00:00
|
|
|
},
|
|
|
|
|
2013-07-17 19:26:06 +00:00
|
|
|
get isRecording() {
|
|
|
|
return this._recorders.size() > 0;
|
|
|
|
},
|
|
|
|
|
2013-05-06 16:50:31 +00:00
|
|
|
_ensureRecorderForSender: function(sender) {
|
|
|
|
let recorder = this._recorders.get(sender);
|
|
|
|
if (!recorder) {
|
2013-08-14 08:34:58 +00:00
|
|
|
recorder = new Shell.Recorder({ stage: global.stage,
|
|
|
|
screen: global.screen });
|
2013-05-06 16:50:31 +00:00
|
|
|
recorder._watchNameId =
|
|
|
|
Gio.bus_watch_name(Gio.BusType.SESSION, sender, 0, null,
|
|
|
|
Lang.bind(this, this._onNameVanished));
|
|
|
|
this._recorders.set(sender, recorder);
|
2013-07-17 19:26:06 +00:00
|
|
|
this.emit('updated');
|
2013-05-06 16:50:31 +00:00
|
|
|
}
|
|
|
|
return recorder;
|
|
|
|
},
|
|
|
|
|
2013-07-17 19:24:20 +00:00
|
|
|
_sessionUpdated: function() {
|
2013-05-06 16:50:31 +00:00
|
|
|
if (Main.sessionMode.allowScreencast)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (let sender in this._recorders.keys())
|
|
|
|
this._recorders.delete(sender);
|
2013-07-17 19:26:06 +00:00
|
|
|
this.emit('updated');
|
2013-05-06 16:50:31 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onNameVanished: function(connection, name) {
|
|
|
|
this._stopRecordingForSender(name);
|
|
|
|
},
|
|
|
|
|
|
|
|
_stopRecordingForSender: function(sender) {
|
|
|
|
let recorder = this._recorders.get(sender);
|
|
|
|
if (!recorder)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Gio.bus_unwatch_name(recorder._watchNameId);
|
|
|
|
recorder.close();
|
|
|
|
this._recorders.delete(sender);
|
2013-07-17 19:26:06 +00:00
|
|
|
this.emit('updated');
|
2013-05-06 16:50:31 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
_applyOptionalParameters: function(recorder, options) {
|
|
|
|
for (let option in options)
|
|
|
|
options[option] = options[option].deep_unpack();
|
|
|
|
|
|
|
|
if (options['pipeline'])
|
|
|
|
recorder.set_pipeline(options['pipeline']);
|
|
|
|
if (options['framerate'])
|
|
|
|
recorder.set_framerate(options['framerate']);
|
|
|
|
if (options['draw-cursor'])
|
|
|
|
recorder.set_draw_cursor(options['draw-cursor']);
|
|
|
|
},
|
|
|
|
|
|
|
|
ScreencastAsync: function(params, invocation) {
|
|
|
|
let returnValue = [false, ''];
|
|
|
|
if (!Main.sessionMode.allowScreencast)
|
|
|
|
invocation.return_value(GLib.Variant.new('(bs)', returnValue));
|
|
|
|
|
|
|
|
let sender = invocation.get_sender();
|
|
|
|
let recorder = this._ensureRecorderForSender(sender);
|
|
|
|
if (!recorder.is_recording()) {
|
|
|
|
let [fileTemplate, options] = params;
|
|
|
|
|
|
|
|
recorder.set_file_template(fileTemplate);
|
|
|
|
this._applyOptionalParameters(recorder, options);
|
2013-05-22 14:42:00 +00:00
|
|
|
let [success, fileName] = recorder.record();
|
|
|
|
returnValue = [success, fileName ? fileName : ''];
|
2013-05-06 16:50:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
invocation.return_value(GLib.Variant.new('(bs)', returnValue));
|
|
|
|
},
|
|
|
|
|
|
|
|
ScreencastAreaAsync: function(params, invocation) {
|
|
|
|
let returnValue = [false, ''];
|
|
|
|
if (!Main.sessionMode.allowScreencast)
|
|
|
|
invocation.return_value(GLib.Variant.new('(bs)', returnValue));
|
|
|
|
|
|
|
|
let sender = invocation.get_sender();
|
|
|
|
let recorder = this._ensureRecorderForSender(sender);
|
|
|
|
|
|
|
|
if (!recorder.is_recording()) {
|
|
|
|
let [x, y, width, height, fileTemplate, options] = params;
|
|
|
|
|
|
|
|
recorder.set_file_template(fileTemplate);
|
|
|
|
recorder.set_area(x, y, width, height);
|
|
|
|
this._applyOptionalParameters(recorder, options);
|
2013-05-22 14:42:00 +00:00
|
|
|
let [success, fileName] = recorder.record();
|
|
|
|
returnValue = [success, fileName ? fileName : ''];
|
2013-05-06 16:50:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
invocation.return_value(GLib.Variant.new('(bs)', returnValue));
|
|
|
|
},
|
|
|
|
|
|
|
|
StopScreencastAsync: function(params, invocation) {
|
|
|
|
let success = this._stopRecordingForSender(invocation.get_sender());
|
|
|
|
invocation.return_value(GLib.Variant.new('(b)', [success]));
|
|
|
|
}
|
|
|
|
});
|
2013-07-17 19:26:06 +00:00
|
|
|
Signals.addSignalMethods(ScreencastService.prototype);
|