From 7939322078af85900e32b5120c1fbcaf9c73f616 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sat, 6 Jan 2018 20:36:01 +0100 Subject: Simplify code to restore new windows to previous position GTK+ / window managers handle positioning of new windows on the screen just fine, so don't do "our own thing" that is prone to errors. Notably the previous code for gtkmm >=3.22 was broken as it assumed Inkscape to be shown on the primary monitor and mixed coordinates relative to the primary display with absolute screen coordinates --- src/ui/interface.cpp | 45 ++++----------------------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) (limited to 'src/ui') diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 826737c2c..3671380fe 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -30,10 +30,6 @@ #include "file.h" #include -#if GTKMM_CHECK_VERSION(3,22,0) -# include -#endif - #include "inkscape.h" #include "extension/db.h" #include "extension/effect.h" @@ -165,8 +161,7 @@ sp_create_window(SPViewWidget *vw, bool editable) win->signal_focus_in_event().connect(sigc::mem_fun(*desktop_widget, &SPDesktopWidget::onFocusInEvent)); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gint prefs_geometry = - (2==prefs->getInt("/options/savewindowgeometry/value", 0)); + gint prefs_geometry = (2==prefs->getInt("/options/savewindowgeometry/value", 0)); if (prefs_geometry) { gint pw = prefs->getInt("/desktop/geometry/width", -1); gint ph = prefs->getInt("/desktop/geometry/height", -1); @@ -175,39 +170,8 @@ sp_create_window(SPViewWidget *vw, bool editable) gint full = prefs->getBool("/desktop/geometry/fullscreen"); gint maxed = prefs->getBool("/desktop/geometry/maximized"); if (pw>0 && ph>0) { -#if GTKMM_CHECK_VERSION(3,22,0) - auto const display = Gdk::Display::get_default(); - auto const monitor = display->get_primary_monitor(); - - // A Gdk::Rectangle in "application pixel" units - Gdk::Rectangle screen_geometry; - monitor->get_geometry(screen_geometry); - auto const screen_width = screen_geometry.get_width(); - auto const screen_height = screen_geometry.get_height(); -#else - auto const screen_width = gdk_screen_width(); - auto const screen_height = gdk_screen_height(); -#endif - gint w = MIN(screen_width, pw); - gint h = MIN(screen_height, ph); - gint x = MIN(screen_width - MIN_ONSCREEN_DISTANCE, px); - gint y = MIN(screen_height - MIN_ONSCREEN_DISTANCE, py); - if (w>0 && h>0) { - x = MIN(screen_width - w, x); - y = MIN(screen_height - h, y); - desktop->setWindowSize(w, h); - } - - // Only restore xy for the first window so subsequent windows don't overlap exactly - // with first. (Maybe rule should be only restore xy if it's different from xy of - // other desktops?) - - // Empirically it seems that active_desktop==this desktop only the first time a - // desktop is created. - SPDesktop *active_desktop = SP_ACTIVE_DESKTOP; - if (active_desktop == desktop || active_desktop==NULL) { - desktop->setWindowPosition(Geom::Point(x, y)); - } + desktop->setWindowSize(pw, ph); + desktop->setWindowPosition(Geom::Point(px, py)); } if (maxed) { win->maximize(); @@ -216,8 +180,7 @@ sp_create_window(SPViewWidget *vw, bool editable) win->fullscreen(); } } - - } + } if ( completeDropTargets == 0 || completeDropTargetsCount == 0 ) { -- cgit v1.2.3 From df4cb22cc7e5935293af6bb17e1c26959dc300ba Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 7 Jan 2018 04:35:34 +0100 Subject: Make stored geometry and default window size enums --- src/ui/dialog/inkscape-preferences.cpp | 10 +++++----- src/ui/interface.cpp | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 0ac12d15c..ba0758d3c 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -684,9 +684,9 @@ void InkscapePreferences::initPageUI() } // Windows - _win_save_geom.init ( _("Save and restore window geometry for each document"), "/options/savewindowgeometry/value", 1, true, 0); - _win_save_geom_prefs.init ( _("Remember and use last window's geometry"), "/options/savewindowgeometry/value", 2, false, &_win_save_geom); - _win_save_geom_off.init ( _("Don't save window geometry"), "/options/savewindowgeometry/value", 0, false, &_win_save_geom); + _win_save_geom.init ( _("Save and restore window geometry for each document"), "/options/savewindowgeometry/value", PREFS_WINDOW_GEOMETRY_FILE, true, 0); + _win_save_geom_prefs.init ( _("Remember and use last window's geometry"), "/options/savewindowgeometry/value", PREFS_WINDOW_GEOMETRY_LAST, false, &_win_save_geom); + _win_save_geom_off.init ( _("Don't save window geometry"), "/options/savewindowgeometry/value", PREFS_WINDOW_GEOMETRY_NONE, false, &_win_save_geom); _win_save_dialog_pos_on.init ( _("Save and restore dialogs status"), "/options/savedialogposition/value", 1, true, 0); _win_save_dialog_pos_off.init ( _("Don't save dialogs status"), "/options/savedialogposition/value", 0, false, &_win_save_dialog_pos_on); @@ -708,9 +708,9 @@ void InkscapePreferences::initPageUI() { Glib::ustring defaultSizeLabels[] = {C_("Window size", "Small"), C_("Window size", "Large"), C_("Window size", "Maximized")}; - int defaultSizeValues[] = {0, 1, 2}; + int defaultSizeValues[] = {PREFS_WINDOW_SIZE_SMALL, PREFS_WINDOW_SIZE_LARGE, PREFS_WINDOW_SIZE_MAXIMIZED}; - _win_default_size.init( "/options/defaultwindowsize/value", defaultSizeLabels, defaultSizeValues, G_N_ELEMENTS(defaultSizeLabels), 1 ); + _win_default_size.init( "/options/defaultwindowsize/value", defaultSizeLabels, defaultSizeValues, G_N_ELEMENTS(defaultSizeLabels), PREFS_WINDOW_SIZE_LARGE); _page_windows.add_line( false, _("Default window size:"), _win_default_size, "", _("Set the default window size"), false); } diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 3671380fe..816f4e337 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -30,6 +30,7 @@ #include "file.h" #include +#include "enums.h" #include "inkscape.h" #include "extension/db.h" #include "extension/effect.h" @@ -161,8 +162,8 @@ sp_create_window(SPViewWidget *vw, bool editable) win->signal_focus_in_event().connect(sigc::mem_fun(*desktop_widget, &SPDesktopWidget::onFocusInEvent)); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gint prefs_geometry = (2==prefs->getInt("/options/savewindowgeometry/value", 0)); - if (prefs_geometry) { + int window_geometry = prefs->getInt("/options/savewindowgeometry/value", PREFS_WINDOW_GEOMETRY_NONE); + if (window_geometry == PREFS_WINDOW_GEOMETRY_LAST) { gint pw = prefs->getInt("/desktop/geometry/width", -1); gint ph = prefs->getInt("/desktop/geometry/height", -1); gint px = prefs->getInt("/desktop/geometry/x", -1); -- cgit v1.2.3 From b706e529a4c10be331a1ca5d0d004cf24e8e5e9a Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 7 Jan 2018 16:30:32 +0100 Subject: Add convenience functions to obtain monitor geometry --- src/ui/CMakeLists.txt | 2 + src/ui/monitor.cpp | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/ui/monitor.h | 51 ++++++++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 src/ui/monitor.cpp create mode 100644 src/ui/monitor.h (limited to 'src/ui') diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index fecb14a91..b9933bba6 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -5,6 +5,7 @@ set(ui_SRC dialog-events.cpp draw-anchor.cpp interface.cpp + monitor.cpp previewholder.cpp selected-color.cpp shape-editor.cpp @@ -186,6 +187,7 @@ set(ui_SRC event-debug.h icon-names.h interface.h + monitor.h previewable.h previewfillable.h previewholder.h diff --git a/src/ui/monitor.cpp b/src/ui/monitor.cpp new file mode 100644 index 000000000..3e0c983fe --- /dev/null +++ b/src/ui/monitor.cpp @@ -0,0 +1,107 @@ +/** + * \file + * \brief helper functions for retrieving monitor geometry, etc. + *//* + * Authors: + * Eduard Braun + * + * Copyright 2018 Authors + * + * This file is part of Inkscape. + * + * Inkscape is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Inkscape is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Inkscape. If not, see . + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include + +#if GTKMM_CHECK_VERSION(3,22,0) +# include +#else +# include +#endif + + +namespace Inkscape { +namespace UI { + +/** get monitor geometry of primary monitor */ +Gdk::Rectangle get_monitor_geometry_primary() { + Gdk::Rectangle monitor_geometry; +#if GTKMM_CHECK_VERSION(3,22,0) + auto const display = Gdk::Display::get_default(); + auto const monitor = display->get_primary_monitor(); + + // Fallback to monitor number 0 if the user hasn't configured a primary monitor + if (!monitor) { + monitor = display->get_monitor(0); + } + + monitor->get_geometry(monitor_geometry); +#else + auto const default_screen = Gdk::Screen::get_default(); + auto const monitor_number = default_screen->get_primary_monitor(); + default_screen->get_monitor_geometry(monitor_number, monitor_geometry); +#endif + return monitor_geometry; +} + +/** get monitor geometry of monitor containing largest part of window */ +Gdk::Rectangle get_monitor_geometry_at_window(const Glib::RefPtr& window) { + Gdk::Rectangle monitor_geometry; +#if GTKMM_CHECK_VERSION(3,22,0) + auto const display = Gdk::Display::get_default(); + auto const monitor = display->get_monitor_at_window(window); + monitor->get_geometry(monitor_geometry); +#else + auto const default_screen = Gdk::Screen::get_default(); + auto const monitor_number = default_screen->get_monitor_at_window(window); + default_screen->get_monitor_geometry(monitor_number, monitor_geometry); +#endif + return monitor_geometry; +} + +/** get monitor geometry of monitor at (or closest to) point on combined screen area */ +Gdk::Rectangle get_monitor_geometry_at_point(int x, int y) { + Gdk::Rectangle monitor_geometry; +#if GTKMM_CHECK_VERSION(3,22,0) + auto const display = Gdk::Display::get_default(); + auto const monitor = display->get_monitor_at_point(x ,y); + monitor->get_geometry(monitor_geometry); +#else + auto const default_screen = Gdk::Screen::get_default(); + auto const monitor_number = default_screen->get_monitor_at_point(x, y); + default_screen->get_monitor_geometry(monitor_number, monitor_geometry); +#endif + return monitor_geometry; +} + +} +} + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace .0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim:filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99: diff --git a/src/ui/monitor.h b/src/ui/monitor.h new file mode 100644 index 000000000..696a8ed73 --- /dev/null +++ b/src/ui/monitor.h @@ -0,0 +1,51 @@ +/** + * \file + * \brief helper functions for retrieving monitor geometry, etc. + *//* + * Authors: + * Eduard Braun + * + * Copyright 2018 Authors + * + * This file is part of Inkscape. + * + * Inkscape is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Inkscape is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Inkscape. If not, see . + */ + +#ifndef SEEN_MONITOR_H +#define SEEN_MONITOR_H + +#include +#include + +namespace Inkscape { +namespace UI { + Gdk::Rectangle get_monitor_geometry_primary(); + Gdk::Rectangle get_monitor_geometry_at_window(const Glib::RefPtr& window); + Gdk::Rectangle get_monitor_geometry_at_point(int x, int y); +} +} + +#endif // SEEN_MONITOR_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace .0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim:filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99: -- cgit v1.2.3 From dd958b6024fb9f68500eb583f4c3d981ed27e08c Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 7 Jan 2018 17:36:45 +0100 Subject: Make natural window size default and fix small window size - Clamp "Small" window size to 600x600 Everything smaller seems pretty unusable but can be discussed. This fixes bug #1659256. - Make sure "Large" window size is at least as large as "Small" to avoid embarassing user reports. - add "Default" as new window size and (surprise) make it the default This will not influence the initial size request at all and should result in the natural window size (unless overriden by the window manager) and should be a suitable default for all cases. Fixed bug: - https://bugs.launchpad.net/inkscape/+bug/1659256 --- src/ui/dialog/inkscape-preferences.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index ba0758d3c..7b7bd6548 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -707,10 +707,16 @@ void InkscapePreferences::initPageUI() _win_ontop_agressive.init ( _("Aggressive"), "/options/transientpolicy/value", 2, false, &_win_ontop_none); { - Glib::ustring defaultSizeLabels[] = {C_("Window size", "Small"), C_("Window size", "Large"), C_("Window size", "Maximized")}; - int defaultSizeValues[] = {PREFS_WINDOW_SIZE_SMALL, PREFS_WINDOW_SIZE_LARGE, PREFS_WINDOW_SIZE_MAXIMIZED}; - - _win_default_size.init( "/options/defaultwindowsize/value", defaultSizeLabels, defaultSizeValues, G_N_ELEMENTS(defaultSizeLabels), PREFS_WINDOW_SIZE_LARGE); + Glib::ustring defaultSizeLabels[] = {C_("Window size", "Default"), + C_("Window size", "Small"), + C_("Window size", "Large"), + C_("Window size", "Maximized")}; + int defaultSizeValues[] = {PREFS_WINDOW_SIZE_NATURAL, + PREFS_WINDOW_SIZE_SMALL, + PREFS_WINDOW_SIZE_LARGE, + PREFS_WINDOW_SIZE_MAXIMIZED}; + + _win_default_size.init( "/options/defaultwindowsize/value", defaultSizeLabels, defaultSizeValues, G_N_ELEMENTS(defaultSizeLabels), PREFS_WINDOW_SIZE_NATURAL); _page_windows.add_line( false, _("Default window size:"), _win_default_size, "", _("Set the default window size"), false); } -- cgit v1.2.3 From 0ab95408b8cd74e560ec30535f6cc4dc9dff3881 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 7 Jan 2018 17:53:16 +0100 Subject: Limit geometry from file to width/height of monitor --- src/ui/interface.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/ui') diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 816f4e337..7df3502f7 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -40,6 +40,7 @@ #include "document.h" #include "ui/interface.h" +#include "ui/monitor.h" #include "desktop.h" #include "selection-chemistry.h" #include "svg-view-widget.h" @@ -133,8 +134,6 @@ static void sp_ui_menu_item_set_name(GtkWidget *data, Glib::ustring const &name); static void sp_recent_open(GtkRecentChooser *, gpointer); -static const int MIN_ONSCREEN_DISTANCE = 50; - void sp_create_window(SPViewWidget *vw, bool editable) { @@ -171,6 +170,9 @@ sp_create_window(SPViewWidget *vw, bool editable) 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)); } -- cgit v1.2.3 From b35da777e89166e572344dce1247efccbb53fcf4 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 7 Jan 2018 19:13:08 +0100 Subject: Use convenience functions to obtain monitor geometry --- src/ui/dialog/dialog.cpp | 28 ++++------------------------ src/ui/uxmanager.cpp | 28 +++++----------------------- 2 files changed, 9 insertions(+), 47 deletions(-) (limited to 'src/ui') diff --git a/src/ui/dialog/dialog.cpp b/src/ui/dialog/dialog.cpp index 3d949a8c9..f7e9a1bed 100644 --- a/src/ui/dialog/dialog.cpp +++ b/src/ui/dialog/dialog.cpp @@ -20,13 +20,10 @@ #include "dialog-manager.h" #include -#if GTKMM_CHECK_VERSION(3,22,0) -# include -#endif - #include #include "inkscape.h" +#include "ui/monitor.h" #include "ui/tools/tool-base.h" #include "desktop.h" @@ -166,26 +163,9 @@ void Dialog::read_geometry() resize(w, h); } -#if GTKMM_CHECK_VERSION(3,22,0) - auto const display = Gdk::Display::get_default(); - auto monitor = display->get_primary_monitor(); - - // If user hasn't configured a primary monitor, nullptr is returned so try first monitor. - if (!monitor) { - std::cerr << "Dialog::read_geometry: no primary monitor configured!" << std::endl; - monitor = display->get_monitor(0); - } - - Gdk::Rectangle screen_geometry; - if (monitor) { - monitor->get_geometry(screen_geometry); - } - auto const screen_width = screen_geometry.get_width(); - auto const screen_height = screen_geometry.get_height(); -#else - auto const screen_width = gdk_screen_width(); - auto const screen_height = gdk_screen_height(); -#endif + Gdk::Rectangle monitor_geometry = Inkscape::UI::get_monitor_geometry_primary(); + auto const screen_width = monitor_geometry.get_width(); + auto const screen_height = monitor_geometry.get_height(); // If there are stored values for where the dialog should be // located, then restore the dialog to that position. diff --git a/src/ui/uxmanager.cpp b/src/ui/uxmanager.cpp index f48f40879..3ec38edf9 100644 --- a/src/ui/uxmanager.cpp +++ b/src/ui/uxmanager.cpp @@ -17,12 +17,10 @@ #include "uxmanager.h" #include "desktop.h" +#include "ui/monitor.h" #include "util/ege-tags.h" #include "widgets/toolbox.h" -#if GTKMM_CHECK_VERSION(3,22,0) -# include -#endif using std::vector; @@ -125,27 +123,11 @@ UXManagerImpl::UXManagerImpl() : tags.addTag(ege::Tag("Icons")); // Figure out if we're on a widescreen display -#if GTKMM_CHECK_VERSION(3,22,0) - auto display = Gdk::Display::get_default(); - auto monitor = display->get_primary_monitor(); - - // Fallback to monitor number 0 if the user hasn't configured a primary monitor - if (!monitor) { - monitor = display->get_monitor(0); - } + Gdk::Rectangle monitor_geometry = Inkscape::UI::get_monitor_geometry_primary(); + int const width = monitor_geometry.get_width(); + int const height = monitor_geometry.get_height(); - if(monitor) { - Gdk::Rectangle monitor_geometry; - monitor->get_geometry(monitor_geometry); - - int const width = monitor_geometry.get_width(); - int const height = monitor_geometry.get_height(); -#else - Glib::RefPtr defaultScreen = Gdk::Screen::get_default(); - if (defaultScreen) { - int width = defaultScreen->get_width(); - int height = defaultScreen->get_height(); -#endif + if (width && height) { gdouble aspect = static_cast(width) / static_cast(height); if (aspect > 1.65) { _widescreen = true; -- cgit v1.2.3