Skip to content

Commit

Permalink
resize on idle
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Nov 8, 2024
1 parent d25c89a commit e157c6b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
15 changes: 12 additions & 3 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}:
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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)
20 changes: 12 additions & 8 deletions src/textual/drivers/linux_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

0 comments on commit e157c6b

Please sign in to comment.