ohos.window (Window)

Note:

Currently in the beta phase.

Provides window-related functionalities.

Import Module

import kit.ArkUI.*

func findWindow(String)

public func findWindow(name: String): Window

Description: Finds a window by name.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Type Required Default Value Description
name String Yes - Window name, which corresponds to the name value in Configuration.

Return Value:

Type Description
Window Returns the found window.

Exceptions:

func createWindow(Configuration)

public func createWindow(config: Configuration): Window

Description: Creates a window with specific configurations. When config.windowType == TypeFloat, the "ohos.permission.SYSTEM_FLOAT_WINDOW" permission is required.

Required Permission: ohos.permission.SYSTEM_FLOAT_WINDOW

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Type Required Default Value Description
config Configuration Yes - Window creation parameters.

Return Value:

Type Description
Window Returns the created window.

Exceptions:

  • BusinessException: Error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    201 Permission verification failed. The application does not have the permission required to call the API.
    401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
    2. Incorrect parameter types.
    1300003 This window manager service works abnormally.
    1300006 This window context is abnormal.

func shiftAppWindowFocus(Int32, Int32)

public func shiftAppWindowFocus(sourceWindowId: Int32, targetWindowId: Int32): Unit

Description: Shifts the window focus from the source window to the target window in the same application. The window focus can be shifted within the main window and child windows.

Ensure that the target window can gain focus (configurable by calling setWindowFocusable()) and that showWindow() has been successfully executed.

**NOTE: **

Before calling shiftAppWindowFocus(), ensure that the target window has called loadContent() and these operations have been effective. Otherwise, an invisible window may gain focus, causing function exceptions or affecting user experience.

System Capability: SystemCapability.Window.SessionManager

Since: 22

Parameters:

Parameter Type Required Default Value Description
sourceWindowId Int32 Yes - Source window ID for focus transfer.
targetWindowId Int32 Yes - Target window ID for focus transfer.

Exceptions:

  • BusinessException: Error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
    2. Incorrect parameter types.
    801 Capability not supported. Failed to call the API due to limited device capabilities.
    1300002 This window state is abnormal.
    1300003 This window manager service works abnormally.
    1300004 Unauthorized operation.

func getLastWindow(BaseContext)

public func getLastWindow(ctx: BaseContext): Window

Description: Retrieves the top-level window of the current application. If there are no sub-windows, the main window of the application is returned.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Type Required Default Value Description
ctx BaseContext Yes - Current application context.

Return Value:

Type Description
Window Returns the retrieved top-level window.

Exceptions:

  • BusinessException: Error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300002 This window state is abnormal.
    1300006 This window context is abnormal.

class AvoidArea

public class AvoidArea {
    public var visible: Bool
    public var leftRect: Rect
    public var topRect: Rect
    public var rightRect: Rect
    public var bottomRect: Rect
    public init(
        visible!: Bool,
        leftRect!: Rect,
        topRect!: Rect,
        rightRect!: Rect,
        bottomRect!: Rect
    )
}

Description: Avoidance area.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

var bottomRect

public var bottomRect: Rect

Description: Rectangle at the bottom of the screen.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Rect

Read/Write: Readable and Writable

Since: 22

var leftRect

public var leftRect: Rect

Description: Rectangle on the left side of the screen.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Rect

Read/Write: Readable and Writable

Since: 22

var rightRect

public var rightRect: Rect

Description: Rectangle on the right side of the screen.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Rect

Read/Write: Readable and Writable

Since: 22

var topRect

public var topRect: Rect

Description: Rectangle at the top of the screen.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Rect

Read/Write: Readable and Writable

Since: 22

var visible

public var visible: Bool

Description: Indicates whether the avoidance area is visible on the screen.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Bool

Read/Write: Readable and Writable

Since: 22

init(Bool, Rect, Rect, Rect, Rect)

public init(
    visible!: Bool,
    leftRect!: Rect,
    topRect!: Rect,
    rightRect!: Rect,
    bottomRect!: Rect
)

Description: Constructor for AvoidArea.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Type Required Default Value Description
visible Bool Yes - Named parameter. Indicates whether the avoidance area is visible.
leftRect Rect Yes - Named parameter. Left rectangle.
topRect Rect Yes - Named parameter. Top rectangle.
rightRect Rect Yes - Named parameter. Right rectangle.
bottomRect Rect Yes - Named parameter. Bottom rectangle.

class Configuration

public class Configuration {
    public var name: String
    public var windowType: WindowType
    public var ctx: BaseContext
    public var displayId: Int64 = -1
    public var parentId: Int64 = -1
    public init(
        name!: String,
        windowType!: WindowType,
        ctx!: BaseContext,
        displayId!: Int64 = -1,
        parentId!: Int64 = -1
    )
}

Description: Parameters for creating sub-windows or system windows.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

var ctx

public var ctx: BaseContext

Description: Current application context information.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: BaseContext

Read/Write: Readable and Writable

Since: 22

var displayId

public var displayId: Int64 = -1

Description: Current physical screen ID.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Int64

Read/Write: Readable and Writable

Since: 22

var name

public var name: String

Description: Window name.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: String

Read/Write: Readable and Writable

Since: 22

var parentId

public var parentId: Int64 = -1

Description: Parent window ID.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Int64

Read/Write: Readable and Writable

Since: 22

var windowType

public var windowType: WindowType

Description: Window type.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: WindowType

Read/Write: Readable and Writable

Since: 22

init(String, WindowType, BaseContext, Int64, Int64)

public init(
    name!: String,
    windowType!: WindowType,
    ctx!: BaseContext,
    displayID!: Int64 = -1,
    parentID!: Int64 = -1
)

Description: Constructor for Configuration.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Type Required Default Value Description
name String Yes - Named parameter. Window name.
windowType WindowType Yes - Named parameter. Window type.
ctx BaseContext Yes - Named parameter. Current application context information.
displayID Int64 No -1 Named parameter. Current physical screen ID.
parentID Int64 No -1 Named parameter. Parent window ID.
public class Rect {
    public var left: Int32
    public var top: Int32
    public var width: UInt32
    public var height: UInt32
    public init(
        left!: Int32,
        top!: Int32,
        width!: UInt32,
        height!: UInt32
    )
}

Function: Window rectangular area.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

var height

public var height: UInt32

Function: Height of the rectangular area in pixels.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: UInt32

Read/Write Permission: Readable and Writable

Since: 22

var left

public var left: Int32

Function: Left boundary of the rectangular area in pixels.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Int32

Read/Write Permission: Readable and Writable

Since: 22

var top

public var top: Int32

Function: Top boundary of the rectangular area in pixels.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Int32

Read/Write Permission: Readable and Writable

Since: 22

var width

public var width: UInt32

Function: Width of the rectangular area in pixels.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: UInt32

Read/Write Permission: Readable and Writable

Since: 22

init(Int32, Int32, UInt32, UInt32)

public init(
    left!: Int32,
    top!: Int32,
    width!: UInt32,
    height!: UInt32
)

Function: Rect constructor.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Type Required Default Value Description
left Int32 Yes - Named parameter. Left boundary of the rectangular area in pixels.
top Int32 Yes - Named parameter. Top boundary of the rectangular area in pixels.
width UInt32 Yes - Named parameter. Width of the rectangular area in pixels.
height UInt32 Yes - Named parameter. Height of the rectangular area in pixels.

class Size

public class Size {
    public var width: UInt32
    public var height: UInt32
    public init(
        width!: UInt32,
        height!: UInt32
    )
}

Function: Window size.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

var height

public var height: UInt32

Function: Height of the window.

Type: UInt32

Read/Write Permission: Readable and Writable

Since: 22

var width

public var width: UInt32

Function: Width of the window.

Type: UInt32

Read/Write Permission: Readable and Writable

Since: 22

init(UInt32, UInt32)

public init(
    width!: UInt32,
    height!: UInt32
)

Function: Size constructor.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Type Required Default Value Description
width UInt32 Yes - Named parameter. Window width.
height UInt32 Yes - Named parameter. Window height.

class SystemBarProperties

public class SystemBarProperties {
    public var statusBarColor: String = "#66000000"
    public var isStatusBarLightIcon: Bool = false
    public var statusBarContentColor: String = "#E5FFFFFF"
    public var navigationBarColor: String = "#66000000"
    public var isNavigationBarLightIcon: Bool = false
    public var navigationBarContentColor: String = "#E5FFFFFF"
    public var enableStatusBarAnimation: Bool = false
    public var enableNavigationBarAnimation: Bool = false
    public init(
        statusBarColor!: String = "#66000000",
        isStatusBarLightIcon!: Bool = false,
        statusBarContentColor!: String = "#E5FFFFFF",
        navigationBarColor!: String = "#66000000",
        isNavigationBarLightIcon!: Bool = false,
        navigationBarContentColor!: String = "#E5FFFFFF",
        enableStatusBarAnimation!: Bool = false,
        enableNavigationBarAnimation!: Bool = false
    )
}

Function: Properties of the status bar and navigation bar, which are not automatically updated.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

var enableNavigationBarAnimation

public var enableNavigationBarAnimation: Bool = false

Function: Enable navigation bar animation.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Bool

Read/Write Permission: Readable and Writable

System Capability: SystemCapability.Window.SessionManager

Since: 22

var enableStatusBarAnimation

public var enableStatusBarAnimation: Bool = false

Function: Enable status bar animation.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Bool

Read/Write Permission: Readable and Writable

System Capability: SystemCapability.Window.SessionManager

Since: 22

var isNavigationBarLightIcon

public var isNavigationBarLightIcon: Bool = false

Function: Light-colored icons for the navigation bar.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Bool

Read/Write Permission: Readable and Writable

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

var isStatusBarLightIcon

public var isStatusBarLightIcon: Bool = false

Function: Light-colored icons for the status bar.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Bool

Read/Write Permission: Readable and Writable

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

var navigationBarColor

public var navigationBarColor: String = "#66000000"

Function: Color of the navigation bar.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: String

Read/Write Permission: Readable and Writable

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

var navigationBarContentColor

public var navigationBarContentColor: String = "#E5FFFFFF"

Function: Content color of the navigation bar.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: String

Read/Write Permission: Readable and Writable

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

var statusBarColor

public var statusBarColor: String = "#66000000"

Function: Color of the status bar.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: String

Read/Write Permission: Readable and Writable

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

var statusBarContentColor

public var statusBarContentColor: String = "#E5FFFFFF"

Function: Content color of the status bar.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: String

Read/Write Permission: Readable and Writable

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

init(String, Bool, String, String, Bool, String, Bool, Bool)

public init(
    statusBarColor!: String = "#66000000",
    isStatusBarLightIcon!: Bool = false,
    statusBarContentColor!: String = "#E5FFFFFF",
    navigationBarColor!: String = "#66000000",
    isNavigationBarLightIcon!: Bool = false,
    navigationBarContentColor!: String = "#E5FFFFFF",
    enableStatusBarAnimation!: Bool = false,
    enableNavigationBarAnimation!: Bool = false
)

Function: SystemBarProperties constructor.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Type Required Default Value Description
statusBarColor String No "#66000000" Named parameter. Color of the status bar.
isStatusBarLightIcon Bool No false Named parameter. Light-colored icons for the status bar.
statusBarContentColor String No "#E5FFFFFF" Named parameter. Content color of the status bar.
navigationBarColor String No "#66000000" Named parameter. Color of the navigation bar.
isNavigationBarLightIcon Bool No false Named parameter. Light-colored icons for the navigation bar.
navigationBarContentColor String No "#E5FFFFFF" Named parameter. Content color of the navigation bar.
enableStatusBarAnimation Bool No false Named parameter. Enable status bar animation.
enableNavigationBarAnimation Bool No false Named parameter. Enable navigation bar animation.

class TitleButtonRect

public class TitleButtonRect {
    public var right: Int32
    public var top: Int32
    public var width: UInt32
    public var height: UInt32
    public init(
      right!: Int32,
      top!: Int32,
      width!: UInt32,
      height!: UInt32
    )
}

Function: Rectangular area for minimize, maximize, and close buttons on the title bar, with coordinates relative to the top-right corner of the window.

System Capability: SystemCapability.Window.SessionManager

Since: 22

var height

public var height: UInt32

Function: Height of the rectangular area.

Type: UInt32

Read/Write Permission: Readable and Writable

System Capability: SystemCapability.Window.SessionManager

Since: 22

var right

public var right: Int32

Function: Right boundary of the rectangular area.

Type: Int32

Read/Write Permission: Readable and Writable

System Capability: SystemCapability.Window.SessionManager

Since: 22

var top

public var top: Int32

Function: Top boundary of the rectangular area.

Type: Int32

Read/Write Permission: Readable and Writable

System Capability: SystemCapability.Window.SessionManager

Since: 22

var width

public var width: UInt32

Function: Width of the rectangular area.

Type: UInt32

Read/Write Permission: Readable and Writable

System Capability: SystemCapability.Window.SessionManager

Since: 22

init(Int32, Int32, UInt32, UInt32)

public init(
    right!: Int32,
    top!: Int32,
    width!: UInt32,
    height!: UInt32
)

Function: TitleButtonRect constructor.

System Capability: SystemCapability.Window.SessionManager

Since: 22

Parameters:

Parameter Type Required Default Value Description
right Int32 Yes - Named parameter. Right boundary of the rectangular area in vp.
top Int32 Yes - Named parameter. Top boundary of the rectangular area in vp.
width UInt32 Yes - Named parameter. Width of the rectangular area in vp.
height UInt32 Yes - Named parameter. Height of the rectangular area in vp.
public class Window {}

Description: Window class.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

func destroyWindow()

public func destroyWindow(): Unit

Description: Destroys this window. This API only takes effect for system windows or application sub-windows.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Exceptions:

func getWindowAvoidArea(AvoidAreaType)

public func getWindowAvoidArea(areaType: AvoidAreaType): AvoidArea

Description: Gets the avoid area.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Name Type Required Default Value Description
areaType AvoidAreaType Yes - Area type.

Return Value:

Type Description
AvoidArea Returns the area where the window cannot be displayed.

Exceptions:

  • BusinessException: Corresponding error codes are listed below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    401 Parameter error. Possible causes:
    1. Mandatory parameters are left unspecified.
    2. Incorrect parameter types.
    1300002 This window state is abnormal.

func getWindowColorSpace()

public func getWindowColorSpace(): ColorSpace

Description: Gets the set color space.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Return Value:

Type Description
ColorSpace Returns the obtained color space.

Exceptions:

func getWindowProperties()

public func getWindowProperties(): WindowProperties

Description: Gets the properties of the current window.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Return Value:

Type Description
WindowProperties Returns the window properties.

Exceptions:

func isWindowShowing()

public func isWindowShowing(): Bool

Description: Checks whether the window is displayed. A value of true indicates the window is displayed, and false indicates the opposite.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Return Value:

Type Description
Bool Returns whether the window is displayed.

Exceptions:

func isWideGamutSupported()

public func isWideGamutSupported(): Bool

Description: Checks whether the window supports wide color gamut settings.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Return Value:

Type Description
Bool A value of true indicates support for wide color gamut color space, and false indicates the opposite.

Exceptions:

func minimize()

public func minimize(): Unit

Description: Minimizes the main window (if the caller is the main window). The main window can be restored from the dock. For 2-in-1 devices, it can be restored by calling recover(). Hides the sub-window (if the caller is a sub-window). Sub-windows cannot be restored from the dock. They can be made visible again by calling showWindow().

System Capability: SystemCapability.Window.SessionManager

Since: 22

Exceptions:

  • BusinessException: Corresponding error codes are listed below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    801 Capability not supported. Failed to call the API due to limited device capabilities.
    1300002 This window state is abnormal.

func moveWindowTo(Int32, Int32)

public func moveWindowTo(x: Int32, y: Int32): Unit

Description: Sets the window position.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Name Type Required Default Value Description
x Int32 Yes - Indicates the X-coordinate of the window.
y Int32 Yes - Indicates the Y-coordinate of the window.

Exceptions:

func off(WindowCallbackType)

public func off(callbackType: WindowCallbackType): Unit

Description: Unregisters the callback for the specified event.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Name Type Required Default Value Description
callbackType WindowCallbackType Yes - Event type.

Exceptions:

  • BusinessException: Corresponding error codes are listed below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300016 Parameter error. Possible cause: 1. Mandatory parameters are left unspecified;
    2. Incorrect parameter types;
    3. Parameter verification failed.

func off(WindowCallbackType, Callback1Argument<UInt32>)

public func off(callbackType: WindowCallbackType, callback: Callback1Argument<UInt32>): Unit

Description: Unregisters the callback for keyboardHeightChange.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Name Type Required Default Value Description
callbackType WindowCallbackType Yes - The value must be KeyboardHeightChange, indicating the keyboard height change event.
callback Callback1Argument<UInt32> Yes - Callback used to return the current keyboard height, which is an integer in px.

Exceptions:

  • BusinessException: Corresponding error codes are listed below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300016 Parameter error. Possible cause: 1. Mandatory parameters are left unspecified;
    2. Incorrect parameter types;
    3. Parameter verification failed.

func on(WindowCallbackType, Callback1Argument<UInt32>)

public func on(callbackType: WindowCallbackType, callback: Callback1Argument<UInt32>): Unit

Description: Registers the callback for keyboardHeightChange.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Name Type Required Default Value Description
callbackType WindowCallbackType Yes - The value must be KeyboardHeightChange, indicating the keyboard height change event.
callback Callback1Argument<UInt32> Yes - Callback used to return the current keyboard height, which is an integer in px.

Exceptions:

  • BusinessException: Corresponding error codes are listed below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300016 Parameter error. Possible cause: 1. Mandatory parameters are left unspecified;
    2. Incorrect parameter types;
    3. Parameter verification failed.

func resetAspectRatio()

public func resetAspectRatio(): Unit

Description: Resets the aspect ratio of the window.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Exceptions:

  • BusinessException: Corresponding error codes are listed below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300002 This window state is abnormal.
    1300004 Unauthorized operation.

func resize(UInt32, UInt32)

public func resize(width: UInt32, height: UInt32): Unit

Description: Sets the window size.

System Capability: SystemCapability.Window.SessionManager

Since: 22

Parameters:

Parameter Name Type Required Default Value Description
width UInt32 Yes - Indicates the width of the window.
height UInt32 Yes - Indicates the height of the window.

Exceptions:

func setAspectRatio(Float64)

public func setAspectRatio(ratio: Float64): Unit

Description: Sets the aspect ratio of the window.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Name Type Required Default Value Description
ratio Float64 Yes - The aspect ratio of the window excluding decorations.

Exceptions:

  • BusinessException: Corresponding error codes are listed below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300002 This window state is abnormal.
    1300004 Unauthorized operation.

func setPreferredOrientation(Orientation)

public func setPreferredOrientation(orientation: Orientation): Unit

Description: Sets the preferred orientation for the main window. This does not take effect on devices that do not support sensor rotation, 2-in-1 devices, or sub-windows.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Name Type Required Default Value Description
orientation Orientation Yes - Window orientation configuration.

Exceptions:

  • BusinessException: Corresponding error codes are listed below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    401 Parameter error. Possible cause: 1. Mandatory parameters are left unspecified;
    2. Incorrect parameter types.
    1300002 This window state is abnormal.
public func setWindowBackgroundColor(color: String): Unit

Function: Sets the window background color.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Initial Version: 22

Parameters:

Parameter Type Required Default Description
color String Yes - The specified color.

Exceptions:

  • BusinessException: Corresponding error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
    2. Incorrect parameter types.
    1300002 This window state is abnormal.

func setWindowBrightness(Float32)

public func setWindowBrightness(brightness: Float32): Unit

Function: Sets the window brightness.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Initial Version: 22

Parameters:

Parameter Type Required Default Description
brightness Float32 Yes - The specified brightness value.

Exceptions:

  • BusinessException: Corresponding error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300002 This window state is abnormal.

func setWindowColorSpace(ColorSpace)

public func setWindowColorSpace(colorSpace: ColorSpace): Unit

Function: Sets the specified color space.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Initial Version: 22

Parameters:

Parameter Type Required Default Description
colorSpace ColorSpace Yes - The specified color space.

Exceptions:

  • BusinessException: Corresponding error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300002 This window state is abnormal.

func setWindowFocusable(Bool)

public func setWindowFocusable(isFocusable: Bool): Unit

Function: Sets whether the window can obtain focus.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Initial Version: 22

Parameters:

Parameter Type Required Default Description
isFocusable Bool Yes - If true, the window can obtain focus; if false, it cannot.

Exceptions:

  • BusinessException: Corresponding error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300002 This window state is abnormal.

func setWindowKeepScreenOn(Bool)

public func setWindowKeepScreenOn(isKeepScreenOn: Bool): Unit

Function: Sets whether to keep the screen always on.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Initial Version: 22

Parameters:

Parameter Type Required Default Description
isKeepScreenOn Bool Yes - If true, the screen will stay always on; if false, it will not.

Exceptions:

  • BusinessException: Corresponding error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300002 This window state is abnormal.

func setWindowSystemBarEnabled(Array<SystemBarType>)

public func setWindowSystemBarEnabled(names: Array<SystemBarType>): Unit

Function: Sets whether to display the system bars of the main window.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Initial Version: 22

Parameters:

Parameter Type Required Default Description
names Array<SystemBarType> Yes - Collection of system bar types.

Exceptions:

  • BusinessException: Corresponding error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300002 This window state is abnormal.

func setWindowSystemBarProperties(SystemBarProperties)

public func setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Unit

Function: Sets the system bar properties.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Initial Version: 22

Parameters:

Parameter Type Required Default Description
systemBarProperties SystemBarProperties Yes - The system bar properties.

Exceptions:

  • BusinessException: Corresponding error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300002 This window state is abnormal.

func setWindowLayoutFullScreen(Bool)

public func setWindowLayoutFullScreen(isLayoutFullScreen: Bool): Unit

Function: Sets whether the main window layout or sub-window layout is immersive.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Initial Version: 22

Parameters:

Parameter Type Required Default Description
isLayoutFullScreen Bool Yes - Whether the window layout is immersive.

Exceptions:

  • BusinessException: Corresponding error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300002 This window state is abnormal.

func setWindowPrivacyMode(Bool)

public func setWindowPrivacyMode(isPrivacyMode: Bool): Unit

Function: Sets whether it is in privacy mode.

Required Permission: ohos.permission.PRIVACY_WINDOW

System Capability: SystemCapability.WindowManager.WindowManager.Core

Initial Version: 22

Parameters:

Parameter Type Required Default Description
isPrivacyMode Bool Yes - If true, it is in privacy mode; if false, it is not.

Exceptions:

  • BusinessException: Corresponding error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300002 This window state is abnormal.

func setWindowSystemBarEnable(Array<SystemBarType>)

public func setWindowSystemBarEnable(names: Array<SystemBarType>): Unit

Function: Sets whether to display the system bars of the main window.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Initial Version: 22

Parameters:

Parameter Type Required Default Description
names Array<SystemBarType> Yes - Collection of system bar types.

Exceptions:

  • BusinessException: Corresponding error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300002 This window state is abnormal.

func setWindowSystemBarProperties(SystemBarProperties)

public func setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Unit

Function: Sets the system bar properties.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Initial Version: 22

Parameters:

Parameter Type Required Default Description
systemBarProperties SystemBarProperties Yes - The system bar properties.

Exceptions:

  • BusinessException: Corresponding error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300002 This window state is abnormal.

func setWindowTouchable(Bool)

public func setWindowTouchable(isTouchable: Bool): Unit

Function: Sets whether the window is touchable.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Initial Version: 22

Parameters:

Parameter Type Required Default Description
isTouchable Bool Yes - If true, the window is touchable; if false, it is not.

Exceptions:

  • BusinessException: Corresponding error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300002 This window state is abnormal.

func showWindow()

public func showWindow(): Unit

Function: Displays this window. This API only takes effect for system windows or application sub-windows. For the main window of an application, when the main window is already displayed, this API will move it to the top.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Initial Version: 22

Exceptions:

  • BusinessException: Corresponding error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300002 This window state is abnormal.

func snapshot()

public func snapshot(): PixelMap

Function: Captures a window snapshot.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Initial Version: 22

Return Value:

Type Description
PixelMap Returns a Promise without a value.

Exceptions:

  • BusinessException: Corresponding error codes are listed in the table below. For details, see Universal Error Codes and Window Error Codes.

    Error Code Description
    1300002 This window state is abnormal.

class WindowProperties

public class WindowProperties {
    public var windowRect: Rect
    public var drawableRect: Rect
    public var windowType: WindowType
    public var isFullScreen: Bool
    public var isLayoutFullScreen: Bool
    public var focusable: Bool
    public var touchable: Bool
    public var brightness: Float32
    public var isKeepScreenOn: Bool
    public var isPrivacyMode: Bool
    public var isTransparent: Bool
    public var id: UInt32
    public init(
        windowRect!: Rect,
        drawableRect!: Rect,
        windowType!: WindowType,
        isFullScreen!: Bool,
        isLayoutFullScreen!: Bool,
        focusable!: Bool,
        touchable!: Bool,
        brightness!: Float32,
        isKeepScreenOn!: Bool,
        isPrivacyMode!: Bool,
        isTransparent!: Bool,
        id!: UInt32
    )
}

Function: Window properties, which are not automatically updated.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Initial Version: 22

var brightness

public var brightness: Float32

Function: The brightness value of the window.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Float32

Read/Write: Readable and Writable

Initial Version: 22

var drawableRect

public var drawableRect: Rect

Function: The position and size of the drawable area relative to the window.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Rect

Read/Write: Readable and Writable

Initial Version: 22

var focusable

public var focusable: Bool

Function: Whether the window can obtain focus. The default value is true.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Bool

Read/Write: Readable and Writable

Initial Version: 22

var id

public var id: UInt32

Function: The window ID.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: UInt32

Read/Write: Readable and Writable

Initial Version: 22

var isFullScreen

public var isFullScreen: Bool

Function: Whether the window is displayed in full-screen mode. The default value is false.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Bool

Read/Write: Readable and Writable

Initial Version: 22

var isKeepScreenOn

public var isKeepScreenOn: Bool

Function: Whether to keep the screen always on.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Bool

Read/Write: Readable and Writable

Initial Version: 22

var isLayoutFullScreen

public var isLayoutFullScreen: Bool

Function: Whether the window layout is in full-screen mode (whether the window is immersive). The default value is false.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Bool

Read/Write: Readable and Writable

Initial Version: 22

var isPrivacyMode

public var isPrivacyMode: Bool

Function: Whether it is in privacy mode.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Bool

Read/Write: Readable and Writable

Initial Version: 22

var isTransparent

public var isTransparent: Bool

Function: Whether it is transparent.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Bool

Read/Write: Readable and Writable

Initial Version: 22

var touchable

public var touchable: Bool

Function: Whether the window is touchable. The default value is false.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Bool

Read/Write: Readable and Writable

Initial Version: 22

var windowType

public var windowType: WindowType

Function: The window type.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: WindowType

Read/Write: Readable and Writable

Initial Version: 22

var windowRect

public var windowRect: Rect

Function: The position and size of the window.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Type: Rect

Read/Write: Readable and Writable

Initial Version: 22

init(Rect, Rect, WindowType, Bool, Bool, Bool, Bool, Float32, Bool, Bool, Bool, UInt32)

public init(
    windowRect!: Rect,
    drawableRect!: Rect,
    windowType!: WindowType,
    isFullScreen!: Bool,
    isLayoutFullScreen!: Bool,
    focusable!: Bool,
    touchable!: Bool,
    brightness!: Float32,
    isKeepScreenOn!: Bool,
    isPrivacyMode!: Bool,
    isTransparent!: Bool,
    id!: UInt32
)

Function: Constructor for Window```markdown

class WindowStage

public class WindowStage {}

Description: Window manager. Manages basic window units, i.e., instances of Window.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

func createSubWindow(String)

public func createSubWindow(name: String): Window

Description: Creates a sub-window under this WindowStage instance.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Type Required Default Description
name String Yes - Name of the sub-window.

Return Value:

Type Description
Window Returns the sub-window.

Exceptions:

func getMainWindow()

public func getMainWindow(): Window

Description: Retrieves the main window of this window stage.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Return Value:

Type Description
Window Returns the main window.

Exceptions:

func getSubWindow()

public func getSubWindow(): Array<Window>

Description: Retrieves all sub-windows of this window stage.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Return Value:

Type Description
Array<Window> Returns all sub-windows.

Exceptions:

func loadContent(String)

public func loadContent(path: String): Unit

Description: Loads page content into this window. It is recommended to call this API during UIAbility startup. If called multiple times, this API will destroy the existing page content (UIContent) before loading new content. Use with caution.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Type Required Default Description
path String Yes - Path of the page to load.

enum AvoidAreaType

public enum AvoidAreaType <: Equatable<AvoidAreaType> {
    | TypeSystem
    | TypeCutout
    | TypeSystemGesture
    | TypeKeyboard
    | TypeNavigationIndicator
    | ...
}

Description: Describes types of avoidable areas.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parent Type:

TypeSystem

TypeSystem

Description: Default system area.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

TypeCutout

TypeCutout

Description: Notch screen area.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

TypeSystemGesture

TypeSystemGesture

Description: System gesture area.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

TypeKeyboard

TypeKeyboard

Description: Keyboard area.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

TypeNavigationIndicator

TypeNavigationIndicator

Description: Navigation indicator area.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

operator func !=(AvoidAreaType)

public operator func !=(other: AvoidAreaType): Bool

Description: Inequality comparison operator.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Type Required Default Description
other AvoidAreaType Yes - Another AvoidAreaType instance to compare.

Return Value:

Type Description
Bool Returns true if the instances are not equal.

operator func ==(AvoidAreaType)

public operator func ==(other: AvoidAreaType): Bool

Description: Equality comparison operator.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Type Required Default Description
other AvoidAreaType Yes - Another AvoidAreaType instance to compare.

Return Value:

Type Description
Bool Returns true if the instances are equal.

enum ColorSpace

public enum ColorSpace <: Equatable<ColorSpace> {
    | Default
    | WideGamut
    | ...
}

Description: Specifies allowed color space types.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parent Type:

Default

Default

Description: Default color space.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

WideGamut

WideGamut

Description: Wide-gamut color space. The specific gamut depends on the screen.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

operator func !=(ColorSpace)

public operator func !=(other: ColorSpace): Bool

Description: Inequality comparison operator.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Type Required Default Description
other ColorSpace Yes - Another ColorSpace instance to compare.

Return Value:

Type Description
Bool Returns true if the instances are not equal.

operator func ==(ColorSpace)

public operator func ==(other: ColorSpace): Bool

Description: Equality comparison operator.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Type Required Default Description
other ColorSpace Yes - Another ColorSpace instance to compare.

Return Value:

Type Description
Bool Returns true if the instances are equal.

enum Orientation

public enum Orientation <: Equatable<Orientation> {
    | Unspecified
    | Portrait
    | Landscape
    | PortraitInverted
    | LandscapeInverted
    | AutoRotation
    | AutoRotationPortrait
    | AutoRotationLandscape
    | AutoRotationRestricted
    | AutoRotationPortraitRestricted
    | AutoRotationLandscapeRestricted
    | Locked
    | ...
}

Description: Display orientation.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parent Type:

Unspecified

Unspecified

Description: Default value. Orientation mode is not explicitly defined and is determined by the system.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Portrait

Portrait

Description: Portrait display.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Landscape

Landscape

Description: Landscape display.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

PortraitInverted

PortraitInverted

Description: Inverted portrait display.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

LandscapeInverted

LandscapeInverted

Description: Inverted landscape display.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

AutoRotation

AutoRotation

Description: Follows sensor rotation, ignoring auto-rotation lock.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

AutoRotationPortrait

AutoRotationPortrait

Description: Follows sensor rotation, works only in portrait mode, ignoring auto-rotation lock.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

AutoRotationLandscape

AutoRotationLandscape

Description: Follows sensor rotation, works only in landscape mode, ignoring auto-rotation lock.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

AutoRotationRestricted

AutoRotationRestricted

Description: Follows sensor rotation, controlled by auto-rotation lock.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

AutoRotationPortraitRestricted

AutoRotationPortraitRestricted

Description: Follows sensor rotation, works only in portrait mode, controlled by auto-rotation lock.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

AutoRotationLandscapeRestricted

AutoRotationLandscapeRestricted

Description: Follows sensor rotation, works only in landscape mode, controlled by auto-rotation lock.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Locked

Locked

Description: Locked mode, maintains the same orientation as before.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

operator func !=(Orientation)

public operator func !=(other: Orientation): Bool

Description: Inequality comparison operator.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Type Required Default Description
other Orientation Yes - Another Orientation instance to compare.

Return Value:

Type Description
Bool Returns true if the instances are not equal.

operator func ==(Orientation)

public operator func ==(other: Orientation): Bool

Description: Equality comparison operator.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Parameter Type Required Default Description
other Orientation Yes - Another Orientation instance to compare.

Return Value:

Type Description
Bool Returns true if the instances are equal.

```cangjie
public enum SystemBarType <: Equatable<SystemBarType> {
    | Status
    | Navigation
    | ...
}

Description: Enumeration of system bar types.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parent Type:

Status

Status

Description: Status bar.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Navigation

Description: Navigation bar.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

operator func !=(SystemBarType)

public operator func !=(other: SystemBarType): Bool

Description: Inequality comparison operator.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Name Type Mandatory Default Value Description
other SystemBarType Yes - Another SystemBarType instance to compare.

Return Value:

Type Description
Bool Comparison result, returns true when not equal.

operator func ==(SystemBarType)

public operator func ==(other: SystemBarType): Bool

Description: Equality comparison operator.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Name Type Mandatory Default Value Description
other SystemBarType Yes - Another SystemBarType instance to compare.

Return Value:

Type Description
Bool Comparison result, returns true when equal.

enum WindowCallbackType

public enum WindowCallbackType <: Equatable<WindowCallbackType> {
    | WindowStageEvent
    | WindowSizeChange
    | WindowAvoidAreaChange
    | KeyboardHeightChange
    | TouchOutside
    | WindowVisibilityChange
    | NoInteractionDetected
    | Screenshot
    | DialogTargetTouch
    | WindowEvent
    | WindowStatusChange
    | SubWindowClose
    | WindowTitleButtonRectChange
    | WindowRectChange
    | ...
}

Description: Enumeration of listening events.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parent Type:

WindowStageEvent

WindowStageEvent

Description: Indicates window stage lifecycle change event.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

WindowSizeChange

WindowSizeChange

Description: Indicates window size change event.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

WindowAvoidAreaChange

WindowAvoidAreaChange

Description: Indicates avoid area change event.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

KeyboardHeightChange

KeyboardHeightChange

Description: Indicates keyboard height change event.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

TouchOutside

TouchOutside

Description: Indicates window outside touch event.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

WindowVisibilityChange

WindowVisibilityChange

Description: Indicates window visibility change.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

NoInteractionDetected

NoInteractionDetected

Description: Indicates no interaction detected in window for a long time.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Screenshot

Screenshot

Description: Indicates screenshot event.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

DialogTargetTouch

DialogTargetTouch

Description: Indicates target window touch event in modal window mode.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

WindowEvent

WindowEvent

Description: Indicates window lifecycle change event.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

WindowStatusChange

WindowStatusChange

Description: Indicates window status change event.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

SubWindowClose

SubWindowClose

Description: Indicates sub-window close event.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

WindowTitleButtonRectChange

WindowTitleButtonRectChange

Description: Indicates title button area change event.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

WindowRectChange

WindowRectChange

Description: Indicates window rectangle change event.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

operator func !=(WindowCallbackType)

public operator func !=(other: WindowCallbackType): Bool

Description: Inequality comparison operator.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Name Type Mandatory Default Value Description
other WindowCallbackType Yes - Another WindowCallbackType instance to compare.

Return Value:

Type Description
Bool Comparison result, returns true when not equal.

operator func ==(WindowCallbackType)

public operator func ==(other: WindowCallbackType): Bool

Description: Equality comparison operator.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Name Type Mandatory Default Value Description
other WindowCallbackType Yes - Another WindowCallbackType instance to compare.

Return Value:

Type Description
Bool Comparison result, returns true when equal.

enum WindowEventType

public enum WindowEventType <: Equatable<WindowEventType> {
    | WindowShown
    | WindowActive
    | WindowInactive
    | WindowHidden
    | WindowDestroyed
    | ...
}

Description: Enumeration of window callback event types.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parent Type:

WindowShown

WindowShown

Description: Window shown event value.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

WindowActive

WindowActive

Description: Window activated event value.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

WindowInactive

WindowInactive

Description: Window deactivated event value.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

WindowHidden

WindowHidden

Description: Window hidden event value.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

WindowDestroyed

WindowDestroyed

Description: Window destroyed event value.

System Capability: SystemCapability.Window.SessionManager

Since: 22

operator func !=(WindowEventType)

public operator func !=(other: WindowEventType): Bool

Description: Inequality comparison operator.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Name Type Mandatory Default Value Description
other WindowEventType Yes - Another WindowEventType instance to compare.

Return Value:

Type Description
Bool Comparison result, returns true when not equal.

operator func ==(WindowEventType)

public operator func ==(other: WindowEventType): Bool

Description: Equality comparison operator.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Name Type Mandatory Default Value Description
other WindowEventType Yes - Another WindowEventType instance to compare.

Return Value:

Type Description
Bool Comparison result, returns true when equal.
public enum WindowStageEventType <: Equatable<WindowStageEventType> {
    | Shown
    | Active
    | Inactive
    | Hidden
    | Resumed
    | Paused
    | ...
}

Description: Window stage callback event types.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parent Type:

Shown

Shown

Description: The window stage is running in the foreground.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Active

Active

Description: The window stage gains focus.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Inactive

Inactive

Description: The window stage loses focus.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Hidden

Hidden

Description: The window stage is running in the background.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Resumed

Resumed

Description: The window stage is interactive in the foreground.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Paused

Paused

Description: The window stage is non-interactive in the foreground.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

operator func !=(WindowStageEventType)

public operator func !=(other: WindowStageEventType): Bool

Description: Inequality comparison operator.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Name Type Mandatory Default Value Description
other WindowStageEventType Yes - Another WindowStageEventType instance to compare.

Return Value:

Type Description
Bool Comparison result, returns true if not equal.

operator func ==(WindowStageEventType)

public operator func ==(other: WindowStageEventType): Bool

Description: Equality comparison operator.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Name Type Mandatory Default Value Description
other WindowStageEventType Yes - Another WindowStageEventType instance to compare.

Return Value:

Type Description
Bool Comparison result, returns true if equal.

enum WindowStatusType

public enum WindowStatusType <: Equatable<WindowStatusType> {
    | Undefined
    | FullScreen
    | Maximize
    | Minimize
    | Floating
    | SplitScreen
    | ...
}

Description: Describes the window status of an application.

System Capability: SystemCapability.Window.SessionManager

Since: 22

Parent Type:

Undefined

Undefined

Description: Undefined window status.

System Capability: SystemCapability.Window.SessionManager

Since: 22

FullScreen

FullScreen

Description: Full-screen window status.

System Capability: SystemCapability.Window.SessionManager

Since: 22

Maximize

Maximize

Description: Maximized window status.

System Capability: SystemCapability.Window.SessionManager

Since: 22

Minimize

Minimize

Description: Minimized window status.

System Capability: SystemCapability.Window.SessionManager

Since: 22

Floating

Floating

Description: Floating window status.

System Capability: SystemCapability.Window.SessionManager

Since: 22

SplitScreen

SplitScreen

Description: Split-screen window status.

System Capability: SystemCapability.Window.SessionManager

Since: 22

operator func !=(WindowStatusType)

public operator func !=(other: WindowStatusType): Bool

Description: Inequality comparison operator.

System Capability: SystemCapability.Window.SessionManager

Since: 22

Parameters:

Name Type Mandatory Default Value Description
other WindowStatusType Yes - Another WindowStatusType instance to compare.

Return Value:

Type Description
Bool Comparison result, returns true if not equal.

operator func ==(WindowStatusType)

public operator func ==(other: WindowStatusType): Bool

Description: Equality comparison operator.

System Capability: SystemCapability.Window.SessionManager

Since: 22

Parameters:

Name Type Mandatory Default Value Description
other WindowStatusType Yes - Another WindowStatusType instance to compare.

Return Value:

Type Description
Bool Comparison result, returns true if equal.

enum WindowType

public enum WindowType <: Equatable<WindowType> {
    | TypeApp
    | TypeMain
    | TypeFloat
    | TypeDialog
    | ...
}

Description: Window types.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parent Type:

TypeApp

TypeApp

Description: Application window. This window type cannot be used when creating a window. It is only for reading purposes in the return value of the getWindowProperties API.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

TypeMain

TypeMain

Description: Main window of an application. This window type cannot be used when creating a window. It is only for reading purposes in the return value of the getWindowProperties API.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

TypeFloat

TypeFloat

Description: Floating window. Requires "ohos.permission.SYSTEM_FLOAT_WINDOW" permission.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

TypeDialog

TypeDialog

Description: Dialog window.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

operator func !=(WindowType)

public operator func !=(other: WindowType): Bool

Description: Inequality comparison operator.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Name Type Mandatory Default Value Description
other WindowType Yes - Another WindowType instance to compare.

Return Value:

Type Description
Bool Comparison result, returns true if not equal.

operator func ==(WindowType)

public operator func ==(other: WindowType): Bool

Description: Equality comparison operator.

System Capability: SystemCapability.WindowManager.WindowManager.Core

Since: 22

Parameters:

Name Type Mandatory Default Value Description
other WindowType Yes - Another WindowType instance to compare.

Return Value:

Type Description
Bool Comparison result, returns true if equal.

Example 1 (Setting Main Window as Untouchable)

After setting the main window property as untouchable, clicking buttons on the page will not trigger pop-ups.

// main_ability.cj

package ohos_app_cangjie_entry

import kit.ArkUI.*
import ohos.app.ability.ui_ability.*

class MainAbility <: UIAbility {
    public init() {
        super()
        registerSelf()
    }

    public override func onWindowStageCreate(windowStage: WindowStage): Unit {
        // 1. Get the application's main window
        var window: Window = windowStage.getMainWindow()

        // 2. Set window properties. Using "touchable" property as an example
        window.setWindowTouchable(false)

        // 3. Load corresponding target page for the main window
        windowStage.loadContent("newPage")
    }
}
// newPage.cj

package ohos_app_cangjie_entry

import kit.ArkUI.*
import ohos.arkui.state_macro_manage.*

@Entry
@Component
class newPage{
    func build(){
        Flex(justifyContent: FlexAlign.Center ,alignItems: ItemAlign.Center) {
            Column{
                Text("New Page")
                Button("Untouchable").onClick({ evt
                    => AlertDialogParamWithConfirm(message:"Unreachable")
                }).margin(10.vp)
            }.margin(10.vp)
        }
    }
}

img1

Example 2 (Main Window Listening for Keyboard Height Change Events)

// main_ability.cj

package ohos_app_cangjie_entry

import ohos.app.ability.ui_ability.*
import kit.ArkUI.*

class MainAbility <: UIAbility {

    public init() {
        super()
        registerSelf()
    }

    public override func onWindowStageCreate(windowStage: WindowStage): Unit {
        windowStage.loadContent("newPage")
        // Pass the Ability's window manager to AppStorage
        AppStorage.setOrCreate("windowStage",windowStage)
    }
}
//newPage.cj

package ohos_app_cangjie_entry

import kit.ArkUI.*
import ohos.hilog.*
import ohos.arkui.state_macro_manage.*
import ohos.callback_invoke.*
import ohos.business_exception.BusinessException

@Entry
@Component
class newPage{

    public override func onPageShow(){
        let windowStage: WindowStage = AppStorage.get<WindowStage>("windowStage").getOrThrow()
        let mainWindow: Window = windowStage.getMainWindow()

        // Enable listening
        var tmp: Unit = mainWindow.on(WindowCallbackType.KeyboardHeightChange,TestCallback(0))
    }

    func build(){
        Flex(justifyContent: FlexAlign.Center ,alignItems: ItemAlign.Center) {
            Column{
                TextInput(placeholder: 'input some words here... ').margin(10.vp)
            }.margin(10.vp)
        }
    }
}

public class TestCallback <: Callback1Argument<UInt32>{

    var count: Int64

    public init(count: Int64){
        this.count = count
    }

    public func invoke(err: ?BusinessException, value: UInt32): Unit {
        count++
        // When raising or hiding the keyboard, logs will print the total count of keyboard height changes
        Hilog.info(0,"","KeyboardHeightChangeCount: ${this.count}")
    }
}

After running, click the text box to trigger callbacks. Check the effect in logs, which will print as follows:

KeyboardHeightChangeCount: 1
KeyboardHeightChangeCount: 2
KeyboardHeightChangeCount: 3

img3