diff --git a/src/textual/app.py b/src/textual/app.py index 7ff28565f8..6ffccdb657 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -786,6 +786,9 @@ def __init__( self._hover_effects_timer: Timer | None = None + self._resize_event: events.Resize | None = None + """A pending resize event, sent on idle.""" + if self.ENABLE_COMMAND_PALETTE: for _key, binding in self._bindings: if binding.action in {"command_palette", "app.command_palette"}: @@ -3826,9 +3829,7 @@ async def _on_key(self, event: events.Key) -> None: async def _on_resize(self, event: events.Resize) -> None: event.stop() - self.screen.post_message(event) - for screen in self._background_screens: - screen.post_message(event) + self._resize_event = event async def _on_app_focus(self, event: events.AppFocus) -> None: """App has focus.""" @@ -4467,3 +4468,11 @@ def _on_terminal_supports_in_band_window_resize( we will just log it. """ self.log.debug(message) + + def _on_idle(self) -> None: + event = self._resize_event + if event is not None: + self._resize_event = None + self.screen.post_message(event) + for screen in self._background_screens: + screen.post_message(event) diff --git a/src/textual/drivers/linux_driver.py b/src/textual/drivers/linux_driver.py index f1eabd8246..abc011b9fd 100644 --- a/src/textual/drivers/linux_driver.py +++ b/src/textual/drivers/linux_driver.py @@ -20,6 +20,7 @@ from textual.driver import Driver from textual.drivers._writer_thread import WriterThread from textual.geometry import Size +from textual.message import Message from textual.messages import TerminalSupportInBandWindowResize if TYPE_CHECKING: @@ -443,18 +444,21 @@ def process_selector_events( except ParseError: pass - def process_message(self, event: events.Event) -> None: - if isinstance(event, TerminalSupportInBandWindowResize): - if event.supported and not event.enabled: + def process_message(self, message: Message) -> None: + # intercept in-band window resize + if isinstance(message, TerminalSupportInBandWindowResize): + # If it is supported, enabled it + if message.supported and not message.enabled: self._enable_in_band_window_resize() - self._in_band_window_resize = event.supported - elif event.enabled: - self._in_band_window_resize = event.supported + self._in_band_window_resize = message.supported + elif message.enabled: + self._in_band_window_resize = message.supported + # Send up-to-date message super().process_message( TerminalSupportInBandWindowResize( - event.supported, self._in_band_window_resize + message.supported, self._in_band_window_resize ) ) return - super().process_message(event) + super().process_message(message)