summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel d'Andrada <daniel.dandrada@canonical.com>2014-11-19 11:54:20 -0200
committerDaniel d'Andrada <daniel.dandrada@canonical.com>2014-11-19 11:54:20 -0200
commitbb789d745499fc382905b05755897bca91efad4f (patch)
treeb84aed52a37a1ad6e314ec1ac89950813210ffdc /src
parentd58b959e551181913f2d8312432ccea8ce5821cd (diff)
X-Ubuntu-Supported-Orientations and X-Ubuntu-Rotates-Window-Contents desktop entries
With the corresponding ApplicationInfo.supportedOrientations and ApplicationInfo.rotatesWindowContents properties MirSurfaceItem was also changed to hold an orientationAngle instead of an orientation as that maps directly to the corresponding Mir surface property, making the whole thing easier/simpler.
Diffstat (limited to 'src')
-rw-r--r--src/modules/Unity/Application/application.cpp21
-rw-r--r--src/modules/Unity/Application/application.h19
-rw-r--r--src/modules/Unity/Application/desktopfilereader.cpp77
-rw-r--r--src/modules/Unity/Application/desktopfilereader.h5
-rw-r--r--src/modules/Unity/Application/mirsurfaceitem.cpp43
-rw-r--r--src/modules/Unity/Application/mirsurfaceitem.h15
6 files changed, 128 insertions, 52 deletions
diff --git a/src/modules/Unity/Application/application.cpp b/src/modules/Unity/Application/application.cpp
index 28a1e56..dc22a90 100644
--- a/src/modules/Unity/Application/application.cpp
+++ b/src/modules/Unity/Application/application.cpp
@@ -57,12 +57,14 @@ Application::Application(const QSharedPointer<TaskController>& taskController,
// FIXME(greyback) need to save long appId internally until ubuntu-app-launch can hide it from us
m_longAppId = desktopFileReader->file().remove(QRegExp(".desktop$")).split('/').last();
- // FIXME: This is a hack. Remove once we have a real implementation for knowing the supported
- // orientations of an app
- m_supportedOrientations = PortraitOrientation
- | LandscapeOrientation
- | InvertedPortraitOrientation
- | InvertedLandscapeOrientation;
+ m_supportedOrientations = m_desktopData->supportedOrientations();
+ if (m_supportedOrientations == Qt::PrimaryOrientation) {
+ // Default to all orientations
+ m_supportedOrientations = Qt::PortraitOrientation | Qt::LandscapeOrientation
+ | Qt::InvertedPortraitOrientation | Qt::InvertedLandscapeOrientation;
+ }
+
+ m_rotatesWindowContents = m_desktopData->rotatesWindowContents();
}
Application::~Application()
@@ -345,11 +347,16 @@ QString Application::longAppId() const
return m_longAppId;
}
-Application::SupportedOrientations Application::supportedOrientations() const
+Qt::ScreenOrientations Application::supportedOrientations() const
{
return m_supportedOrientations;
}
+bool Application::rotatesWindowContents() const
+{
+ return m_rotatesWindowContents;
+}
+
Session* Application::session() const
{
return m_session;
diff --git a/src/modules/Unity/Application/application.h b/src/modules/Unity/Application/application.h
index 946f95d..8a76c74 100644
--- a/src/modules/Unity/Application/application.h
+++ b/src/modules/Unity/Application/application.h
@@ -46,27 +46,15 @@ class Application : public unity::shell::application::ApplicationInfoInterface
{
Q_OBJECT
- Q_FLAGS(Orientation SupportedOrientations)
-
Q_PROPERTY(QString desktopFile READ desktopFile CONSTANT)
Q_PROPERTY(QString exec READ exec CONSTANT)
Q_PROPERTY(bool fullscreen READ fullscreen NOTIFY fullscreenChanged)
Q_PROPERTY(Stage stage READ stage WRITE setStage NOTIFY stageChanged)
- Q_PROPERTY(SupportedOrientations supportedOrientations READ supportedOrientations CONSTANT)
Q_PROPERTY(Session* session READ session NOTIFY sessionChanged DESIGNABLE false)
public:
Q_DECLARE_FLAGS(Stages, Stage)
- // Matching Qt::ScreenOrientation values for convenience
- enum Orientation {
- PortraitOrientation = 0x1,
- LandscapeOrientation = 0x2,
- InvertedPortraitOrientation = 0x4,
- InvertedLandscapeOrientation = 0x8
- };
- Q_DECLARE_FLAGS(SupportedOrientations, Orientation)
-
Application(const QSharedPointer<TaskController>& taskController,
DesktopFileReader *desktopFileReader,
State state,
@@ -88,6 +76,8 @@ public:
QColor splashColor() const override;
QColor splashColorHeader() const override;
QColor splashColorFooter() const override;
+ Qt::ScreenOrientations supportedOrientations() const override;
+ bool rotatesWindowContents() const override;
void setStage(Stage stage);
void setState(State state);
@@ -103,7 +93,6 @@ public:
bool fullscreen() const;
Stages supportedStages() const;
- SupportedOrientations supportedOrientations() const;
pid_t pid() const;
@@ -136,7 +125,8 @@ private:
bool m_focused;
bool m_canBeResumed;
QStringList m_arguments;
- SupportedOrientations m_supportedOrientations;
+ Qt::ScreenOrientations m_supportedOrientations;
+ bool m_rotatesWindowContents;
Session *m_session;
friend class ApplicationManager;
@@ -147,6 +137,5 @@ private:
} // namespace qtmir
Q_DECLARE_METATYPE(qtmir::Application*)
-Q_DECLARE_OPERATORS_FOR_FLAGS(qtmir::Application::SupportedOrientations)
#endif // APPLICATION_H
diff --git a/src/modules/Unity/Application/desktopfilereader.cpp b/src/modules/Unity/Application/desktopfilereader.cpp
index 303e55f..5700270 100644
--- a/src/modules/Unity/Application/desktopfilereader.cpp
+++ b/src/modules/Unity/Application/desktopfilereader.cpp
@@ -202,6 +202,83 @@ QString DesktopFileReader::splashColorFooter() const
return d->getKey("X-Ubuntu-Splash-Color-Footer");
}
+Qt::ScreenOrientations DesktopFileReader::supportedOrientations() const
+{
+ Q_D(const DesktopFileReader);
+ Qt::ScreenOrientations result;
+
+ if (!parseOrientations(d->getKey("X-Ubuntu-Supported-Orientations"), result)) {
+ qCWarning(QTMIR_APPLICATIONS) << d->file << "has an invalid X-Ubuntu-Supported-Orientations entry.";
+ }
+
+ return result;
+}
+
+bool DesktopFileReader::rotatesWindowContents() const
+{
+ Q_D(const DesktopFileReader);
+ bool result;
+
+ if (!parseBoolean(d->getKey("X-Ubuntu-Rotates-Window-Contents"), result)) {
+ qCWarning(QTMIR_APPLICATIONS) << d->file << "has an invalid X-Ubuntu-Rotates-Window-Contents entry.";
+ }
+
+ return result;
+}
+
+bool DesktopFileReader::parseOrientations(const QString &rawString, Qt::ScreenOrientations &result)
+{
+ if (rawString.isEmpty()) {
+ result = Qt::PrimaryOrientation;
+ return true;
+ }
+
+ result = 0;
+ bool ok = true;
+
+ QStringList orientationsList = rawString
+ .simplified()
+ .replace(QChar(','), ";")
+ .remove(QChar(' '))
+ .remove(QChar('-'))
+ .remove(QChar('_'))
+ .toLower()
+ .split(";");
+
+ for (int i = 0; i < orientationsList.count(); ++i) {
+ const QString &orientationString = orientationsList.at(i);
+ if (orientationString == "portrait") {
+ result |= Qt::PortraitOrientation;
+ } else if (orientationString == "landscape") {
+ result |= Qt::LandscapeOrientation;
+ } else if (orientationString == "invertedportrait") {
+ result |= Qt::InvertedPortraitOrientation;
+ } else if (orientationString == "invertedlandscape") {
+ result |= Qt::InvertedLandscapeOrientation;
+ } else {
+ ok = false;
+ }
+ }
+
+ return ok;
+}
+
+bool DesktopFileReader::parseBoolean(const QString &rawString, bool &result)
+{
+ QString cookedString = rawString.trimmed().toLower();
+
+ result = cookedString == "y"
+ || cookedString == "1"
+ || cookedString == "yes"
+ || cookedString == "true";
+
+ return result || rawString.isEmpty()
+ || cookedString == "n"
+ || cookedString == "0"
+ || cookedString == "no"
+ || cookedString == "false";
+}
+
bool DesktopFileReader::loaded() const
{
Q_D(const DesktopFileReader);
diff --git a/src/modules/Unity/Application/desktopfilereader.h b/src/modules/Unity/Application/desktopfilereader.h
index f17fbcb..1844096 100644
--- a/src/modules/Unity/Application/desktopfilereader.h
+++ b/src/modules/Unity/Application/desktopfilereader.h
@@ -53,8 +53,13 @@ public:
virtual QString splashColor() const;
virtual QString splashColorHeader() const;
virtual QString splashColorFooter() const;
+ virtual Qt::ScreenOrientations supportedOrientations() const;
+ virtual bool rotatesWindowContents() const;
virtual bool loaded() const;
+ static bool parseOrientations(const QString &rawString, Qt::ScreenOrientations &result);
+ static bool parseBoolean(const QString &rawString, bool &result);
+
protected:
DesktopFileReader(const QString &appId, const QFileInfo &desktopFile);
diff --git a/src/modules/Unity/Application/mirsurfaceitem.cpp b/src/modules/Unity/Application/mirsurfaceitem.cpp
index dfb0373..1156ba5 100644
--- a/src/modules/Unity/Application/mirsurfaceitem.cpp
+++ b/src/modules/Unity/Application/mirsurfaceitem.cpp
@@ -252,7 +252,7 @@ MirSurfaceItem::MirSurfaceItem(std::shared_ptr<mir::scene::Surface> surface,
, m_session(session)
, m_firstFrameDrawn(false)
, m_live(true)
- , m_orientation(Qt::PortraitOrientation)
+ , m_orientationAngle(0)
, m_textureProvider(nullptr)
, m_lastTouchEvent(nullptr)
{
@@ -359,49 +359,42 @@ MirSurfaceItem::State MirSurfaceItem::state() const
return static_cast<MirSurfaceItem::State>(m_surface->state());
}
-Qt::ScreenOrientation MirSurfaceItem::orientation() const
+int MirSurfaceItem::orientationAngle() const
{
- return m_orientation;
+ return m_orientationAngle;
}
-void MirSurfaceItem::setOrientation(const Qt::ScreenOrientation orientation)
+void MirSurfaceItem::setOrientationAngle(int angle)
{
- qCDebug(QTMIR_SURFACES) << "MirSurfaceItem::setOrientation - orientation=" << orientation;
+ qCDebug(QTMIR_SURFACES, "MirSurfaceItem::setOrientationAngle(%d)", angle);
- if (m_orientation == orientation)
+ if (m_orientationAngle == angle)
return;
MirOrientation mirOrientation;
- Qt::ScreenOrientation nativeOrientation = QGuiApplication::primaryScreen()->nativeOrientation();
- const bool landscapeNativeOrientation = (nativeOrientation == Qt::LandscapeOrientation);
- Qt::ScreenOrientation requestedOrientation = orientation;
- if (orientation == Qt::PrimaryOrientation) { // means orientation equals native orientation, set it as such
- requestedOrientation = nativeOrientation;
- }
-
- switch(requestedOrientation) {
- case Qt::PortraitOrientation:
- mirOrientation = (landscapeNativeOrientation) ? mir_orientation_right : mir_orientation_normal;
+ switch (angle) {
+ case 0:
+ mirOrientation = mir_orientation_normal;
break;
- case Qt::LandscapeOrientation:
- mirOrientation = (landscapeNativeOrientation) ? mir_orientation_normal : mir_orientation_left;
+ case 90:
+ mirOrientation = mir_orientation_right;
break;
- case Qt::InvertedPortraitOrientation:
- mirOrientation = (landscapeNativeOrientation) ? mir_orientation_left : mir_orientation_inverted;
+ case 180:
+ mirOrientation = mir_orientation_inverted;
break;
- case Qt::InvertedLandscapeOrientation:
- mirOrientation = (landscapeNativeOrientation) ? mir_orientation_inverted : mir_orientation_right;
+ case 270:
+ mirOrientation = mir_orientation_left;
break;
default:
- qWarning("Unrecognized Qt::ScreenOrientation!");
+ qCWarning(QTMIR_SURFACES, "Unsupported orientation angle: %d", angle);
return;
}
m_surface->set_orientation(mirOrientation);
- m_orientation = orientation;
- Q_EMIT orientationChanged();
+ m_orientationAngle = angle;
+ Q_EMIT orientationAngleChanged(angle);
}
QString MirSurfaceItem::name() const
diff --git a/src/modules/Unity/Application/mirsurfaceitem.h b/src/modules/Unity/Application/mirsurfaceitem.h
index b91094a..989338d 100644
--- a/src/modules/Unity/Application/mirsurfaceitem.h
+++ b/src/modules/Unity/Application/mirsurfaceitem.h
@@ -74,7 +74,11 @@ class MirSurfaceItem : public QQuickItem
Q_PROPERTY(State state READ state NOTIFY stateChanged)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(bool live READ live NOTIFY liveChanged)
- Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged DESIGNABLE false)
+
+ // How many degrees, clockwise, the UI in the surface has to rotate to match with the
+ // shell UI orientation
+ Q_PROPERTY(int orientationAngle READ orientationAngle WRITE setOrientationAngle
+ NOTIFY orientationAngleChanged DESIGNABLE false)
public:
explicit MirSurfaceItem(std::shared_ptr<mir::scene::Surface> surface,
@@ -107,7 +111,6 @@ public:
State state() const;
QString name() const;
bool live() const;
- Qt::ScreenOrientation orientation() const;
SessionInterface *session() const;
Q_INVOKABLE void release();
@@ -121,7 +124,9 @@ public:
bool isFirstFrameDrawn() const { return m_firstFrameDrawn; }
- void setOrientation(const Qt::ScreenOrientation orientation);
+ int orientationAngle() const;
+ void setOrientationAngle(int angle);
+
void setSession(SessionInterface *app);
// to allow easy touch event injection from tests
@@ -134,7 +139,7 @@ Q_SIGNALS:
void typeChanged();
void stateChanged();
void nameChanged();
- void orientationChanged();
+ void orientationAngleChanged(int angle);
void liveChanged(bool live);
void firstFrameDrawn(MirSurfaceItem *item);
@@ -194,7 +199,7 @@ private:
QPointer<SessionInterface> m_session;
bool m_firstFrameDrawn;
bool m_live;
- Qt::ScreenOrientation m_orientation; //FIXME - have to save the state as Mir has no getter for it (bug:1357429)
+ int m_orientationAngle; //FIXME - have to save the state as Mir has no getter for it (bug:1357429)
QMirSurfaceTextureProvider *m_textureProvider;