Use dispatchTouchEvent for widget drag and prioritize widgets in layout
This commit is contained in:
1 parent
3cf65af790
commit
f4e4cd3884
3 files changed
+31
-32
No files matched your search
@@ -545,7 +545,7 @@ public class LauncherActivity extends NativeActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
switch (ev.getActionMasked()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
lifted = false;
|
||||
@@ -553,36 +553,20 @@ public class LauncherActivity extends NativeActivity {
|
||||
downRawY = lastRawY = ev.getRawY();
|
||||
main.removeCallbacks(longPress);
|
||||
main.postDelayed(longPress, 450);
|
||||
break;
|
||||
super.dispatchTouchEvent(ev);
|
||||
return true;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
handleMove(ev);
|
||||
if (lifted) return true;
|
||||
break;
|
||||
return super.dispatchTouchEvent(ev);
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
boolean wasLifted = lifted;
|
||||
handleEnd(ev);
|
||||
if (wasLifted) return true;
|
||||
break;
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
return super.onInterceptTouchEvent(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);
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -351,6 +351,17 @@ void LauncherWindow::pollHostEvents() {
|
||||
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 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].y = row;
|
||||
saveHome();
|
||||
|
||||
+14
-10
@@ -37,17 +37,21 @@ 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);
|
||||
for (int i = 0; i < items.size(); ++i) {
|
||||
const auto &s = items[i];
|
||||
if (!s.isWidget() && hidden.contains(s.component)) continue;
|
||||
const int w = std::clamp(s.w, 1, cols);
|
||||
const int h = std::max(1, s.h);
|
||||
if (s.x >= 0 && s.y >= 0 && isFree(s.x, s.y, w, h)) {
|
||||
occupy(s.x, s.y, w, h);
|
||||
out.cells[i] = {s.x, s.y};
|
||||
placed[i] = true;
|
||||
for (int pass = 0; pass < 2; ++pass) {
|
||||
const bool wantWidget = (pass == 0);
|
||||
for (int i = 0; i < items.size(); ++i) {
|
||||
const auto &s = items[i];
|
||||
if (s.isWidget() != wantWidget) continue;
|
||||
if (!s.isWidget() && hidden.contains(s.component)) continue;
|
||||
const int w = std::clamp(s.w, 1, cols);
|
||||
const int h = std::max(1, s.h);
|
||||
if (s.x >= 0 && s.y >= 0 && isFree(s.x, s.y, w, h)) {
|
||||
occupy(s.x, s.y, w, h);
|
||||
out.cells[i] = {s.x, s.y};
|
||||
placed[i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user