From 75b73f6821ea3cb277db9d92a916efc31be19553 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 9 Jul 2021 08:54:22 +0530 Subject: [PATCH] Allow using neighboring window operations in the stack layout --- docs/changelog.rst | 4 ++++ kitty/layout/stack.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index c557d3f75..1c0afec5a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -21,6 +21,10 @@ To update |kitty|, :doc:`follow the instructions `. - Fix turning off cursor blink via escape codes not working (:iss:`3808`) +- Allow using neighboring window operations in the stack layout. The previous + window is considered the left and top neighbor and the next window is + considered the bottom and right neighbor (:iss:`3778`) + 0.21.2 [2021-06-28] ---------------------- diff --git a/kitty/layout/stack.py b/kitty/layout/stack.py index 8b98029de..9578ffe11 100644 --- a/kitty/layout/stack.py +++ b/kitty/layout/stack.py @@ -2,9 +2,10 @@ # vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2020, Kovid Goyal +from kitty.typing import WindowType from kitty.window_list import WindowList -from .base import Layout +from .base import Layout, NeighborsMap class Stack(Layout): @@ -17,3 +18,12 @@ class Stack(Layout): active_group = all_windows.active_group for group in all_windows.iter_all_layoutable_groups(): self.layout_single_window_group(group, add_blank_rects=group is active_group) + + def neighbors_for_window(self, window: WindowType, all_windows: WindowList) -> NeighborsMap: + wg = all_windows.group_for_window(window) + assert wg is not None + groups = tuple(all_windows.iter_all_layoutable_groups()) + idx = groups.index(wg) + before = [] if wg is groups[0] else [groups[idx-1].id] + after = [] if wg is groups[-1] else [groups[idx+1].id] + return {'top': before, 'left': before, 'right': after, 'bottom': after}