From 95941a8fca886ba258716c535d51d0d68d075993 Mon Sep 17 00:00:00 2001

From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= jaakko.keranen@iki.fi

Date: Sat, 18 Sep 2021 08:26:31 +0300

Subject: [PATCH 1/1] Tracking hover widget; cleanup

The hover widget may get deleted during event processing, so Window keeps track of it for refreshing.

TODO: Random crash when a destroyed menu is still in the onTop array (?).


src/app.c | 20 ++++++--------------

src/ui/inputwidget.c | 1 +

src/ui/mobile.c | 6 +++---

src/ui/mobile.h | 2 --

src/ui/root.c | 4 +++-

src/ui/touch.c | 6 +-----

src/ui/widget.c | 22 +++++++++++++++-------

src/ui/window.c | 6 +-----

src/ui/window.h | 2 +-

9 files changed, 31 insertions(+), 38 deletions(-)

diff --git a/src/app.c b/src/app.c

index ed72c450..e06a32ce 100644

--- a/src/app.c

+++ b/src/app.c

@@ -1069,11 +1069,6 @@ iLocalDef iBool isWaitingAllowed_App_(iApp *d) {

     return iFalse;

 }

#endif

-//#if defined (iPlatformMobile)

-// if (!isFinished_Anim(&d->window->rootOffset)) {

-// return iFalse;

-// }

-//#endif

 return !value_Atomic(&d->pendingRefresh) && isEmpty_SortedArray(&d->tickers);

}

@@ -1273,7 +1268,7 @@ void processEvents_App(enum iAppEventMode eventMode) {

                 }

             }

#endif

             iBool wasUsed = processEvent_Window(d->window, &ev);

             if (!wasUsed) {

                 /* There may be a key bindings for this. */

@@ -1309,8 +1304,8 @@ void processEvents_App(enum iAppEventMode eventMode) {

                 free(ev.user.data1);

             }

             /* Update when hover has changed. */

                 refresh_Widget(d->window->hover);

             }

             break;

@@ -1318,7 +1313,7 @@ void processEvents_App(enum iAppEventMode eventMode) {

     }

 }

#if defined (LAGRANGE_ENABLE_IDLE_SLEEP)

     /* This is where we spend most of our time when idle. 60 Hz still quite a lot but we

        can't wait too long after the user tries to interact again with the app. In any

        case, on macOS SDL_WaitEvent() seems to use 10x more CPU time than sleeping. */

@@ -1410,10 +1405,7 @@ void refresh_App(void) {

 }

#endif

 if (!exchange_Atomic(&d->pendingRefresh, iFalse)) {

-// if (isFinished_Anim(&d->window->rootOffset)) {

-// }

 }

// iTime draw;

// initCurrent_Time(&draw);

@@ -2746,7 +2738,7 @@ iBool handleCommand_App(const char *cmd) {

 else if (equal_Command(cmd, "feeds.update.finished")) {

     showCollapsed_Widget(findWidget_Root("feeds.progress"), iFalse);

     refreshFinished_Feeds();

     return iFalse;

 }

 else if (equal_Command(cmd, "visited.changed")) {

diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c

index d078593a..a561d5bd 100644

--- a/src/ui/inputwidget.c

+++ b/src/ui/inputwidget.c

@@ -1916,6 +1916,7 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) {

     }

     return iFalse;

 }

// else if (isCommand_UserEvent(ev, "keyboard.changed")) {

// if (isFocused_Widget(d) && arg_Command(command_UserEvent(ev))) {

// iRect rect = bounds_Widget(w);

diff --git a/src/ui/mobile.c b/src/ui/mobile.c

index e04e8d20..3cb6e631 100644

--- a/src/ui/mobile.c

+++ b/src/ui/mobile.c

@@ -425,10 +425,10 @@ static iWidget *addChildPanel_(iWidget *parent, iLabelWidget *panelButton,

 return panel;

}

-void finalizeSheet_Mobile(iWidget *sheet) {

+//void finalizeSheet_Mobile(iWidget *sheet) {

+// arrange_Widget(sheet);

// postRefresh_App();

-}

+//}

static size_t countItems_(const iMenuItem *itemsNullTerminated) {

 size_t num = 0;

diff --git a/src/ui/mobile.h b/src/ui/mobile.h

index 957c0e42..9d7ac8e4 100644

--- a/src/ui/mobile.h

+++ b/src/ui/mobile.h

@@ -55,5 +55,3 @@ enum iTransitionDir {

void setupMenuTransition_Mobile (iWidget *menu, iBool isIncoming);

void setupSheetTransition_Mobile (iWidget *sheet, int flags);

-void finalizeSheet_Mobile (iWidget *sheet);

diff --git a/src/ui/root.c b/src/ui/root.c

index 71f53af4..21bed366 100644

--- a/src/ui/root.c

+++ b/src/ui/root.c

@@ -271,13 +271,15 @@ void destroyPending_Root(iRoot *d) {

 setCurrent_Root(d);

 iForEach(PtrSet, i, d->pendingDestruction) {

     iWidget *widget = *i.value;

     if (!isFinished_Anim(&widget->visualOffset) ||

         isBeingVisuallyOffsetByReference_Widget(widget)) {

         continue;

     }

     if (widget->flags & keepOnTop_WidgetFlag) {

     }

     if (widget->parent) {

         removeChild_Widget(widget->parent, widget);

     }

diff --git a/src/ui/touch.c b/src/ui/touch.c

index 5130149b..613f2c0d 100644

--- a/src/ui/touch.c

+++ b/src/ui/touch.c

@@ -472,13 +472,9 @@ iBool processEvent_Touch(const SDL_Event *ev) {

 }

 iTouchState *d = touchState_();

 iWindow *window = get_Window();    

-// if (!isFinished_Anim(&window->rootOffset)) {

-// return iFalse;

-// }

 const iInt2 rootSize = size_Window(window);

 const SDL_TouchFingerEvent *fing = &ev->tfinger;

 const uint32_t nowTime = SDL_GetTicks();

 if (ev->type == SDL_FINGERDOWN) {

     /* Register the new touch. */

diff --git a/src/ui/widget.c b/src/ui/widget.c

index 25142691..184ce2a3 100644

--- a/src/ui/widget.c

+++ b/src/ui/widget.c

@@ -163,11 +163,15 @@ static void aboutToBeDestroyed_Widget_(iWidget *d) {

 d->flags |= destroyPending_WidgetFlag;

 if (isFocused_Widget(d)) {

     setFocus_Widget(NULL);

 }

 remove_Periodic(periodic_App(), d);

 if (isHover_Widget(d)) {

 }

 iForEach(ObjectList, i, d->children) {

     aboutToBeDestroyed_Widget_(as_Widget(i.object));

@@ -214,6 +218,7 @@ void setFlags_Widget(iWidget *d, int64_t flags, iBool set) {

         }

         else {

             removeOne_PtrArray(onTop, d);

         }

     }

     if (d->flags & arrangeWidth_WidgetFlag &&

@@ -880,9 +885,6 @@ iInt2 localToWindow_Widget(const iWidget *d, iInt2 localCoord) {

     applyVisualOffset_Widget_(w, &pos);

     addv_I2(&window, pos);

 }

-//#if defined (iPlatformMobile)

-// window.y += value_Anim(&get_Window()->rootOffset);

-//#endif

 return window;

}

@@ -962,7 +964,11 @@ static iBool filterEvent_Widget_(const iWidget *d, const SDL_Event *ev) {

}

void unhover_Widget(void) {

}

iBool dispatchEvent_Widget(iWidget *d, const SDL_Event *ev) {

@@ -1415,7 +1421,9 @@ static void findPotentiallyVisible_Widget_(const iWidget *d, iPtrArray *pvs) {

 iRect fullyMasked = zero_Rect();

 if (isRoot_Widget_(d)) {

     iReverseConstForEach(PtrArray, i, onTop_Root(d->root)) {

     }

 }

 iReverseConstForEach(ObjectList, i, d->children) {

diff --git a/src/ui/window.c b/src/ui/window.c

index ed2ec024..0dd248e6 100644

--- a/src/ui/window.c

+++ b/src/ui/window.c

@@ -405,6 +405,7 @@ void init_Window(iWindow *d, iRect rect) {

 d->splitMode = d->pendingSplitMode = 0;

 d->pendingSplitUrl = new_String();

 d->hover = NULL;

 d->mouseGrab = NULL;

 d->focus = NULL;

 iZap(d->cursors);

@@ -421,7 +422,6 @@ void init_Window(iWindow *d, iRect rect) {

 d->ignoreClick = iFalse;

 d->focusGainedAt = 0;

 d->keyboardHeight = 0;

-// init_Anim(&d->rootOffset, 0.0f);

 uint32_t flags = 0;

#if defined (iPlatformAppleDesktop)

 SDL_SetHint(SDL_HINT_RENDER_DRIVER, shouldDefaultToMetalRenderer_MacOS() ? "metal" : "opengl");

@@ -1215,10 +1215,6 @@ iBool isOpenGLRenderer_Window(void) {

void setKeyboardHeight_Window(iWindow *d, int height) {

 if (d->keyboardHeight != height) {

     d->keyboardHeight = height;

-// if (height == 0) {

-// setFlags_Anim(&d->rootOffset, easeBoth_AnimFlag, iTrue);

-// setValue_Anim(&d->rootOffset, 0, 250);

-// }

     postCommandf_App("keyboard.changed arg:%d", height);

     postRefresh_App();

 }

diff --git a/src/ui/window.h b/src/ui/window.h

index a5b8f137..282e1682 100644

--- a/src/ui/window.h

+++ b/src/ui/window.h

@@ -86,6 +86,7 @@ struct Impl_Window {

 iRoot *       roots[2];     /* root widget and UI state; second one is for split mode */

 iRoot *       keyRoot;      /* root that has the current keyboard input focus */

 iWidget *     hover;

 iWidget *     mouseGrab;

 iWidget *     focus;

 float         pixelRatio;   /* conversion between points and pixels, e.g., coords, window size */

@@ -98,7 +99,6 @@ struct Impl_Window {

 SDL_Cursor *  cursors[SDL_NUM_SYSTEM_CURSORS];

 SDL_Cursor *  pendingCursor;

 int           loadAnimTimer;

-// iAnim rootOffset;

 int           keyboardHeight; /* mobile software keyboards */

};

--

2.25.1

Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.7/patch/95941a8fca886ba258716c535d51d0d68d075993.patch
Status Code
Success (20)
Meta
text/plain
Capsule Response Time
74.645239 milliseconds
Gemini-to-HTML Time
5.113657 milliseconds

This content has been proxied by September (ba2dc).