Quantcast
Channel: Intel Developer Zone Articles
Viewing all articles
Browse latest Browse all 3384

Detecting Slate/Clamshell Mode & Screen Orientation in Convertible PC

$
0
0

Downloads


Download Detecting Slate/Clamshell Mode & Screen Orientation in Convertible PC [PDF 574KB]
Download DockingDemo3.zip[37 KB]

Executive Summary


This project demonstrates how to detect slate vs. clamshell mode as well as simple orientation detection on Windows* 8 desktop mode. The application is a tray application in the notification area and is based on win32 and ATL. The tray application also works when the machine is running in New Windows 8 UI mode. It uses windows message and sensor API notification mechanism and doesn’t need polling. However, the app requires appropriate device drivers and it was found that many current OEM platforms don’t have the necessary drivers for slate / clamshell mode detection. Simple orientation sensor works on all the tested platforms.

System Requirements


System requirements for slate / clamshell mode detection are as follows :

  1. Slate / clamshell mode indicator device driver (Compatible ID PNP0C60.)
  2. Docking mode indicator device driver (Compatible ID PNP0C70.)
  3. Go to Device Manager -> Human Interface Devices -> GPIO Buttons Driver -> Details -> Compatible Ids. If you find PNP0C60, that’s the driver. Without this driver, slate mode detection doesn’t work.
  4. For classical docking mode detection, you need this driver.

System requirements for orientation :

  1. Simple Device Orientation Sensor.
  2. Present in all tested convertible PCs.

Application Overview


  • Compile and run the application, and it will create a tray icon. For testing purpose, customize “Notification Area Icons” so that DockingDemo.exe’s behavior is to “Show icon and notifications” in the lower right corner of the screen.
  • Move the mouse over the icon and it shows the current status.

  • Right click on the icon for further menus – About, Save Log…, and Exit. Save Log will let you save all the events to a specified file. When you save the events to the log, it clears the events in the memory.
  • Rotate and switch back and forth between the slate / clamshell mode or rotate the platform. The tray icon will pop up a balloon to notify the change.

Slate / Clamshell Mode Detection


OS broadcasts WM_SETTINGCHANGE message to the windows when it detects slate mode change with the string “ConvertibleSlateMode” in lParam. In case of docking mode change, it broadcasts the same message with the string “SystemDockMode.” WinProc in DockingDemo.cpp handles this message. The API to query the actual status is GetSystemMetrics. This method works when the system is running New Windows 8 UI mode.

 
BOOL bSlateMode = (GetSystemMetrics(SM_CONVERTIBLESLATEMODE) == 0); 
BOOL bDocked = (GetSystemMetrics(SM_SYSTEMDOCKED) != 0); 

Screen Orientation Detection


In desktop environment, OS broadcasts WM_DISPLAYCHANGE message to the windows when it detects orientation changes. lParam’s low word is the width and high word is the height of the new orientation.

There are two problems with this approach :

  • This approach only detects landscape and portrait mode. There is no distinction between landscape vs. landscape flipped and portrait vs. portrait flipped.
  • WM_DISPLAYCHANGE simply doesn’t work when it is running in New Windows 8 UI mode.

Fortunately, Microsoft* provides COM interfaces to directly access the various sensors and there are various white papers about how to use it. Some of the references are listed here.

In this project, SimpleOrientationSensor class implements the infrastructure to access the orientation sensor, and OrientationEvents class is sub-classed from ISensorEvents to register the callbacks for the orientation change events. Since the Sensor APIs use callback mechanism, the user application doesn’t have to poll the events. This approach works when the system is running in New Windows 8 UI mode.

The relationship between slate mode and rotation needs to be carefully thought out. Rotation may be enabled / disabled automatically depending on the slate / clamshell mode. To ensure the proper behavior, a combination of GetAutoRotationState API and rotation sensor is used for this sample, i.e., discard rotation event notification when autorotation is NOT enabled. In that case, use EnumDisplaySettings to get the current orientation in NotifyOrientationChange function as shown in the code snippet below.

Intel, the Intel logo and Xeon are trademarks of Intel Corporation in the U.S. and other countries. *Other names and brands may be claimed as the property of others.
Copyright© 2013 Intel Corporation. All rights reserved.

License
Intel sample sources are provided to users under the Intel Sample Source Code License Agreement.

  • ultrabook
  • Windows *8
  • desktop
  • Tablet
  • applications
  • slate mode
  • clamshell mode
  • orientation detection
  • Developers
  • Microsoft Windows* 8
  • Windows*
  • Intermediate
  • Microsoft Windows* 8 Desktop
  • Microsoft Windows* 8 Style UI
  • Sensors
  • Touch Interfaces
  • Laptop
  • Tablet
  • Desktop
  • Protected Attachments: 

    AttachmentSize
    Downloaddockingdemo3.zip36.96 KB
  • URL

  • Viewing all articles
    Browse latest Browse all 3384

    Trending Articles



    <script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>