on xenial help sign in
Make use of MirSurface::inputBounds and drop UbuntuKeyboardInfo hack
commit9a78d6d4e4953390dec14f4df5d414e2075d67c7 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateThu 30 Jun 2016, 10:51 (10 years ago) parenta189f76
15 files changed+75−185
CMakeLists.txt+1−1 debian/control+3−3 qml/Components/InputMethod.qml+8−44 qml/Shell.qml+1−1 qml/Stages/DesktopStage.qml+5−1 tests/mocks/Unity/Application/CMakeLists.txt−1 tests/mocks/Unity/Application/MirSurface.cpp+21 tests/mocks/Unity/Application/MirSurface.h+8 tests/mocks/Unity/Application/UbuntuKeyboardInfo.cpp−58 tests/mocks/Unity/Application/UbuntuKeyboardInfo.h−57 tests/mocks/Unity/Application/VirtualKeyboard.cpp+20−1 tests/mocks/Unity/Application/VirtualKeyboard.h+4−1 tests/mocks/Unity/Application/plugin.cpp−8 tests/mocks/Unity/Application/resources/VirtualKeyboard.qml+1−6 tests/qmltests/Stages/tst_DesktopStage.qml+3−3
CMakeLists.txt+1−1
@@ -57,7 +57,7 @@ find_package(Qt5DBus 5.4 REQUIRED)
5757find_package(Qt5Concurrent 5.4 REQUIRED)
5858find_package(Qt5Sql 5.4 REQUIRED)
5959
60−pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=18)
60+pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=19)
6161pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
6262pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
6363pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
debian/control+3−3
@@ -33,7 +33,7 @@ Build-Depends: cmake,
3333 libubuntugestures5-dev,
3434 libubuntugestures5-private-dev,
3535 libudev-dev,
36− libunity-api-dev (>= 7.115),
36+ libunity-api-dev (>= 7.116),
3737 libusermetricsoutput1-dev,
3838# Need those X11 libs touch emulation from mouse events in manual QML tests on a X11 desktop
3939 libx11-dev[!armhf],
@@ -138,7 +138,7 @@ Depends: qml-module-qtquick-layouts,
138138 qtdeclarative5-ubuntu-settings-components (>= 0.7),
139139 qtdeclarative5-unity-notifications-plugin (>= 0.1.2) | unity-notifications-impl,
140140 ubuntu-thumbnailer-impl-0,
141− unity-application-impl-17,
141+ unity-application-impl-19,
142142 unity-notifications-impl-3,
143143 unity-plugin-scopes | unity-scopes-impl,
144144 unity-scopes-impl-12,
@@ -184,7 +184,7 @@ Pre-Depends: ${misc:Pre-Depends},
184184Depends: ${misc:Depends},
185185 ${shlibs:Depends},
186186Provides: unity-application-impl,
187− unity-application-impl-16,
187+ unity-application-impl-19,
188188Replaces: unity8-autopilot (<< 8.02+15.04.20150422-0ubuntu1)
189189Description: Fake environment for running Unity 8 shell
190190 Provides fake implementations of some QML modules used by Unity 8 shell
qml/Components/InputMethod.qml+8−44
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2014,2015 Canonical, Ltd.
2+ * Copyright (C) 2014-2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -16,13 +16,12 @@
1616
1717import QtQuick 2.4
1818import Unity.Application 0.1
19−import Ubuntu.Components 1.3
2019import Ubuntu.Gestures 0.1
2120
2221Item {
2322 id: root
2423
25− property int transitionDuration: UbuntuAnimation.FastDuration
24+ readonly property rect visibleRect: surfaceItem.surface ? surfaceItem.surface.inputBounds : Qt.rect(0, 0, 0, 0)
2625
2726 MirSurfaceItem {
2827 id: surfaceItem
@@ -42,51 +41,16 @@ Item {
4241 }
4342
4443 TouchGate {
45− x: UbuntuKeyboardInfo.x
46− y: UbuntuKeyboardInfo.y
47− width: UbuntuKeyboardInfo.width
48− height: UbuntuKeyboardInfo.height
44+ x: root.visibleRect.x
45+ y: root.visibleRect.y
46+ width: root.visibleRect.width
47+ height: root.visibleRect.height
4948
5049 targetItem: surfaceItem
5150 }
5251
53− state: {
54− if (surfaceItem.surface &&
52+ visible: surfaceItem.surface &&
5553 surfaceItem.surfaceState != Mir.HiddenState &&
5654 surfaceItem.surfaceState != Mir.MinimizedState &&
57− root.enabled) {
58− return "shown";
59− } else {
60− return "hidden";
61− }
62− }
63−
64− states: [
65− State {
66− name: "shown"
67− PropertyChanges {
68− target: root
69− visible: true
70− y: 0
71− }
72− },
73− State {
74− name: "hidden"
75− PropertyChanges {
76− target: root
77− visible: false
78− // half-way down because the vkb occupies only the lower half of the surface
79− // TODO: consider keyboard rotation
80− y: root.parent.height / 2.0
81− }
82− }
83− ]
84−
85− transitions: [
86− Transition {
87− from: "*"; to: "*"
88− PropertyAction { property: "visible"; value: true }
89− UbuntuNumberAnimation { property: "y"; duration: transitionDuration }
90− }
91− ]
55+ root.enabled
9256}
qml/Shell.qml+1−1
@@ -652,7 +652,7 @@ StyledItem {
652652 paused: callManager.hasCalls || !greeter || greeter.shown ||
653653 wizard.active
654654 delayed: dialogs.hasActiveDialog || notifications.hasNotification ||
655− inputMethod.state === "shown" ||
655+ inputMethod.visible ||
656656 (launcher.shown && !launcher.lockedVisible) ||
657657 panel.indicators.shown || stage.dragProgress > 0
658658 usageScenario: shell.usageScenario
qml/Stages/DesktopStage.qml+5−1
@@ -156,6 +156,10 @@ AbstractStage {
156156 }
157157 }
158158 }
159+
160+ readonly property real virtualKeyboardHeight: SurfaceManager.inputMethodSurface
161+ ? SurfaceManager.inputMethodSurface.inputBounds.height
162+ : 0
159163 }
160164
161165 Connections {
@@ -273,7 +277,7 @@ AbstractStage {
273277 property: "y"
274278 value: appDelegate.requestedY -
275279 Math.min(appDelegate.requestedY - PanelState.panelHeight,
276− Math.max(0, UbuntuKeyboardInfo.height - (appContainer.height - (appDelegate.requestedY + appDelegate.height))))
280+ Math.max(0, priv.virtualKeyboardHeight - (appContainer.height - (appDelegate.requestedY + appDelegate.height))))
277281 when: appDelegate.focus && appDelegate.state == "normal"
278282 && SurfaceManager.inputMethodSurface
279283 && SurfaceManager.inputMethodSurface.state != Mir.HiddenState
tests/mocks/Unity/Application/CMakeLists.txt−1
@@ -7,7 +7,6 @@ set(FakeUnityApplicationQml_SOURCES
77 MirSurfaceListModel.cpp
88 ObjectListModel.h
99 SurfaceManager.cpp
10− UbuntuKeyboardInfo.cpp
1110 VirtualKeyboard.cpp
1211 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
1312 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
tests/mocks/Unity/Application/MirSurface.cpp+21
@@ -87,6 +87,8 @@ MirSurface::MirSurface(const QString& name,
8787 m_zombieTimer.setInterval(100);
8888 m_zombieTimer.setSingleShot(true);
8989 connect(&m_zombieTimer, &QTimer::timeout, this, [this](){ this->setLive(false); });
90+
91+ updateInputBoundsAfterResize();
9092}
9193
9294MirSurface::~MirSurface()
@@ -326,6 +328,13 @@ void MirSurface::doResize(int width, int height)
326328 if (changed) {
327329 Q_EMIT sizeChanged(QSize(width, height));
328330 }
331+
332+ updateInputBoundsAfterResize();
333+}
334+
335+void MirSurface::updateInputBoundsAfterResize()
336+{
337+ setInputBounds(QRect(0, 0, m_width, m_height));
329338}
330339
331340bool MirSurface::isSlowToResize() const
@@ -439,6 +448,18 @@ bool MirSurface::focused() const
439448 return controller ? controller->focusedSurface() == this : false;
440449}
441450
451+QRect MirSurface::inputBounds() const
452+{
453+ return m_inputBounds;
454+}
455+
456+void MirSurface::setInputBounds(const QRect &boundsRect)
457+{
458+ if (boundsRect != m_inputBounds) {
459+ m_inputBounds = boundsRect;
460+ Q_EMIT inputBoundsChanged(m_inputBounds);
461+ }
462+}
442463#if MIRSURFACE_DEBUG
443464#undef DEBUG_MSG
444465#define DEBUG_MSG(params) qDebug().nospace() << "MirFocusController::" << __func__ << " " << params
tests/mocks/Unity/Application/MirSurface.h+8
@@ -102,6 +102,7 @@ public:
102102 Mir::ShellChrome shellChrome() const override;
103103
104104 bool focused() const override;
105+ QRect inputBounds() const override;
105106
106107 Q_INVOKABLE void requestFocus() override;
107108
@@ -128,6 +129,8 @@ public:
128129 Q_INVOKABLE void setWidthIncrement(int);
129130 Q_INVOKABLE void setHeightIncrement(int);
130131
132+ Q_INVOKABLE virtual void setInputBounds(const QRect &boundsRect);
133+
131134 /////
132135 // internal mock stuff
133136
@@ -160,6 +163,9 @@ Q_SIGNALS:
160163 void raiseRequested();
161164 void closeRequested();
162165
166+protected:
167+ virtual void updateInputBoundsAfterResize();
168+
163169private Q_SLOTS:
164170 void applyDelayedResize();
165171
@@ -202,6 +208,8 @@ private:
202208 QHash<qintptr, View> m_views;
203209
204210 QTimer m_zombieTimer;
211+
212+ QRect m_inputBounds;
205213};
206214
207215#endif // MOCK_MIR_SURFACE_H
tests/mocks/Unity/Application/UbuntuKeyboardInfo.cppdeleted−58
@@ -1,58 +0,0 @@
1−/*
2− * Copyright (C) 2014-2015 Canonical, Ltd.
3− *
4− * This program is free software: you can redistribute it and/or modify it under
5− * the terms of the GNU Lesser General Public License version 3, as published by
6− * the Free Software Foundation.
7− *
8− * This program is distributed in the hope that it will be useful, but WITHOUT
9− * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10− * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11− * Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "UbuntuKeyboardInfo.h"
18−
19−UbuntuKeyboardInfo::UbuntuKeyboardInfo(QObject *parent)
20− : QObject(parent),
21− m_x(0),
22− m_y(0),
23− m_width(200),
24− m_height(0)
25−{
26−}
27−
28−void UbuntuKeyboardInfo::setX(qreal value)
29−{
30− if (value != m_x) {
31− m_x = value;
32− Q_EMIT xChanged(m_x);
33− }
34−}
35−
36−void UbuntuKeyboardInfo::setY(qreal value)
37−{
38− if (value != m_y) {
39− m_y = value;
40− Q_EMIT yChanged(m_y);
41− }
42−}
43−
44−void UbuntuKeyboardInfo::setWidth(qreal value)
45−{
46− if (value != m_width) {
47− m_width = value;
48− Q_EMIT widthChanged(m_width);
49− }
50−}
51−
52−void UbuntuKeyboardInfo::setHeight(qreal value)
53−{
54− if (value != m_height) {
55− m_height = value;
56− Q_EMIT heightChanged(m_height);
57− }
58−}
tests/mocks/Unity/Application/UbuntuKeyboardInfo.hdeleted−57
@@ -1,57 +0,0 @@
1−/*
2− * Copyright (C) 2014-2015 Canonical, Ltd.
3− *
4− * This program is free software: you can redistribute it and/or modify it under
5− * the terms of the GNU Lesser General Public License version 3, as published by
6− * the Free Software Foundation.
7− *
8− * This program is distributed in the hope that it will be useful, but WITHOUT
9− * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10− * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11− * Lesser General Public License for more details.
12− *
13− * You should have received a copy of the GNU Lesser General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#ifndef UBUNTU_KEYBOARD_INFO_H
18−#define UBUNTU_KEYBOARD_INFO_H
19−
20−#include <QLocalSocket>
21−#include <QTimer>
22−
23−class UbuntuKeyboardInfo : public QObject {
24− Q_OBJECT
25− Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged)
26− Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged)
27− Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged)
28− Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged)
29−public:
30− UbuntuKeyboardInfo(QObject *parent = 0);
31− virtual ~UbuntuKeyboardInfo() {}
32− qreal x() const { return m_x; }
33− qreal y() const { return m_y; }
34− qreal width() const { return m_width; }
35− qreal height() const { return m_height; }
36−
37− // Just in the fake implementation
38− void setX(qreal value);
39− void setY(qreal value);
40− void setWidth(qreal value);
41− void setHeight(qreal value);
42−
43−Q_SIGNALS:
44− void xChanged(qreal x);
45− void yChanged(qreal y);
46− void widthChanged(qreal width);
47− void heightChanged(qreal height);
48−
49−private:
50− QLocalSocket m_socket;
51− qint32 m_x;
52− qint32 m_y;
53− qint32 m_width;
54− qint32 m_height;
55−};
56−
57−#endif // UBUNTU_KEYBOARD_INFO_H
tests/mocks/Unity/Application/VirtualKeyboard.cpp+20−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015,2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -34,3 +34,22 @@ VirtualKeyboard::VirtualKeyboard()
3434VirtualKeyboard::~VirtualKeyboard()
3535{
3636}
37+
38+void VirtualKeyboard::updateInputBoundsAfterResize()
39+{
40+ int width = this->width();
41+
42+ int height;
43+ if (this->width() > this->height()) {
44+ // landscape
45+ height = this->height() * 0.4;
46+ } else {
47+ // portrait
48+ height = this->width() * 0.6;
49+ }
50+
51+ int x = 0;
52+ int y = this->height() - height;
53+
54+ setInputBounds(QRect(x, y, width, height));
55+}
tests/mocks/Unity/Application/VirtualKeyboard.h+4−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015,2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -27,6 +27,9 @@ class VirtualKeyboard : public MirSurface
2727public:
2828 explicit VirtualKeyboard();
2929 ~VirtualKeyboard();
30+
31+protected:
32+ void updateInputBoundsAfterResize() override;
3033};
3134
3235Q_DECLARE_METATYPE(VirtualKeyboard*)
tests/mocks/Unity/Application/plugin.cpp−8
@@ -19,7 +19,6 @@
1919#include "ApplicationManager.h"
2020#include "MirSurfaceItem.h"
2121#include "SurfaceManager.h"
22−#include "UbuntuKeyboardInfo.h"
2322
2423// unity-api
2524#include <unity/shell/application/Mir.h>
@@ -53,12 +52,6 @@ QObject* surfaceManagerSingleton(QQmlEngine*, QJSEngine*)
5352 return SurfaceManager::instance();
5453}
5554
56−QObject* ubuntuKeyboardInfoSingleton(QQmlEngine*, QJSEngine*)
57−{
58− createUnityApplicationSharedSingletons();
59− return new UbuntuKeyboardInfo;
60−}
61−
6255QObject* mirFocusControllerSingleton(QQmlEngine*, QJSEngine*)
6356{
6457 createUnityApplicationSharedSingletons();
@@ -86,7 +79,6 @@ void FakeUnityApplicationQmlPlugin::registerTypes(const char *uri)
8679
8780 qmlRegisterSingletonType<ApplicationManager>(uri, 0, 1, "ApplicationManager", applicationManagerSingleton);
8881 qmlRegisterSingletonType<SurfaceManager>(uri, 0, 1, "SurfaceManager", surfaceManagerSingleton);
89− qmlRegisterSingletonType<UbuntuKeyboardInfo>(uri, 0, 1, "UbuntuKeyboardInfo", ubuntuKeyboardInfoSingleton);
9082
9183 qmlRegisterUncreatableType<Mir>(uri, 0, 1, "Mir", "Mir provides enum values, it can't be instantiated");
9284}
tests/mocks/Unity/Application/resources/VirtualKeyboard.qml+1−6
@@ -1,5 +1,5 @@
11/*
2− * Copyright 2014-2015 Canonical Ltd.
2+ * Copyright 2014-2016 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU Lesser General Public License as published by
@@ -38,9 +38,4 @@ Item {
3838 anchors.fill: parent
3939 }
4040 }
41−
42− Binding { target: UbuntuKeyboardInfo; property: "x"; value: screenshotImage.x}
43− Binding { target: UbuntuKeyboardInfo; property: "y"; value: screenshotImage.y}
44− Binding { target: UbuntuKeyboardInfo; property: "width"; value: screenshotImage.width}
45− Binding { target: UbuntuKeyboardInfo; property: "height"; value: screenshotImage.height}
4641}
tests/qmltests/Stages/tst_DesktopStage.qml+3−3
@@ -532,14 +532,14 @@ Item {
532532 verify(dashAppDelegate);
533533 dashAppDelegate.requestedHeight = data.windowHeight;
534534 dashAppDelegate.requestedY = data.windowY;
535− UbuntuKeyboardInfo.height = 0;
535+ SurfaceManager.inputMethodSurface.setInputBounds(Qt.rect(0, 0, 0, 0));
536536 var initialY = dashAppDelegate.y;
537537 verify(initialY > PanelState.panelHeight);
538538
539− UbuntuKeyboardInfo.height = root.height / 2;
539+ SurfaceManager.inputMethodSurface.setInputBounds(Qt.rect(0, root.height / 2, root.width, root.height / 2));
540540 tryCompare(dashAppDelegate, "y", data.targetDisplacement);
541541
542− UbuntuKeyboardInfo.height = 0;
542+ SurfaceManager.inputMethodSurface.setInputBounds(Qt.rect(0, 0, 0, 0));
543543 tryCompare(dashAppDelegate, "y", initialY);
544544 SurfaceManager.inputMethodSurface.state = oldOSKState;
545545 }