XCB platform plugin: use QBasicTimer instead of storing a timer id

Change-Id: Ibd329e17acda73bd892533836b3048c664336fc7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Ahmad Samir 2024-08-22 16:03:21 +03:00
parent 1bef712e2a
commit be4ea227ce
4 changed files with 14 additions and 19 deletions

View File

@ -13,6 +13,8 @@
#include <QtCore/QDebug>
using namespace std::chrono_literals;
QT_BEGIN_NAMESPACE
#ifndef QT_NO_CLIPBOARD
@ -130,14 +132,12 @@ QXcbClipboardTransaction::QXcbClipboardTransaction(QXcbClipboard *clipboard, xcb
xcb_change_window_attributes(m_clipboard->xcb_connection(), m_window,
XCB_CW_EVENT_MASK, values);
m_abortTimerId = startTimer(std::chrono::milliseconds{m_clipboard->clipboardTimeout()});
m_abortTimer.start(m_clipboard->clipboardTimeout() * 1ms, this);
}
QXcbClipboardTransaction::~QXcbClipboardTransaction()
{
if (m_abortTimerId)
killTimer(m_abortTimerId);
m_abortTimerId = 0;
m_abortTimer.stop();
m_clipboard->removeTransaction(m_window);
}
@ -147,9 +147,7 @@ bool QXcbClipboardTransaction::updateIncrementalProperty(const xcb_property_noti
return false;
// restart the timer
if (m_abortTimerId)
killTimer(m_abortTimerId);
m_abortTimerId = startTimer(std::chrono::milliseconds{m_clipboard->clipboardTimeout()});
m_abortTimer.start(m_clipboard->clipboardTimeout() * 1ms, this);
uint bytes_left = uint(m_data.size()) - m_offset;
if (bytes_left > 0) {
@ -180,7 +178,7 @@ bool QXcbClipboardTransaction::updateIncrementalProperty(const xcb_property_noti
void QXcbClipboardTransaction::timerEvent(QTimerEvent *ev)
{
if (ev->timerId() == m_abortTimerId) {
if (ev->id() == m_abortTimer.id()) {
// this can happen when the X client we are sending data
// to decides to exit (normally or abnormally)
qCDebug(lcQpaClipboard, "timed out while sending data to %p", this);

View File

@ -9,6 +9,7 @@
#include <xcb/xcb.h>
#include <xcb/xfixes.h>
#include <QtCore/qbasictimer.h>
#include <QtCore/qobject.h>
#include <QtCore/qmap.h>
@ -42,7 +43,7 @@ private:
xcb_atom_t m_target;
uint8_t m_format;
uint m_offset = 0;
int m_abortTimerId = 0;
QBasicTimer m_abortTimer;
};
class QXcbClipboard : public QXcbObject, public QPlatformClipboard

View File

@ -91,7 +91,6 @@ QXcbDrag::QXcbDrag(QXcbConnection *c) : QXcbObject(c)
m_dropData = new QXcbDropData(this);
init();
cleanup_timer = -1;
}
QXcbDrag::~QXcbDrag()
@ -508,9 +507,8 @@ void QXcbDrag::drop(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardMod
transactions.append(t);
// timer is needed only for drops that came from other processes.
if (!t.targetWindow && cleanup_timer == -1) {
cleanup_timer = startTimer(XdndDropTransactionTimeout);
}
if (!t.targetWindow && !cleanup_timer.isActive())
cleanup_timer.start(XdndDropTransactionTimeout, this);
qCDebug(lcQpaXDnd) << "sending drop to target:" << current_target;
@ -1089,7 +1087,7 @@ void QXcbDrag::handleFinished(const xcb_client_message_event_t *event)
void QXcbDrag::timerEvent(QTimerEvent* e)
{
if (e->timerId() == cleanup_timer) {
if (e->id() == cleanup_timer.id()) {
bool stopTimer = true;
for (int i = 0; i < transactions.size(); ++i) {
const Transaction &t = transactions.at(i);
@ -1115,10 +1113,8 @@ void QXcbDrag::timerEvent(QTimerEvent* e)
}
}
if (stopTimer && cleanup_timer != -1) {
killTimer(cleanup_timer);
cleanup_timer = -1;
}
if (stopTimer)
cleanup_timer.stop();
}
}

View File

@ -128,7 +128,7 @@ private:
// 10 minute timer used to discard old XdndDrop transactions
static constexpr std::chrono::minutes XdndDropTransactionTimeout{10};
int cleanup_timer;
QBasicTimer cleanup_timer;
QList<xcb_atom_t> drag_types;