File indexing completed on 2024-11-10 04:56:31
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #pragma once 0010 0011 #include <libinput.h> 0012 #include <memory> 0013 0014 namespace KWin 0015 { 0016 0017 class Session; 0018 class Udev; 0019 0020 namespace LibInput 0021 { 0022 0023 class Event; 0024 0025 class Context 0026 { 0027 public: 0028 Context(Session *session, std::unique_ptr<Udev> &&udev); 0029 ~Context(); 0030 bool initialize(); 0031 bool isValid() const 0032 { 0033 return m_libinput != nullptr; 0034 } 0035 bool isSuspended() const 0036 { 0037 return m_suspended; 0038 } 0039 0040 Session *session() const; 0041 int fileDescriptor(); 0042 void dispatch(); 0043 void suspend(); 0044 void resume(); 0045 0046 operator libinput *() 0047 { 0048 return m_libinput; 0049 } 0050 operator libinput *() const 0051 { 0052 return m_libinput; 0053 } 0054 0055 /** 0056 * Gets the next event, if there is no new event @c nullptr is returned 0057 */ 0058 std::unique_ptr<Event> event(); 0059 0060 static int openRestrictedCallback(const char *path, int flags, void *user_data); 0061 static void closeRestrictedCallBack(int fd, void *user_data); 0062 static const struct libinput_interface s_interface; 0063 0064 private: 0065 int openRestricted(const char *path, int flags); 0066 void closeRestricted(int fd); 0067 0068 Session *m_session; 0069 struct libinput *m_libinput; 0070 bool m_suspended; 0071 std::unique_ptr<Udev> m_udev; 0072 }; 0073 0074 } 0075 }