1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qlinuxfbintegration.h" |
5 | #include "qlinuxfbscreen.h" |
6 | #if QT_CONFIG(kms) |
7 | #include "qlinuxfbdrmscreen.h" |
8 | #endif |
9 | |
10 | #include <QtGui/private/qgenericunixfontdatabase_p.h> |
11 | #include <QtGui/private/qgenericunixservices_p.h> |
12 | #include <QtGui/private/qgenericunixeventdispatcher_p.h> |
13 | |
14 | #include <QtFbSupport/private/qfbvthandler_p.h> |
15 | #include <QtFbSupport/private/qfbbackingstore_p.h> |
16 | #include <QtFbSupport/private/qfbwindow_p.h> |
17 | #include <QtFbSupport/private/qfbcursor_p.h> |
18 | |
19 | #include <QtGui/private/qguiapplication_p.h> |
20 | #include <qpa/qplatforminputcontextfactory_p.h> |
21 | #include <qpa/qwindowsysteminterface.h> |
22 | |
23 | #if QT_CONFIG(libinput) |
24 | #include <QtInputSupport/private/qlibinputhandler_p.h> |
25 | #endif |
26 | |
27 | #if QT_CONFIG(evdev) |
28 | #include <QtInputSupport/private/qevdevmousemanager_p.h> |
29 | #include <QtInputSupport/private/qevdevkeyboardmanager_p.h> |
30 | #include <QtInputSupport/private/qevdevtouchmanager_p.h> |
31 | #endif |
32 | |
33 | #if QT_CONFIG(tslib) |
34 | #include <QtInputSupport/private/qtslib_p.h> |
35 | #endif |
36 | |
37 | QT_BEGIN_NAMESPACE |
38 | |
39 | using namespace Qt::StringLiterals; |
40 | |
41 | QLinuxFbIntegration::QLinuxFbIntegration(const QStringList ¶mList) |
42 | : m_primaryScreen(nullptr), |
43 | m_fontDb(new QGenericUnixFontDatabase), |
44 | m_kbdMgr(nullptr) |
45 | { |
46 | #if QT_CONFIG(kms) |
47 | if (qEnvironmentVariableIntValue(varName: "QT_QPA_FB_DRM" ) != 0) |
48 | m_primaryScreen = new QLinuxFbDrmScreen(paramList); |
49 | #endif |
50 | if (!m_primaryScreen) |
51 | m_primaryScreen = new QLinuxFbScreen(paramList); |
52 | } |
53 | |
54 | QLinuxFbIntegration::~QLinuxFbIntegration() |
55 | { |
56 | QWindowSystemInterface::handleScreenRemoved(screen: m_primaryScreen); |
57 | } |
58 | |
59 | void QLinuxFbIntegration::initialize() |
60 | { |
61 | if (m_primaryScreen->initialize()) |
62 | QWindowSystemInterface::handleScreenAdded(screen: m_primaryScreen); |
63 | else |
64 | qWarning(msg: "linuxfb: Failed to initialize screen" ); |
65 | |
66 | m_inputContext = QPlatformInputContextFactory::create(); |
67 | |
68 | m_vtHandler.reset(other: new QFbVtHandler); |
69 | |
70 | if (!qEnvironmentVariableIntValue(varName: "QT_QPA_FB_DISABLE_INPUT" )) |
71 | createInputHandlers(); |
72 | } |
73 | |
74 | bool QLinuxFbIntegration::hasCapability(QPlatformIntegration::Capability cap) const |
75 | { |
76 | switch (cap) { |
77 | case ThreadedPixmaps: return true; |
78 | case WindowManagement: return false; |
79 | case RhiBasedRendering: return false; |
80 | default: return QPlatformIntegration::hasCapability(cap); |
81 | } |
82 | } |
83 | |
84 | QPlatformBackingStore *QLinuxFbIntegration::createPlatformBackingStore(QWindow *window) const |
85 | { |
86 | return new QFbBackingStore(window); |
87 | } |
88 | |
89 | QPlatformWindow *QLinuxFbIntegration::createPlatformWindow(QWindow *window) const |
90 | { |
91 | return new QFbWindow(window); |
92 | } |
93 | |
94 | QAbstractEventDispatcher *QLinuxFbIntegration::createEventDispatcher() const |
95 | { |
96 | return createUnixEventDispatcher(); |
97 | } |
98 | |
99 | QList<QPlatformScreen *> QLinuxFbIntegration::screens() const |
100 | { |
101 | QList<QPlatformScreen *> list; |
102 | list.append(t: m_primaryScreen); |
103 | return list; |
104 | } |
105 | |
106 | QPlatformFontDatabase *QLinuxFbIntegration::fontDatabase() const |
107 | { |
108 | return m_fontDb.data(); |
109 | } |
110 | |
111 | QPlatformServices *QLinuxFbIntegration::services() const |
112 | { |
113 | if (m_services.isNull()) |
114 | m_services.reset(other: new QGenericUnixServices); |
115 | |
116 | return m_services.data(); |
117 | } |
118 | |
119 | void QLinuxFbIntegration::createInputHandlers() |
120 | { |
121 | #if QT_CONFIG(libinput) |
122 | if (!qEnvironmentVariableIntValue(varName: "QT_QPA_FB_NO_LIBINPUT" )) { |
123 | new QLibInputHandler("libinput"_L1 , QString()); |
124 | return; |
125 | } |
126 | #endif |
127 | |
128 | #if QT_CONFIG(tslib) |
129 | bool useTslib = qEnvironmentVariableIntValue("QT_QPA_FB_TSLIB" ); |
130 | if (useTslib) |
131 | new QTsLibMouseHandler("TsLib"_L1 , QString()); |
132 | #endif |
133 | |
134 | #if QT_CONFIG(evdev) |
135 | m_kbdMgr = new QEvdevKeyboardManager("EvdevKeyboard"_L1 , QString(), this); |
136 | new QEvdevMouseManager("EvdevMouse"_L1 , QString(), this); |
137 | #if QT_CONFIG(tslib) |
138 | if (!useTslib) |
139 | #endif |
140 | new QEvdevTouchManager("EvdevTouch"_L1 , QString() /* spec */, this); |
141 | #endif |
142 | } |
143 | |
144 | QPlatformNativeInterface *QLinuxFbIntegration::nativeInterface() const |
145 | { |
146 | return const_cast<QLinuxFbIntegration *>(this); |
147 | } |
148 | |
149 | QFunctionPointer QLinuxFbIntegration::platformFunction(const QByteArray &function) const |
150 | { |
151 | Q_UNUSED(function); |
152 | return nullptr; |
153 | } |
154 | |
155 | #if QT_CONFIG(evdev) |
156 | void QLinuxFbIntegration::loadKeymap(const QString &filename) |
157 | { |
158 | if (m_kbdMgr) |
159 | m_kbdMgr->loadKeymap(file: filename); |
160 | else |
161 | qWarning(msg: "QLinuxFbIntegration: Cannot load keymap, no keyboard handler found" ); |
162 | } |
163 | |
164 | void QLinuxFbIntegration::switchLang() |
165 | { |
166 | if (m_kbdMgr) |
167 | m_kbdMgr->switchLang(); |
168 | else |
169 | qWarning(msg: "QLinuxFbIntegration: Cannot switch language, no keyboard handler found" ); |
170 | } |
171 | #endif |
172 | |
173 | QT_END_NAMESPACE |
174 | |