3 title: Window Manager Developer Guide
5 https://git.automotivelinux.org/apps/agl-service-windowmanager/plain/doc/ApplicationGuide.md?h=master
8 <!-- WARNING: This file is generated by fetch_docs.js using /home/boron/Documents/AGL/docs-webtemplate/site/_data/tocs/apis_services/master/agl-service-windowmanager-developer-guides-api-services-book.yml -->
10 # Window Manager Application Guide
14 - [Target reader of this document](#target-reader-of-this-document)
15 - [Overview](#overview)
16 - [Supported usecase](#supported-usecase)
17 - [Getting Started](#getting-started)
18 - [Build](#build-by-sdk)
21 - [Enable to call Window Manager](#enable-to-call-window-manager)
22 - [Software Architecture](#software-architecture)
23 - [Sequence](#sequence)
24 - [API reference](#api-reference)
25 - [Request to Window Manager](#request-to-window-manager)
26 - [Event from Window Manager](#event-from-window-manager)
27 - [Client Library](#client-library)
28 - [Sample code](#sample-code)
29 - [Policy Manager](#policy-manager)
30 - [Enabling split](#enabling-split)
31 - [Release Note](#release-note)
33 | Version | Author | Updated at |
35 | 0.8 | TOYOTA MOTOR CORPORATION| 22th/Feb/2019 |
39 ## Target reader of this document
41 This document is intended for developers and system integrators who
42 need to know, how Window manager works and how it is to be used.
44 ### Scope of this Document
46 This document covers Window manager that was implemented for TMC and
47 delivered to the Automotive Grade Linux (AGL) project. It includes its
48 implementation details, concepts of operation, configuration and usage.
52 - document of the underlying architecture, see
53 [HMI-Framework](https://wiki.automotivelinux.org/hmiframework).
55 - document of the AGL application framework and its technologies,
57 Framework](https://wiki.automotivelinux.org/agl-distro/app-framework).
59 - document of HomeScreen, see
60 [HomeScreen](./ApplicationGuide.html).
62 It is highly recommended to have a good understanding of these documents
63 and projects before using Window manager.
69 Window Manager is the service process which provides window management based on policy.
70 And implements a layout switching of applications on
71 multiple layers and with different layer layouts.
72 Window Manager is based on ivi layer management from GENIVI and AGL application framework.
74 Window Manager consists of
77 - service binding library
78 - shared library for policy management
81 In order to understand Window Manager, the below figure shows the one of typical usecases.
82 In this example, there are two mode for window management.
84 1. Window Management in `Car Stops`
85 1. Window Management in `Car Runs`
87 ![Figure: Typical usecase](parts/state_change_example.png)
89 The important points are:
91 - Window transition should be done by Window Manager
93 Window Manager switch application displayed on top layer by user operation(touch shortcut button).
94 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.
96 - There is a priority `role` for each application.
98 Window Manager realizes state transition change based on the policy which consists of `role`.
99 According to the state transition table, it controls the visibility of application window, layout change, and so on.
100 The reasons why this is necessary are
102 - to support user driving
103 - not to disturb a driver concerns on driving for safety
105 In this example, for safety, when the car starts running, Window Manager set up the role `videoplayer`
106 to be masked and uncontrollable by user not to disturb driver concerns.
107 And, for supporting driving, set up `navigation` role to be displayed 3 seconds after the car ran.
108 In `Car Run` state, the user can't switch to other application from Navigation application until car stops.
113 - When an user chooses a different application, Window Manager changes the layout and then displays the application.
114 - When an user chooses a different application, Window Manager changes the layout and then hides the displayed application.
116 - Window Manager changes layout according to policy table based on `role`.
117 3. Define Layout by `area` configuration
118 - Window Manager realizes the abstracted `area` and can resize the window by using it. User can easily edit this configuration.
127 git clone https://gerrit.automotivelinux.org/gerrit/apps/agl-service-windowmanager
128 cd agl-service-windowmanager
131 source <your SDK path> // normally this is /opt/agl-sdk/environment
137 The widget package is populated in the 'package' directory.
141 root windowmanager-service.wgt
146 Copy windowmanager-service.wgt to the file system then execute the following command.
149 afm-util install windowmanager-service.wgt
154 You can make Window Manager object files with the following two stage operations.
161 repo init -u https://gerrit.automotivelinux.org/gerrit/AGL/AGL-repo
168 source meta-agl/scripts/aglsetup.sh -m m3ulcb agl-demo hmi-framework
169 bitbake agl-demo-platform
174 ## Enable to call Window Manager
176 To call Window Manager, it is important to enable the permission from security framework.
177 To use Window Manager API, an application or a service shall add the following configuration definition into "config.xml" of your application.
180 <feature name="urn:AGL:widget:required-api">
181 <param name="windowmanager" value="ws" />
185 To call Window Manager function easily, Window Manager provides a library which is called "libwindowmanager".
186 This library provides a function style API calling interface.
187 So you can include the libwindowmanager.hpp header file, and can link against this library.
188 Please also refer to the sample application.
190 See also our [Sample code](#sample-code).
194 ## Software Architecture
196 The static relationship with other components is shown below.
197 The actual logic of Window Manager is the binding in Binder(afb-daemon).
198 Window Manager is based on AGL application framework,
199 so the IPC via websocket is protected by AGL application framework.
201 The upper binder is for the application side security context.
202 The lower binder is the Window Manager for the server side security context.
203 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.
204 On the other hand, regarding lower binder there is only one module in the system. This binder receives messages from multiple applications.
206 An application can use libwindowmanager.so to call Window Manager API simply.
208 Window Manager is based on the GENIVI layer management system.
210 ![wm_software_stack.png](parts/wm_software_stack.png)
214 Layers are entities that means the application stack group defined in `layers.json`.
215 This doesn't mean layer ID defined in GENIVI ivi layer.
216 The layer ID is used for application itself in Window Manager.
217 Currently, application can't have multiple surfaces in Window Manager.
221 Surfaces are *placed* on layers . The surface
222 will then be resized to dimensions, according to the name of `areas.json`
223 application requests by `activateWindow` or policy management.
224 As default, `normal.full` is set by libwindowmanager for native application.
228 The window manager is configured with the *layers.json*, *areas.json*, *roles.db* configuration
229 files. By default they are searched in `${AFM_APP_INSTALL_DIR}/etc/`.
231 Sample configurations are provided with the window manager
232 implementation, these samples are installed to ${AFM_APP_INSTALL_DIR}/etc/ .
234 This configuration is supposed to be configured by policy designer which means OEM or Tier1.
238 `layers.json` has three roles.
240 1. Create application containers `Layer`.
241 1. Set id range for applications.
242 1. Attach application to `Layer` according to the role application requests.
244 The sample configuration is here
248 "comment": "Surface ID to Layer ID mapping",
251 "surface_role": "HomeScreen",
252 "comment": "This surface should never be made invisible (The HomeScreen)"
257 "role": "BackGroundLayer",
258 "name": "BackGroundLayer",
260 "comment": "Single BackGround layer map for the map, radio, music and video"
263 "role": "homescreen",
264 "name": "FarHomeScreen",
266 "comment": "FarHomeScreen is the part of HomeScreen. The z order of this layer is lower than NearHomeScreen"
269 "role": "music|video|browser|radio|phone|map|hvac|settings|dashboard|poi|mixer|sdl|launcher|fallback",
272 "comment": "Range of IDs that will always be placed on layer 1001"
275 "role": "^on_screen.*",
278 "comment": "Range of IDs that will always be placed on the OnScreen layer, that gets a very high 'dummy' id of 9999"
284 Each mapping defines the following items to map corresponding surfaces
287 - `role` defines what kind of ability the application has. And the application will be attached to `Layer` according to the `role`.
288 A regular expression that application drawing names
289 are matched against. If applications match this regular expression,
290 the surface will be visible on this layer.
292 - `name` is just a name definition for `Layer`, it has no
293 functional use apart from identifying a layer with a name.
294 - `layer_id` is the id used in GENIVI IVI layer management control.
296 `Layer` stacks from beginning to end.
298 The above `Layer` example image is below.
300 ![wm_layer_stack.png](parts/wm_layer_stack.png)
303 "fallback" role is the special role. This role is set if the role application requests doesn't exist
304 in `layers.json`. Then, Window Manager will accept any applications.
305 If the "fallback" is not set in layers.json, window manager blocks the application displaying in such case.
306 In such a situation, you have to add your role(application name) at "role" in layers.json.
309 `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.
310 The problem is issued in <https://jira.automotivelinux.org/browse/SPEC-1484>.
314 Area means abstract expressions of 2-dimensional size and position.
315 `areas.json` defines the area which an application is set.
321 "name": "fullscreen",
330 "name": "normal.full",
339 "name": "split.main",
360 The image of the above setting is described below.
362 ![wm_area.png](parts/wm_area.png)
364 - `name` is an abstract data of rectangle.
366 - `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.
368 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.
372 `fullscreen` must be set because this is the base size of scaling in Window Manger.
376 The direction of the coordinates depends on `transform` in weston.ini.
377 Currently, agl-demo-platform set `transform=270`.
378 This suppose to use screen vertically.
386 To understand the sequence between application and window manager, refer to the [spec document](https://wiki.automotivelinux.org/hmiframework).
388 The typical sequence to render your application, follow the sequence below.
390 1. Register your role (and request surfaceID)
392 ![request_role.png](parts/request_role.png)
394 The above sequence is the initialization phase of your application to use Window Manager.
395 An Application has to register your `role` to Window Manager. For ivi-shell application, Window Manager generates surfaceID to input it into the function
396 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`.
398 [requestSurface](#requestSurface)
400 [setEventHandler](#wm_subscribe)
402 setEventHandler is API of libwindowmanager. This calls wm_subscribe internally.
404 2. Display your window
406 ![hmi_framework_designed_seq_toyota.png](parts/hmi_framework_designed_seq_toyota.png)
408 To display your window, your application has to request `activateWindow` with `role` and `area` to Window Manager.
409 Window Manager checks the app should be visible on the `area` according to the policy table using `role` .
410 If it is accepted, afb_req_success will be returned, and next Window Manager
411 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,
412 but this shall be emitted to other applications whose size shall be changed.
414 [activateWindow](#activateWindow)
416 [syncDraw](#syncDraw)
420 [flushDraw](#flushDraw)
422 3. Activate OnScreen Window
424 ![deactivate_window.png](parts/deactivate_window.png)
426 [deactivateWindow](#deactivateWindow)
428 [See sample code for more detail about OnScreen Window.](https://gerrit.automotivelinux.org/gerrit/gitweb?p=apps%2Fonscreenapp.git;a=summary)
430 The above sequence shows the sample of OnScreen Window.
431 If the role is high priority than NormapApp, Window Manager rejects NormalApp
432 request when OnScreenApp is displayed.
434 Note : Above repository is currently empty, so please refer to the sandbox branch.
440 ### Request to Window Manager
442 | Use | verb | version |
444 | Initialize | requestSurface | from 0.7 |
445 | | wm_subscribe | from 0.7 |
446 | | requestSurfaceXDG | from 0.7 |
447 |Activate/Deactivate| activateWindow | from 0.7 |
448 | | deactivateWindow | from 0.7 |
449 | | endDraw | from 0.7 |
450 | Change area size | changeAreaSize | from 0.8 |
451 | Get Infomation | getDisplayInfo | from 0.7 |
452 | | getAreaList | from 0.8 |
454 Note: We created this table from 0.7
456 The data of IPC via websocket consists of JSON.
457 This section describes the verb of API and key.
458 Normally, the body of requesting API will be here.
462 #### *requestSurface*
464 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.
466 - verb : "requestSurface"
467 - argument : {"drawing_name":"your role"}
469 the value must be selected in layers.json.
475 "drawing_name" : "navigation"
479 #### *requestSurfaceXDG*
481 This API is for XDGLauncher, so it is not necessary for normal application.
482 XDGLauncher is created for XDG application for desktop app without editing for HMI-Framework.
483 Please see the repository in detail.
484 <https://gerrit.automotivelinux.org/gerrit/gitweb?p=staging%2Fxdg-launcher.git;a=summary>
488 Subscribe the Window Manager's event.
489 Application must subscribe `syncDraw` event.
491 - verb : "wm_subscribe"
492 - argument : {"event" : *event number*}
502 The event is abstracted with a number (enumeration).
512 | 6 | "screenUpdated" |
514 ### Activate/Deactivate
516 #### *activateWindow*
518 Request to display your application with `role` on the `area` to Window Manager.
519 Window Manager checks the app should be visible on the `area` and change layout according to the policy table using `role` .
520 If it is accepted, afb_req_success will be returned, and next Window Manager
521 will push the event `syncDraw` to applications which will be displayed.
522 If it is denied, afb_req_fail will be returned.
524 - verb : "activateWindow"
525 - argument : {"drawing_name" : "your role", "drawing_area" : "your area"}
527 the value must be selected among layers.json.
533 "drawing_name" : "navigation",
534 "drawing_area" : "normal.full"
538 #### *deactivateWindow*
540 Request to hide your application to Window Manager.
541 This verb is supposed to be used by high priority application which
542 are for example popup application or system UI application such like alert.
543 If Window Manager set the priority of popup high in the policy, Window Manager may not hide the popup even if normal applications
544 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.
546 - verb : "deactivateWindow"
551 Notify Window Manager of application finishes drawing.
552 This function must be sent in event `syncDraw`.
553 Otherwise, Window Manager will roll back to previous state and reject your request `activateWindow` .
556 - argument : {"drawing_name" : "your role"}
562 "drawing_name" : "navigation",
566 #### *changeAreaSize*
568 Request to change the size of area and location. Then Window Manager sends `syncDraw` to the applications whose size and location will be changed.
569 The caller has responsible of appearance of layouts.
571 The use case of this function is shown in below.
572 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.
574 ![chnage_layout_img](parts/wm_change_layout.png)
576 The sequence is below.
578 ![change_layout_sequnce](parts/change_layout_seq.png)
580 - verb : "changeAreaSize"
581 - argument : {"areas" : [{"name":"area_name","rect":{"x":int,"y":int,"w":int,"h":int}, ...}]}
583 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.
587 #### *getDisplayInfo*
589 Get screen information such as resolution.
591 - verb : "getDisplayInfo"
594 Return : The screen information will return.
607 "jtype" : "afb-reply",
611 "uuid":"05ae219a-0e56-4f46-af9f-3186a18cb110"
618 "width_mm", "height_mm" is from output which is one of the wayland object.
619 These items lack reliability, so recommend not to use.
623 Get area definition defined in areas.json.
625 - verb : "getAreaList"
628 Return : The area definition list.
646 "name":"restriction.split.sub",
659 "uuid":"0e6b8835-0df0-4a34-9718-125e6258b378"
664 ### Event from Window Manager
666 | Number | Event | version |
668 | 0 | "active" | from 0.7|
669 | 1 | "inactive" | from 0.7 |
670 | 2 | "visible" | from 0.7 |
671 | 3 | "invisible" | from 0.7 |
672 | 4 | "syncDraw" | from 0.7 |
673 | 5 | "flushDraw" | from 0.7 |
674 | 6 | "screenUpdated" | from 0.7 |
676 Events also consists of JSON.
677 The data of event is contained in `data` such like
681 "event":"windowmanager\/active",
683 "drawing_name":"navigation"
689 "event" is the event name.
690 "data" is the data object from Window Manager and contains
691 the message of event.
692 This section describes "event" and the contents of "data".
696 This event means when the application becomes active state.
702 "event":"windowmanager\/active",
704 "drawing_name":"launcher"
713 This event means when the application becomes inactive state.
719 "event":"windowmanager\/inactive",
721 "drawing_name":"launcher"
730 This event is issued when the application is visible state.
736 "event":"windowmanager\/visible",
738 "drawing_name":"launcher"
747 This event is issued when the application is invisible state.
753 "event":"windowmanager\/invisible",
755 "drawing_name":"launcher"
764 This event is issued by Window Manager state change operation in policy to the following cases.
766 - Your app requested `activateWindow` then your application will be resized or visible.
767 - Other app requested `activateWindow` then your application will be resized or visible.
768 - Window Manager change layout due to vehicle condition.
770 This event is the requests from Window Manager to
772 - request your app to callback `endDraw` to Window Manager.
773 - request your app to resize and redraw according to "drawing_area".
775 This is the abstract word then the real size is given in "drawing_rect".
781 "event":"windowmanager\/syncDraw",
783 "drawing_name":"radio",
784 "drawing_area":"normal.full",
796 An application which gets this event must send `endDraw`.
797 For details, please see the sequence.
801 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.
807 "event":"windowmanager\/flushDraw",
809 "drawing_name":"launcher"
818 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.
822 "event":"windowmanager\/screenUpdated",
833 "ids" is the application_id described in config.xml of application.
837 A client library implementation that internally uses the *libafbwsc*, is
838 provided in the `libwindowmanager`.
839 This library is for C++ native application.
841 Regarding more detail, please refer to <https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Flibwindowmanager.git;a=summary>
847 In order to enable application to activate application(render on layer),
848 above described steps need to be implemented.
850 As a minimal example the usage and initialization can look like the
853 Typical implementation of C++ application.
855 - Repo: `git clone https://gerrit.automotivelinux.org/gerrit/src/libhomescreen`
856 - Path: `sample/simple-egl/main.c`
858 Typical implementation of Qt application.
860 - Repo: `git clone https://gerrit.automotivelinux.org/gerrit/apps/radio`
861 - Repo: `git clone https://gerrit.automotivelinux.org/gerrit/apps/videoplayer`
863 This is the good example to write more simply for Qt application using QtAGLExtras.
869 Policy Manager decides next layout by using input event data and current state
870 based on the policy table.
872 And PolicyManager is plugin for WindowManager.
873 Therefore the OEMs can replace it.
877 Window Manager supports split layout to change policy and `areas.json`.
878 This section describes how to play split layout. The sample image is here.
880 ![example_split.png](parts/example_split.png)
882 To play the split layout,
884 1. Edit in `policy_manager/CMakeLists.txt` as follows:
886 ```cmake:policy_manager/CMakeList.txt
891 This results in using source code generated by ZIPC.
893 1. Set bool value "ON" to TRY_SPLIT_LAYOUT at line 28 in policy_manager/CMakeLists.txt as follows:
894 set(TRY_SPLIT_LAYOUT ON CACHE BOOL "Enable to show split layout")
896 1. copy window manager to your board
897 1. re-install windowmanager and reboot
899 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.
903 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.
919 - Add API of getting area list and changing area size on runtime
923 - Reduce binary size to use ilmControl library.
924 - Change layer management. Client has one ivi-layer and can have multi surfaces.
925 - Stop conversion table which is compatible with old role to avoid complexity.
926 - Upgrade bindings v3.
927 - Add configuration file over-ride mechanism.
931 - Only single-surface Qt applications are support through the
932 libwindowmanager library. This is a limitation of how Qt creates surface
933 IDs for the ivi-application interface.
935 - Currenly, Window Manager supports only one screen. Dual display is not supported.
936 - As implemented in sample code, Qt application has to wait requesting `activateWindow` until `frameSwapped` is emitted.
937 - 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).
938 - Editing ZIPC is difficult for open source developer due to licence.