From 4df5c6d0b0feb94d09966d62113746c2094028df Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Mon, 26 Mar 2018 15:42:08 +0000 Subject: Android: Avoids hiding and showing keyboard when focus changes from text input to text input git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12805 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl.cxx | 13 ++++++++++--- src/drivers/Android/Fl_Android_Screen_Keyboard.cxx | 6 ++++-- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Fl.cxx b/src/Fl.cxx index 3c0c92654..011e978e0 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -861,6 +861,11 @@ Fl_Widget* fl_oldfocus; // kludge for Fl_Group... \e test if the widget wants the focus (by it returning non-zero from handle()). + Widgets can set the NEEDS_KEYBOARD flag to indicate that a keyboard is + essential for the widget to function. Touchscreen devices will be sent a + request to show and on-screen keyboard if no hardware keyboard is + connected. + \see Fl_Widget::take_focus() */ void Fl::focus(Fl_Widget *o) @@ -869,10 +874,12 @@ void Fl::focus(Fl_Widget *o) // request an on-screen keyboard on touch screen devices if needed Fl_Widget *prevFocus = Fl::focus(); - if ( prevFocus && (prevFocus->flags()&Fl_Widget::NEEDS_KEYBOARD) ) + char hideKeyboard = ( prevFocus && (prevFocus->flags()&Fl_Widget::NEEDS_KEYBOARD) ); + char showKeyboard = (o && (o->flags()&Fl_Widget::NEEDS_KEYBOARD)); + if (hideKeyboard && !showKeyboard) Fl::screen_driver()->release_keyboard(); - if (o && (o->flags()&Fl_Widget::NEEDS_KEYBOARD)) - Fl::screen_driver()->request_keyboard( /*o->type()*/ ); + if (showKeyboard && !hideKeyboard) + Fl::screen_driver()->request_keyboard(); if (o && !o->visible_focus()) return; Fl_Widget *p = focus_; diff --git a/src/drivers/Android/Fl_Android_Screen_Keyboard.cxx b/src/drivers/Android/Fl_Android_Screen_Keyboard.cxx index 91a78f42b..c708040ec 100644 --- a/src/drivers/Android/Fl_Android_Screen_Keyboard.cxx +++ b/src/drivers/Android/Fl_Android_Screen_Keyboard.cxx @@ -363,8 +363,10 @@ int64_t AKeyEvent_getEventTime (const AInputEvent *key_event) return 0; } - -void Fl_Android_Screen_Driver::request_keyboard() +// TODO: different inputs may be able to request different keyboards +// TODO: knowing the position of the widget, we may be able to avoid +// obstructing it with the on-screen keyboard +void Fl_Android_Screen_Driver::request_keyboard( /*o->rect(), o->type()*/ ) { if (pKeyboardCount==0) { /* -- cgit v1.2.3