File indexing completed on 2025-03-16 11:20:44
0001 /* 0002 SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <kwinglobals.h> 0010 0011 #include <QObject> 0012 #include <QString> 0013 0014 #include <memory> 0015 #include <sys/types.h> 0016 0017 namespace KWin 0018 { 0019 0020 /** 0021 * The Session class represents the session controlled by the compositor. 0022 * 0023 * The Session class provides information about the virtual terminal where the compositor 0024 * is running and a way to open files that require special privileges, e.g. DRM devices or 0025 * input devices. 0026 */ 0027 class KWIN_EXPORT Session : public QObject 0028 { 0029 Q_OBJECT 0030 0031 public: 0032 /** 0033 * This enum type is used to specify the type of the session. 0034 */ 0035 enum class Type { 0036 Noop, 0037 ConsoleKit, 0038 Logind, 0039 }; 0040 0041 /** 0042 * This enum type is used to specify optional capabilities of the session. 0043 */ 0044 enum class Capability : uint { 0045 SwitchTerminal = 0x1, 0046 }; 0047 Q_DECLARE_FLAGS(Capabilities, Capability) 0048 0049 static std::unique_ptr<Session> create(); 0050 static std::unique_ptr<Session> create(Type type); 0051 0052 /** 0053 * Returns @c true if the session is active; otherwise returns @c false. 0054 */ 0055 virtual bool isActive() const = 0; 0056 0057 /** 0058 * Returns the capabilities supported by the session. 0059 */ 0060 virtual Capabilities capabilities() const = 0; 0061 0062 /** 0063 * Returns the seat name for the Session. 0064 */ 0065 virtual QString seat() const = 0; 0066 0067 /** 0068 * Returns the terminal controlled by the Session. 0069 */ 0070 virtual uint terminal() const = 0; 0071 0072 /** 0073 * Opens the file with the specified @a fileName. Returns the file descriptor 0074 * of the file or @a -1 if an error has occurred. 0075 */ 0076 virtual int openRestricted(const QString &fileName) = 0; 0077 0078 /** 0079 * Closes a file that has been opened using the openRestricted() function. 0080 */ 0081 virtual void closeRestricted(int fileDescriptor) = 0; 0082 0083 /** 0084 * Switches to the specified virtual @a terminal. This function does nothing if the 0085 * Capability::SwitchTerminal capability is unsupported. 0086 */ 0087 virtual void switchTo(uint terminal) = 0; 0088 0089 Q_SIGNALS: 0090 /** 0091 * This signal is emitted when the session is resuming from suspend. 0092 */ 0093 void awoke(); 0094 /** 0095 * This signal is emitted when the active state of the session has changed. 0096 */ 0097 void activeChanged(bool active); 0098 0099 /** 0100 * This signal is emitted when the specified device can be used again. 0101 */ 0102 void deviceResumed(dev_t deviceId); 0103 0104 /** 0105 * This signal is emitted when the given device cannot be used by the compositor 0106 * anymore. For example, this normally occurs when switching between VTs. 0107 * 0108 * Note that when this signal is emitted for a DRM device, master permissions can 0109 * be already revoked. 0110 */ 0111 void devicePaused(dev_t deviceId); 0112 0113 protected: 0114 explicit Session() = default; 0115 }; 0116 0117 } // namespace KWin 0118 0119 Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::Session::Capabilities)