tiling: Move cycle to Tiling.cycleWorkspaceSettings

This commit is contained in:
Tor Hedin Brønner
2019-10-21 12:47:39 +02:00
parent 384dd6dab6
commit 4cfe445477
2 changed files with 45 additions and 44 deletions
+2 -44
View File
@@ -115,55 +115,13 @@ function cycleWorkspaceSettings(binding = "<Super>q") {
var Settings = Extension.imports.settings;
var Utils = Extension.imports.utils;
function rotated(list, dir=1) {
return [].concat(
list.slice(dir),
list.slice(0, dir)
);
}
function cycle(mw, dir=1) {
let n = global.workspace_manager.get_n_workspaces();
let N = Settings.workspaceList.get_strv('list').length;
let space = Tiling.spaces.selectedSpace;
let wsI = space.workspace.index();
// 2 6 7 8 <-- indices
// x a b c <-- settings
// a b c x <-- rotated settings
let uuids = Settings.workspaceList.get_strv('list');
// Work on tuples of [uuid, settings] since we need to uuid association
// in the last step
let settings = uuids.map(
uuid => [uuid, Settings.getWorkspaceSettingsByUUID(uuid)]
);
settings.sort((a, b) => a[1].get_int('index') - b[1].get_int('index'));
let unbound = settings.slice(n);
let strip = [settings[wsI]].concat(unbound);
strip = rotated(strip, dir);
let nextSettings = strip[0];
unbound = strip.slice(1);
nextSettings[1].set_int('index', wsI);
space.setSettings(nextSettings); // ASSUMPTION: ok that two settings have same index here
// Re-assign unbound indices:
for (let i = n; i < N; i++) {
unbound[i-n][1].set_int('index', i);
}
}
Keybindings.bindkey(
binding, "next-space-setting",
mw => cycle(mw, -1), { activeInNavigator: true }
mw => Tiling.cycleWorkspaceSettings(-1), { activeInNavigator: true }
);
Keybindings.bindkey(
"<Shift>"+binding, "prev-space-setting",
mw => cycle(mw, 1), { activeInNavigator: true }
mw => Tiling.cycleWorkspaceSettings(1), { activeInNavigator: true }
);
}
+43
View File
@@ -2891,6 +2891,49 @@ function sortWindows(space, windows) {
.map(c => c.meta_window);
}
function rotated(list, dir=1) {
return [].concat(
list.slice(dir),
list.slice(0, dir)
);
}
function cycleWorkspaceSettings(dir=1) {
let n = workspaceManager.get_n_workspaces();
let N = Settings.workspaceList.get_strv('list').length;
let space = spaces.selectedSpace;
let wsI = space.workspace.index();
// 2 6 7 8 <-- indices
// x a b c <-- settings
// a b c x <-- rotated settings
let uuids = Settings.workspaceList.get_strv('list');
// Work on tuples of [uuid, settings] since we need to uuid association
// in the last step
let settings = uuids.map(
uuid => [uuid, Settings.getWorkspaceSettingsByUUID(uuid)]
);
settings.sort((a, b) => a[1].get_int('index') - b[1].get_int('index'));
let unbound = settings.slice(n);
let strip = [settings[wsI]].concat(unbound);
strip = rotated(strip, dir);
let nextSettings = strip[0];
unbound = strip.slice(1);
nextSettings[1].set_int('index', wsI);
space.setSettings(nextSettings); // ASSUMPTION: ok that two settings have same index here
// Re-assign unbound indices:
for (let i = n; i < N; i++) {
unbound[i-n][1].set_int('index', i);
}
return space;
}
// Backward compatibility
function defwinprop(...args) {