MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9

Example of a manual swipe lock

This page demonstrates an additional way for implementing swipe lock on your application. The method described here uses the XChangeProperty function to disable swipe gestures on a rectangular section of the device display.

Designing swipe lock

In this example, the swipe lock feature is created in a function named disableCompositorAnimations. As parameters, it takes the current QWidget UI object and a rectangular QRectF area on the screen that will be affected with swipe lock. QRectF gets its dimensions when disableCompositorAnimations function is called, and inserts them into customRegion array. This array format is required by the underlying X11 window system of the device.

Note: Although this example assigns the device full-screen resolution as QRectF dimensions, it is possible to create a rectangular area of any size where swipe lock is enabled.

void disableCompositorAnimations(QWidget *window,  QRectF *rect)
   if (window != NULL)
       unsigned int customRegion[] =

Next, the default display used by the application is queried with QX11Info::display, for which the atom identifier for symbol _MEEGOTOUCH_CUSTOM_REGION is returned. This atom identifier is required by the underlying X11 display manager to process swipe lock.

Display *dpy = QX11Info::display();
Atom customRegionAtom = XInternAtom(dpy,"_MEEGOTOUCH_CUSTOM_REGION", False);

The actual swipe locking function is done with XChangeProperty, which takes the rectangular area defined in customRegion and enables swipe lock on it.

XChangeProperty(dpy, window->winId(), customRegionAtom,
                XA_CARDINAL, 32, PropModeReplace,
                reinterpret_cast<unsigned char*>(&customRegion[0]), 4);

Applying swipe lock

You can activate swipe lock at any point during runtime by calling disableCompositorAnimations. To have swipe lock in effect for the whole time the application is running, it is best to do so already in main.cpp.

Before calling disableCompositorAnimations, you need to introduce a few variables

QApplication app(argc, argv);
MainWindow mainWindow;
QRectF mainWindowRect;
QSize windowSize;

Even if the application is already in the full-screen mode, it needs to be set to the full-screen dimensions with the resize function so that the values for main window size are internally updated properly. Due to the asynchronous nature of X11 system, the window size values are not always properly updated if you just call mainWindow.showFullScreen, hence the resize call ensures that the main window geometry is properly updated before calling the swipe lock function. To get the correct full screen dimensions, use the screenGeometry function.

windowSize.setWidth( ((QApplication::desktop())->screenGeometry()).width() );
windowSize.setHeight( ((QApplication::desktop())->screenGeometry()).height() );

mainWindow.resize( windowSize );

Assign the rectangular area to be affected with swipe lock. The following line fills mainWindowRect with proper screen size values to be processed later by the disableCompositorAnimations function.

mainWindowRect.setRect( mainWindow.x(), mainWindow.y(), mainWindow.width(), mainWindow.height() );

When mainWindow is set to the full-screen mode and mainWindowRect parameters have been assigned, you can call disableCompositorAnimations. This activates swipe lock.

disableCompositorAnimations( &mainWindow,  &mainWindowRect);

Finally, enter the main loop of the application:

return app.exec();