on xenial help sign in
Add global InputMethodManager to handle inputMethod across screens
1b30ec8Marius Gripsgard
plugins/WindowManager/CMakeLists.txt+1
@@ -4,6 +4,7 @@ set(WINDOWMANAGER_SRC
4 Window.cpp
4 Window.cpp
5 WindowManagerPlugin.cpp
5 WindowManagerPlugin.cpp
6 WindowMargins.cpp
6 WindowMargins.cpp
7+ InputMethodManager.cpp
7 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
8 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
8 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
9 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
9 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
10 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
plugins/WindowManager/InputMethodManager.cppnew file+56
@@ -0,0 +1,56 @@
1+/*
2+ * Copyright (C) 2019 UBports Foundation.
3+ * Author(s) Marius Gripsgard <marius@ubports.com>
4+ *
5+ * This program is free software: you can redistribute it and/or modify it under
6+ * the terms of the GNU Lesser General Public License version 3, as published by
7+ * the Free Software Foundation.
8+ *
9+ * This program is distributed in the hope that it will be useful, but WITHOUT
10+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
11+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public License
15+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ */
17+
18+#include "InputMethodManager.h"
19+#include <QDebug>
20+
21+#include <unity/shell/application/MirSurfaceInterface.h>
22+
23+// local
24+#include "Window.h"
25+
26+Q_LOGGING_CATEGORY(INPUTMETHODMANAGER, "InputMethodManager", QtInfoMsg)
27+#define DEBUG_MSG qCDebug(INPUTMETHODMANAGER).nospace().noquote() << __func__
28+
29+namespace unityapi = unity::shell::application;
30+
31+InputMethodManager *InputMethodManager::instance()
32+{
33+ static InputMethodManager* inputMethod(new InputMethodManager());
34+ return inputMethod;
35+}
36+
37+InputMethodManager::InputMethodManager()
38+{
39+}
40+
41+void InputMethodManager::setWindow(Window* window)
42+{
43+ if (window == m_inputMethodWindow) {
44+ return;
45+ }
46+
47+ DEBUG_MSG << "(" << window << ")";
48+
49+ m_inputMethodWindow = window;
50+ Q_EMIT surfaceChanged(surface());
51+}
52+
53+unityapi::MirSurfaceInterface* InputMethodManager::surface() const
54+{
55+ return m_inputMethodWindow ? m_inputMethodWindow->surface() : nullptr;
56+}
plugins/WindowManager/InputMethodManager.hnew file+55
@@ -0,0 +1,55 @@
1+/*
2+ * Copyright (C) 2019 UBports Foundation.
3+ * Author(s) Marius Gripsgard <marius@ubports.com>
4+ *
5+ * This program is free software: you can redistribute it and/or modify it under
6+ * the terms of the GNU Lesser General Public License version 3, as published by
7+ * the Free Software Foundation.
8+ *
9+ * This program is distributed in the hope that it will be useful, but WITHOUT
10+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
11+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public License
15+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ */
17+
18+#pragma once
19+
20+#include <QLoggingCategory>
21+#include <QObject>
22+
23+#include "WindowManagerGlobal.h"
24+
25+Q_DECLARE_LOGGING_CATEGORY(INPUTMETHODMANAGER)
26+
27+class Window;
28+
29+namespace unity {
30+ namespace shell {
31+ namespace application {
32+ class MirSurfaceInterface;
33+ }
34+ }
35+}
36+
37+class WINDOWMANAGERQML_EXPORT InputMethodManager : public QObject
38+{
39+ Q_OBJECT
40+ Q_PROPERTY(unity::shell::application::MirSurfaceInterface* surface READ surface NOTIFY surfaceChanged)
41+
42+public:
43+ InputMethodManager();
44+ static InputMethodManager* instance();
45+
46+ void setWindow(Window* window);
47+
48+Q_SIGNALS:
49+ void surfaceChanged(unity::shell::application::MirSurfaceInterface* inputMethodSurface);
50+
51+private:
52+ unity::shell::application::MirSurfaceInterface* surface() const;
53+
54+ Window* m_inputMethodWindow{nullptr};
55+};
plugins/WindowManager/TopLevelWindowModel.cpp+3
@@ -30,6 +30,7 @@
30
30
31// local
31// local
32#include "Window.h"
32#include "Window.h"
33+#include "InputMethodManager.h"
33
34
34Q_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL, "toplevelwindowmodel", QtInfoMsg)
35Q_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL, "toplevelwindowmodel", QtInfoMsg)
35
36
@@ -472,6 +473,7 @@ void TopLevelWindowModel::setInputMethodWindow(Window *window)
472 }
473 }
473 m_inputMethodWindow = window;
474 m_inputMethodWindow = window;
474 Q_EMIT inputMethodSurfaceChanged(m_inputMethodWindow->surface());
475 Q_EMIT inputMethodSurfaceChanged(m_inputMethodWindow->surface());
476+ InputMethodManager::instance()->setWindow(window);
475}
477}
476
478
477void TopLevelWindowModel::removeInputMethodWindow()
479void TopLevelWindowModel::removeInputMethodWindow()
@@ -480,6 +482,7 @@ void TopLevelWindowModel::removeInputMethodWindow()
480 delete m_inputMethodWindow;
482 delete m_inputMethodWindow;
481 m_inputMethodWindow = nullptr;
483 m_inputMethodWindow = nullptr;
482 Q_EMIT inputMethodSurfaceChanged(nullptr);
484 Q_EMIT inputMethodSurfaceChanged(nullptr);
485+ InputMethodManager::instance()->setWindow(nullptr);
483 }
486 }
484}
487}
485
488
plugins/WindowManager/WindowManagerPlugin.cpp+9
@@ -20,14 +20,23 @@
20#include "TopLevelWindowModel.h"
20#include "TopLevelWindowModel.h"
21#include "Window.h"
21#include "Window.h"
22#include "WindowMargins.h"
22#include "WindowMargins.h"
23+#include "InputMethodManager.h"
23
24
24#include <QtQml>
25#include <QtQml>
25
26
27+QObject *inputMethodManager(QQmlEngine *engine, QJSEngine *scriptEngine)
28+{
29+ Q_UNUSED(engine)
30+ Q_UNUSED(scriptEngine)
31+ return InputMethodManager::instance();
32+}
33+
26void WindowManagerPlugin::registerTypes(const char *uri)
34void WindowManagerPlugin::registerTypes(const char *uri)
27{
35{
28 qmlRegisterType<AvailableDesktopArea>(uri, 1, 0, "AvailableDesktopArea");
36 qmlRegisterType<AvailableDesktopArea>(uri, 1, 0, "AvailableDesktopArea");
29 qmlRegisterType<TopLevelWindowModel>(uri, 1, 0, "TopLevelWindowModel");
37 qmlRegisterType<TopLevelWindowModel>(uri, 1, 0, "TopLevelWindowModel");
30 qmlRegisterType<WindowMargins>(uri, 1, 0, "WindowMargins");
38 qmlRegisterType<WindowMargins>(uri, 1, 0, "WindowMargins");
39+ qmlRegisterSingletonType<InputMethodManager>(uri, 1, 0, "InputMethodManager", inputMethodManager);
31
40
32 qRegisterMetaType<Window*>("Window*");
41 qRegisterMetaType<Window*>("Window*");
33
42
qml/Components/InputMethod.qml+2−1
@@ -17,13 +17,14 @@
17import QtQuick 2.4
17import QtQuick 2.4
18import Unity.Application 0.1
18import Unity.Application 0.1
19import Ubuntu.Gestures 0.1
19import Ubuntu.Gestures 0.1
20+import WindowManager 1.0
20
21
21Item {
22Item {
22 id: root
23 id: root
23
24
24 readonly property rect visibleRect: surfaceItem.surface && visible ? surfaceItem.surface.inputBounds : Qt.rect(0, 0, 0, 0)
25 readonly property rect visibleRect: surfaceItem.surface && visible ? surfaceItem.surface.inputBounds : Qt.rect(0, 0, 0, 0)
25
26
26− property var surface
27+ property var surface: root.enabled ? InputMethodManager.surface : null;
27
28
28 MirSurfaceItem {
29 MirSurfaceItem {
29 id: surfaceItem
30 id: surfaceItem
qml/OrientedShell.qml+7−1
@@ -275,7 +275,13 @@ Item {
275 hasMouse: pointerInputDevices > 0
275 hasMouse: pointerInputDevices > 0
276 hasKeyboard: keyboardsModel.count > 0
276 hasKeyboard: keyboardsModel.count > 0
277 hasTouchscreen: touchScreensModel.count > 0
277 hasTouchscreen: touchScreensModel.count > 0
278+
279+ // Since we dont have proper multiscreen support yet
280+ // hardcode screen count to only show osk on this screen
281+ // when it's the only one connected.
282+ // FIXME once multiscreen has landed
283+ oskEnabled: (!hasKeyboard && screens.count === 1) ||
278− oskEnabled: unity8Settings.alwaysShowOsk || !hasKeyboard || forceOSKEnabled
284+ unity8Settings.alwaysShowOsk || forceOSKEnabled
279
285
280 usageScenario: {
286 usageScenario: {
281 if (unity8Settings.usageMode === "Windowed") {
287 if (unity8Settings.usageMode === "Windowed") {
qml/Shell.qml−1
@@ -373,7 +373,6 @@ StyledItem {
373 InputMethod {
373 InputMethod {
374 id: inputMethod
374 id: inputMethod
375 objectName: "inputMethod"
375 objectName: "inputMethod"
376− surface: topLevelSurfaceList.inputMethodSurface
377 anchors {
376 anchors {
378 fill: parent
377 fill: parent
379 topMargin: panel.panelHeight
378 topMargin: panel.panelHeight