From 09f2d95a9ccf6eeee7a93fe67d1006ac0d6d124c Mon Sep 17 00:00:00 2001 From: Vlad Zagorodniy Date: Wed, 10 Jul 2019 16:26:49 +0300 Subject: [PATCH] Don't use deprecated QDesktopWidget Summary: QApplication::desktop() is deprecated. It is advised to use QGuiApplication::screens() instead. Reviewers: #kwin, apol Reviewed By: apol Subscribers: apol, davidedmundson, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D22379 --- kcmkwin/kwinoptions/windows.cpp | 2 +- kcmkwin/kwinscreenedges/monitor.cpp | 31 +++++++++++++++++++++++++--- kcmkwin/kwintabbox/layoutpreview.cpp | 4 +++- kcmkwin/kwintabbox/main.cpp | 2 +- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/kcmkwin/kwinoptions/windows.cpp b/kcmkwin/kwinoptions/windows.cpp index 3dbe15ee82..c6a3a6bc7d 100644 --- a/kcmkwin/kwinoptions/windows.cpp +++ b/kcmkwin/kwinoptions/windows.cpp @@ -119,7 +119,7 @@ KFocusConfig::KFocusConfig(bool _standAlone, KConfig *_config, QWidget * parent) void KFocusConfig::updateMultiScreen() { - m_ui->multiscreenBox->setVisible(QApplication::desktop()->screenCount() > 1); + m_ui->multiscreenBox->setVisible(QApplication::screens().count() > 1); } diff --git a/kcmkwin/kwinscreenedges/monitor.cpp b/kcmkwin/kwinscreenedges/monitor.cpp index d1f0fb0d00..73b709b7bc 100644 --- a/kcmkwin/kwinscreenedges/monitor.cpp +++ b/kcmkwin/kwinscreenedges/monitor.cpp @@ -26,20 +26,45 @@ along with this program. If not, see . #include #include -#include #include #include #include #include +#include +#include namespace KWin { +static QWindow *windowFromWidget(const QWidget *widget) +{ + QWindow *windowHandle = widget->windowHandle(); + if (windowHandle) { + return windowHandle; + } + + const QWidget *nativeParent = widget->nativeParentWidget(); + if (nativeParent) { + return nativeParent->windowHandle(); + } + + return nullptr; +} + +static QScreen *screenFromWidget(const QWidget *widget) +{ + const QWindow *windowHandle = windowFromWidget(widget); + if (windowHandle && windowHandle->screen()) { + return windowHandle->screen(); + } + + return QGuiApplication::primaryScreen(); +} + Monitor::Monitor(QWidget* parent) : ScreenPreviewWidget(parent) { - QDesktopWidget *desktop = QApplication::desktop(); - QRect avail = desktop->availableGeometry(desktop->screenNumber(this)); + QRect avail = screenFromWidget(this)->geometry(); setRatio((qreal)avail.width() / (qreal)avail.height()); for (int i = 0; i < 8; diff --git a/kcmkwin/kwintabbox/layoutpreview.cpp b/kcmkwin/kwintabbox/layoutpreview.cpp index 716b000b2c..2859d673e6 100644 --- a/kcmkwin/kwintabbox/layoutpreview.cpp +++ b/kcmkwin/kwintabbox/layoutpreview.cpp @@ -25,6 +25,7 @@ along with this program. If not, see . #include #include #include +#include #include #include #include @@ -243,7 +244,8 @@ void SwitcherItem::setCurrentIndex(int index) QRect SwitcherItem::screenGeometry() const { - return qApp->desktop()->screenGeometry(qApp->desktop()->primaryScreen()); + const QScreen *primaryScreen = qApp->primaryScreen(); + return primaryScreen->geometry(); } void SwitcherItem::incrementIndex() diff --git a/kcmkwin/kwintabbox/main.cpp b/kcmkwin/kwintabbox/main.cpp index f1827ee7cf..bc64d73991 100644 --- a/kcmkwin/kwintabbox/main.cpp +++ b/kcmkwin/kwintabbox/main.cpp @@ -145,7 +145,7 @@ KWinTabBoxConfig::KWinTabBoxConfig(QWidget* parent, const QVariantList& args) connect(ui[i]->otherActivities, SIGNAL(clicked(bool)), SLOT(changed())); connect(ui[i]->filterScreens, SIGNAL(clicked(bool)), SLOT(changed())); - if (QApplication::desktop()->screenCount() < 2) { + if (QApplication::screens().count() < 2) { ui[i]->filterScreens->hide(); ui[i]->screenFilter->hide(); } else {