Skip to content

Commit

Permalink
refact: disable scale for app
Browse files Browse the repository at this point in the history
Disabling scale by env instead of scaleFactor, and it's removed
in AM.

Issue: linuxdeepin/developer-center#7733
  • Loading branch information
18202781743 committed Apr 3, 2024
1 parent 251714c commit 477ad32
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 38 deletions.
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions desktopintegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions desktopintegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions qml/AppItemMenu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
54 changes: 49 additions & 5 deletions src/ddeintegration/appmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,65 @@ 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"
};

static bool inScaleEnvironments(const QString &env)

Check warning on line 192 in src/ddeintegration/appmgr.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'inScaleEnvironments' is never used.
{
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();
}

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)

Check warning on line 217 in src/ddeintegration/appmgr.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'setDisableScale' is never used.
{
AppManager1Application * amAppIface = createAM1AppIface(desktopId);
if (!amAppIface) return;

amAppIface->setScaleFactor(scaleFactor);
QString environ = amAppIface->environ();
QStringList envs(environ.split(';'));
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);
});
}

amAppIface->setEnviron(envs.join(';'));
}

bool AppMgr::isOnDesktop(const QString &desktopId)
Expand Down
4 changes: 2 additions & 2 deletions src/ddeintegration/appmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,56 @@
<node>
<interface name="org.desktopspec.ApplicationManager1.Application">
<annotation
name="org.freedesktop.DBus.Description"
value="This interface is designed to provide a dbus interface of desktop file. Missing fields will be added later."
name="org.freedesktop.DBus.Description"
value="This interface is designed to provide a dbus interface of desktop file. Missing fields will be added later."
/>
<property name="Categories" type="as" access="read"/>
<property name="X_linglong" type="b" access="read"/>
<property name="X_Flatpak" type="b" access="read"/>

<property name="Categories" type="as" access="read" />
<property name="X_linglong" type="b" access="read" />
<property name="X_Flatpak" type="b" access="read" />
<property name="X_Deepin_Vendor" type="s" access="read">
<annotation name="org.freedesktop.DBus.Description" value="Whem this property is 'deepin', display name of the application
should use GenericName."
<annotation name="org.freedesktop.DBus.Description"
value="Whem this property is 'deepin', display name of the application
should use GenericName."
/>
</property>
<property name="InstalledTime" type="x" access="read"/>
<property name="NoDisplay" type="b" access="read"/>
<property name="MimeTypes" type="as" access="readwrite"/>

<property name="NoDisplay" type="b" access="read" />
<property name="MimeTypes" type="as" access="readwrite" />

<property name="Actions" type="as" access="read">
<annotation
<annotation
name="org.freedesktop.DBus.Description"
value="Names of all action identifiers of this application.
Check https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#extra-actions
for futher information."
/>
</property>

<property name="AutoStart" type="b" access="readwrite"/>
<property name="LastLaunchedTime" type="x" access="read"/>
<property name="LaunchedTimes" type="x" access="read"/>
<property name="AutoStart" type="b" access="readwrite" />
<property name="LastLaunchedTime" type="x" access="read">
<annotation
name="org.freedesktop.DBus.Description"
value="Set the value of this property to -1 to
indicates that some errors has occured."
/>
</property>

<property name="LaunchedTimes" type="x" access="read">
<annotation
name="org.freedesktop.DBus.Description"
value="Set the value of this property to -1 to
indicates that some errors has occured."
/>
</property>

<property name="InstalledTime" type="x" access="read">
<annotation
name="org.freedesktop.DBus.Description"
value="Set the value of this property to -1 to
indicates that some errors has occured."
/>
</property>

<property name="Instances" type="ao" access="read">
<annotation
Expand All @@ -48,17 +70,18 @@
</property>

<property name="Terminal" type="b" access="read">
<annotation
<annotation
name="org.freedesktop.DBus.Description"
value="Indicate this application should launch by terminal or not."
/>
</property>

<property name="ScaleFactor" type="d" access="readwrite">
<annotation
name="org.freedesktop.DBus.Description"
value="Indicate the scale factor of application's instance.
Note: Set `0` to use global scaleFactor"
<property name="Environ" type="s" access="readwrite">
<annotation
name="org.freedesktop.DBus.Description"
value="Indicate the environment of application's instance.
passing some specific environment variables to Launch
this application, eg. 'LANG=en_US;PATH=xxx:yyy;'"
/>
</property>

Expand Down Expand Up @@ -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."
Expand Down

0 comments on commit 477ad32

Please sign in to comment.