File indexing completed on 2021-12-21 14:17:30

0001 /********************************************************************
0002  KSld - the KDE Screenlocker Daemon
0003  This file is part of the KDE project.
0004 
0005  Copyright 1999 Martin R. Jones <mjones@kde.org>
0006  Copyright 2003 Oswald Buddenhagen <ossi@kde.org>
0007  Copyright 2008 Chani Armitage <chanika@gmail.com>
0008  Copyright (C) 2011 Martin Gräßlin <mgraesslin@kde.org>
0009 
0010 This program is free software; you can redistribute it and/or modify
0011 it under the terms of the GNU General Public License as published by
0012 the Free Software Foundation; either version 2 of the License, or
0013 (at your option) any later version.
0014 
0015 This program is distributed in the hope that it will be useful,
0016 but WITHOUT ANY WARRANTY; without even the implied warranty of
0017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018 GNU General Public License for more details.
0019 
0020 You should have received a copy of the GNU General Public License
0021 along with this program.  If not, see <http://www.gnu.org/licenses/>.
0022 *********************************************************************/
0023 #ifndef SCREENLOCKER_KSLDAPP_H
0024 #define SCREENLOCKER_KSLDAPP_H
0025 
0026 #include <QElapsedTimer>
0027 #include <QProcessEnvironment>
0028 
0029 #include <KScreenLocker/kscreenlocker_export.h>
0030 
0031 // forward declarations
0032 class GlobalAccel;
0033 class LogindIntegration;
0034 class QTimer;
0035 class KSldTest;
0036 class PowerManagementInhibition;
0037 
0038 namespace ScreenLocker
0039 {
0040 enum class EstablishLock {
0041     Immediate, /// Require password from the start. Use if invoked explicitly by the user
0042     Delayed, /// Allow the user to log back in without a password for a configured grace time.
0043     DefaultToSwitchUser, /// UI should default to showing the "switch user dialog"
0044 };
0045 
0046 class AbstractLocker;
0047 class WaylandServer;
0048 
0049 class KSCREENLOCKER_EXPORT KSldApp : public QObject
0050 {
0051     Q_OBJECT
0052     Q_CLASSINFO("D-Bus Interface", "org.kde.ksld.App")
0053 
0054 public:
0055     enum LockState {
0056         Unlocked,
0057         AcquiringLock,
0058         Locked,
0059     };
0060     Q_ENUM(LockState)
0061 
0062     static KSldApp *self();
0063 
0064     explicit KSldApp(QObject *parent = nullptr);
0065     ~KSldApp() override;
0066 
0067     LockState lockState() const
0068     {
0069         return m_lockState;
0070     }
0071 
0072     /**
0073      * @returns the number of milliseconds passed since the screen has been locked.
0074      **/
0075     uint activeTime() const;
0076 
0077     void configure();
0078 
0079     void userActivity();
0080     bool isGraceTime() const;
0081 
0082     void setWaylandFd(int fd);
0083 
0084     void setGreeterEnvironment(const QProcessEnvironment &env);
0085 
0086     /**
0087      * Can be used by the lock window to remove the lock during grace time.
0088      **/
0089     void unlock();
0090     void inhibit();
0091     void uninhibit();
0092 
0093     void lock(EstablishLock establishLock, int attemptCount = 0);
0094     void initialize();
0095 
0096     bool event(QEvent *event) override;
0097 
0098     /**
0099      * For testing
0100      * @internal
0101      **/
0102     int idleId() const
0103     {
0104         return m_idleId;
0105     }
0106     /**
0107      * For testing
0108      * @internal
0109      **/
0110     void setIdleId(int idleId)
0111     {
0112         m_idleId = idleId;
0113     }
0114     /**
0115      * For testing
0116      * @internal
0117      **/
0118     void setGraceTime(int msec)
0119     {
0120         m_lockGrace = msec;
0121     }
0122 
0123     bool forceSoftwareRendering() const
0124     {
0125         return m_forceSoftwareRendering;
0126     }
0127 
0128     void setForceSoftwareRendering(bool force)
0129     {
0130         m_forceSoftwareRendering = force;
0131     }
0132 
0133 Q_SIGNALS:
0134     void aboutToLock();
0135     void locked();
0136     void unlocked();
0137     void lockStateChanged();
0138 
0139 private Q_SLOTS:
0140     void cleanUp();
0141     void endGraceTime();
0142     void solidSuspend();
0143 
0144 public Q_SLOTS:
0145     void lockScreenShown();
0146 
0147 private:
0148     void initializeX11();
0149     bool establishGrab();
0150     void startLockProcess(EstablishLock establishLock);
0151     void showLockWindow();
0152     void hideLockWindow();
0153     void doUnlock();
0154     bool isFdoPowerInhibited() const;
0155 
0156     LockState m_lockState;
0157     QProcess *m_lockProcess;
0158     AbstractLocker *m_lockWindow;
0159     WaylandServer *m_waylandServer;
0160 
0161     /**
0162      * Timer to measure how long the screen is locked.
0163      * This information is required by DBus Interface.
0164      **/
0165     QElapsedTimer m_lockedTimer;
0166     int m_idleId;
0167     /**
0168      * Number of milliseconds after locking in which user activity will result in screen being
0169      * unlocked without requiring a password.
0170      **/
0171     int m_lockGrace;
0172     /**
0173      * Controls whether user activity may remove the lock. Only enabled after idle timeout.
0174      **/
0175     bool m_inGraceTime;
0176     /**
0177      * Grace time ends when timer expires.
0178      **/
0179     QTimer *m_graceTimer;
0180     int m_inhibitCounter;
0181     LogindIntegration *m_logind;
0182     GlobalAccel *m_globalAccel = nullptr;
0183     bool m_hasXInput2 = false;
0184     bool m_forceSoftwareRendering = false;
0185 
0186     bool m_isX11;
0187     bool m_isWayland;
0188     int m_greeterCrashedCounter = 0;
0189     QProcessEnvironment m_greeterEnv;
0190     PowerManagementInhibition *m_powerManagementInhibition;
0191 
0192     int m_waylandFd = -1;
0193 
0194     // for auto tests
0195     friend KSldTest;
0196 };
0197 } // namespace
0198 
0199 #endif // SCREENLOCKER_KSLDAPP_H