File: screenRecorder.js

package info (click to toggle)
cinnamon 6.4.13-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,304 kB
  • sloc: javascript: 54,298; ansic: 51,499; python: 21,971; xml: 2,803; sh: 96; makefile: 27; perl: 13
file content (91 lines) | stat: -rw-r--r-- 2,511 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-

const Cinnamon = imports.gi.Cinnamon;
const Meta = imports.gi.Meta;
const Signals = imports.signals;
const Gio = imports.gi.Gio;
const Main = imports.ui.main;

var ScreenRecorder = class ScreenRecorder {
    constructor() {
        this.recorder = null;
        this.recorderSettings = new Gio.Settings({ schema_id: 'org.cinnamon.recorder' });

        Meta.keybindings_set_custom_handler('toggle-recording', () => this.toggle_recording());
    }

    get recording() {
        if (this.recorder === null) {
            return false;
        }
        return this.recorder.is_recording();
    }

    set recording(record) {
        if (record) {
            this._start_recording();
        }
        else
        {
            this._stop_recording();
        }
    }

    _ensure_recorder() {
        if (this.recorder === null) {
            this.recorder = new Cinnamon.Recorder({ stage: global.stage, display: global.display });
        }
    }

    _start_recording() {
        this._ensure_recorder();

        if (this.recorder.is_recording()) {
            return;
        }

        // read the parameters from GSettings always in case they have changed
        this.recorder.set_framerate(this.recorderSettings.get_int('framerate'));
        this.recorder.set_file_template('cinnamon-%Y-%m-%dT%H%M%S%z.' + this.recorderSettings.get_string('file-extension'));
        let pipeline = this.recorderSettings.get_string('pipeline');

        if (Main.layoutManager.monitors.length > 1) {
            let {x, y, width, height} = Main.layoutManager.primaryMonitor;
            this.recorder.set_area(x, y, width, height);
        }

        if (!pipeline.match(/^\s*$/))
            this.recorder.set_pipeline(pipeline);
        else
            this.recorder.set_pipeline(null);

        Meta.disable_unredirect_for_display(global.display);
        this.recorder.record();

        this.emit("recording", true);
    }

    _stop_recording() {
        if (this.recorder === null) {
            return;
        }

        if (this.recorder.is_recording()) {
            this.recorder.close();
            Meta.enable_unredirect_for_display(global.display);
        }

        this.emit("recording", false);
    }

    toggle_recording() {
        if (this.recording) {
            this._stop_recording();
        }
        else
        {
            this._start_recording();
        }
    }
}
Signals.addSignalMethods(ScreenRecorder.prototype);