From adccd6ae3b048fb976fcd81338e2fb72bcdada7d Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Mon, 5 Oct 2020 04:24:14 +0200 Subject: [PATCH] Now hides the input cursor when a widget gets hidden --- ChangeLog | 3 +++ examples/checklist.cpp | 2 +- examples/input-dialog.cpp | 2 +- examples/mandelbrot.cpp | 2 +- examples/rotozoomer.cpp | 6 +++--- examples/term-attributes.cpp | 2 +- examples/ui.cpp | 2 +- src/fvterm.cpp | 32 ++++++++++++++++---------------- src/fwidget.cpp | 7 ++++++- src/fwindow.cpp | 12 ++++++++++-- src/include/final/fsystemimpl.h | 2 +- src/include/final/fvterm.h | 9 +++++++++ 12 files changed, 53 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index de56b965..ac8bb9e5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2020-10-05 Markus Gans + * Now hides the input cursor when a widget gets hidden + 2020-10-04 Markus Gans * Replaces some C-style arrays with std::array * Now you can use the arrow keys to move a window into the visible area diff --git a/examples/checklist.cpp b/examples/checklist.cpp index 46c19675..a0f7f2c7 100644 --- a/examples/checklist.cpp +++ b/examples/checklist.cpp @@ -82,7 +82,7 @@ CheckList::CheckList (finalcut::FWidget* parent) FDialog::setText (L"Shopping list"); const std::size_t nf_offset = ( finalcut::FTerm::isNewFont() ) ? 1 : 0; FDialog::setSize (FSize{28 + nf_offset, 13} ); - setShadow(); + setShadow(); // Instead of the transparent window shadow listview.ignorePadding(); listview.setGeometry ( FPoint{1 + int(nf_offset), 2} , FSize{getWidth() - nf_offset, getHeight() - 1} ); diff --git a/examples/input-dialog.cpp b/examples/input-dialog.cpp index c0912dc2..c4bb2245 100644 --- a/examples/input-dialog.cpp +++ b/examples/input-dialog.cpp @@ -65,7 +65,7 @@ int main (int argc, char* argv[]) finalcut::FDialog dgl{&app}; dgl.setText ("Data input"); dgl.setGeometry (FPoint{4, 2}, FSize{37, 22}); - dgl.setShadow(); + dgl.setShadow(); // Instead of the transparent window shadow // Create input fields finalcut::FLineEdit name_field {&dgl}; diff --git a/examples/mandelbrot.cpp b/examples/mandelbrot.cpp index f8c52b96..e087776a 100644 --- a/examples/mandelbrot.cpp +++ b/examples/mandelbrot.cpp @@ -167,7 +167,7 @@ int main (int argc, char* argv[]) // Create a simple dialog box Mandelbrot mb{&app}; mb.setGeometry (FPoint{6, 1}, FSize{70, 23}); - mb.setShadow(); + mb.setShadow(); // Instead of the transparent window shadow // Set the mandelbrot object as main widget finalcut::FWidget::setMainWidget(&mb); diff --git a/examples/rotozoomer.cpp b/examples/rotozoomer.cpp index 448ff8af..fa00a994 100644 --- a/examples/rotozoomer.cpp +++ b/examples/rotozoomer.cpp @@ -139,8 +139,8 @@ void RotoZoomer::draw() //---------------------------------------------------------------------- void RotoZoomer::rotozoomer (double cx, double cy, double r, double a) { - const int Cols = int(getClientWidth()); - const int Lines = int(getClientHeight()); + const auto Cols = int(getClientWidth()); + const auto Lines = int(getClientHeight()); auto Ax = int(4096.0 * (cx + r * std::cos(a))); auto Ay = int(4096.0 * (cy + r * std::sin(a))); auto Bx = int(4096.0 * (cx + r * std::cos(a + 2.02358))); @@ -323,7 +323,7 @@ int main (int argc, char* argv[]) if ( benchmark ) roto.setGeometry (FPoint{1, 1}, FSize{80, 24}); - roto.setShadow(); + roto.setShadow(); // Instead of the transparent window shadow // Set the RotoZoomer object as main widget finalcut::FWidget::setMainWidget(&roto); diff --git a/examples/term-attributes.cpp b/examples/term-attributes.cpp index 37ac4cf5..f7da8ef3 100644 --- a/examples/term-attributes.cpp +++ b/examples/term-attributes.cpp @@ -499,7 +499,7 @@ int main (int argc, char* argv[]) // the parent object "app" (FObject destructor). AttribDlg dialog{&app}; dialog.setSize (FSize{69, 21}); - dialog.setShadow(); + dialog.setShadow(); // Instead of the transparent window shadow // Create the attribute demo widget as a child object from the dialog AttribDemo demo(&dialog); diff --git a/examples/ui.cpp b/examples/ui.cpp index 562113ab..e080d9a7 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -1067,7 +1067,7 @@ int main (int argc, char* argv[]) MyDialog d{&app}; d.setText (title); d.setSize (FSize{56, app.getHeight() - 4}); - d.setShadow(); + d.setShadow(); // Instead of the transparent window shadow // Set the dialog object d as the main widget of the application. // When you close the main widget, the application will be closed. diff --git a/src/fvterm.cpp b/src/fvterm.cpp index 4992c157..77d02a23 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -800,23 +800,23 @@ void FVTerm::removeArea (FTermArea*& area) { // remove the virtual window - if ( area != nullptr ) + if ( area == nullptr ) + return; + + if ( area->changes != nullptr ) { - if ( area->changes != nullptr ) - { - delete[] area->changes; - area->changes = nullptr; - } - - if ( area->data != nullptr ) - { - delete[] area->data; - area->data = nullptr; - } - - delete area; - area = nullptr; + delete[] area->changes; + area->changes = nullptr; } + + if ( area->data != nullptr ) + { + delete[] area->data; + area->data = nullptr; + } + + delete area; + area = nullptr; } //---------------------------------------------------------------------- @@ -876,7 +876,7 @@ bool FVTerm::updateVTermCursor (const FTermArea* area) const if ( ! area ) return false; - if ( area != active_area ) + if ( ! isActive(area) ) return false; if ( ! area->visible ) diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 4d843aef..d44b85c7 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -638,7 +638,7 @@ bool FWidget::setCursorPos (const FPoint& pos) widget_cursor_position.setPoint(pos); - if ( ! flags.focus || isWindowWidget() ) + if ( ! flags.focus || flags.hidden || isWindowWidget() ) return false; if ( ! FWindow::getWindowWidget(this) ) @@ -999,6 +999,11 @@ void FWidget::hide() { flags.shown = false; + if ( flags.visible_cursor && FWidget::getFocusWidget() == this ) + { + getPrintArea()->input_cursor_visible = false; + } + if ( ! isDialogWidget() && FWidget::getFocusWidget() == this && ! focusPrevChild() ) diff --git a/src/fwindow.cpp b/src/fwindow.cpp index bb66c627..5d005844 100644 --- a/src/fwindow.cpp +++ b/src/fwindow.cpp @@ -278,8 +278,17 @@ void FWindow::show() //---------------------------------------------------------------------- void FWindow::hide() { + const auto& virtual_win = getVWin(); + + if ( isActive(virtual_win) + && virtual_win->visible + && virtual_win->input_cursor_visible ) + { + hideVTermCursor(); + } + if ( isVirtualWindow() ) - getVWin()->visible = false; + virtual_win->visible = false; FWidget::hide(); const auto& t_geometry = getTermGeometryWithShadow(); @@ -681,7 +690,6 @@ void FWindow::switchToPrevWindow (const FWidget* widget) const bool is_activated = activatePrevWindow(); auto active_win = static_cast(getActiveWindow()); - if ( ! is_activated && getWindowList() && getWindowList()->size() > 1 ) { diff --git a/src/include/final/fsystemimpl.h b/src/include/final/fsystemimpl.h index 25bbf3c4..17d56a4b 100644 --- a/src/include/final/fsystemimpl.h +++ b/src/include/final/fsystemimpl.h @@ -145,7 +145,7 @@ class FSystemImpl : public FSystem { va_list args{}; va_start (args, flags); - mode_t mode = static_cast(va_arg (args, int)); + auto mode = static_cast(va_arg (args, int)); int ret = ::open (pathname, flags, mode); va_end (args); return ret; diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index a61acf75..1107aa86 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -292,6 +292,7 @@ class FVTerm void setActiveArea (FTermArea*) const; // Inquiries + bool isActive (const FTermArea*) const; bool hasPrintArea() const; bool hasChildPrintArea() const; bool isVirtualWindow() const; @@ -307,6 +308,7 @@ class FVTerm static void removeArea (FTermArea*&); static void restoreVTerm (const FRect&); bool updateVTermCursor (const FTermArea*) const; + void hideVTermCursor() const; static void setAreaCursor ( const FPoint& , bool, FTermArea* ); static void getArea (const FPoint&, const FTermArea*); @@ -966,6 +968,10 @@ inline void FVTerm::setChildPrintArea (FTermArea* area) inline void FVTerm::setActiveArea (FTermArea* area) const { active_area = area; } +//---------------------------------------------------------------------- +inline bool FVTerm::isActive (const FTermArea* area) const +{ return bool( area == active_area ); } + //---------------------------------------------------------------------- inline bool FVTerm::hasPrintArea() const { return print_area; } @@ -982,6 +988,9 @@ inline bool FVTerm::isVirtualWindow() const inline bool FVTerm::isCursorHideable() const { return cursor_hideable; } +//---------------------------------------------------------------------- +inline void FVTerm::hideVTermCursor() const +{ vterm->input_cursor_visible = false; } } // namespace finalcut