Qt: keep widgets under menus, and clear the search reliably

A sheet (the long-press menus, the widget picker) used to take every native
widget off the screen, since Qt can't draw over them. Now they stay: the
widget layer hides them below the sheet's top edge as it rises and dims
the rest like the sheet's backdrop, which takes their touches.

The search boxes ask for no suggestions, so Android keyboards type straight
in instead of composing words, and the clear button commits and clears
again once a late commit has landed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hiQsCq11CwCPnKPp9D
This commit is contained in:
Claude committed 2026-11-02 05:37:02 +00:00
1 parent e050f52417
commit bc37c623c8
6 files changed
+89 -16

No files matched your search

@@ -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 * 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. * 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 * Holds the widget views. Qt can't draw over them, so the layer clips them itself:
* widgets must be hidden above its edge: cover(top) clips them (and their touches) * the app drawer slides down over the home screen, so cover(top) hides them above
* above top px, -1 hides them all, 0 shows them all. Touches that land on no widget * its edge (-1 all of them, 0 none); a sheet rises from the bottom, so sheet(bottom,
* fall through to Qt underneath. * 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 { static final class CoverLayer extends FrameLayout {
private int top; private int top, bottom;
private boolean dim;
CoverLayer(Context c) { super(c); } CoverLayer(Context c) { super(c); }
void cover(int y) { void cover(int y) {
if (y == top) return; if (y == top) return;
top = y; top = y;
setVisibility(y < 0 ? View.INVISIBLE : View.VISIBLE); apply();
setClipBounds(y > 0 ? new Rect(0, y, Math.max(getWidth(), 1), Math.max(getHeight(), y + 1)) : null); }
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 @Override
public boolean dispatchTouchEvent(MotionEvent ev) { 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); return super.dispatchTouchEvent(ev);
} }
} }
+26 -6
View File
@@ -297,12 +297,13 @@ Window {
} }
// ---- telling Host where the live widget slots are // ---- telling Host where the live widget slots are
// A slot is live (its native view is shown over it) while nothing covers the home // A slot is live (its native view is shown over it) unless the drawer is open. While
// screen. While one is resized the others step aside, so nothing covers its handles. // one is resized the others step aside, so nothing covers its handles. Under the
// Under the open drawer the widgets stay put and the drawer's edge covers them. // 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: { readonly property var liveSlots: {
const out = []; const out = [];
if (drawerOpen || sheet !== "") return out; if (drawerOpen) return out;
for (let i = 0; i < home.length; i++) { for (let i = 0; i < home.length; i++) {
const s = home[i], b = boxOf(i); const s = home[i], b = boxOf(i);
if (s.kind !== "widget" || !b || (resizing >= 0 && i !== resizing)) continue; if (s.kind !== "widget" || !b || (resizing >= 0 && i !== resizing)) continue;
@@ -314,7 +315,7 @@ Window {
property string placed: "" property string placed: ""
function place() { function place() {
const j = JSON.stringify(liveSlots); const j = JSON.stringify(liveSlots);
if (j === placed || (drawerOpen && sheet === "")) return; if (j === placed || drawerOpen) return;
placed = j; placed = j;
Host.placeWidgets(liveSlots); Host.placeWidgets(liveSlots);
} }
@@ -350,6 +351,25 @@ Window {
const gy = y < 0 ? -1 : homeContent.mapToGlobal(0, y).y; const gy = y < 0 ? -1 : homeContent.mapToGlobal(0, y).y;
if (gy !== coverSent) { coverSent = gy; Host.coverWidgets(gy); } 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); } onFrameSwapped: if (uncoverPending) { uncoverPending = false; coverSent = 0; Host.coverWidgets(0); }
// ---- Host // ---- Host
@@ -464,7 +484,7 @@ Window {
readonly property bool isLifted: index === root.lifted readonly property bool isLifted: index === root.lifted
readonly property bool isResizing: index === root.resizing readonly property bool isResizing: index === root.resizing
readonly property bool live: Host.android && isWidget && !root.drawerOpen 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) readonly property int row: isWidget ? -1 : (root.appRow[s.str] ?? -1)
objectName: "slot" + index objectName: "slot" + index
visible: b !== null visible: b !== null
+8 -2
View File
@@ -20,11 +20,15 @@ Rectangle {
function focusNow() { input.forceActiveFocus(); Qt.inputMethod.show() } function focusNow() { input.forceActiveFocus(); Qt.inputMethod.show() }
// Empty the box, including a word still being composed, and keep typing in it. // 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() { function clearText() {
Qt.inputMethod.reset(); Qt.inputMethod.commit();
input.clear(); input.clear();
input.forceActiveFocus(); input.forceActiveFocus();
clearAgain.restart();
} }
Timer { id: clearAgain; interval: 120; onTriggered: input.clear() }
TextInput { TextInput {
id: input id: input
@@ -37,7 +41,9 @@ Rectangle {
selectionColor: Qt.rgba(1, 1, 1, .35) selectionColor: Qt.rgba(1, 1, 1, .35)
font.pixelSize: root.fontSize font.pixelSize: root.fontSize
clip: true 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() onAccepted: root.accepted()
Keys.onEscapePressed: root.escaped() Keys.onEscapePressed: root.escaped()
Text { Text {
+2
View File
@@ -9,6 +9,8 @@ Item {
property real bottomInset: 0 property real bottomInset: 0
property real maxWidth: 560 property real maxWidth: 560
default property alias content: column.data 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() signal closeRequested()
anchors.fill: parent anchors.fill: parent
visible: open || panel.y < height visible: open || panel.y < height
+10
View File
@@ -198,6 +198,16 @@ void Backend::coverWidgets(qreal y) {
#endif #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<void>(kActivity, "sheetWidgets", "(IZ)V", jint(py), jboolean(dim));
#else
Q_UNUSED(y);
Q_UNUSED(dim);
#endif
}
QVariantMap Backend::widgetLimits(int id) const { QVariantMap Backend::widgetLimits(int id) const {
#ifdef Q_OS_ANDROID #ifdef Q_OS_ANDROID
const QJsonObject o = QJsonDocument::fromJson( const QJsonObject o = QJsonDocument::fromJson(
+2
View File
@@ -46,6 +46,8 @@ public:
Q_INVOKABLE void placeWidgets(const QVariantList &list); Q_INVOKABLE void placeWidgets(const QVariantList &list);
// The drawer covers the screen down to global logical y; -1 all of it, 0 none. // The drawer covers the screen down to global logical y; -1 all of it, 0 none.
Q_INVOKABLE void coverWidgets(qreal y); 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. // {w, minW, minH, maxW, maxH (0: no limit), h, v} in logical px.
Q_INVOKABLE QVariantMap widgetLimits(int id) const; Q_INVOKABLE QVariantMap widgetLimits(int id) const;
// [{x, y, w, h}] in global logical px: no system back swipe there. // [{x, y, w, h}] in global logical px: no system back swipe there.