Skip to content

Commit 51b4aa7

Browse files
author
Phil Wise
committed
Show/hide matchbox-keyboard rather than onboard
1 parent f18dd30 commit 51b4aa7

7 files changed

+142
-28
lines changed

CMakeLists.txt

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,30 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
1616
find_package(Qt5Widgets REQUIRED)
1717
find_package(Qt5WebKitWidgets REQUIRED)
1818
find_package(Qt5DBus REQUIRED)
19+
find_package(X11)
1920

2021
qt5_wrap_ui(UI_MAINWINDOW mainwindow.ui)
2122

2223
set_source_files_properties(softwareloadingmanager.xml
2324
PROPERTIES INCLUDE softwareloadingmanagerdbus.h)
24-
qt5_add_dbus_interfaces(DBUS_FILES onboard.xml softwareloadingmanager.xml)
25+
qt5_add_dbus_interfaces(DBUS_FILES softwareloadingmanager.xml)
2526
qt5_add_resources(RCC_FILES resources/resources.qrc)
2627

28+
# Generate config.h from config.h.in
29+
configure_file(config.h.in config.h)
30+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
31+
2732
add_executable(openivi-html5
2833
main.cc mainwindow.cc webgraphicview.cc softwareloadingmanager.cc
2934
car.cc installdetail.cc packageid.cc
35+
virtualkeyboard.cc
3036
${DBUS_FILES} ${RCC_FILES} ${UI_MAINWINDOW})
3137

38+
if (X11_FOUND)
39+
target_link_libraries(openivi-html5 ${X11_LIBRARIES})
40+
include_directories(${X11_INCLUDE_DIR})
41+
endif(X11_FOUND)
42+
3243
set_property(TARGET openivi-html5 PROPERTY CXX_STANDARD 11)
3344

3445
qt5_use_modules(openivi-html5 Widgets DBus WebKitWidgets)

config.h.in

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef OPENIVI_CONFIGURE_H_
2+
#define OPENIVI_CONFIGURE_H_
3+
4+
#cmakedefine X11_FOUND
5+
6+
#endif /* OPENIVI_CONFIGURE_H_ */

onboard.xml

-16
This file was deleted.

virtualkeyboard.cc

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

virtualkeyboard.h

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef OPENIVI_VIRTUALKEYBOARD_H_
2+
#define OPENIVI_VIRTUALKEYBOARD_H_
3+
4+
/*
5+
OpenIVI HTML5 environment
6+
Copyright (C) 2015 ATS Advanced Telematic Systems GmbH
7+
8+
This program is free software; you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation; either version 2 of the License, or
11+
(at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License along
19+
with this program; if not, write to the Free Software Foundation, Inc.,
20+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21+
*/
22+
23+
/**
24+
* Interface to control the on screen keyboard, matchbox-keyboard.
25+
*/
26+
class VirtualKeyboard {
27+
public:
28+
VirtualKeyboard();
29+
~VirtualKeyboard();
30+
void Show() { SendCommand(1); }
31+
void Hide() { SendCommand(2); }
32+
33+
private:
34+
void SendCommand(int);
35+
// including <X11/Xlib.h> breaks QT, so use a void* pointer here
36+
void *x11Display_;
37+
};
38+
39+
/* vim: set expandtab tabstop=2 shiftwidth=2: */
40+
#endif /* OPENIVI_VIRTUALKEYBOARD_H_ */

webgraphicview.cc

+2-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "softwareloadingmanager.h"
2828

2929
using org::genivi::software_loading_manager;
30-
using org::onboard::Onboard::Keyboard;
3130

3231
WebGraphicView::WebGraphicView(QWidget *parent)
3332
: QGraphicsView(parent),
@@ -36,9 +35,6 @@ WebGraphicView::WebGraphicView(QWidget *parent)
3635
scene_(new QGraphicsScene(this)),
3736
webInspector_(new QWebInspector),
3837
softwareLoadingManager_(new SoftwareLoadingManager(this)),
39-
onboard_(new Keyboard("org.onboard.Onboard",
40-
QString("/org/onboard/Onboard/Keyboard"),
41-
QDBusConnection::sessionBus(), this)),
4238
car_(new Car(this)) {
4339
page_->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
4440
page_->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
@@ -73,11 +69,9 @@ void WebGraphicView::FocusUpdate() {
7369
bool shouldDisplayKeyboard = r.isValid();
7470
if (keyboardVisible_ != shouldDisplayKeyboard) {
7571
if (shouldDisplayKeyboard) {
76-
auto r = onboard_->Show();
77-
r.waitForFinished();
72+
virtualKeyboard_.Show();
7873
} else {
79-
auto r = onboard_->Hide();
80-
r.waitForFinished();
74+
virtualKeyboard_.Hide();
8175
}
8276
keyboardVisible_ = shouldDisplayKeyboard;
8377
}
@@ -86,7 +80,6 @@ void WebGraphicView::FocusUpdate() {
8680
void WebGraphicView::AddJavascriptObjectsToWindow() {
8781
page_->currentFrame()->addToJavaScriptWindowObject("slm",
8882
softwareLoadingManager_);
89-
page_->currentFrame()->addToJavaScriptWindowObject("onboard", onboard_);
9083

9184
page_->currentFrame()->evaluateJavaScript("genivi = {slm:slm}");
9285

webgraphicview.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#include <QWebPage>
2828

2929
#include "softwareloadingmanager.h"
30-
#include "onboardinterface.h"
3130
#include "car.h"
31+
#include "virtualkeyboard.h"
3232

3333
class WebGraphicView : public QGraphicsView {
3434
Q_OBJECT
@@ -54,7 +54,7 @@ class WebGraphicView : public QGraphicsView {
5454
QGraphicsScene *scene_;
5555
QWebInspector *webInspector_;
5656
SoftwareLoadingManager *softwareLoadingManager_;
57-
org::onboard::Onboard::Keyboard *onboard_;
57+
VirtualKeyboard virtualKeyboard_;
5858
Car *car_;
5959
};
6060

0 commit comments

Comments
 (0)