summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rosca <[email protected]>2016-12-03 15:35:01 +0100
committerDavid Rosca <[email protected]>2016-12-06 16:11:55 +0100
commitbc7304068610c033e777bd711e1eb569be98bcec (patch)
tree1127c2b7b1129997f50e6e09b1d51f0a3deb057b
parent947b25348934be7d31a9a2f554d234442a69a1dd (diff)
Implement drag from free space also for QtQuickControls
Use window manager to handle window move when dragging from free space also with QtQuickControls. Registering QQuickItems is hacky, because there is no Style::polish for QtQuickControls, so those items are now registered from ::isQtQuickControl. Differential Revision: https://phabricator.kde.org/D3578
-rw-r--r--kstyle/CMakeLists.txt4
-rw-r--r--kstyle/breezestyle.cpp4
-rw-r--r--kstyle/breezewindowmanager.cpp89
-rw-r--r--kstyle/breezewindowmanager.h25
4 files changed, 93 insertions, 29 deletions
diff --git a/kstyle/CMakeLists.txt b/kstyle/CMakeLists.txt
index c214429..545b8f7 100644
--- a/kstyle/CMakeLists.txt
+++ b/kstyle/CMakeLists.txt
@@ -39,7 +39,7 @@ if(BREEZE_USE_KDE4)
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 @@ else()
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
index f097a78..51c637e 100644
--- a/kstyle/breezestyle.cpp
+++ b/kstyle/breezestyle.cpp
@@ -6973,7 +6973,9 @@ namespace Breeze
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<QQuickItem*>( option->styleObject ) );
+ return is;
#else
Q_UNUSED( widget );
Q_UNUSED( option );
diff --git a/kstyle/breezewindowmanager.cpp b/kstyle/breezewindowmanager.cpp
index b1b6b8b..265fe50 100644
--- a/kstyle/breezewindowmanager.cpp
+++ b/kstyle/breezewindowmanager.cpp
@@ -89,6 +89,8 @@
#include <NETRootInfo>
#else
#include <NETWM>
+#include <QQuickItem>
+#include <QQuickWindow>
#endif
#endif
@@ -317,6 +319,22 @@ namespace Breeze
}
+#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 @@ namespace Breeze
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 @@ namespace Breeze
{
_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 @@ namespace Breeze
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<QQuickItem*>( 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<QWidget*>( object );
@@ -483,7 +531,7 @@ namespace Breeze
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 @@ namespace Breeze
}
_target.clear();
+#if !BREEZE_USE_KDE4
+ _quickTarget.clear();
+#endif
if( _dragTimer.isActive() ) _dragTimer.stop();
_dragPoint = QPoint();
_globalDragPoint = QPoint();
@@ -800,10 +851,10 @@ namespace Breeze
}
//____________________________________________________________
- 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
@@ -811,9 +862,9 @@ namespace Breeze
{
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 @@ namespace Breeze
}
//_______________________________________________________
- 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,28 +901,27 @@ namespace Breeze
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;
@@ -886,7 +929,7 @@ namespace Breeze
shellSurface->requestMove( _seat, _waylandSerial );
#else
- Q_UNUSED( widget );
+ Q_UNUSED( window );
Q_UNUSED( position );
#endif
}
diff --git a/kstyle/breezewindowmanager.h b/kstyle/breezewindowmanager.h
index a26bb51..af00397 100644
--- a/kstyle/breezewindowmanager.h
+++ b/kstyle/breezewindowmanager.h
@@ -31,6 +31,10 @@
#include <QString>
#include <QWidget>
+#if !BREEZE_USE_KDE4
+#include <QQuickItem>
+#endif
+
#if BREEZE_HAVE_KWAYLAND
namespace KWayland
{
@@ -66,6 +70,11 @@ namespace Breeze
//* 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 @@ namespace Breeze
//* 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 @@ namespace Breeze
/** Weak pointer is used in case the target gets deleted while drag is in progress */
WeakPointer<QWidget> _target;
+#if !BREEZE_USE_KDE4
+ WeakPointer<QQuickItem> _quickTarget;
+#endif
+
//* true if drag is about to start
bool _dragAboutToStart;