@@ -125,6 +125,9 @@ FApplication::~FApplication() // destructor
125125 if ( eventInQueue () )
126126 event_queue.clear ();
127127
128+ // Unset the resize handler
129+ FTermData::getInstance ().setResizeHandler (nullptr );
130+
128131 resetLog ();
129132}
130133
@@ -487,6 +490,39 @@ void FApplication::processExternalUserEvent()
487490 // This method can be overloaded and replaced by own code
488491}
489492
493+ // ----------------------------------------------------------------------
494+ void FApplication::resize ()
495+ {
496+ auto foutput_ptr = FVTerm::getFOutput ();
497+ static auto & mouse = FMouseControl::getInstance ();
498+
499+ // Detect and save the current terminal size
500+ foutput_ptr->detectTerminalSize ();
501+ auto width = getDesktopWidth ();
502+ auto height = getDesktopHeight ();
503+ mouse.setMaxWidth (uInt16 (width));
504+ mouse.setMaxHeight (uInt16 (height));
505+
506+ // The screen content is now unknown
507+ foutput_ptr->clearTerminalState ();
508+ foutput_ptr->clearTerminalAttributes ();
509+
510+ // Determine the new terminal size
511+ const FRect old_term_geometry {getTermGeometry ()};
512+ setDesktopWidgetSize (width, height);
513+ FRect term_geometry {getTermGeometry ()};
514+ term_geometry.move (-1 , -1 );
515+
516+ if ( old_term_geometry.getSize () == term_geometry.getSize () )
517+ return ;
518+
519+ resizeVTerm (term_geometry.getSize ());
520+ resizeRegion ({term_geometry, getShadow ()}, getVirtualDesktop ());
521+ FVTerm::startDrawing (); // Avoid flickering - no update during adjustment
522+ adjustSizeGlobal ();
523+ FVTerm::finishDrawing ();
524+ }
525+
490526// ----------------------------------------------------------------------
491527auto FApplication::event (FEvent* ev) -> bool
492528{
@@ -533,6 +569,16 @@ void FApplication::onLog (FEvent*)
533569 has_log_data = false ;
534570}
535571
572+ // ----------------------------------------------------------------------
573+ void FApplication::onResize (FResizeEvent* ev)
574+ {
575+ // This event handler can be reimplemented in a subclass
576+ // to receive resize events
577+
578+ processResizeEvent ();
579+ ev->accept ();
580+ }
581+
536582// ----------------------------------------------------------------------
537583void FApplication::onClose (FCloseEvent*)
538584{
@@ -596,6 +642,9 @@ void FApplication::init()
596642 // Initialize logging
597643 if ( ! getStartOptions ().logfile_stream .is_open () )
598644 getLog ()->setLineEnding (FLog::LineEnding::CRLF );
645+
646+ // Set the resize handler
647+ FTermData::getInstance ().setResizeHandler ( [this ] () { queueResize (); } );
599648}
600649
601650// ----------------------------------------------------------------------
@@ -1459,20 +1508,13 @@ auto FApplication::processParameters (const Args& args) -> FWidget*
14591508// ----------------------------------------------------------------------
14601509void FApplication::processResizeEvent ()
14611510{
1462- if ( ! has_terminal_resized ) // A SIGWINCH signal was received
1463- return ;
1511+ // This method will be called when the terminal size changes
14641512
1465- auto foutput_ptr = FVTerm::getFOutput ();
1466- foutput_ptr->detectTerminalSize (); // Detect and save the current terminal size
1467- static auto & mouse = FMouseControl::getInstance ();
1468- mouse.setMaxWidth (uInt16 (getDesktopWidth ()));
1469- mouse.setMaxHeight (uInt16 (getDesktopHeight ()));
1470- FResizeEvent r_ev (Event::Resize);
1471- sendEvent (internal::var::app_object, &r_ev);
1472- has_terminal_resized = false ;
1513+ resize ();
1514+ redraw ();
14731515
1474- if ( r_ev. isAccepted () )
1475- foutput_ptr ->commitTerminalResize ();
1516+ has_terminal_resized = false ;
1517+ FVTerm::getFOutput () ->commitTerminalResize ();
14761518}
14771519
14781520// ----------------------------------------------------------------------
@@ -1562,6 +1604,18 @@ void FApplication::queueLog()
15621604 FApplication::queueEvent (this , std::move (ev));
15631605}
15641606
1607+ // ----------------------------------------------------------------------
1608+ void FApplication::queueResize ()
1609+ {
1610+ if ( has_terminal_resized ) // A SIGWINCH signal was received
1611+ return ;
1612+
1613+ has_terminal_resized = true ;
1614+
1615+ auto ev = std::make_unique<FEvent>(Event::Resize);
1616+ FApplication::queueEvent (this , std::move (ev));
1617+ }
1618+
15651619// ----------------------------------------------------------------------
15661620void FApplication::processLogger () const
15671621{
@@ -1583,12 +1637,11 @@ auto FApplication::processNextEvent() -> bool
15831637{
15841638 uInt num_events{0 };
15851639
1586- if ( hasDataInQueue () || hasTerminalResized () || isNextEventTimeout () )
1640+ if ( hasDataInQueue () || isNextEventTimeout () )
15871641 {
15881642 time_last_event = FObjectTimer::getCurrentTime ();
15891643 num_events += processTimerEvent ();
15901644 processInput ();
1591- processResizeEvent (); // when the terminal size has changed
15921645 sendQueuedEvents ();
15931646 processTerminalScreenUpdate ();
15941647 }
@@ -1607,14 +1660,6 @@ void FApplication::performTimerAction (FObject* receiver, FEvent* event)
16071660 sendEvent (receiver, event);
16081661}
16091662
1610- // ----------------------------------------------------------------------
1611- inline auto FApplication::hasTerminalResized () -> bool
1612- {
1613- auto foutput_ptr = FVTerm::getFOutput ();
1614- has_terminal_resized = foutput_ptr->hasTerminalResized ();
1615- return has_terminal_resized;
1616- }
1617-
16181663// ----------------------------------------------------------------------
16191664auto FApplication::isEventProcessable ( FObject* receiver
16201665 , const FEvent* event ) -> bool
0 commit comments