Skip to main content

euv_core/platform/harmony/
enum.rs

1use super::*;
2
3/// Unified host-declared rendering channel shared across HarmonyOS, Wearables, MiniApps, and QuickApps.
4#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
5pub enum HostRenderChannel {
6    /// Direct native GPU rendering on a verified host surface (Vulkan / GLES3 / Metal).
7    GpuDirect,
8    /// GPU texture upload from a CPU software framebuffer.
9    GpuUpload,
10    /// Native CPU software pixel buffer (`OH_NativeWindow` / watch framebuffer).
11    #[default]
12    SoftwareBuffer,
13    /// Host `<canvas>` 2D context (`putImageData`).
14    Canvas2d,
15    /// Host `<canvas>` WebGL 1.0 context.
16    WebGl,
17    /// Host `<canvas>` WebGL 2.0 context.
18    WebGl2,
19}
20
21/// All 7 HarmonyOS / OpenHarmony physical device categories unified by `HarmonyPlatform`.
22#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
23pub enum HarmonyDeviceType {
24    /// HarmonyOS smartphone (`deviceType: "phone"`).
25    #[default]
26    Phone,
27    /// HarmonyOS tablet (`deviceType: "tablet"`).
28    Tablet,
29    /// HarmonyOS PC / 2-in-1 desktop (`deviceType: "2in1"`).
30    Pc2In1,
31    /// HarmonyOS foldable phone/tablet with dynamic hinge transitions (`"foldable"`).
32    Foldable,
33    /// HarmonyOS Watch / Wearable (`deviceType: "wearable"`).
34    Watch,
35    /// HarmonyOS Smart TV / Vision (`deviceType: "tv"`).
36    Tv,
37    /// HarmonyOS Automotive / Smart Cockpit (`deviceType: "car"`).
38    Automotive,
39}
40
41/// Physical hinge posture state reported by HarmonyOS foldable devices (`display.FoldStatus`).
42#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
43pub enum HarmonyFoldState {
44    /// Device is closed to its compact cover screen.
45    Folded,
46    /// Device is partially unfolded (tent / flex laptop posture).
47    HalfFolded,
48    /// Device is fully unfolded to its tablet-class inner display.
49    #[default]
50    Expanded,
51}
52
53/// Active native rendering path bound to HarmonyOS `OHNativeWindow`.
54#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
55pub enum HarmonyGraphicsApi {
56    /// Direct GPU rendering over Khronos Vulkan (`VK_OHOS_surface`).
57    Vulkan,
58    /// Direct GPU rendering over EGL + OpenGL ES 3.0 (`eglCreateWindowSurface`).
59    #[default]
60    OpenGlEs3,
61    /// Reference CPU software buffer upload via `OH_NativeWindow_NativeWindowRequestBuffer` / `FlushBuffer`.
62    SoftwareBuffer,
63}
64
65/// Stage-Model HarmonyOS `UIAbility` and `WindowStage` lifecycle hooks normalized into EUV `SystemEvent`s.
66#[derive(Clone, Debug, PartialEq)]
67pub enum HarmonyLifecycleHook {
68    /// `UIAbility.onCreate(want)` creating a fresh ability session.
69    OnCreate {
70        /// Optional incoming Want URI deep link.
71        want_uri: Option<String>,
72    },
73    /// `UIAbility.onWindowStageCreate(windowStage)` attaching `OHNativeWindow` / `XComponent`.
74    OnWindowStageCreate {
75        /// Raw `OHNativeWindow*` pointer (`0` when deferred).
76        native_window: usize,
77        /// Raw `OH_NativeXComponent*` pointer (`0` when deferred).
78        xcomponent: usize,
79    },
80    /// `UIAbility.onForeground()` resuming rendering and active interactive frame pumping.
81    OnForeground,
82    /// `WindowStageEventType.ACTIVE` signaling active window input focus.
83    OnWindowActive,
84    /// `WindowStageEventType.INACTIVE` signaling transient focus loss (control center, multi-window switch).
85    OnWindowInactive,
86    /// `UIAbility.onBackground()` freezing rendering, timers, and frame pumping (0% CPU/GPU).
87    OnBackground,
88    /// `UIAbility.onWindowStageDestroy()` detaching native surface handles safely.
89    OnWindowStageDestroy,
90    /// `UIAbility.onDestroy()` terminating the ability session gracefully.
91    OnDestroy,
92    /// `UIAbility.onMemoryLevel(level)` reporting OS memory pressure.
93    OnMemoryLevel(i32),
94    /// `UIAbility.onConfigurationUpdate` updating theme, locale, density, or foldable state.
95    OnConfigurationUpdate {
96        /// Updated OS appearance mode (`Light` / `Dark`).
97        theme: ThemeMode,
98        /// Updated BCP-47 locale tag.
99        locale: String,
100        /// Updated display density scale factor (`vp -> px`).
101        density: f32,
102        /// Optional updated foldable hinge posture.
103        fold_state: Option<HarmonyFoldState>,
104    },
105    /// System gesture or hardware Back button press (`onBackPress`).
106    OnBackPress,
107    /// Warm-launch `UIAbility.onNewWant(want)` delivering a new deep-link URI.
108    OnNewWant(String),
109    /// Window status or layout mode change (`window.WindowStatusType` on HarmonyOS PC/Tablet/Foldable).
110    OnWindowModeChanged(HarmonyWindowMode),
111    /// Host network reachability update (`@ohos.net.connection`).
112    OnNetworkStatusChanged(NetworkStatus),
113}
114
115/// HarmonyOS Stage-Model window presentation modes spanning Phone fullscreen, Tablet split-screen, and PC freeform desktop windows.
116#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
117pub enum HarmonyWindowMode {
118    /// Standard single-surface fullscreen application window (Phone / Watch / TV / Car).
119    #[default]
120    Fullscreen,
121    /// Freeform resizable desktop window on HarmonyOS PC (`2in1`) or Tablet desktop mode.
122    Floating,
123    /// Maximized desktop window on HarmonyOS PC (`2in1`).
124    Maximized,
125    /// Minimized desktop window on HarmonyOS PC (`2in1`).
126    Minimized,
127    /// Split-screen primary pane on HarmonyOS Tablet, Foldable, or PC.
128    SplitPrimary,
129    /// Split-screen secondary pane on HarmonyOS Tablet, Foldable, or PC.
130    SplitSecondary,
131}
132
133/// Outbound ArkTS / N-API host command emitted by `HarmonyPlatform` for PC desktop windowing, cursor, IME, and OS bridges.
134#[derive(Clone, Debug, PartialEq)]
135pub enum HarmonyHostCommand {
136    /// Updates the HarmonyOS PC/Tablet window title (`win.setWindowTitle`).
137    SetWindowTitle(String),
138    /// Transitions the HarmonyOS PC/Tablet window mode (`maximize` / `minimize` / `recover` / `setWindowLayoutFullScreen`).
139    SetWindowMode(HarmonyWindowMode),
140    /// Requests a freeform window resize on HarmonyOS PC (`win.resize`).
141    SetWindowSize {
142        /// Target logical width in vp.
143        width: u32,
144        /// Target logical height in vp.
145        height: u32,
146    },
147    /// Shows or hides native HarmonyOS PC window titlebar decorations (`win.setWindowDecorVisible`).
148    SetDecorations(bool),
149    /// Pins or unpins a HarmonyOS PC window above sibling windows (`win.setWindowTopmost`).
150    SetAlwaysOnTop(bool),
151    /// Updates the desktop pointer cursor style (`pointer.setPointerStyle`).
152    SetCursor(CursorIcon),
153    /// Shows or hides the HarmonyOS soft keyboard / IME (`@ohos.inputMethod`).
154    SetIme {
155        /// Whether text input is active.
156        enabled: bool,
157        /// Logical anchor rectangle for candidate bar placement.
158        rect: Rect,
159    },
160    /// Writes UTF-8 text to `@ohos.pasteboard`.
161    SetClipboard(String),
162    /// Triggers short haptic feedback via `@ohos.vibrator`.
163    VibrateShort,
164    /// Requests closing a HarmonyOS window (`win.destroyWindow`).
165    CloseWindow(WindowId),
166}