From c60f5dab3729d587eb025afefaf1f5555706368d Mon Sep 17 00:00:00 2001 From: Tuomas Nurmi Date: Thu, 9 Mar 2023 18:07:10 +0200 Subject: [PATCH 1/3] Port away from deprecated QDesktopWidget functions. Following the instructions on https://doc.qt.io/qt-5/qdesktopwidget-obsolete.html --- src/covermanager/CoverManager.cpp | 4 ++-- src/covermanager/CoverViewDialog.cpp | 3 +-- src/dialogs/OrganizeCollectionDialog.cpp | 4 ++-- src/widgets/Osd.cpp | 22 +++++++++++----------- src/widgets/PixmapViewer.cpp | 6 +++--- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/covermanager/CoverManager.cpp b/src/covermanager/CoverManager.cpp index e67a89416a..eb0d63f637 100644 --- a/src/covermanager/CoverManager.cpp +++ b/src/covermanager/CoverManager.cpp @@ -39,11 +39,11 @@ #include #include -#include #include #include //showCoverMenu() #include #include +#include #include #include #include @@ -228,7 +228,7 @@ CoverManager::slotContinueConstruction() //SLOT connect( m_progress, &CompoundProgressBar::allDone, this, &CoverManager::progressAllDone ); - QSize size = QApplication::desktop()->screenGeometry( this ).size() / 1.5; + QSize size = this->screen()->size() / 1.5; QSize sz = Amarok::config( "Cover Manager" ).readEntry( "Window Size", size ); resize( sz.width(), sz.height() ); diff --git a/src/covermanager/CoverViewDialog.cpp b/src/covermanager/CoverViewDialog.cpp index bb01e1f7fb..d3a1b96f7e 100644 --- a/src/covermanager/CoverViewDialog.cpp +++ b/src/covermanager/CoverViewDialog.cpp @@ -25,7 +25,6 @@ #include #include -#include #include #include @@ -72,7 +71,7 @@ CoverViewDialog::zoomFactorChanged( qreal value ) void CoverViewDialog::createViewer( const QImage &image, const QWidget *widget ) { - int screenNumber = QApplication::desktop()->screenNumber( widget ); + int screenNumber = QApplication::screens().indexOf( widget->screen() ); PixmapViewer *pixmapViewer = new PixmapViewer( this, QPixmap::fromImage(image), screenNumber ); QHBoxLayout *layout = new QHBoxLayout( this ); layout->addWidget( pixmapViewer ); diff --git a/src/dialogs/OrganizeCollectionDialog.cpp b/src/dialogs/OrganizeCollectionDialog.cpp index fb59c98224..cfda1f109c 100644 --- a/src/dialogs/OrganizeCollectionDialog.cpp +++ b/src/dialogs/OrganizeCollectionDialog.cpp @@ -30,9 +30,9 @@ #include "ui_OrganizeCollectionDialogBase.h" #include -#include #include #include +#include #include #include @@ -84,7 +84,7 @@ OrganizeCollectionWidget::OrganizeCollectionWidget( QWidget *parent ) // show some non-editable tags before and after // but only if screen size is large enough (BR: 283361) - const QRect screenRect = QApplication::desktop()->screenGeometry(); + const QRect screenRect = QApplication::primaryScreen()->geometry(); if( screenRect.width() >= 1024 ) { m_schemaLineLayout->insertWidget( 0, diff --git a/src/widgets/Osd.cpp b/src/widgets/Osd.cpp index dc1cf722e3..062f3ceeb9 100644 --- a/src/widgets/Osd.cpp +++ b/src/widgets/Osd.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -245,7 +246,7 @@ OSDWidget::determineMetrics( const int M ) // determine a sensible maximum size, don't cover the whole desktop or cross the screen const QSize margin( ( M + MARGIN ) * 2, ( M + MARGIN ) * 2 ); //margins const QSize image = m_cover.isNull() ? QSize( 0, 0 ) : minImageSize; - const QSize max = QApplication::desktop()->screen( m_screen )->size() - margin; + const QSize max = QApplication::screens()[ screen() ]->size() - margin; // If we don't do that, the boundingRect() might not be suitable for drawText() (Qt issue N67674) m_text.replace( QRegExp( " +\n" ), "\n" ); @@ -311,7 +312,7 @@ OSDWidget::determineMetrics( const int M ) rect.adjust( -M, -M, M, M ); const QSize newSize = rect.size(); - const QRect screen = QApplication::desktop()->screenGeometry( m_screen ); + const QRect screenRect = QApplication::screens()[ screen() ]->geometry(); QPoint newPos( MARGIN, m_yOffset ); switch( m_alignment ) @@ -320,25 +321,25 @@ OSDWidget::determineMetrics( const int M ) break; case Right: - newPos.rx() = screen.width() - MARGIN - newSize.width(); + newPos.rx() = screenRect.width() - MARGIN - newSize.width(); break; case Center: - newPos.ry() = ( screen.height() - newSize.height() ) / 2; + newPos.ry() = ( screenRect.height() - newSize.height() ) / 2; Q_FALLTHROUGH(); case Middle: - newPos.rx() = ( screen.width() - newSize.width() ) / 2; + newPos.rx() = ( screenRect.width() - newSize.width() ) / 2; break; } //ensure we don't dip below the screen - if ( newPos.y() + newSize.height() > screen.height() - MARGIN ) - newPos.ry() = screen.height() - MARGIN - newSize.height(); + if ( newPos.y() + newSize.height() > screenRect.height() - MARGIN ) + newPos.ry() = screenRect.height() - MARGIN - newSize.height(); // correct for screen position - newPos += screen.topLeft(); + newPos += screenRect.topLeft(); return QRect( newPos, rect.size() ); } @@ -551,7 +552,7 @@ OSDPreviewWidget::mouseMoveEvent( QMouseEvent *e ) { // Here we implement a "snap-to-grid" like positioning system for the preview widget - const QRect screenRect = QApplication::desktop()->screenGeometry( screen() ); + const QRect screenRect = QApplication::screens()[ screen() ]->geometry(); const uint hcenter = screenRect.width() / 2; const uint eGlobalPosX = e->globalPos().x() - screenRect.left(); const uint snapZone = screenRect.width() / 24; @@ -592,8 +593,7 @@ OSDPreviewWidget::mouseMoveEvent( QMouseEvent *e ) move( destination ); // compute current Position && Y-offset - QDesktopWidget *desktop = QApplication::desktop(); - const int currentScreen = desktop->screenNumber( pos() ); + const int currentScreen = QGuiApplication::screens().indexOf( QGuiApplication::screenAt( pos() ) ); // set new data OSDWidget::setScreen( currentScreen ); diff --git a/src/widgets/PixmapViewer.cpp b/src/widgets/PixmapViewer.cpp index 158540f541..332dbc5d5e 100644 --- a/src/widgets/PixmapViewer.cpp +++ b/src/widgets/PixmapViewer.cpp @@ -21,11 +21,11 @@ #include -#include #include #include #include #include +#include #include @@ -35,8 +35,8 @@ PixmapViewer::PixmapViewer( QWidget *parent, const QPixmap &pix, int screenNumbe { m_zoomFactor = 1.0; // initial zoom - int screenWidth = QApplication::desktop()->availableGeometry( screenNumber ).width(); - int screenHeight = QApplication::desktop()->availableGeometry( screenNumber ).height(); + int screenWidth = QApplication::screens()[ screenNumber ]->availableGeometry().width(); + int screenHeight = QApplication::screens()[ screenNumber ]->availableGeometry().height(); if( screenWidth < m_pixmap.width() || screenHeight < m_pixmap.height() ) { qreal zoomFactorX = qreal(screenWidth) / m_pixmap.width(); -- GitLab From b95c439ebba30ba257ba75d060b237a293415ea8 Mon Sep 17 00:00:00 2001 From: Tuomas Nurmi Date: Sat, 11 Mar 2023 15:22:18 +0200 Subject: [PATCH 2/3] Disable OSD options not available on Wayland. --- src/configdialog/dialogs/NotificationsConfig.cpp | 6 +++++- src/widgets/Osd.cpp | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/configdialog/dialogs/NotificationsConfig.cpp b/src/configdialog/dialogs/NotificationsConfig.cpp index 0c16fdcb17..1c3387206a 100644 --- a/src/configdialog/dialogs/NotificationsConfig.cpp +++ b/src/configdialog/dialogs/NotificationsConfig.cpp @@ -51,7 +51,11 @@ NotificationsConfig::NotificationsConfig( Amarok2ConfigDialog* parent ) #endif // Enable/disable the translucency option depending on availability of desktop compositing - kcfg_OsdUseTranslucency->setEnabled( KWindowSystem::compositingActive() ); + // As opacity functionality is not available on Wayland at least with current implementation, don't enable option there + kcfg_OsdUseTranslucency->setEnabled( !KWindowSystem::isPlatformWayland() && KWindowSystem::compositingActive() ); + + // Also disable other functionalities not (yet?) available on Wayland + kcfg_OsdScreen->setEnabled( !KWindowSystem::isPlatformWayland() ); connect( m_osdPreview, &OSDPreviewWidget::positionChanged, this, &NotificationsConfig::slotPositionChanged ); diff --git a/src/widgets/Osd.cpp b/src/widgets/Osd.cpp index 062f3ceeb9..e29a1b2347 100644 --- a/src/widgets/Osd.cpp +++ b/src/widgets/Osd.cpp @@ -509,7 +509,9 @@ OSDPreviewWidget::OSDPreviewWidget( QWidget *parent ) setDuration( 0 ); setImage( Amarok::icon() ); setTranslucent( AmarokConfig::osdUseTranslucency() ); - setText( i18n( "On-Screen-Display preview\nDrag to reposition" ) ); + // Drag-positioning not available on Wayland, so let's hide any untrue ideas about dragging + // TODO maybe one day Wayland will be first-class OSD citizen + setText( KWindowSystem::isPlatformWayland() ? i18n ( "Preview" ) : i18n( "On-Screen-Display preview\nDrag to reposition" ) ); } void @@ -517,7 +519,9 @@ OSDPreviewWidget::mousePressEvent( QMouseEvent *event ) { m_dragYOffset = event->pos(); - if( event->button() == Qt::LeftButton && !m_dragging ) + // As we can't position OSD on Wayland at the moment, and grabbing mouse doesn't quite work + // either, let's disable this for now. + if( !KWindowSystem::isPlatformWayland() && event->button() == Qt::LeftButton && !m_dragging ) { grabMouse( Qt::SizeAllCursor ); m_dragging = true; -- GitLab From d70177ab4a57c3aecf63cfd3937044c575ee1a6a Mon Sep 17 00:00:00 2001 From: Tuomas Nurmi Date: Sat, 11 Mar 2023 17:58:59 +0200 Subject: [PATCH 3/3] Remove obsolete ifdef. Apparently Q_WS's are not defined any more. Turns out, if run, the setType actually makes the OSD positioning to go totally bonkers on X11, so let's just remove it. --- src/widgets/Osd.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/widgets/Osd.cpp b/src/widgets/Osd.cpp index e29a1b2347..1eee135be4 100644 --- a/src/widgets/Osd.cpp +++ b/src/widgets/Osd.cpp @@ -87,10 +87,6 @@ OSDWidget::OSDWidget( QWidget *parent, const char *name ) setObjectName( name ); setFocusPolicy( Qt::NoFocus ); - #ifdef Q_WS_X11 - KWindowSystem::setType( winId(), NET::Notification ); - #endif - m_timer->setSingleShot( true ); connect( m_timer, &QTimer::timeout, this, &OSDWidget::hide ); -- GitLab