mirror of
https://github.com/YACReader/yacreader
synced 2026-04-12 15:49:53 -04:00
Improve window state handling
It fixes multi-screen setups support and fullscreen in Windows
This commit is contained in:
@ -15,6 +15,8 @@ Version counting is based on semantic versioning (Major.Feature.Patch)
|
||||
* Add a theme editor and support for custom themes.
|
||||
* The apps include 12 built in themes to pick from.
|
||||
* Add an application language setting with a system default option in YACReader and YACReaderLibrary.
|
||||
* Fix fullscreen mode in Windows, interaction with the OS is now possible while the apps are in fullscreen.
|
||||
* Improve support for multi-screen setups.
|
||||
|
||||
### All apps
|
||||
* Add support for user-installed Qt image format plugins via the shared `plugins/imageformats` folder in the YACReader settings directory.
|
||||
|
||||
@ -32,8 +32,6 @@ void Configuration::load(QSettings *settings)
|
||||
settings->setValue(FLOW_TYPE, 0);
|
||||
if (!settings->contains(FULLSCREEN))
|
||||
settings->setValue(FULLSCREEN, false);
|
||||
if (!settings->contains(MAXIMIZED))
|
||||
settings->setValue(MAXIMIZED, false);
|
||||
if (!settings->contains(DOUBLE_PAGE))
|
||||
settings->setValue(DOUBLE_PAGE, false);
|
||||
if (!settings->contains(SHOW_TOOLBARS))
|
||||
|
||||
@ -77,8 +77,6 @@ public:
|
||||
|
||||
QByteArray getGeometry() const { return settings->value(Y_WINDOW_GEOMETRY).toByteArray(); }
|
||||
void setGeometry(const QByteArray &g) { settings->setValue(Y_WINDOW_GEOMETRY, g); }
|
||||
bool getMaximized() { return settings->value(MAXIMIZED).toBool(); }
|
||||
void setMaximized(bool b) { settings->setValue(MAXIMIZED, b); }
|
||||
bool getDoublePage() { return settings->value(DOUBLE_PAGE).toBool(); }
|
||||
void setDoublePage(bool b) { settings->setValue(DOUBLE_PAGE, b); }
|
||||
bool getDoubleMangaPage() { return settings->value(DOUBLE_MANGA_PAGE).toBool(); }
|
||||
|
||||
@ -30,7 +30,6 @@
|
||||
#include <QMessageBox>
|
||||
#include <QStandardPaths>
|
||||
#include <QToolButton>
|
||||
#include <QWindow>
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
@ -190,7 +189,7 @@ void MainWindowViewer::setupUI()
|
||||
}
|
||||
|
||||
int heightDesktopResolution = screen != nullptr ? screen->size().height() : 600;
|
||||
int widthDesktopResolution = screen != nullptr ? screen->size().height() : 1024;
|
||||
int widthDesktopResolution = screen != nullptr ? screen->size().width() : 1024;
|
||||
int height, width;
|
||||
height = static_cast<int>(heightDesktopResolution * 0.84);
|
||||
width = static_cast<int>(height * 0.70);
|
||||
@ -198,6 +197,19 @@ void MainWindowViewer::setupUI()
|
||||
if (!restoreGeometry(conf.getGeometry())) {
|
||||
move(QPoint((widthDesktopResolution - width) / 2, ((heightDesktopResolution - height) - 40) / 2));
|
||||
resize(QSize(width, height));
|
||||
} else {
|
||||
// Guard against the window landing off-screen when a monitor is unplugged
|
||||
// between sessions. Qt 6 tries to remap the geometry to the primary screen
|
||||
// when the saved screen is gone, but the result can still be off-screen.
|
||||
const QRect restored = geometry();
|
||||
const auto availableScreens = QApplication::screens();
|
||||
const bool onScreen = std::any_of(
|
||||
availableScreens.cbegin(), availableScreens.cend(),
|
||||
[&restored](QScreen *s) { return s->availableGeometry().intersects(restored); });
|
||||
if (!onScreen) {
|
||||
const QRect avail = QApplication::primaryScreen()->availableGeometry();
|
||||
move(avail.center() - QPoint(width / 2, height / 2));
|
||||
}
|
||||
}
|
||||
|
||||
had = new HelpAboutDialog(this); // TODO load data
|
||||
@ -229,14 +241,8 @@ void MainWindowViewer::setupUI()
|
||||
|
||||
viewer->setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
previousWindowFlags = windowFlags();
|
||||
previousPos = pos();
|
||||
previousSize = size();
|
||||
|
||||
if (fullscreen)
|
||||
toFullScreen();
|
||||
if (conf.getMaximized())
|
||||
showMaximized();
|
||||
|
||||
setAcceptDrops(true);
|
||||
|
||||
@ -1049,58 +1055,6 @@ void MainWindowViewer::toggleFullScreen()
|
||||
Configuration::getConfiguration().setFullScreen(fullscreen = !fullscreen);
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN // fullscreen mode in Windows for preventing this bug: QTBUG-41309 https://bugreports.qt.io/browse/QTBUG-41309
|
||||
|
||||
void MainWindowViewer::toFullScreen()
|
||||
{
|
||||
fromMaximized = this->isMaximized();
|
||||
|
||||
hideToolBars();
|
||||
viewer->hide();
|
||||
viewer->fullscreen = true; // TODO, change by the right use of windowState();
|
||||
|
||||
previousWindowFlags = windowFlags();
|
||||
previousPos = pos();
|
||||
previousSize = size();
|
||||
|
||||
showNormal();
|
||||
setWindowFlags(previousWindowFlags | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
||||
|
||||
QRect r = windowHandle()->screen()->geometry();
|
||||
|
||||
r.setHeight(r.height() + 1);
|
||||
|
||||
setGeometry(r);
|
||||
show();
|
||||
|
||||
viewer->show();
|
||||
if (viewer->magnifyingGlassIsVisible())
|
||||
viewer->showMagnifyingGlass();
|
||||
}
|
||||
|
||||
void MainWindowViewer::toNormal()
|
||||
{
|
||||
// show all
|
||||
viewer->hide();
|
||||
viewer->fullscreen = false; // TODO, change by the right use of windowState();
|
||||
// viewer->hideMagnifyingGlass();
|
||||
|
||||
setWindowFlags(previousWindowFlags);
|
||||
move(previousPos);
|
||||
resize(previousSize);
|
||||
show();
|
||||
|
||||
if (fromMaximized)
|
||||
showMaximized();
|
||||
|
||||
if (Configuration::getConfiguration().getShowToolbars())
|
||||
showToolBars();
|
||||
viewer->show();
|
||||
if (viewer->magnifyingGlassIsVisible())
|
||||
viewer->showMagnifyingGlass();
|
||||
}
|
||||
|
||||
#else
|
||||
void MainWindowViewer::toFullScreen()
|
||||
{
|
||||
fromMaximized = this->isMaximized();
|
||||
@ -1131,7 +1085,6 @@ void MainWindowViewer::toNormal()
|
||||
if (viewer->magnifyingGlassIsVisible())
|
||||
viewer->showMagnifyingGlass();
|
||||
}
|
||||
#endif
|
||||
|
||||
void MainWindowViewer::toggleToolBars()
|
||||
{
|
||||
@ -1441,9 +1394,10 @@ void MainWindowViewer::closeEvent(QCloseEvent *event)
|
||||
|
||||
viewer->save();
|
||||
Configuration &conf = Configuration::getConfiguration();
|
||||
if (!fullscreen && !isMaximized())
|
||||
conf.setGeometry(saveGeometry());
|
||||
conf.setMaximized(isMaximized());
|
||||
// saveGeometry() encodes the current screen, the maximized/fullscreen state, and
|
||||
// the normal (pre-maximize) geometry in one blob, so restoreGeometry() puts the
|
||||
// window back on the right monitor in the right state regardless of how it was closed.
|
||||
conf.setGeometry(saveGeometry());
|
||||
|
||||
event->accept();
|
||||
}
|
||||
|
||||
@ -91,10 +91,6 @@ private:
|
||||
bool toolbars;
|
||||
bool fromMaximized;
|
||||
|
||||
// QTBUG-41883
|
||||
QSize _size;
|
||||
QPoint _pos;
|
||||
|
||||
QString currentDirectory;
|
||||
QString currentDirectoryImgDest;
|
||||
//! Widgets
|
||||
@ -193,11 +189,6 @@ private:
|
||||
quint64 libraryId;
|
||||
OpenComicSource source;
|
||||
|
||||
// fullscreen mode in Windows for preventing this bug: QTBUG-41309 https://bugreports.qt.io/browse/QTBUG-41309
|
||||
Qt::WindowFlags previousWindowFlags;
|
||||
QPoint previousPos;
|
||||
QSize previousSize;
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
void sendComic();
|
||||
|
||||
@ -23,7 +23,6 @@
|
||||
#include <QStackedWidget>
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
#include <QWindow>
|
||||
#include <QtCore>
|
||||
|
||||
#include <algorithm>
|
||||
@ -215,11 +214,25 @@ void LibraryWindow::setupUI()
|
||||
setMinimumSize(800, 480);
|
||||
|
||||
// restore
|
||||
if (settings->contains(MAIN_WINDOW_GEOMETRY))
|
||||
if (settings->contains(MAIN_WINDOW_GEOMETRY)) {
|
||||
restoreGeometry(settings->value(MAIN_WINDOW_GEOMETRY).toByteArray());
|
||||
else
|
||||
restoreState(settings->value(MAIN_WINDOW_STATE).toByteArray());
|
||||
// Guard against the window landing off-screen when a monitor is unplugged
|
||||
// between sessions. Qt 6 tries to remap the geometry to the primary screen
|
||||
// when the saved screen is gone, but the result can still be off-screen.
|
||||
const QRect restored = geometry();
|
||||
const auto availableScreens = QApplication::screens();
|
||||
const bool onScreen = std::any_of(
|
||||
availableScreens.cbegin(), availableScreens.cend(),
|
||||
[&restored](QScreen *s) { return s->availableGeometry().intersects(restored); });
|
||||
if (!onScreen) {
|
||||
const QRect avail = QApplication::primaryScreen()->availableGeometry();
|
||||
setGeometry(QRect(avail.center() - QPoint(width() / 2, height() / 2), size()));
|
||||
}
|
||||
} else {
|
||||
// if(settings->value(USE_OPEN_GL).toBool() == false)
|
||||
showMaximized();
|
||||
}
|
||||
|
||||
trayIconController = new TrayIconController(settings, this);
|
||||
|
||||
@ -1988,49 +2001,6 @@ void LibraryWindow::toggleFullScreen()
|
||||
fullscreen = !fullscreen;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN // fullscreen mode in Windows for preventing this bug: QTBUG-41309 https://bugreports.qt.io/browse/QTBUG-41309
|
||||
void LibraryWindow::toFullScreen()
|
||||
{
|
||||
fromMaximized = this->isMaximized();
|
||||
|
||||
sideBar->hide();
|
||||
libraryToolBar->hide();
|
||||
|
||||
previousWindowFlags = windowFlags();
|
||||
previousPos = pos();
|
||||
previousSize = size();
|
||||
|
||||
showNormal();
|
||||
setWindowFlags(previousWindowFlags | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
||||
|
||||
QRect r = windowHandle()->screen()->geometry();
|
||||
|
||||
r.setHeight(r.height() + 1);
|
||||
|
||||
setGeometry(r);
|
||||
show();
|
||||
|
||||
contentViewsManager->toFullscreen();
|
||||
}
|
||||
|
||||
void LibraryWindow::toNormal()
|
||||
{
|
||||
sideBar->show();
|
||||
libraryToolBar->show();
|
||||
|
||||
setWindowFlags(previousWindowFlags);
|
||||
move(previousPos);
|
||||
resize(previousSize);
|
||||
show();
|
||||
|
||||
if (fromMaximized)
|
||||
showMaximized();
|
||||
|
||||
contentViewsManager->toNormal();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void LibraryWindow::toFullScreen()
|
||||
{
|
||||
fromMaximized = this->isMaximized();
|
||||
@ -2065,8 +2035,6 @@ void LibraryWindow::toNormal()
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void LibraryWindow::setSearchFilter(QString filter)
|
||||
{
|
||||
if (!filter.isEmpty()) {
|
||||
@ -2399,6 +2367,7 @@ void LibraryWindow::prepareToCloseApp()
|
||||
librariesUpdateCoordinator->stop();
|
||||
|
||||
settings->setValue(MAIN_WINDOW_GEOMETRY, saveGeometry());
|
||||
settings->setValue(MAIN_WINDOW_STATE, saveState());
|
||||
|
||||
contentViewsManager->comicsView->close();
|
||||
sideBar->close();
|
||||
|
||||
@ -348,10 +348,6 @@ private:
|
||||
//! @return true If the search mode was active when this function was called.
|
||||
bool exitSearchMode();
|
||||
|
||||
// fullscreen mode in Windows for preventing this bug: QTBUG-41309 https://bugreports.qt.io/browse/QTBUG-41309
|
||||
Qt::WindowFlags previousWindowFlags;
|
||||
QPoint previousPos;
|
||||
QSize previousSize;
|
||||
std::future<void> upgradeLibraryFuture;
|
||||
|
||||
TrayIconController *trayIconController;
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
#define FLOW_TYPE "FLOW_TYPE"
|
||||
#define FULLSCREEN "FULLSCREEN"
|
||||
#define Y_WINDOW_GEOMETRY "GEOMETRY"
|
||||
#define MAXIMIZED "MAXIMIZED"
|
||||
#define CLOSE_TO_TRAY "CLOSE_TO_TRAY"
|
||||
#define CLOSE_TO_TRAY_NOTIFIED "CLOSE_TO_TRAY_NOTIFIED"
|
||||
#define START_TO_TRAY "START_TO_TRAY"
|
||||
|
||||
@ -55,7 +55,10 @@ YACReader::WhatsNewDialog::WhatsNewDialog(QWidget *parent)
|
||||
" • Migrate Flow implementation from OpenGL to QRhi. This is a full new implementation with better performance and compatibility with operating systems and hardware<br/>"
|
||||
" • Add light/dark themes support that follow the system configuration<br/>"
|
||||
" • Add a theme editor and support for custom themes<br/>"
|
||||
" • The apps include 12 built in themes to pick from<br/>"
|
||||
" • Add an application language setting with a system default option in YACReader and YACReaderLibrary<br/>"
|
||||
" • Fix fullscreen mode in Windows, interaction with the OS is now possible while the apps are in fullscreen<br/>"
|
||||
" • Improve support for multi-screen setups<br/>"
|
||||
"<br/>"
|
||||
"<span style=\"font-weight:600\">All apps</span><br/>"
|
||||
" • Add support for user-installed Qt image format plugins via the shared <i>plugins/imageformats</i> folder in the YACReader settings directory<br/>"
|
||||
|
||||
Reference in New Issue
Block a user