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
=== modified file 'src/platforms/mirserver/screen.cpp'
--- src/platforms/mirserver/screen.cpp 2014-09-10 15:04:42 +0000
+++ src/platforms/mirserver/screen.cpp 2014-10-22 15:48:16 +0000
@@ -104,11 +104,12 @@
104const QEvent::Type OrientationReadingEvent::m_type =104const QEvent::Type OrientationReadingEvent::m_type =
105 static_cast<QEvent::Type>(QEvent::registerEventType());105 static_cast<QEvent::Type>(QEvent::registerEventType());
106106
107107bool Screen::skipDBusRegistration = false;
108108
109Screen::Screen(mir::graphics::DisplayConfigurationOutput const &screen)109Screen::Screen(mir::graphics::DisplayConfigurationOutput const &screen)
110 : QObject(nullptr)110 : QObject(nullptr)
111 , m_orientationSensor(new QOrientationSensor(this))111 , m_orientationSensor(new QOrientationSensor(this))
112 , m_unityScreen(nullptr)
112{113{
113 readMirDisplayConfiguration(screen);114 readMirDisplayConfiguration(screen);
114115
@@ -125,6 +126,32 @@
125 QObject::connect(m_orientationSensor, &QOrientationSensor::readingChanged,126 QObject::connect(m_orientationSensor, &QOrientationSensor::readingChanged,
126 this, &Screen::onOrientationReadingChanged);127 this, &Screen::onOrientationReadingChanged);
127 m_orientationSensor->start();128 m_orientationSensor->start();
129
130 if (!skipDBusRegistration) {
131 // FIXME This is a unity8 specific dbus call and shouldn't be in qtmir
132 m_unityScreen = new QDBusInterface("com.canonical.Unity.Screen",
133 "/com/canonical/Unity/Screen",
134 "com.canonical.Unity.Screen",
135 QDBusConnection::systemBus(), this);
136
137 m_unityScreen->connection().connect("com.canonical.Unity.Screen",
138 "/com/canonical/Unity/Screen",
139 "com.canonical.Unity.Screen",
140 "DisplayPowerStateChange",
141 this,
142 SLOT(onDisplayPowerStateChanged(int, int)));
143 }
144}
145
146bool Screen::orientationSensorEnabled()
147{
148 return m_orientationSensor->isActive();
149}
150
151void Screen::onDisplayPowerStateChanged(int status, int reason)
152{
153 Q_UNUSED(reason);
154 toggleSensors(status);
128}155}
129156
130void Screen::readMirDisplayConfiguration(mir::graphics::DisplayConfigurationOutput const &screen)157void Screen::readMirDisplayConfiguration(mir::graphics::DisplayConfigurationOutput const &screen)
@@ -147,7 +174,6 @@
147 m_refreshRate = mode.vrefresh_hz;174 m_refreshRate = mode.vrefresh_hz;
148}175}
149176
150// FIXME: nothing is using this method yet, but we should turn off sensors when display is off.
151void Screen::toggleSensors(const bool enable) const177void Screen::toggleSensors(const bool enable) const
152{178{
153 qCDebug(QTMIR_SENSOR_MESSAGES) << "Screen::toggleSensors - enable=" << enable;179 qCDebug(QTMIR_SENSOR_MESSAGES) << "Screen::toggleSensors - enable=" << enable;
154180
=== modified file 'src/platforms/mirserver/screen.h'
--- src/platforms/mirserver/screen.h 2014-08-25 15:26:08 +0000
+++ src/platforms/mirserver/screen.h 2014-10-22 15:48:16 +0000
@@ -22,6 +22,7 @@
2222
23#include <QObject>23#include <QObject>
24#include <QTimer>24#include <QTimer>
25#include <QtDBus/QDBusInterface>
25#include <qpa/qplatformscreen.h>26#include <qpa/qplatformscreen.h>
2627
27#include "mir/graphics/display_configuration.h"28#include "mir/graphics/display_configuration.h"
@@ -48,7 +49,12 @@
48 // QObject methods.49 // QObject methods.
49 void customEvent(QEvent* event) override;50 void customEvent(QEvent* event) override;
5051
52 // To make it testable
53 static bool skipDBusRegistration;
54 bool orientationSensorEnabled();
55
51public Q_SLOTS:56public Q_SLOTS:
57 void onDisplayPowerStateChanged(int, int);
52 void onOrientationReadingChanged();58 void onOrientationReadingChanged();
5359
54private:60private:
@@ -63,6 +69,8 @@
63 Qt::ScreenOrientation m_nativeOrientation;69 Qt::ScreenOrientation m_nativeOrientation;
64 Qt::ScreenOrientation m_currentOrientation;70 Qt::ScreenOrientation m_currentOrientation;
65 QOrientationSensor *m_orientationSensor;71 QOrientationSensor *m_orientationSensor;
72
73 QDBusInterface *m_unityScreen;
66};74};
6775
68#endif // SCREEN_H76#endif // SCREEN_H
6977
=== added directory 'tests/mirserver/Screen'
=== added file 'tests/mirserver/Screen/Screen.pro'
--- tests/mirserver/Screen/Screen.pro 1970-01-01 00:00:00 +0000
+++ tests/mirserver/Screen/Screen.pro 2014-10-22 15:48:16 +0000
@@ -0,0 +1,16 @@
1include(../../test-includes.pri)
2
3TARGET = ScreenTest
4
5QT += gui-private
6
7INCLUDEPATH += \
8 ../../../src/platforms/mirserver \
9 ../../../src/common
10
11SOURCES += \
12 screen_test.cpp \
13 ../../../src/common/debughelpers.cpp
14
15LIBS += -Wl,-rpath,$${OUT_PWD}/../../../src/platforms/mirserver \
16 -L../../../src/platforms/mirserver -lqpa-mirserver
017
=== added file 'tests/mirserver/Screen/screen_test.cpp'
--- tests/mirserver/Screen/screen_test.cpp 1970-01-01 00:00:00 +0000
+++ tests/mirserver/Screen/screen_test.cpp 2014-10-22 15:48:16 +0000
@@ -0,0 +1,65 @@
1/*
2 * Copyright (C) 2014 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
18#include <gmock/gmock.h>
19#include <gtest/gtest.h>
20
21#include "mir/graphics/display_configuration.h"
22
23#include <screen.h>
24
25namespace mg = mir::graphics;
26namespace geom = mir::geometry;
27
28mg::DisplayConfigurationOutput const fake_output
29{
30 mg::DisplayConfigurationOutputId{3},
31 mg::DisplayConfigurationCardId{2},
32 mg::DisplayConfigurationOutputType::dvid,
33 {
34 mir_pixel_format_abgr_8888
35 },
36 {
37 {geom::Size{10, 20}, 60.0},
38 {geom::Size{10, 20}, 59.0},
39 {geom::Size{15, 20}, 59.0}
40 },
41 0,
42 geom::Size{10, 20},
43 true,
44 true,
45 geom::Point(),
46 2,
47 mir_pixel_format_abgr_8888,
48 mir_power_mode_on,
49 mir_orientation_normal
50};
51
52TEST(ScreenTest, OrientationSensor)
53{
54 Screen::skipDBusRegistration = true;
55 Screen *screen = new Screen(fake_output);
56
57 // Default state should be active
58 ASSERT_TRUE(screen->orientationSensorEnabled());
59
60 screen->onDisplayPowerStateChanged(0,0);
61 ASSERT_FALSE(screen->orientationSensorEnabled());
62
63 screen->onDisplayPowerStateChanged(1,0);
64 ASSERT_TRUE(screen->orientationSensorEnabled());
65}
066
=== modified file 'tests/mirserver/mirserver.pro'
--- tests/mirserver/mirserver.pro 2014-09-22 17:26:06 +0000
+++ tests/mirserver/mirserver.pro 2014-10-22 15:48:16 +0000
@@ -1,2 +1,2 @@
1TEMPLATE = subdirs1TEMPLATE = subdirs
2SUBDIRS = QtEventFeeder Clipboard2SUBDIRS = QtEventFeeder Clipboard Screen

Subscribers

People subscribed via source and target branches