-
Notifications
You must be signed in to change notification settings - Fork 13
/
gnomesome_settings.js
127 lines (116 loc) · 3.76 KB
/
gnomesome_settings.js
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
const Gio = imports.gi.Gio;
const Glib = imports.gi.GLib;
const Config = imports.misc.config;
const ExtensionUtils = imports.misc.extensionUtils;
const Ext = ExtensionUtils.getCurrentExtension();
const GnomesomeSettingsConvenience = Ext.imports.convenience;
const SCHEMA_ROOT = 'org.gnome.shell.extensions.gnomesome';
const KEYBINDINGS = SCHEMA_ROOT + '.keybindings';
const PREFS = SCHEMA_ROOT + '.prefs';
function envp_with_gnomesome_xdg_data_dir() {
var xdg_data_base = Ext.dir.get_child('data');
if(!xdg_data_base.query_exists(null)) {
return null;
}
xdg_data_base = xdg_data_base.get_path();
var XDG_DATA_DIRS = 'XDG_DATA_DIRS';
var old_xdg_data = Glib.getenv(XDG_DATA_DIRS);
var new_xdg_data = null;
if(old_xdg_data != null) {
var entries = old_xdg_data.split(':');
if(entries.indexOf(xdg_data_base) == -1) {
new_xdg_data = old_xdg_data + ':' + xdg_data_base;
}
} else {
var default_xdg = "/usr/local/share/:/usr/share/";
new_xdg_data = default_xdg + ":" + xdg_data_base;
}
//TODO: so much effort to modify one key in the environment,
// surely there is an easier way...
var strings = [];
strings.push(XDG_DATA_DIRS + '=' + new_xdg_data);
var keys = Glib.listenv();
for(var i in keys) {
var key = keys[i];
if(key == XDG_DATA_DIRS) continue;
var val = Glib.getenv(key);
strings.push(key + '=' + val);
};
return strings;
};
function get_local_gsettings(schema_path) {
return GnomesomeSettingsConvenience.getSettings(schema_path);
};
function Keybindings() {
var self = this;
var settings = this.settings = get_local_gsettings(KEYBINDINGS);
this.each = function(fn, ctx) {
var keys = settings.list_children();
for (var i=0; i < keys.length; i++) {
var key = keys[i];
var setting = {
key: key,
get: function() { return settings.get_string_array(key); },
set: function(v) { settings.set_string_array(key, v); },
};
fn.call(ctx, setting);
}
};
};
function settingsLoader(path) {
var settings = get_local_gsettings(PREFS);
return {
settings: settings,
get_boolean: function() { return settings.get_boolean(this.key); },
set_boolean: function(v) { settings.set_boolean(this.key, v); },
get_int: function() { return settings.get_int(this.key); },
set_int: function(v) { settings.set_int(this.key, v); },
get_string: function() { return settings.get_string(this.key); },
set_string: function(v) { settings.set_string(this.key, v); }
}
}
function Prefs() {
var self = this;
let l = settingsLoader(PREFS);
var settings = this.settings = l.settings;
this.SHOW_INDICATOR = {
key: 'show-indicator',
gsettings: settings,
get: l.get_boolean,
set: l.set_boolean,
};
this.DEFAULT_LAYOUT = {
key: 'default-layout',
gsettings: settings,
get: l.get_string,
set: l.set_string,
};
this.LAUNCH_TERMINAL = {
key: 'launch-terminal',
gsettings: settings,
get: l.get_string,
set: l.set_string,
};
this.OUTER_GAPS = {
key: 'outer-gaps',
gsettings: settings,
get: l.get_int,
set: l.set_int,
};
this.INNER_GAPS = {
key: 'inner-gaps',
gsettings: settings,
get: l.get_int,
set: l.set_int,
};
this.POINTER_FOLLOWS_FOCUS = {
key: 'pointer-follows-focus',
gsettings: settings,
get: l.get_boolean,
set: l.set_boolean,
};
};
function initTranslations(domain) {
GnomesomeSettingsConvenience.initTranslations(domain);
}
var prefs = new Prefs();