diff --git a/api/dbus/org.desktopspec.ApplicationManager1.Application.xml b/api/dbus/org.desktopspec.ApplicationManager1.Application.xml index f5a48ed..cf18f2f 100644 --- a/api/dbus/org.desktopspec.ApplicationManager1.Application.xml +++ b/api/dbus/org.desktopspec.ApplicationManager1.Application.xml @@ -41,6 +41,21 @@ /> + + + + + + + + storage) : QObject(parent) + , m_scaleFactor(getScaleFactor()) , m_storage(std::move(storage)) , m_desktopSource(std::move(source)) { @@ -43,8 +44,33 @@ ApplicationService::ApplicationService(DesktopFile source, } return; } - m_lastLaunch = value.toInt(); + + value = storagePtr->readApplicationValue(appId, ApplicationPropertiesGroup, ScaleFactor); + if (!value.isNull()) { + bool ok{false}; + auto tmp = value.toDouble(&ok); + if (ok) { + m_scaleFactor = tmp; + m_customScale = true; + } + } + + if (!QDBusConnection::sessionBus().connect("org.deepin.dde.XSettings1", + "/org/deepin/dde/XSettings1", + "org.deepin.dde.XSettings1", + "SetScaleFactorDone", + this, + SLOT(onGlobalScaleFactorChanged()))) { + qWarning() << "connect to org.deepin.dde.XSettings1 failed, scaleFactor is invalid."; + } +} + +void ApplicationService::onGlobalScaleFactorChanged() noexcept +{ + if (!m_customScale) { + m_scaleFactor = getScaleFactor(); + } } ApplicationService::~ApplicationService() @@ -192,7 +218,14 @@ QDBusObjectPath ApplicationService::Launch(const QString &action, const QStringL return {}; } + if (terminal()) { + // don't change this sequence + execCmds.push_front("-C"); // means run a shellscript + execCmds.push_front("--keep-open"); // keep terminal open, prevent exit immediately + execCmds.push_front("deepin-terminal"); + } cmds.append(std::move(execCmds)); + auto &jobManager = parent()->jobManager(); return jobManager.addJob( m_applicationPath.path(), @@ -430,6 +463,15 @@ bool ApplicationService::x_linglong() const noexcept return !val.isNull(); } +bool ApplicationService::terminal() const noexcept +{ + auto val = findEntryValue(DesktopFileEntryKey, "Terminal", EntryValueType::String); + if (!val.isNull()) { + return val.toBool(); + } + return false; +} + qulonglong ApplicationService::installedTime() const noexcept { return m_desktopSource.createTime(); @@ -440,6 +482,47 @@ qulonglong ApplicationService::lastLaunchedTime() const noexcept return m_lastLaunch; } +double ApplicationService::scaleFactor() const noexcept +{ + return m_scaleFactor; +} + +void ApplicationService::setScaleFactor(double value) noexcept +{ + if (value == m_scaleFactor) { + return; + } + + auto storagePtr = m_storage.lock(); + if (!storagePtr) { + qCritical() << "broken storage."; + sendErrorReply(QDBusError::InternalError); + return; + } + + auto appId = id(); + if (value == 0) { + m_customScale = false; + m_scaleFactor = getScaleFactor(); + storagePtr->deleteApplicationValue(appId, ApplicationPropertiesGroup, ScaleFactor); + return; + } + + if(m_customScale){ + if (!storagePtr->updateApplicationValue(appId, ApplicationPropertiesGroup, ScaleFactor, value)) { + sendErrorReply(QDBusError::Failed,"update scaleFactor failed."); + return; + } + } else { + if (!storagePtr->createApplicationValue(appId, ApplicationPropertiesGroup, ScaleFactor, value)) { + sendErrorReply(QDBusError::Failed, "set scaleFactor failed."); + } + } + + m_scaleFactor = value; + emit scaleFactorChanged(); +} + bool ApplicationService::autostartCheck(const QString &linkPath) const noexcept { QFileInfo info{linkPath}; @@ -640,6 +723,8 @@ void ApplicationService::resetEntry(DesktopEntry *newEntry) noexcept emit actionsChanged(); emit categoriesChanged(); emit MimeTypesChanged(); + emit terminalChanged(); + emit scaleFactorChanged(); } LaunchTask ApplicationService::unescapeExec(const QString &str, const QStringList &fields) @@ -854,6 +939,23 @@ void ApplicationService::updateAfterLaunch(bool isLaunch) noexcept } } +double getScaleFactor() noexcept +{ + auto sessionBus = QDBusConnection::sessionBus(); + QDBusMessage reply1 = sessionBus.call(QDBusMessage::createMethodCall( + "org.deepin.dde.XSettings1", "/org/deepin/dde/XSettings1", "org.deepin.dde.XSettings1", "GetScaleFactor")); + + if (reply1.type() != QDBusMessage::ReplyMessage) { + qWarning() << "call GetScaleFactor Failed:" << reply1.errorMessage(); + return 1.0; + } + + QDBusReply ret1(reply1); + double scale = ret1.isValid() ? ret1.value() : 1.0; + scale = scale > 0 ? scale : 1; + return scale; +} + QString getDeepinWineScaleFactor(const QString &appId) noexcept { qCritical() << "Don't using env to control the window scale factor, this function" @@ -888,19 +990,7 @@ QString getDeepinWineScaleFactor(const QString &appId) noexcept } } - auto sessionBus = QDBusConnection::sessionBus(); - QDBusMessage reply1 = sessionBus.call(QDBusMessage::createMethodCall( - "org.deepin.dde.XSettings1", "/org/deepin/dde/XSettings1", "org.deepin.dde.XSettings1", "GetScaleFactor")); - - if (reply1.type() != QDBusMessage::ReplyMessage) { - qWarning() << "call GetScaleFactor Failed:" << reply1.errorMessage(); - return factor; - } - - QDBusReply ret1(reply1); - double scale = ret1.isValid() ? ret1.value() : 1.0; - scale = scale > 0 ? scale : 1; + auto scale = getScaleFactor(); factor = QString::number(scale, 'f', -1); - return factor; } diff --git a/src/dbus/applicationservice.h b/src/dbus/applicationservice.h index 281d94c..2f8a190 100644 --- a/src/dbus/applicationservice.h +++ b/src/dbus/applicationservice.h @@ -26,6 +26,7 @@ #include "applicationmanager1service.h" QString getDeepinWineScaleFactor(const QString &appId) noexcept; +double getScaleFactor() noexcept; class ApplicationService : public QObject, public QDBusContext { @@ -61,6 +62,13 @@ public: Q_PROPERTY(qulonglong LastLaunchedTime READ lastLaunchedTime NOTIFY lastLaunchedTimeChanged) [[nodiscard]] qulonglong lastLaunchedTime() const noexcept; + Q_PROPERTY(double ScaleFactor READ scaleFactor WRITE setScaleFactor NOTIFY scaleFactorChanged) + [[nodiscard]] double scaleFactor() const noexcept; + void setScaleFactor(double value) noexcept; + + Q_PROPERTY(bool Terminal READ terminal NOTIFY terminalChanged) + [[nodiscard]] bool terminal() const noexcept; + // FIXME: // This property should implement with fuse guarded $XDG_CONFIG_HOME/autostart/. // Current implementation has some problems, @@ -111,6 +119,9 @@ public: void resetEntry(DesktopEntry *newEntry) noexcept; void detachAllInstance() noexcept; +private Q_SLOTS: + void onGlobalScaleFactorChanged() noexcept; + public Q_SLOTS: QDBusObjectPath Launch(const QString &action, const QStringList &fields, const QVariantMap &options); [[nodiscard]] ObjectMap GetManagedObjects() const; @@ -135,6 +146,8 @@ Q_SIGNALS: void actionsChanged(); void categoriesChanged(); void MimeTypesChanged(); + void terminalChanged(); + void scaleFactorChanged(); private: friend class ApplicationManager1Service; @@ -143,7 +156,9 @@ private: std::weak_ptr storage); static QSharedPointer createApplicationService( DesktopFile source, ApplicationManager1Service *parent, std::weak_ptr storage) noexcept; + bool m_customScale{false}; qint64 m_lastLaunch{0}; + double m_scaleFactor; std::weak_ptr m_storage; QDBusObjectPath m_applicationPath; QString m_launcher{getApplicationLauncherBinary()};