refact: add environ and remove scaleFactor property
- remove scaleFactor property ! - add environ property to set scaleFactor easily
This commit is contained in:
parent
02bebd4ef0
commit
144461c379
@ -76,11 +76,12 @@
|
|||||||
/>
|
/>
|
||||||
</property>
|
</property>
|
||||||
|
|
||||||
<property name="ScaleFactor" type="d" access="readwrite">
|
<property name="Environ" type="s" access="readwrite">
|
||||||
<annotation
|
<annotation
|
||||||
name="org.freedesktop.DBus.Description"
|
name="org.freedesktop.DBus.Description"
|
||||||
value="Indicate the scale factor of application's instance.
|
value="Indicate the environment of application's instance.
|
||||||
Note: Set `0` to use global scaleFactor"
|
passing some specific environment variables to Launch
|
||||||
|
this application, eg. 'LANG=en_US;PATH=xxx:yyy;'"
|
||||||
/>
|
/>
|
||||||
</property>
|
</property>
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ constexpr auto AppExecOption = u8"appExec";
|
|||||||
constexpr auto STORAGE_VERSION = 0;
|
constexpr auto STORAGE_VERSION = 0;
|
||||||
constexpr auto ApplicationPropertiesGroup = u8"Application Properties";
|
constexpr auto ApplicationPropertiesGroup = u8"Application Properties";
|
||||||
constexpr auto LastLaunchedTime = u8"LastLaunchedTime";
|
constexpr auto LastLaunchedTime = u8"LastLaunchedTime";
|
||||||
constexpr auto ScaleFactor = u8"ScaleFactor";
|
constexpr auto Environ = u8"Environ";
|
||||||
constexpr auto LaunchedTimes = u8"LaunchedTimes";
|
constexpr auto LaunchedTimes = u8"LaunchedTimes";
|
||||||
constexpr auto InstalledTime = u8"InstalledTime";
|
constexpr auto InstalledTime = u8"InstalledTime";
|
||||||
|
|
||||||
|
@ -32,51 +32,16 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <wordexp.h>
|
#include <wordexp.h>
|
||||||
|
|
||||||
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<double> ret1(reply1);
|
|
||||||
double scale = ret1.isValid() ? ret1.value() : 1.0;
|
|
||||||
scale = scale > 0 ? scale : 1;
|
|
||||||
return scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ApplicationService::appendExtraEnvironments(QVariantMap &runtimeOptions) const noexcept
|
void ApplicationService::appendExtraEnvironments(QVariantMap &runtimeOptions) const noexcept
|
||||||
{
|
{
|
||||||
QString oldEnv;
|
QString oldEnv;
|
||||||
// scale factor
|
|
||||||
static QStringList scaleEnvs{"DEEPIN_WINE_SCALE=%1;", "QT_SCALE_FACTOR=%1;"};
|
|
||||||
auto factor = scaleFactor();
|
|
||||||
if (auto it = runtimeOptions.find("env"); it != runtimeOptions.cend()) {
|
if (auto it = runtimeOptions.find("env"); it != runtimeOptions.cend()) {
|
||||||
oldEnv = it->value<QString>();
|
oldEnv = it->value<QString>();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &env : scaleEnvs) {
|
const QString &env = environ();
|
||||||
oldEnv.append(env.arg(factor));
|
if (!env.isEmpty())
|
||||||
}
|
oldEnv.prepend(env);
|
||||||
|
|
||||||
// FIX #7528 GTK app only scale the UI, not scaling of text.
|
|
||||||
// GDK_SCALE Must be set to an integer, see https://docs.gtk.org/gtk3/x11.html
|
|
||||||
// 1.25 ==> 1 , 1.75 ==>2
|
|
||||||
int scale = qRound(factor);
|
|
||||||
oldEnv.append(QString("GDK_SCALE=%1;").arg(scale));
|
|
||||||
if (scale > 0) { // avoid division by 0
|
|
||||||
oldEnv.append(QString("GDK_DPI_SCALE=%1;").arg(qreal(1.0 / scale)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// GIO
|
|
||||||
oldEnv.append(QString{"GIO_LAUNCHED_DESKTOP_FILE=%1;"}.arg(m_desktopSource.sourcePath()));
|
|
||||||
|
|
||||||
// set for dxcb platform plugin, which should use scale factor directly instead of processing double times.
|
|
||||||
oldEnv.append(QString{"D_DXCB_FORCE_OVERRIDE_HIDPI=1"});
|
|
||||||
|
|
||||||
runtimeOptions.insert("env", oldEnv);
|
runtimeOptions.insert("env", oldEnv);
|
||||||
}
|
}
|
||||||
@ -85,7 +50,6 @@ ApplicationService::ApplicationService(DesktopFile source,
|
|||||||
ApplicationManager1Service *parent,
|
ApplicationManager1Service *parent,
|
||||||
std::weak_ptr<ApplicationManager1Storage> storage)
|
std::weak_ptr<ApplicationManager1Storage> storage)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_scaleFactor(getScaleFactor())
|
|
||||||
, m_storage(std::move(storage))
|
, m_storage(std::move(storage))
|
||||||
, m_desktopSource(std::move(source))
|
, m_desktopSource(std::move(source))
|
||||||
{
|
{
|
||||||
@ -139,30 +103,9 @@ ApplicationService::ApplicationService(DesktopFile source,
|
|||||||
m_launchedTimes = value.toLongLong();
|
m_launchedTimes = value.toLongLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
value = storagePtr->readApplicationValue(appId, ApplicationPropertiesGroup, ScaleFactor);
|
value = storagePtr->readApplicationValue(appId, ApplicationPropertiesGroup, ::Environ);
|
||||||
if (!value.isNull()) {
|
if (!value.isNull()) {
|
||||||
bool ok{false};
|
m_environ = value.toString();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -606,13 +549,17 @@ qint64 ApplicationService::launchedTimes() const noexcept
|
|||||||
return m_launchedTimes;
|
return m_launchedTimes;
|
||||||
}
|
}
|
||||||
|
|
||||||
double ApplicationService::scaleFactor() const noexcept
|
QString ApplicationService::environ() const noexcept
|
||||||
{
|
{
|
||||||
return m_scaleFactor;
|
return m_environ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplicationService::setScaleFactor(double value) noexcept
|
void ApplicationService::setEnviron(const QString &value) noexcept
|
||||||
{
|
{
|
||||||
|
if (environ().trimmed() == value.trimmed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto storagePtr = m_storage.lock();
|
auto storagePtr = m_storage.lock();
|
||||||
if (!storagePtr) {
|
if (!storagePtr) {
|
||||||
qCritical() << "broken storage.";
|
qCritical() << "broken storage.";
|
||||||
@ -621,28 +568,19 @@ void ApplicationService::setScaleFactor(double value) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto appId = id();
|
auto appId = id();
|
||||||
if (value == 0) {
|
if (!m_environ.isEmpty()) {
|
||||||
m_customScale = false;
|
if (!storagePtr->updateApplicationValue(appId, ApplicationPropertiesGroup, Environ, value)) {
|
||||||
m_scaleFactor = getScaleFactor();
|
sendErrorReply(QDBusError::Failed, "update environ failed.");
|
||||||
if (!storagePtr->deleteApplicationValue(appId, ApplicationPropertiesGroup, ScaleFactor)) {
|
|
||||||
qCritical() << "failed to delete app's property:" << appId;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_customScale) {
|
|
||||||
if (!storagePtr->updateApplicationValue(appId, ApplicationPropertiesGroup, ScaleFactor, value)) {
|
|
||||||
sendErrorReply(QDBusError::Failed, "update scaleFactor failed.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!storagePtr->createApplicationValue(appId, ApplicationPropertiesGroup, ScaleFactor, value)) {
|
if (!storagePtr->createApplicationValue(appId, ApplicationPropertiesGroup, Environ, value)) {
|
||||||
sendErrorReply(QDBusError::Failed, "set scaleFactor failed.");
|
sendErrorReply(QDBusError::Failed, "set environ failed.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_scaleFactor = value;
|
m_environ = value;
|
||||||
emit scaleFactorChanged();
|
emit environChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ApplicationService::autostartCheck(const QString &filePath) const noexcept
|
bool ApplicationService::autostartCheck(const QString &filePath) const noexcept
|
||||||
@ -907,7 +845,7 @@ void ApplicationService::resetEntry(DesktopEntry *newEntry) noexcept
|
|||||||
emit categoriesChanged();
|
emit categoriesChanged();
|
||||||
emit MimeTypesChanged();
|
emit MimeTypesChanged();
|
||||||
emit terminalChanged();
|
emit terminalChanged();
|
||||||
emit scaleFactorChanged();
|
emit environChanged();
|
||||||
emit launchedTimesChanged();
|
emit launchedTimesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,9 +67,9 @@ public:
|
|||||||
Q_PROPERTY(qint64 LaunchedTimes READ launchedTimes NOTIFY launchedTimesChanged)
|
Q_PROPERTY(qint64 LaunchedTimes READ launchedTimes NOTIFY launchedTimesChanged)
|
||||||
[[nodiscard]] qint64 launchedTimes() const noexcept;
|
[[nodiscard]] qint64 launchedTimes() const noexcept;
|
||||||
|
|
||||||
Q_PROPERTY(double ScaleFactor READ scaleFactor WRITE setScaleFactor NOTIFY scaleFactorChanged)
|
Q_PROPERTY(QString Environ READ environ WRITE setEnviron NOTIFY environChanged)
|
||||||
[[nodiscard]] double scaleFactor() const noexcept;
|
[[nodiscard]] QString environ() const noexcept;
|
||||||
void setScaleFactor(double value) noexcept;
|
void setEnviron(const QString &value) noexcept;
|
||||||
|
|
||||||
Q_PROPERTY(bool Terminal READ terminal NOTIFY terminalChanged)
|
Q_PROPERTY(bool Terminal READ terminal NOTIFY terminalChanged)
|
||||||
[[nodiscard]] bool terminal() const noexcept;
|
[[nodiscard]] bool terminal() const noexcept;
|
||||||
@ -134,9 +134,6 @@ public:
|
|||||||
[[nodiscard]] LaunchTask unescapeExec(const QString &str, const QStringList &fields) noexcept;
|
[[nodiscard]] LaunchTask unescapeExec(const QString &str, const QStringList &fields) noexcept;
|
||||||
[[nodiscard]] static std::optional<QStringList> unescapeExecArgs(const QString &str) noexcept;
|
[[nodiscard]] static std::optional<QStringList> unescapeExecArgs(const QString &str) noexcept;
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void onGlobalScaleFactorChanged() noexcept;
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
// NOTE: 'realExec' only for internal implementation
|
// NOTE: 'realExec' only for internal implementation
|
||||||
QDBusObjectPath
|
QDBusObjectPath
|
||||||
@ -164,7 +161,7 @@ Q_SIGNALS:
|
|||||||
void categoriesChanged();
|
void categoriesChanged();
|
||||||
void MimeTypesChanged();
|
void MimeTypesChanged();
|
||||||
void terminalChanged();
|
void terminalChanged();
|
||||||
void scaleFactorChanged();
|
void environChanged();
|
||||||
void launchedTimesChanged();
|
void launchedTimesChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -174,11 +171,10 @@ private:
|
|||||||
std::weak_ptr<ApplicationManager1Storage> storage);
|
std::weak_ptr<ApplicationManager1Storage> storage);
|
||||||
static QSharedPointer<ApplicationService> createApplicationService(
|
static QSharedPointer<ApplicationService> createApplicationService(
|
||||||
DesktopFile source, ApplicationManager1Service *parent, std::weak_ptr<ApplicationManager1Storage> storage) noexcept;
|
DesktopFile source, ApplicationManager1Service *parent, std::weak_ptr<ApplicationManager1Storage> storage) noexcept;
|
||||||
bool m_customScale{false};
|
|
||||||
qint64 m_lastLaunch{0};
|
qint64 m_lastLaunch{0};
|
||||||
qint64 m_installedTime{0};
|
qint64 m_installedTime{0};
|
||||||
qint64 m_launchedTimes{0};
|
qint64 m_launchedTimes{0};
|
||||||
double m_scaleFactor;
|
QString m_environ;
|
||||||
std::weak_ptr<ApplicationManager1Storage> m_storage;
|
std::weak_ptr<ApplicationManager1Storage> m_storage;
|
||||||
AutostartSource m_autostartSource;
|
AutostartSource m_autostartSource;
|
||||||
QDBusObjectPath m_applicationPath;
|
QDBusObjectPath m_applicationPath;
|
||||||
|
Loading…
Reference in New Issue
Block a user