Changeset View
Changeset View
Standalone View
Standalone View
kstyle/oxygenwindowmanager.cpp
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | |||||
59 | #include <QGroupBox> | 59 | #include <QGroupBox> | ||
60 | #include <QLabel> | 60 | #include <QLabel> | ||
61 | #include <QListView> | 61 | #include <QListView> | ||
62 | #include <QMainWindow> | 62 | #include <QMainWindow> | ||
63 | #include <QMdiSubWindow> | 63 | #include <QMdiSubWindow> | ||
64 | #include <QMenuBar> | 64 | #include <QMenuBar> | ||
65 | #include <QMouseEvent> | 65 | #include <QMouseEvent> | ||
66 | #include <QProgressBar> | 66 | #include <QProgressBar> | ||
67 | #include <QQuickItem> | ||||
68 | #include <QQuickWindow> | ||||
67 | #include <QScrollBar> | 69 | #include <QScrollBar> | ||
68 | #include <QStatusBar> | 70 | #include <QStatusBar> | ||
69 | #include <QStyle> | 71 | #include <QStyle> | ||
70 | #include <QStyleOptionGroupBox> | 72 | #include <QStyleOptionGroupBox> | ||
71 | #include <QTabBar> | 73 | #include <QTabBar> | ||
72 | #include <QTabWidget> | 74 | #include <QTabWidget> | ||
73 | #include <QToolBar> | 75 | #include <QToolBar> | ||
74 | #include <QToolButton> | 76 | #include <QToolButton> | ||
75 | #include <QTreeView> | 77 | #include <QTreeView> | ||
76 | 78 | | |||
77 | #include <QTextStream> | 79 | #include <QTextStream> | ||
78 | | ||||
79 | #if QT_VERSION >= 0x050300 | | |||
80 | // needed to deal with device pixel ratio | 80 | // needed to deal with device pixel ratio | ||
81 | #include <QWindow> | 81 | #include <QWindow> | ||
82 | #endif | | |||
83 | 82 | | |||
84 | #if OXYGEN_HAVE_X11 | 83 | #if OXYGEN_HAVE_X11 | ||
85 | #include <QX11Info> | 84 | #include <QX11Info> | ||
86 | #include <xcb/xcb.h> | 85 | #include <xcb/xcb.h> | ||
87 | 86 | | |||
88 | #if OXYGEN_USE_KDE4 | | |||
89 | #include <NETRootInfo> | | |||
90 | #else | | |||
91 | #include <NETWM> | 87 | #include <NETWM> | ||
92 | #endif | | |||
93 | 88 | | |||
94 | #endif | 89 | #endif | ||
95 | 90 | | |||
96 | #if !OXYGEN_USE_KDE4 | | |||
97 | #include <QQuickItem> | | |||
98 | #include <QQuickWindow> | | |||
99 | #endif | | |||
100 | | ||||
101 | #if OXYGEN_HAVE_KWAYLAND | 91 | #if OXYGEN_HAVE_KWAYLAND | ||
102 | #include <KWayland/Client/connection_thread.h> | 92 | #include <KWayland/Client/connection_thread.h> | ||
103 | #include <KWayland/Client/pointer.h> | 93 | #include <KWayland/Client/pointer.h> | ||
104 | #include <KWayland/Client/registry.h> | 94 | #include <KWayland/Client/registry.h> | ||
105 | #include <KWayland/Client/shell.h> | 95 | #include <KWayland/Client/shell.h> | ||
106 | #include <KWayland/Client/seat.h> | 96 | #include <KWayland/Client/seat.h> | ||
107 | #endif | 97 | #endif | ||
108 | 98 | | |||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 108 | { | |||
158 | 148 | | |||
159 | protected: | 149 | protected: | ||
160 | 150 | | |||
161 | //* application-wise event. | 151 | //* application-wise event. | ||
162 | /** needed to catch end of XMoveResize events */ | 152 | /** needed to catch end of XMoveResize events */ | ||
163 | bool appMouseEvent( QObject*, QEvent* event ) | 153 | bool appMouseEvent( QObject*, QEvent* event ) | ||
164 | { | 154 | { | ||
165 | 155 | | |||
166 | #if OXYGEN_USE_KDE4 | | |||
167 | // store target window (see later) | | |||
168 | QWidget* window( _parent->_target.data()->window() ); | | |||
169 | #else | | |||
170 | Q_UNUSED( event ); | 156 | Q_UNUSED( event ); | ||
171 | #endif | | |||
172 | 157 | | |||
173 | /* | 158 | /* | ||
174 | post some mouseRelease event to the target, in order to counter balance | 159 | post some mouseRelease event to the target, in order to counter balance | ||
175 | the mouse press that triggered the drag. Note that it triggers a resetDrag | 160 | the mouse press that triggered the drag. Note that it triggers a resetDrag | ||
176 | */ | 161 | */ | ||
177 | QMouseEvent mouseEvent( QEvent::MouseButtonRelease, _parent->_dragPoint, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier ); | 162 | QMouseEvent mouseEvent( QEvent::MouseButtonRelease, _parent->_dragPoint, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier ); | ||
178 | qApp->sendEvent( _parent->_target.data(), &mouseEvent ); | 163 | qApp->sendEvent( _parent->_target.data(), &mouseEvent ); | ||
179 | 164 | | |||
180 | #if OXYGEN_USE_KDE4 | | |||
181 | if( event->type() == QEvent::MouseMove ) | | |||
182 | { | | |||
183 | /* | | |||
184 | HACK: quickly move the main cursor out of the window and back | | |||
185 | this is needed to get the focus right for the window children | | |||
186 | the origin of this issue is unknown at the moment. | | |||
187 | This apparently got fixed with qt5 | | |||
188 | */ | | |||
189 | const QPoint cursor = QCursor::pos(); | | |||
190 | QCursor::setPos(window->mapToGlobal( window->rect().topRight() ) + QPoint(1, 0) ); | | |||
191 | QCursor::setPos(cursor); | | |||
192 | | ||||
193 | } | | |||
194 | #endif | | |||
195 | | ||||
196 | return false; | 165 | return false; | ||
197 | 166 | | |||
198 | } | 167 | } | ||
199 | 168 | | |||
200 | private: | 169 | private: | ||
201 | 170 | | |||
202 | //* parent | 171 | //* parent | ||
203 | WindowManager* _parent; | 172 | WindowManager* _parent; | ||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Line(s) | 279 | { | |||
317 | */ | 286 | */ | ||
318 | widget->removeEventFilter( this ); | 287 | widget->removeEventFilter( this ); | ||
319 | widget->installEventFilter( this ); | 288 | widget->installEventFilter( this ); | ||
320 | 289 | | |||
321 | } | 290 | } | ||
322 | 291 | | |||
323 | } | 292 | } | ||
324 | 293 | | |||
325 | #if !OXYGEN_USE_KDE4 | | |||
326 | void WindowManager::registerQuickItem( QQuickItem* item ) | 294 | void WindowManager::registerQuickItem( QQuickItem* item ) | ||
327 | { | 295 | { | ||
328 | if ( !item ) return; | 296 | if ( !item ) return; | ||
329 | 297 | | |||
330 | QQuickWindow *window = item->window(); | 298 | QQuickWindow *window = item->window(); | ||
331 | if (window) { | 299 | if (window) { | ||
332 | QQuickItem *contentItem = window->contentItem(); | 300 | QQuickItem *contentItem = window->contentItem(); | ||
333 | contentItem->setAcceptedMouseButtons( Qt::LeftButton ); | 301 | contentItem->setAcceptedMouseButtons( Qt::LeftButton ); | ||
334 | contentItem->removeEventFilter( this ); | 302 | contentItem->removeEventFilter( this ); | ||
335 | contentItem->installEventFilter( this ); | 303 | contentItem->installEventFilter( this ); | ||
336 | } | 304 | } | ||
337 | 305 | | |||
338 | } | 306 | } | ||
339 | #endif | | |||
340 | 307 | | |||
341 | //_____________________________________________________________ | 308 | //_____________________________________________________________ | ||
342 | void WindowManager::unregisterWidget( QWidget* widget ) | 309 | void WindowManager::unregisterWidget( QWidget* widget ) | ||
343 | { | 310 | { | ||
344 | if( widget ) | 311 | if( widget ) | ||
345 | { widget->removeEventFilter( this ); } | 312 | { widget->removeEventFilter( this ); } | ||
346 | } | 313 | } | ||
347 | 314 | | |||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 353 | { | |||
389 | switch ( event->type() ) | 356 | switch ( event->type() ) | ||
390 | { | 357 | { | ||
391 | case QEvent::MouseButtonPress: | 358 | case QEvent::MouseButtonPress: | ||
392 | return mousePressEvent( object, event ); | 359 | return mousePressEvent( object, event ); | ||
393 | break; | 360 | break; | ||
394 | 361 | | |||
395 | case QEvent::MouseMove: | 362 | case QEvent::MouseMove: | ||
396 | if ( object == _target.data() | 363 | if ( object == _target.data() | ||
397 | #if !OXYGEN_USE_KDE4 | | |||
398 | || object == _quickTarget.data() | 364 | || object == _quickTarget.data() | ||
399 | #endif | | |||
400 | ) return mouseMoveEvent( object, event ); | 365 | ) return mouseMoveEvent( object, event ); | ||
401 | break; | 366 | break; | ||
402 | 367 | | |||
403 | case QEvent::MouseButtonRelease: | 368 | case QEvent::MouseButtonRelease: | ||
404 | if ( _target | 369 | if ( _target | ||
405 | #if !OXYGEN_USE_KDE4 | | |||
406 | || _quickTarget | 370 | || _quickTarget | ||
407 | #endif | | |||
408 | ) return mouseReleaseEvent( object, event ); | 371 | ) return mouseReleaseEvent( object, event ); | ||
409 | 372 | | |||
410 | break; | 373 | break; | ||
411 | 374 | | |||
412 | default: | 375 | default: | ||
413 | break; | 376 | break; | ||
414 | 377 | | |||
415 | } | 378 | } | ||
416 | 379 | | |||
417 | return false; | 380 | return false; | ||
418 | 381 | | |||
419 | } | 382 | } | ||
420 | 383 | | |||
421 | //_____________________________________________________________ | 384 | //_____________________________________________________________ | ||
422 | void WindowManager::timerEvent( QTimerEvent* event ) | 385 | void WindowManager::timerEvent( QTimerEvent* event ) | ||
423 | { | 386 | { | ||
424 | 387 | | |||
425 | if( event->timerId() == _dragTimer.timerId() ) | 388 | if( event->timerId() == _dragTimer.timerId() ) | ||
426 | { | 389 | { | ||
427 | 390 | | |||
428 | _dragTimer.stop(); | 391 | _dragTimer.stop(); | ||
429 | #if OXYGEN_USE_KDE4 | | |||
430 | if( _target ) | | |||
431 | { startDrag( _target.data()->window(), _globalDragPoint ); } | | |||
432 | #else | | |||
433 | if( _target ) | 392 | if( _target ) | ||
434 | { startDrag( _target.data()->window()->windowHandle(), _globalDragPoint ); } | 393 | { startDrag( _target.data()->window()->windowHandle(), _globalDragPoint ); } | ||
435 | else if( _quickTarget ) | 394 | else if( _quickTarget ) | ||
436 | { startDrag( _quickTarget.data()->window(), _globalDragPoint ); } | 395 | { startDrag( _quickTarget.data()->window(), _globalDragPoint ); } | ||
437 | #endif | | |||
438 | 396 | | |||
439 | 397 | | |||
440 | } else { | 398 | } else { | ||
441 | 399 | | |||
442 | return QObject::timerEvent( event ); | 400 | return QObject::timerEvent( event ); | ||
443 | 401 | | |||
444 | } | 402 | } | ||
445 | 403 | | |||
446 | } | 404 | } | ||
447 | 405 | | |||
448 | //_____________________________________________________________ | 406 | //_____________________________________________________________ | ||
449 | bool WindowManager::mousePressEvent( QObject* object, QEvent* event ) | 407 | bool WindowManager::mousePressEvent( QObject* object, QEvent* event ) | ||
450 | { | 408 | { | ||
451 | 409 | | |||
452 | // cast event and check buttons/modifiers | 410 | // cast event and check buttons/modifiers | ||
453 | QMouseEvent *mouseEvent = static_cast<QMouseEvent*>( event ); | 411 | QMouseEvent *mouseEvent = static_cast<QMouseEvent*>( event ); | ||
454 | if( !( mouseEvent->modifiers() == Qt::NoModifier && mouseEvent->button() == Qt::LeftButton ) ) | 412 | if( !( mouseEvent->modifiers() == Qt::NoModifier && mouseEvent->button() == Qt::LeftButton ) ) | ||
455 | { return false; } | 413 | { return false; } | ||
456 | #if !OXYGEN_USE_KDE4 | | |||
457 | if (mouseEvent->source() != Qt::MouseEventNotSynthesized) | 414 | if (mouseEvent->source() != Qt::MouseEventNotSynthesized) | ||
458 | { return false; } | 415 | { return false; } | ||
459 | #endif | | |||
460 | 416 | | |||
461 | // check lock | 417 | // check lock | ||
462 | if( isLocked() ) return false; | 418 | if( isLocked() ) return false; | ||
463 | else setLocked( true ); | 419 | else setLocked( true ); | ||
464 | 420 | | |||
465 | #if !OXYGEN_USE_KDE4 | | |||
466 | // check QQuickItem - we can immediately start drag, because QQuickWindow's contentItem | 421 | // check QQuickItem - we can immediately start drag, because QQuickWindow's contentItem | ||
467 | // only receives mouse events that weren't handled by children | 422 | // only receives mouse events that weren't handled by children | ||
468 | if ( QQuickItem *item = qobject_cast<QQuickItem*>( object ) ) { | 423 | if ( QQuickItem *item = qobject_cast<QQuickItem*>( object ) ) { | ||
469 | _quickTarget = item; | 424 | _quickTarget = item; | ||
470 | _dragPoint = mouseEvent->pos(); | 425 | _dragPoint = mouseEvent->pos(); | ||
471 | _globalDragPoint = mouseEvent->globalPos(); | 426 | _globalDragPoint = mouseEvent->globalPos(); | ||
472 | 427 | | |||
473 | if( _dragTimer.isActive() ) _dragTimer.stop(); | 428 | if( _dragTimer.isActive() ) _dragTimer.stop(); | ||
474 | _dragTimer.start( _dragDelay, this ); | 429 | _dragTimer.start( _dragDelay, this ); | ||
475 | 430 | | |||
476 | return true; | 431 | return true; | ||
477 | } | 432 | } | ||
478 | #endif | | |||
479 | 433 | | |||
480 | // cast to widget | 434 | // cast to widget | ||
481 | QWidget *widget = static_cast<QWidget*>( object ); | 435 | QWidget *widget = static_cast<QWidget*>( object ); | ||
482 | 436 | | |||
483 | // check if widget can be dragged from current position | 437 | // check if widget can be dragged from current position | ||
484 | if( isBlackListed( widget ) || !canDrag( widget ) ) return false; | 438 | if( isBlackListed( widget ) || !canDrag( widget ) ) return false; | ||
485 | 439 | | |||
486 | // retrieve widget's child at event position | 440 | // retrieve widget's child at event position | ||
Show All 22 Lines | |||||
509 | 463 | | |||
510 | //_____________________________________________________________ | 464 | //_____________________________________________________________ | ||
511 | bool WindowManager::mouseMoveEvent( QObject* object, QEvent* event ) | 465 | bool WindowManager::mouseMoveEvent( QObject* object, QEvent* event ) | ||
512 | { | 466 | { | ||
513 | 467 | | |||
514 | Q_UNUSED( object ); | 468 | Q_UNUSED( object ); | ||
515 | QMouseEvent *mouseEvent = static_cast<QMouseEvent*>( event ); | 469 | QMouseEvent *mouseEvent = static_cast<QMouseEvent*>( event ); | ||
516 | 470 | | |||
517 | #if !OXYGEN_USE_KDE4 | | |||
518 | if (mouseEvent->source() != Qt::MouseEventNotSynthesized) | 471 | if (mouseEvent->source() != Qt::MouseEventNotSynthesized) | ||
519 | { return false; } | 472 | { return false; } | ||
520 | #endif | | |||
521 | 473 | | |||
522 | // stop timer | 474 | // stop timer | ||
523 | if( _dragTimer.isActive() ) _dragTimer.stop(); | 475 | if( _dragTimer.isActive() ) _dragTimer.stop(); | ||
524 | 476 | | |||
525 | // cast event and check drag distance | 477 | // cast event and check drag distance | ||
526 | if( !_dragInProgress ) | 478 | if( !_dragInProgress ) | ||
527 | { | 479 | { | ||
528 | 480 | | |||
▲ Show 20 Lines • Show All 319 Lines • ▼ Show 20 Line(s) | 798 | { | |||
848 | if( (!useWMMoveResize() ) && _target && _cursorOverride ) { | 800 | if( (!useWMMoveResize() ) && _target && _cursorOverride ) { | ||
849 | 801 | | |||
850 | qApp->restoreOverrideCursor(); | 802 | qApp->restoreOverrideCursor(); | ||
851 | _cursorOverride = false; | 803 | _cursorOverride = false; | ||
852 | 804 | | |||
853 | } | 805 | } | ||
854 | 806 | | |||
855 | _target.clear(); | 807 | _target.clear(); | ||
856 | #if !OXYGEN_USE_KDE4 | | |||
857 | _quickTarget.clear(); | 808 | _quickTarget.clear(); | ||
858 | #endif | | |||
859 | if( _dragTimer.isActive() ) _dragTimer.stop(); | 809 | if( _dragTimer.isActive() ) _dragTimer.stop(); | ||
860 | _dragPoint = QPoint(); | 810 | _dragPoint = QPoint(); | ||
861 | _globalDragPoint = QPoint(); | 811 | _globalDragPoint = QPoint(); | ||
862 | _dragAboutToStart = false; | 812 | _dragAboutToStart = false; | ||
863 | _dragInProgress = false; | 813 | _dragInProgress = false; | ||
864 | 814 | | |||
865 | } | 815 | } | ||
866 | 816 | | |||
867 | //____________________________________________________________ | 817 | //____________________________________________________________ | ||
868 | void WindowManager::startDrag( Window* window, const QPoint& position ) | 818 | void WindowManager::startDrag( QWindow* window, const QPoint& position ) | ||
869 | { | 819 | { | ||
870 | 820 | | |||
871 | if( !( enabled() && window ) ) return; | 821 | if( !( enabled() && window ) ) return; | ||
872 | if( QWidget::mouseGrabber() ) return; | 822 | if( QWidget::mouseGrabber() ) return; | ||
873 | 823 | | |||
874 | // ungrab pointer | 824 | // ungrab pointer | ||
875 | if( useWMMoveResize() ) | 825 | if( useWMMoveResize() ) | ||
876 | { | 826 | { | ||
Show All 12 Lines | |||||
889 | 839 | | |||
890 | _dragInProgress = true; | 840 | _dragInProgress = true; | ||
891 | 841 | | |||
892 | return; | 842 | return; | ||
893 | 843 | | |||
894 | } | 844 | } | ||
895 | 845 | | |||
896 | //_______________________________________________________ | 846 | //_______________________________________________________ | ||
897 | void WindowManager::startDragX11( Window* window, const QPoint& position ) | 847 | void WindowManager::startDragX11( QWindow* window, const QPoint& position ) | ||
898 | { | 848 | { | ||
899 | #if OXYGEN_HAVE_X11 | 849 | #if OXYGEN_HAVE_X11 | ||
900 | // connection | 850 | // connection | ||
901 | xcb_connection_t* connection( Helper::connection() ); | 851 | xcb_connection_t* connection( Helper::connection() ); | ||
902 | 852 | | |||
903 | #if QT_VERSION >= 0x050300 | | |||
904 | const qreal dpiRatio = qApp->devicePixelRatio(); | 853 | const qreal dpiRatio = qApp->devicePixelRatio(); | ||
905 | #else | | |||
906 | const qreal dpiRatio = 1; | | |||
907 | #endif | | |||
908 | | ||||
909 | #if OXYGEN_USE_KDE4 | | |||
910 | Display* net_connection = QX11Info::display(); | | |||
911 | #else | | |||
912 | xcb_connection_t* net_connection = connection; | | |||
913 | #endif | | |||
914 | 854 | | |||
915 | xcb_ungrab_pointer( connection, XCB_TIME_CURRENT_TIME ); | 855 | xcb_ungrab_pointer( connection, XCB_TIME_CURRENT_TIME ); | ||
916 | NETRootInfo( net_connection, NET::WMMoveResize ).moveResizeRequest( | 856 | NETRootInfo( connection, NET::WMMoveResize ).moveResizeRequest( | ||
917 | window->winId(), position.x() * dpiRatio, | 857 | window->winId(), position.x() * dpiRatio, | ||
918 | position.y() * dpiRatio, | 858 | position.y() * dpiRatio, | ||
919 | NET::Move ); | 859 | NET::Move ); | ||
920 | 860 | | |||
921 | #else | 861 | #else | ||
922 | 862 | | |||
923 | Q_UNUSED( window ); | 863 | Q_UNUSED( window ); | ||
924 | Q_UNUSED( position ); | 864 | Q_UNUSED( position ); | ||
925 | 865 | | |||
926 | #endif | 866 | #endif | ||
927 | } | 867 | } | ||
928 | 868 | | |||
929 | //_______________________________________________________ | 869 | //_______________________________________________________ | ||
930 | void WindowManager::startDragWayland( Window* window, const QPoint& ) | 870 | void WindowManager::startDragWayland( QWindow* window, const QPoint& ) | ||
931 | { | 871 | { | ||
932 | #if OXYGEN_HAVE_KWAYLAND | 872 | #if OXYGEN_HAVE_KWAYLAND | ||
933 | if( !_seat ) { | 873 | if( !_seat ) { | ||
934 | return; | 874 | return; | ||
935 | } | 875 | } | ||
936 | 876 | | |||
937 | auto shellSurface = KWayland::Client::ShellSurface::fromWindow(window); | 877 | auto shellSurface = KWayland::Client::ShellSurface::fromWindow(window); | ||
938 | if( !shellSurface ) { | 878 | if( !shellSurface ) { | ||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |