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) 2015 The Qt Company Ltd. | - | ||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||
5 | ** | - | ||||||
6 | ** This file is part of the plugins of the Qt Toolkit. | - | ||||||
7 | ** | - | ||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||
25 | ** | - | ||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||
29 | ** | - | ||||||
30 | ** $QT_END_LICENSE$ | - | ||||||
31 | ** | - | ||||||
32 | ****************************************************************************/ | - | ||||||
33 | - | |||||||
34 | #include "qfbvthandler_p.h" | - | ||||||
35 | #include <QtCore/QSocketNotifier> | - | ||||||
36 | - | |||||||
37 | #if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) && (!defined(QT_NO_EVDEV) || !defined(QT_NO_LIBINPUT)) | - | ||||||
38 | - | |||||||
39 | #define VTH_ENABLED | - | ||||||
40 | - | |||||||
41 | #include <private/qcore_unix_p.h> | - | ||||||
42 | #include <unistd.h> | - | ||||||
43 | #include <signal.h> | - | ||||||
44 | #include <errno.h> | - | ||||||
45 | #include <fcntl.h> | - | ||||||
46 | #include <sys/signalfd.h> | - | ||||||
47 | #include <sys/ioctl.h> | - | ||||||
48 | #include <linux/kd.h> | - | ||||||
49 | - | |||||||
50 | #ifndef KDSKBMUTE | - | ||||||
51 | #define KDSKBMUTE 0x4B51 | - | ||||||
52 | #endif | - | ||||||
53 | - | |||||||
54 | #ifdef K_OFF | - | ||||||
55 | #define KBD_OFF_MODE K_OFF | - | ||||||
56 | #else | - | ||||||
57 | #define KBD_OFF_MODE K_RAW | - | ||||||
58 | #endif | - | ||||||
59 | - | |||||||
60 | #endif | - | ||||||
61 | - | |||||||
62 | QT_BEGIN_NAMESPACE | - | ||||||
63 | - | |||||||
64 | #ifdef VTH_ENABLED | - | ||||||
65 | static void setTTYCursor(bool enable) | - | ||||||
66 | { | - | ||||||
67 | const char * const devs[] = { "/dev/tty0", "/dev/tty", "/dev/console", 0 }; | - | ||||||
68 | int fd = -1; | - | ||||||
69 | for (const char * const *dev = devs; *dev; ++dev) {
| 0 | ||||||
70 | fd = QT_OPEN(*dev, O_RDWR); | - | ||||||
71 | if (fd != -1) {
| 0 | ||||||
72 | // Enable/disable screen blanking and the blinking cursor. | - | ||||||
73 | const char *termctl = enable ? "\033[9;15]\033[?33h\033[?25h\033[?0c" : "\033[9;0]\033[?33l\033[?25l\033[?1c";
| 0 | ||||||
74 | QT_WRITE(fd, termctl, strlen(termctl) + 1); | - | ||||||
75 | QT_CLOSE(fd); | - | ||||||
76 | return; never executed: return; | 0 | ||||||
77 | } | - | ||||||
78 | } never executed: end of block | 0 | ||||||
79 | } never executed: end of block | 0 | ||||||
80 | #endif | - | ||||||
81 | - | |||||||
82 | #ifdef VTH_ENABLED | - | ||||||
83 | static QFbVtHandler *vth; | - | ||||||
84 | - | |||||||
85 | void QFbVtHandler::signalHandler(int sigNo) | - | ||||||
86 | { | - | ||||||
87 | char a = sigNo; | - | ||||||
88 | QT_WRITE(vth->m_sigFd[0], &a, sizeof(a)); | - | ||||||
89 | } never executed: end of block | 0 | ||||||
90 | #endif | - | ||||||
91 | - | |||||||
92 | QFbVtHandler::QFbVtHandler(QObject *parent) | - | ||||||
93 | : QObject(parent), | - | ||||||
94 | m_tty(-1), | - | ||||||
95 | m_signalNotifier(0) | - | ||||||
96 | { | - | ||||||
97 | #ifdef VTH_ENABLED | - | ||||||
98 | if (isatty(0))
| 0 | ||||||
99 | m_tty = 0; never executed: m_tty = 0; | 0 | ||||||
100 | - | |||||||
101 | if (::socketpair(AF_UNIX, SOCK_STREAM, 0, m_sigFd)) {
| 0 | ||||||
102 | qErrnoWarning(errno, "QFbVtHandler: socketpair() failed"); | - | ||||||
103 | return; never executed: return; | 0 | ||||||
104 | } | - | ||||||
105 | - | |||||||
106 | vth = this; | - | ||||||
107 | setTTYCursor(false); | - | ||||||
108 | setKeyboardEnabled(false); | - | ||||||
109 | - | |||||||
110 | m_signalNotifier = new QSocketNotifier(m_sigFd[1], QSocketNotifier::Read, this); | - | ||||||
111 | connect(m_signalNotifier, &QSocketNotifier::activated, this, &QFbVtHandler::handleSignal); | - | ||||||
112 | - | |||||||
113 | if (!qEnvironmentVariableIntValue("QT_QPA_NO_SIGNAL_HANDLER")) {
| 0 | ||||||
114 | struct sigaction sa; | - | ||||||
115 | sa.sa_flags = 0; | - | ||||||
116 | sa.sa_handler = signalHandler; | - | ||||||
117 | sigemptyset(&sa.sa_mask); | - | ||||||
118 | sigaction(SIGINT, &sa, 0); // Ctrl+C | - | ||||||
119 | sigaction(SIGTSTP, &sa, 0); // Ctrl+Z | - | ||||||
120 | sigaction(SIGCONT, &sa, 0); | - | ||||||
121 | sigaction(SIGTERM, &sa, 0); // default signal used by kill | - | ||||||
122 | } never executed: end of block | 0 | ||||||
123 | #endif | - | ||||||
124 | } never executed: end of block | 0 | ||||||
125 | - | |||||||
126 | QFbVtHandler::~QFbVtHandler() | - | ||||||
127 | { | - | ||||||
128 | #ifdef VTH_ENABLED | - | ||||||
129 | setKeyboardEnabled(true); | - | ||||||
130 | setTTYCursor(true); | - | ||||||
131 | - | |||||||
132 | if (m_signalNotifier) {
| 0 | ||||||
133 | close(m_sigFd[0]); | - | ||||||
134 | close(m_sigFd[1]); | - | ||||||
135 | } never executed: end of block | 0 | ||||||
136 | #endif | - | ||||||
137 | } never executed: end of block | 0 | ||||||
138 | - | |||||||
139 | void QFbVtHandler::setKeyboardEnabled(bool enable) | - | ||||||
140 | { | - | ||||||
141 | #ifdef VTH_ENABLED | - | ||||||
142 | if (m_tty == -1)
| 0 | ||||||
143 | return; never executed: return; | 0 | ||||||
144 | - | |||||||
145 | if (enable) {
| 0 | ||||||
146 | ::ioctl(m_tty, KDSKBMUTE, 0); | - | ||||||
147 | ::ioctl(m_tty, KDSKBMODE, m_oldKbdMode); | - | ||||||
148 | } else { never executed: end of block | 0 | ||||||
149 | ::ioctl(m_tty, KDGKBMODE, &m_oldKbdMode); | - | ||||||
150 | if (!qEnvironmentVariableIntValue("QT_QPA_ENABLE_TERMINAL_KEYBOARD")) {
| 0 | ||||||
151 | ::ioctl(m_tty, KDSKBMUTE, 1); | - | ||||||
152 | ::ioctl(m_tty, KDSKBMODE, KBD_OFF_MODE); | - | ||||||
153 | } never executed: end of block | 0 | ||||||
154 | } never executed: end of block | 0 | ||||||
155 | #else | - | ||||||
156 | Q_UNUSED(enable); | - | ||||||
157 | #endif | - | ||||||
158 | } | - | ||||||
159 | - | |||||||
160 | void QFbVtHandler::handleSignal() | - | ||||||
161 | { | - | ||||||
162 | #ifdef VTH_ENABLED | - | ||||||
163 | m_signalNotifier->setEnabled(false); | - | ||||||
164 | - | |||||||
165 | char sigNo; | - | ||||||
166 | if (QT_READ(m_sigFd[1], &sigNo, sizeof(sigNo)) == sizeof(sigNo)) {
| 0 | ||||||
167 | switch (sigNo) { | - | ||||||
168 | case SIGINT: // fallthrough never executed: case 2: | 0 | ||||||
169 | case SIGTERM: never executed: case 15: | 0 | ||||||
170 | handleInt(); | - | ||||||
171 | break; never executed: break; | 0 | ||||||
172 | case SIGTSTP: never executed: case 20: | 0 | ||||||
173 | emit aboutToSuspend(); | - | ||||||
174 | setKeyboardEnabled(true); | - | ||||||
175 | setTTYCursor(true); | - | ||||||
176 | ::kill(getpid(), SIGSTOP); | - | ||||||
177 | break; never executed: break; | 0 | ||||||
178 | case SIGCONT: never executed: case 18: | 0 | ||||||
179 | setTTYCursor(false); | - | ||||||
180 | setKeyboardEnabled(false); | - | ||||||
181 | emit resumed(); | - | ||||||
182 | break; never executed: break; | 0 | ||||||
183 | default: never executed: default: | 0 | ||||||
184 | break; never executed: break; | 0 | ||||||
185 | } | - | ||||||
186 | } | - | ||||||
187 | - | |||||||
188 | m_signalNotifier->setEnabled(true); | - | ||||||
189 | #endif | - | ||||||
190 | } never executed: end of block | 0 | ||||||
191 | - | |||||||
192 | void QFbVtHandler::handleInt() | - | ||||||
193 | { | - | ||||||
194 | #ifdef VTH_ENABLED | - | ||||||
195 | emit interrupted(); | - | ||||||
196 | setKeyboardEnabled(true); | - | ||||||
197 | setTTYCursor(true); | - | ||||||
198 | _exit(1); | - | ||||||
199 | #endif | - | ||||||
200 | } never executed: end of block | 0 | ||||||
201 | - | |||||||
202 | QT_END_NAMESPACE | - | ||||||
Source code | Switch to Preprocessed file |