File: backgroundManager.js

package info (click to toggle)
cinnamon 6.4.13-2
  • links: PTS, VCS
  • area: main
  • in suites: 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 (132 lines) | stat: -rw-r--r-- 5,487 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// -*- mode: js2; indent-tabs-mode: nil; js2-basic-offset: 4 -*-

const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Meta = imports.gi.Meta;

const LOGGING = false;

var BackgroundManager = class {
    constructor() {
        let schema = Gio.SettingsSchemaSource.get_default();
        if (!schema.lookup("org.gnome.desktop.background", true))
            return

        this._gnomeSettings = new Gio.Settings({ schema_id: "org.gnome.desktop.background" });
        this._cinnamonSettings = new Gio.Settings({ schema_id: "org.cinnamon.desktop.background" });

        this.color_shading_type = this._gnomeSettings.get_string("color-shading-type");
        this._gnomeSettings.connect("changed::color-shading-type", Lang.bind(this, this._onColorShadingTypeChanged));

        this.picture_options = this._gnomeSettings.get_string("picture-options");
        this._gnomeSettings.connect("changed::picture-options", Lang.bind(this, this._onPictureOptionsChanged));

        this.picture_uri = this._gnomeSettings.get_string("picture-uri");
        this._gnomeSettings.connect("changed::picture-uri", Lang.bind(this, this._onPictureURIChanged));

        this.primary_color = this._gnomeSettings.get_string("primary-color");
        this._gnomeSettings.connect("changed::primary-color", Lang.bind(this, this._onPrimaryColorChanged));

        this.secondary_color = this._gnomeSettings.get_string("secondary-color");
        this._gnomeSettings.connect("changed::secondary-color", Lang.bind(this, this._onSecondaryColorChanged));

        this.picture_opacity = this._gnomeSettings.get_int("picture-opacity");
        this._gnomeSettings.connect("changed::picture-opacity", Lang.bind(this, this._onPictureOpacityChanged));
    }

    showBackground() {
        if (Meta.is_wayland_compositor()) {
            global.bottom_window_group.show();
        }
        else {
            global.background_actor.show();
        }
    }

    hideBackground() {
        if (Meta.is_wayland_compositor()) {
            global.bottom_window_group.hide();
        }
        else {
            global.background_actor.hide();
        }
    }

    _onColorShadingTypeChanged(schema, key) {
        let oldValue = this.color_shading_type
        let newValue = this._gnomeSettings.get_string(key);
        if (oldValue != newValue) {
            let cinnamonValue = this._cinnamonSettings.get_string(key);
            if (cinnamonValue != newValue) {
                if (LOGGING) global.log("BackgroundManager: %s changed (%s --> %s)".format(key, oldValue, newValue));
                this._cinnamonSettings.set_string(key, newValue);
            }
            this.color_shading_type = newValue;
        }
    }

    _onPictureOptionsChanged(schema, key) {
        let oldValue = this.picture_options
        let newValue = this._gnomeSettings.get_string(key);
        if (oldValue != newValue) {
            let cinnamonValue = this._cinnamonSettings.get_string(key);
            if (cinnamonValue != newValue) {
                if (LOGGING) global.log("BackgroundManager: %s changed (%s --> %s)".format(key, oldValue, newValue));
                this._cinnamonSettings.set_string(key, newValue);
            }
            this.picture_options = newValue;
        }
    }

    _onPictureURIChanged(schema, key) {
        let oldValue = this.picture_uri
        let newValue = this._gnomeSettings.get_string(key);
        if (oldValue != newValue) {
            let cinnamonValue = this._cinnamonSettings.get_string(key);
            if (cinnamonValue != newValue) {
                if (LOGGING) global.log("BackgroundManager: %s changed (%s --> %s)".format(key, oldValue, newValue));
                this._cinnamonSettings.set_string(key, newValue);
            }
            this.picture_uri = newValue;
        }
    }

    _onPrimaryColorChanged(schema, key) {
        let oldValue = this.primary_color
        let newValue = this._gnomeSettings.get_string(key);
        if (oldValue != newValue) {
            let cinnamonValue = this._cinnamonSettings.get_string(key);
            if (cinnamonValue != newValue) {
                if (LOGGING) global.log("BackgroundManager: %s changed (%s --> %s)".format(key, oldValue, newValue));
                this._cinnamonSettings.set_string(key, newValue);
            }
            this.primary_color = newValue;
        }
    }

    _onSecondaryColorChanged(schema, key) {
        let oldValue = this.secondary_color
        let newValue = this._gnomeSettings.get_string(key);
        if (oldValue != newValue) {
            let cinnamonValue = this._cinnamonSettings.get_string(key);
            if (cinnamonValue != newValue) {
                if (LOGGING) global.log("BackgroundManager: %s changed (%s --> %s)".format(key, oldValue, newValue));
                this._cinnamonSettings.set_string(key, newValue);
            }
            this.secondary_color = newValue;
        }
    }

    _onPictureOpacityChanged(schema, key) {
        let oldValue = this.picture_opacity
        let newValue = this._gnomeSettings.get_int(key);
        if (oldValue != newValue) {
            let cinnamonValue = this._cinnamonSettings.get_int(key);
            if (cinnamonValue != newValue) {
                if (LOGGING) global.log("BackgroundManager: %s changed (%s --> %s)".format(key, oldValue, newValue));
                this._cinnamonSettings.set_int(key, newValue);
            }
            this.picture_opacity = newValue;
        }
    }
};