Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined workspace settings handling #188

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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}`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything which prevents us from using Workspace ${i} here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, as long as the list is "monotonic" (which it is atm.) that would also work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I'd vote for Workspace n in that case, as that makes it clearer that it's a workspace related.

return [uuid, settings];
}

Expand Down
7 changes: 5 additions & 2 deletions tiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,11 @@ box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, .7);
this.label.hide();
}
let name = this.settings.get_string('name');
if (name === '')
name = Meta.prefs_get_workspace_name(this.workspace.index());
if (name === '') {
// This should usually not happen as we assign a name when a workspace is created
// IMPROVEMENT: If static workspaces are used it would make sense to simply use "Workspace ${index}"
name = "Unnamed";
}
Meta.prefs_change_workspace_name(this.workspace.index(), name);
this.label.text = name;
this.name = name;
Expand Down