Changeset View
Changeset View
Standalone View
Standalone View
udev.cpp
Show All 12 Lines | |||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | GNU General Public License for more details. | 15 | GNU General Public License for more details. | ||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "udev.h" | 20 | #include "udev.h" | ||
21 | #include "logind.h" | ||||
21 | // Qt | 22 | // Qt | ||
22 | #include <QByteArray> | 23 | #include <QByteArray> | ||
23 | #include <QScopedPointer> | 24 | #include <QScopedPointer> | ||
24 | // system | 25 | // system | ||
25 | #include <libudev.h> | 26 | #include <libudev.h> | ||
26 | #include <functional> | 27 | #include <functional> | ||
27 | 28 | | |||
28 | namespace KWin | 29 | namespace KWin | ||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 98 | { | |||
101 | udev_enumerate_scan_devices(m_enumerate.data()); | 102 | udev_enumerate_scan_devices(m_enumerate.data()); | ||
102 | } | 103 | } | ||
103 | 104 | | |||
104 | UdevDevice::Ptr UdevEnumerate::find(std::function<bool(const UdevDevice::Ptr &device)> test) | 105 | UdevDevice::Ptr UdevEnumerate::find(std::function<bool(const UdevDevice::Ptr &device)> test) | ||
105 | { | 106 | { | ||
106 | if (m_enumerate.isNull()) { | 107 | if (m_enumerate.isNull()) { | ||
107 | return UdevDevice::Ptr(); | 108 | return UdevDevice::Ptr(); | ||
108 | } | 109 | } | ||
110 | QString defaultSeat = QStringLiteral("seat0"); | ||||
109 | udev_list_entry *it = udev_enumerate_get_list_entry(m_enumerate.data()); | 111 | udev_list_entry *it = udev_enumerate_get_list_entry(m_enumerate.data()); | ||
110 | UdevDevice::Ptr firstFound; | 112 | UdevDevice::Ptr firstFound; | ||
111 | while (it) { | 113 | while (it) { | ||
112 | auto current = it; | 114 | auto current = it; | ||
113 | it = udev_list_entry_get_next(it); | 115 | it = udev_list_entry_get_next(it); | ||
114 | auto device = m_udev->deviceFromSyspath(udev_list_entry_get_name(current)); | 116 | auto device = m_udev->deviceFromSyspath(udev_list_entry_get_name(current)); | ||
115 | if (!device) { | 117 | if (!device) { | ||
116 | continue; | 118 | continue; | ||
117 | } | 119 | } | ||
120 | QString deviceSeat = device->property("ID_SEAT"); | ||||
121 | if (deviceSeat.isEmpty()) { | ||||
122 | deviceSeat = defaultSeat; | ||||
123 | } | ||||
124 | if (deviceSeat != LogindIntegration::self()->seat()) { | ||||
125 | continue; | ||||
126 | } | ||||
118 | if (test(device)) { | 127 | if (test(device)) { | ||
119 | return device; | 128 | return device; | ||
120 | } | 129 | } | ||
121 | if (!firstFound) { | 130 | if (!firstFound) { | ||
122 | firstFound.swap(device); | 131 | firstFound.swap(device); | ||
123 | } | 132 | } | ||
124 | } | 133 | } | ||
125 | return firstFound; | 134 | return firstFound; | ||
126 | } | 135 | } | ||
127 | 136 | | |||
128 | UdevDevice::Ptr Udev::primaryGpu() | 137 | UdevDevice::Ptr Udev::primaryGpu() | ||
129 | { | 138 | { | ||
130 | if (!m_udev) { | 139 | if (!m_udev) { | ||
131 | return UdevDevice::Ptr(); | 140 | return UdevDevice::Ptr(); | ||
132 | } | 141 | } | ||
133 | UdevEnumerate enumerate(this); | 142 | UdevEnumerate enumerate(this); | ||
134 | enumerate.addMatch(UdevEnumerate::Match::SubSystem, "drm"); | 143 | enumerate.addMatch(UdevEnumerate::Match::SubSystem, "drm"); | ||
135 | enumerate.addMatch(UdevEnumerate::Match::SysName, "card[0-9]*"); | 144 | enumerate.addMatch(UdevEnumerate::Match::SysName, "card[0-9]*"); | ||
136 | enumerate.scan(); | 145 | enumerate.scan(); | ||
137 | return enumerate.find([](const UdevDevice::Ptr &device) { | 146 | return enumerate.find([](const UdevDevice::Ptr &device) { | ||
138 | // TODO: check seat | | |||
139 | auto pci = device->getParentWithSubsystemDevType("pci"); | 147 | auto pci = device->getParentWithSubsystemDevType("pci"); | ||
140 | if (!pci) { | 148 | if (!pci) { | ||
141 | return false; | 149 | return false; | ||
142 | } | 150 | } | ||
143 | const char *systAttrValue = udev_device_get_sysattr_value(pci, "boot_vga"); | 151 | const char *systAttrValue = udev_device_get_sysattr_value(pci, "boot_vga"); | ||
144 | if (systAttrValue && qstrcmp(systAttrValue, "1") == 0) { | 152 | if (systAttrValue && qstrcmp(systAttrValue, "1") == 0) { | ||
145 | return true; | 153 | return true; | ||
146 | } | 154 | } | ||
Show All 26 Lines | 175 | { | |||
173 | enumerate.addMatch(UdevEnumerate::Match::SysName, "renderD[0-9]*"); | 181 | enumerate.addMatch(UdevEnumerate::Match::SysName, "renderD[0-9]*"); | ||
174 | enumerate.scan(); | 182 | enumerate.scan(); | ||
175 | return enumerate.find([](const UdevDevice::Ptr &device) { | 183 | return enumerate.find([](const UdevDevice::Ptr &device) { | ||
176 | Q_UNUSED(device) | 184 | Q_UNUSED(device) | ||
177 | return true; | 185 | return true; | ||
178 | }); | 186 | }); | ||
179 | } | 187 | } | ||
180 | 188 | | |||
189 | UdevDevice::Ptr Udev::primaryFramebuffer() | ||||
190 | { | ||||
191 | if (!m_udev) { | ||||
192 | return UdevDevice::Ptr(); | ||||
193 | } | ||||
194 | UdevEnumerate enumerate(this); | ||||
195 | enumerate.addMatch(UdevEnumerate::Match::SubSystem, "graphics"); | ||||
196 | enumerate.addMatch(UdevEnumerate::Match::SysName, "fb[0-9]*"); | ||||
197 | enumerate.scan(); | ||||
198 | return enumerate.find([](const UdevDevice::Ptr &device) { | ||||
199 | auto pci = device->getParentWithSubsystemDevType("pci"); | ||||
200 | if (!pci) { | ||||
201 | return false; | ||||
202 | } | ||||
203 | const char *systAttrValue = udev_device_get_sysattr_value(pci, "boot_vga"); | ||||
204 | if (systAttrValue && qstrcmp(systAttrValue, "1") == 0) { | ||||
205 | return true; | ||||
206 | } | ||||
207 | return false; | ||||
208 | }); | ||||
209 | } | ||||
210 | | ||||
181 | UdevDevice::Ptr Udev::deviceFromSyspath(const char *syspath) | 211 | UdevDevice::Ptr Udev::deviceFromSyspath(const char *syspath) | ||
182 | { | 212 | { | ||
183 | return UdevDevice::Ptr(new UdevDevice(udev_device_new_from_syspath(m_udev, syspath))); | 213 | return UdevDevice::Ptr(new UdevDevice(udev_device_new_from_syspath(m_udev, syspath))); | ||
184 | } | 214 | } | ||
185 | 215 | | |||
186 | UdevMonitor *Udev::monitor() | 216 | UdevMonitor *Udev::monitor() | ||
187 | { | 217 | { | ||
188 | UdevMonitor *m = new UdevMonitor(this); | 218 | UdevMonitor *m = new UdevMonitor(this); | ||
▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines |