Skip to content

Commit

Permalink
Make sure x input window is with in screen after Flip Y.
Browse files Browse the repository at this point in the history
In certian cases, the flip y may move window out of screen. We should
move the window back with slide y logic.
  • Loading branch information
wengxt committed Mar 17, 2024
1 parent f372ada commit be94c03
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/ui/classic/xcbinputwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,40 @@ void XCBInputWindow::updatePosition(InputContext *inputContext) {
}

if (closestScreen) {
int newX, newY;
int newX;

if (x < closestScreen->left()) {
newX = closestScreen->left();
} else {
newX = x;
}

if ((newX + static_cast<int>(actualWidth)) > closestScreen->right()) {
newX = closestScreen->right() - actualWidth;
}

int newY;
if (y < closestScreen->top()) {
newY = closestScreen->top();
} else {
newY = y + (h ? h : (10 * ((dpi_ < 0 ? 96.0 : dpi_) / 96.0)));
}

if ((newX + static_cast<int>(actualWidth)) > closestScreen->right()) {
newX = closestScreen->right() - actualWidth;
}

// Try flip y.
if ((newY + static_cast<int>(actualHeight)) > closestScreen->bottom()) {
if (newY > closestScreen->bottom()) {
newY = closestScreen->bottom() - actualHeight - 40;
} else { /* better position the window */
newY = newY - actualHeight - ((h == 0) ? 40 : h);
}

// If after flip, top is out of the screen, we still prefer the top
// edge to be always with in screen.
if (newY < closestScreen->top()) {
newY = closestScreen->top();
}
}

x = newX;
y = newY;
}
Expand Down

0 comments on commit be94c03

Please sign in to comment.