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/svg-view-slideshow.cpp | 41 ++++------------------------------------- src/ui/dialog/dialog.cpp | 28 ++++------------------------ src/ui/uxmanager.cpp | 28 +++++----------------------- 3 files changed, 13 insertions(+), 84 deletions(-) (limited to 'src') diff --git a/src/svg-view-slideshow.cpp b/src/svg-view-slideshow.cpp index 0e50d582b..430fd9ce5 100644 --- a/src/svg-view-slideshow.cpp +++ b/src/svg-view-slideshow.cpp @@ -30,11 +30,6 @@ #endif #include - -#if GTKMM_CHECK_VERSION(3,22,0) -# include -#endif - #include #include #include @@ -42,16 +37,13 @@ #include "document.h" #include "ui/icon-names.h" +#include "ui/monitor.h" #include "util/units.h" #include "svg-view.h" #include "svg-view-slideshow.h" #include "svg-view-widget.h" -#if GTKMM_CHECK_VERSION(3,22,0) -# include -#endif - SPSlideShow::SPSlideShow(std::vector const &slides, bool full_screen, int timer, double scale) : _slides(slides) @@ -64,34 +56,9 @@ SPSlideShow::SPSlideShow(std::vector const &slides, bool full_scr , _ctrlwin(NULL) { // setup initial document -#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); - } - - if (monitor) { - Gdk::Rectangle monitor_geometry; - monitor->get_geometry(monitor_geometry); - - auto const monitor_width = monitor_geometry.get_width(); - auto const monitor_height = monitor_geometry.get_height(); - -#else - auto default_screen = Gdk::Screen::get_default(); - - if (default_screen) { - auto const monitor_width = default_screen->get_width(); - auto const monitor_height = default_screen->get_height(); -#endif - - set_default_size(MIN ((int)_doc->getWidth().value("px")*_scale, monitor_width - 64), - MIN ((int)_doc->getHeight().value("px")*_scale, monitor_height - 64)); - - } + Gdk::Rectangle monitor_geometry = Inkscape::UI::get_monitor_geometry_primary(); // TODO: is inkview always launched on primary monitor? + set_default_size(MIN ((int)_doc->getWidth().value("px")*_scale, monitor_geometry.get_width() - 64), + MIN ((int)_doc->getHeight().value("px")*_scale, monitor_geometry.get_height() - 64)); _view = sp_svg_view_widget_new(_doc); SP_SVG_VIEW_WIDGET(_view)->setResize( false, _doc->getWidth().value("px"), _doc->getHeight().value("px") ); 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