Lagrange [work/v1.12]

Android: Improved software keyboard handling

=> e956dbda62a41fe1799e7e8af5ea42a53d8aebcd

diff --git a/src/android.c b/src/android.c
index d4c4a512..e23244ac 100644
--- a/src/android.c
+++ b/src/android.c
@@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 #include "ui/command.h"
 #include "ui/metrics.h"
 #include "ui/mobile.h"
+#include "ui/window.h"
 
 #include 
 #include 
@@ -243,5 +244,12 @@ iBool handleCommand_Android(const char *cmd) {
                             0xff000000 | (top.r << 16) | (top.g << 8) | top.b,
                             0xff000000 | (btm.r << 16) | (btm.g << 8) | btm.b);
     }
+    else if (equal_Command(cmd, "android.keyboard.changed")) {
+        iMainWindow *mw = get_MainWindow();
+        if (mw) {
+            setKeyboardHeight_MainWindow(mw, arg_Command(cmd));
+        }
+        return iTrue;
+    }
     return iFalse;
 }
diff --git a/src/ui/root.c b/src/ui/root.c
index b8db1a4b..1d4f50d2 100644
--- a/src/ui/root.c
+++ b/src/ui/root.c
@@ -1244,14 +1244,15 @@ static iBool handleToolBarCommands_(iWidget *toolBar, const char *cmd) {
         const int showSpan = 400;
         const int hideSpan = 350;
         const int animFlag = easeOut_AnimFlag | softer_AnimFlag;
+        int landscapeOffset = 5 * gap_UI; /* TODO: Why this amount? Something's funny here. */
 #else
-        const int showSpan = 100;
-        const int hideSpan = 200;
+        const int showSpan = 80;
+        const int hideSpan = 250;
         const int animFlag = easeOut_AnimFlag;
+        int landscapeOffset = 0;
 #endif
         if (focus_Widget() == findChild_Widget(navBar, "url") && height > 0) {
-            int inputHeight = 5 * gap_UI; /* TODO: Why this amount? Something's funny here. */
-            int keyboardPad = height - (isPortrait_App() ? height_Widget(toolBar) : inputHeight);
+            int keyboardPad = height - (isPortrait_App() ? height_Widget(toolBar) : landscapeOffset);
             bottomBar->padding[3] = keyboardPad;
             arrange_Widget(bottomBar);
             arrange_Widget(bottomBar);
diff --git a/src/ui/touch.c b/src/ui/touch.c
index 1de6c244..dacdbfef 100644
--- a/src/ui/touch.c
+++ b/src/ui/touch.c
@@ -271,24 +271,16 @@ static uint32_t gestureSpan_Touch_(const iTouch *d) {
     return d->posTime[0] - d->posTime[lastIndex];
 }
 
-static void update_TouchState_(void *ptr) {
-    iWindow *win = get_Window();
-    const iWidget *oldHover = win->hover;
-    iTouchState *d = ptr;
-    /* Check for long presses to simulate right clicks. */
-    const uint32_t nowTime = SDL_GetTicks();
-    iForEach(Array, i, d->touches) {
-        iTouch *touch = i.value;
-        /* Post the next pending scroll. */
-        if (touch->numPendingScroll > touch->pendingScrollThreshold) {
-            const iInt2 pixels = touch->pendingScroll[0];
+static void postPendingScroll_TouchState_(iTouchState *d, iTouch *touch) {
+    if (touch->numPendingScroll > touch->pendingScrollThreshold) {
+        const iInt2 pixels = touch->pendingScroll[0];
 //            printf("%u :: (%d/%d) pending scroll %d,%d\n", nowTime, touch->numPendingScroll, touch->pendingScrollThreshold, pixels.x, pixels.y);
-            memmove(touch->pendingScroll, touch->pendingScroll + 1,
-                    sizeof(touch->pendingScroll[0]) * (iElemCount(touch->pendingScroll) - 1));
-            touch->numPendingScroll--;
-            dispatchMotion_Touch_(touch->startPos, 0);
-            setCurrent_Root(touch->affinity->root);
-            dispatchEvent_Widget(touch->affinity, (SDL_Event *) &(SDL_MouseWheelEvent){
+        memmove(touch->pendingScroll, touch->pendingScroll + 1,
+                sizeof(touch->pendingScroll[0]) * (iElemCount(touch->pendingScroll) - 1));
+        touch->numPendingScroll--;
+        dispatchMotion_Touch_(touch->startPos, 0);
+        setCurrent_Root(touch->affinity->root);
+        dispatchEvent_Widget(touch->affinity, (SDL_Event *) &(SDL_MouseWheelEvent){
                 .type = SDL_MOUSEWHEEL,
                 .which = SDL_TOUCH_MOUSEID,
                 .windowID = id_Window(window_Widget(touch->affinity)),
@@ -296,10 +288,21 @@ static void update_TouchState_(void *ptr) {
                 .x = pixels.x,
                 .y = pixels.y,
                 .direction = perPixel_MouseWheelFlag,
-            });
-            /* TODO: Keep increasing movement if the direction is the same. */
-            clearWidgetMomentum_TouchState_(d, touch->affinity);
-        }
+        });
+        /* TODO: Keep increasing movement if the direction is the same. */
+        clearWidgetMomentum_TouchState_(d, touch->affinity);
+    }
+}
+
+static void update_TouchState_(void *ptr) {
+    iWindow *win = get_Window();
+    const iWidget *oldHover = win->hover;
+    iTouchState *d = ptr;
+    /* Check for long presses to simulate right clicks. */
+    const uint32_t nowTime = SDL_GetTicks();
+    iForEach(Array, i, d->touches) {
+        iTouch *touch = i.value;
+        postPendingScroll_TouchState_(d, touch);
         if (touch->pinchId || touch->isTouchDrag) {
             continue;
         }
@@ -691,6 +694,10 @@ iBool processEvent_Touch(const SDL_Event *ev) {
                     touch->pendingScrollThreshold = 0;
 #endif
                     touch->numPendingScroll++;
+#if defined (iPlatformAndroidMobile)
+                    /* No need to wait. */
+                    postPendingScroll_TouchState_(d, touch);
+#endif
                 }
             }
         }
diff --git a/src/ui/util.c b/src/ui/util.c
index 6803a108..ec720bae 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -2566,8 +2566,8 @@ iWidget *makePreferences_Widget(void) {
             { "toggle id:prefs.gemtext.ansi.fg" },
             { "toggle id:prefs.gemtext.ansi.bg" },
             { "toggle id:prefs.gemtext.ansi.fontstyle" },
-            { "padding android:1" },
-            { "dropdown android:1 id:prefs.font.ui", 0, 0, (const void *) constData_Array(makeFontItems_("ui")) },
+//            { "padding android:1" },
+//            { "dropdown android:1 id:prefs.font.ui", 0, 0, (const void *) constData_Array(makeFontItems_("ui")) },
             { "padding" },
             { "button text:" fontpack_Icon " " uiTextAction_ColorEscape "${menu.fonts}", 0, 0, "!open url:about:fonts" },
             { NULL }  
diff --git a/src/ui/window.c b/src/ui/window.c
index 7186a484..f58d7b46 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -1058,6 +1058,7 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) {
                 postCommand_App("media.player.update"); /* in case a player needs updating */
                 return iFalse; /* unfreeze all frozen windows */
             }
+#if 0
             if (event.type == SDL_USEREVENT && isCommand_UserEvent(ev, "window.sysframe") && mw) {
                 /* This command is sent on Android to update the keyboard height. */
                 const char *cmd = command_UserEvent(ev);
@@ -1082,6 +1083,7 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) {
                 setKeyboardHeight_MainWindow(mw, top + mw->maxDrawableHeight - bottom);
                 return iTrue;
             }
+#endif
             if (processEvent_Touch(&event)) {
                 return iTrue;
             }
Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.12/cdiff/e956dbda62a41fe1799e7e8af5ea42a53d8aebcd
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
181.35365 milliseconds
Gemini-to-HTML Time
0.404064 milliseconds

This content has been proxied by September (ba2dc).