Fix widget drag visibility and top-left grid snapping

This commit is contained in:
nandi committed 2026-11-13 11:55:37 -08:00
1 parent 52d03decbd
commit 3cf65af790
2 files changed
+39 -26

No files matched your search

@@ -506,19 +506,25 @@ public class LauncherActivity extends NativeActivity {
WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams(); WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams();
startWinX = lp.x; startWinX = lp.x;
startWinY = lp.y; startWinY = lp.y;
nativeOnEvent("widget-lift:" + this.widgetId + ":" + lastRawX + ":" + lastRawY); nativeOnEvent("widget-lift:" + this.widgetId + ":" + startWinX + ":" + startWinY);
}; };
} }
boolean isLifted() { return lifted; }
private void handleMove(MotionEvent ev) { private void handleMove(MotionEvent ev) {
lastRawX = ev.getRawX(); lastRawX = ev.getRawX();
lastRawY = ev.getRawY(); lastRawY = ev.getRawY();
if (lifted) { if (lifted) {
WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams(); WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams();
lp.x = Math.round(startWinX + (lastRawX - downRawX)); int nx = Math.round(startWinX + (lastRawX - downRawX));
lp.y = Math.round(startWinY + (lastRawY - downRawY)); int ny = Math.round(startWinY + (lastRawY - downRawY));
getWindowManager().updateViewLayout(this, lp); if (nx != lp.x || ny != lp.y) {
nativeOnEvent("widget-drag:" + lastRawX + ":" + lastRawY); lp.x = nx;
lp.y = ny;
getWindowManager().updateViewLayout(this, lp);
nativeOnEvent("widget-drag:" + nx + ":" + ny);
}
} else if (Math.hypot(lastRawX - downRawX, lastRawY - downRawY) > touchSlop) { } else if (Math.hypot(lastRawX - downRawX, lastRawY - downRawY) > touchSlop) {
main.removeCallbacks(longPress); main.removeCallbacks(longPress);
} }
@@ -531,8 +537,10 @@ public class LauncherActivity extends NativeActivity {
setAlpha(1.0f); setAlpha(1.0f);
setScaleX(1.0f); setScaleX(1.0f);
setScaleY(1.0f); setScaleY(1.0f);
nativeOnEvent("widget-drop:" + widgetId + ":" + ev.getRawX() + ":" + ev.getRawY() int finalX = Math.round(startWinX + (ev.getRawX() - downRawX));
+ ":" + downRawX + ":" + downRawY); int finalY = Math.round(startWinY + (ev.getRawY() - downRawY));
float dist = (float) Math.hypot(ev.getRawX() - downRawX, ev.getRawY() - downRawY);
nativeOnEvent("widget-drop:" + widgetId + ":" + finalX + ":" + finalY + ":" + dist);
} }
} }
@@ -622,6 +630,9 @@ public class LauncherActivity extends NativeActivity {
lp.token = getWindow().getDecorView().getWindowToken(); lp.token = getWindow().getDecorView().getWindowToken();
AppWidgetHostView v = widgetViews.get(id); AppWidgetHostView v = widgetViews.get(id);
if (v instanceof DraggableWidgetView && ((DraggableWidgetView) v).isLifted()) {
continue;
}
if (v == null) { if (v == null) {
AppWidgetProviderInfo info = widgets.getAppWidgetInfo(id); AppWidgetProviderInfo info = widgets.getAppWidgetInfo(id);
if (info == null) continue; if (info == null) continue;
+21 -19
View File
@@ -334,12 +334,11 @@ void LauncherWindow::pollHostEvents() {
} }
} else if (ev.startsWith(QLatin1String("widget-drop:"))) { } else if (ev.startsWith(QLatin1String("widget-drop:"))) {
const QStringList parts = ev.mid(12).split(QLatin1Char(':')); const QStringList parts = ev.mid(12).split(QLatin1Char(':'));
if (parts.size() >= 5) { if (parts.size() >= 4) {
const int id = parts[0].toInt(); const int id = parts[0].toInt();
const qreal dpr = devicePixelRatio(); const qreal dpr = devicePixelRatio();
const QPointF dropPos(parts[1].toDouble() / dpr, parts[2].toDouble() / dpr); const QPointF winPos(parts[1].toDouble() / dpr, parts[2].toDouble() / dpr);
const QPointF downPos(parts[3].toDouble() / dpr, parts[4].toDouble() / dpr); const qreal dist = parts[3].toDouble() / dpr;
const qreal dist = std::hypot(dropPos.x() - downPos.x(), dropPos.y() - downPos.y());
int idx = -1; int idx = -1;
for (int i = 0; i < m_home.size(); ++i) { for (int i = 0; i < m_home.size(); ++i) {
if (m_home[i].widgetId == id) { idx = i; break; } if (m_home[i].widgetId == id) { idx = i; break; }
@@ -347,11 +346,11 @@ void LauncherWindow::pollHostEvents() {
m_liftedHome = -1; m_liftedHome = -1;
if (idx >= 0) { if (idx >= 0) {
if (dist > 12.0) { if (dist > 12.0) {
const qreal localX = dropPos.x() - gridX(); const qreal localX = winPos.x() - gridX();
const qreal localY = dropPos.y() - (gridTop() - m_homeScroll); const qreal localY = winPos.y() - (gridTop() - m_homeScroll);
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(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(localY / (Layout::kCellH + Layout::kRowGap))); const int row = std::max(0, int(std::lround(localY / (Layout::kCellH + Layout::kRowGap))));
m_home[idx].x = col; m_home[idx].x = col;
m_home[idx].y = row; m_home[idx].y = row;
saveHome(); saveHome();
@@ -637,7 +636,7 @@ void LauncherWindow::drawHome(QPainter &p) {
const qreal dpr = devicePixelRatio(); const qreal dpr = devicePixelRatio();
QJsonArray placedWidgets; QJsonArray placedWidgets;
for (int i = 0; i < m_home.size(); ++i) { for (int i = 0; i < m_home.size(); ++i) {
if (i == m_liftedHome || packed.cells[i].col < 0) continue; if (packed.cells[i].col < 0) continue;
const auto &slot = m_home[i]; const auto &slot = m_home[i];
QRectF r = Layout::cellBox(packed.cells[i], cw, slot.w, slot.h); QRectF r = Layout::cellBox(packed.cells[i], cw, slot.w, slot.h);
r.translate(gridX(), gridTop() - m_homeScroll); r.translate(gridX(), gridTop() - m_homeScroll);
@@ -651,6 +650,7 @@ void LauncherWindow::drawHome(QPainter &p) {
placedWidgets.append(entry); placedWidgets.append(entry);
continue; continue;
} }
if (i == m_liftedHome) continue;
if (r.bottom() < gridTop() || r.top() > height()) continue; if (r.bottom() < gridTop() || r.top() > height()) continue;
const int appIdx = m_appIndex.value(slot.component, -1); const int appIdx = m_appIndex.value(slot.component, -1);
const QString label = appIdx >= 0 ? m_apps[appIdx].label : slot.component.section(QLatin1Char('/'), 0, 0); const QString label = appIdx >= 0 ? m_apps[appIdx].label : slot.component.section(QLatin1Char('/'), 0, 0);
@@ -668,16 +668,18 @@ void LauncherWindow::drawHome(QPainter &p) {
const auto &lifted = m_home[m_liftedHome]; const auto &lifted = m_home[m_liftedHome];
const qreal localX = m_liftPos.x() - gridX(); const qreal localX = m_liftPos.x() - gridX();
const qreal localY = m_liftPos.y() - (gridTop() - m_homeScroll); const qreal localY = m_liftPos.y() - (gridTop() - m_homeScroll);
if (localX >= 0 && localY >= 0) { const int maxCol = std::max(0, homeCols() - lifted.w);
const int maxCol = std::max(0, homeCols() - lifted.w); const int col = lifted.isWidget()
const int col = std::clamp(int(localX / (homeColW() + Layout::kColGap)), 0, maxCol); ? std::clamp(int(std::lround(localX / (homeColW() + Layout::kColGap))), 0, maxCol)
const int row = std::max(0, int(localY / (Layout::kCellH + Layout::kRowGap))); : std::clamp(int(localX / (homeColW() + Layout::kColGap)), 0, maxCol);
QRectF target = Layout::cellBox({col, row}, cw, lifted.w, lifted.h); const int row = lifted.isWidget()
target.translate(gridX(), gridTop() - m_homeScroll); ? std::max(0, int(std::lround(localY / (Layout::kCellH + Layout::kRowGap))))
p.setPen(QPen(QColor(255, 255, 255, 110), 1.5, Qt::DashLine)); : std::max(0, int(localY / (Layout::kCellH + Layout::kRowGap)));
p.setBrush(QColor(255, 255, 255, 24)); QRectF target = Layout::cellBox({col, row}, cw, lifted.w, lifted.h);
p.drawRoundedRect(target, 16.0, 16.0); target.translate(gridX(), gridTop() - m_homeScroll);
} p.setPen(QPen(QColor(255, 255, 255, 110), 1.5, Qt::DashLine));
p.setBrush(QColor(255, 255, 255, 24));
p.drawRoundedRect(target, 16.0, 16.0);
if (!lifted.isWidget()) { if (!lifted.isWidget()) {
const QString comp = lifted.component; const QString comp = lifted.component;
const int appIdx = m_appIndex.value(comp, -1); const int appIdx = m_appIndex.value(comp, -1);