settings: assign a name and color on new workspace settings

"Unidentified" workspace settings can behave strangely when cycling
settings (and especially if dynamic workspaces is used)
This commit is contained in:
Ole Jørgen Brønner
2019-10-17 20:57:57 +02:00
parent 0ce41886a0
commit 0f89db1af1
+19
View File
@@ -114,6 +114,22 @@ function disable() {
/// Workspaces
function getUnusedColor() {
function workspaceColors() {
let list = workspaceList.get_strv('list');
return new Set(list.map(getWorkspaceSettingsByUUID).map(s => s.get_string('color')))
}
let palette = settings.get_strv('workspace-colors');
let usedColors = workspaceColors();
for (let color of palette) {
if (!usedColors.has(color)) {
return color;
}
}
return palette[Math.floor(Math.random()*palette.length)];
}
function getWorkspaceSettings(index) {
let list = workspaceList.get_strv('list');
@@ -133,6 +149,9 @@ function getNewWorkspaceSettings(index) {
list.push(uuid);
workspaceList.set_strv('list', list);
settings.set_int('index', index);
settings.set_string('color', getUnusedColor());
let n = findWorkspaceSettingsByName(/^Unnamed .*/).length;
settings.set_string(`Unnamed ${n+1}`)
return [uuid, settings];
}