diff --git a/debian/control b/debian/control index 705d4ea7..e221411c 100644 --- a/debian/control +++ b/debian/control @@ -30,7 +30,7 @@ Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, - dde-application-manager (>= 1.2.2), + dde-application-manager (>> 1.2.2), dde-application-wizard-daemon-compat, libdtk6declarative(>=6.0.9), qml6-module-qtquick-layouts, diff --git a/desktopintegration.cpp b/desktopintegration.cpp index 11043afc..8048466f 100644 --- a/desktopintegration.cpp +++ b/desktopintegration.cpp @@ -60,14 +60,14 @@ QString DesktopIntegration::environmentVariable(const QString &env) return qEnvironmentVariable(env.toStdString().c_str()); } -double DesktopIntegration::scaleFactor(const QString &desktopId) +double DesktopIntegration::disableScale(const QString &desktopId) { - return AppMgr::scaleFactor(desktopId); + return AppMgr::disableScale(desktopId); } -void DesktopIntegration::setScaleFactor(const QString &desktopId, double scaleFactor) +void DesktopIntegration::setDisableScale(const QString &desktopId, double disableScale) { - return AppMgr::setScaleFactor(desktopId, scaleFactor); + return AppMgr::setDisableScale(desktopId, disableScale); } void DesktopIntegration::showFolder(QStandardPaths::StandardLocation location) diff --git a/desktopintegration.h b/desktopintegration.h index 10491a8a..a97d91cd 100644 --- a/desktopintegration.h +++ b/desktopintegration.h @@ -43,8 +43,8 @@ class DesktopIntegration : public QObject Q_INVOKABLE static void openSystemSettings(); Q_INVOKABLE static void launchByDesktopId(const QString & desktopId); Q_INVOKABLE static QString environmentVariable(const QString & env); - Q_INVOKABLE static double scaleFactor(const QString & desktopId); - Q_INVOKABLE static void setScaleFactor(const QString & desktopId, double scaleFactor); + Q_INVOKABLE static double disableScale(const QString & desktopId); + Q_INVOKABLE static void setDisableScale(const QString & desktopId, double disableScale); Q_INVOKABLE static void showFolder(enum QStandardPaths::StandardLocation location); Q_INVOKABLE static void showUrl(const QString & url); Q_INVOKABLE bool appIsCompulsoryForDesktop(const QString & desktopId); diff --git a/qml/AppItemMenu.qml b/qml/AppItemMenu.qml index 07f08fb1..1570cdfb 100644 --- a/qml/AppItemMenu.qml +++ b/qml/AppItemMenu.qml @@ -96,10 +96,10 @@ Loader { visible: !hideDisplayScalingMenu height: visible ? implicitHeight : 0 // FIXME: same as above checkable: true - checked: Math.abs(DesktopIntegration.scaleFactor(root.desktopId) - 1.0) < 0.0001 + checked: DesktopIntegration.disableScale(root.desktopId) text: qsTr("Disable display scaling") onTriggered: { - DesktopIntegration.setScaleFactor(root.desktopId, checked ? 1 : 0) + DesktopIntegration.setDisableScale(root.desktopId, checked ? true : false) } } MenuItem { diff --git a/src/ddeintegration/appmgr.cpp b/src/ddeintegration/appmgr.cpp index 869a0359..a4429016 100644 --- a/src/ddeintegration/appmgr.cpp +++ b/src/ddeintegration/appmgr.cpp @@ -182,21 +182,56 @@ void AppMgr::setAutoStart(const QString &desktopId, bool autoStart) amAppIface->setAutoStart(autoStart); } -// 0: global scaleFactor -double AppMgr::scaleFactor(const QString &desktopId) +static const QStringList DisabledScaleEnvironments { + "DEEPIN_WINE_SCALE=1", + "QT_SCALE_FACTOR=1", + "GDK_SCALE=1", + "GDK_DPI_SCALE=1" +}; + +bool AppMgr::disableScale(const QString &desktopId) { AppManager1Application * amAppIface = createAM1AppIface(desktopId); if (!amAppIface) return 0; - return amAppIface->scaleFactor(); + const auto environ = amAppIface->environ(); + const QStringList envs(environ.split(';')); + // return true if envs contains any one of DisabledScaleEnvironments. + auto iter = std::find_if(envs.begin(), envs.end(), [] (const QString &env) { + return DisabledScaleEnvironments.contains(env); + }); + return iter != envs.end(); } -void AppMgr::setScaleFactor(const QString &desktopId, double scaleFactor) +void AppMgr::setDisableScale(const QString &desktopId, bool disableScale) { AppManager1Application * amAppIface = createAM1AppIface(desktopId); if (!amAppIface) return; - amAppIface->setScaleFactor(scaleFactor); + QString environ = amAppIface->environ(); + QStringList envs(environ.split(';', Qt::SkipEmptyParts)); + if (disableScale) { + // remove all ScaleEnvironments, avoid other caller has set it manually. + envs.removeIf([] (const QString &env) { + auto iter = std::find_if(DisabledScaleEnvironments.begin(), DisabledScaleEnvironments.end(), + [env] (const QString &item) { + const auto left = item.split('='); + const auto right = env.split('='); + return !right.isEmpty() && left.at(0) == right.at(0); + }); + return iter != DisabledScaleEnvironments.end(); + }); + envs << DisabledScaleEnvironments; + } else { + // remove all DisabledScaleEnvironments. + envs.removeIf([] (const QString &env) { + return DisabledScaleEnvironments.contains(env); + }); + } + + environ = envs.join(';'); + qDebug() << "Update environ for the desktopId" << desktopId << ", env:" << environ; + amAppIface->setEnviron(environ); } bool AppMgr::isOnDesktop(const QString &desktopId) diff --git a/src/ddeintegration/appmgr.h b/src/ddeintegration/appmgr.h index f2574f82..68e1342a 100644 --- a/src/ddeintegration/appmgr.h +++ b/src/ddeintegration/appmgr.h @@ -39,8 +39,8 @@ class AppMgr : public QObject static bool launchApp(const QString & desktopId); static bool autoStart(const QString & desktopId); static void setAutoStart(const QString & desktopId, bool autoStart); - static double scaleFactor(const QString & desktopId); - static void setScaleFactor(const QString & desktopId, double scaleFactor); + static bool disableScale(const QString & desktopId); + static void setDisableScale(const QString & desktopId, bool disableScale); static bool isOnDesktop(const QString & desktopId); static bool sendToDesktop(const QString & desktopId); static bool removeFromDesktop(const QString & desktopId); diff --git a/src/ddeintegration/xml/org.desktopspec.ApplicationManager1.Application.xml b/src/ddeintegration/xml/org.desktopspec.ApplicationManager1.Application.xml index 8441fefc..f15d40cc 100644 --- a/src/ddeintegration/xml/org.desktopspec.ApplicationManager1.Application.xml +++ b/src/ddeintegration/xml/org.desktopspec.ApplicationManager1.Application.xml @@ -2,24 +2,25 @@ - - - - + + + + - - - - + + + - - - + + + + + + + + + + + + - - - + @@ -120,7 +143,7 @@ this application, eg. 'LANG=en_US;PATH=xxx:yyy;' 3. `path` (type s): set this application's working directory, please pass - absoult directory path. + absolute directory path. NOTE: When application launched with `uid` option, `env` option will not take effect at all."