@@ -595,25 +595,12 @@ WaylandClipboard::WaylandClipboard(QObject *parent)
595595 });
596596
597597 m_manager->instantiate ();
598+ m_deviceRequestedTimer.start ();
598599}
599600
600601WaylandClipboard *WaylandClipboard::createInstance ()
601602{
602- qInfo () << " Using Wayland clipboard access" ;
603- auto clipboard = new WaylandClipboard (qApp);
604-
605- QElapsedTimer timer;
606- timer.start ();
607- while ( !clipboard->isActive () && timer.elapsed () < 5000 ) {
608- QCoreApplication::processEvents ();
609- }
610- if ( timer.elapsed () > 100 ) {
611- qWarning () << " Activating Wayland clipboard took" << timer.elapsed () << " ms" ;
612- }
613- if ( !clipboard->isActive () ) {
614- qCritical () << " Failed to activate Wayland clipboard" ;
615- }
616- return clipboard;
603+ return new WaylandClipboard (qApp);
617604}
618605
619606void WaylandClipboard::setMimeData (QMimeData *mime, QClipboard::Mode mode)
@@ -664,6 +651,30 @@ const QMimeData *WaylandClipboard::mimeData(QClipboard::Mode mode) const
664651 return nullptr ;
665652}
666653
654+ DataControlDevice *WaylandClipboard::device () const
655+ {
656+ if (m_device)
657+ return m_device.get ();
658+
659+ if (m_deviceRequestedTimer.elapsed () > 5000 )
660+ return nullptr ;
661+
662+ while (!m_device && m_deviceRequestedTimer.elapsed () < 5000 ) {
663+ QCoreApplication::processEvents ();
664+ }
665+
666+ if (m_device) {
667+ if (m_deviceRequestedTimer.elapsed () > 200 ) {
668+ qWarning () << " Activating Wayland clipboard took"
669+ << m_deviceRequestedTimer.elapsed () << " ms" ;
670+ }
671+ return m_device.get ();
672+ }
673+
674+ qCritical () << " Failed to activate Wayland clipboard" ;
675+ return nullptr ;
676+ }
677+
667678bool WaylandClipboard::isSelectionSupported () const
668679{
669680 return m_device && zwlr_data_control_device_v1_get_version (m_device->object ())
0 commit comments