Skip to content

Commit c46b906

Browse files
committed
merge
2 parents de5dc5c + 6bc9501 commit c46b906

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/textual/screen.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -925,12 +925,20 @@ def _update_focus_styles(
925925
[widget for widget in widgets if widget._has_focus_within], animate=True
926926
)
927927

928-
def set_focus(self, widget: Widget | None, scroll_visible: bool = True) -> None:
928+
def set_focus(
929+
self,
930+
widget: Widget | None,
931+
scroll_visible: bool = True,
932+
from_app_focus: bool = False,
933+
) -> None:
929934
"""Focus (or un-focus) a widget. A focused widget will receive key events first.
930935
931936
Args:
932937
widget: Widget to focus, or None to un-focus.
933938
scroll_visible: Scroll widget in to view.
939+
from_app_focus: True if this focus is due to the app itself having regained
940+
focus. False if the focus is being set because a widget within the app
941+
regained focus.
934942
"""
935943
if widget is self.focused:
936944
# Widget is already focused
@@ -955,7 +963,7 @@ def set_focus(self, widget: Widget | None, scroll_visible: bool = True) -> None:
955963
# Change focus
956964
self.focused = widget
957965
# Send focus event
958-
widget.post_message(events.Focus())
966+
widget.post_message(events.Focus(from_app_focus=from_app_focus))
959967
focused = widget
960968

961969
if scroll_visible:

0 commit comments

Comments
 (0)