MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9

Enabling swipe lock

Swipe lock is a useful feature for many kinds of applications, including games. It disables the normal swipe functionality of the device UI, allowing applications to use swipe for other actions than switching applications. For example, drawing applications can benefit from swipe lock to avoid confusing normal drawing motions with the swipe gesture.

Note: When swipe lock is enabled, the user has to have a way to get out of the application since the usual way (swipe gesture) is disabled. Always provide a way for the user to minimise or exit the application by other means, such as a Pause or Minimise button. Remember also to implement swipe lock only when it is necessary. For example, when designing a game, use swipe locking only during actual gameplay, so that when the user taps Pause, swipe is re-enabled and they can use other applications.

Using swipe lock

Swipe lock is most conveniently used with the QML Screen element, which contains the allowSwipe boolean toggle for activating swipe lock. allowSwipe can only be used on the whole device screen.

Note: allowSwipe is included from Harmattan PR 1.1 onwards. If your application uses this feature, it cannot be used in any device with an older operating system.

The following code snippet shows how to use swipe lock in your application. It creates a button that switches between enabled and disabled swipe lock modes with screen.allowSwipe and displays the swipe lock status on a separate text label.

import QtQuick 1.1
import 1.1 // includes Screen.allowSwipe

Page {
   tools: commonTools

   // Swipe lock button - could be a pause button for a game, for example
   Button {
       anchors {
           right: parent.right
           margins: 10
       text: qsTr("Toggle swipe")
       onClicked: { screen.allowSwipe = !screen.allowSwipe }

   // show the current swipe state for testing purposes
   Label {
       id: label
       anchors.centerIn: parent
       text: qsTr("Swipe ") + (screen.allowSwipe ? qsTr("enabled") : qsTr("disabled"))
       color: (screen.allowSwipe ? "black" : "red")

Additional example

For a more customisable low-level method of enabling swipe lock with XChangeProperty function, see section Example of a manual swipe lock.