---
# System prepended metadata

title: WindowShowState
tags: [Chromium-Graphics, elkurin-daily-note]

---

# WindowShowState

In Chromium, there are multiple ways to represent the current window's state.  
[ui::PlatformWindowState](https://source.chromium.org/chromium/chromium/src/+/main:ui/platform_window/platform_window_delegate.h;l=35;drc=566136c38399f2d800672f43239cca16b617ddc5) is one of them.  
We also have [ash::WindowState](https://source.chromium.org/chromium/chromium/src/+/main:ash/wm/window_state.h;l=58;drc=eba294fc5b5484bef8fb3c1b7ca48ac7bcb27385) which is a class, not enum. It contains [chromeos::WindowStateType](chromeos/ui/base/window_state_type.h) as a state enum.  

These states are just a different enum for each platform and correspond to each other.

Today's target is [ui::WindowShowState](https://source.chromium.org/chromium/chromium/src/+/main:ui/base/ui_base_types.h;l=21;drc=e9fe61fd0dc3b731e9ee186f9dde74d986e3592d).  
Unlike PlatformWindowState and WindowStateType, it does not really correspond to one another which increases the complexity in UI.

## enum
Here's the enum that WindowShowState can express.
```cpp=
enum WindowShowState {
  // A default un-set state.
  SHOW_STATE_DEFAULT = 0,
  SHOW_STATE_NORMAL = 1,
  SHOW_STATE_MINIMIZED = 2,
  SHOW_STATE_MAXIMIZED = 3,
  SHOW_STATE_INACTIVE = 4,  // Views only, not persisted.
  SHOW_STATE_FULLSCREEN = 5,
  SHOW_STATE_END = 6  // The end of show state enum.
};
```
PlatformWindowState and WindowStateType supports chromeos-specific state such as snapped state, pinned ullscreen state... but WindowShowState does not.  
Adding them looks like TODO work.

`SHOW_STATE_DEFAULT` is used as a initial state.  
For example, on creating ne wwindow by BrowserServiceLacros, [`initial_show_state`](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/lacros/browser_service_lacros.cc;l=724;drc=e9fe61fd0dc3b731e9ee186f9dde74d986e3592d) is set to DEFAULT.

NORMAL represents non-minimized, maximized, fullscreen state.  
The window with a custom bounds.  
Note that even the window size is the maximum in the display, it's still considered as normal.

MINIMIZED, MAXIMIZED, FULLSCREEN is obvious. The window is minimized, maximized or fullscreen.

Last remaining one is INACTIVE.

## Inactive State
Then what is INACTIVE?  
INACTIVE is not actually the window state.  
When the window is not focused, it is called "inactive".  
This state represents the activation status, not the winow state.  
So, the window may be maximized, may be minimized, may be normal when the state is INACTIVE.  
It should not be fullscreen thought since fullscreen window must be focused.

This concept works well on showing the window.

[NativeWidgetAura::Show](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/widget/native_widget_aura.cc;l=713;drc=e9fe61fd0dc3b731e9ee186f9dde74d986e3592d) runs with a specific WindowShowState `show_state`.  
It uses `show_state` value to decide the property.  
If it's maximized or minimized, set the custom `restore_bounds` as the restore bounds.  
If it's maximized or fullscreen, we set [`kShowStateKey`](https://source.chromium.org/chromium/chromium/src/+/main:ui/aura/client/aura_constants.cc;l=75;drc=e9fe61fd0dc3b731e9ee186f9dde74d986e3592d) property to the current state.  
Then call Window::Show, but will NOT activate if the state is INACTIVE.  
After the activation, minimized the window is `show_state` is minimized. On [Minimize](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/widget/native_widget_aura.cc;l=814;drc=e9fe61fd0dc3b731e9ee186f9dde74d986e3592d) the `kShowStateKey` property will be overriden by minimized.

WindowShowState is used on Widget initialization as well.  
On [Widget::Init](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/widget/widget.cc;l=453;drc=e5e508bf101f65eed6f846327cb29f07c1fe0a38), the widget will be initialized with [Widget::InitParams](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/widget/widget.h;l=183;drc=e9fe61fd0dc3b731e9ee186f9dde74d986e3592d).  
Here, the window state kept is in [WindowShowState](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/widget/widget.h;l=337;drc=e9fe61fd0dc3b731e9ee186f9dde74d986e3592d) format.


## Correspondance to other states
chromeos::WindowStateType has inactive state, so we can convert it.  
However, PlatformWindowState only supports the pure window state and does not have inactive state.  

We have PlatformWindowState -> WindowStateType conversion.: [ToChromeosWindowStateType](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/widget/desktop_aura/desktop_window_tree_host_lacros.cc;l=40;drc=3b37c45f265d5601f8a5b4e27f9ff07370cf4f23).

```cpp=
chromeos::WindowStateType ToChromeosWindowStateType(
    ui::PlatformWindowState state) {
  switch (state) {
    case ui::PlatformWindowState::kUnknown:
      return chromeos::WindowStateType::kDefault;
    case ui::PlatformWindowState::kMaximized:
      return chromeos::WindowStateType::kMaximized;
    case ui::PlatformWindowState::kMinimized:
      return chromeos::WindowStateType::kMinimized;
    case ui::PlatformWindowState::kNormal:
      return chromeos::WindowStateType::kNormal;
    case ui::PlatformWindowState::kFullScreen:
      return chromeos::WindowStateType::kFullscreen;
    case ui::PlatformWindowState::kSnappedPrimary:
      return chromeos::WindowStateType::kPrimarySnapped;
    case ui::PlatformWindowState::kSnappedSecondary:
      return chromeos::WindowStateType::kSecondarySnapped;
    case ui::PlatformWindowState::kFloated:
      return chromeos::WindowStateType::kFloated;
    case ui::PlatformWindowState::kPinnedFullscreen:
      return chromeos::WindowStateType::kPinned;
    case ui::PlatformWindowState::kTrustedPinnedFullscreen:
      return chromeos::WindowStateType::kTrustedPinned;
  }
}
```

As yo ucan see, there is not map toward inactive.  

We also have WindowStateType <-> WindowShowState conversion: [ToWindowStateType](https://source.chromium.org/chromium/chromium/src/+/main:chromeos/ui/base/window_state_type.cc;l=43;drc=e9fe61fd0dc3b731e9ee186f9dde74d986e3592d) and [ToWindowShowState](https://source.chromium.org/chromium/chromium/src/+/main:chromeos/ui/base/window_state_type.cc;l=63;drc=e9fe61fd0dc3b731e9ee186f9dde74d986e3592d).  
These two are almost the same while WindowStateType has more types like TrustedPinned, PrimarySnapped, Pip...  
These special state can be parsed as fullscreen in WindowShowState.