[kstyle] Port to QWindow::startSystemMove()

QWindow::startSystemMove() is a new feature in Qt 5.15 that provides a
platform-independent way to start an interactive move operation.
wilder-portage
Vlad Zahorodnii 6 years ago
parent 1e43c4da25
commit 6d83b04544
  1. 35
      kstyle/CMakeLists.txt
  2. 5
      kstyle/breeze.kcfg
  3. 4
      kstyle/breezehelper.cpp
  4. 174
      kstyle/breezewindowmanager.cpp
  5. 56
      kstyle/breezewindowmanager.h
  6. 8
      kstyle/config-breeze.h.cmake

@ -8,8 +8,9 @@ find_package(KF5 REQUIRED COMPONENTS
ConfigWidgets ConfigWidgets
WindowSystem) WindowSystem)
find_package(Qt5 COMPONENTS Quick) find_package(Qt5 COMPONENTS Quick X11Extras)
set(BREEZE_HAVE_QTQUICK ${Qt5Quick_FOUND}) set(BREEZE_HAVE_QTQUICK ${Qt5Quick_FOUND})
set(BREEZE_HAVE_QTX11EXTRAS ${Qt5X11Extras_FOUND})
find_package( KF5FrameworkIntegration CONFIG ) find_package( KF5FrameworkIntegration CONFIG )
set_package_properties(KF5FrameworkIntegration PROPERTIES set_package_properties(KF5FrameworkIntegration PROPERTIES
@ -20,26 +21,6 @@ set_package_properties(KF5FrameworkIntegration PROPERTIES
set(BREEZE_HAVE_KSTYLE ${KF5FrameworkIntegration_FOUND}) set(BREEZE_HAVE_KSTYLE ${KF5FrameworkIntegration_FOUND})
find_package(XCB COMPONENTS XCB)
set_package_properties(XCB PROPERTIES
DESCRIPTION "X protocol C-language Binding"
URL "https://xcb.freedesktop.org"
TYPE OPTIONAL
PURPOSE "Required to pass style properties to native Windows on X11 Platform"
)
find_package(KF5Wayland CONFIG)
set(BREEZE_HAVE_KWAYLAND ${KF5Wayland_FOUND})
if(UNIX AND NOT APPLE)
set(BREEZE_HAVE_X11 ${XCB_XCB_FOUND})
if (XCB_XCB_FOUND)
find_package(Qt5 REQUIRED CONFIG COMPONENTS X11Extras)
endif()
else()
set(BREEZE_HAVE_X11 FALSE)
endif()
################# includes ################# ################# includes #################
include_directories( include_directories(
@ -102,6 +83,9 @@ target_link_libraries(breeze Qt5::Core Qt5::Gui Qt5::Widgets Qt5::DBus)
if( BREEZE_HAVE_QTQUICK ) if( BREEZE_HAVE_QTQUICK )
target_link_libraries(breeze Qt5::Quick) target_link_libraries(breeze Qt5::Quick)
endif() endif()
if (BREEZE_HAVE_QTX11EXTRAS)
target_link_libraries(breeze Qt5::X11Extras)
endif()
target_link_libraries(breeze KF5::ConfigCore KF5::ConfigWidgets KF5::GuiAddons KF5::IconThemes KF5::WindowSystem) target_link_libraries(breeze KF5::ConfigCore KF5::ConfigWidgets KF5::GuiAddons KF5::IconThemes KF5::WindowSystem)
target_link_libraries(breeze breezecommon5) target_link_libraries(breeze breezecommon5)
@ -115,15 +99,6 @@ if (WIN32)
target_compile_definitions(breeze PRIVATE _USE_MATH_DEFINES _BSD_SOURCE) target_compile_definitions(breeze PRIVATE _USE_MATH_DEFINES _BSD_SOURCE)
endif() endif()
if(BREEZE_HAVE_X11)
target_link_libraries(breeze ${XCB_LIBRARIES})
target_link_libraries(breeze Qt5::X11Extras)
endif()
if(BREEZE_HAVE_KWAYLAND)
target_link_libraries(breeze KF5::WaylandClient)
endif()
########### install files ############### ########### install files ###############
install(TARGETS breeze DESTINATION ${QT_PLUGIN_INSTALL_DIR}/styles/) install(TARGETS breeze DESTINATION ${QT_PLUGIN_INSTALL_DIR}/styles/)

@ -164,11 +164,6 @@
<default></default> <default></default>
</entry> </entry>
<!-- if true, move events are passed to the window manager (e.g. KWin) -->
<entry name="UseWMMoveResize" type="Bool">
<default>true</default>
</entry>
<!-- splitter proxy --> <!-- splitter proxy -->
<entry name="SplitterProxyEnabled" type="Bool"> <entry name="SplitterProxyEnabled" type="Bool">
<default>true</default> <default>true</default>

@ -15,7 +15,7 @@
#include <QApplication> #include <QApplication>
#include <QPainter> #include <QPainter>
#if BREEZE_HAVE_X11 #if BREEZE_HAVE_QTX11EXTRAS
#include <QX11Info> #include <QX11Info>
#endif #endif
@ -1563,7 +1563,7 @@ namespace Breeze
bool Helper::compositingActive() const bool Helper::compositingActive() const
{ {
#if BREEZE_HAVE_X11 #if BREEZE_HAVE_QTX11EXTRAS
if( isX11() ) if( isX11() )
{ return QX11Info::isCompositingManagerRunning( QX11Info::appScreen() ); } { return QX11Info::isCompositingManagerRunning( QX11Info::appScreen() ); }
#endif #endif

@ -47,22 +47,6 @@
#include <QQuickWindow> #include <QQuickWindow>
#endif #endif
#if BREEZE_HAVE_X11
#include <QX11Info>
#include <xcb/xcb.h>
#include <NETWM>
#endif
#if BREEZE_HAVE_KWAYLAND
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/pointer.h>
#include <KWayland/Client/registry.h>
#include <KWayland/Client/shell.h>
#include <KWayland/Client/seat.h>
#endif
namespace Util namespace Util
{ {
template<class T> template<class T>
@ -115,7 +99,7 @@ namespace Breeze
we trigger on the first MouseMove or MousePress events that are received we trigger on the first MouseMove or MousePress events that are received
by any widget in the application to detect that the drag is finished by any widget in the application to detect that the drag is finished
*/ */
if( _parent->useWMMoveResize() && _parent->_dragInProgress && _parent->_target && ( event->type() == QEvent::MouseMove || event->type() == QEvent::MouseButtonPress ) ) if( _parent->_dragInProgress && _parent->_target && ( event->type() == QEvent::MouseMove || event->type() == QEvent::MouseButtonPress ) )
{ return appMouseEvent( object, event ); } { return appMouseEvent( object, event ); }
return false; return false;
@ -166,67 +150,12 @@ namespace Breeze
setEnabled( StyleConfigData::windowDragMode() != StyleConfigData::WD_NONE ); setEnabled( StyleConfigData::windowDragMode() != StyleConfigData::WD_NONE );
setDragMode( StyleConfigData::windowDragMode() ); setDragMode( StyleConfigData::windowDragMode() );
setUseWMMoveResize( StyleConfigData::useWMMoveResize() );
setDragDistance( QApplication::startDragDistance() ); setDragDistance( QApplication::startDragDistance() );
setDragDelay( QApplication::startDragTime() ); setDragDelay( QApplication::startDragTime() );
initializeWhiteList(); initializeWhiteList();
initializeBlackList(); initializeBlackList();
initializeWayland();
}
//_______________________________________________________
void WindowManager::initializeWayland()
{
#if BREEZE_HAVE_KWAYLAND
if( !Helper::isWayland() ) return;
if( _seat ) return;
using namespace KWayland::Client;
auto connection = ConnectionThread::fromApplication( this );
if( !connection ) return;
auto registry = new Registry( this );
registry->create( connection );
connect(registry, &Registry::interfacesAnnounced, this,
[registry, this] {
const auto interface = registry->interface( Registry::Interface::Seat );
if( interface.name != 0 )
{
_seat = registry->createSeat( interface.name, interface.version, this );
connect(_seat, &Seat::hasPointerChanged, this, &WindowManager::waylandHasPointerChanged);
}
}
);
registry->setup();
connection->roundtrip();
#endif
}
//_______________________________________________________
void WindowManager::waylandHasPointerChanged(bool hasPointer)
{
#if BREEZE_HAVE_KWAYLAND
Q_ASSERT( _seat );
if( hasPointer )
{
if( !_pointer )
{
_pointer = _seat->createPointer(this);
connect(_pointer, &KWayland::Client::Pointer::buttonStateChanged, this,
[this] (quint32 serial) { _waylandSerial = serial; }
);
}
} else {
delete _pointer;
_pointer = nullptr;
}
#else
Q_UNUSED( hasPointer );
#endif
} }
//_____________________________________________________________ //_____________________________________________________________
@ -351,9 +280,9 @@ namespace Breeze
{ {
_dragTimer.stop(); _dragTimer.stop();
if( _target ) startDrag( _target.data()->window()->windowHandle(), _globalDragPoint ); if( _target ) startDrag( _target.data()->window()->windowHandle() );
#if BREEZE_HAVE_QTQUICK #if BREEZE_HAVE_QTQUICK
else if( _quickTarget ) startDrag( _quickTarget.data()->window(), _globalDragPoint ); else if( _quickTarget ) startDrag( _quickTarget.data()->window() );
#endif #endif
} else { } else {
@ -460,14 +389,6 @@ namespace Breeze
return true; return true;
} else if( !useWMMoveResize() && _target ) {
// use QWidget::move for the grabbing
/* this works only if the sending object and the target are identical */
auto window( _target.data()->window() );
window->move( window->pos() + mouseEvent->pos() - _dragPoint );
return true;
} else return false; } else return false;
} }
@ -760,13 +681,6 @@ namespace Breeze
void WindowManager::resetDrag() void WindowManager::resetDrag()
{ {
if( (!useWMMoveResize() ) && _target && _cursorOverride ) {
qApp->restoreOverrideCursor();
_cursorOverride = false;
}
_target.clear(); _target.clear();
#if BREEZE_HAVE_QTQUICK #if BREEZE_HAVE_QTQUICK
_quickTarget.clear(); _quickTarget.clear();
@ -780,91 +694,13 @@ namespace Breeze
} }
//____________________________________________________________ //____________________________________________________________
void WindowManager::startDrag( QWindow* window, const QPoint& position ) void WindowManager::startDrag( QWindow* window )
{ {
if( !( enabled() && window ) ) return; if( !( enabled() && window ) ) return;
if( QWidget::mouseGrabber() ) return; if( QWidget::mouseGrabber() ) return;
// ungrab pointer _dragInProgress = window->startSystemMove();
if( useWMMoveResize() )
{
if( Helper::isX11() ) startDragX11( window, position );
else if( Helper::isWayland() ) startDragWayland( window, position );
} else if( !_cursorOverride ) {
qApp->setOverrideCursor( Qt::SizeAllCursor );
_cursorOverride = true;
}
_dragInProgress = true;
}
//_______________________________________________________
void WindowManager::startDragX11( QWindow* window, const QPoint& position )
{
#if BREEZE_HAVE_X11
// connection
auto connection( QX11Info::connection() );
auto net_connection = connection;
const qreal dpiRatio = window->devicePixelRatio();
const QPoint origin = window->screen()->geometry().topLeft();
const QPoint native = (position - origin) * dpiRatio + origin;
xcb_ungrab_pointer( connection, XCB_TIME_CURRENT_TIME );
NETRootInfo( net_connection, NET::WMMoveResize ).moveResizeRequest(
window->winId(), native.x(), native.y(), NET::Move );
#else
Q_UNUSED( window );
Q_UNUSED( position );
#endif
}
//_______________________________________________________
void WindowManager::startDragWayland( QWindow* window, const QPoint& )
{
#if BREEZE_HAVE_KWAYLAND
if( !_seat ) {
return;
}
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( window );
#endif
}
//____________________________________________________________
bool WindowManager::supportWMMoveResize() const
{
#if BREEZE_HAVE_KWAYLAND
if( Helper::isWayland() )
{
return true;
}
#endif
#if BREEZE_HAVE_X11
return Helper::isX11();
#else
return false;
#endif
} }

@ -24,17 +24,6 @@
#include <QQuickItem> #include <QQuickItem>
#endif #endif
#if BREEZE_HAVE_KWAYLAND
namespace KWayland
{
namespace Client
{
class Pointer;
class Seat;
}
}
#endif
namespace Breeze namespace Breeze
{ {
@ -92,14 +81,6 @@ namespace Breeze
void setEnabled( bool value ) void setEnabled( bool value )
{ _enabled = value; } { _enabled = value; }
//* returns true if window manager is used for moving
bool useWMMoveResize() const
{ return supportWMMoveResize() && _useWMMoveResize; }
//* use window manager for moving, when available
void setUseWMMoveResize( bool value )
{ _useWMMoveResize = value; }
//* drag mode //* drag mode
int dragMode() const int dragMode() const
{ return _dragMode; } { return _dragMode; }
@ -130,12 +111,6 @@ namespace Breeze
*/ */
void initializeBlackList(); void initializeBlackList();
//* initializes the Wayland specific parts
void initializeWayland();
//* The Wayland Seat's hasPointer property changed
void waylandHasPointerChanged(bool hasPointer);
//@} //@}
//* returns true if widget is dragable //* returns true if widget is dragable
@ -158,17 +133,7 @@ namespace Breeze
void resetDrag(); void resetDrag();
//* start drag //* start drag
void startDrag( QWindow*, const QPoint& ); void startDrag( QWindow* );
//* X11 specific implementation for startDrag
void startDragX11( QWindow*, const QPoint& );
//* Wayland specific implementation for startDrag
void startDragWayland( QWindow*, const QPoint& );
//* returns true if window manager is used for moving
/** right now this is true only for X11 */
bool supportWMMoveResize() const;
//* utility function //* utility function
bool isDockWidgetTitle( const QWidget* ) const; bool isDockWidgetTitle( const QWidget* ) const;
@ -193,9 +158,6 @@ namespace Breeze
//* enability //* enability
bool _enabled = true; bool _enabled = true;
//* use WM moveResize
bool _useWMMoveResize = true;
//* drag mode //* drag mode
int _dragMode = StyleConfigData::WD_FULL; int _dragMode = StyleConfigData::WD_FULL;
@ -280,25 +242,9 @@ namespace Breeze
//* true if drag is locked //* true if drag is locked
bool _locked = false; bool _locked = false;
//* cursor override
/** used to keep track of application cursor being overridden when dragging in non-WM mode */
bool _cursorOverride = false;
//* application event filter //* application event filter
QObject* _appEventFilter = nullptr; QObject* _appEventFilter = nullptr;
#if BREEZE_HAVE_KWAYLAND
//* The Wayland seat object which needs to be passed to move requests.
KWayland::Client::Seat* _seat = nullptr;
//* The Wayland pointer object where we get pointer events on.
KWayland::Client::Pointer* _pointer = nullptr;
//* latest serial which needs to be passed to the move requests.
quint32 _waylandSerial = 0;
#endif
//* allow access of all private members to the app event filter //* allow access of all private members to the app event filter
friend class AppEventFilter; friend class AppEventFilter;

@ -12,12 +12,10 @@
/* Define to 1 if QtQuick is available */ /* Define to 1 if QtQuick is available */
#cmakedefine01 BREEZE_HAVE_QTQUICK #cmakedefine01 BREEZE_HAVE_QTQUICK
/* Define to 1 if QtX11Extras is available */
#cmakedefine01 BREEZE_HAVE_QTX11EXTRAS
/* Define to 1 if FrameworkIntegration/Kstyle libraries are found */ /* Define to 1 if FrameworkIntegration/Kstyle libraries are found */
#cmakedefine01 BREEZE_HAVE_KSTYLE #cmakedefine01 BREEZE_HAVE_KSTYLE
/* Define to 1 if XCB libraries are found */
#cmakedefine01 BREEZE_HAVE_X11
#cmakedefine01 BREEZE_HAVE_KWAYLAND
#endif #endif

Loading…
Cancel
Save