Repository navigation
Expand file tree
/
Copy pathcommon.js
More file actions
171 lines (159 loc) · 4.01 KB
/
Copy pathcommon.js
File metadata and controls
171 lines (159 loc) · 4.01 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
"use strict";
export const SECONDS_PER_HOUR = 3600;
// D-Bus constants
export const DBUS_NAME = "org.gnome.shell.extensions.SmartAutoMove";
export const DBUS_PATH = "/org/gnome/shell/extensions/SmartAutoMove";
export const DBUS_INTERFACE = `
<node>
<interface name="org.gnome.shell.extensions.SmartAutoMove">
<method name="ListWindows">
<arg type="s" direction="out" name="windows_json"/>
</method>
<method name="RefreshFromCurrentActors">
</method>
</interface>
</node>
`;
// Settings constants for prefs.js
export const SETTINGS_KEY_DEBUG_LOGGING = "debug-logging";
export const SETTINGS_KEY_CONFIG_VERSION = "config-version";
export const SETTINGS_KEY_SAVED_WINDOWS = "saved-windows";
export const SETTINGS_KEY_OVERRIDES = "overrides";
export const SETTINGS_KEY_MATCH_THRESHOLD = "match-threshold";
// Sync mode constants
export const SYNC_MODE_IGNORE = 0;
export const SYNC_MODE_RESTORE = 1;
export const SYNC_MODE_DEFAULT = "DEFAULT";
// Settings configuration for prefs.js binding
export const SETTINGS_CONFIG = [
{
key: "debug-logging",
property: "active",
widgetId: "debug-logging-switch",
},
{
key: "new-window-max-wait-ms",
property: "value",
widgetId: "new-window-max-wait-spin",
},
{
key: "new-window-title-stability-ms",
property: "value",
widgetId: "new-window-title-stability-spin",
},
{
key: "generic-title-max-length",
property: "value",
widgetId: "generic-title-max-length-spin",
},
{
key: "ambiguity-threshold",
property: "value",
widgetId: "ambiguity-threshold-generic-spin",
},
{
key: "min-score-spread",
property: "value",
widgetId: "min-score-spread-spin",
},
{
key: "generic-title-extended-wait",
property: "value",
widgetId: "generic-title-extended-wait-spin",
},
{
key: "max-unseen-age",
property: "value",
widgetId: "max-unseen-age-spin",
},
{
key: "match-threshold",
property: "value",
widgetId: "match-threshold-spin",
},
{
key: "sync-mode",
property: "active-id",
widgetId: "sync-mode-combo",
},
{
key: "freeze-saves",
property: "active",
widgetId: "freeze-saves-switch",
},
{
key: "activate-workspace",
property: "active",
widgetId: "activate-workspace-switch",
},
{
key: "ignore-position",
property: "active",
widgetId: "ignore-position-switch",
},
{
key: "ignore-workspace",
property: "active",
widgetId: "ignore-workspace-switch",
},
{
key: "ignore-monitor",
property: "active",
widgetId: "ignore-monitor-switch",
},
];
export function getActionId(action) {
if (action === SYNC_MODE_IGNORE || action === "IGNORE") return "IGNORE";
if (action === SYNC_MODE_RESTORE || action === "RESTORE") return "RESTORE";
return "DEFAULT";
}
export function parseOverrides(overridesStr) {
let parsed;
try {
parsed = JSON.parse(overridesStr || "{}");
} catch (e) {
return {};
}
// normalize every value to an array of rules: prefs.js and the matcher both
// expect arrays, but a value may be a single rule object (legacy/convenience
// form written by the test harness or hand-edited dconf).
for (const wsh of Object.keys(parsed)) {
if (!Array.isArray(parsed[wsh])) {
parsed[wsh] = parsed[wsh] ? [parsed[wsh]] : [];
}
}
return parsed;
}
export function deleteNonOccupiedWindows(savedWindows) {
Object.keys(savedWindows).forEach((wsh) => {
savedWindows[wsh] = savedWindows[wsh].filter((sw) => sw.occupied);
if (savedWindows[wsh].length === 0) {
delete savedWindows[wsh];
}
});
}
export function ignoreSavedWindow(
savedWindows,
overrides,
wsh,
swi,
threshold,
ignoreAny,
) {
if (!savedWindows[wsh] || !savedWindows[wsh][swi]) return;
const sw = savedWindows[wsh][swi];
if (!overrides[wsh]) {
overrides[wsh] = [];
}
if (ignoreAny) {
overrides[wsh].push({
action: "IGNORE",
threshold: threshold,
});
} else {
overrides[wsh].unshift({
title: sw.title,
action: "IGNORE",
});
}
}