Interface NativeWindow
- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
WindowPeer
- All Known Implementing Classes:
HeadlessWindow,StubWindow
This is the application's view of a window, which the 1.0 contract freezes. What the toolkit
asks of a window below it (input, frames, the input method, owned popups) is
WindowPeer's, in the incubating layer; every window is one, which is why this interface
is sealed: an application uses windows, and a backend implements them there.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceNotified when the window moves to a monitor with a different content scale. -
Method Summary
Modifier and TypeMethodDescriptiondefault AccessibilityBridgebackend()default ScreenRectbounds()default voidcaptureNextFrame(Path pngFile) Captures the next rendered frame to a PNG file, creating the parent directories if they are missing: the--screenshotpath.voidcaptureNextFrame(Consumer<Image> sink) Captures the next rendered frame (post-flush, pre-swap) and hands the pixels tosink: a per-window screenshot without touching the frame callback, and without a file.voidclose()Same asrequestClose(); actual destruction happens in the loop/backend.@Nullable CloseRequestHandlerfloatdefault floatcursorX()default floatcursorY()default @Nullable Displaydisplay()default voidMakes the window fullscreen without changing the display's mode: native fullscreen on macOS, a borderless window covering the monitor at its current mode on Windows and X11, and the compositor's fullscreen on Wayland.voidenterFullscreen(int width, int height, int refreshRate) Makes the window fullscreen on the monitor it occupies, in one of two ways, chosen by whether the call names a display mode.default voidenterFullscreen(Resolution mode) Makes the window fullscreen atmode, switching the display to it: the exclusive fullscreen a game asks for, on every platform but Wayland, which changes no display's mode.voidLeaves fullscreen of either kind, and does nothing for a window that is not fullscreen.voidfocus()Brings this window to the front and gives it input focus.intintvoidhide()booleanisClosed()booleanWhether the window is fullscreen, of either kind.default booleandefault booleanbooleanbooleanlauncher()floatfloatfloatdefault voidmaximize()Maximizes the window: it fills the screen's work area, keeping its frame.default voidminimize()Minimizes the window: it leaves the screen and stays in the desktop's dock or task bar, from where the user brings it back.default longThis window's handle in the platform's own terms: anHWNDon Windows, anNSWindowon macOS, anxcb_window_torwl_surfaceon Linux.default SubscriptionobserveState(Consumer<WindowState> listener) Observes the window's state: the listener is told each time the window is shown or hidden, minimized, maximized or restored, enters or leaves fullscreen, is moved or changes size, whether the application did it or the user.voidoverrideContentScale(float scale) Forces the rendering content scale, ignoring the monitor's.default PointerModeprinter()voidAsks the window to close (processed by the event loop).voidMarks the window dirty so the loop renders a frame for it.default voidrestore()Puts a minimized or a maximized window back to the size and the place it had before.intscreenX()intscreenY()default voidsetAboveSystemChrome(boolean above) Raises this window above the OS chrome so it can cover the whole display.default voidsetAccessibility(AccessibilityBridge bridge) Hands this window the platform accessibility bridge an application chose for it.voidsetClosePolicy(ClosePolicy policy) Sets what a user's close does once it is allowed: dispose the window (the default), hide it, or end the application.voidsetCloseRequestHandler(@Nullable CloseRequestHandler handler) Sets the handler asked whether this window may close: when the user closes it (the OS close button, Alt-F4, Cmd-W), and when the application is ending (Backend.requestQuit()).voidRegisters a listener for runtime monitor/content-scale changes.default voidSets the mouse cursor shown while the pointer is over this window.default voidsetCursorPosition(float x, float y) Warps the pointer to (x,y) in logical points relative to this window's content area.default voidSets the window icon (title bar / taskbar) from one or more candidate sizes; the platform picks the closest (16–48px covers the common slots).default voidsetImageCursor(@Nullable ImageCursor cursor) Shows a customImageCursorinstead of the current standardshape;nullclears it and restores the last shape.default voidsetMousePassthrough(boolean passthrough) Makes the window transparent to MOUSE input: clicks, wheel and hover pass through to whatever sits beneath it, for overlay/HUD windows whose empty (usually transparent) regions must not steal the desktop's mouse.default voidsetOpacity(float opacity) Sets the whole-window opacity in[0..1]at the compositor level, the fade primitive behindScene.fadeWindow(float, double, java.lang.Runnable).default voidsetPointerMode(@Nullable PointerMode mode) Sets how this window treats the pointer: visibility, confinement, relative capture.voidsetScreenPosition(int x, int y) Moves the window (native screen coordinates; seelogicalToScreenFactor()).voidsetSize(int width, int height) Resizes the window to the given size in logical points.default voidsetSizeLimits(int minWidth, int minHeight, int maxWidth, int maxHeight) Constrains user resizing to the given bounds in logical points; pass<= 0for any bound to leave it unconstrained.voidSets the native title bar text.voidshow()default SizeLimitsdefault WindowStatestate()title()default voidtoFront()Brings the window in front of the others and gives it the keyboard, whatever state it is in: shown if it was hidden, restored if it was minimized.
-
Method Details
-
title
String title()- Returns:
- the current title
-
setTitle
Sets the native title bar text. -
logicalWidth
float logicalWidth()- Returns:
- width in logical points (framebuffer width ÷ content scale)
-
logicalHeight
float logicalHeight()- Returns:
- height in logical points (framebuffer height ÷ content scale)
-
framebufferWidth
int framebufferWidth()- Returns:
- framebuffer width in physical pixels
-
framebufferHeight
int framebufferHeight()- Returns:
- framebuffer height in physical pixels
-
contentScale
float contentScale()- Returns:
- the content scale in effect for this window: the monitor's, or the forced one. Fractional values (1.25, 1.5, 1.75) are first-class citizens, never assume integer
-
overrideContentScale
void overrideContentScale(float scale) Forces the rendering content scale, ignoring the monitor's. Screenshot scenes use it to validate 1.0/1.25/1.5/2.0 rendering on any monitor. Pass0to return to the monitor scale. -
setSize
void setSize(int width, int height) Resizes the window to the given size in logical points. -
setSizeLimits
default void setSizeLimits(int minWidth, int minHeight, int maxWidth, int maxHeight) Constrains user resizing to the given bounds in logical points; pass<= 0for any bound to leave it unconstrained. Only affects interactive resizes;setSize(int, int)is not clamped. A window made from aWindowConfigwithWindowConfig.minSize(int, int)orWindowConfig.maxSize(int, int)starts with those. The default implementation ignores it (headless/embedding). UI thread only. -
sizeLimits
- Returns:
- the bounds the user may resize this window within, as its configuration or the last
setSizeLimits(int, int, int, int)set them;SizeLimits.NONEwhere the implementation keeps none (headless, embedding)
-
setIcon
Sets the window icon (title bar / taskbar) from one or more candidate sizes; the platform picks the closest (16–48px covers the common slots). No-op where the platform has no per-window icons (macOS uses the app bundle's icon; a Wayland desktop shows the application entry's). The default implementation ignores it (headless/embedding). UI thread only. -
setCloseRequestHandler
Sets the handler asked whether this window may close: when the user closes it (the OS close button, Alt-F4, Cmd-W), and when the application is ending (Backend.requestQuit()). It answers through theCloseRequestit is handed, at once or later, so an "unsaved changes" dialog can decide. With no handler, the window agrees. A program'srequestClose()bypasses it.nullclears. UI thread only.A window created with an owner (
WindowConfig.popup(NativeWindow, int, int)orWindowConfig.ownedBy(limn.backend.NativeWindow): a native dialog, a menu) is not asked when the application ends: its owner speaks for it, and it closes with it.No default: a backend that ignored it lost an application's "unsaved changes" veto silently. A backend with no close gesture of its own (headless, embedded) keeps the handler, asks it only when the application ends, and says so in its implementation.
- Parameters:
handler- the handler, ornullfor none
-
closeRequestHandler
@Nullable CloseRequestHandler closeRequestHandler()- Returns:
- the handler set with
setCloseRequestHandler(limn.backend.CloseRequestHandler), ornullfor none
-
setClosePolicy
Sets what a user's close does once it is allowed: dispose the window (the default), hide it, or end the application. A program'srequestClose()disposes whatever this says. UI thread only.- Parameters:
policy- the policy; nevernull- Throws:
NullPointerException- ifpolicyisnull
-
closePolicy
ClosePolicy closePolicy()- Returns:
- what a user's close does;
ClosePolicy.DISPOSEunless set
-
show
void show() -
hide
void hide() -
minimize
default void minimize()Minimizes the window: it leaves the screen and stays in the desktop's dock or task bar, from where the user brings it back. Unlikehide(), the user can reach it again without the application's help. UI thread only.The default does nothing, which is the answer of a window with no desktop under it; so do
maximize(),restore()and the two readings beside them. -
maximize
default void maximize()Maximizes the window: it fills the screen's work area, keeping its frame. A window in fullscreen is left as it is. UI thread only. -
restore
default void restore()Puts a minimized or a maximized window back to the size and the place it had before. A window that is neither is left as it is. UI thread only. -
isMinimized
default boolean isMinimized()- Returns:
- whether the window is minimized now. Under Wayland a client is not told, and the
answer is
false
-
isMaximized
default boolean isMaximized()- Returns:
- whether the window is maximized now
-
bounds
- Returns:
- the window's content's place and size in native screen coordinates:
screenX(),screenY(), and its logical size bylogicalToScreenFactor(). UI thread only
-
state
- Returns:
- where the window is, how large and in which state, now. UI thread only
-
observeState
Observes the window's state: the listener is told each time the window is shown or hidden, minimized, maximized or restored, enters or leaves fullscreen, is moved or changes size, whether the application did it or the user. It is told on the UI thread, after the change and once for it, with the state as it then is; a window the user drags or resizes tells it at each place and size along the way.The default tells nothing, which is the answer of a window with no desktop under it.
- Parameters:
listener- what to tell- Returns:
- a handle that unsubscribes; cancelling it twice is a no-op. UI thread only
-
toFront
default void toFront()Brings the window in front of the others and gives it the keyboard, whatever state it is in: shown if it was hidden, restored if it was minimized. It is what a click on an application's tray icon or on a "show the window" command calls. Whether a window may come in front of another application's is the desktop's to allow, as forfocus(). UI thread only. -
setOpacity
default void setOpacity(float opacity) Sets the whole-window opacity in[0..1]at the compositor level, the fade primitive behindScene.fadeWindow(float, double, java.lang.Runnable). Affects the entire window uniformly, decorations included. A no-op where the platform's compositor does not support per-window opacity, and under Wayland, which gives a program none; the default implementation ignores it (headless/embedding). UI thread only. -
setCursor
Sets the mouse cursor shown while the pointer is over this window. The scene calls this as the hovered widget changes;nullorCursor.DEFAULTrestores the plain arrow. A shape the platform cannot provide falls back to the arrow. The default implementation ignores it (headless/embedding). UI thread only. -
focus
void focus()Brings this window to the front and gives it input focus. UI thread only. -
isVisible
boolean isVisible()- Returns:
- whether the window is currently visible on screen
-
isClosed
boolean isClosed()- Returns:
- whether this window has already been closed/destroyed
-
enterFullscreen
void enterFullscreen(int width, int height, int refreshRate) Makes the window fullscreen on the monitor it occupies, in one of two ways, chosen by whether the call names a display mode.Naming no mode,
width,heightandrefreshRateall ≤ 0 asenterFullscreen()passes them, leaves the display in the mode it is in, which is the fullscreen a document, a dashboard or any application that is not a game wants:- macOS: native fullscreen, what the green button and Control-Command-F do. The window moves to a Space of its own with an animation of most of a second, the menu bar and the title bar slide in when the pointer reaches the top of the screen, and the person can leave it the way they leave any application's. This call returns before the animation ends, and the window reports its new size when AppKit resizes it.
- Windows and X11: a borderless window covering the monitor at the mode it is in, on X11 through the window manager's fullscreen state where it has one.
- Wayland: the compositor's fullscreen.
Naming a mode, a size or a refresh rate or both, is the exclusive fullscreen a game asks for: the display is switched to the mode it lists nearest to the one named, which holds the application for a noticeable moment each way (more than half a second on a Mac), and is switched back by
exitFullscreen(). A dimension ≤ 0 beside a named one is the current one. The size is in screen coordinates, as aResolution's is: pixels on Windows, X11 and Wayland, points on macOS. On macOS the window covers the menu bar and the Dock and has no Space of its own; the mode a Retina display is in is usually not one it can be switched to, so naming the current mode switches to another. Wayland lets no application change the display's mode, and there the window is fullscreen at the compositor's whatever is named.Losing the focus tells the two apart. A window at a named mode is minimized when another window takes the focus, on every platform, and a switched mode is switched back until the window is restored, which is what a game wants when the person switches away from it. A window at the mode the display is in is not: on Windows, X11 and Wayland it stays fullscreen behind the window that took the focus, as a browser's fullscreen does, and the person comes back to it as they left it; on macOS the person moves to another Space and back.
A window already fullscreen one way and asked for the other leaves the first: a switched mode is switched back before native fullscreen begins, and native fullscreen is left, with its animation, before the mode is switched. The windowed position and size are remembered for
exitFullscreen(). UI thread only.- Parameters:
width- width in screen coordinates, or ≤ 0 to name noneheight- height in screen coordinates, or ≤ 0 to name nonerefreshRate- refresh rate in Hz, or ≤ 0 to name none
-
enterFullscreen
default void enterFullscreen()Makes the window fullscreen without changing the display's mode: native fullscreen on macOS, a borderless window covering the monitor at its current mode on Windows and X11, and the compositor's fullscreen on Wayland. The fullscreen of an application rather than a game: it is not minimized when another window takes the focus, but stays fullscreen behind it. SeeenterFullscreen(int, int, int). UI thread only. -
enterFullscreen
Makes the window fullscreen atmode, switching the display to it: the exclusive fullscreen a game asks for, on every platform but Wayland, which changes no display's mode. The normalized form ofenterFullscreen(int, int, int)that takes aResolution, such as one fromdisplay().availableResolutions(). To keep the display as it is, callenterFullscreen()instead: on macOS a Retina display's current mode is usually not among those a switch can reach. The window is minimized when another window takes the focus, and the display switched back until it is restored. UI thread only.- Parameters:
mode- the mode to switch to- Throws:
NullPointerException- ifmodeis null, as it is from a display that lists none
-
exitFullscreen
void exitFullscreen()Leaves fullscreen of either kind, and does nothing for a window that is not fullscreen. A switched mode is switched back and the windowed position and size asked for before this returns, and given back as the window had them: where the window manager answers later, as on X11, a window it gives back maximized when it was not, or elsewhere or at another size, is asked once more when the answer comes. macOS native fullscreen is left with its animation, after this returns, and is left whether the application or the person entered it. UI thread only. -
isFullscreen
boolean isFullscreen()Whether the window is fullscreen, of either kind. On macOS that includes native fullscreen the person entered with the green button, Control-Command-F or the menu, and the answer is where the window is going rather than where its animation has got to:truefrom the momententerFullscreen()returns or the person starts the animation,falsefrom the momentexitFullscreen()returns or the person starts leaving. Elsewhere it is whether this window was made fullscreen and has not been told to leave.Each change of this answer is told to the window's input, through
WindowInput.windowFullscreenChanged(boolean), including the changes the person makes on macOS. A window that can never be fullscreen never tells it.- Returns:
- whether the window is, or is going to be, fullscreen
-
isModalBlocked
boolean isModalBlocked()- Returns:
- whether this window is currently locked by an active modal (its input is ignored); the scene dims it while true
-
backend
Backend backend()- Returns:
- the backend that owns this window (popup creation, shutdown)
-
fileDialogs
FileDialogs fileDialogs()- Returns:
- the platform's file and folder choosers, owned by this window;
FileDialogs.NONEfor a window with none (headless, embedded). No default: a backend that answeredNONEby omission made every "Open…" in an application silently do nothing. UI thread only.
-
launcher
Launcher launcher()- Returns:
- what hands an address or a file to the system this window is on;
Launcher.NONEfor a window with no desktop under it (headless, embedded). No default, for the reasonfileDialogs()has none: a link that silently opens nothing. UI thread only.
-
printer
Printer printer()- Returns:
- what prints a PDF through the system's own print dialog, owned by this window;
Printer.NONEfor a window with no printing under it (headless, embedded). No default, for the reasonlauncher()has none: a "Print…" that silently prints nothing. UI thread only.
-
clipboard
Clipboard clipboard()- Returns:
- the system clipboard
-
screenX
int screenX()- Returns:
- window x in native screen coordinates
-
screenY
int screenY()- Returns:
- window y in native screen coordinates
-
setScreenPosition
void setScreenPosition(int x, int y) Moves the window (native screen coordinates; seelogicalToScreenFactor()). -
setMousePassthrough
default void setMousePassthrough(boolean passthrough) Makes the window transparent to MOUSE input: clicks, wheel and hover pass through to whatever sits beneath it, for overlay/HUD windows whose empty (usually transparent) regions must not steal the desktop's mouse. While enabled this window receives no mouse events at all; pollcursorX()/cursorY()to decide when to turn it back off (e.g. the cursor entered one of the overlay's visible items). Keyboard focus is unaffected. No-op where the platform lacks support. -
cursorX
default float cursorX()- Returns:
- the cursor's current x in logical points relative to this
window's content area; polled, so it works while unfocused or
mouse-passthrough
(which mutes events).
NaNwhen unsupported. UI thread only.
-
cursorY
default float cursorY()- Returns:
- the cursor's current y; see
cursorX()
-
setPointerMode
Sets how this window treats the pointer: visibility, confinement, relative capture. See eachPointerModeconstant;nullmeansPointerMode.NORMAL. InPointerMode.RELATIVEthe window stops receivingWindowInput.mouseMoved(float, float)and receivesWindowInput.mouseDelta(float, float)instead. Interactions that capture from a widget must restoreNORMALwhen they end (release/EXIT/detach); the mode is window state and survives the widget. No-op where unsupported. UI thread only. -
pointerMode
- Returns:
- the current
PointerMode(defaultPointerMode.NORMAL)
-
setImageCursor
Shows a customImageCursorinstead of the current standardshape;nullclears it and restores the last shape. The scene drives this fromWidget.setImageCursor(limn.backend.ImageCursor)hover resolution; call it directly only in windowless/manual setups. UI thread only. -
setCursorPosition
default void setCursorPosition(float x, float y) Warps the pointer to (x,y) in logical points relative to this window's content area. No input event is synthesized; the next real mouse event reflects the new position. Useful withPointerMode.RELATIVEinteractions and edge-wrap schemes; may be restricted by the platform while the window is unfocused, and does nothing under Wayland, which lets no program move the pointer. UI thread only. -
setAboveSystemChrome
default void setAboveSystemChrome(boolean above) Raises this window above the OS chrome so it can cover the whole display. On macOS the menu bar and Dock draw at window levels above an ordinary always-on-top window, so a full-screen transparent overlay would otherwise be occluded by them. When enabled the window floats above that chrome (a cube can fly over the menu bar; transparent regions still show it through, and passthrough keeps it clickable); disabling restores the normal always-on-top level. No-op where the platform needs nothing extra to cover its chrome. UI thread only. -
logicalToScreenFactor
float logicalToScreenFactor()- Returns:
- multiplier from logical points to native screen coordinates (1.0 on macOS, the monitor scale on Windows/X11), for positioning popups relative to widget bounds
-
display
- Returns:
- the
Displaythis window currently sits on (the monitor containing the window's centre), ornullwhen headless/embedded. ItsDisplay.workArea()is what external popups clamp against to stay on screen. UI thread only.
-
captureNextFrame
Captures the next rendered frame (post-flush, pre-swap) and hands the pixels tosink: a per-window screenshot without touching the frame callback, and without a file. Requests a frame, so it works on an idle window.sinkruns on the UI thread inside that frame.The image is display-referred: it is what the composite produced, not scene-referred content awaiting a display transform. See
GpuRenderer.captureFramebuffer(java.util.function.Consumer). -
captureNextFrame
Captures the next rendered frame to a PNG file, creating the parent directories if they are missing: the--screenshotpath. -
accessibility
- Returns:
- the platform accessibility bridge for this window, or
AccessibilityBridge.NONEwhen it has none.defaulton the merits rather than as a compatibility dodge: none is the correct behaviour for a window with no accessibility — a test double, an embedded surface, any future backend on its first day — and getting exactly zero cost by writing nothing is better than getting it by writing the same stub in each.
-
setAccessibility
Hands this window the platform accessibility bridge an application chose for it.The other half of the seam above, and it was missing: an application could read what a window's bridge was and had no way to say what it should be, so the per-platform bridges ADR 039 makes optional artifacts could be added to a classpath and never installed. It is a setter and not a constructor argument because the Windows bridge needs
nativeHandle()to exist before it can be made, and that handle is the window's.defaultfor the same reason the getter is: a window with no accessibility is a correct window, and ignoring the offer is the correct thing for one to do.- Parameters:
bridge- what to hand a scene bound here, nevernull
-
nativeHandle
default long nativeHandle()This window's handle in the platform's own terms: anHWNDon Windows, anNSWindowon macOS, anxcb_window_torwl_surfaceon Linux.Exists for one caller and should have no other: a platform accessibility bridge that has to attach to the window itself. The Windows one replaces the window procedure to answer
WM_GETOBJECT; the macOS one will need theNSWindowto reach its content view. Nothing in the toolkit reads this, and an application that finds itself wanting it for anything else is describing a gap in this interface rather than a use for this method.- Returns:
- the handle, or
0where there is none — a test double, an embedded surface, a platform this backend has not been taught
-
setContentScaleListener
Registers a listener for runtime monitor/content-scale changes. -
requestFrame
void requestFrame()Marks the window dirty so the loop renders a frame for it. UI thread only: from a background thread, hop withUi.post(window::requestFrame). -
requestClose
void requestClose()Asks the window to close (processed by the event loop). Any-thread safe. -
close
void close()Same asrequestClose(); actual destruction happens in the loop/backend.- Specified by:
closein interfaceAutoCloseable
-