diff --git a/kstyle/CMakeLists.txt b/kstyle/CMakeLists.txt --- a/kstyle/CMakeLists.txt +++ b/kstyle/CMakeLists.txt @@ -39,7 +39,7 @@ else() - find_package(Qt5 REQUIRED CONFIG COMPONENTS Widgets DBus) + find_package(Qt5 REQUIRED CONFIG COMPONENTS Widgets DBus Quick) find_package(KF5 REQUIRED COMPONENTS I18n Config @@ -151,7 +151,7 @@ kconfig_add_kcfg_files(breeze_PART_SRCS breezestyleconfigdata.kcfgc) add_library(breeze MODULE ${breeze_PART_SRCS}) - target_link_libraries(breeze Qt5::Core Qt5::Gui Qt5::Widgets Qt5::DBus) + target_link_libraries(breeze Qt5::Core Qt5::Gui Qt5::Widgets Qt5::DBus Qt5::Quick) target_link_libraries(breeze KF5::ConfigCore KF5::ConfigWidgets KF5::GuiAddons KF5::WindowSystem) if( KF5FrameworkIntegration_FOUND ) diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -6973,7 +6973,9 @@ bool Style::isQtQuickControl( const QStyleOption* option, const QWidget* widget ) const { #if QT_VERSION >= 0x050000 - return (widget == nullptr) && option && option->styleObject && option->styleObject->inherits( "QQuickItem" ); + const bool is = (widget == nullptr) && option && option->styleObject && option->styleObject->inherits( "QQuickItem" ); + if ( is ) _windowManager->registerQuickItem( static_cast( option->styleObject ) ); + return is; #else Q_UNUSED( widget ); Q_UNUSED( option ); diff --git a/kstyle/breezewindowmanager.h b/kstyle/breezewindowmanager.h --- a/kstyle/breezewindowmanager.h +++ b/kstyle/breezewindowmanager.h @@ -31,6 +31,10 @@ #include #include +#if !BREEZE_USE_KDE4 +#include +#endif + #if BREEZE_HAVE_KWAYLAND namespace KWayland { @@ -66,6 +70,11 @@ //* register widget void registerWidget( QWidget* ); +#if !BREEZE_USE_KDE4 + //* register quick item + void registerQuickItem( QQuickItem* ); +#endif + //* unregister widget void unregisterWidget( QWidget* ); @@ -163,14 +172,20 @@ //* reset drag void resetDrag( void ); +#if QT_VERSION >= 0x050000 + using Window = QWindow; +#else + using Window = QWidget; +#endif + //* start drag - void startDrag( QWidget*, const QPoint& ); + void startDrag( Window*, const QPoint& ); //* X11 specific implementation for startDrag - void startDragX11( QWidget*, const QPoint& ); + void startDragX11( Window*, const QPoint& ); //* Wayland specific implementation for startDrag - void startDragWayland( QWidget*, const QPoint& ); + void startDragWayland( Window*, const QPoint& ); //* returns true if window manager is used for moving /** right now this is true only for X11 */ @@ -263,6 +278,10 @@ /** Weak pointer is used in case the target gets deleted while drag is in progress */ WeakPointer _target; +#if !BREEZE_USE_KDE4 + WeakPointer _quickTarget; +#endif + //* true if drag is about to start bool _dragAboutToStart; diff --git a/kstyle/breezewindowmanager.cpp b/kstyle/breezewindowmanager.cpp --- a/kstyle/breezewindowmanager.cpp +++ b/kstyle/breezewindowmanager.cpp @@ -89,6 +89,8 @@ #include #else #include +#include +#include #endif #endif @@ -317,6 +319,22 @@ } +#if !BREEZE_USE_KDE4 + void WindowManager::registerQuickItem( QQuickItem* item ) + { + if ( !item ) return; + + QQuickWindow *window = item->window(); + if (window) { + QQuickItem *contentItem = window->contentItem(); + contentItem->setAcceptedMouseButtons( Qt::LeftButton ); + contentItem->removeEventFilter( this ); + contentItem->installEventFilter( this ); + } + + } +#endif + //_____________________________________________________________ void WindowManager::unregisterWidget( QWidget* widget ) { @@ -372,11 +390,19 @@ break; case QEvent::MouseMove: - if ( object == _target.data() ) return mouseMoveEvent( object, event ); + if ( object == _target.data() +#if !BREEZE_USE_KDE4 + || object == _quickTarget.data() +#endif + ) return mouseMoveEvent( object, event ); break; case QEvent::MouseButtonRelease: - if ( _target ) return mouseReleaseEvent( object, event ); + if ( _target +#if !BREEZE_USE_KDE4 + || _quickTarget +#endif + ) return mouseReleaseEvent( object, event ); break; default: @@ -396,8 +422,15 @@ { _dragTimer.stop(); +#if BREEZE_USE_KDE4 + if( _target ) + { startDrag( _target.data()->window(), _globalDragPoint ); } +#else if( _target ) - { startDrag( _target.data(), _globalDragPoint ); } + { startDrag( _target.data()->window()->windowHandle(), _globalDragPoint ); } + else if( _quickTarget ) + { startDrag( _quickTarget.data()->window(), _globalDragPoint ); } +#endif } else { @@ -420,6 +453,21 @@ if( isLocked() ) return false; else setLocked( true ); +#if !BREEZE_USE_KDE4 + // check QQuickItem - we can immediately start drag, because QQuickWindow's contentItem + // only receives mouse events that weren't handled by children + if ( QQuickItem *item = qobject_cast( object ) ) { + _quickTarget = item; + _dragPoint = mouseEvent->pos(); + _globalDragPoint = mouseEvent->globalPos(); + + if( _dragTimer.isActive() ) _dragTimer.stop(); + _dragTimer.start( _dragDelay, this ); + + return true; + } +#endif + // cast to widget QWidget *widget = static_cast( object ); @@ -483,7 +531,7 @@ return true; - } else if( !useWMMoveResize() ) { + } else if( !useWMMoveResize() && _target ) { // use QWidget::move for the grabbing /* this works only if the sending object and the target are identical */ @@ -791,6 +839,9 @@ } _target.clear(); +#if !BREEZE_USE_KDE4 + _quickTarget.clear(); +#endif if( _dragTimer.isActive() ) _dragTimer.stop(); _dragPoint = QPoint(); _globalDragPoint = QPoint(); @@ -800,20 +851,20 @@ } //____________________________________________________________ - void WindowManager::startDrag( QWidget* widget, const QPoint& position ) + void WindowManager::startDrag( Window* window, const QPoint& position ) { - if( !( enabled() && widget ) ) return; + if( !( enabled() && window ) ) return; if( QWidget::mouseGrabber() ) return; // ungrab pointer if( useWMMoveResize() ) { if( Helper::isX11() ) { - startDragX11( widget, position ); + startDragX11( window, position ); } else if( Helper::isWayland() ) { - startDragWayland( widget, position ); + startDragWayland( window, position ); } } else if( !_cursorOverride ) { @@ -830,21 +881,14 @@ } //_______________________________________________________ - void WindowManager::startDragX11( QWidget* widget, const QPoint& position ) + void WindowManager::startDragX11( Window* window, const QPoint& position ) { #if BREEZE_HAVE_X11 // connection xcb_connection_t* connection( Helper::connection() ); - // window - const WId window( widget->window()->winId() ); - #if QT_VERSION >= 0x050300 - qreal dpiRatio = 1; - QWindow* windowHandle = widget->window()->windowHandle(); - if( windowHandle ) dpiRatio = windowHandle->devicePixelRatio(); - else dpiRatio = qApp->devicePixelRatio(); - dpiRatio = qApp->devicePixelRatio(); + const qreal dpiRatio = window->devicePixelRatio(); #else const qreal dpiRatio = 1; #endif @@ -857,36 +901,35 @@ xcb_ungrab_pointer( connection, XCB_TIME_CURRENT_TIME ); NETRootInfo( net_connection, NET::WMMoveResize ).moveResizeRequest( - window, position.x() * dpiRatio, + window->winId(), position.x() * dpiRatio, position.y() * dpiRatio, NET::Move ); #else - Q_UNUSED( widget ); + Q_UNUSED( window ); Q_UNUSED( position ); #endif } //_______________________________________________________ - void WindowManager::startDragWayland( QWidget* widget, const QPoint& position ) + void WindowManager::startDragWayland( Window* window, const QPoint& position ) { #if BREEZE_HAVE_KWAYLAND if( !_seat ) { return; } - QWindow* windowHandle = widget->window()->windowHandle(); - auto shellSurface = KWayland::Client::ShellSurface::fromWindow(windowHandle); + auto shellSurface = KWayland::Client::ShellSurface::fromWindow(window); if( !shellSurface ) { // TODO: also check for xdg-shell in future return; } shellSurface->requestMove( _seat, _waylandSerial ); #else - Q_UNUSED( widget ); + Q_UNUSED( window ); Q_UNUSED( position ); #endif }