From 7048d098f15eae7138b7d01c88ad6aebc1afaf26 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 17 Feb 2019 19:33:48 +0100 Subject: Rescue code for restoring last used window geometry It was accidentally dropped in 8b1840f9507f10911f63fc00b9885354ead99d53 Also show window *after* setting position/size. This gives the window manager the chance to move an off-screen window back into the visible desktop bounds (e.g. after a monitor was disconnected). --- src/inkscape-window.cpp | 7 +++++-- src/object/sp-namedview.cpp | 39 ++++++++++++++++++++++++++++++++------- src/object/sp-namedview.h | 1 + 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/inkscape-window.cpp b/src/inkscape-window.cpp index 8c0525a87..f85d94473 100644 --- a/src/inkscape-window.cpp +++ b/src/inkscape-window.cpp @@ -85,11 +85,14 @@ InkscapeWindow::InkscapeWindow(SPDocument* document) // ================ Window Options ============== - show(); // Must show before resize! - // Resize the window to match the document properties sp_namedview_window_from_document(_desktop); // This should probably be a member function here. + + // Must show before setting zoom and view! (crashes otherwise) + // Should show after resizing/moving to allow window manager to correct an invalid windows size/position + show(); + sp_namedview_zoom_and_view_from_document(_desktop); sp_namedview_update_layers_from_document(_desktop); } diff --git a/src/object/sp-namedview.cpp b/src/object/sp-namedview.cpp index cc1e185a8..e4ab351d1 100644 --- a/src/object/sp-namedview.cpp +++ b/src/object/sp-namedview.cpp @@ -750,9 +750,28 @@ void sp_namedview_window_from_document(SPDesktop *desktop) // restore window size and position stored with the document Gtk::Window *win = desktop->getToplevel(); g_assert(win); + if (window_geometry == PREFS_WINDOW_GEOMETRY_LAST) { - // do nothing, as we already have code for that in interface.cpp - // TODO: Probably should not do similar things in two places + gint pw = prefs->getInt("/desktop/geometry/width", -1); + gint ph = prefs->getInt("/desktop/geometry/height", -1); + gint px = prefs->getInt("/desktop/geometry/x", -1); + gint py = prefs->getInt("/desktop/geometry/y", -1); + gint full = prefs->getBool("/desktop/geometry/fullscreen"); + gint maxed = prefs->getBool("/desktop/geometry/maximized"); + if (pw>0 && ph>0) { + + Gdk::Rectangle monitor_geometry = Inkscape::UI::get_monitor_geometry_at_point(px, py); + pw = std::min(pw, monitor_geometry.get_width()); + ph = std::min(ph, monitor_geometry.get_height()); + desktop->setWindowSize(pw, ph); + desktop->setWindowPosition(Geom::Point(px, py)); + } + if (maxed) { + win->maximize(); + } + if (full) { + win->fullscreen(); + } } else if ((window_geometry == PREFS_WINDOW_GEOMETRY_FILE && nv->window_maximized) || (new_document && (default_size == PREFS_WINDOW_SIZE_MAXIMIZED))) { win->maximize(); @@ -812,7 +831,17 @@ void sp_namedview_window_from_document(SPDesktop *desktop) // Cancel any history of transforms up to this point (must be before call to zoom). desktop->clear_transform_history(); - // restore zoom and view + if (show_dialogs) { + desktop->show_dialogs(); + } +} + +/* + * Restores zoom and view from the document settings + */ +void sp_namedview_zoom_and_view_from_document(SPDesktop *desktop) +{ + SPNamedView *nv = desktop->namedview; if (nv->zoom != 0 && nv->zoom != HUGE_VAL && !IS_NAN(nv->zoom) && nv->cx != HUGE_VAL && !IS_NAN(nv->cx) && nv->cy != HUGE_VAL && !IS_NAN(nv->cy)) { @@ -820,10 +849,6 @@ void sp_namedview_window_from_document(SPDesktop *desktop) } else if (desktop->getDocument()) { // document without saved zoom, zoom to its page desktop->zoom_page(); } - - if (show_dialogs) { - desktop->show_dialogs(); - } } void SPNamedView::writeNewGrid(SPDocument *document,int gridtype) diff --git a/src/object/sp-namedview.h b/src/object/sp-namedview.h index 0d3b6b8f2..85db55a27 100644 --- a/src/object/sp-namedview.h +++ b/src/object/sp-namedview.h @@ -121,6 +121,7 @@ SPNamedView *sp_document_namedview(SPDocument *document, char const *name); SPNamedView const *sp_document_namedview(SPDocument const *document, char const *name); void sp_namedview_window_from_document(SPDesktop *desktop); +void sp_namedview_zoom_and_view_from_document(SPDesktop *desktop); void sp_namedview_document_from_window(SPDesktop *desktop); void sp_namedview_update_layers_from_document (SPDesktop *desktop); -- cgit v1.2.3 From bbfd5e166a8adaf0e76919d5ee13e68db1f256c9 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Wed, 20 Feb 2019 00:40:10 +0100 Subject: Fix query for monitor dimensions The call to Gdk::Display::get_monitor_at_window() in Inkscape::UI::get_monitor_geometry_at_window() requires the underlying GdkWindow to be fully initialized. This is achieved by calling "realize()" before attempting to read that information. Previously we used to show the window first (which implies realizing it) which worked around the issue. However it required us to hide and show it once again later if we wanted to move it in order for the window manager's routines to sanitize the position to kick in. --- src/inkscape-window.cpp | 8 ++++++-- src/object/sp-namedview.cpp | 4 ---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/inkscape-window.cpp b/src/inkscape-window.cpp index f85d94473..bcf10cedd 100644 --- a/src/inkscape-window.cpp +++ b/src/inkscape-window.cpp @@ -85,11 +85,15 @@ InkscapeWindow::InkscapeWindow(SPDocument* document) // ================ Window Options ============== + // Make sure the GdkWindow is fully initialized before resizing/moving + // (ensures the monitor it'll be shown on is known) + realize(); + // Resize the window to match the document properties sp_namedview_window_from_document(_desktop); // This should probably be a member function here. - + // Must show before setting zoom and view! (crashes otherwise) - // Should show after resizing/moving to allow window manager to correct an invalid windows size/position + // Showing after resizing/moving allows the window manager to correct an invalid size/position of the window show(); sp_namedview_zoom_and_view_from_document(_desktop); diff --git a/src/object/sp-namedview.cpp b/src/object/sp-namedview.cpp index e4ab351d1..eafdf6dba 100644 --- a/src/object/sp-namedview.cpp +++ b/src/object/sp-namedview.cpp @@ -819,11 +819,7 @@ void sp_namedview_window_from_document(SPDesktop *desktop) #endif desktop->setWindowSize(w, h); if (move_to_screen) { - // Hiding window will close app if it's last window. If we really need to hide it - // here, we need to up the reference count of the application before hiding, and lower after showing. - // win->hide(); desktop->setWindowPosition(Geom::Point(nv->window_x, nv->window_y)); - // win->show(); } } } -- cgit v1.2.3