Skip to content

Commit b2d9dc3

Browse files
committed
Include a flag in Focus events to indicate whether they're due to the App regaining focus or whether they're a standard focus.
1 parent d1464b5 commit b2d9dc3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/textual/screen.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,12 +869,20 @@ def _update_focus_styles(
869869
[widget for widget in widgets if widget._has_focus_within], animate=True
870870
)
871871

872-
def set_focus(self, widget: Widget | None, scroll_visible: bool = True) -> None:
872+
def set_focus(
873+
self,
874+
widget: Widget | None,
875+
scroll_visible: bool = True,
876+
from_app_focus: bool = False,
877+
) -> None:
873878
"""Focus (or un-focus) a widget. A focused widget will receive key events first.
874879
875880
Args:
876881
widget: Widget to focus, or None to un-focus.
877882
scroll_visible: Scroll widget in to view.
883+
from_app_focus: True if this focus is due to the app itself having regained
884+
focus. False if the focus is being set because a widget within the app
885+
regained focus.
878886
"""
879887
if widget is self.focused:
880888
# Widget is already focused
@@ -899,7 +907,7 @@ def set_focus(self, widget: Widget | None, scroll_visible: bool = True) -> None:
899907
# Change focus
900908
self.focused = widget
901909
# Send focus event
902-
widget.post_message(events.Focus())
910+
widget.post_message(events.Focus(from_app_focus=from_app_focus))
903911
focused = widget
904912

905913
if scroll_visible:

0 commit comments

Comments
 (0)