| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the plugins of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qlinuxfbintegration.h" |
| 41 | #include "qlinuxfbscreen.h" |
| 42 | #if QT_CONFIG(kms) |
| 43 | #include "qlinuxfbdrmscreen.h" |
| 44 | #endif |
| 45 | |
| 46 | #include <QtFontDatabaseSupport/private/qgenericunixfontdatabase_p.h> |
| 47 | #include <QtServiceSupport/private/qgenericunixservices_p.h> |
| 48 | #include <QtEventDispatcherSupport/private/qgenericunixeventdispatcher_p.h> |
| 49 | |
| 50 | #include <QtFbSupport/private/qfbvthandler_p.h> |
| 51 | #include <QtFbSupport/private/qfbbackingstore_p.h> |
| 52 | #include <QtFbSupport/private/qfbwindow_p.h> |
| 53 | #include <QtFbSupport/private/qfbcursor_p.h> |
| 54 | |
| 55 | #include <QtGui/private/qguiapplication_p.h> |
| 56 | #include <qpa/qplatforminputcontextfactory_p.h> |
| 57 | #include <qpa/qwindowsysteminterface.h> |
| 58 | |
| 59 | #if QT_CONFIG(libinput) |
| 60 | #include <QtInputSupport/private/qlibinputhandler_p.h> |
| 61 | #endif |
| 62 | |
| 63 | #if QT_CONFIG(evdev) |
| 64 | #include <QtInputSupport/private/qevdevmousemanager_p.h> |
| 65 | #include <QtInputSupport/private/qevdevkeyboardmanager_p.h> |
| 66 | #include <QtInputSupport/private/qevdevtouchmanager_p.h> |
| 67 | #endif |
| 68 | |
| 69 | #if QT_CONFIG(tslib) |
| 70 | #include <QtInputSupport/private/qtslib_p.h> |
| 71 | #endif |
| 72 | |
| 73 | #include <QtPlatformHeaders/qlinuxfbfunctions.h> |
| 74 | |
| 75 | QT_BEGIN_NAMESPACE |
| 76 | |
| 77 | QLinuxFbIntegration::QLinuxFbIntegration(const QStringList ¶mList) |
| 78 | : m_primaryScreen(nullptr), |
| 79 | m_fontDb(new QGenericUnixFontDatabase), |
| 80 | m_services(new QGenericUnixServices), |
| 81 | m_kbdMgr(0) |
| 82 | { |
| 83 | #if QT_CONFIG(kms) |
| 84 | if (qEnvironmentVariableIntValue(varName: "QT_QPA_FB_DRM" ) != 0) |
| 85 | m_primaryScreen = new QLinuxFbDrmScreen(paramList); |
| 86 | #endif |
| 87 | if (!m_primaryScreen) |
| 88 | m_primaryScreen = new QLinuxFbScreen(paramList); |
| 89 | } |
| 90 | |
| 91 | QLinuxFbIntegration::~QLinuxFbIntegration() |
| 92 | { |
| 93 | QWindowSystemInterface::handleScreenRemoved(screen: m_primaryScreen); |
| 94 | } |
| 95 | |
| 96 | void QLinuxFbIntegration::initialize() |
| 97 | { |
| 98 | if (m_primaryScreen->initialize()) |
| 99 | QWindowSystemInterface::handleScreenAdded(screen: m_primaryScreen); |
| 100 | else |
| 101 | qWarning(msg: "linuxfb: Failed to initialize screen" ); |
| 102 | |
| 103 | m_inputContext = QPlatformInputContextFactory::create(); |
| 104 | |
| 105 | m_vtHandler.reset(other: new QFbVtHandler); |
| 106 | |
| 107 | if (!qEnvironmentVariableIntValue(varName: "QT_QPA_FB_DISABLE_INPUT" )) |
| 108 | createInputHandlers(); |
| 109 | } |
| 110 | |
| 111 | bool QLinuxFbIntegration::hasCapability(QPlatformIntegration::Capability cap) const |
| 112 | { |
| 113 | switch (cap) { |
| 114 | case ThreadedPixmaps: return true; |
| 115 | case WindowManagement: return false; |
| 116 | default: return QPlatformIntegration::hasCapability(cap); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | QPlatformBackingStore *QLinuxFbIntegration::createPlatformBackingStore(QWindow *window) const |
| 121 | { |
| 122 | return new QFbBackingStore(window); |
| 123 | } |
| 124 | |
| 125 | QPlatformWindow *QLinuxFbIntegration::createPlatformWindow(QWindow *window) const |
| 126 | { |
| 127 | return new QFbWindow(window); |
| 128 | } |
| 129 | |
| 130 | QAbstractEventDispatcher *QLinuxFbIntegration::createEventDispatcher() const |
| 131 | { |
| 132 | return createUnixEventDispatcher(); |
| 133 | } |
| 134 | |
| 135 | QList<QPlatformScreen *> QLinuxFbIntegration::screens() const |
| 136 | { |
| 137 | QList<QPlatformScreen *> list; |
| 138 | list.append(t: m_primaryScreen); |
| 139 | return list; |
| 140 | } |
| 141 | |
| 142 | QPlatformFontDatabase *QLinuxFbIntegration::fontDatabase() const |
| 143 | { |
| 144 | return m_fontDb.data(); |
| 145 | } |
| 146 | |
| 147 | QPlatformServices *QLinuxFbIntegration::services() const |
| 148 | { |
| 149 | return m_services.data(); |
| 150 | } |
| 151 | |
| 152 | void QLinuxFbIntegration::createInputHandlers() |
| 153 | { |
| 154 | #if QT_CONFIG(libinput) |
| 155 | if (!qEnvironmentVariableIntValue(varName: "QT_QPA_FB_NO_LIBINPUT" )) { |
| 156 | new QLibInputHandler(QLatin1String("libinput" ), QString()); |
| 157 | return; |
| 158 | } |
| 159 | #endif |
| 160 | |
| 161 | #if QT_CONFIG(tslib) |
| 162 | bool useTslib = qEnvironmentVariableIntValue("QT_QPA_FB_TSLIB" ); |
| 163 | if (useTslib) |
| 164 | new QTsLibMouseHandler(QLatin1String("TsLib" ), QString()); |
| 165 | #endif |
| 166 | |
| 167 | #if QT_CONFIG(evdev) |
| 168 | m_kbdMgr = new QEvdevKeyboardManager(QLatin1String("EvdevKeyboard" ), QString(), this); |
| 169 | new QEvdevMouseManager(QLatin1String("EvdevMouse" ), QString(), this); |
| 170 | #if QT_CONFIG(tslib) |
| 171 | if (!useTslib) |
| 172 | #endif |
| 173 | new QEvdevTouchManager(QLatin1String("EvdevTouch" ), QString() /* spec */, this); |
| 174 | #endif |
| 175 | } |
| 176 | |
| 177 | QPlatformNativeInterface *QLinuxFbIntegration::nativeInterface() const |
| 178 | { |
| 179 | return const_cast<QLinuxFbIntegration *>(this); |
| 180 | } |
| 181 | |
| 182 | QFunctionPointer QLinuxFbIntegration::platformFunction(const QByteArray &function) const |
| 183 | { |
| 184 | #if QT_CONFIG(evdev) |
| 185 | if (function == QLinuxFbFunctions::loadKeymapTypeIdentifier()) |
| 186 | return QFunctionPointer(loadKeymapStatic); |
| 187 | else if (function == QLinuxFbFunctions::switchLangTypeIdentifier()) |
| 188 | return QFunctionPointer(switchLangStatic); |
| 189 | #else |
| 190 | Q_UNUSED(function) |
| 191 | #endif |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | void QLinuxFbIntegration::loadKeymapStatic(const QString &filename) |
| 197 | { |
| 198 | #if QT_CONFIG(evdev) |
| 199 | QLinuxFbIntegration *self = static_cast<QLinuxFbIntegration *>(QGuiApplicationPrivate::platformIntegration()); |
| 200 | if (self->m_kbdMgr) |
| 201 | self->m_kbdMgr->loadKeymap(file: filename); |
| 202 | else |
| 203 | qWarning(msg: "QLinuxFbIntegration: Cannot load keymap, no keyboard handler found" ); |
| 204 | #else |
| 205 | Q_UNUSED(filename); |
| 206 | #endif |
| 207 | } |
| 208 | |
| 209 | void QLinuxFbIntegration::switchLangStatic() |
| 210 | { |
| 211 | #if QT_CONFIG(evdev) |
| 212 | QLinuxFbIntegration *self = static_cast<QLinuxFbIntegration *>(QGuiApplicationPrivate::platformIntegration()); |
| 213 | if (self->m_kbdMgr) |
| 214 | self->m_kbdMgr->switchLang(); |
| 215 | else |
| 216 | qWarning(msg: "QLinuxFbIntegration: Cannot switch language, no keyboard handler found" ); |
| 217 | #endif |
| 218 | } |
| 219 | |
| 220 | QT_END_NAMESPACE |
| 221 | |