From 4cfe445477ddaecb0605fcec8f29504dbde7d213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Hedin=20Br=C3=B8nner?= Date: Mon, 21 Oct 2019 10:44:36 +0200 Subject: [PATCH] tiling: Move cycle to Tiling.cycleWorkspaceSettings --- examples/keybindings.js | 46 ++--------------------------------------- tiling.js | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 44 deletions(-) diff --git a/examples/keybindings.js b/examples/keybindings.js index efcd942..46dd5f0 100644 --- a/examples/keybindings.js +++ b/examples/keybindings.js @@ -115,55 +115,13 @@ function cycleWorkspaceSettings(binding = "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( ""+binding, "prev-space-setting", - mw => cycle(mw, 1), { activeInNavigator: true } + mw => Tiling.cycleWorkspaceSettings(1), { activeInNavigator: true } ); } diff --git a/tiling.js b/tiling.js index 1823073..f1cb860 100644 --- a/tiling.js +++ b/tiling.js @@ -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) {