Ensure there are no duplicate watchers for send-text sessions
This commit is contained in:
parent
b080296326
commit
af15b0313a
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
import base64
|
import base64
|
||||||
import sys
|
import sys
|
||||||
from functools import partial
|
|
||||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, Union
|
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, Union
|
||||||
|
|
||||||
from kitty.fast_data_types import KeyEvent as WindowSystemKeyEvent, get_boss
|
from kitty.fast_data_types import KeyEvent as WindowSystemKeyEvent, get_boss
|
||||||
@ -32,25 +31,35 @@ class Session:
|
|||||||
sessions_map: Dict[str, Session] = {}
|
sessions_map: Dict[str, Session] = {}
|
||||||
|
|
||||||
|
|
||||||
def clear_unfocused_cursors(sid: str, *a: Any) -> None:
|
class SessionAction:
|
||||||
s = sessions_map.pop(sid, None)
|
|
||||||
if s is not None:
|
def __init__(self, sid: str):
|
||||||
boss = get_boss()
|
self.sid = sid
|
||||||
for wid in s.window_ids:
|
|
||||||
qw = boss.window_id_map.get(wid)
|
|
||||||
if qw is not None:
|
|
||||||
qw.screen.render_unfocused_cursor = 0
|
|
||||||
|
|
||||||
|
|
||||||
def handle_focus_change(sid: str, window: Window, focused: bool) -> None:
|
class ClearSession(SessionAction):
|
||||||
s = sessions_map.get(sid)
|
|
||||||
if s is not None:
|
def __call__(self, *a: Any) -> None:
|
||||||
boss = get_boss()
|
s = sessions_map.pop(self.sid, None)
|
||||||
val = int(focused)
|
if s is not None:
|
||||||
for wid in s.window_ids:
|
boss = get_boss()
|
||||||
qw = boss.window_id_map.get(wid)
|
for wid in s.window_ids:
|
||||||
if qw is not None:
|
qw = boss.window_id_map.get(wid)
|
||||||
qw.screen.render_unfocused_cursor = val
|
if qw is not None:
|
||||||
|
qw.screen.render_unfocused_cursor = 0
|
||||||
|
|
||||||
|
|
||||||
|
class FocusChangedSession(SessionAction):
|
||||||
|
|
||||||
|
def __call__(self, window: Window, focused: bool) -> None:
|
||||||
|
s = sessions_map.get(self.sid)
|
||||||
|
if s is not None:
|
||||||
|
boss = get_boss()
|
||||||
|
val = int(focused)
|
||||||
|
for wid in s.window_ids:
|
||||||
|
qw = boss.window_id_map.get(wid)
|
||||||
|
if qw is not None:
|
||||||
|
qw.screen.render_unfocused_cursor = val
|
||||||
|
|
||||||
|
|
||||||
class SendText(RemoteCommand):
|
class SendText(RemoteCommand):
|
||||||
@ -200,12 +209,18 @@ Do not send text to the active window, even if it is one of the matched windows.
|
|||||||
for w in actual_windows:
|
for w in actual_windows:
|
||||||
w.screen.render_unfocused_cursor = 0
|
w.screen.render_unfocused_cursor = 0
|
||||||
s.window_ids.discard(w.id)
|
s.window_ids.discard(w.id)
|
||||||
clear_unfocused_cursors(sid)
|
ClearSession(sid)()
|
||||||
elif session == 'start':
|
elif session == 'start':
|
||||||
s = create_or_update_session()
|
s = create_or_update_session()
|
||||||
if window is not None:
|
if window is not None:
|
||||||
window.actions_on_removal.append(partial(clear_unfocused_cursors, sid))
|
|
||||||
window.actions_on_focus_change.append(partial(handle_focus_change, sid))
|
def is_ok(x: Any) -> bool:
|
||||||
|
return not isinstance(x, SessionAction) or x.sid != sid
|
||||||
|
|
||||||
|
window.actions_on_removal = list(filter(is_ok, window.actions_on_removal))
|
||||||
|
window.actions_on_focus_change = list(filter(is_ok, window.actions_on_focus_change))
|
||||||
|
window.actions_on_removal.append(ClearSession(sid))
|
||||||
|
window.actions_on_focus_change.append(FocusChangedSession(sid))
|
||||||
for w in actual_windows:
|
for w in actual_windows:
|
||||||
w.screen.render_unfocused_cursor = 1
|
w.screen.render_unfocused_cursor = 1
|
||||||
s.window_ids.add(w.id)
|
s.window_ids.add(w.id)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user