mirror of
https://github.com/gosticks/PaperWM.git
synced 2026-08-11 19:50:28 +00:00
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:
+19
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user