Skip to content

Commit 9e86ee7

Browse files
captainbrossetMichael Hoffman
andauthored
Updating the Window Controls Overlay docs (#2149)
* Update to the WCO docs * Update microsoft-edge/progressive-web-apps-chromium/how-to/window-controls-overlay.md Co-authored-by: Michael Hoffman <v-mhoffman@microsoft.com> Co-authored-by: Michael Hoffman <v-mhoffman@microsoft.com>
1 parent e90e25d commit 9e86ee7

8 files changed

Lines changed: 46 additions & 64 deletions

File tree

microsoft-edge/progressive-web-apps-chromium/how-to/window-controls-overlay.md

Lines changed: 46 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ ms.author: msedgedevrel
66
ms.topic: conceptual
77
ms.prod: microsoft-edge
88
ms.technology: pwa
9-
ms.date: 09/02/2021
9+
ms.date: 09/01/2022
1010
---
1111
# Display content in the title bar
1212

13-
A PWA can define how it should be displayed on mobile platforms, by using the [display](https://developer.mozilla.org/docs/Web/Manifest/display) property in the app manifest file. However, to create an immersive, native-like experience, _desktop_ PWAs can't use this approach.
13+
A PWA can define how it should be displayed on mobile platforms, by using the [display](https://developer.mozilla.org/docs/Web/Manifest/display) member in the web app manifest file. However, to create an immersive, native-like experience, _desktop_ PWAs can use another approach.
1414

15-
By default, the app area starts immediately below the reserved title bar area:
15+
By default, a PWA installed on desktop can display content in an area that starts immediately below the reserved title bar area:
1616

17-
![The default Windows app title bar shown on the My Tracks demo app.](../media/my-tracks-titlebar.png)
17+
![A PWA app on Windows showing that the app content is displayed below the reserved title bar area.](../media/wco-reserved-titlebar.png)
1818

1919
Displaying content where the title bar normally is can help PWAs feel more native. Many desktop applications, such as Visual Studio Code, Microsoft Teams, and Microsoft Edge already do this:
2020

@@ -26,32 +26,14 @@ The Window Controls Overlay API does the following:
2626
* Makes it possible for your content to stay clear of this overlay.
2727

2828

29-
<!-- ====================================================================== -->
30-
## Enable the Window Controls Overlay API in Microsoft Edge
31-
32-
The Window Controls Overlay API is experimental and must be enabled in Microsoft Edge, to use it.
33-
34-
To enable the Window Controls Overlay API:
35-
36-
1. In Microsoft Edge, go to `edge://flags`.
37-
1. Select **Search flags** and then type "window controls overlay".
38-
1. Select **Default** > **Enabled** > **Restart**.
39-
40-
![Enable the Window Controls Overlay API experiment.](../media/enable-window-controls-overlay-experiment.png)
41-
42-
The Window Controls Overlay API is also available as an origin trials feature. For your app's users to benefit from the Window Controls Overlay without having to enable it in Microsoft Edge, you can use an origin trial.
43-
44-
For more information about Origin Trials, go to [Microsoft Edge Origin Trials Developer Console](https://developer.microsoft.com/microsoft-edge/origin-trials).
45-
46-
4729
<!-- ====================================================================== -->
4830
## Enable the Window Controls Overlay in your app
4931

5032
The first thing to do is to enable the Window Controls Overlay feature in your app's [Web App Manifest file](web-app-manifests.md). To do this, in the manifest file, set the `display_override` property:
5133

5234
```json
5335
{
54-
"display_override": ["window-controls-overlay"]
36+
"display_override": ["window-controls-overlay"]
5537
}
5638
```
5739

@@ -61,7 +43,7 @@ The first thing to do is to enable the Window Controls Overlay feature in your a
6143

6244
When the Window Controls Overlay feature is enabled, the user can choose to have the title bar or not, by clicking the title bar toggle button:
6345

64-
![Select the title bar toggle button.](../media/my-tracks-titlebar-toggle.png)
46+
![Select the title bar toggle button.](../media/wco-toggle-button.png)
6547

6648
Your code can't assume that the window controls overlay is displayed, because:
6749
* The user can choose whether to display the title bar.
@@ -79,56 +61,57 @@ Four environment variables are added by the Window Controls Overlay feature:
7961

8062
| Variable | Description |
8163
|:--- |:---
82-
| `titlebar-area-x` | Distance, in `px`, of the overlay from the left side of the window |
83-
| `titlebar-area-y` | Distance, in `px`, of the overlay from the top side of the window |
84-
| `titlebar-area-width` | Width of the overlay, in `px` |
85-
| `titlebar-area-height` | Height of the overlay, in `px` |
64+
| `titlebar-area-x` | Distance, in `px`, of the area normally occupied by the title bar from the left side of the window |
65+
| `titlebar-area-y` | Distance, in `px`, of the area normally occupied by the title bar from the top side of the window |
66+
| `titlebar-area-width` | Width of the title bar area, in `px` |
67+
| `titlebar-area-height` | Height of the title bar area, in `px` |
8668

87-
You can use these environment variables to position and size your app's title bar:
69+
You can use these environment variables to position and size your own content where the title bar would normally appear, when the window controls overlay feature is disabled:
8870

8971
```css
9072
#title-bar {
91-
position: fixed;
92-
left: env(titlebar-area-x);
93-
top: env(titlebar-area-y);
94-
height: env(titlebar-area-height);
95-
width: env(titlebar-area-width);
73+
position: fixed;
74+
left: env(titlebar-area-x, 0);
75+
top: env(titlebar-area-y, 0);
76+
height: env(titlebar-area-height, 50px);
77+
width: env(titlebar-area-width, 100%);
9678
}
9779
```
9880

9981
Using `position: fixed;` makes sure your title bar does not scroll with the rest of the content and instead stays aligned with the window controls overlay.
10082

10183
Knowing where the overlay is and how big it is is important. The overlay might not always be on the same side of the window; on macOS, the overlay is on the left side, but on Windows, the overlay is on the right side. Also, the overlay might not always be the same size.
10284

85+
The `env()` CSS function takes a second parameter that's useful for defining the position of your app content when the window controls overlay feature is missing or disabled.
86+
10387

10488
<!-- ====================================================================== -->
10589
## Make regions of your app drag handlers for the window
10690

107-
When the title bar is hidden, only the system-critical window controls remain visible (the **Maximize**, **Minimize**, **Close**, and **App Info** icons). This means that there is very little space available for users to move the app around.
91+
When the title bar is hidden, only the system-critical window controls remain visible (the **Maximize**, **Minimize**, **Close**, and **App Info** icons). This means that there is very little space available for users to move the application window around.
10892

10993
You can use the `-webkit-app-region` CSS property to offer more ways for users to drag the app. For example, if your app has its own titlebar, you can turn its titlebar into a window drag handler:
11094

11195
```css
11296
#title-bar {
113-
position: absolute;
114-
left: env(titlebar-area-x);
115-
top: env(titlebar-area-y);
116-
height: env(titlebar-area-height);
117-
width: env(titlebar-area-width);
118-
-webkit-app-region: drag;
97+
position: fixed;
98+
left: env(titlebar-area-x, 0);
99+
top: env(titlebar-area-y, 0);
100+
height: env(titlebar-area-height, 50px);
101+
width: env(titlebar-area-width, 100%);
102+
-webkit-app-region: drag;
119103
}
120104
```
121105

122106

123107
<!-- ====================================================================== -->
124108
## React to overlay changes
125109

126-
A user can toggle the title bar or change the window dimensions while the app is running. Knowing when these things happen can be important for your app. Your app might need to rearrange some of the content that's displayed in the title bar, or rearrange your layout elsewhere on the page.
110+
A user can toggle the title bar or change the window dimensions while the app is running. Knowing when these things happen can be important for your app. Your app might need to rearrange some of the content that's displayed in the title bar, or rearrange the layout elsewhere on the page.
127111

128-
To listen for changes, use the `geometrychange` event. To detect whether the title bar is visible, use the `visible` property on the `navigator.windowControlsOverlay` object.
112+
To listen for changes, use the `geometrychange` event on the `navigator.windowControlsOverlay` object. To detect whether the title bar is visible, use the `visible` property on the `navigator.windowControlsOverlay` object.
129113

130-
> [!NOTE]
131-
> The `geometrychange` is fired very frequently when the user resizes the window. To avoid running layout-changing code too often and causing performance problems in your app, use a `debounce` function to limit how many times the event is handled. See [The Difference Between Throttling and Debouncing](https://css-tricks.com/the-difference-between-throttling-and-debouncing/).
114+
Note that the `geometrychange` is fired very frequently when the user resizes the window. To avoid running layout-changing code too often and causing performance problems in your app, use a `debounce` function to limit how many times the event is handled. See [The Difference Between Throttling and Debouncing](https://css-tricks.com/the-difference-between-throttling-and-debouncing/).
132115

133116
```javascript
134117
const debounce = (func, wait) => {
@@ -144,40 +127,39 @@ const debounce = (func, wait) => {
144127
};
145128

146129
if ('windowControlsOverlay' in navigator) {
147-
navigator.windowControlsOverlay.addEventListener('geometrychange', debounce(e => {
148-
// Detect if the Window Controls Overlay is visible.
149-
const isOverlayVisible = navigator.windowControlsOverlay.visible;
150-
// Get the size and position of the title bar area.
151-
const titleBarRect = e.titlebarAreaRect;
152-
153-
console.log(`The overlay is ${isOverlayVisible ? 'visible' : 'hidden'}, the title bar width is ${titleBarRect.width}px`);
154-
}, 200));
130+
navigator.windowControlsOverlay.addEventListener('geometrychange', debounce(e => {
131+
// Detect if the Window Controls Overlay is visible.
132+
const isOverlayVisible = navigator.windowControlsOverlay.visible;
133+
134+
// Get the size and position of the title bar area.
135+
const titleBarRect = e.titlebarAreaRect;
136+
137+
console.log(`The overlay is ${isOverlayVisible ? 'visible' : 'hidden'}, the title bar width is ${titleBarRect.width}px`);
138+
}, 200));
155139
}
156140
```
157141

158142

159143
<!-- ====================================================================== -->
160144
## Demo app
161145

162-
My Tracks is a PWA demo app that uses the Window Controls Overlay feature.
163-
164-
1. In Microsoft Edge, [Enable the Window Controls Overlay](#enable-the-window-controls-overlay-in-your-app).
146+
1DIV is a PWA demo app that uses the Window Controls Overlay feature.
165147

166-
2. Go to [My Tracks](https://captainbrosset.github.io/mytracks/) and install the app.
148+
1. In Microsoft Edge, go to [1DIV](https://microsoftedge.github.io/Demos/1DIV/dist/) and install the app.
167149

168-
3. Select the **Hide title bar** button from the app title bar.
150+
1. Click **Hide title bar** in the app title bar.
169151

170-
The app now displays content all the way to the top of the window frame, where the title bar used to be. The top area of the map is a drag handler, to let the user move the window.
152+
The app now displays content all the way to the top of the window frame, where the title bar used to be. The top area of the app is a drag handler, to let users move the window.
171153

172-
![The top area of the map can be used to move the window.](../media/my-tracks-draggable-titlebar.png)
154+
![The top area of the map can be used to move the window.](../media/wco-draggable-titlebar.png)
173155

174-
The source code for this app is in the [My Tracks](https://github.com/captainbrosset/mytracks) repo.
156+
The source code for this demo app is in the [1DIV](https://github.com/MicrosoftEdge/Demos/tree/main/1DIV) repo.
175157

176-
* The [manifest.json](https://github.com/captainbrosset/mytracks/blob/main/mytracks/manifest.json) source file declares the app's use of the Window Controls Overlay feature.
158+
* The [manifest.json](https://github.com/MicrosoftEdge/Demos/blob/main/1DIV/dist/manifest.json) source file declares the app's use of the Window Controls Overlay feature.
177159

178-
* The [overlay.js](https://github.com/captainbrosset/mytracks/blob/main/src/overlay.js) source file uses the `navigator.windowControlsOverlay` object.
160+
* The [app.js](https://github.com/MicrosoftEdge/Demos/blob/main/1DIV/src/app.js) source file uses the `navigator.windowControlsOverlay` object.
179161

180-
* The [style.css](https://github.com/captainbrosset/mytracks/blob/main/mytracks/style.css) source file uses the `titlebar-area-height` CSS environment variable.
162+
* The [app.css](https://github.com/MicrosoftEdge/Demos/blob/main/1DIV/dist/app.css) source file uses the `titlebar-area-*` CSS environment variables.
181163

182164

183165
<!-- ====================================================================== -->
Binary file not shown.
Binary file not shown.
Binary file not shown.
155 KB
Loading
91.7 KB
Loading
85.4 KB
Loading
85.7 KB
Loading

0 commit comments

Comments
 (0)