如何固定你的Ubuntu应用的方向

在这篇文章中,我们将介绍如何固定一个Ubuntu应用的方向。固定应用的方向对有些游戏应用来说,非常有用。这样可以让游戏专注于一个方向的布局,比如开车的游戏!


在Ubuntu应用中,我们可以通过如下的flag:


MainView {
    // objectName for functional testing purposes (autopilot-qt5)
    objectName: "mainView"

    // Note! applicationName needs to match the "name" field of the click manifest
    applicationName: "usermetrics.liu-xiao-guo"

    /*
     This property enables the application to change orientation
     when the device is rotated. The default is false.
    */
    //automaticOrientation: true

    // Removes the old toolbar and enables new features of the new header.
    useDeprecatedToolbar: false

    width: units.gu(60)
    height: units.gu(85)
   ...
}

这里有一个automaticOrientation标志位。由于一些原因,目前还是不能正常工作,虽然我们可以设置它为false。


目前我发现一个更加简单的办法,就是直接修改项目的.desktop文件:


[Desktop Entry]
Name=fixedorientationapp
Exec=qmlscene $@ Main.qml
Icon=fixedorientationapp.png
Terminal=false
Type=Application
X-Ubuntu-Touch=true
X-Ubuntu-Supported-Orientations=landscape


我们在上面添加了X-Ubuntu-Supported-Orientations=landscape。这样我们的应用就只有在landscape模式下。


当我们把项目的.desktop文件修改为:


[Desktop Entry]
Name=fixedorientationapp
Exec=qmlscene $@ Main.qml
Icon=fixedorientationapp.png
Terminal=false
Type=Application
X-Ubuntu-Touch=true
X-Ubuntu-Supported-Orientations=portrait

当我们运行我们的应用时,我们的应用只有在portrait模式下运行。不可以更改。

如何固定你的Ubuntu应用的方向_第1张图片


整个应用的代码:https://github.com/liu-xiao-guo/fixedorientationapp



你可能感兴趣的:(如何固定你的Ubuntu应用的方向)