Skip to content

Commit 1d9d72a

Browse files
committed
Subtract the window's position when placing the cached hint pixmap
1 parent 975c78b commit 1d9d72a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/main/java/mousemaster/WindowsOverlay.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,13 @@ private static void setHintMeshWindow(HintMeshWindow hintMeshWindow,
465465
QLabel pixmapLabel = new ClearBackgroundQLabel();
466466
pixmapLabel.setPixmap(pixmapAndPosition.pixmap);
467467
Hint originalFirstHint = pixmapAndPosition.originalHintMesh.hints().getFirst();
468+
int originalWindowX = pixmapAndPosition.windowX;
469+
int originalWindowY = pixmapAndPosition.windowY;
468470
Hint newFirstHint = hintMesh.hints().getFirst();
469471
// Translate the original pixmap which may be at a different position than
470472
// the new hint mesh.
471-
pixmapLabel.setGeometry(pixmapAndPosition.x() + (int) Math.round(newFirstHint.centerX() - originalFirstHint.centerX()),
472-
pixmapAndPosition.y() + (int) Math.round(newFirstHint.centerY() - originalFirstHint.centerY()),
473+
pixmapLabel.setGeometry(pixmapAndPosition.x() + (int) Math.round(newFirstHint.centerX() - window.x() - originalFirstHint.centerX() - originalWindowX),
474+
pixmapAndPosition.y() + (int) Math.round(newFirstHint.centerY() - window.y() - originalFirstHint.centerY() - originalWindowY),
473475
pixmapAndPosition.pixmap().width(), pixmapAndPosition.pixmap().height());
474476
newContainer = pixmapLabel;
475477
transitionHintContainers(
@@ -497,7 +499,7 @@ private static void setHintMeshWindow(HintMeshWindow hintMeshWindow,
497499
hintBoxGeometriesByHintMeshKey.put(hintMeshKey,
498500
hintBoxGeometries);
499501
if (isHintGrid) {
500-
cacheQtHintWindowIntoPixmap(container, hintMeshKey, hintMesh);
502+
cacheQtHintWindowIntoPixmap(window, container, hintMeshKey, hintMesh);
501503
}
502504
transitionHintContainers(
503505
style.transitionAnimationEnabled() && isHintGrid && !oldContainerHidden && !zoomChanged,
@@ -1044,11 +1046,12 @@ private static QFont qFont(String fontName, double fontSize, FontWeight fontWeig
10441046
return font;
10451047
}
10461048

1047-
private static void cacheQtHintWindowIntoPixmap(QWidget container,
1049+
private static void cacheQtHintWindowIntoPixmap(TransparentWindow window, QWidget container,
10481050
HintMesh hintMeshKey, HintMesh hintMesh) {
10491051
QPixmap pixmap = container.grab();
10501052
PixmapAndPosition pixmapAndPosition =
1051-
new PixmapAndPosition(pixmap, container.x(), container.y(), hintMesh);
1053+
new PixmapAndPosition(pixmap, container.x(), container.y(), hintMesh,
1054+
window.x(), window.y());
10521055
logger.trace("Caching " + pixmapAndPosition + ", cache size is " + hintMeshPixmaps.size());
10531056
// pixmap.save("screenshot.png", "PNG");
10541057
hintMeshPixmaps.put(hintMeshKey, pixmapAndPosition);
@@ -1110,7 +1113,7 @@ private static HintBox[][] addSubgridBoxes(HintBox hintBox,
11101113
return hintBoxes;
11111114
}
11121115

1113-
private record PixmapAndPosition(QPixmap pixmap, int x, int y, HintMesh originalHintMesh) {
1116+
private record PixmapAndPosition(QPixmap pixmap, int x, int y, HintMesh originalHintMesh, int windowX, int windowY) {
11141117
@Override
11151118
public String toString() {
11161119
return "PixmapAndPosition[" + x + ", " + y + ", "
@@ -2017,7 +2020,8 @@ public static void animateHintMatch(Hint hint) {
20172020
PixmapAndPosition pixmapAndPosition =
20182021
new PixmapAndPosition(pixmap,
20192022
container.geometry().x() + hintBoxGeometry.x(),
2020-
container.geometry().y() + hintBoxGeometry.y(), hintMesh);
2023+
container.geometry().y() + hintBoxGeometry.y(), hintMesh,
2024+
hintMeshWindow.window.x(), hintMeshWindow.window.y());
20212025
HintMeshStyle style =
20222026
lastHintMeshKey.styleByFilter().get(ViewportFilter.of(screen));
20232027
setHintMeshWindow(hintMeshWindow, hintMesh, -1, style, false, pixmapAndPosition);

0 commit comments

Comments
 (0)