examples: keybinding for cycling workspace settings (among "unbound" and current)

Only relevant when using dynamic workspace. Typically used to change the empty
workspace settings to the one you want.
This commit is contained in:
Ole Jørgen Brønner
2019-09-29 21:48:01 +02:00
parent 8891577a4e
commit 024e8bb705

View File

@@ -33,7 +33,6 @@ function gotoByIndex() {
}
}
function windowMarks() {
const Meta = imports.gi.Meta;
var marks = {}
@@ -77,7 +76,6 @@ function windowMarks() {
}
}
function swapNeighbours(binding = "<Super>y") {
var Tiling = Extension.imports.tiling;
var Meta = imports.gi.Meta;
@@ -107,6 +105,67 @@ function cycleMonitor(binding = "<Super>d") {
});
}
/**
Cycle the workspace settings bound to the current workspace.
(among the unused settings)
NB: Only relevant when using dynamic workspaces.
*/
function cycleWorkspaceSettings(binding = "<Super>q") {
var Tiling = Extension.imports.tiling;
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 }
);
Keybindings.bindkey(
"<Shift>"+binding, "prev-space-setting",
mw => cycle(mw, 1), { activeInNavigator: true }
);
}
function showNavigator(binding = "<Super>j") {
Keybindings.bindkey(binding, "show-minimap", () => null, { opensMinimap: true })