| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/platformsupport/fbconvenience/qfbvthandler.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 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 "qfbvthandler_p.h" | - | ||||||
| 41 | #include <QtCore/QSocketNotifier> | - | ||||||
| 42 | - | |||||||
| 43 | #if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) && (!defined(QT_NO_EVDEV) || !defined(QT_NO_LIBINPUT)) | - | ||||||
| 44 | - | |||||||
| 45 | #define VTH_ENABLED | - | ||||||
| 46 | - | |||||||
| 47 | #include <private/qcore_unix_p.h> | - | ||||||
| 48 | #include <unistd.h> | - | ||||||
| 49 | #include <signal.h> | - | ||||||
| 50 | #include <errno.h> | - | ||||||
| 51 | #include <fcntl.h> | - | ||||||
| 52 | #include <sys/signalfd.h> | - | ||||||
| 53 | #include <sys/ioctl.h> | - | ||||||
| 54 | #include <linux/kd.h> | - | ||||||
| 55 | - | |||||||
| 56 | #ifndef KDSKBMUTE | - | ||||||
| 57 | #define KDSKBMUTE 0x4B51 | - | ||||||
| 58 | #endif | - | ||||||
| 59 | - | |||||||
| 60 | #ifdef K_OFF | - | ||||||
| 61 | #define KBD_OFF_MODE K_OFF | - | ||||||
| 62 | #else | - | ||||||
| 63 | #define KBD_OFF_MODE K_RAW | - | ||||||
| 64 | #endif | - | ||||||
| 65 | - | |||||||
| 66 | #endif | - | ||||||
| 67 | - | |||||||
| 68 | QT_BEGIN_NAMESPACE | - | ||||||
| 69 | - | |||||||
| 70 | #ifdef VTH_ENABLED | - | ||||||
| 71 | static void setTTYCursor(bool enable) | - | ||||||
| 72 | { | - | ||||||
| 73 | const char * const devs[] = { "/dev/tty0", "/dev/tty", "/dev/console", 0 }; | - | ||||||
| 74 | int fd = -1; | - | ||||||
| 75 | for (const char * const *dev = devs; *dev; ++dev) {
| 0 | ||||||
| 76 | fd = QT_OPEN(*dev, O_RDWR); | - | ||||||
| 77 | if (fd != -1) {
| 0 | ||||||
| 78 | // Enable/disable screen blanking and the blinking cursor. | - | ||||||
| 79 | const char *termctl = enable ? "\033[9;15]\033[?33h\033[?25h\033[?0c" : "\033[9;0]\033[?33l\033[?25l\033[?1c";
| 0 | ||||||
| 80 | QT_WRITE(fd, termctl, strlen(termctl) + 1); | - | ||||||
| 81 | QT_CLOSE(fd); | - | ||||||
| 82 | return; never executed: return; | 0 | ||||||
| 83 | } | - | ||||||
| 84 | } never executed: end of block | 0 | ||||||
| 85 | } never executed: end of block | 0 | ||||||
| 86 | #endif | - | ||||||
| 87 | - | |||||||
| 88 | #ifdef VTH_ENABLED | - | ||||||
| 89 | static QFbVtHandler *vth; | - | ||||||
| 90 | - | |||||||
| 91 | void QFbVtHandler::signalHandler(int sigNo) | - | ||||||
| 92 | { | - | ||||||
| 93 | char a = sigNo; | - | ||||||
| 94 | QT_WRITE(vth->m_sigFd[0], &a, sizeof(a)); | - | ||||||
| 95 | } never executed: end of block | 0 | ||||||
| 96 | #endif | - | ||||||
| 97 | - | |||||||
| 98 | QFbVtHandler::QFbVtHandler(QObject *parent) | - | ||||||
| 99 | : QObject(parent), | - | ||||||
| 100 | m_tty(-1), | - | ||||||
| 101 | m_signalNotifier(0) | - | ||||||
| 102 | { | - | ||||||
| 103 | #ifdef VTH_ENABLED | - | ||||||
| 104 | if (isatty(0))
| 0 | ||||||
| 105 | m_tty = 0; never executed: m_tty = 0; | 0 | ||||||
| 106 | - | |||||||
| 107 | if (::socketpair(AF_UNIX, SOCK_STREAM, 0, m_sigFd)) {
| 0 | ||||||
| 108 | qErrnoWarning(errno, "QFbVtHandler: socketpair() failed"); | - | ||||||
| 109 | return; never executed: return; | 0 | ||||||
| 110 | } | - | ||||||
| 111 | - | |||||||
| 112 | vth = this; | - | ||||||
| 113 | setTTYCursor(false); | - | ||||||
| 114 | setKeyboardEnabled(false); | - | ||||||
| 115 | - | |||||||
| 116 | m_signalNotifier = new QSocketNotifier(m_sigFd[1], QSocketNotifier::Read, this); | - | ||||||
| 117 | connect(m_signalNotifier, &QSocketNotifier::activated, this, &QFbVtHandler::handleSignal); | - | ||||||
| 118 | - | |||||||
| 119 | if (!qEnvironmentVariableIntValue("QT_QPA_NO_SIGNAL_HANDLER")) {
| 0 | ||||||
| 120 | struct sigaction sa; | - | ||||||
| 121 | sa.sa_flags = 0; | - | ||||||
| 122 | sa.sa_handler = signalHandler; | - | ||||||
| 123 | sigemptyset(&sa.sa_mask); | - | ||||||
| 124 | sigaction(SIGINT, &sa, 0); // Ctrl+C | - | ||||||
| 125 | sigaction(SIGTSTP, &sa, 0); // Ctrl+Z | - | ||||||
| 126 | sigaction(SIGCONT, &sa, 0); | - | ||||||
| 127 | sigaction(SIGTERM, &sa, 0); // default signal used by kill | - | ||||||
| 128 | } never executed: end of block | 0 | ||||||
| 129 | #endif | - | ||||||
| 130 | } never executed: end of block | 0 | ||||||
| 131 | - | |||||||
| 132 | QFbVtHandler::~QFbVtHandler() | - | ||||||
| 133 | { | - | ||||||
| 134 | #ifdef VTH_ENABLED | - | ||||||
| 135 | setKeyboardEnabled(true); | - | ||||||
| 136 | setTTYCursor(true); | - | ||||||
| 137 | - | |||||||
| 138 | if (m_signalNotifier) {
| 0 | ||||||
| 139 | close(m_sigFd[0]); | - | ||||||
| 140 | close(m_sigFd[1]); | - | ||||||
| 141 | } never executed: end of block | 0 | ||||||
| 142 | #endif | - | ||||||
| 143 | } never executed: end of block | 0 | ||||||
| 144 | - | |||||||
| 145 | void QFbVtHandler::setKeyboardEnabled(bool enable) | - | ||||||
| 146 | { | - | ||||||
| 147 | #ifdef VTH_ENABLED | - | ||||||
| 148 | if (m_tty == -1)
| 0 | ||||||
| 149 | return; never executed: return; | 0 | ||||||
| 150 | - | |||||||
| 151 | if (enable) {
| 0 | ||||||
| 152 | ::ioctl(m_tty, KDSKBMUTE, 0); | - | ||||||
| 153 | ::ioctl(m_tty, KDSKBMODE, m_oldKbdMode); | - | ||||||
| 154 | } else { never executed: end of block | 0 | ||||||
| 155 | ::ioctl(m_tty, KDGKBMODE, &m_oldKbdMode); | - | ||||||
| 156 | if (!qEnvironmentVariableIntValue("QT_QPA_ENABLE_TERMINAL_KEYBOARD")) {
| 0 | ||||||
| 157 | ::ioctl(m_tty, KDSKBMUTE, 1); | - | ||||||
| 158 | ::ioctl(m_tty, KDSKBMODE, KBD_OFF_MODE); | - | ||||||
| 159 | } never executed: end of block | 0 | ||||||
| 160 | } never executed: end of block | 0 | ||||||
| 161 | #else | - | ||||||
| 162 | Q_UNUSED(enable); | - | ||||||
| 163 | #endif | - | ||||||
| 164 | } | - | ||||||
| 165 | - | |||||||
| 166 | void QFbVtHandler::handleSignal() | - | ||||||
| 167 | { | - | ||||||
| 168 | #ifdef VTH_ENABLED | - | ||||||
| 169 | m_signalNotifier->setEnabled(false); | - | ||||||
| 170 | - | |||||||
| 171 | char sigNo; | - | ||||||
| 172 | if (QT_READ(m_sigFd[1], &sigNo, sizeof(sigNo)) == sizeof(sigNo)) {
| 0 | ||||||
| 173 | switch (sigNo) { | - | ||||||
| 174 | case SIGINT: // fallthrough never executed: case 2: | 0 | ||||||
| 175 | case SIGTERM: never executed: case 15: | 0 | ||||||
| 176 | handleInt(); | - | ||||||
| 177 | break; never executed: break; | 0 | ||||||
| 178 | case SIGTSTP: never executed: case 20: | 0 | ||||||
| 179 | emit aboutToSuspend(); | - | ||||||
| 180 | setKeyboardEnabled(true); | - | ||||||
| 181 | setTTYCursor(true); | - | ||||||
| 182 | ::kill(getpid(), SIGSTOP); | - | ||||||
| 183 | break; never executed: break; | 0 | ||||||
| 184 | case SIGCONT: never executed: case 18: | 0 | ||||||
| 185 | setTTYCursor(false); | - | ||||||
| 186 | setKeyboardEnabled(false); | - | ||||||
| 187 | emit resumed(); | - | ||||||
| 188 | break; never executed: break; | 0 | ||||||
| 189 | default: never executed: default: | 0 | ||||||
| 190 | break; never executed: break; | 0 | ||||||
| 191 | } | - | ||||||
| 192 | } | - | ||||||
| 193 | - | |||||||
| 194 | m_signalNotifier->setEnabled(true); | - | ||||||
| 195 | #endif | - | ||||||
| 196 | } never executed: end of block | 0 | ||||||
| 197 | - | |||||||
| 198 | void QFbVtHandler::handleInt() | - | ||||||
| 199 | { | - | ||||||
| 200 | #ifdef VTH_ENABLED | - | ||||||
| 201 | emit interrupted(); | - | ||||||
| 202 | setKeyboardEnabled(true); | - | ||||||
| 203 | setTTYCursor(true); | - | ||||||
| 204 | _exit(1); | - | ||||||
| 205 | #endif | - | ||||||
| 206 | } never executed: end of block | 0 | ||||||
| 207 | - | |||||||
| 208 | QT_END_NAMESPACE | - | ||||||
| Source code | Switch to Preprocessed file |