Client: Use a QWaylandSurface for pointer focus
Task-number: QTBUG-74373 Change-Id: Idfd94442ff542b81956d4852e07eb3b5dff80712 Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
This commit is contained in:
parent
5d1b75d9c1
commit
4b40d01819
@ -47,6 +47,7 @@
|
|||||||
#include "qwaylandinputdevice_p.h"
|
#include "qwaylandinputdevice_p.h"
|
||||||
#include "qwaylanddisplay_p.h"
|
#include "qwaylanddisplay_p.h"
|
||||||
#include "qwaylandabstractdecoration_p.h"
|
#include "qwaylandabstractdecoration_p.h"
|
||||||
|
#include "qwaylandsurface_p.h"
|
||||||
|
|
||||||
#include <QtCore/QMimeData>
|
#include <QtCore/QMimeData>
|
||||||
#include <QtGui/QGuiApplication>
|
#include <QtGui/QGuiApplication>
|
||||||
@ -107,9 +108,10 @@ void QWaylandDataDevice::startDrag(QMimeData *mimeData, QWaylandWindow *icon)
|
|||||||
m_dragSource.reset(new QWaylandDataSource(m_display->dndSelectionHandler(), mimeData));
|
m_dragSource.reset(new QWaylandDataSource(m_display->dndSelectionHandler(), mimeData));
|
||||||
connect(m_dragSource.data(), &QWaylandDataSource::cancelled, this, &QWaylandDataDevice::dragSourceCancelled);
|
connect(m_dragSource.data(), &QWaylandDataSource::cancelled, this, &QWaylandDataDevice::dragSourceCancelled);
|
||||||
|
|
||||||
QWaylandWindow *origin = m_display->currentInputDevice()->pointerFocus();
|
auto *seat = m_display->currentInputDevice();
|
||||||
|
auto *origin = seat->pointerFocus();
|
||||||
if (!origin)
|
if (!origin)
|
||||||
origin = m_display->currentInputDevice()->touchFocus();
|
origin = seat->touchFocus();
|
||||||
|
|
||||||
start_drag(m_dragSource->object(), origin->wlSurface(), icon->wlSurface(), m_display->currentInputDevice()->serial());
|
start_drag(m_dragSource->object(), origin->wlSurface(), icon->wlSurface(), m_display->currentInputDevice()->serial());
|
||||||
}
|
}
|
||||||
|
@ -189,6 +189,11 @@ QWaylandInputDevice::Pointer::~Pointer()
|
|||||||
wl_pointer_destroy(object());
|
wl_pointer_destroy(object());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWaylandWindow *QWaylandInputDevice::Pointer::focusWindow() const
|
||||||
|
{
|
||||||
|
return mFocus ? mFocus->waylandWindow() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
#if QT_CONFIG(cursor)
|
#if QT_CONFIG(cursor)
|
||||||
|
|
||||||
class WlCallback : public QtWayland::wl_callback {
|
class WlCallback : public QtWayland::wl_callback {
|
||||||
@ -498,7 +503,7 @@ void QWaylandInputDevice::removeMouseButtonFromState(Qt::MouseButton button)
|
|||||||
|
|
||||||
QWaylandWindow *QWaylandInputDevice::pointerFocus() const
|
QWaylandWindow *QWaylandInputDevice::pointerFocus() const
|
||||||
{
|
{
|
||||||
return mPointer ? mPointer->mFocus : nullptr;
|
return mPointer ? mPointer->focusWindow() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWaylandWindow *QWaylandInputDevice::keyboardFocus() const
|
QWaylandWindow *QWaylandInputDevice::keyboardFocus() const
|
||||||
@ -596,8 +601,8 @@ void QWaylandInputDevice::Pointer::pointer_enter(uint32_t serial, struct wl_surf
|
|||||||
<< "attempting to work around it by invalidating the current focus";
|
<< "attempting to work around it by invalidating the current focus";
|
||||||
invalidateFocus();
|
invalidateFocus();
|
||||||
}
|
}
|
||||||
mFocus = window;
|
mFocus = window->waylandSurface();
|
||||||
connect(mFocus, &QWaylandWindow::wlSurfaceDestroyed, this, &Pointer::handleFocusDestroyed);
|
connect(mFocus, &QObject::destroyed, this, &Pointer::handleFocusDestroyed);
|
||||||
|
|
||||||
mSurfacePos = QPointF(wl_fixed_to_double(sx), wl_fixed_to_double(sy));
|
mSurfacePos = QPointF(wl_fixed_to_double(sx), wl_fixed_to_double(sy));
|
||||||
mGlobalPos = window->window()->mapToGlobal(mSurfacePos.toPoint());
|
mGlobalPos = window->window()->mapToGlobal(mSurfacePos.toPoint());
|
||||||
@ -657,7 +662,7 @@ public:
|
|||||||
|
|
||||||
void QWaylandInputDevice::Pointer::pointer_motion(uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y)
|
void QWaylandInputDevice::Pointer::pointer_motion(uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y)
|
||||||
{
|
{
|
||||||
QWaylandWindow *window = mFocus;
|
QWaylandWindow *window = focusWindow();
|
||||||
if (!window) {
|
if (!window) {
|
||||||
// We destroyed the pointer focus surface, but the server didn't get the message yet...
|
// We destroyed the pointer focus surface, but the server didn't get the message yet...
|
||||||
// or the server didn't send an enter event first. In either case, ignore the event.
|
// or the server didn't send an enter event first. In either case, ignore the event.
|
||||||
@ -709,7 +714,7 @@ public:
|
|||||||
void QWaylandInputDevice::Pointer::pointer_button(uint32_t serial, uint32_t time,
|
void QWaylandInputDevice::Pointer::pointer_button(uint32_t serial, uint32_t time,
|
||||||
uint32_t button, uint32_t state)
|
uint32_t button, uint32_t state)
|
||||||
{
|
{
|
||||||
QWaylandWindow *window = mFocus;
|
QWaylandWindow *window = focusWindow();
|
||||||
if (!window) {
|
if (!window) {
|
||||||
// We destroyed the pointer focus surface, but the server didn't get the message yet...
|
// We destroyed the pointer focus surface, but the server didn't get the message yet...
|
||||||
// or the server didn't send an enter event first. In either case, ignore the event.
|
// or the server didn't send an enter event first. In either case, ignore the event.
|
||||||
@ -754,7 +759,7 @@ void QWaylandInputDevice::Pointer::pointer_button(uint32_t serial, uint32_t time
|
|||||||
|
|
||||||
QPointF pos = mSurfacePos;
|
QPointF pos = mSurfacePos;
|
||||||
QPointF global = mGlobalPos;
|
QPointF global = mGlobalPos;
|
||||||
if (grab && grab != mFocus) {
|
if (grab && grab != focusWindow()) {
|
||||||
pos = QPointF(-1, -1);
|
pos = QPointF(-1, -1);
|
||||||
global = grab->window()->mapToGlobal(pos.toPoint());
|
global = grab->window()->mapToGlobal(pos.toPoint());
|
||||||
|
|
||||||
@ -769,7 +774,7 @@ void QWaylandInputDevice::Pointer::pointer_button(uint32_t serial, uint32_t time
|
|||||||
|
|
||||||
void QWaylandInputDevice::Pointer::invalidateFocus()
|
void QWaylandInputDevice::Pointer::invalidateFocus()
|
||||||
{
|
{
|
||||||
disconnect(mFocus, &QWaylandWindow::wlSurfaceDestroyed, this, &Pointer::handleFocusDestroyed);
|
disconnect(mFocus, &QObject::destroyed, this, &Pointer::handleFocusDestroyed);
|
||||||
mFocus = nullptr;
|
mFocus = nullptr;
|
||||||
mEnterSerial = 0;
|
mEnterSerial = 0;
|
||||||
}
|
}
|
||||||
@ -777,9 +782,11 @@ void QWaylandInputDevice::Pointer::invalidateFocus()
|
|||||||
void QWaylandInputDevice::Pointer::releaseButtons()
|
void QWaylandInputDevice::Pointer::releaseButtons()
|
||||||
{
|
{
|
||||||
mButtons = Qt::NoButton;
|
mButtons = Qt::NoButton;
|
||||||
MotionEvent e(mFocus, mParent->mTime, mSurfacePos, mGlobalPos, mButtons, mParent->modifiers());
|
|
||||||
if (mFocus)
|
if (auto *window = focusWindow()) {
|
||||||
mFocus->handleMouse(mParent, e);
|
MotionEvent e(focusWindow(), mParent->mTime, mSurfacePos, mGlobalPos, mButtons, mParent->modifiers());
|
||||||
|
window->handleMouse(mParent, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class WheelEvent : public QWaylandPointerEvent
|
class WheelEvent : public QWaylandPointerEvent
|
||||||
@ -796,9 +803,7 @@ public:
|
|||||||
|
|
||||||
void QWaylandInputDevice::Pointer::pointer_axis(uint32_t time, uint32_t axis, int32_t value)
|
void QWaylandInputDevice::Pointer::pointer_axis(uint32_t time, uint32_t axis, int32_t value)
|
||||||
{
|
{
|
||||||
QWaylandWindow *window = mFocus;
|
if (!focusWindow()) {
|
||||||
|
|
||||||
if (!window) {
|
|
||||||
// We destroyed the pointer focus surface, but the server didn't get the message yet...
|
// We destroyed the pointer focus surface, but the server didn't get the message yet...
|
||||||
// or the server didn't send an enter event first. In either case, ignore the event.
|
// or the server didn't send an enter event first. In either case, ignore the event.
|
||||||
return;
|
return;
|
||||||
@ -851,8 +856,7 @@ void QWaylandInputDevice::Pointer::pointer_axis_source(uint32_t source)
|
|||||||
|
|
||||||
void QWaylandInputDevice::Pointer::pointer_axis_stop(uint32_t time, uint32_t axis)
|
void QWaylandInputDevice::Pointer::pointer_axis_stop(uint32_t time, uint32_t axis)
|
||||||
{
|
{
|
||||||
QWaylandWindow *window = mFocus;
|
if (!focusWindow())
|
||||||
if (window == nullptr)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mParent->mTime = time;
|
mParent->mTime = time;
|
||||||
@ -882,9 +886,9 @@ void QWaylandInputDevice::Pointer::pointer_axis_stop(uint32_t time, uint32_t axi
|
|||||||
|
|
||||||
QWaylandWindow *target = QWaylandWindow::mouseGrab();
|
QWaylandWindow *target = QWaylandWindow::mouseGrab();
|
||||||
if (!target)
|
if (!target)
|
||||||
target = mFocus;
|
target = focusWindow();
|
||||||
Qt::KeyboardModifiers mods = mParent->modifiers();
|
Qt::KeyboardModifiers mods = mParent->modifiers();
|
||||||
WheelEvent wheelEvent(mFocus, Qt::ScrollEnd, mParent->mTime, mSurfacePos, mGlobalPos,
|
WheelEvent wheelEvent(focusWindow(), Qt::ScrollEnd, mParent->mTime, mSurfacePos, mGlobalPos,
|
||||||
QPoint(), QPoint(), Qt::MouseEventNotSynthesized, mods);
|
QPoint(), QPoint(), Qt::MouseEventNotSynthesized, mods);
|
||||||
target->handleMouse(mParent, wheelEvent);
|
target->handleMouse(mParent, wheelEvent);
|
||||||
mScrollBeginSent = false;
|
mScrollBeginSent = false;
|
||||||
@ -893,8 +897,7 @@ void QWaylandInputDevice::Pointer::pointer_axis_stop(uint32_t time, uint32_t axi
|
|||||||
|
|
||||||
void QWaylandInputDevice::Pointer::pointer_axis_discrete(uint32_t axis, int32_t value)
|
void QWaylandInputDevice::Pointer::pointer_axis_discrete(uint32_t axis, int32_t value)
|
||||||
{
|
{
|
||||||
QWaylandWindow *window = mFocus;
|
if (!focusWindow())
|
||||||
if (window == nullptr)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch (axis) {
|
switch (axis) {
|
||||||
@ -999,11 +1002,11 @@ void QWaylandInputDevice::Pointer::flushScrollEvent()
|
|||||||
if (!angleDelta.isNull()) {
|
if (!angleDelta.isNull()) {
|
||||||
QWaylandWindow *target = QWaylandWindow::mouseGrab();
|
QWaylandWindow *target = QWaylandWindow::mouseGrab();
|
||||||
if (!target)
|
if (!target)
|
||||||
target = mFocus;
|
target = focusWindow();
|
||||||
|
|
||||||
if (isDefinitelyTerminated(mFrameData.axisSource) && !mScrollBeginSent) {
|
if (isDefinitelyTerminated(mFrameData.axisSource) && !mScrollBeginSent) {
|
||||||
qCDebug(lcQpaWaylandInput) << "Flushing scroll event sending ScrollBegin";
|
qCDebug(lcQpaWaylandInput) << "Flushing scroll event sending ScrollBegin";
|
||||||
target->handleMouse(mParent, WheelEvent(mFocus, Qt::ScrollBegin, mParent->mTime,
|
target->handleMouse(mParent, WheelEvent(focusWindow(), Qt::ScrollBegin, mParent->mTime,
|
||||||
mSurfacePos, mGlobalPos, QPoint(), QPoint(),
|
mSurfacePos, mGlobalPos, QPoint(), QPoint(),
|
||||||
Qt::MouseEventNotSynthesized,
|
Qt::MouseEventNotSynthesized,
|
||||||
mParent->modifiers()));
|
mParent->modifiers()));
|
||||||
@ -1016,7 +1019,7 @@ void QWaylandInputDevice::Pointer::flushScrollEvent()
|
|||||||
Qt::MouseEventSource source = mFrameData.wheelEventSource();
|
Qt::MouseEventSource source = mFrameData.wheelEventSource();
|
||||||
|
|
||||||
qCDebug(lcQpaWaylandInput) << "Flushing scroll event" << phase << pixelDelta << angleDelta;
|
qCDebug(lcQpaWaylandInput) << "Flushing scroll event" << phase << pixelDelta << angleDelta;
|
||||||
target->handleMouse(mParent, WheelEvent(mFocus, phase, mParent->mTime, mSurfacePos, mGlobalPos,
|
target->handleMouse(mParent, WheelEvent(focusWindow(), phase, mParent->mTime, mSurfacePos, mGlobalPos,
|
||||||
pixelDelta, angleDelta, source, mParent->modifiers()));
|
pixelDelta, angleDelta, source, mParent->modifiers()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1366,7 +1369,7 @@ void QWaylandInputDevice::handleTouchPoint(int id, double x, double y, Qt::Touch
|
|||||||
|
|
||||||
//is it possible that mTouchFocus is null;
|
//is it possible that mTouchFocus is null;
|
||||||
if (!win && mPointer)
|
if (!win && mPointer)
|
||||||
win = mPointer->mFocus;
|
win = mPointer->focusWindow();
|
||||||
if (!win && mKeyboard)
|
if (!win && mKeyboard)
|
||||||
win = mKeyboard->focusWindow();
|
win = mKeyboard->focusWindow();
|
||||||
if (!win || !win->window())
|
if (!win || !win->window())
|
||||||
|
@ -258,6 +258,7 @@ class Q_WAYLAND_CLIENT_EXPORT QWaylandInputDevice::Pointer : public QObject, pub
|
|||||||
public:
|
public:
|
||||||
explicit Pointer(QWaylandInputDevice *seat);
|
explicit Pointer(QWaylandInputDevice *seat);
|
||||||
~Pointer() override;
|
~Pointer() override;
|
||||||
|
QWaylandWindow *focusWindow() const;
|
||||||
#if QT_CONFIG(cursor)
|
#if QT_CONFIG(cursor)
|
||||||
QString cursorThemeName() const;
|
QString cursorThemeName() const;
|
||||||
int cursorSize() const; // in surface coordinates
|
int cursorSize() const; // in surface coordinates
|
||||||
@ -294,7 +295,7 @@ public:
|
|||||||
void releaseButtons();
|
void releaseButtons();
|
||||||
|
|
||||||
QWaylandInputDevice *mParent = nullptr;
|
QWaylandInputDevice *mParent = nullptr;
|
||||||
QPointer<QWaylandWindow> mFocus;
|
QPointer<QWaylandSurface> mFocus;
|
||||||
uint32_t mEnterSerial = 0;
|
uint32_t mEnterSerial = 0;
|
||||||
#if QT_CONFIG(cursor)
|
#if QT_CONFIG(cursor)
|
||||||
struct {
|
struct {
|
||||||
|
@ -70,6 +70,7 @@ public:
|
|||||||
explicit QWaylandSurface(QWaylandDisplay *display);
|
explicit QWaylandSurface(QWaylandDisplay *display);
|
||||||
~QWaylandSurface() override;
|
~QWaylandSurface() override;
|
||||||
QWaylandScreen *oldestEnteredScreen();
|
QWaylandScreen *oldestEnteredScreen();
|
||||||
|
QWaylandWindow *waylandWindow() const { return m_window; }
|
||||||
|
|
||||||
static QWaylandSurface *fromWlSurface(::wl_surface *surface);
|
static QWaylandSurface *fromWlSurface(::wl_surface *surface);
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include "qwaylandtouch_p.h"
|
#include "qwaylandtouch_p.h"
|
||||||
#include "qwaylandinputdevice_p.h"
|
#include "qwaylandinputdevice_p.h"
|
||||||
#include "qwaylanddisplay_p.h"
|
#include "qwaylanddisplay_p.h"
|
||||||
|
#include "qwaylandsurface_p.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
@ -127,6 +127,7 @@ public:
|
|||||||
QSize surfaceSize() const;
|
QSize surfaceSize() const;
|
||||||
QRect windowGeometry() const;
|
QRect windowGeometry() const;
|
||||||
|
|
||||||
|
QWaylandSurface *waylandSurface() const { return mSurface.data(); }
|
||||||
::wl_surface *wlSurface();
|
::wl_surface *wlSurface();
|
||||||
static QWaylandWindow *fromWlSurface(::wl_surface *surface);
|
static QWaylandWindow *fromWlSurface(::wl_surface *surface);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user