Processing System Events

The following examples give some suggestions about how to process events related to the whole system, rather than individual windows or window groups.

Variant: ScreenPlay and non-ScreenPlay. Target audience: Application developers.

Window group with focus changes

To detect if the window group with focus has changed, use the EEventFocusGroupChanged event type.

You can get the handle of the window group with focus by calling the RWsSession::GetFocusWindowGroup() function for the iWs Window Server session.

    // Window group with focus changes
    case EEventFocusGroupChanged:
        // Get the handle of the group with focus
        TInt handle = iWs.GetFocusWindowGroup();

Window group destroyed, or changes name

To detect if the window group has been destroyed or changed name, use the EEventWindowGroupsChanged event type.

You can get a list of identifiers of window groups in the Window Server session by calling RWsSession::WindowGroupList(). Call the RWsSession::GetWindowGroupNameFromIdentifier() function to get the window group name passed to it in the windowName buffer.

    // Window group destroyed, or changes name
    case EEventWindowGroupsChanged:
        // Get a list of the names and IDs of the all the window groups
        CArrayFixFlat<Tint>* windowList = new CArrayFixFlat<TInt>(4);

        // Get a list of window group IDs
        for (TInt I = 0; I< windowList -> Count(); I++)
            // Get the window name for each window group ID
            iWs.GetWindowGroupNameFromIdentifier( (*windowList)[I], windowName );

            // do something with windowName...
            // ..
            CleanupStack::PopAndDestroy(); // windowList

Screen size mode changed

To detect if screen size or mode changed event has been issued, use the EEventScreenDeviceChanged event type.

You can get the screen rotation and size by calling CWsScreenDevice::GetScreenModeSizeAndRotation(). Pass as parameters the current screen mode and a TPixelsTwipsAndRotation object to get the orientation of the specified screen mode, and its size in both pixels and twips.

    // Screen size mode changed
    case EEventScreenDeviceChanged:
        // Get the new screen mode and size
        TInt newMode = iScreen.CurrentScreenMode();
        TPixelsTwipsAndRotation sizeAndRotation;
        iScreen.GetScreenModeSizeAndRotation(newMode, sizeAndRotation);

Note that for screen size mode changed events, often after having got the new size and rotation you would set it back on your screen device.

In ScreenPlay this event is related to the EEventDisplayChanged event. See Display Control and Mapping in the Window Server Client for more information.

Power on/off events

To detect if power on/off events have been issued, use the EEventSwitchOn, EEventSwitchOff or EEventKeySwitchOff event types.

    // Power on/off events
    case EEventSwitchOn:
    case EEventSwitchOff:
    case EEventKeySwitchOff:

Case open/closed events

To detect if case open/closed events have been issued, use the EEventCaseOpened, EEventCaseClosed event types.

    // Case open/closed events
    case EEventCaseOpened:
    case EEventCaseClosed:

A Window Server error event message

To detect if an error event message has been issued, use the EEventErrorMessage event type.

You can get information about the error event by calling the TWsEvent::ErrorMessage() function.

    // A Window Server error event message
    case EEventErrorMessage:
        // Get error category and code
        TWsErrorMessage* msg = iWsEvent.ErrorMessage();
        TWsErrorMessage::TErrorCategory errorCategory = msg -> iErrorCategory;
        TUint code = msg -> iError;

Related concepts