1 # Window Manager Application Guide
5 - [Target reader of this document](#target-reader-of-this-document)
6 - [Overview](#overview)
7 - [Supported usecase](#supported-usecase)
8 - [Getting Started](#getting-started)
9 - [Build](#build-by-sdk)
12 - [Enable to call Window Manager](#enable-to-call-window-manager)
13 - [Software Architecture](#software-architecture)
14 - [Sequence](#sequence)
15 - [API reference](#api-reference)
16 - [Request to Window Manager](#request-to-window-manager)
17 - [Event from Window Manager](#event-from-window-manager)
18 - [Client Library](#client-library)
19 - [Sample code](#sample-code)
20 - [Policy Manager](#policy-manager)
21 - [Enabling split](#enabling-split)
22 - [Release Note](#release-note)
24 | Version | Author | Updated at |
26 | 0.8 | TOYOTA MOTOR CORPORATION| 22th/Feb/2019 |
30 ## Target reader of this document
32 This document is intended for developers and system integrators who
33 need to know, how Window manager works and how it is to be used.
35 ### Scope of this Document
37 This document covers Window manager that was implemented for TMC and
38 delivered to the Automotive Grade Linux (AGL) project. It includes its
39 implementation details, concepts of operation, configuration and usage.
43 - document of the underlying architecture, see
44 [HMI-Framework](https://wiki.automotivelinux.org/hmiframework).
46 - document of the AGL application framework and its technologies,
48 Framework](https://wiki.automotivelinux.org/agl-distro/app-framework).
50 - document of HomeScreen, see
51 [HomeScreen](./ApplicationGuide.html).
53 It is highly recommended to have a good understanding of these documents
54 and projects before using Window manager.
60 Window Manager is the service process which provides window management based on policy.
61 And implements a layout switching of applications on
62 multiple layers and with different layer layouts.
63 Window Manager is based on ivi layer management from GENIVI and AGL application framework.
65 Window Manager consists of
68 - service binding library
69 - shared library for policy management
72 In order to understand Window Manager, the below figure shows the one of typical usecases.
73 In this example, there are two mode for window management.
75 1. Window Management in `Car Stops`
76 1. Window Management in `Car Runs`
78 ![Figure: Typical usecase](parts/state_change_example.png)
80 The important points are:
82 - Window transition should be done by Window Manager
84 Window Manager switch application displayed on top layer by user operation(touch shortcut button).
85 In this example, when an user touches `navigation` shortcut button, Window Manager displays `navigation` and hide `launcher`. Next, when an user touches `videoplayer` shortcut button, Window Manager divides a screen into two parts and display two applications.
87 - There is a priority `role` for each application.
89 Window Manager realizes state transition change based on the policy which consists of `role`.
90 According to the state transition table, it controls the visibility of application window, layout change, and so on.
91 The reasons why this is necessary are
93 - to support user driving
94 - not to disturb a driver concerns on driving for safety
96 In this example, for safety, when the car starts running, Window Manager set up the role `videoplayer`
97 to be masked and uncontrollable by user not to disturb driver concerns.
98 And, for supporting driving, set up `navigation` role to be displayed 3 seconds after the car ran.
99 In `Car Run` state, the user can't switch to other application from Navigation application until car stops.
104 - When an user chooses a different application, Window Manager changes the layout and then displays the application.
105 - When an user chooses a different application, Window Manager changes the layout and then hides the displayed application.
107 - Window Manager changes layout according to policy table based on `role`.
108 3. Define Layout by `area` configuration
109 - Window Manager realizes the abstracted `area` and can resize the window by using it. User can easily edit this configuration.
118 git clone https://gerrit.automotivelinux.org/gerrit/apps/agl-service-windowmanager
119 cd agl-service-windowmanager
122 source <your SDK path> // normally this is /opt/agl-sdk/environment
128 The widget package is populated in the 'package' directory.
132 root windowmanager-service.wgt
137 Copy windowmanager-service.wgt to the file system then execute the following command.
140 afm-util install windowmanager-service.wgt
145 You can make Window Manager object files with the following two stage operations.
152 repo init -u https://gerrit.automotivelinux.org/gerrit/AGL/AGL-repo
159 source meta-agl/scripts/aglsetup.sh -m m3ulcb agl-demo hmi-framework
160 bitbake agl-demo-platform
165 ## Enable to call Window Manager
167 To call Window Manager, it is important to enable the permission from security framework.
168 To use Window Manager API, an application or a service shall add the following configuration definition into "config.xml" of your application.
171 <feature name="urn:AGL:widget:required-api">
172 <param name="windowmanager" value="ws" />
176 To call Window Manager function easily, Window Manager provides a library which is called "libwindowmanager".
177 This library provides a function style API calling interface.
178 So you can include the libwindowmanager.hpp header file, and can link against this library.
179 Please also refer to the sample application.
181 See also our [Sample code](#sample-code).
185 ## Software Architecture
187 The static relationship with other components is shown below.
188 The actual logic of Window Manager is the binding in Binder(afb-daemon).
189 Window Manager is based on AGL application framework,
190 so the IPC via websocket is protected by AGL application framework.
192 The upper binder is for the application side security context.
193 The lower binder is the Window Manager for the server side security context.
194 Usually an application side binder has some business logic for each application, so the number of binders depend on the number of applications which use Window Manager.
195 On the other hand, regarding lower binder there is only one module in the system. This binder receives messages from multiple applications.
197 An application can use libwindowmanager.so to call Window Manager API simply.
199 Window Manager is based on the GENIVI layer management system.
201 ![wm_software_stack.png](parts/wm_software_stack.png)
205 Layers are entities that means the application stack group defined in `layers.json`.
206 This doesn't mean layer ID defined in GENIVI ivi layer.
207 The layer ID is used for application itself in Window Manager.
208 Currently, application can't have multiple surfaces in Window Manager.
212 Surfaces are *placed* on layers . The surface
213 will then be resized to dimensions, according to the name of `areas.json`
214 application requests by `activateWindow` or policy management.
215 As default, `normal.full` is set by libwindowmanager for native application.
219 The window manager is configured with the *layers.json*, *areas.json*, *roles.db* configuration
220 files. By default they are searched in `${AFM_APP_INSTALL_DIR}/etc/`.
222 Sample configurations are provided with the window manager
223 implementation, these samples are installed to ${AFM_APP_INSTALL_DIR}/etc/ .
225 This configuration is supposed to be configured by policy designer which means OEM or Tier1.
229 `layers.json` has three roles.
231 1. Create application containers `Layer`.
232 1. Set id range for applications.
233 1. Attach application to `Layer` according to the role application requests.
235 The sample configuration is here
239 "comment": "Surface ID to Layer ID mapping",
242 "surface_role": "HomeScreen",
243 "comment": "This surface should never be made invisible (The HomeScreen)"
248 "role": "BackGroundLayer",
249 "name": "BackGroundLayer",
251 "comment": "Single BackGround layer map for the map, radio, music and video"
254 "role": "homescreen",
255 "name": "FarHomeScreen",
257 "comment": "FarHomeScreen is the part of HomeScreen. The z order of this layer is lower than NearHomeScreen"
260 "role": "music|video|browser|radio|phone|map|hvac|settings|dashboard|poi|mixer|sdl|launcher|fallback",
263 "comment": "Range of IDs that will always be placed on layer 1001"
266 "role": "^on_screen.*",
269 "comment": "Range of IDs that will always be placed on the OnScreen layer, that gets a very high 'dummy' id of 9999"
275 Each mapping defines the following items to map corresponding surfaces
278 - `role` defines what kind of ability the application has. And the application will be attached to `Layer` according to the `role`.
279 A regular expression that application drawing names
280 are matched against. If applications match this regular expression,
281 the surface will be visible on this layer.
283 - `name` is just a name definition for `Layer`, it has no
284 functional use apart from identifying a layer with a name.
285 - `layer_id` is the id used in GENIVI IVI layer management control.
287 `Layer` stacks from beginning to end.
289 The above `Layer` example image is below.
291 ![wm_layer_stack.png](parts/wm_layer_stack.png)
294 "fallback" role is the special role. This role is set if the role application requests doesn't exist
295 in `layers.json`. Then, Window Manager will accept any applications.
296 If the "fallback" is not set in layers.json, window manager blocks the application displaying in such case.
297 In such a situation, you have to add your role(application name) at "role" in layers.json.
300 `BackGroundLayer` name of `Layer` is exception for work around. This layer is fallback layer not to stop event loop of application when it becomes invisible.
301 The problem is issued in <https://jira.automotivelinux.org/browse/SPEC-1484>.
305 Area means abstract expressions of 2-dimensional size and position.
306 `areas.json` defines the area which an application is set.
312 "name": "fullscreen",
321 "name": "normal.full",
330 "name": "split.main",
351 The image of the above setting is described below.
353 ![wm_area.png](parts/wm_area.png)
355 - `name` is an abstract data of rectangle.
357 - `rect` has 4 arguments. `x`, `y` means the offset from (0, 0) of screen.`w` means the width of the area, and `h` means the height of the area. The dimensions can be specified relative to the screen dimensions.
359 The dimensions can be specified absolute to the screen dimensions. But if `fullscreen` is not suitable to screen dimensions, Window Manager scales the area automatically.
363 `fullscreen` must be set because this is the base size of scaling in Window Manger.
367 The direction of the coordinates depends on `transform` in weston.ini.
368 Currently, agl-demo-platform set `transform=270`.
369 This suppose to use screen vertically.
377 To understand the sequence between application and window manager, refer to the [spec document](https://wiki.automotivelinux.org/hmiframework).
379 The typical sequence to render your application, follow the sequence below.
381 1. Register your role (and request surfaceID)
383 ![request_role.png](parts/request_role.png)
385 The above sequence is the initialization phase of your application to use Window Manager.
386 An Application has to register your `role` to Window Manager. For ivi-shell application, Window Manager generates surfaceID to input it into the function
387 to create surface. And also it is important for synchronization to get `syncDraw` event for receiving the request for resize and redraw, and notifying Window Manager of `endDraw`, so register callback function with setEventHandler for `syncDraw`.
389 [requestSurface](#requestSurface)
391 [setEventHandler](#wm_subscribe)
393 setEventHandler is API of libwindowmanager. This calls wm_subscribe internally.
395 2. Display your window
397 ![hmi_framework_designed_seq_toyota.png](parts/hmi_framework_designed_seq_toyota.png)
399 To display your window, your application has to request `activateWindow` with `role` and `area` to Window Manager.
400 Window Manager checks the app should be visible on the `area` according to the policy table using `role` .
401 If it is accepted, afb_req_success will be returned, and next Window Manager
402 will push the event `syncDraw` to applications which will be displayed. If it is denied, afb_req_fail will be returned. In this sample sequence, `syncDraw` is emitted to the apps who requested only,
403 but this shall be emitted to other applications whose size shall be changed.
405 [activateWindow](#activateWindow)
407 [syncDraw](#syncDraw)
411 [flushDraw](#flushDraw)
413 3. Activate OnScreen Window
415 ![deactivate_window.png](parts/deactivate_window.png)
417 [deactivateWindow](#deactivateWindow)
419 [See sample code for more detail about OnScreen Window.](https://gerrit.automotivelinux.org/gerrit/gitweb?p=apps%2Fonscreenapp.git;a=summary)
421 The above sequence shows the sample of OnScreen Window.
422 If the role is high priority than NormapApp, Window Manager rejects NormalApp
423 request when OnScreenApp is displayed.
425 Note : Above repository is currently empty, so please refer to the sandbox branch.
431 ### Request to Window Manager
433 | Use | verb | version |
435 | Initialize | requestSurface | from 0.7 |
436 | | wm_subscribe | from 0.7 |
437 | | requestSurfaceXDG | from 0.7 |
438 |Activate/Deactivate| activateWindow | from 0.7 |
439 | | deactivateWindow | from 0.7 |
440 | | endDraw | from 0.7 |
441 | Change area size | changeAreaSize | from 0.8 |
442 | Get Infomation | getDisplayInfo | from 0.7 |
443 | | getAreaList | from 0.8 |
445 Note: We created this table from 0.7
447 The data of IPC via websocket consists of JSON.
448 This section describes the verb of API and key.
449 Normally, the body of requesting API will be here.
453 #### *requestSurface*
455 Register your role to Window Manager and get surfaceID for ivi-shell. The role is used for policy management. SurfaceID is supposed to be set to the API `ivi_application_surface_create` of ivi-application protocol or set it to environment variable `QT_IVI_SURFACE_ID` if your app is Qt and integrate ivi-shell.
457 - verb : "requestSurface"
458 - argument : {"drawing_name":"your role"}
460 the value must be selected in layers.json.
466 "drawing_name" : "navigation"
470 #### *requestSurfaceXDG*
472 This API is for XDGLauncher, so it is not necessary for normal application.
473 XDGLauncher is created for XDG application for desktop app without editing for HMI-Framework.
474 Please see the repository in detail.
475 <https://gerrit.automotivelinux.org/gerrit/gitweb?p=staging%2Fxdg-launcher.git;a=summary>
479 Subscribe the Window Manager's event.
480 Application must subscribe `syncDraw` event.
482 - verb : "wm_subscribe"
483 - argument : {"event" : *event number*}
493 The event is abstracted with a number (enumeration).
503 | 6 | "screenUpdated" |
505 ### Activate/Deactivate
507 #### *activateWindow*
509 Request to display your application with `role` on the `area` to Window Manager.
510 Window Manager checks the app should be visible on the `area` and change layout according to the policy table using `role` .
511 If it is accepted, afb_req_success will be returned, and next Window Manager
512 will push the event `syncDraw` to applications which will be displayed.
513 If it is denied, afb_req_fail will be returned.
515 - verb : "activateWindow"
516 - argument : {"drawing_name" : "your role", "drawing_area" : "your area"}
518 the value must be selected among layers.json.
524 "drawing_name" : "navigation",
525 "drawing_area" : "normal.full"
529 #### *deactivateWindow*
531 Request to hide your application to Window Manager.
532 This verb is supposed to be used by high priority application which
533 are for example popup application or system UI application such like alert.
534 If Window Manager set the priority of popup high in the policy, Window Manager may not hide the popup even if normal applications
535 send `activateWindow` until popup application send `deactivateWindow` . This behavior depends on the policy table. After this request, Window Manager checks which app should be visible and change layout according to the policy table.
537 - verb : "deactivateWindow"
542 Notify Window Manager of application finishes drawing.
543 This function must be sent in event `syncDraw`.
544 Otherwise, Window Manager will roll back to previous state and reject your request `activateWindow` .
547 - argument : {"drawing_name" : "your role"}
553 "drawing_name" : "navigation",
557 #### *changeAreaSize*
559 Request to change the size of area and location. Then Window Manager sends `syncDraw` to the applications whose size and location will be changed.
560 The caller has responsible of appearance of layouts.
562 The use case of this function is shown in below.
563 The system application such like HomeScreen call this function, then the layout changes. The trigger may be user request on GUI, or system events and so on.
565 ![chnage_layout_img](parts/wm_change_layout.png)
567 The sequence is below.
569 ![change_layout_sequnce](parts/change_layout_seq.png)
571 - verb : "changeAreaSize"
572 - argument : {"areas" : [{"name":"area_name","rect":{"x":int,"y":int,"w":int,"h":int}, ...}]}
574 Note: Only the application whose role is written in whitelist is allowed to call this API. This is because marcious application can change the layouts. The layout should be controled by system application.
578 #### *getDisplayInfo*
580 Get screen information such as resolution.
582 - verb : "getDisplayInfo"
585 Return : The screen information will return.
598 "jtype" : "afb-reply",
602 "uuid":"05ae219a-0e56-4f46-af9f-3186a18cb110"
609 "width_mm", "height_mm" is from output which is one of the wayland object.
610 These items lack reliability, so recommend not to use.
614 Get area definition defined in areas.json.
616 - verb : "getAreaList"
619 Return : The area definition list.
637 "name":"restriction.split.sub",
650 "uuid":"0e6b8835-0df0-4a34-9718-125e6258b378"
655 ### Event from Window Manager
657 | Number | Event | version |
659 | 0 | "active" | from 0.7|
660 | 1 | "inactive" | from 0.7 |
661 | 2 | "visible" | from 0.7 |
662 | 3 | "invisible" | from 0.7 |
663 | 4 | "syncDraw" | from 0.7 |
664 | 5 | "flushDraw" | from 0.7 |
665 | 6 | "screenUpdated" | from 0.7 |
667 Events also consists of JSON.
668 The data of event is contained in `data` such like
672 "event":"windowmanager\/active",
674 "drawing_name":"navigation"
680 "event" is the event name.
681 "data" is the data object from Window Manager and contains
682 the message of event.
683 This section describes "event" and the contents of "data".
687 This event means when the application becomes active state.
693 "event":"windowmanager\/active",
695 "drawing_name":"launcher"
704 This event means when the application becomes inactive state.
710 "event":"windowmanager\/inactive",
712 "drawing_name":"launcher"
721 This event is issued when the application is visible state.
727 "event":"windowmanager\/visible",
729 "drawing_name":"launcher"
738 This event is issued when the application is invisible state.
744 "event":"windowmanager\/invisible",
746 "drawing_name":"launcher"
755 This event is issued by Window Manager state change operation in policy to the following cases.
757 - Your app requested `activateWindow` then your application will be resized or visible.
758 - Other app requested `activateWindow` then your application will be resized or visible.
759 - Window Manager change layout due to vehicle condition.
761 This event is the requests from Window Manager to
763 - request your app to callback `endDraw` to Window Manager.
764 - request your app to resize and redraw according to "drawing_area".
766 This is the abstract word then the real size is given in "drawing_rect".
772 "event":"windowmanager\/syncDraw",
774 "drawing_name":"radio",
775 "drawing_area":"normal.full",
787 An application which gets this event must send `endDraw`.
788 For details, please see the sequence.
792 This event is issued after Window Manager receives all `endDraw` from applications who recieved `syncDraw` . After this event, Window Manager expects applications to update its surface.
798 "event":"windowmanager\/flushDraw",
800 "drawing_name":"launcher"
809 This event is issued after the visible application changes as a state transition change. This contains resized applications and visible applications. This event is issued to all subscriber. Typical usecase is only for HomeScreen. If HomeScreen has an animation until the started application is visible such as progress bar, this signal may become a switch to stop the animation.
813 "event":"windowmanager\/screenUpdated",
824 "ids" is the application_id described in config.xml of application.
828 A client library implementation that internally uses the *libafbwsc*, is
829 provided in the `libwindowmanager`.
830 This library is for C++ native application.
832 Regarding more detail, please refer to <https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Flibwindowmanager.git;a=summary>
838 In order to enable application to activate application(render on layer),
839 above described steps need to be implemented.
841 As a minimal example the usage and initialization can look like the
844 Typical implementation of C++ application.
846 - Repo: `git clone https://gerrit.automotivelinux.org/gerrit/src/libhomescreen`
847 - Path: `sample/simple-egl/main.c`
849 Typical implementation of Qt application.
851 - Repo: `git clone https://gerrit.automotivelinux.org/gerrit/apps/radio`
852 - Repo: `git clone https://gerrit.automotivelinux.org/gerrit/apps/videoplayer`
854 This is the good example to write more simply for Qt application using QtAGLExtras.
860 Policy Manager decides next layout by using input event data and current state
861 based on the policy table.
863 And PolicyManager is plugin for WindowManager.
864 Therefore the OEMs can replace it.
868 Window Manager supports split layout to change policy and `areas.json`.
869 This section describes how to play split layout. The sample image is here.
871 ![example_split.png](parts/example_split.png)
873 To play the split layout,
875 1. Edit in `policy_manager/CMakeLists.txt` as follows:
877 ```cmake:policy_manager/CMakeList.txt
882 This results in using source code generated by ZIPC.
884 1. Set bool value "ON" to TRY_SPLIT_LAYOUT at line 28 in policy_manager/CMakeLists.txt as follows:
885 set(TRY_SPLIT_LAYOUT ON CACHE BOOL "Enable to show split layout")
887 1. copy window manager to your board
888 1. re-install windowmanager and reboot
890 As a result, if application requests `navi` with `activateWindow` when current layout is `video` or `mediaplayer`, Window Manager change layout to split window. The reverse is true.
894 Currently, the policy manager force application change the size even if the application which has the role doesn't have the split design. In that case, the view of application may be ugly. Window Manager supposes that applications may have multi designs according to system design by OEM. For example, if OEM sets 2 pattern layout for `navi`, the application which requests `navi` should have 2 pattern designs.
910 - Add API of getting area list and changing area size on runtime
914 - Reduce binary size to use ilmControl library.
915 - Change layer management. Client has one ivi-layer and can have multi surfaces.
916 - Stop conversion table which is compatible with old role to avoid complexity.
917 - Upgrade bindings v3.
918 - Add configuration file over-ride mechanism.
922 - Only single-surface Qt applications are support through the
923 libwindowmanager library. This is a limitation of how Qt creates surface
924 IDs for the ivi-application interface.
926 - Currenly, Window Manager supports only one screen. Dual display is not supported.
927 - As implemented in sample code, Qt application has to wait requesting `activateWindow` until `frameSwapped` is emitted.
928 - Qt application conceals, wayland and openGL processes, so it is difficult to call `swapBuffer` after `flushDraw` event described in the architecture document. But no problem if you use toolkit such as Qt, because it is automatically processed between applications and compositor(weston).
929 - Editing ZIPC is difficult for open source developer due to licence.