File indexing completed on 2024-07-14 14:38:30

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2003 Luboš Luňák <l.lunak@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-or-later
0006 */
0007 
0008 #include "kusertimestamp.h"
0009 
0010 #include "config-kwindowsystem.h"
0011 #include "kwindowsystem.h"
0012 
0013 #if KWINDOWSYSTEM_HAVE_X11
0014 
0015 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
0016 #include <private/qtx11extras_p.h>
0017 #else
0018 #include <QX11Info>
0019 #endif
0020 
0021 #include <netwm.h>
0022 #endif
0023 
0024 unsigned long KUserTimestamp::userTimestamp()
0025 {
0026     if (KWindowSystem::isPlatformX11()) {
0027 #if KWINDOWSYSTEM_HAVE_X11
0028         return QX11Info::appUserTime();
0029 #endif
0030     }
0031     return 0;
0032 }
0033 
0034 void KUserTimestamp::updateUserTimestamp(unsigned long time)
0035 {
0036 #if KWINDOWSYSTEM_HAVE_X11
0037     if (!KWindowSystem::isPlatformX11()) {
0038         return;
0039     }
0040     if (time == 0) { // get current X timestamp
0041         time = QX11Info::getTimestamp();
0042     }
0043 
0044     if (QX11Info::appUserTime() == 0 || NET::timestampCompare(time, QX11Info::appUserTime()) > 0) { // time > appUserTime
0045         QX11Info::setAppUserTime(time);
0046     }
0047     if (QX11Info::appTime() == 0 || NET::timestampCompare(time, QX11Info::appTime()) > 0) { // time > appTime
0048         QX11Info::setAppTime(time);
0049     }
0050 #else
0051     Q_UNUSED(time)
0052 #endif
0053 }