Commit 6d83b045 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

[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.
parent 1e43c4da
......@@ -8,8 +8,9 @@ find_package(KF5 REQUIRED COMPONENTS
ConfigWidgets
WindowSystem)
find_package(Qt5 COMPONENTS Quick)
find_package(Qt5 COMPONENTS Quick X11Extras)
set(BREEZE_HAVE_QTQUICK ${Qt5Quick_FOUND})
set(BREEZE_HAVE_QTX11EXTRAS ${Qt5X11Extras_FOUND})
find_package( KF5FrameworkIntegration CONFIG )
set_package_properties(KF5FrameworkIntegration PROPERTIES
......@@ -20,26 +21,6 @@ set_package_properties(KF5FrameworkIntegration PROPERTIES
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 #################
include_directories(
......@@ -102,6 +83,9 @@ target_link_libraries(breeze Qt5::Core Qt5::Gui Qt5::Widgets Qt5::DBus)
if( BREEZE_HAVE_QTQUICK )
target_link_libraries(breeze Qt5::Quick)
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 breezecommon5)
......@@ -115,15 +99,6 @@ if (WIN32)
target_compile_definitions(breeze PRIVATE _USE_MATH_DEFINES _BSD_SOURCE)
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(TARGETS breeze DESTINATION ${QT_PLUGIN_INSTALL_DIR}/styles/)
......
......@@ -164,11 +164,6 @@
<default></default>
</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 -->
<entry name="SplitterProxyEnabled" type="Bool">
<default>true</default>
......
......@@ -15,7 +15,7 @@
#include <QApplication>
#include <QPainter>
#if BREEZE_HAVE_X11
#if BREEZE_HAVE_QTX11EXTRAS
#include <QX11Info>
#endif
......@@ -1563,7 +1563,7 @@ namespace Breeze
bool Helper::compositingActive() const
{
#if BREEZE_HAVE_X11
#if BREEZE_HAVE_QTX11EXTRAS
if( isX11() )
{ return QX11Info::isCompositingManagerRunning( QX11Info::appScreen() ); }
#endif
......
......@@ -47,22 +47,6 @@
#include <QQuickWindow>
#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
{
template<class T>
......@@ -115,7 +99,7 @@ namespace Breeze
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
*/
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 false;
......@@ -166,67 +150,12 @@ namespace Breeze
setEnabled( StyleConfigData::windowDragMode() != StyleConfigData::WD_NONE );
setDragMode( StyleConfigData::windowDragMode() );
setUseWMMoveResize( StyleConfigData::useWMMoveResize() );
setDragDistance( QApplication::startDragDistance() );
setDragDelay( QApplication::startDragTime() );
initializeWhiteList();
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();
if( _target ) startDrag( _target.data()->window()->windowHandle(), _globalDragPoint );
if( _target ) startDrag( _target.data()->window()->windowHandle() );
#if BREEZE_HAVE_QTQUICK
else if( _quickTarget ) startDrag( _quickTarget.data()->window(), _globalDragPoint );
else if( _quickTarget ) startDrag( _quickTarget.data()->window() );
#endif
} else {
......@@ -460,14 +389,6 @@ namespace Breeze
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;
}
......@@ -760,13 +681,6 @@ namespace Breeze
void WindowManager::resetDrag()
{
if( (!useWMMoveResize() ) && _target && _cursorOverride ) {
qApp->restoreOverrideCursor();
_cursorOverride = false;
}
_target.clear();
#if BREEZE_HAVE_QTQUICK
_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( QWidget::mouseGrabber() ) return;
// ungrab pointer
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
_dragInProgress = window->startSystemMove();
}
......
......@@ -24,17 +24,6 @@
#include <QQuickItem>
#endif
#if BREEZE_HAVE_KWAYLAND
namespace KWayland
{
namespace Client
{
class Pointer;
class Seat;
}
}
#endif
namespace Breeze
{
......@@ -92,14 +81,6 @@ namespace Breeze
void setEnabled( bool 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
int dragMode() const
{ return _dragMode; }
......@@ -130,12 +111,6 @@ namespace Breeze
*/
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
......@@ -158,17 +133,7 @@ namespace Breeze
void resetDrag();
//* start drag
void startDrag( QWindow*, const QPoint& );
//* 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;
void startDrag( QWindow* );
//* utility function
bool isDockWidgetTitle( const QWidget* ) const;
......@@ -193,9 +158,6 @@ namespace Breeze
//* enability
bool _enabled = true;
//* use WM moveResize
bool _useWMMoveResize = true;
//* drag mode
int _dragMode = StyleConfigData::WD_FULL;
......@@ -280,25 +242,9 @@ namespace Breeze
//* true if drag is locked
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
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
friend class AppEventFilter;
......
......@@ -12,12 +12,10 @@
/* Define to 1 if QtQuick is available */
#cmakedefine01 BREEZE_HAVE_QTQUICK
/* Define to 1 if QtX11Extras is available */
#cmakedefine01 BREEZE_HAVE_QTX11EXTRAS
/* Define to 1 if FrameworkIntegration/Kstyle libraries are found */
#cmakedefine01 BREEZE_HAVE_KSTYLE
/* Define to 1 if XCB libraries are found */
#cmakedefine01 BREEZE_HAVE_X11
#cmakedefine01 BREEZE_HAVE_KWAYLAND
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment