def handle_result(args: List[str], result: str, target_window_id: int, boss: Boss) -> None: w = boss.window_id_map.get(target_window_id) if w is None: return if w.screen.is_main_linebuf(): if args[1] != "scroll_line_down" or w.screen.scrolled_by > 0: getattr(w, args[1])() return mods, key = ke.parse_shortcut(args[2]) shift, alt, ctrl, super, hyper, meta, caps_lock, num_lock = ( bool(mods & bit) for bit in (ke.SHIFT, ke.ALT, ke.CTRL, ke.SUPER, ke.HYPER, ke.META, ke.CAPS_LOCK, ke.NUM_LOCK)) for action in [ke.EventType.PRESS, ke.EventType.RELEASE]: key_event = ke.KeyEvent(type=action, mods=mods, key=key, shift=shift, alt=alt, ctrl=ctrl, super=super, hyper=hyper, meta=meta, caps_lock=caps_lock, num_lock=num_lock) window_system_event = key_event.as_window_system_event() sequence = w.encoded_key(window_system_event) w.write_to_child(sequence)
def handle_result(args, answer, target_window_id, boss): _kitten = args[0] action_if_tabs = ' '.join(args[1:-1]) if_no_tabs = args[-1] tm = boss.active_tab_manager if tm is None: return if len(tm.tabs) > 1: boss.dispatch_action(parse_key_action(action_if_tabs)) return w = boss.window_id_map.get(target_window_id) mods, key = ke.parse_shortcut(if_no_tabs) shift, alt, ctrl, super, hyper, meta, caps_lock, num_lock = ( bool(mods & bit) for bit in ( ke.SHIFT, ke.ALT, ke.CTRL, ke.SUPER, ke.HYPER, ke.META, ke.CAPS_LOCK, ke.NUM_LOCK)) for action in [ke.PRESS, ke.RELEASE]: key_event = ke.KeyEvent( type=action, mods=mods, key=key, shift=shift, alt=alt, ctrl=ctrl, super=super, hyper=hyper, meta=meta, caps_lock=caps_lock, num_lock=num_lock) window_system_event = key_event.as_window_system_event() sequence = w.encoded_key(window_system_event) w.write_to_child(sequence)
def add_shortcut(self, action: KeyActionType, spec: Union[str, ParsedShortcut]) -> None: if not hasattr(self, '_key_shortcuts'): self._key_shortcuts: Dict[ParsedShortcut, KeyActionType] = {} if isinstance(spec, str): from kitty.key_encoding import parse_shortcut spec = parse_shortcut(spec) self._key_shortcuts[spec] = action
def encode_key_mapping(window, key_mapping): mods, key = parse_shortcut(key_mapping) event = KeyEvent( mods=mods, key=key, shift=bool(mods & 1), alt=bool(mods & 2), ctrl=bool(mods & 4), super=bool(mods & 8), hyper=bool(mods & 16), meta=bool(mods & 32), ).as_window_system_event() return window.encoded_key(event)
def encode_key_mapping(key_mapping, window): mods, key = parse_shortcut(key_mapping) event = KeyEvent( mods=mods, key=key, shift=bool(mods & SHIFT), alt=bool(mods & ALT), ctrl=bool(mods & CTRL), super=bool(mods & SUPER), hyper=bool(mods & HYPER), meta=bool(mods & META), ).as_window_system_event() return window.encoded_key(event)
def encode_key_mapping(key_mapping): mods, key = parse_shortcut(key_mapping) event = KeyEvent( mods=mods, key=key, shift=bool(mods & 1), alt=bool(mods & 2), ctrl=bool(mods & 4), super=bool(mods & 8), hyper=bool(mods & 16), meta=bool(mods & 32), ).as_window_system_event() return encode_key_for_tty(event.key, event.shifted_key, event.alternate_key, event.mods, event.action)
def handle_result(args, result, target_window_id, boss): w = boss.window_id_map.get(target_window_id) tab = boss.active_tab # The direciton to move to, e.g. top, right, bottom, left direction = args[2] # a key mapping, e.g. "ctrl+h" key_mapping = args[3] # The regular expresion to use to match against the process name. # This can be changes by passing a fourth argument to pass_keys.py # in your kitty.conf file. process_name = args[4] if len(args) > 4 else "n?vim" if w is None: return else: fp = w.child.foreground_processes # check the first word of the each foreground process if not any(re.search(process_name, p['cmdline'][0], re.I) for p in fp): window = boss.active_window boss.active_tab.neighboring_window(direction) if boss.active_window == window: directions = { "top": "north", "bottom": "south", "left": "west", "right": "east"} import os os.system(f"bspc node --focus {directions[direction]}") return # mods, key, is_text = ku.parse_kittens_shortcut(key_mapping) mods, key = ke.parse_shortcut(key_mapping) extended = w.screen.current_key_encoding_flags() & 0b1000 for action in actions(extended): sequence = ( ('\x1b_{}\x1b\\' if extended else '{}') .format( fdt.encode_key_for_tty( getattr(fdt, 'GLFW_FKEY_{}'.format(key.upper())), w.screen.cursor_key_mode, extended, convert_mods(mods), action))) w.write_to_child(sequence)