File indexing completed on 2024-04-21 05:27:35
0001 /* 0002 SPDX-FileCopyrightText: 1999 Martin R. Jones <mjones@kde.org> 0003 SPDX-FileCopyrightText: 2003 Oswald Buddenhagen <ossi@kde.org> 0004 SPDX-FileCopyrightText: 2008 Chani Armitage <chanika@gmail.com> 0005 SPDX-FileCopyrightText: 2011 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #pragma once 0010 0011 #include <QElapsedTimer> 0012 #include <QProcessEnvironment> 0013 0014 #include <KScreenLocker/kscreenlocker_export.h> 0015 0016 // forward declarations 0017 class GlobalAccel; 0018 class LogindIntegration; 0019 class QTimer; 0020 class KSldTest; 0021 class PowerManagementInhibition; 0022 0023 namespace ScreenLocker 0024 { 0025 enum class EstablishLock { 0026 Immediate, /// Require password from the start. Use if invoked explicitly by the user 0027 Delayed, /// Allow the user to log back in without a password for a configured grace time. 0028 DefaultToSwitchUser, /// UI should default to showing the "switch user dialog" 0029 }; 0030 0031 class AbstractLocker; 0032 class WaylandServer; 0033 0034 class KSCREENLOCKER_EXPORT KSldApp : public QObject 0035 { 0036 Q_OBJECT 0037 Q_CLASSINFO("D-Bus Interface", "org.kde.ksld.App") 0038 0039 public: 0040 enum LockState { 0041 Unlocked, 0042 AcquiringLock, 0043 Locked, 0044 }; 0045 Q_ENUM(LockState) 0046 0047 static KSldApp *self(); 0048 0049 explicit KSldApp(QObject *parent = nullptr); 0050 ~KSldApp() override; 0051 0052 LockState lockState() const 0053 { 0054 return m_lockState; 0055 } 0056 0057 /** 0058 * @returns the number of milliseconds passed since the screen has been locked. 0059 **/ 0060 uint activeTime() const; 0061 0062 void configure(); 0063 0064 void userActivity(); 0065 bool isGraceTime() const; 0066 0067 void setWaylandFd(int fd); 0068 0069 void setGreeterEnvironment(const QProcessEnvironment &env); 0070 0071 /** 0072 * Can be used by the lock window to remove the lock during grace time. 0073 **/ 0074 void unlock(); 0075 void inhibit(); 0076 void uninhibit(); 0077 0078 void lock(EstablishLock establishLock, int attemptCount = 0); 0079 void initialize(); 0080 0081 bool event(QEvent *event) override; 0082 0083 /** 0084 * For testing 0085 * @internal 0086 **/ 0087 int idleId() const 0088 { 0089 return m_idleId; 0090 } 0091 /** 0092 * For testing 0093 * @internal 0094 **/ 0095 void setIdleId(int idleId) 0096 { 0097 m_idleId = idleId; 0098 } 0099 /** 0100 * For testing 0101 * @internal 0102 **/ 0103 void setGraceTime(int msec) 0104 { 0105 m_lockGrace = msec; 0106 } 0107 0108 bool forceSoftwareRendering() const 0109 { 0110 return m_forceSoftwareRendering; 0111 } 0112 0113 void setForceSoftwareRendering(bool force) 0114 { 0115 m_forceSoftwareRendering = force; 0116 } 0117 0118 Q_SIGNALS: 0119 void aboutToLock(); 0120 void locked(); 0121 void unlocked(); 0122 void lockStateChanged(); 0123 0124 private Q_SLOTS: 0125 void cleanUp(); 0126 void endGraceTime(); 0127 void solidSuspend(); 0128 0129 public Q_SLOTS: 0130 void lockScreenShown(); 0131 0132 private: 0133 void initializeX11(); 0134 bool establishGrab(); 0135 void startLockProcess(EstablishLock establishLock); 0136 void showLockWindow(); 0137 void hideLockWindow(); 0138 void doUnlock(); 0139 void lockProcessRequestedUnlock(); 0140 bool isFdoPowerInhibited() const; 0141 0142 LockState m_lockState; 0143 QProcess *m_lockProcess; 0144 AbstractLocker *m_lockWindow; 0145 WaylandServer *m_waylandServer; 0146 0147 /** 0148 * Timer to measure how long the screen is locked. 0149 * This information is required by DBus Interface. 0150 **/ 0151 QElapsedTimer m_lockedTimer; 0152 int m_idleId; 0153 /** 0154 * Number of milliseconds after locking in which user activity will result in screen being 0155 * unlocked without requiring a password. 0156 **/ 0157 int m_lockGrace; 0158 /** 0159 * Controls whether user activity may remove the lock. Only enabled after idle timeout. 0160 **/ 0161 bool m_inGraceTime; 0162 /** 0163 * Grace time ends when timer expires. 0164 **/ 0165 QTimer *m_graceTimer; 0166 int m_inhibitCounter; 0167 LogindIntegration *m_logind; 0168 GlobalAccel *m_globalAccel = nullptr; 0169 bool m_hasXInput2 = false; 0170 bool m_forceSoftwareRendering = false; 0171 0172 bool m_isX11; 0173 bool m_isWayland; 0174 int m_greeterCrashedCounter = 0; 0175 QProcessEnvironment m_greeterEnv; 0176 PowerManagementInhibition *m_powerManagementInhibition; 0177 0178 int m_waylandFd = -1; 0179 0180 // for auto tests 0181 friend KSldTest; 0182 }; 0183 } // namespace