From: Peter Kümmel Date: Sat, 17 Mar 2007 12:28:26 +0000 (+0000) Subject: fix bug: vert. maximized window is completely maximized after restart X-Git-Tag: 1.6.10~10580 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=38cdcd70c1b848b862978dea0b7dc55b8db2f228;p=features.git fix bug: vert. maximized window is completely maximized after restart src/frontends/Application.h : enum for maximized src/frontends/LyXView.h : enum for maximized src/frontends/qt4/GuiView.h : enum for maximized src/frontends/Application.C : enum for maximized src/lyx_main.C : enum for maximized src/frontends/qt4/GuiView.C : restore complete, vert. hor. maximized window git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17463 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/Application.C b/src/frontends/Application.C index d4bde4b1eb..08f678f990 100644 --- a/src/frontends/Application.C +++ b/src/frontends/Application.C @@ -47,7 +47,7 @@ Application::Application(int &, char **) LyXView & Application::createView(unsigned int width, unsigned int height, int posx, int posy, - bool maximize, + int maximized, unsigned int iconSizeXY, const std::string & geometryArg) { @@ -59,7 +59,7 @@ LyXView & Application::createView(unsigned int width, /*int workArea_id_ =*/ gui().newWorkArea(width, height, view_id); view.init(); - view.setGeometry(width, height, posx, posy, maximize, iconSizeXY, geometryArg); + view.setGeometry(width, height, posx, posy, maximized, iconSizeXY, geometryArg); view.setFocus(); setCurrentView(view); diff --git a/src/frontends/Application.h b/src/frontends/Application.h index e782213264..779542f34f 100644 --- a/src/frontends/Application.h +++ b/src/frontends/Application.h @@ -172,8 +172,8 @@ public: /// Create the main window with given geometry settings. LyXView & createView(unsigned int width, unsigned int height, - int posx, int posy, bool maximize, unsigned int iconSizeXY, - const std::string & geometryArg); + int posx, int posy, int maximized, + unsigned int iconSizeXY, const std::string & geometryArg); /// LyXView const * currentView() const; diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index 45e3e71de0..ec3c8b9040 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -90,12 +90,19 @@ public: */ virtual void init() = 0; + enum Maximized { + NotMaximized, + VerticallyMaximized, + HorizontallyMaximized, + CompletelyMaximized + }; + /// virtual void setGeometry( unsigned int width, unsigned int height, int posx, int posy, - bool maximize, + int maximize, unsigned int iconSizeXY, const std::string & geometryArg) = 0; diff --git a/src/frontends/qt4/GuiView.C b/src/frontends/qt4/GuiView.C index 43cd3fca0f..b2d7732f2e 100644 --- a/src/frontends/qt4/GuiView.C +++ b/src/frontends/qt4/GuiView.C @@ -290,22 +290,51 @@ void GuiView::saveGeometry() // Then also the moveEvent, resizeEvent, and the // code for floatingGeometry_ can be removed; // adjust GuiView::setGeometry() + + QRect normal_geometry; + int maximized; #ifdef Q_WS_WIN - QRect geometry = normalGeometry(); + normal_geometry = normalGeometry(); + if (isMaximized()) { + maximized = CompletelyMaximized; + } else { + maximized = NotMaximized; + } #else - updateFloatingGeometry(); - QRect geometry = floatingGeometry_; -#endif + normal_geometry = updateFloatingGeometry(); + + QDesktopWidget& dw = *qApp->desktop(); + QRect desk = dw.availableGeometry(dw.primaryScreen()); + // Qt bug on Linux: load completely maximized, vert max. save-> frameGeometry().height() is wrong + if (isMaximized() && desk.width() <= frameGeometry().width() && desk.height() <= frameGeometry().height()) { + maximized = CompletelyMaximized; + // maximizing does not work when the window is allready hor. or vert. maximized + // Tested only on KDE + int dh = frameGeometry().height() - height(); + if (desk.height() <= normal_geometry.height() + dh) + normal_geometry.setHeight(normal_geometry.height() - 1); + int dw = frameGeometry().width() - width(); + if (desk.width() <= normal_geometry.width() + dw) + normal_geometry.setWidth(normal_geometry.width() - 1); + } else if (desk.height() <= frameGeometry().height()) { + maximized = VerticallyMaximized; + } else if (desk.width() <= frameGeometry().width()) { + maximized = HorizontallyMaximized; + } else { + maximized = NotMaximized; + } + +#endif // save windows size and position Session & session = LyX::ref().session(); - session.sessionInfo().save("WindowWidth", convert(geometry.width())); - session.sessionInfo().save("WindowHeight", convert(geometry.height())); - session.sessionInfo().save("WindowIsMaximized", (isMaximized() ? "yes" : "no")); + session.sessionInfo().save("WindowWidth", convert(normal_geometry.width())); + session.sessionInfo().save("WindowHeight", convert(normal_geometry.height())); + session.sessionInfo().save("WindowMaximized", convert(maximized)); session.sessionInfo().save("IconSizeXY", convert(iconSize().width())); if (lyxrc.geometry_xysaved) { - session.sessionInfo().save("WindowPosX", convert(geometry.x() + d.posx_offset)); - session.sessionInfo().save("WindowPosY", convert(geometry.y() + d.posy_offset)); + session.sessionInfo().save("WindowPosX", convert(normal_geometry.x() + d.posx_offset)); + session.sessionInfo().save("WindowPosY", convert(normal_geometry.y() + d.posy_offset)); } getToolbars().saveToolbarInfo(); } @@ -314,7 +343,7 @@ void GuiView::saveGeometry() void GuiView::setGeometry(unsigned int width, unsigned int height, int posx, int posy, - bool maximize, + int maximized, unsigned int iconSizeXY, const string & geometryArg) { @@ -347,8 +376,26 @@ void GuiView::setGeometry(unsigned int width, resize(width, height); } - if (maximize) - setWindowState(Qt::WindowMaximized); + // remember original size + floatingGeometry_ = QRect(posx, posy, width, height); + + if (maximized != NotMaximized) { + if (maximized == CompletelyMaximized) { + setWindowState(Qt::WindowMaximized); + } else { +#ifndef Q_WS_WIN + // TODO How to set by the window manager? + // setWindowState(Qt::WindowVerticallyMaximized); + // is not possible + QDesktopWidget& dw = *qApp->desktop(); + QRect desk = dw.availableGeometry(dw.primaryScreen()); + if (maximized == VerticallyMaximized) + resize(width, desk.height()); + if (maximized == HorizontallyMaximized) + resize(desk.width(), height); +#endif + } + } } else { @@ -386,7 +433,7 @@ void GuiView::setGeometry(unsigned int width, d.posy_offset = posy - normalGeometry().y(); #else #ifndef Q_WS_MACX - if (!maximize) { + if (maximized == NotMaximized) { d.posx_offset = posx - geometry().x(); d.posy_offset = posy - geometry().y(); } @@ -550,10 +597,15 @@ bool GuiView::hasFocus() const } -void GuiView::updateFloatingGeometry() +QRect GuiView::updateFloatingGeometry() { - if (!isMaximized()) + QDesktopWidget& dw = *qApp->desktop(); + QRect desk = dw.availableGeometry(dw.primaryScreen()); + // remember only non-maximized sizes + if (!isMaximized() && desk.width() > frameGeometry().width() && desk.height() > frameGeometry().height()) { floatingGeometry_ = QRect(x(), y(), width(), height()); + } + return floatingGeometry_; } diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 1f81ccaab8..756139dc5b 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -61,7 +61,7 @@ public: unsigned int width, unsigned int height, int posx, int posy, - bool maximize, + int maximized, unsigned int iconSizeXY, const std::string & geometryArg); virtual void saveGeometry(); @@ -139,7 +139,7 @@ private: bool quitting_by_menu_; /// - void updateFloatingGeometry(); + QRect updateFloatingGeometry(); /// QRect floatingGeometry_; diff --git a/src/lyx_main.C b/src/lyx_main.C index 0b59f51e92..8abf695a2b 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -634,7 +634,7 @@ LyXView * LyX::newLyXView() unsigned int height = 510; // default icon size, will be overwritten by stored session value unsigned int iconSizeXY = 0; - bool maximize = false; + int maximized = LyXView::NotMaximized; // first try lyxrc if (lyxrc.geometry_width != 0 && lyxrc.geometry_height != 0 ) { width = lyxrc.geometry_width; @@ -648,8 +648,9 @@ LyXView * LyX::newLyXView() val = session().sessionInfo().load("WindowHeight"); if (!val.empty()) height = convert(val); - if (session().sessionInfo().load("WindowIsMaximized") == "yes") - maximize = true; + val = session().sessionInfo().load("WindowMaximized"); + if (!val.empty()) + maximized = convert(val); val = session().sessionInfo().load("IconSizeXY"); if (!val.empty()) iconSizeXY = convert(val); @@ -674,7 +675,7 @@ LyXView * LyX::newLyXView() } // create the main window - LyXView * view = &pimpl_->application_->createView(width, height, posx, posy, maximize, iconSizeXY, geometryArg); + LyXView * view = &pimpl_->application_->createView(width, height, posx, posy, maximized, iconSizeXY, geometryArg); return view; }