Skip to content

Commit

Permalink
kbswipe: Compat w backswipe on newer firmwares
Browse files Browse the repository at this point in the history
  • Loading branch information
thyttan committed Aug 3, 2023
1 parent 4061bd2 commit 8ba3c68
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
2 changes: 2 additions & 0 deletions apps/kbswipe/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
0.06: Support input of numbers and uppercase characters.
0.07: Support input of symbols.
0.08: Redone patterns a,e,m,w,z.
0.09: Catch and discard swipe events on fw2v19 and up (as well as some cutting
edge 2v18 ones), allowing compatability with the Back Swipe app.
40 changes: 25 additions & 15 deletions apps/kbswipe/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,28 +253,38 @@ exports.input = function(options) {
};
Bangle.drawWidgets();

let dragHandlerKB = e=>{
"ram";
if (isInside(R, e)) {
if (lastDrag) g.reset().setColor("#f00").drawLine(lastDrag.x,lastDrag.y,e.x,e.y);
lastDrag = e.b ? e : 0;
}
}

let touchHandlerKB = (n,e) => {
if (WIDGETS.kbswipe && isInside({x: WIDGETS.kbswipe.x, y: WIDGETS.kbswipe.y, w: WIDGETS.kbswipe.width, h: 24}, e)) {
// touch inside widget
cycleInput();
} else if (isInside(R, e)) {
// touch inside app area
show();
}
}

let catchSwipe = ()=>{
E.stopEventPropagation&&E.stopEventPropagation();
};

return new Promise((resolve,reject) => {
Bangle.setUI({mode:"custom", drag:e=>{
"ram";
if (isInside(R, e)) {
if (lastDrag) g.reset().setColor("#f00").drawLine(lastDrag.x,lastDrag.y,e.x,e.y);
lastDrag = e.b ? e : 0;
}
},touch:(n,e) => {
if (WIDGETS.kbswipe && isInside({x: WIDGETS.kbswipe.x, y: WIDGETS.kbswipe.y, w: WIDGETS.kbswipe.width, h: 24}, e)) {
// touch inside widget
cycleInput();
} else if (isInside(R, e)) {
// touch inside app area
show();
}
}, back:()=>{
Bangle.setUI({mode:"custom", drag:dragHandlerKB, touch:touchHandlerKB, back:()=>{
delete WIDGETS.kbswipe;
Bangle.removeListener("stroke", strokeHandler);
Bangle.prependListener&&Bangle.removeListener('swipe', catchSwipe); // Remove swipe lister if it was added with `Bangle.prependListener()` (fw2v19 and up).
if (flashInterval) clearInterval(flashInterval);
Bangle.setUI();
g.clearRect(Bangle.appRect);
resolve(text);
}});
Bangle.prependListener&&Bangle.prependListener('swipe', catchSwipe); // Intercept swipes on fw2v19 and later. Should not break on older firmwares.
});
};
2 changes: 1 addition & 1 deletion apps/kbswipe/metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ "id": "kbswipe",
"name": "Swipe keyboard",
"version":"0.08",
"version":"0.09",
"description": "A library for text input via PalmOS style swipe gestures (beta!)",
"icon": "app.png",
"type":"textinput",
Expand Down

0 comments on commit 8ba3c68

Please sign in to comment.