|
1 | 1 | # Based on MIT licensed code at https://github.com/chancez/dotfiles/blob/badc69d3895a6a942285amount26b8c372a55d77533eamount/kitty/.config/kitty/relative_resize.py
|
2 | 2 | from kittens.tui.handler import result_handler
|
| 3 | +from kitty.key_encoding import KeyEvent, parse_shortcut |
| 4 | + |
| 5 | + |
| 6 | +def encode_key_mapping(window, key_mapping): |
| 7 | + mods, key = parse_shortcut(key_mapping) |
| 8 | + event = KeyEvent( |
| 9 | + mods=mods, |
| 10 | + key=key, |
| 11 | + shift=bool(mods & 1), |
| 12 | + alt=bool(mods & 2), |
| 13 | + ctrl=bool(mods & 4), |
| 14 | + super=bool(mods & 8), |
| 15 | + hyper=bool(mods & 16), |
| 16 | + meta=bool(mods & 32), |
| 17 | + ).as_window_system_event() |
| 18 | + |
| 19 | + return window.encoded_key(event) |
| 20 | + |
3 | 21 |
|
4 | 22 | def main(args):
|
5 | 23 | pass
|
6 | 24 |
|
| 25 | + |
7 | 26 | def relative_resize_window(direction, amount, target_window_id, boss):
|
8 | 27 | window = boss.window_id_map.get(target_window_id)
|
9 | 28 | if window is None:
|
10 | 29 | return
|
11 | 30 |
|
12 |
| - neighbors = boss.active_tab.current_layout.neighbors_for_window(window, boss.active_tab.windows) |
| 31 | + neighbors = boss.active_tab.current_layout.neighbors_for_window( |
| 32 | + window, boss.active_tab.windows |
| 33 | + ) |
13 | 34 | current_window_id = boss.active_tab.active_window
|
14 | 35 |
|
15 | 36 | left_neighbors = neighbors.get('left')
|
@@ -57,8 +78,20 @@ def relative_resize_window(direction, amount, target_window_id, boss):
|
57 | 78 | elif direction == 'down' and bottom_neighbors:
|
58 | 79 | boss.active_tab.resize_window('taller', amount)
|
59 | 80 |
|
| 81 | + |
60 | 82 | @result_handler(no_ui=True)
|
61 | 83 | def handle_result(args, result, target_window_id, boss):
|
62 | 84 | direction = args[1]
|
63 | 85 | amount = int(args[2])
|
64 |
| - relative_resize_window(direction, amount, target_window_id, boss) |
| 86 | + window = boss.window_id_map.get(target_window_id) |
| 87 | + |
| 88 | + keymap = args[3] |
| 89 | + |
| 90 | + cmd = window.child.foreground_cmdline[0] |
| 91 | + if cmd == 'nvim': |
| 92 | + encoded = encode_key_mapping(window, keymap) |
| 93 | + window.write_to_child(encoded) |
| 94 | + elif cmd == 'tmux': |
| 95 | + pass |
| 96 | + else: |
| 97 | + relative_resize_window(direction, amount, target_window_id, boss) |
0 commit comments