Merge lp:~josharenson/qtmir/disable_orientation_sensors_based_on_screen_state into lp:qtmir

Proposed by Josh Arenson
Status: Merged
Approved by: Daniel d'Andrada
Approved revision: 274
Merged at revision: 279
Proposed branch: lp:~josharenson/qtmir/disable_orientation_sensors_based_on_screen_state
Merge into: lp:qtmir
Diff against target: 192 lines (+118/-3)
5 files modified
src/platforms/mirserver/screen.cpp (+28/-2)
src/platforms/mirserver/screen.h (+8/-0)
tests/mirserver/Screen/Screen.pro (+16/-0)
tests/mirserver/Screen/screen_test.cpp (+65/-0)
tests/mirserver/mirserver.pro (+1/-1)
To merge this branch: bzr merge lp:~josharenson/qtmir/disable_orientation_sensors_based_on_screen_state
Reviewer Review Type Date Requested Status
Gerry Boland (community) Approve
Daniel d'Andrada (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+238606@code.launchpad.net

Commit message

Add support for enabling/disabling orientation sensor based on screen power state.

Description of the change

* Are there any related MPs required for this MP to build/function as expected? Please list.
No

 * Did you perform an exploratory manual test run of your code change and any related functionality?
Yes

 * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
N/A

Fix lp:1375297

This turns the orientation sensor on or off depending on the power state of the screen.

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

Fix whitespace issues

271. By Josh Arenson

Remove leftover tab

272. By Josh Arenson

Add FIXME

273. By Josh Arenson

Fix whitespace

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
274. By Josh Arenson

Change unityScreen to m_unityScreen as it is a member variable

Revision history for this message
Daniel d'Andrada (dandrader) wrote :

Looks good to me.

* Did you perform an exploratory manual test run of the code change and any related functionality?
Yes.

* Did CI run pass? If not, please explain why.
Yes.

review: Approve
Revision history for this message
Gerry Boland (gerboland) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/platforms/mirserver/screen.cpp'
2--- src/platforms/mirserver/screen.cpp 2014-09-10 15:04:42 +0000
3+++ src/platforms/mirserver/screen.cpp 2014-10-22 15:48:16 +0000
4@@ -104,11 +104,12 @@
5 const QEvent::Type OrientationReadingEvent::m_type =
6 static_cast<QEvent::Type>(QEvent::registerEventType());
7
8-
9+bool Screen::skipDBusRegistration = false;
10
11 Screen::Screen(mir::graphics::DisplayConfigurationOutput const &screen)
12 : QObject(nullptr)
13 , m_orientationSensor(new QOrientationSensor(this))
14+ , m_unityScreen(nullptr)
15 {
16 readMirDisplayConfiguration(screen);
17
18@@ -125,6 +126,32 @@
19 QObject::connect(m_orientationSensor, &QOrientationSensor::readingChanged,
20 this, &Screen::onOrientationReadingChanged);
21 m_orientationSensor->start();
22+
23+ if (!skipDBusRegistration) {
24+ // FIXME This is a unity8 specific dbus call and shouldn't be in qtmir
25+ m_unityScreen = new QDBusInterface("com.canonical.Unity.Screen",
26+ "/com/canonical/Unity/Screen",
27+ "com.canonical.Unity.Screen",
28+ QDBusConnection::systemBus(), this);
29+
30+ m_unityScreen->connection().connect("com.canonical.Unity.Screen",
31+ "/com/canonical/Unity/Screen",
32+ "com.canonical.Unity.Screen",
33+ "DisplayPowerStateChange",
34+ this,
35+ SLOT(onDisplayPowerStateChanged(int, int)));
36+ }
37+}
38+
39+bool Screen::orientationSensorEnabled()
40+{
41+ return m_orientationSensor->isActive();
42+}
43+
44+void Screen::onDisplayPowerStateChanged(int status, int reason)
45+{
46+ Q_UNUSED(reason);
47+ toggleSensors(status);
48 }
49
50 void Screen::readMirDisplayConfiguration(mir::graphics::DisplayConfigurationOutput const &screen)
51@@ -147,7 +174,6 @@
52 m_refreshRate = mode.vrefresh_hz;
53 }
54
55-// FIXME: nothing is using this method yet, but we should turn off sensors when display is off.
56 void Screen::toggleSensors(const bool enable) const
57 {
58 qCDebug(QTMIR_SENSOR_MESSAGES) << "Screen::toggleSensors - enable=" << enable;
59
60=== modified file 'src/platforms/mirserver/screen.h'
61--- src/platforms/mirserver/screen.h 2014-08-25 15:26:08 +0000
62+++ src/platforms/mirserver/screen.h 2014-10-22 15:48:16 +0000
63@@ -22,6 +22,7 @@
64
65 #include <QObject>
66 #include <QTimer>
67+#include <QtDBus/QDBusInterface>
68 #include <qpa/qplatformscreen.h>
69
70 #include "mir/graphics/display_configuration.h"
71@@ -48,7 +49,12 @@
72 // QObject methods.
73 void customEvent(QEvent* event) override;
74
75+ // To make it testable
76+ static bool skipDBusRegistration;
77+ bool orientationSensorEnabled();
78+
79 public Q_SLOTS:
80+ void onDisplayPowerStateChanged(int, int);
81 void onOrientationReadingChanged();
82
83 private:
84@@ -63,6 +69,8 @@
85 Qt::ScreenOrientation m_nativeOrientation;
86 Qt::ScreenOrientation m_currentOrientation;
87 QOrientationSensor *m_orientationSensor;
88+
89+ QDBusInterface *m_unityScreen;
90 };
91
92 #endif // SCREEN_H
93
94=== added directory 'tests/mirserver/Screen'
95=== added file 'tests/mirserver/Screen/Screen.pro'
96--- tests/mirserver/Screen/Screen.pro 1970-01-01 00:00:00 +0000
97+++ tests/mirserver/Screen/Screen.pro 2014-10-22 15:48:16 +0000
98@@ -0,0 +1,16 @@
99+include(../../test-includes.pri)
100+
101+TARGET = ScreenTest
102+
103+QT += gui-private
104+
105+INCLUDEPATH += \
106+ ../../../src/platforms/mirserver \
107+ ../../../src/common
108+
109+SOURCES += \
110+ screen_test.cpp \
111+ ../../../src/common/debughelpers.cpp
112+
113+LIBS += -Wl,-rpath,$${OUT_PWD}/../../../src/platforms/mirserver \
114+ -L../../../src/platforms/mirserver -lqpa-mirserver
115
116=== added file 'tests/mirserver/Screen/screen_test.cpp'
117--- tests/mirserver/Screen/screen_test.cpp 1970-01-01 00:00:00 +0000
118+++ tests/mirserver/Screen/screen_test.cpp 2014-10-22 15:48:16 +0000
119@@ -0,0 +1,65 @@
120+/*
121+ * Copyright (C) 2014 Canonical, Ltd.
122+ *
123+ * This program is free software: you can redistribute it and/or modify it under
124+ * the terms of the GNU Lesser General Public License version 3, as published by
125+ * the Free Software Foundation.
126+ *
127+ * This program is distributed in the hope that it will be useful, but WITHOUT
128+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
129+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
130+ * Lesser General Public License for more details.
131+ *
132+ * You should have received a copy of the GNU Lesser General Public License
133+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
134+ *
135+ */
136+
137+#include <gmock/gmock.h>
138+#include <gtest/gtest.h>
139+
140+#include "mir/graphics/display_configuration.h"
141+
142+#include <screen.h>
143+
144+namespace mg = mir::graphics;
145+namespace geom = mir::geometry;
146+
147+mg::DisplayConfigurationOutput const fake_output
148+{
149+ mg::DisplayConfigurationOutputId{3},
150+ mg::DisplayConfigurationCardId{2},
151+ mg::DisplayConfigurationOutputType::dvid,
152+ {
153+ mir_pixel_format_abgr_8888
154+ },
155+ {
156+ {geom::Size{10, 20}, 60.0},
157+ {geom::Size{10, 20}, 59.0},
158+ {geom::Size{15, 20}, 59.0}
159+ },
160+ 0,
161+ geom::Size{10, 20},
162+ true,
163+ true,
164+ geom::Point(),
165+ 2,
166+ mir_pixel_format_abgr_8888,
167+ mir_power_mode_on,
168+ mir_orientation_normal
169+};
170+
171+TEST(ScreenTest, OrientationSensor)
172+{
173+ Screen::skipDBusRegistration = true;
174+ Screen *screen = new Screen(fake_output);
175+
176+ // Default state should be active
177+ ASSERT_TRUE(screen->orientationSensorEnabled());
178+
179+ screen->onDisplayPowerStateChanged(0,0);
180+ ASSERT_FALSE(screen->orientationSensorEnabled());
181+
182+ screen->onDisplayPowerStateChanged(1,0);
183+ ASSERT_TRUE(screen->orientationSensorEnabled());
184+}
185
186=== modified file 'tests/mirserver/mirserver.pro'
187--- tests/mirserver/mirserver.pro 2014-09-22 17:26:06 +0000
188+++ tests/mirserver/mirserver.pro 2014-10-22 15:48:16 +0000
189@@ -1,2 +1,2 @@
190 TEMPLATE = subdirs
191-SUBDIRS = QtEventFeeder Clipboard
192+SUBDIRS = QtEventFeeder Clipboard Screen

Subscribers

People subscribed via source and target branches