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_services(new QGenericUnixServices), |
45 | m_kbdMgr(nullptr) |
46 | { |
47 | #if QT_CONFIG(kms) |
48 | if (qEnvironmentVariableIntValue(varName: "QT_QPA_FB_DRM" ) != 0) |
49 | m_primaryScreen = new QLinuxFbDrmScreen(paramList); |
50 | #endif |
51 | if (!m_primaryScreen) |
52 | m_primaryScreen = new QLinuxFbScreen(paramList); |
53 | } |
54 | |
55 | QLinuxFbIntegration::~QLinuxFbIntegration() |
56 | { |
57 | QWindowSystemInterface::handleScreenRemoved(screen: m_primaryScreen); |
58 | } |
59 | |
60 | void QLinuxFbIntegration::initialize() |
61 | { |
62 | if (m_primaryScreen->initialize()) |
63 | QWindowSystemInterface::handleScreenAdded(screen: m_primaryScreen); |
64 | else |
65 | qWarning(msg: "linuxfb: Failed to initialize screen" ); |
66 | |
67 | m_inputContext = QPlatformInputContextFactory::create(); |
68 | |
69 | m_vtHandler.reset(other: new QFbVtHandler); |
70 | |
71 | if (!qEnvironmentVariableIntValue(varName: "QT_QPA_FB_DISABLE_INPUT" )) |
72 | createInputHandlers(); |
73 | } |
74 | |
75 | bool QLinuxFbIntegration::hasCapability(QPlatformIntegration::Capability cap) const |
76 | { |
77 | switch (cap) { |
78 | case ThreadedPixmaps: return true; |
79 | case WindowManagement: return false; |
80 | case RhiBasedRendering: return false; |
81 | default: return QPlatformIntegration::hasCapability(cap); |
82 | } |
83 | } |
84 | |
85 | QPlatformBackingStore *QLinuxFbIntegration::createPlatformBackingStore(QWindow *window) const |
86 | { |
87 | return new QFbBackingStore(window); |
88 | } |
89 | |
90 | QPlatformWindow *QLinuxFbIntegration::createPlatformWindow(QWindow *window) const |
91 | { |
92 | return new QFbWindow(window); |
93 | } |
94 | |
95 | QAbstractEventDispatcher *QLinuxFbIntegration::createEventDispatcher() const |
96 | { |
97 | return createUnixEventDispatcher(); |
98 | } |
99 | |
100 | QList<QPlatformScreen *> QLinuxFbIntegration::screens() const |
101 | { |
102 | QList<QPlatformScreen *> list; |
103 | list.append(t: m_primaryScreen); |
104 | return list; |
105 | } |
106 | |
107 | QPlatformFontDatabase *QLinuxFbIntegration::fontDatabase() const |
108 | { |
109 | return m_fontDb.data(); |
110 | } |
111 | |
112 | QPlatformServices *QLinuxFbIntegration::services() const |
113 | { |
114 | return m_services.data(); |
115 | } |
116 | |
117 | void QLinuxFbIntegration::createInputHandlers() |
118 | { |
119 | #if QT_CONFIG(libinput) |
120 | if (!qEnvironmentVariableIntValue(varName: "QT_QPA_FB_NO_LIBINPUT" )) { |
121 | new QLibInputHandler("libinput"_L1 , QString()); |
122 | return; |
123 | } |
124 | #endif |
125 | |
126 | #if QT_CONFIG(tslib) |
127 | bool useTslib = qEnvironmentVariableIntValue("QT_QPA_FB_TSLIB" ); |
128 | if (useTslib) |
129 | new QTsLibMouseHandler("TsLib"_L1 , QString()); |
130 | #endif |
131 | |
132 | #if QT_CONFIG(evdev) |
133 | m_kbdMgr = new QEvdevKeyboardManager("EvdevKeyboard"_L1 , QString(), this); |
134 | new QEvdevMouseManager("EvdevMouse"_L1 , QString(), this); |
135 | #if QT_CONFIG(tslib) |
136 | if (!useTslib) |
137 | #endif |
138 | new QEvdevTouchManager("EvdevTouch"_L1 , QString() /* spec */, this); |
139 | #endif |
140 | } |
141 | |
142 | QPlatformNativeInterface *QLinuxFbIntegration::nativeInterface() const |
143 | { |
144 | return const_cast<QLinuxFbIntegration *>(this); |
145 | } |
146 | |
147 | QFunctionPointer QLinuxFbIntegration::platformFunction(const QByteArray &function) const |
148 | { |
149 | Q_UNUSED(function); |
150 | return nullptr; |
151 | } |
152 | |
153 | #if QT_CONFIG(evdev) |
154 | void QLinuxFbIntegration::loadKeymap(const QString &filename) |
155 | { |
156 | if (m_kbdMgr) |
157 | m_kbdMgr->loadKeymap(file: filename); |
158 | else |
159 | qWarning(msg: "QLinuxFbIntegration: Cannot load keymap, no keyboard handler found" ); |
160 | } |
161 | |
162 | void QLinuxFbIntegration::switchLang() |
163 | { |
164 | if (m_kbdMgr) |
165 | m_kbdMgr->switchLang(); |
166 | else |
167 | qWarning(msg: "QLinuxFbIntegration: Cannot switch language, no keyboard handler found" ); |
168 | } |
169 | #endif |
170 | |
171 | QT_END_NAMESPACE |
172 | |