KWin
Loading...
Searching...
No Matches
udev.h
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#pragma once
10#include <kwin_export.h>
11#include <memory>
12
13#include <QList>
14#include <vector>
15
16#include <sys/types.h>
17
18struct udev;
19struct udev_device;
20struct udev_monitor;
21
22namespace KWin
23{
24class Udev;
25
26class KWIN_EXPORT UdevDevice
27{
28public:
29 UdevDevice(udev_device *device);
31
32 QString devNode() const;
33 dev_t devNum() const;
34 const char *property(const char *key);
35 bool hasProperty(const char *key, const char *value);
36 QString action() const;
37
38 QMap<QByteArray, QByteArray> properties() const;
39 bool isBootVga() const;
40 QString seat() const;
41 bool isHotpluggable() const;
42
43 operator udev_device *() const
44 {
45 return m_device;
46 }
47 operator udev_device *()
48 {
49 return m_device;
50 }
51
52private:
53 udev_device *const m_device;
54};
55
56class KWIN_EXPORT UdevMonitor
57{
58public:
59 explicit UdevMonitor(Udev *udev);
61
62 int fd() const;
63 bool isValid() const
64 {
65 return m_monitor != nullptr;
66 }
67 void filterSubsystemDevType(const char *subSystem, const char *devType = nullptr);
68 void enable();
69 std::unique_ptr<UdevDevice> getDevice();
70
71private:
72 udev_monitor *m_monitor;
73};
74
75class KWIN_EXPORT Udev
76{
77public:
78 Udev();
79 ~Udev();
80
81 bool isValid() const
82 {
83 return m_udev != nullptr;
84 }
85 std::vector<std::unique_ptr<UdevDevice>> listGPUs();
86 std::unique_ptr<UdevDevice> deviceFromSyspath(const char *syspath);
87 std::unique_ptr<UdevMonitor> monitor();
88 operator udev *() const
89 {
90 return m_udev;
91 }
92 operator udev *()
93 {
94 return m_udev;
95 }
96
97private:
98 struct udev *m_udev;
99};
100
101}
bool isValid() const
Definition udev.h:81
bool isValid() const
Definition udev.h:63