Merge lp:~robertcarr/unity-mir/default-input-focus into lp:unity-mir

Proposed by Robert Carr
Status: Superseded
Proposed branch: lp:~robertcarr/unity-mir/default-input-focus
Merge into: lp:unity-mir
Diff against target: 233 lines (+140/-2)
6 files modified
src/modules/Unity/Application/mirsurfacemanager.cpp (+4/-0)
src/unity-mir/focussetter.cpp (+56/-0)
src/unity-mir/focussetter.h (+56/-0)
src/unity-mir/shellserverconfiguration.cpp (+16/-0)
src/unity-mir/shellserverconfiguration.h (+4/-0)
src/unity-mir/unity-mir.pro (+4/-2)
To merge this branch: bzr merge lp:~robertcarr/unity-mir/default-input-focus
Reviewer Review Type Date Requested Status
Gerry Boland (community) code review Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+189733@code.launchpad.net

This proposal has been superseded by a proposal from 2013-10-08.

Commit message

Focus the shell when no sessions are focused.

It's difficult with the current architecture for the shell to receive keyboard focus, as it does not have an associated application session. Work around this by implementing a defaulting FocusSetter, which assigns keyboard focus to the shell surface when focus would otherwise be cleared.

Description of the change

It's difficult with the current architecture for the shell to receive keyboard focus, as it does not have an associated application session. Work around this by implementing a defaulting FocusSetter, which assigns keyboard focus to the shell surface when focus would otherwise be cleared.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

Please adjust commit message to prepend a short description of the change - the discursive bit afterwards is fine.

+std::shared_ptr<mir::shell::FocusSetter> the_shell_focus_setter() override;
please fix the indent.

Code looks clean. Otherwise.

review: Approve (code review)

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/modules/Unity/Application/mirsurfacemanager.cpp'
2--- src/modules/Unity/Application/mirsurfacemanager.cpp 2013-09-06 05:34:01 +0000
3+++ src/modules/Unity/Application/mirsurfacemanager.cpp 2013-10-07 23:19:43 +0000
4@@ -28,6 +28,7 @@
5 #include "sessionlistener.h"
6 #include "surfaceconfigurator.h"
7 #include "surfacesource.h"
8+#include "focussetter.h"
9 #include "logging.h"
10
11 namespace msh = mir::shell;
12@@ -125,6 +126,9 @@
13 {
14 DLOG("MirSurfaceManager::shellSurfaceCreated (this=%p)", this);
15 m_shellSurface = new MirSurface(surface, nullptr);
16+
17+ m_mirServer->focusSetter()->set_default_keyboard_target(surface);
18+
19 Q_EMIT shellSurfaceChanged(m_shellSurface);
20 }
21
22
23=== added file 'src/unity-mir/focussetter.cpp'
24--- src/unity-mir/focussetter.cpp 1970-01-01 00:00:00 +0000
25+++ src/unity-mir/focussetter.cpp 2013-10-07 23:19:43 +0000
26@@ -0,0 +1,56 @@
27+/*
28+ * Copyright (C) 2013 Canonical, Ltd.
29+ *
30+ * This program is free software: you can redistribute it and/or modify it under
31+ * the terms of the GNU Lesser General Public License version 3, as published by
32+ * the Free Software Foundation.
33+ *
34+ * This program is distributed in the hope that it will be useful, but WITHOUT
35+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
36+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
37+ * Lesser General Public License for more details.
38+ *
39+ * You should have received a copy of the GNU Lesser General Public License
40+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
41+ */
42+
43+#include <mir/shell/surface.h>
44+
45+#include "focussetter.h"
46+#include "logging.h"
47+
48+namespace msh = mir::shell;
49+
50+FocusSetter::FocusSetter(std::shared_ptr<msh::FocusSetter> const& underlying_setter, std::shared_ptr<mir::shell::InputTargeter> const& keyboard_input_targeter, QObject *parent)
51+ : QObject(parent),
52+ underlying_setter(underlying_setter),
53+ keyboard_input_targeter(keyboard_input_targeter)
54+{
55+}
56+
57+FocusSetter::~FocusSetter()
58+{
59+}
60+
61+void FocusSetter::set_focus_to(std::shared_ptr<msh::Session> const& session)
62+{
63+ // Ensure we always call the underlying setter to dispatch focus/unfocus notifications.
64+ underlying_setter->set_focus_to(session);
65+ if (session == nullptr)
66+ {
67+ auto default_target = default_keyboard_target.lock();
68+ if (!default_target)
69+ return;
70+ default_target->take_input_focus(keyboard_input_targeter);
71+ }
72+}
73+
74+void FocusSetter::set_default_keyboard_target(std::weak_ptr<msh::Surface> const& default_target)
75+{
76+ auto t = default_target.lock();
77+ assert(t);
78+
79+ default_keyboard_target = default_target;
80+
81+ t->take_input_focus(keyboard_input_targeter);
82+}
83
84=== added file 'src/unity-mir/focussetter.h'
85--- src/unity-mir/focussetter.h 1970-01-01 00:00:00 +0000
86+++ src/unity-mir/focussetter.h 2013-10-07 23:19:43 +0000
87@@ -0,0 +1,56 @@
88+/*
89+ * Copyright (C) 2013 Canonical, Ltd.
90+ *
91+ * This program is free software: you can redistribute it and/or modify it under
92+ * the terms of the GNU Lesser General Public License version 3, as published by
93+ * the Free Software Foundation.
94+ *
95+ * This program is distributed in the hope that it will be useful, but WITHOUT
96+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
97+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
98+ * Lesser General Public License for more details.
99+ *
100+ * You should have received a copy of the GNU Lesser General Public License
101+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
102+ */
103+
104+#ifndef FOCUSSETTER_H
105+#define FOCUSSETTER_H
106+
107+// mir
108+#include <mir/shell/focus_setter.h>
109+
110+// Qt
111+#include <QObject>
112+
113+namespace mir
114+{
115+namespace shell
116+{
117+class InputTargeter;
118+class Surface;
119+}
120+}
121+
122+class FocusSetter : public QObject, public mir::shell::FocusSetter
123+{
124+ Q_OBJECT
125+
126+public:
127+ FocusSetter(std::shared_ptr<mir::shell::FocusSetter> const& underlying_setter, std::shared_ptr<mir::shell::InputTargeter> const& keyboard_input_targeter,
128+ QObject *parent = 0);
129+ ~FocusSetter();
130+
131+ void set_focus_to(std::shared_ptr<mir::shell::Session> const& session) override;
132+
133+ // We support a surface to be given key input when focus is otherwise to be cleared.
134+ void set_default_keyboard_target(std::weak_ptr<mir::shell::Surface> const& default_keyboard_target);
135+
136+private:
137+ std::shared_ptr<mir::shell::FocusSetter> const underlying_setter;
138+ std::shared_ptr<mir::shell::InputTargeter> const keyboard_input_targeter;
139+
140+ std::weak_ptr<mir::shell::Surface> default_keyboard_target;
141+};
142+
143+#endif // FOCUSSETTER_H
144
145=== modified file 'src/unity-mir/shellserverconfiguration.cpp'
146--- src/unity-mir/shellserverconfiguration.cpp 2013-08-21 23:10:11 +0000
147+++ src/unity-mir/shellserverconfiguration.cpp 2013-10-07 23:19:43 +0000
148@@ -22,6 +22,7 @@
149 #include "surfacesource.h"
150 #include "sessionauthorizer.h"
151 #include "surfacecontroller.h"
152+#include "focussetter.h"
153 #include "logging.h"
154
155 // mir
156@@ -107,6 +108,16 @@
157 });
158 }
159
160+std::shared_ptr<msh::FocusSetter>
161+ShellServerConfiguration::the_shell_focus_setter()
162+{
163+ return shell_focus_setter(
164+ [this]
165+ {
166+ return std::make_shared<FocusSetter>(DefaultServerConfiguration::the_shell_focus_setter(), the_input_targeter());
167+ });
168+}
169+
170 /************************************ Shell side ************************************/
171 SessionAuthorizer *ShellServerConfiguration::sessionAuthorizer()
172 {
173@@ -130,3 +141,8 @@
174 {
175 return m_surfaceSource.get();
176 }
177+
178+FocusSetter *ShellServerConfiguration::focusSetter()
179+{
180+ return static_cast<FocusSetter*>(the_shell_focus_setter().get());
181+}
182
183=== modified file 'src/unity-mir/shellserverconfiguration.h'
184--- src/unity-mir/shellserverconfiguration.h 2013-08-21 23:10:11 +0000
185+++ src/unity-mir/shellserverconfiguration.h 2013-10-07 23:19:43 +0000
186@@ -20,6 +20,8 @@
187 #include <QObject>
188 #include <mir/default_server_configuration.h>
189
190+
191+class FocusSetter;
192 class SessionListener;
193 class SessionAuthorizer;
194 class SurfaceSource;
195@@ -43,6 +45,7 @@
196 std::shared_ptr<mir::shell::SessionListener> the_shell_session_listener() override;
197 std::shared_ptr<mir::shell::SurfaceConfigurator> the_shell_surface_configurator() override;
198 std::shared_ptr<mir::shell::SurfaceFactory> the_shell_surface_factory() override;
199+std::shared_ptr<mir::shell::FocusSetter> the_shell_focus_setter() override;
200 std::shared_ptr<mir::frontend::SessionAuthorizer> the_session_authorizer() override;
201 std::shared_ptr<mir::surfaces::SurfaceController> the_surface_controller() override;
202
203@@ -52,6 +55,7 @@
204 SessionListener *sessionListener();
205 SurfaceConfigurator *surfaceConfigurator();
206 SurfaceSource *surfaceSource();
207+ FocusSetter *focusSetter();
208
209 protected:
210 std::shared_ptr<SurfaceSource> m_surfaceSource;
211
212=== modified file 'src/unity-mir/unity-mir.pro'
213--- src/unity-mir/unity-mir.pro 2013-09-26 09:51:23 +0000
214+++ src/unity-mir/unity-mir.pro 2013-10-07 23:19:43 +0000
215@@ -23,7 +23,8 @@
216 shellserverconfiguration.cpp \
217 surfacecontroller.cpp \
218 surfacesource.cpp \
219- surfaceconfigurator.cpp
220+ surfaceconfigurator.cpp \
221+ focussetter.cpp
222
223 HEADERS += \
224 dbusscreen.h \
225@@ -36,7 +37,8 @@
226 surfacecontroller.h \
227 surfacesource.h \
228 surfaceconfigurator.h \
229- logging.h
230+ logging.h \
231+ focussetter.h
232
233 target.path = $$[QT_INSTALL_LIBS]
234

Subscribers

People subscribed via source and target branches