Simplify and modernize QWaylandInputDevice
Use enum values and nullptr instead of using magic ints directly. Also get rid of ifdefs in constructors by using in-class member initializers. Change-Id: I037bec7070296a4a8cb46ebe85104caf5a08fb77 Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@liri.io>
This commit is contained in:
parent
dd13698a73
commit
7b40685ad2
@ -80,13 +80,6 @@ namespace QtWaylandClient {
|
||||
|
||||
QWaylandInputDevice::Keyboard::Keyboard(QWaylandInputDevice *p)
|
||||
: mParent(p)
|
||||
, mFocus(0)
|
||||
#if QT_CONFIG(xkbcommon_evdev)
|
||||
, mXkbContext(0)
|
||||
, mXkbMap(0)
|
||||
, mXkbState(0)
|
||||
#endif
|
||||
, mNativeModifiers(0)
|
||||
{
|
||||
connect(&mRepeatTimer, SIGNAL(timeout()), this, SLOT(repeatKey()));
|
||||
}
|
||||
@ -168,7 +161,7 @@ QWaylandInputDevice::Keyboard::~Keyboard()
|
||||
releaseKeyMap();
|
||||
#endif
|
||||
if (mFocus)
|
||||
QWindowSystemInterface::handleWindowActivated(0);
|
||||
QWindowSystemInterface::handleWindowActivated(nullptr);
|
||||
if (mParent->mVersion >= 3)
|
||||
wl_keyboard_release(object());
|
||||
else
|
||||
@ -182,16 +175,6 @@ void QWaylandInputDevice::Keyboard::stopRepeat()
|
||||
|
||||
QWaylandInputDevice::Pointer::Pointer(QWaylandInputDevice *p)
|
||||
: mParent(p)
|
||||
, mFocus(0)
|
||||
, mEnterSerial(0)
|
||||
#if QT_CONFIG(cursor)
|
||||
, mCursorSerial(0)
|
||||
#endif
|
||||
, mButtons(0)
|
||||
#if QT_CONFIG(cursor)
|
||||
, mCursorBuffer(nullptr)
|
||||
, mCursorShape(Qt::BitmapCursor)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
@ -205,7 +188,6 @@ QWaylandInputDevice::Pointer::~Pointer()
|
||||
|
||||
QWaylandInputDevice::Touch::Touch(QWaylandInputDevice *p)
|
||||
: mParent(p)
|
||||
, mFocus(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -223,17 +205,6 @@ QWaylandInputDevice::QWaylandInputDevice(QWaylandDisplay *display, int version,
|
||||
, mQDisplay(display)
|
||||
, mDisplay(display->wl_display())
|
||||
, mVersion(qMin(version, 4))
|
||||
, mCaps(0)
|
||||
#if QT_CONFIG(wayland_datadevice)
|
||||
, mDataDevice(0)
|
||||
#endif
|
||||
, mKeyboard(0)
|
||||
, mPointer(0)
|
||||
, mTouch(0)
|
||||
, mTextInput(0)
|
||||
, mTime(0)
|
||||
, mSerial(0)
|
||||
, mTouchDevice(0)
|
||||
{
|
||||
#if QT_CONFIG(wayland_datadevice)
|
||||
if (mQDisplay->dndSelectionHandler()) {
|
||||
@ -262,7 +233,7 @@ void QWaylandInputDevice::seat_capabilities(uint32_t caps)
|
||||
mKeyboard->init(get_keyboard());
|
||||
} else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && mKeyboard) {
|
||||
delete mKeyboard;
|
||||
mKeyboard = 0;
|
||||
mKeyboard = nullptr;
|
||||
}
|
||||
|
||||
if (caps & WL_SEAT_CAPABILITY_POINTER && !mPointer) {
|
||||
@ -271,7 +242,7 @@ void QWaylandInputDevice::seat_capabilities(uint32_t caps)
|
||||
pointerSurface = mQDisplay->createSurface(this);
|
||||
} else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && mPointer) {
|
||||
delete mPointer;
|
||||
mPointer = 0;
|
||||
mPointer = nullptr;
|
||||
}
|
||||
|
||||
if (caps & WL_SEAT_CAPABILITY_TOUCH && !mTouch) {
|
||||
@ -286,7 +257,7 @@ void QWaylandInputDevice::seat_capabilities(uint32_t caps)
|
||||
}
|
||||
} else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && mTouch) {
|
||||
delete mTouch;
|
||||
mTouch = 0;
|
||||
mTouch = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,17 +321,17 @@ void QWaylandInputDevice::removeMouseButtonFromState(Qt::MouseButton button)
|
||||
|
||||
QWaylandWindow *QWaylandInputDevice::pointerFocus() const
|
||||
{
|
||||
return mPointer ? mPointer->mFocus : 0;
|
||||
return mPointer ? mPointer->mFocus : nullptr;
|
||||
}
|
||||
|
||||
QWaylandWindow *QWaylandInputDevice::keyboardFocus() const
|
||||
{
|
||||
return mKeyboard ? mKeyboard->mFocus : 0;
|
||||
return mKeyboard ? mKeyboard->mFocus : nullptr;
|
||||
}
|
||||
|
||||
QWaylandWindow *QWaylandInputDevice::touchFocus() const
|
||||
{
|
||||
return mTouch ? mTouch->mFocus : 0;
|
||||
return mTouch ? mTouch->mFocus : nullptr;
|
||||
}
|
||||
|
||||
Qt::KeyboardModifiers QWaylandInputDevice::modifiers() const
|
||||
@ -440,7 +411,7 @@ void QWaylandInputDevice::setCursor(struct wl_buffer *buffer, const QPoint &hotS
|
||||
/* Hide cursor */
|
||||
if (!buffer)
|
||||
{
|
||||
mPointer->set_cursor(mPointer->mEnterSerial, NULL, 0, 0);
|
||||
mPointer->set_cursor(mPointer->mEnterSerial, nullptr, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -463,7 +434,7 @@ class EnterEvent : public QWaylandPointerEvent
|
||||
{
|
||||
public:
|
||||
EnterEvent(const QPointF &l, const QPointF &g)
|
||||
: QWaylandPointerEvent(QWaylandPointerEvent::Enter, 0, l, g, 0, Qt::NoModifier)
|
||||
: QWaylandPointerEvent(QWaylandPointerEvent::Enter, 0, l, g, nullptr, Qt::NoModifier)
|
||||
{}
|
||||
};
|
||||
|
||||
@ -503,7 +474,7 @@ void QWaylandInputDevice::Pointer::pointer_leave(uint32_t time, struct wl_surfac
|
||||
QWaylandWindow *window = QWaylandWindow::fromWlSurface(surface);
|
||||
window->handleMouseLeave(mParent);
|
||||
}
|
||||
mFocus = 0;
|
||||
mFocus = nullptr;
|
||||
mButtons = Qt::NoButton;
|
||||
|
||||
mParent->mTime = time;
|
||||
@ -522,7 +493,7 @@ void QWaylandInputDevice::Pointer::pointer_motion(uint32_t time, wl_fixed_t surf
|
||||
{
|
||||
QWaylandWindow *window = mFocus;
|
||||
|
||||
if (window == NULL) {
|
||||
if (!window) {
|
||||
// We destroyed the pointer focus surface, but the server
|
||||
// didn't get the message yet.
|
||||
return;
|
||||
@ -624,7 +595,7 @@ void QWaylandInputDevice::Pointer::pointer_axis(uint32_t time, uint32_t axis, in
|
||||
QPoint pixelDelta;
|
||||
QPoint angleDelta;
|
||||
|
||||
if (window == NULL) {
|
||||
if (!window) {
|
||||
// We destroyed the pointer focus surface, but the server
|
||||
// didn't get the message yet.
|
||||
return;
|
||||
@ -653,7 +624,7 @@ void QWaylandInputDevice::Keyboard::keyboard_keymap(uint32_t format, int32_t fd,
|
||||
return;
|
||||
}
|
||||
|
||||
char *map_str = (char *)mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
char *map_str = static_cast<char *>(mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0));
|
||||
if (map_str == MAP_FAILED) {
|
||||
close(fd);
|
||||
return;
|
||||
@ -664,8 +635,8 @@ void QWaylandInputDevice::Keyboard::keyboard_keymap(uint32_t format, int32_t fd,
|
||||
releaseComposeState();
|
||||
releaseKeyMap();
|
||||
|
||||
mXkbContext = xkb_context_new(xkb_context_flags(0));
|
||||
mXkbMap = xkb_map_new_from_string(mXkbContext, map_str, XKB_KEYMAP_FORMAT_TEXT_V1, (xkb_keymap_compile_flags)0);
|
||||
mXkbContext = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||
mXkbMap = xkb_map_new_from_string(mXkbContext, map_str, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
munmap(map_str, size);
|
||||
close(fd);
|
||||
|
||||
@ -704,7 +675,7 @@ void QWaylandInputDevice::Keyboard::keyboard_leave(uint32_t time, struct wl_surf
|
||||
window->unfocus();
|
||||
}
|
||||
|
||||
mFocus = NULL;
|
||||
mFocus = nullptr;
|
||||
|
||||
mParent->mQDisplay->handleKeyboardFocusChanged(mParent);
|
||||
|
||||
@ -735,7 +706,7 @@ void QWaylandInputDevice::Keyboard::keyboard_key(uint32_t serial, uint32_t time,
|
||||
{
|
||||
QWaylandWindow *window = mFocus;
|
||||
uint32_t code = key + 8;
|
||||
bool isDown = state != 0;
|
||||
bool isDown = state != WL_KEYBOARD_KEY_STATE_RELEASED;
|
||||
QEvent::Type type = isDown ? QEvent::KeyPress : QEvent::KeyRelease;
|
||||
QString text;
|
||||
int qtkey = key + 8; // qt-compositor substracts 8 for some reason
|
||||
@ -874,7 +845,7 @@ void QWaylandInputDevice::Touch::touch_up(uint32_t serial, uint32_t time, int32_
|
||||
{
|
||||
Q_UNUSED(serial);
|
||||
Q_UNUSED(time);
|
||||
mFocus = 0;
|
||||
mFocus = nullptr;
|
||||
mParent->handleTouchPoint(id, 0, 0, Qt::TouchPointReleased);
|
||||
|
||||
// As of Weston 1.5.90 there is no touch_frame after the last touch_up
|
||||
@ -900,7 +871,7 @@ void QWaylandInputDevice::Touch::touch_cancel()
|
||||
if (touchExt)
|
||||
touchExt->touchCanceled();
|
||||
|
||||
QWindowSystemInterface::handleTouchCancelEvent(0, mParent->mTouchDevice);
|
||||
QWindowSystemInterface::handleTouchCancelEvent(nullptr, mParent->mTouchDevice);
|
||||
}
|
||||
|
||||
void QWaylandInputDevice::handleTouchPoint(int id, double x, double y, Qt::TouchPointState state)
|
||||
@ -985,7 +956,7 @@ void QWaylandInputDevice::Touch::touch_frame()
|
||||
return;
|
||||
}
|
||||
|
||||
QWindow *window = mFocus ? mFocus->window() : 0;
|
||||
QWindow *window = mFocus ? mFocus->window() : nullptr;
|
||||
|
||||
if (mFocus) {
|
||||
const QWindowSystemInterface::TouchPoint &tp = mTouchPoints.last();
|
||||
|
@ -147,27 +147,27 @@ private:
|
||||
struct wl_display *mDisplay;
|
||||
|
||||
int mVersion;
|
||||
uint32_t mCaps;
|
||||
uint32_t mCaps = 0;
|
||||
|
||||
struct wl_surface *pointerSurface;
|
||||
|
||||
#if QT_CONFIG(wayland_datadevice)
|
||||
QWaylandDataDevice *mDataDevice;
|
||||
QWaylandDataDevice *mDataDevice = nullptr;
|
||||
#endif
|
||||
|
||||
Keyboard *mKeyboard;
|
||||
Pointer *mPointer;
|
||||
Touch *mTouch;
|
||||
Keyboard *mKeyboard = nullptr;
|
||||
Pointer *mPointer = nullptr;
|
||||
Touch *mTouch = nullptr;
|
||||
|
||||
QWaylandTextInput *mTextInput;
|
||||
QWaylandTextInput *mTextInput = nullptr;
|
||||
|
||||
uint32_t mTime;
|
||||
uint32_t mSerial;
|
||||
uint32_t mTime = 0;
|
||||
uint32_t mSerial = 0;
|
||||
|
||||
void seat_capabilities(uint32_t caps) override;
|
||||
void handleTouchPoint(int id, double x, double y, Qt::TouchPointState state);
|
||||
|
||||
QTouchDevice *mTouchDevice;
|
||||
QTouchDevice *mTouchDevice = nullptr;
|
||||
|
||||
QSharedPointer<QWaylandBuffer> mPixmapCursor;
|
||||
|
||||
@ -210,13 +210,13 @@ public:
|
||||
QWaylandInputDevice *mParent;
|
||||
QPointer<QWaylandWindow> mFocus;
|
||||
#if QT_CONFIG(xkbcommon_evdev)
|
||||
xkb_context *mXkbContext;
|
||||
xkb_keymap *mXkbMap;
|
||||
xkb_state *mXkbState;
|
||||
xkb_context *mXkbContext = nullptr;
|
||||
xkb_keymap *mXkbMap = nullptr;
|
||||
xkb_state *mXkbState = nullptr;
|
||||
xkb_compose_table *mXkbComposeTable = nullptr;
|
||||
xkb_compose_state *mXkbComposeState = nullptr;
|
||||
#endif
|
||||
uint32_t mNativeModifiers;
|
||||
uint32_t mNativeModifiers = 0;
|
||||
|
||||
int mRepeatKey;
|
||||
uint32_t mRepeatCode;
|
||||
@ -264,16 +264,16 @@ public:
|
||||
|
||||
QWaylandInputDevice *mParent;
|
||||
QPointer<QWaylandWindow> mFocus;
|
||||
uint32_t mEnterSerial;
|
||||
uint32_t mEnterSerial = 0;
|
||||
#if QT_CONFIG(cursor)
|
||||
uint32_t mCursorSerial;
|
||||
uint32_t mCursorSerial = 0;
|
||||
#endif
|
||||
QPointF mSurfacePos;
|
||||
QPointF mGlobalPos;
|
||||
Qt::MouseButtons mButtons;
|
||||
Qt::MouseButtons mButtons = Qt::NoButton;
|
||||
#if QT_CONFIG(cursor)
|
||||
wl_buffer *mCursorBuffer;
|
||||
Qt::CursorShape mCursorShape;
|
||||
wl_buffer *mCursorBuffer = nullptr;
|
||||
Qt::CursorShape mCursorShape = Qt::BitmapCursor;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user