]> git.scottworley.com Git - roundrobintaborder/blob - extension.js
Version 3
[roundrobintaborder] / extension.js
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
7 * or version 3 of the License (at your option).
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
19 let 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.
26 function 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
33 function init() {
34 oldGetTabList = global.display.get_tab_list;
35 }
36
37 function 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();
41 ret.sort((a, b) => roundRobinComparitor(currentWindow, a, b));
42 return ret;
43 };
44 }
45
46 function disable() {
47 global.display.get_tab_list = oldGetTabList;
48 }
49