summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Samir <[email protected]>2024-08-22 16:03:21 +0300
committerAhmad Samir <[email protected]>2024-08-31 18:57:08 +0300
commitbe4ea227cec04d4844a735f045e6f10b5a988bb1 (patch)
tree982cdcb2228d6a6d373c563e24922b66f46a1877
parent1bef712e2a8386856a71f9b6568fcd3d21d0b052 (diff)
XCB platform plugin: use QBasicTimer instead of storing a timer id
Change-Id: Ibd329e17acda73bd892533836b3048c664336fc7 Reviewed-by: Thiago Macieira <[email protected]>
-rw-r--r--src/plugins/platforms/xcb/qxcbclipboard.cpp14
-rw-r--r--src/plugins/platforms/xcb/qxcbclipboard.h3
-rw-r--r--src/plugins/platforms/xcb/qxcbdrag.cpp14
-rw-r--r--src/plugins/platforms/xcb/qxcbdrag.h2
4 files changed, 14 insertions, 19 deletions
diff --git a/src/plugins/platforms/xcb/qxcbclipboard.cpp b/src/plugins/platforms/xcb/qxcbclipboard.cpp
index 77157595b87..53f45e0775d 100644
--- a/src/plugins/platforms/xcb/qxcbclipboard.cpp
+++ b/src/plugins/platforms/xcb/qxcbclipboard.cpp
@@ -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);
diff --git a/src/plugins/platforms/xcb/qxcbclipboard.h b/src/plugins/platforms/xcb/qxcbclipboard.h
index 134daf4be7c..4538481f1cc 100644
--- a/src/plugins/platforms/xcb/qxcbclipboard.h
+++ b/src/plugins/platforms/xcb/qxcbclipboard.h
@@ -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
diff --git a/src/plugins/platforms/xcb/qxcbdrag.cpp b/src/plugins/platforms/xcb/qxcbdrag.cpp
index 71335444e9c..b6f38d6592e 100644
--- a/src/plugins/platforms/xcb/qxcbdrag.cpp
+++ b/src/plugins/platforms/xcb/qxcbdrag.cpp
@@ -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();
}
}
diff --git a/src/plugins/platforms/xcb/qxcbdrag.h b/src/plugins/platforms/xcb/qxcbdrag.h
index ae7cc915c8c..5bbebecf318 100644
--- a/src/plugins/platforms/xcb/qxcbdrag.h
+++ b/src/plugins/platforms/xcb/qxcbdrag.h
@@ -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;