-
Notifications
You must be signed in to change notification settings - Fork 8
/
virtualkeyboard.cc
80 lines (61 loc) · 2.33 KB
/
virtualkeyboard.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
OpenIVI HTML5 environment
Copyright (C) 2015 ATS Advanced Telematic Systems GmbH
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <QDebug>
#include "virtualkeyboard.h"
#include "config.h"
/* If X11 is not available, for example on Mac OSX builds, use a dummy
implementation of VirtualKeyboard */
#ifdef X11_FOUND
#include <X11/Xlib.h>
VirtualKeyboard::VirtualKeyboard() : x11Display_(XOpenDisplay(NULL)) {
if (!x11Display_) {
qDebug() << "XOpenDisplay failed";
}
}
VirtualKeyboard::~VirtualKeyboard() {
if (x11Display_) {
XCloseDisplay((Display*)x11Display_);
}
}
void VirtualKeyboard::SendCommand(int command) {
if (x11Display_) {
Display* dsp = (Display*)x11Display_;
XEvent event;
memset(&event, 0, sizeof(XEvent));
Atom Atom_MB_IM_INVOKER_COMMAND =
XInternAtom(dsp, "_MB_IM_INVOKER_COMMAND", False);
event.xclient.type = ClientMessage;
event.xclient.window = DefaultRootWindow(dsp);
event.xclient.message_type = Atom_MB_IM_INVOKER_COMMAND;
event.xclient.format = 32;
event.xclient.data.l[0] =
command; /* MBKeyboardRemoteShow | MBKeyboardRemoteHide */
XSendEvent(dsp, DefaultRootWindow(dsp), False,
SubstructureRedirectMask | SubstructureNotifyMask, &event);
XSync(dsp, False);
} else {
qDebug() << "No xdisplay found. Not showing/hiding keyboard";
}
}
#else /* X11_FOUND */
VirtualKeyboard::VirtualKeyboard() : x11Display_(0) {
qDebug() << "X11 not found at build time. VirtualKeyboard disabled";
}
VirtualKeyboard::~VirtualKeyboard() {}
void VirtualKeyboard::SendCommand(int) {
qDebug() << "X11 not found at build time. Not showing/hiding keyboard";
}
#endif