BangleApps icon indicating copy to clipboard operation
BangleApps copied to clipboard

swipeinv: (WIP) Add inversion of drag events. Refactor to hijack and modify the events

Open thyttan opened this issue 10 months ago • 6 comments

... instead of the handling of them. This should add compatibility with most apps, even if Bangle.setUI is not used.

Ping @nxdefiant and @jt-nti , what do you think of this approach?

I'm also thinking of adding settings so horizontal and vertical inversion can be set individually, also per app.

thyttan avatar Apr 20 '25 22:04 thyttan

Nice, I have not tested this, but looks good to me.

nxdefiant avatar Apr 21 '25 06:04 nxdefiant

I think this works now, can be tried at https://thyttan.github.io/BangleApps/?id=swipeinv

not looking to merge yet though.

thyttan avatar May 01 '25 23:05 thyttan

@thyttan looks interesting, I'll give it a try when I get a chance, thanks

jt-nti avatar May 02 '25 08:05 jt-nti

I think I notice this approach making the watch feel a bit slower than the old one. So that's a minus in that case. But not conclusive, just a feeling.

thyttan avatar May 02 '25 21:05 thyttan

I also had the idea to do the inversions by wrapping the listener functions at their registration. That way swipeinv would not depend on being first in the listener call chain to work.

It's here: https://github.com/thyttan/BangleApps/commit/5cbb72ee55f7fb7d335ffba228575a862a0ae612

But I didn't get that to work yet.

thyttan avatar May 02 '25 21:05 thyttan

Doesn't feel too much slower (if at all) now since I added ram keyword to functions.

thyttan avatar May 04 '25 15:05 thyttan

So you're happy to merge this now?

As it's just an optional app I feel like there's no problem merging this in?

gfwilliams avatar Sep 02 '25 10:09 gfwilliams

Yes I believe it can go in 🙂

If I find a better approach I can do another PR. But on that note, do you think wrapping listener functions (Bangle.on/prependListener) could be better? I suspect it may not be possible without significantly slowing things down though.

I also had the idea to do the inversions by wrapping the listener functions at their registration. That way swipeinv would not depend on being first in the listener call chain to work.

It's here: https://github.com/thyttan/BangleApps/commit/5cbb72ee55f7fb7d335ffba228575a862a0ae612

But I didn't get that to work yet.

thyttan avatar Sep 02 '25 11:09 thyttan

Thanks! I reckon the current method is good enough. Overriding .on/etc feels like it's going to cause issues (removeListener likely won't work then).

Although looking at it, because drag passes an object, you don't need all the re-emit stuff that dragInverter does. Just:

let dragInverter = (e) => {
        "ram"
        const APP_ID = getAppIdFromCurrentFile();
        if (SETTINGS.global ^ Object.keys(SETTINGS.apps).includes(APP_ID)) {
            e.inverted = true;
            if (SETTINGS.global ^ (SETTINGS.apps[APP_ID]&&SETTINGS.apps[APP_ID].dragH)) {e.dx *= -1;}
            if (SETTINGS.global ^ (SETTINGS.apps[APP_ID]&&SETTINGS.apps[APP_ID].dragV)) {e.dy *= -1;}
        }
      }

Because subsequent functions in that chain will get the same (modified) object. That'll speed it up.

swipeInverter needs to be as-is

gfwilliams avatar Sep 02 '25 13:09 gfwilliams

Did that change you suggested - haven't tested yet so changed to draft.

thyttan avatar Sep 03 '25 17:09 thyttan

Tried it some - seems to work ok! Thanks!

thyttan avatar Sep 12 '25 19:09 thyttan

Great, thanks!

gfwilliams avatar Sep 15 '25 13:09 gfwilliams