summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEduard Braun <eduard.braun2@gmx.de>2017-02-11 20:55:19 +0000
committerEduard Braun <eduard.braun2@gmx.de>2017-02-11 20:55:19 +0000
commit0dc3e9ec72db77e707135e42023bfb2d8e04bcbd (patch)
tree5230f28c4bdbbab730d8cd884ca2d5dcb872be4c /src
parentFix a critical warning on convert to paths https://bugs.launchpad.net/inkscap... (diff)
downloadinkscape-0dc3e9ec72db77e707135e42023bfb2d8e04bcbd.tar.gz
inkscape-0dc3e9ec72db77e707135e42023bfb2d8e04bcbd.zip
Fix and improve window sizing and positioning behavior when opening new documents
* The option "Remember and use last window's geometry" often had no effect. * When setting "Default window size" to "Large" the functions gdk_screen_width() / gdk_screen_height() were used to derive the size of the Inkscape window. However those functions return the combined screen size of all attached monitors resulting in window sizes that were too large. Now the size of the primary display is used. * In many cases the Inkscape window was moved to the top left corner of the combined screen area (which could be on a different monitor at best and outside of the visible screen area at worst). Inkscape should always spawn on the primary monitor now when not restoring the previous position. Fixed bugs: - https://launchpad.net/bugs/1190828 - https://launchpad.net/bugs/195683 - https://launchpad.net/bugs/568867 - https://launchpad.net/bugs/1654464 (bzr r15507)
Diffstat (limited to 'src')
-rw-r--r--src/sp-namedview.cpp64
1 files changed, 38 insertions, 26 deletions
diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp
index d430f6321..166e90238 100644
--- a/src/sp-namedview.cpp
+++ b/src/sp-namedview.cpp
@@ -754,7 +754,7 @@ void SPNamedView::show(SPDesktop *desktop)
namespace {
-gint const MIN_ONSCREEN_DISTANCE = 50;
+gint const MIN_ONSCREEN_DISTANCE = 100;
gdouble const NEWDOC_X_SCALE = 0.75;
gdouble const NEWDOC_Y_SCALE = NEWDOC_X_SCALE;
@@ -774,12 +774,6 @@ Geom::Point calcAnchorPoint(gint const x, gint const y,
} // namespace
-void SPNamedView::writeNewGrid(SPDocument *document,int gridtype)
-{
- g_assert(this->getRepr() != NULL);
- Inkscape::CanvasGrid::writeNewGridToRepr(this->getRepr(),document,static_cast<Inkscape::GridType>(gridtype));
-}
-
/*
* Restores window geometry from the document settings or defaults in prefs
*/
@@ -788,22 +782,42 @@ void sp_namedview_window_from_document(SPDesktop *desktop)
SPNamedView *nv = desktop->namedview;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
bool geometry_from_file = (1 == prefs->getInt("/options/savewindowgeometry/value", 0));
+ bool geometry_from_last = (2 == prefs->getInt("/options/savewindowgeometry/value", 0));
gint default_geometry = prefs->getInt("/options/defaultwindowsize/value", 1);
bool new_document = (nv->window_width <= 0) || (nv->window_height <= 0);
bool show_dialogs = true;
// restore window size and position stored with the document
- bool sizeSet = false;
-
- if ((geometry_from_file && nv->window_maximized) || (new_document && (default_geometry == 2))) {
+ if (geometry_from_last) {
+ // do nothing, as we already have code for that in interface.cpp
+ // TODO: Probably should not do similar things in two places
+ } else if ((geometry_from_file && nv->window_maximized) || (new_document && (default_geometry == 2))) {
Gtk::Window *win = desktop->getToplevel();
if (win) {
win->maximize();
}
- sizeSet = true;
- } else if (geometry_from_file && !nv->window_maximized) {
- gint w = MIN(gdk_screen_width(), nv->window_width);
- gint h = MIN(gdk_screen_height(), nv->window_height);
+ } else {
+ // gdk_screen_width() / gdk_screen_height() return the dimensions of all displays combined
+ // therefore we have to get the dimensions of one monitor explicitly (currently the primary monitor)
+ // TODO: account for multi-monitor setups (i.e. on which monitor do we want to display Inkscape?)
+ gint monitor_number;
+ GdkRectangle monitor_geometry;
+ monitor_number = gdk_screen_get_primary_monitor(gdk_screen_get_default());
+ gdk_screen_get_monitor_geometry(gdk_screen_get_default(), monitor_number, &monitor_geometry);
+
+ gint w = monitor_geometry.width;
+ gint h = monitor_geometry.height;
+ bool move_to_screen = false;
+ if (geometry_from_file and !new_document) {
+ w = MIN(w, nv->window_width);
+ h = MIN(h, nv->window_height);
+ move_to_screen = true;
+ } else if (default_geometry == 1) {
+ w *= NEWDOC_X_SCALE;
+ h *= NEWDOC_Y_SCALE;
+ } else if (default_geometry == 0) {
+ w = h = 0; // use the smallest possible window size; could be a factor like NEWDOC_X_SCALE in future
+ }
if ((w > 0) && (h > 0)) {
#ifndef WIN32
gint dx= 0;
@@ -817,22 +831,14 @@ void sp_namedview_window_from_document(SPDesktop *desktop)
show_dialogs = FALSE;
}
#endif
- Geom::Point origin = calcAnchorPoint(nv->window_x, nv->window_y, w, h, MIN_ONSCREEN_DISTANCE);
desktop->setWindowSize(w, h);
- desktop->setWindowPosition(origin);
- sizeSet = true;
+ if (move_to_screen) {
+ Geom::Point origin = calcAnchorPoint(nv->window_x, nv->window_y, w, h, MIN_ONSCREEN_DISTANCE);
+ desktop->setWindowPosition(origin);
+ }
}
}
- if (!sizeSet && new_document && (default_geometry == 1))
- {
- gint w = gdk_screen_width() * NEWDOC_X_SCALE;
- gint h = gdk_screen_height() * NEWDOC_Y_SCALE;
- Geom::Point origin = calcAnchorPoint(nv->window_x, nv->window_y, w, h, MIN_ONSCREEN_DISTANCE);
- desktop->setWindowSize(w, h);
- desktop->setWindowPosition(origin);
- }
-
// restore zoom and view
if (nv->zoom != 0 && nv->zoom != HUGE_VAL && !IS_NAN(nv->zoom)
&& nv->cx != HUGE_VAL && !IS_NAN(nv->cx)
@@ -850,6 +856,12 @@ void sp_namedview_window_from_document(SPDesktop *desktop)
}
}
+void SPNamedView::writeNewGrid(SPDocument *document,int gridtype)
+{
+ g_assert(this->getRepr() != NULL);
+ Inkscape::CanvasGrid::writeNewGridToRepr(this->getRepr(),document,static_cast<Inkscape::GridType>(gridtype));
+}
+
bool SPNamedView::getSnapGlobal() const
{
return this->snap_manager.snapprefs.getSnapEnabledGlobally();