Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 110 additions & 84 deletions Runtime/DisplayXRNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,104 @@ public static extern void displayxr_set_transparent_overlay(
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void displayxr_set_window_decorated(int decorated);

/// <summary>
/// (#131) Put the transparent overlay into fixed full-screen,
/// app-managed window mode. enabled=1 sizes the overlay HWND to its
/// monitor at the aligned origin and DISABLES the native right-drag
/// move so the app owns all window interaction via virtual rects (3D
/// canvas sub-rect via displayxr_set_canvas_rect + 2D surround). This
/// turns move/resize into pure rectangle math (no OS resize, no
/// phase-snap, no mid-resize content drop). enabled=0 restores native
/// move. Windows transparent overlay only; no-op elsewhere.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void displayxr_set_overlay_fullscreen(int enabled);

/// <summary>
/// (#131) Opt in to a born-fullscreen transparent overlay. Must be called
/// BEFORE the overlay is created — call as early as possible, e.g. from a
/// RuntimeInitializeOnLoadMethod(BeforeSplashScreen). The overlay is then
/// created already covering its monitor, so the app needs no post-creation
/// resize (which recreates the swapchain = a startup flash) and Unity can
/// stay WINDOWED (avoiding fullscreen independent-flip, which bypasses DWM
/// alpha compositing and washes the content out). No-op once the overlay
/// exists. Windows transparent overlay only.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void displayxr_set_fullscreen_overlay_pref(int enabled);

/// <summary>
/// (#131) Set the transparent overlay's mouse cursor shape (applied each
/// mouse move over the overlay client area). Shapes: 0=arrow, 1=size-WE,
/// 2=size-NS, 3=size-NWSE, 4=size-NESW, 5=size-all (move). The region
/// editor uses it for resize affordances on window edges/corners and
/// region lines. Windows transparent overlay only; no-op elsewhere.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void displayxr_set_overlay_cursor(int shape);

/// <summary>
/// Read cursor position (overlay-client coords, top-left origin) and
/// mouse button state. Designed for transparent overlay mode where
/// Unity's New Input System Mouse.current.position is frozen because
/// the cloaked Unity HWND isn't OS-foreground (documented Unity
/// limitation). Returns (-1, -1) for clientX/Y if no overlay HWND.
/// Buttons: bit 0 = left, 1 = right, 2 = middle.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void displayxr_get_overlay_pointer(
out int clientX, out int clientY, out int buttons);

/// <summary>
/// (v1.2.2) Atomically read + zero the overlay's accumulated mouse-
/// wheel delta. Returns Win32 raw units (120 per notch; positive =
/// wheel forward). Always 0 in opaque mode (no transparent overlay).
/// The plugin no longer self-resizes the overlay on wheel events;
/// apps consume this value and decide what to do with it.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int displayxr_consume_overlay_wheel_delta();

/// <summary>
/// (display-zones port) Atomically read + zero the overlay's close-
/// request flag. Returns 1 once after the user pressed the decorated
/// overlay's close (X) button or Alt+F4. The plugin swallows the
/// overlay's WM_CLOSE (it does NOT destroy the overlay HWND, which would
/// leave cloaked Unity running headless) and raises this flag instead.
/// Apps poll it each frame and call Application.Quit() so the whole
/// process shuts down cleanly. Always 0 when no transparent overlay.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int displayxr_consume_overlay_close_request();

/// <summary>
/// (display-zones port) Resize the managed overlay window to width x
/// height px via SetWindowPos (#61-bracketed, clamped to a min size).
/// The reliable resize path on the SR display — the weaver subclass eats
/// mouse edge interactions on the non-activating overlay, but
/// SetWindowPos is never intercepted. Apps drive it from a keyboard
/// shortcut. No-op when there is no managed overlay window.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void displayxr_resize_overlay(int width, int height);

/// <summary>
/// (display-zones port) Get/set the managed overlay window's screen-space
/// top-left, for app-side window-position persistence. Set is #61-bracketed
/// (size unchanged). No-op when there is no managed overlay window.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void displayxr_get_overlay_position(out int x, out int y);

[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void displayxr_set_overlay_position(int x, int y);
#endif

// Click-through region (#57/#131 on Windows, #332 on Linux). Same exports
// on both: Windows builds a SetWindowRgn on the overlay HWND, Linux an XShape
// input region on Unity's window (see displayxr_linux.c). On Linux they are
// no-ops outside transparent mode.
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN || UNITY_STANDALONE_LINUX
/// <summary>
/// Set the rectangular hit-test region of the overlay. Coords
/// are overlay client-space pixels (top-left origin).
Expand Down Expand Up @@ -445,98 +543,26 @@ public static extern void displayxr_set_overlay_surround_rect(
public static extern void displayxr_set_overlay_surround_mask(
IntPtr mask, int mask_w, int mask_h,
int dst_x, int dst_y, int dst_w, int dst_h);
#endif

#if UNITY_STANDALONE_LINUX && !UNITY_EDITOR
/// <summary>
/// (#131) Put the transparent overlay into fixed full-screen,
/// app-managed window mode. enabled=1 sizes the overlay HWND to its
/// monitor at the aligned origin and DISABLES the native right-drag
/// move so the app owns all window interaction via virtual rects (3D
/// canvas sub-rect via displayxr_set_canvas_rect + 2D surround). This
/// turns move/resize into pure rectangle math (no OS resize, no
/// phase-snap, no mid-resize content drop). enabled=0 restores native
/// move. Windows transparent overlay only; no-op elsewhere.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void displayxr_set_overlay_fullscreen(int enabled);

/// <summary>
/// (#131) Opt in to a born-fullscreen transparent overlay. Must be called
/// BEFORE the overlay is created — call as early as possible, e.g. from a
/// RuntimeInitializeOnLoadMethod(BeforeSplashScreen). The overlay is then
/// created already covering its monitor, so the app needs no post-creation
/// resize (which recreates the swapchain = a startup flash) and Unity can
/// stay WINDOWED (avoiding fullscreen independent-flip, which bypasses DWM
/// alpha compositing and washes the content out). No-op once the overlay
/// exists. Windows transparent overlay only.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void displayxr_set_fullscreen_overlay_pref(int enabled);

/// <summary>
/// (#131) Set the transparent overlay's mouse cursor shape (applied each
/// mouse move over the overlay client area). Shapes: 0=arrow, 1=size-WE,
/// 2=size-NS, 3=size-NWSE, 4=size-NESW, 5=size-all (move). The region
/// editor uses it for resize affordances on window edges/corners and
/// region lines. Windows transparent overlay only; no-op elsewhere.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void displayxr_set_overlay_cursor(int shape);

/// <summary>
/// Read cursor position (overlay-client coords, top-left origin) and
/// mouse button state. Designed for transparent overlay mode where
/// Unity's New Input System Mouse.current.position is frozen because
/// the cloaked Unity HWND isn't OS-foreground (documented Unity
/// limitation). Returns (-1, -1) for clientX/Y if no overlay HWND.
/// Buttons: bit 0 = left, 1 = right, 2 = middle.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void displayxr_get_overlay_pointer(
out int clientX, out int clientY, out int buttons);

/// <summary>
/// (v1.2.2) Atomically read + zero the overlay's accumulated mouse-
/// wheel delta. Returns Win32 raw units (120 per notch; positive =
/// wheel forward). Always 0 in opaque mode (no transparent overlay).
/// The plugin no longer self-resizes the overlay on wheel events;
/// apps consume this value and decide what to do with it.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int displayxr_consume_overlay_wheel_delta();

/// <summary>
/// (display-zones port) Atomically read + zero the overlay's close-
/// request flag. Returns 1 once after the user pressed the decorated
/// overlay's close (X) button or Alt+F4. The plugin swallows the
/// overlay's WM_CLOSE (it does NOT destroy the overlay HWND, which would
/// leave cloaked Unity running headless) and raises this flag instead.
/// Apps poll it each frame and call Application.Quit() so the whole
/// process shuts down cleanly. Always 0 when no transparent overlay.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int displayxr_consume_overlay_close_request();

/// <summary>
/// (display-zones port) Resize the managed overlay window to width x
/// height px via SetWindowPos (#61-bracketed, clamped to a min size).
/// The reliable resize path on the SR display — the weaver subclass eats
/// mouse edge interactions on the non-activating overlay, but
/// SetWindowPos is never intercepted. Apps drive it from a keyboard
/// shortcut. No-op when there is no managed overlay window.
/// (#332) Right-drag move of the Linux transparent overlay. Call every
/// frame with the right button's state; the first pressed call starts
/// the drag, later ones move Unity's window (the overlay follows) by
/// how far the pointer has moved, the first released call ends it.
/// Returns 1 while a drag is in progress. No-op outside transparent mode.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void displayxr_resize_overlay(int width, int height);
public static extern int displayxr_linux_drag_window(int right_pressed);

/// <summary>
/// (display-zones port) Get/set the managed overlay window's screen-space
/// top-left, for app-side window-position persistence. Set is #61-bracketed
/// (size unchanged). No-op when there is no managed overlay window.
/// (#332) 1 while the Linux transparent overlay is up and the click-through
/// exports act; 0 for the opaque child window or without X. Cached state,
/// cheap to poll every frame.
/// </summary>
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void displayxr_get_overlay_position(out int x, out int y);

[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void displayxr_set_overlay_position(int x, int y);
public static extern int displayxr_linux_click_through_active();
#endif

}
Expand Down
Loading
Loading