Use dispatchTouchEvent for widget drag and prioritize widgets in layout

This commit is contained in:
nandi committed 2026-11-13 12:12:32 -08:00
1 parent 3cf65af790
commit f4e4cd3884
3 files changed
+22 -23

No files matched your search

@@ -545,7 +545,7 @@ public class LauncherActivity extends NativeActivity {
} }
@Override @Override
public boolean onInterceptTouchEvent(MotionEvent ev) { public boolean dispatchTouchEvent(MotionEvent ev) {
switch (ev.getActionMasked()) { switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_DOWN:
lifted = false; lifted = false;
@@ -553,36 +553,20 @@ public class LauncherActivity extends NativeActivity {
downRawY = lastRawY = ev.getRawY(); downRawY = lastRawY = ev.getRawY();
main.removeCallbacks(longPress); main.removeCallbacks(longPress);
main.postDelayed(longPress, 450); main.postDelayed(longPress, 450);
break; super.dispatchTouchEvent(ev);
return true;
case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_MOVE:
handleMove(ev); handleMove(ev);
if (lifted) return true; if (lifted) return true;
break; return super.dispatchTouchEvent(ev);
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_CANCEL:
boolean wasLifted = lifted; boolean wasLifted = lifted;
handleEnd(ev); handleEnd(ev);
if (wasLifted) return true; if (wasLifted) return true;
break; return super.dispatchTouchEvent(ev);
} }
return super.onInterceptTouchEvent(ev); return super.dispatchTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_MOVE:
handleMove(ev);
if (lifted) return true;
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
boolean wasLifted = lifted;
handleEnd(ev);
if (wasLifted) return true;
break;
}
return super.onTouchEvent(ev);
} }
} }
+11
View File
@@ -351,6 +351,17 @@ void LauncherWindow::pollHostEvents() {
const int maxCol = std::max(0, homeCols() - m_home[idx].w); const int maxCol = std::max(0, homeCols() - m_home[idx].w);
const int col = std::clamp(int(std::lround(localX / (homeColW() + Layout::kColGap))), 0, maxCol); const int col = std::clamp(int(std::lround(localX / (homeColW() + Layout::kColGap))), 0, maxCol);
const int row = std::max(0, int(std::lround(localY / (Layout::kCellH + Layout::kRowGap)))); const int row = std::max(0, int(std::lround(localY / (Layout::kCellH + Layout::kRowGap))));
const int ww = m_home[idx].w;
const int wh = m_home[idx].h;
// Unpin any app icons overlapping the widget's target rect so they reflow around it.
for (int i = 0; i < m_home.size(); ++i) {
if (i == idx || m_home[i].isWidget()) continue;
if (m_home[i].x >= col && m_home[i].x < col + ww
&& m_home[i].y >= row && m_home[i].y < row + wh) {
m_home[i].x = -1;
m_home[i].y = -1;
}
}
m_home[idx].x = col; m_home[idx].x = col;
m_home[idx].y = row; m_home[idx].y = row;
saveHome(); saveHome();
+5 -1
View File
@@ -37,10 +37,13 @@ PackedGrid packHome(const QVector<HomeSlot> &items, int cols, const QSet<QString
} }
}; };
// Pass 1: place pinned slots first if their area is free. // Pass 1: place pinned slots first (widgets before apps) if their area is free.
QVector<bool> placed(items.size(), false); QVector<bool> placed(items.size(), false);
for (int pass = 0; pass < 2; ++pass) {
const bool wantWidget = (pass == 0);
for (int i = 0; i < items.size(); ++i) { for (int i = 0; i < items.size(); ++i) {
const auto &s = items[i]; const auto &s = items[i];
if (s.isWidget() != wantWidget) continue;
if (!s.isWidget() && hidden.contains(s.component)) continue; if (!s.isWidget() && hidden.contains(s.component)) continue;
const int w = std::clamp(s.w, 1, cols); const int w = std::clamp(s.w, 1, cols);
const int h = std::max(1, s.h); const int h = std::max(1, s.h);
@@ -50,6 +53,7 @@ PackedGrid packHome(const QVector<HomeSlot> &items, int cols, const QSet<QString
placed[i] = true; placed[i] = true;
} }
} }
}
// Pass 2: pack remaining visible slots into the earliest free area. // Pass 2: pack remaining visible slots into the earliest free area.
for (int i = 0; i < items.size(); ++i) { for (int i = 0; i < items.size(); ++i) {