From 249ec0cc06cc64122b3e4eaea2befbada1c298ea Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 7 Dec 2016 11:35:26 +0530 Subject: [PATCH] Shortcuts to select specific windows --- kitty/kitty.conf | 10 ++++++++++ kitty/tabs.py | 20 +++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/kitty/kitty.conf b/kitty/kitty.conf index b09bc6c1d..98700ff93 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -142,6 +142,16 @@ map ctrl+shift+] next_window map ctrl+shift+[ previous_window map ctrl+shift+w close_window map ctrl+shift+l next_layout +map ctrl+shift+1 first_window +map ctrl+shift+2 second_window +map ctrl+shift+3 third_window +map ctrl+shift+4 fourth_window +map ctrl+shift+5 fifth_window +map ctrl+shift+6 sixth_window +map ctrl+shift+7 seventh_window +map ctrl+shift+8 eight_window +map ctrl+shift+9 ninth_window +map ctrl+shift+0 tenth_window # Tab management map ctrl+shift+right next_tab diff --git a/kitty/tabs.py b/kitty/tabs.py index 27ded928f..dfdf24ffd 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -3,6 +3,7 @@ # License: GPL v3 Copyright: 2016, Kovid Goyal from collections import deque +from functools import partial from threading import Lock from ctypes import addressof @@ -36,6 +37,8 @@ class Tab: l = session_tab.layout queue_action(self.startup, session_tab) self.current_layout = all_layouts[l](opts, self.borders.border_width, self.windows) + for i, which in enumerate('first second third fourth fifth sixth seventh eight ninth tenth'.split()): + setattr(self, which + '_window', partial(self.nth_window, num=i)) def startup(self, session_tab): for cmd in session_tab.windows: @@ -110,17 +113,24 @@ class Tab: self.borders(self.windows, self.active_window, self.current_layout.needs_window_borders and len(self.windows) > 1) glfw_post_empty_event() - def set_active_window(self, window): - try: - idx = self.windows.index(window) - except ValueError: - return + def set_active_window_idx(self, idx): if idx != self.active_window_idx: self.current_layout.set_active_window(self.windows, idx) self.active_window_idx = idx self.borders(self.windows, self.active_window, self.current_layout.needs_window_borders and len(self.windows) > 1) glfw_post_empty_event() + def set_active_window(self, window): + try: + idx = self.windows.index(window) + except ValueError: + return + self.set_active_window_idx(idx) + + def nth_window(self, num=0): + if self.windows: + self.set_active_window_idx(min(num, len(self.windows)-1)) + def _next_window(self, delta=1): if len(self.windows) > 1: self.active_window_idx = self.current_layout.next_window(self.windows, self.active_window_idx, delta)