| 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 <QtGui/private/qgenericunixfontdatabase_p.h> |
| 47 | #include <QtGui/private/qgenericunixservices_p.h> |
| 48 | #include <QtGui/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 | QT_BEGIN_NAMESPACE |
| 74 | |
| 75 | QLinuxFbIntegration::QLinuxFbIntegration(const QStringList ¶mList) |
| 76 | : m_primaryScreen(nullptr), |
| 77 | m_fontDb(new QGenericUnixFontDatabase), |
| 78 | m_services(new QGenericUnixServices), |
| 79 | m_kbdMgr(0) |
| 80 | { |
| 81 | #if QT_CONFIG(kms) |
| 82 | if (qEnvironmentVariableIntValue("QT_QPA_FB_DRM" ) != 0) |
| 83 | m_primaryScreen = new QLinuxFbDrmScreen(paramList); |
| 84 | #endif |
| 85 | if (!m_primaryScreen) |
| 86 | m_primaryScreen = new QLinuxFbScreen(paramList); |
| 87 | } |
| 88 | |
| 89 | QLinuxFbIntegration::~QLinuxFbIntegration() |
| 90 | { |
| 91 | QWindowSystemInterface::handleScreenRemoved(m_primaryScreen); |
| 92 | } |
| 93 | |
| 94 | void QLinuxFbIntegration::initialize() |
| 95 | { |
| 96 | if (m_primaryScreen->initialize()) |
| 97 | QWindowSystemInterface::handleScreenAdded(m_primaryScreen); |
| 98 | else |
| 99 | qWarning("linuxfb: Failed to initialize screen" ); |
| 100 | |
| 101 | m_inputContext = QPlatformInputContextFactory::create(); |
| 102 | |
| 103 | m_vtHandler.reset(new QFbVtHandler); |
| 104 | |
| 105 | if (!qEnvironmentVariableIntValue("QT_QPA_FB_DISABLE_INPUT" )) |
| 106 | createInputHandlers(); |
| 107 | } |
| 108 | |
| 109 | bool QLinuxFbIntegration::hasCapability(QPlatformIntegration::Capability cap) const |
| 110 | { |
| 111 | switch (cap) { |
| 112 | case ThreadedPixmaps: return true; |
| 113 | case WindowManagement: return false; |
| 114 | default: return QPlatformIntegration::hasCapability(cap); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | QPlatformBackingStore *QLinuxFbIntegration::createPlatformBackingStore(QWindow *window) const |
| 119 | { |
| 120 | return new QFbBackingStore(window); |
| 121 | } |
| 122 | |
| 123 | QPlatformWindow *QLinuxFbIntegration::createPlatformWindow(QWindow *window) const |
| 124 | { |
| 125 | return new QFbWindow(window); |
| 126 | } |
| 127 | |
| 128 | QAbstractEventDispatcher *QLinuxFbIntegration::createEventDispatcher() const |
| 129 | { |
| 130 | return createUnixEventDispatcher(); |
| 131 | } |
| 132 | |
| 133 | QList<QPlatformScreen *> QLinuxFbIntegration::screens() const |
| 134 | { |
| 135 | QList<QPlatformScreen *> list; |
| 136 | list.append(m_primaryScreen); |
| 137 | return list; |
| 138 | } |
| 139 | |
| 140 | QPlatformFontDatabase *QLinuxFbIntegration::fontDatabase() const |
| 141 | { |
| 142 | return m_fontDb.data(); |
| 143 | } |
| 144 | |
| 145 | QPlatformServices *QLinuxFbIntegration::services() const |
| 146 | { |
| 147 | return m_services.data(); |
| 148 | } |
| 149 | |
| 150 | void QLinuxFbIntegration::createInputHandlers() |
| 151 | { |
| 152 | #if QT_CONFIG(libinput) |
| 153 | if (!qEnvironmentVariableIntValue("QT_QPA_FB_NO_LIBINPUT" )) { |
| 154 | new QLibInputHandler(QLatin1String("libinput" ), QString()); |
| 155 | return; |
| 156 | } |
| 157 | #endif |
| 158 | |
| 159 | #if QT_CONFIG(tslib) |
| 160 | bool useTslib = qEnvironmentVariableIntValue("QT_QPA_FB_TSLIB" ); |
| 161 | if (useTslib) |
| 162 | new QTsLibMouseHandler(QLatin1String("TsLib" ), QString()); |
| 163 | #endif |
| 164 | |
| 165 | #if QT_CONFIG(evdev) |
| 166 | m_kbdMgr = new QEvdevKeyboardManager(QLatin1String("EvdevKeyboard" ), QString(), this); |
| 167 | new QEvdevMouseManager(QLatin1String("EvdevMouse" ), QString(), this); |
| 168 | #if QT_CONFIG(tslib) |
| 169 | if (!useTslib) |
| 170 | #endif |
| 171 | new QEvdevTouchManager(QLatin1String("EvdevTouch" ), QString() /* spec */, this); |
| 172 | #endif |
| 173 | } |
| 174 | |
| 175 | QPlatformNativeInterface *QLinuxFbIntegration::nativeInterface() const |
| 176 | { |
| 177 | return const_cast<QLinuxFbIntegration *>(this); |
| 178 | } |
| 179 | |
| 180 | QFunctionPointer QLinuxFbIntegration::platformFunction(const QByteArray &function) const |
| 181 | { |
| 182 | Q_UNUSED(function); |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | #if QT_CONFIG(evdev) |
| 187 | void QLinuxFbIntegration::loadKeymap(const QString &filename) |
| 188 | { |
| 189 | if (m_kbdMgr) |
| 190 | m_kbdMgr->loadKeymap(filename); |
| 191 | else |
| 192 | qWarning("QLinuxFbIntegration: Cannot load keymap, no keyboard handler found" ); |
| 193 | } |
| 194 | |
| 195 | void QLinuxFbIntegration::switchLang() |
| 196 | { |
| 197 | if (m_kbdMgr) |
| 198 | m_kbdMgr->switchLang(); |
| 199 | else |
| 200 | qWarning("QLinuxFbIntegration: Cannot switch language, no keyboard handler found" ); |
| 201 | } |
| 202 | #endif |
| 203 | |
| 204 | QT_END_NAMESPACE |
| 205 | |