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