Skip to content

Instantly share code, notes, and snippets.

@xkr47

xkr47/myapp.cpp

Forked from kimmoli/myclass.cpp
Last active Aug 29, 2015
Embed
What would you like to do?
Disable SailfishOS app cover animation when cover is not visible
...
#include "myclass.h"
...
int main(int argc, char *argv[])
{
qmlRegisterType<myclass>("harbour.myapp.myclass", 1, 0, "myclass");
...
}
#include <QDBusConnection>
#include "myclass.h"
myclass::myclass(QObject *parent) :
QObject(parent),
m_coverStatus(0),
m_displayStatus("on"),
m_deviceLock(0),
m_coverVisible(false)
{
QDBusConnection::sessionBus().connect("", "/com/jolla/lipstick", "com.jolla.lipstick", "coverstatus",
this, SLOT(handleCoverstatus(const QDBusMessage&)));
QDBusConnection::systemBus().connect("", "/com/nokia/mce/signal", "com.nokia.mce.signal", "display_status_ind",
this, SLOT(handleDisplaystatus(const QDBusMessage&)));
QDBusConnection::systemBus().connect("", "/devicelock", "org.nemomobile.lipstick.devicelock", "stateChanged",
this, SLOT(handleDeviceLockChange(const QDBusMessage&)));
}
void myclass::handleCoverstatus(const QDBusMessage& msg)
{
QList<QVariant> args = msg.arguments();
m_coverStatus = args.at(0).toInt();
emit coverStatusChanged();
this->handleCovervisible();
}
void myclass::handleDisplaystatus(const QDBusMessage& msg)
{
QList<QVariant> args = msg.arguments();
m_displayStatus = args.at(0).toString();
emit displayStatusChanged();
this->handleCovervisible();
}
void SystemStatus::handleDevicelock(const QDBusMessage& msg)
{
QList<QVariant> args = msg.arguments();
m_deviceLock = args.at(0).toInt();
emit deviceLockChanged();
this->handleCovervisible();
}
void SystemStatus::handleCovervisible() {
bool newCoverVisible = m_coverStatus != 0 && m_displayStatus != "off" && m_deviceLock == 0;
if (newCoverVisible != m_coverVisible) {
m_coverVisible = newCoverVisible;
emit coverVisibleChanged();
}
}
#ifndef MYCLASS_H
#define MYCLASS_H
#include <QDBusMessage>
class myclass : public QObject
{
Q_OBJECT
public:
Q_PROPERTY(int coverStatus READ getCoverStatus NOTIFY coverStatusChanged())
Q_PROPERTY(QString displayStatus READ getDisplayStatus NOTIFY displayStatusChanged())
Q_PROPERTY(int deviceLock READ getDeviceLock NOTIFY deviceLockChanged())
Q_PROPERTY(bool coverVisible READ getCoverVisible NOTIFY coverVisibleChanged())
explicit myclass(QObject *parent = 0);
public:
int getCoverStatus() { return m_coverStatus; }
QString getDisplayStatus() { return m_displayStatus; }
int getDeviceLock() { return m_deviceLock; }
bool getCoverVisible() { return m_coverVisible; }
public slots:
void handleCoverstatus(const QDBusMessage& msg);
void handleDisplaystatus(const QDBusMessage& msg);
void handleDevicelock(const QDBusMessage& msg);
private:
void handleCovervisible();
signals:
void coverStatusChanged();
void displayStatusChanged();
void deviceLockChanged();
void coverVisibleChanged();
private:
int m_coverStatus;
QString m_displayStatus;
int m_deviceLock;
bool m_coverVisible;
};
#endif // MYCLASS_H
QT += dbus
BuildRequires: pkgconfig(Qt5DBus)
# ... or in yourapp.yaml:
#
# PkgConfigBR:
# ...
# - Qt5DBus
...
import harbour.myapp.myclass 1.0
...
myclass {
id: myclass
}
Timer
{
id: coverRefreshTimer
interval: 500
running: myclass.coverVisible // timer only active when cover is visible
repeat: true
onTriggered: updateCover()
}
@xkr47

This comment has been minimized.

Copy link
Owner Author

@xkr47 xkr47 commented Jun 30, 2015

  • coverStatus
    • 0 when home screen is not visible
    • 1 when home screen is becoming visible
    • 2 when home screen is visible (e.g. covers are visible)
    • 3 when home screen is becoming invisible
    • Please note home screen might be considered visible even if it is covered by the device unlock screen or when the display is off. Therefore we also check the other parameters below.
  • displayStatus
    • "on" when display on
    • "dimmed" when about to turn off in a few seconds
    • "off" when off
  • deviceLock
    • 0 when device is not locked
    • 1 when locked
  • coverVisible - combination of the above properties - coverStatus != 0 && displayStatus != "off" && deviceLock == 0
    • true when cover is visible to the user
    • false when cover is not visible to the user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment