Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #3190 #3464

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/pdfviewer/PDFDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2857,21 +2857,21 @@ PDFDocument::PDFDocument(PDFDocumentConfig *const pdfConfig, bool embedded)
int &h = globalConfig->windowHeight;
QRect screen = UtilsUi::getAvailableGeometryAt(QPoint(x, y));
// add some tolerance, as fullscreen seems to have negative coordinate (KDE, Win7 ...)
screen.adjust(-8, -8, +8, +8);
// screen.adjust(-8, -8, +8, +8);
if (!screen.contains(x, y)) {
// top left is not on screen
x = screen.x() + screen.width() * 2 / 3;
y = screen.y() + 10;
if (x + w > screen.right()) w = screen.width() / 3 - 26;
if (y + h > screen.height()) h = screen.height() - 100;
}
resize(w, h); //important to first resize then move then maximize
move(x, y);
if (globalConfig->windowMaximized)
showMaximized();
else
setWindowState(Qt::WindowNoState);

resize(w, h); //important to first resize then move
move(x, y);
if (!globalConfig->windowState.isEmpty()) restoreState(globalConfig->windowState);
toolBar->setVisible(globalConfig->toolbarVisible);
statusbar->setVisible(true);
Expand Down Expand Up @@ -4298,11 +4298,15 @@ PDFDocument *PDFDocument::findDocument(const QString &fileName)

void PDFDocument::saveGeometryToConfig()
{
globalConfig->windowLeft = x();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the window position is only saved when not maximised, then the move(x,y) is possibly undefined or wrong.
This probably comes into play for multi-monitor set-ups ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I've seen with debug under Win10 lead me to the conclusion that retrieving window coordinates while in maximized (and similar) modes returns invalid values. Especially the coordinate of the upper left window corner has negative values. It seems that line 2860 was introduced to fix this. So I assume that maximized/fullscreen needs to be handled by flags not by coordinates.

Be aware that the code retrieves coordinates from different things: The window corner as mentioned before and the size of the pdf widget. This can introduce problems because we and Qt have no access to the geometry of the window decoration (how thick are the border lines of the window surrounding the widget, height of the window title, and so on, which are under control of the window manager). Typically we don't need to know these details when all changes to the coordinates (and flags) are retrieved. Because with these values we should be able to restore a correct window at any time. So the move should be no problem here. Can you reproduce some case?

But this is currently not the case. After my PR I observed following: Maximize and restore pdf window. Thus window coordinates are retrieved and stored. Now move or resize the window, then maximize it, then end txs. When starting txs again the maximized window mode is restored with my PR, but when the maximized flag is cleared, then the normal window has the last saved coordinates instead of the last ones used. I tried to improve this with following code where I need help:

connect(window(), SIGNAL(PDFDocument::windowStateChanged(Qt::WindowState)), this, SLOT(slotWindowStateChanged(Qt::WindowState)));

But I couldn't figure out how to find the window as the sender of the signal. If this would work then the current coordinates of the window could be retrieved by txs on maximizing the window (and the like). This should be sufficient for single monitor setups.

In multi monitor setups this may lead to cases where the window is placed on the wrong screens. And what about the case that one drags the maximized window to another screen such that it appears maximized (or normal) there?

globalConfig->windowTop = y();
globalConfig->windowWidth = width();
globalConfig->windowHeight = height();
globalConfig->windowMaximized = isMaximized();
if (!embeddedMode) {
if (!isMaximized() && !isFullScreen()) {
globalConfig->windowLeft = x();
globalConfig->windowTop = y();
globalConfig->windowWidth = width();
globalConfig->windowHeight = height();
}
globalConfig->windowMaximized = isMaximized();
}
globalConfig->windowState = saveState();
globalConfig->toolbarVisible = toolBar->isVisible();
globalConfig->annotationPanelVisible = annotationPanel->isVisible();
Expand Down
1 change: 1 addition & 0 deletions utilities/manual/source/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- First line of macro editor no longer uses macro type, use buttons to set type. Macro format changes slightly. For details s. [#3458](https://github.com/texstudio-org/texstudio/pull/3458)
- add export of all macros in Edit Macros dialog
- fix missing connection error message when browsing macro repository [#3448](https://github.com/texstudio-org/texstudio/pull/3448)
- fix pdf viewer window can be restored to maximized window from embedded state or start of txs [#3190](https://github.com/texstudio-org/texstudio/issues/3190)

## TeXstudio 4.7.2

Expand Down