summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2015-11-05 14:30:53 -0800
committerGerald Combs <gerald@wireshark.org>2015-11-05 23:39:58 +0000
commitd02104c9a61c353ce6ed54c6ca6207ed3a1fcdf0 (patch)
tree8bad6b6ed1fde8251bfe404975a710a35e9074b1
parent2096c006aa33f1b49f601f8142fee6615fe2e7f0 (diff)
downloadwireshark-d02104c9a61c353ce6ed54c6ca6207ed3a1fcdf0.tar.gz
Qt: Check for a sane window geometry.
On Windows (and probably X11) it's possible to set an offscreen window geometry. Add a rect_on_screen function to qt_ui_utils and use it as a sanity check in MainWindow::loadWindowGeometry. If this doesn't work well (e.g. if we end up with dueling Qt and GTK+ geometries) we might want to create separate Qt and GTK+ preferences. Bug: 11568 Change-Id: Icde1181671770356e87f07d584894ec3148e1bd2 Reviewed-on: https://code.wireshark.org/review/11584 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Gerald Combs <gerald@wireshark.org>
-rw-r--r--ui/qt/main_window.cpp17
-rw-r--r--ui/qt/qt_ui_utils.cpp12
-rw-r--r--ui/qt/qt_ui_utils.h9
3 files changed, 33 insertions, 5 deletions
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp
index 00e293e1aa..f28ef8b6f2 100644
--- a/ui/qt/main_window.cpp
+++ b/ui/qt/main_window.cpp
@@ -775,7 +775,7 @@ void MainWindow::dropEvent(QDropEvent *event)
// position and size preference are enabled.
void MainWindow::loadWindowGeometry()
{
- int min_sensible_dimension_ = 200;
+ int min_sensible_dimension = 200;
#ifndef Q_OS_MAC
if (recent.gui_geometry_main_maximized) {
@@ -783,14 +783,21 @@ void MainWindow::loadWindowGeometry()
} else
#endif
{
+ QRect recent_geom(recent.gui_geometry_main_x, recent.gui_geometry_main_y,
+ recent.gui_geometry_main_width, recent.gui_geometry_main_height);
+ if (!rect_on_screen(recent_geom)) {
+ // We're not visible on any screens. Give up and use the default geometry.
+ return;
+ }
+
// if (prefs.gui_geometry_save_position) {
- move(recent.gui_geometry_main_x, recent.gui_geometry_main_y);
+ move(recent_geom.topLeft());
// }
if (// prefs.gui_geometry_save_size &&
- recent.gui_geometry_main_width > min_sensible_dimension_ &&
- recent.gui_geometry_main_height > min_sensible_dimension_) {
- resize(recent.gui_geometry_main_width, recent.gui_geometry_main_height);
+ recent_geom.width() > min_sensible_dimension &&
+ recent_geom.height() > min_sensible_dimension) {
+ resize(recent_geom.size());
}
}
}
diff --git a/ui/qt/qt_ui_utils.cpp b/ui/qt/qt_ui_utils.cpp
index aee727ab8b..67bf510b0e 100644
--- a/ui/qt/qt_ui_utils.cpp
+++ b/ui/qt/qt_ui_utils.cpp
@@ -41,7 +41,9 @@
#include <QDir>
#include <QFileInfo>
#include <QFontDatabase>
+#include <QGuiApplication>
#include <QProcess>
+#include <QScreen>
#include <QUrl>
#include <QUuid>
@@ -231,6 +233,16 @@ void desktop_show_in_folder(const QString file_path)
}
}
+bool rect_on_screen(const QRect &rect)
+{
+ foreach (const QScreen *screen, QGuiApplication::screens()) {
+ if (screen->availableGeometry().contains(rect))
+ return true;
+ }
+
+ return false;
+}
+
/*
* Editor modelines
*
diff --git a/ui/qt/qt_ui_utils.h b/ui/qt/qt_ui_utils.h
index 401ddbe00f..1beab1d8fa 100644
--- a/ui/qt/qt_ui_utils.h
+++ b/ui/qt/qt_ui_utils.h
@@ -37,6 +37,7 @@
class QAction;
class QFont;
+class QRect;
#ifdef __cplusplus
extern "C" {
@@ -193,6 +194,14 @@ bool qStringCaseLessThan(const QString &s1, const QString &s2);
*/
void desktop_show_in_folder(const QString file_path);
+/**
+ * Test to see if a rect is visible on screen.
+ *
+ * @param rect
+ * @return true if the rect is completely enclosed by one of the display
+ * screens, false otherwise.
+ */
+bool rect_on_screen(const QRect &rect);
#endif /* __QT_UI_UTILS__H__ */
// XXX Add a routine to fetch the HWND corresponding to a widget using QPlatformIntegration