Changeset View
Changeset View
Standalone View
Standalone View
kstyle/oxygenwindowmanager.cpp
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | |||||
88 | #if OXYGEN_USE_KDE4 | 88 | #if OXYGEN_USE_KDE4 | ||
89 | #include <NETRootInfo> | 89 | #include <NETRootInfo> | ||
90 | #else | 90 | #else | ||
91 | #include <NETWM> | 91 | #include <NETWM> | ||
92 | #endif | 92 | #endif | ||
93 | 93 | | |||
94 | #endif | 94 | #endif | ||
95 | 95 | | |||
96 | #if OXYGEN_HAVE_KWAYLAND | ||||
97 | #include <KWayland/Client/connection_thread.h> | ||||
98 | #include <KWayland/Client/pointer.h> | ||||
99 | #include <KWayland/Client/registry.h> | ||||
100 | #include <KWayland/Client/shell.h> | ||||
101 | #include <KWayland/Client/seat.h> | ||||
102 | #endif | ||||
103 | | ||||
96 | namespace Oxygen | 104 | namespace Oxygen | ||
97 | { | 105 | { | ||
98 | 106 | | |||
99 | //* provide application-wise event filter | 107 | //* provide application-wise event filter | ||
100 | /** | 108 | /** | ||
101 | it us used to unlock dragging and make sure event look is properly restored | 109 | it us used to unlock dragging and make sure event look is properly restored | ||
102 | after a drag has occurred | 110 | after a drag has occurred | ||
103 | */ | 111 | */ | ||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Line(s) | 203 | WindowManager::WindowManager( QObject* parent ): | |||
198 | _useWMMoveResize( true ), | 206 | _useWMMoveResize( true ), | ||
199 | _dragMode( StyleConfigData::WD_FULL ), | 207 | _dragMode( StyleConfigData::WD_FULL ), | ||
200 | _dragDistance( QApplication::startDragDistance() ), | 208 | _dragDistance( QApplication::startDragDistance() ), | ||
201 | _dragDelay( QApplication::startDragTime() ), | 209 | _dragDelay( QApplication::startDragTime() ), | ||
202 | _dragAboutToStart( false ), | 210 | _dragAboutToStart( false ), | ||
203 | _dragInProgress( false ), | 211 | _dragInProgress( false ), | ||
204 | _locked( false ), | 212 | _locked( false ), | ||
205 | _cursorOverride( false ) | 213 | _cursorOverride( false ) | ||
214 | #if OXYGEN_HAVE_KWAYLAND | ||||
215 | , _seat( Q_NULLPTR ) | ||||
216 | , _pointer( Q_NULLPTR ) | ||||
217 | , _waylandSerial( 0 ) | ||||
218 | #endif | ||||
206 | { | 219 | { | ||
207 | 220 | | |||
208 | // install application wise event filter | 221 | // install application wise event filter | ||
209 | _appEventFilter = new AppEventFilter( this ); | 222 | _appEventFilter = new AppEventFilter( this ); | ||
210 | qApp->installEventFilter( _appEventFilter ); | 223 | qApp->installEventFilter( _appEventFilter ); | ||
211 | 224 | | |||
212 | } | 225 | } | ||
213 | 226 | | |||
214 | //_____________________________________________________________ | 227 | //_____________________________________________________________ | ||
215 | void WindowManager::initialize( void ) | 228 | void WindowManager::initialize( void ) | ||
216 | { | 229 | { | ||
217 | 230 | | |||
218 | setEnabled( StyleConfigData::windowDragMode() != StyleConfigData::WD_NONE ); | 231 | setEnabled( StyleConfigData::windowDragMode() != StyleConfigData::WD_NONE ); | ||
219 | setDragMode( StyleConfigData::windowDragMode() ); | 232 | setDragMode( StyleConfigData::windowDragMode() ); | ||
220 | setUseWMMoveResize( StyleConfigData::useWMMoveResize() ); | 233 | setUseWMMoveResize( StyleConfigData::useWMMoveResize() ); | ||
221 | 234 | | |||
222 | setDragDistance( QApplication::startDragDistance() ); | 235 | setDragDistance( QApplication::startDragDistance() ); | ||
223 | setDragDelay( QApplication::startDragTime() ); | 236 | setDragDelay( QApplication::startDragTime() ); | ||
224 | 237 | | |||
225 | initializeWhiteList(); | 238 | initializeWhiteList(); | ||
226 | initializeBlackList(); | 239 | initializeBlackList(); | ||
240 | initializeWayland(); | ||||
241 | | ||||
242 | } | ||||
243 | | ||||
244 | //_______________________________________________________ | ||||
245 | void WindowManager::initializeWayland() | ||||
246 | { | ||||
247 | #if OXYGEN_HAVE_KWAYLAND | ||||
248 | if( !Helper::isWayland() ) return; | ||||
227 | 249 | | |||
250 | if( _seat ) { | ||||
251 | // already initialized | ||||
252 | return; | ||||
253 | } | ||||
254 | | ||||
255 | using namespace KWayland::Client; | ||||
256 | auto connection = ConnectionThread::fromApplication( this ); | ||||
257 | if( !connection ) { | ||||
258 | return; | ||||
259 | } | ||||
260 | Registry *registry = new Registry( this ); | ||||
261 | registry->create( connection ); | ||||
262 | connect(registry, &Registry::interfacesAnnounced, this, | ||||
263 | [registry, this] { | ||||
264 | const auto interface = registry->interface( Registry::Interface::Seat ); | ||||
265 | if( interface.name != 0 ) { | ||||
266 | _seat = registry->createSeat( interface.name, interface.version, this ); | ||||
267 | connect(_seat, &Seat::hasPointerChanged, this, &WindowManager::waylandHasPointerChanged); | ||||
268 | } | ||||
269 | } | ||||
270 | ); | ||||
271 | | ||||
272 | registry->setup(); | ||||
273 | connection->roundtrip(); | ||||
274 | #endif | ||||
275 | } | ||||
276 | | ||||
277 | //_______________________________________________________ | ||||
278 | void WindowManager::waylandHasPointerChanged(bool hasPointer) | ||||
279 | { | ||||
280 | #if OXYGEN_HAVE_KWAYLAND | ||||
281 | Q_ASSERT( _seat ); | ||||
282 | if( hasPointer ) { | ||||
283 | if( !_pointer ) { | ||||
284 | _pointer = _seat->createPointer(this); | ||||
285 | connect(_pointer, &KWayland::Client::Pointer::buttonStateChanged, this, | ||||
286 | [this] (quint32 serial) { | ||||
287 | _waylandSerial = serial; | ||||
288 | } | ||||
289 | ); | ||||
290 | } | ||||
291 | } else { | ||||
292 | delete _pointer; | ||||
293 | _pointer = nullptr; | ||||
294 | } | ||||
295 | #endif | ||||
228 | } | 296 | } | ||
229 | 297 | | |||
230 | //_____________________________________________________________ | 298 | //_____________________________________________________________ | ||
231 | void WindowManager::registerWidget( QWidget* widget ) | 299 | void WindowManager::registerWidget( QWidget* widget ) | ||
232 | { | 300 | { | ||
233 | 301 | | |||
234 | if( isBlackListed( widget ) || isDragable( widget ) ) | 302 | if( isBlackListed( widget ) || isDragable( widget ) ) | ||
235 | { | 303 | { | ||
▲ Show 20 Lines • Show All 304 Lines • ▼ Show 20 Line(s) | 600 | { | |||
540 | 608 | | |||
541 | return false; | 609 | return false; | ||
542 | } | 610 | } | ||
543 | 611 | | |||
544 | //_____________________________________________________________ | 612 | //_____________________________________________________________ | ||
545 | bool WindowManager::canDrag( QWidget* widget ) | 613 | bool WindowManager::canDrag( QWidget* widget ) | ||
546 | { | 614 | { | ||
547 | 615 | | |||
548 | // do not start drag on Wayland, this is not yet supported | | |||
549 | // To implement integration with KWayland is required | | |||
550 | // and QtWayland must support getting the wl_seat. | | |||
551 | // Other option would be adding support to Qt for starting a move | | |||
552 | if( Helper::isWayland() ) return false; | | |||
553 | | ||||
554 | // check if enabled | 616 | // check if enabled | ||
555 | if( !enabled() ) return false; | 617 | if( !enabled() ) return false; | ||
556 | 618 | | |||
557 | // assume isDragable widget is already passed | 619 | // assume isDragable widget is already passed | ||
558 | // check some special cases where drag should not be effective | 620 | // check some special cases where drag should not be effective | ||
559 | 621 | | |||
560 | // check mouse grabber | 622 | // check mouse grabber | ||
561 | if( QWidget::mouseGrabber() ) return false; | 623 | if( QWidget::mouseGrabber() ) return false; | ||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Line(s) | |||||
740 | { | 802 | { | ||
741 | 803 | | |||
742 | if( !( enabled() && widget ) ) return; | 804 | if( !( enabled() && widget ) ) return; | ||
743 | if( QWidget::mouseGrabber() ) return; | 805 | if( QWidget::mouseGrabber() ) return; | ||
744 | 806 | | |||
745 | // ungrab pointer | 807 | // ungrab pointer | ||
746 | if( useWMMoveResize() ) | 808 | if( useWMMoveResize() ) | ||
747 | { | 809 | { | ||
810 | if( Helper::isX11() ) { | ||||
811 | startDragX11( widget, position ); | ||||
812 | } else if( Helper::isWayland() ) { | ||||
813 | startDragWayland( widget, position ); | ||||
814 | } | ||||
815 | | ||||
816 | } else if( !_cursorOverride ) { | ||||
817 | | ||||
818 | qApp->setOverrideCursor( Qt::SizeAllCursor ); | ||||
819 | _cursorOverride = true; | ||||
820 | | ||||
821 | } | ||||
822 | | ||||
823 | _dragInProgress = true; | ||||
824 | | ||||
825 | return; | ||||
748 | 826 | | |||
827 | } | ||||
828 | | ||||
829 | //_______________________________________________________ | ||||
830 | void WindowManager::startDragX11( QWidget* widget, const QPoint& position ) | ||||
831 | { | ||||
749 | #if OXYGEN_HAVE_X11 | 832 | #if OXYGEN_HAVE_X11 | ||
750 | // connection | 833 | // connection | ||
751 | xcb_connection_t* connection( Helper::connection() ); | 834 | xcb_connection_t* connection( Helper::connection() ); | ||
752 | 835 | | |||
753 | // window | 836 | // window | ||
754 | const WId window( widget->window()->winId() ); | 837 | const WId window( widget->window()->winId() ); | ||
755 | 838 | | |||
756 | #if QT_VERSION >= 0x050300 | 839 | #if QT_VERSION >= 0x050300 | ||
Show All 15 Lines | |||||
772 | xcb_ungrab_pointer( connection, XCB_TIME_CURRENT_TIME ); | 855 | xcb_ungrab_pointer( connection, XCB_TIME_CURRENT_TIME ); | ||
773 | NETRootInfo( net_connection, NET::WMMoveResize ).moveResizeRequest( | 856 | NETRootInfo( net_connection, NET::WMMoveResize ).moveResizeRequest( | ||
774 | window, position.x() * dpiRatio, | 857 | window, position.x() * dpiRatio, | ||
775 | position.y() * dpiRatio, | 858 | position.y() * dpiRatio, | ||
776 | NET::Move ); | 859 | NET::Move ); | ||
777 | 860 | | |||
778 | #else | 861 | #else | ||
779 | 862 | | |||
863 | Q_UNUSED( widget ); | ||||
780 | Q_UNUSED( position ); | 864 | Q_UNUSED( position ); | ||
781 | 865 | | |||
782 | #endif | 866 | #endif | ||
867 | } | ||||
783 | 868 | | |||
784 | } else if( !_cursorOverride ) { | 869 | //_______________________________________________________ | ||
785 | 870 | void WindowManager::startDragWayland( QWidget* widget, const QPoint& position ) | |||
786 | qApp->setOverrideCursor( Qt::SizeAllCursor ); | 871 | { | ||
787 | _cursorOverride = true; | 872 | #if OXYGEN_HAVE_KWAYLAND | ||
873 | if( !_seat ) { | ||||
874 | return; | ||||
875 | } | ||||
788 | 876 | | |||
877 | QWindow* windowHandle = widget->window()->windowHandle(); | ||||
878 | auto shellSurface = KWayland::Client::ShellSurface::fromWindow(windowHandle); | ||||
879 | if( !shellSurface ) { | ||||
880 | // TODO: also check for xdg-shell in future | ||||
881 | return; | ||||
789 | } | 882 | } | ||
790 | 883 | | |||
791 | _dragInProgress = true; | 884 | shellSurface->requestMove( _seat, _waylandSerial ); | ||
885 | #else | ||||
792 | 886 | | |||
793 | return; | 887 | Q_UNUSED( widget ); | ||
888 | Q_UNUSED( position ); | ||||
794 | 889 | | |||
890 | #endif | ||||
795 | } | 891 | } | ||
796 | 892 | | |||
797 | //____________________________________________________________ | 893 | //____________________________________________________________ | ||
798 | bool WindowManager::supportWMMoveResize( void ) const | 894 | bool WindowManager::supportWMMoveResize( void ) const | ||
799 | { | 895 | { | ||
896 | #if OXYGEN_HAVE_KWAYLAND | ||||
897 | if( Helper::isWayland() ) { | ||||
898 | return true; | ||||
899 | } | ||||
900 | #endif | ||||
800 | 901 | | |||
801 | #if OXYGEN_HAVE_X11 | 902 | #if OXYGEN_HAVE_X11 | ||
802 | return Helper::isX11(); | 903 | return Helper::isX11(); | ||
803 | #else | 904 | #else | ||
804 | return false; | 905 | return false; | ||
805 | #endif | 906 | #endif | ||
806 | 907 | | |||
807 | } | 908 | } | ||
Show All 16 Lines |