diff --git a/qt/android/src/dev/ultra/launcher/HomeActivity.java b/qt/android/src/dev/ultra/launcher/HomeActivity.java index f900027..fdb2cc8 100644 --- a/qt/android/src/dev/ultra/launcher/HomeActivity.java +++ b/qt/android/src/dev/ultra/launcher/HomeActivity.java @@ -546,6 +546,16 @@ public class HomeActivity extends QtActivity { }); } + /** A sheet covers the screen from y (screen px) down, and dims the rest; y 0: no sheet. */ + static void sheetWidgets(int y, boolean dim) { + onMain(a -> { + if (a.widgetLayer == null) return; + if (y <= 0) { a.widgetLayer.sheet(0, dim); return; } + a.widgetLayer.getLocationOnScreen(a.layerAt); + a.widgetLayer.sheet(Math.max(1, y - a.layerAt[1]), dim); + }); + } + /** * Lay widget views over QML's live slots: [[id, x, y, w, h, editing], ...] in screen * px, where editing is 1 for the one showing resize handles. @@ -623,26 +633,49 @@ public class HomeActivity extends QtActivity { } /** - * Holds the widget views. The app drawer slides down over the home screen, so the - * widgets must be hidden above its edge: cover(top) clips them (and their touches) - * above top px, -1 hides them all, 0 shows them all. Touches that land on no widget - * fall through to Qt underneath. + * Holds the widget views. Qt can't draw over them, so the layer clips them itself: + * the app drawer slides down over the home screen, so cover(top) hides them above + * its edge (-1 all of them, 0 none); a sheet rises from the bottom, so sheet(bottom, + * dim) hides them below its top edge (0: no sheet) and dims the rest like the + * sheet's backdrop, which then takes their touches (a tap closes the sheet). Touches + * that land on no widget fall through to Qt underneath. */ static final class CoverLayer extends FrameLayout { - private int top; + private int top, bottom; + private boolean dim; CoverLayer(Context c) { super(c); } void cover(int y) { if (y == top) return; top = y; - setVisibility(y < 0 ? View.INVISIBLE : View.VISIBLE); - setClipBounds(y > 0 ? new Rect(0, y, Math.max(getWidth(), 1), Math.max(getHeight(), y + 1)) : null); + apply(); + } + + void sheet(int y, boolean dimmed) { + if (y == bottom && dimmed == dim) return; + bottom = y; + dim = dimmed; + apply(); + } + + private void apply() { + setVisibility(top < 0 ? View.INVISIBLE : View.VISIBLE); + setAlpha(dim ? .55f : 1f); + if (top <= 0 && bottom <= 0) { + setClipBounds(null); + } else { + int t = Math.max(top, 0), b = bottom > 0 ? bottom : Math.max(getHeight(), t + 1); + setClipBounds(new Rect(0, t, Math.max(getWidth(), 1), Math.max(b, t + 1))); + } } @Override public boolean dispatchTouchEvent(MotionEvent ev) { - if (top != 0 && ev.getActionMasked() == MotionEvent.ACTION_DOWN && (top < 0 || ev.getY() < top)) return false; + if (ev.getActionMasked() == MotionEvent.ACTION_DOWN + && (dim || top < 0 || (top > 0 && ev.getY() < top) || (bottom > 0 && ev.getY() >= bottom))) { + return false; + } return super.dispatchTouchEvent(ev); } } diff --git a/qt/qml/Main.qml b/qt/qml/Main.qml index 2a3b6c8..92c1ad6 100644 --- a/qt/qml/Main.qml +++ b/qt/qml/Main.qml @@ -297,12 +297,13 @@ Window { } // ---- telling Host where the live widget slots are - // A slot is live (its native view is shown over it) while nothing covers the home - // screen. While one is resized the others step aside, so nothing covers its handles. - // Under the open drawer the widgets stay put and the drawer's edge covers them. + // A slot is live (its native view is shown over it) unless the drawer is open. While + // one is resized the others step aside, so nothing covers its handles. Under the + // open drawer the widgets stay put and the drawer's edge covers them; under a sheet + // they stay put too, dimmed, and hidden below the sheet's edge (sheetCover). readonly property var liveSlots: { const out = []; - if (drawerOpen || sheet !== "") return out; + if (drawerOpen) return out; for (let i = 0; i < home.length; i++) { const s = home[i], b = boxOf(i); if (s.kind !== "widget" || !b || (resizing >= 0 && i !== resizing)) continue; @@ -314,7 +315,7 @@ Window { property string placed: "" function place() { const j = JSON.stringify(liveSlots); - if (j === placed || (drawerOpen && sheet === "")) return; + if (j === placed || drawerOpen) return; placed = j; Host.placeWidgets(liveSlots); } @@ -350,6 +351,25 @@ Window { const gy = y < 0 ? -1 : homeContent.mapToGlobal(0, y).y; if (gy !== coverSent) { coverSent = gy; Host.coverWidgets(gy); } } + // Native widgets under a sheet: hidden below its top edge, the rest dimmed. + readonly property var sheets: [menuSheet, itemSheet, appSheet, widgetSheet] + readonly property real sheetEdge: { + let y = 0; + for (const s of sheets) if (s.visible) y = y > 0 ? Math.min(y, s.edge) : Math.max(1, s.edge); + return y; + } + readonly property bool sheetDim: sheets.some(s => s.open) + property string sheetSent: "0,false" + function sheetCover() { + const y = sheetEdge > 0 ? homeContent.mapToGlobal(0, sheetEdge).y : 0; + const k = Math.round(y) + "," + sheetDim; + if (k === sheetSent) return; + sheetSent = k; + Host.sheetWidgets(y, sheetDim); + } + onSheetEdgeChanged: sheetCover() + onSheetDimChanged: sheetCover() + onFrameSwapped: if (uncoverPending) { uncoverPending = false; coverSent = 0; Host.coverWidgets(0); } // ---- Host @@ -464,7 +484,7 @@ Window { readonly property bool isLifted: index === root.lifted readonly property bool isResizing: index === root.resizing readonly property bool live: Host.android && isWidget && !root.drawerOpen - && root.sheet === "" && (root.resizing < 0 || isResizing) + && (root.resizing < 0 || isResizing) readonly property int row: isWidget ? -1 : (root.appRow[s.str] ?? -1) objectName: "slot" + index visible: b !== null diff --git a/qt/qml/SearchField.qml b/qt/qml/SearchField.qml index fa97fbe..82e82a3 100644 --- a/qt/qml/SearchField.qml +++ b/qt/qml/SearchField.qml @@ -20,11 +20,15 @@ Rectangle { function focusNow() { input.forceActiveFocus(); Qt.inputMethod.show() } // Empty the box, including a word still being composed, and keep typing in it. + // Android commits a composing word asynchronously, so it can land after the clear: + // clear again once it has. function clearText() { - Qt.inputMethod.reset(); + Qt.inputMethod.commit(); input.clear(); input.forceActiveFocus(); + clearAgain.restart(); } + Timer { id: clearAgain; interval: 120; onTriggered: input.clear() } TextInput { id: input @@ -37,7 +41,9 @@ Rectangle { selectionColor: Qt.rgba(1, 1, 1, .35) font.pixelSize: root.fontSize clip: true - inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase + // No suggestions: Android keyboards then type straight into the box rather than + // composing words, so the list filters on every key. + inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhSensitiveData | Qt.ImhNoAutoUppercase onAccepted: root.accepted() Keys.onEscapePressed: root.escaped() Text { diff --git a/qt/qml/Sheet.qml b/qt/qml/Sheet.qml index 5993f26..7c1cfe1 100644 --- a/qt/qml/Sheet.qml +++ b/qt/qml/Sheet.qml @@ -9,6 +9,8 @@ Item { property real bottomInset: 0 property real maxWidth: 560 default property alias content: column.data + // Where the panel's top edge is, for hiding native widgets under it. + readonly property real edge: panel.y signal closeRequested() anchors.fill: parent visible: open || panel.y < height diff --git a/qt/src/backend.cpp b/qt/src/backend.cpp index a783388..c6d79c2 100644 --- a/qt/src/backend.cpp +++ b/qt/src/backend.cpp @@ -198,6 +198,16 @@ void Backend::coverWidgets(qreal y) { #endif } +void Backend::sheetWidgets(qreal y, bool dim) { +#ifdef Q_OS_ANDROID + const int py = y <= 0 ? 0 : int(std::floor(y * dpr())); + QJniObject::callStaticMethod(kActivity, "sheetWidgets", "(IZ)V", jint(py), jboolean(dim)); +#else + Q_UNUSED(y); + Q_UNUSED(dim); +#endif +} + QVariantMap Backend::widgetLimits(int id) const { #ifdef Q_OS_ANDROID const QJsonObject o = QJsonDocument::fromJson( diff --git a/qt/src/backend.h b/qt/src/backend.h index 8646b5e..9bace54 100644 --- a/qt/src/backend.h +++ b/qt/src/backend.h @@ -46,6 +46,8 @@ public: Q_INVOKABLE void placeWidgets(const QVariantList &list); // The drawer covers the screen down to global logical y; -1 all of it, 0 none. Q_INVOKABLE void coverWidgets(qreal y); + // A sheet covers the screen from global logical y down (0: none) and dims the rest. + Q_INVOKABLE void sheetWidgets(qreal y, bool dim); // {w, minW, minH, maxW, maxH (0: no limit), h, v} in logical px. Q_INVOKABLE QVariantMap widgetLimits(int id) const; // [{x, y, w, h}] in global logical px: no system back swipe there.