@ -93,6 +93,14 @@
# endif
# 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 Breeze
namespace Breeze
{
{
@ -203,6 +211,11 @@ namespace Breeze
_dragInProgress ( false ) ,
_dragInProgress ( false ) ,
_locked ( false ) ,
_locked ( false ) ,
_cursorOverride ( false )
_cursorOverride ( false )
# if BREEZE_HAVE_KWAYLAND
, _seat ( Q_NULLPTR )
, _pointer ( Q_NULLPTR )
, _waylandSerial ( 0 )
# endif
{
{
// install application wise event filter
// install application wise event filter
@ -224,7 +237,62 @@ namespace Breeze
initializeWhiteList ( ) ;
initializeWhiteList ( ) ;
initializeBlackList ( ) ;
initializeBlackList ( ) ;
initializeWayland ( ) ;
}
//_______________________________________________________
void WindowManager : : initializeWayland ( )
{
# if BREEZE_HAVE_KWAYLAND
if ( ! Helper : : isWayland ( ) ) return ;
if ( _seat ) {
// already initialized
return ;
}
using namespace KWayland : : Client ;
auto connection = ConnectionThread : : fromApplication ( this ) ;
if ( ! connection ) {
return ;
}
Registry * 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 ;
}
# endif
}
}
//_____________________________________________________________
//_____________________________________________________________
@ -570,12 +638,6 @@ namespace Breeze
bool WindowManager : : canDrag ( QWidget * widget , QWidget * child , const QPoint & position )
bool WindowManager : : canDrag ( QWidget * widget , QWidget * child , const QPoint & position )
{
{
// do not start drag on Wayland, this is not yet supported
// To implement integration with KWayland is required
// and QtWayland must support getting the wl_seat.
// Other option would be adding support to Qt for starting a move
if ( Helper : : isWayland ( ) ) return false ;
// retrieve child at given position and check cursor again
// retrieve child at given position and check cursor again
if ( child & & child - > cursor ( ) . shape ( ) ! = Qt : : ArrowCursor ) return false ;
if ( child & & child - > cursor ( ) . shape ( ) ! = Qt : : ArrowCursor ) return false ;
@ -746,58 +808,94 @@ namespace Breeze
if ( useWMMoveResize ( ) )
if ( useWMMoveResize ( ) )
{
{
# if BREEZE_HAVE_X11
if ( Helper : : isX11 ( ) ) {
// connection
startDragX11 ( widget , position ) ;
xcb_connection_t * connection ( Helper : : connection ( ) ) ;
} else if ( Helper : : isWayland ( ) ) {
startDragWayland ( widget , position ) ;
}
// window
} else if ( ! _cursorOverride ) {
const WId window ( widget - > window ( ) - > winId ( ) ) ;
# if QT_VERSION >= 0x050300
qApp - > setOverrideCursor ( Qt : : SizeAllCursor ) ;
qreal dpiRatio = 1 ;
_cursorOverride = true ;
QWindow * windowHandle = widget - > window ( ) - > windowHandle ( ) ;
if ( windowHandle ) dpiRatio = windowHandle - > devicePixelRatio ( ) ;
else dpiRatio = qApp - > devicePixelRatio ( ) ;
dpiRatio = qApp - > devicePixelRatio ( ) ;
# else
const qreal dpiRatio = 1 ;
# endif
# if BREEZE_USE_KDE4
}
Display * net_connection = QX11Info : : display ( ) ;
# else
xcb_connection_t * net_connection = connection ;
# endif
xcb_ungrab_pointer ( connection , XCB_TIME_CURRENT_TIME ) ;
_dragInProgress = true ;
NETRootInfo ( net_connection , NET : : WMMoveResize ) . moveResizeRequest (
window , position . x ( ) * dpiRatio ,
position . y ( ) * dpiRatio ,
NET : : Move ) ;
# else
return ;
Q_UNUSED ( position ) ;
}
# endif
//_______________________________________________________
void WindowManager : : startDragX11 ( QWidget * widget , 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 ( ) ;
# else
const qreal dpiRatio = 1 ;
# endif
} else if ( ! _cursorOverride ) {
# if BREEZE_USE_KDE4
Display * net_connection = QX11Info : : display ( ) ;
# else
xcb_connection_t * net_connection = connection ;
# endif
qApp - > setOverrideCursor ( Qt : : SizeAllCursor ) ;
xcb_ungrab_pointer ( connection , XCB_TIME_CURRENT_TIME ) ;
_cursorOverride = true ;
NETRootInfo ( net_connection , NET : : WMMoveResize ) . moveResizeRequest (
window , position . x ( ) * dpiRatio ,
position . y ( ) * dpiRatio ,
NET : : Move ) ;
}
# else
_dragInProgress = true ;
Q_UNUSED ( widget ) ;
Q_UNUSED ( position ) ;
return ;
# endif
}
//_______________________________________________________
void WindowManager : : startDragWayland ( QWidget * widget , const QPoint & position )
{
# if BREEZE_HAVE_KWAYLAND
if ( ! _seat ) {
return ;
}
QWindow * windowHandle = widget - > window ( ) - > windowHandle ( ) ;
auto shellSurface = KWayland : : Client : : ShellSurface : : fromWindow ( windowHandle ) ;
if ( ! shellSurface ) {
// TODO: also check for xdg-shell in future
return ;
}
shellSurface - > requestMove ( _seat , _waylandSerial ) ;
# endif
}
}
//____________________________________________________________
//____________________________________________________________
bool WindowManager : : supportWMMoveResize ( void ) const
bool WindowManager : : supportWMMoveResize ( void ) const
{
{
# if BREEZE_HAVE_KWAYLAND
if ( Helper : : isWayland ( ) ) {
return true ;
}
# endif
# if BREEZE_HAVE_X11
# if BREEZE_HAVE_X11
return Helper : : isX11 ( ) ;
return Helper : : isX11 ( ) ;
# else
# else