]> git.scottworley.com Git - roundrobintaborder/blame - extension.js
Remove 'or any later version' license choice
[roundrobintaborder] / extension.js
CommitLineData
6cc6bf8d
SW
1/* roundrobintaborder: Make the window switch order round-robin instead of most-recently-used
2 * Copyright (C) 2019 Scott Worley
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
dbc13896 7 * or version 3 of the License (at your option).
6cc6bf8d
SW
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19let oldGetTabList;
20
21// We sort windows as if lexicographically by the key
22// [is_smaller_than_or_equal_to_current_window_id, id].
23// This causes the current window to have the key
24// [1, <largest id of all windows that have 1 in the first key slot>]
25// and thus to always sort to the end of the list.
26function roundRobinComparitor(currentWindow, a, b) {
27 const aid = a.get_id(), alec = aid <= currentWindow;
28 const bid = b.get_id(), blec = bid <= currentWindow;
29 if (alec !== blec) return blec - alec;
30 return bid - aid;
31}
32
33function init() {
34 oldGetTabList = global.display.get_tab_list;
35}
36
37function enable() {
38 global.display.get_tab_list = function(type, workspace) {
39 const ret = oldGetTabList.call(this, type, workspace);
40 const currentWindow = global.display.get_focus_window().get_id();
5739d08a 41 ret.sort((a, b) => roundRobinComparitor(currentWindow, a, b));
6cc6bf8d
SW
42 return ret;
43 };
44}
45
46function disable() {
47 global.display.get_tab_list = oldGetTabList;
48}
49