XPLMDisplay


Create and manage windows, handle keyboard/mouse input, control avionics device screens, and query screen/monitor geometry.


Enumerations

XPLMDeviceID

This constant indicates the device we want to override or enhance. We can get a callback before or after each item.

Constant Value Description
xplm_device_GNS430_1 0 GNS430, pilot side.
xplm_device_GNS430_2 1 GNS430, copilot side.
xplm_device_GNS530_1 2 GNS530, pilot side.
xplm_device_GNS530_2 3 GNS530, copilot side.
xplm_device_CDU739_1 4 generic airliner CDU, pilot side.
xplm_device_CDU739_2 5 generic airliner CDU, copilot side.
xplm_device_G1000_PFD_1 6 G1000 Primary Flight Display, pilot side.
xplm_device_G1000_MFD 7 G1000 Multifunction Display.
xplm_device_G1000_PFD_2 8 G1000 Primary Flight Display, copilot side.
xplm_device_CDU815_1 9 Primus CDU, pilot side.
xplm_device_CDU815_2 10 Primus CDU, copilot side.
xplm_device_Primus_PFD_1 11 Primus Primary Flight Display, pilot side.
xplm_device_Primus_PFD_2 12 Primus Primary Flight Display, copilot side.
xplm_device_Primus_MFD_1 13 Primus Multifunction Display, pilot side.
xplm_device_Primus_MFD_2 14 Primus Multifunction Display, copilot side.
xplm_device_Primus_MFD_3 15 Primus Multifunction Display, central.
xplm_device_Primus_RMU_1 16 Primus Radio Management Unit, pilot side.
xplm_device_Primus_RMU_2 17 Primus Radio Management Unit, copilot side.
xplm_device_MCDU_1 18 Airbus MCDU, pilot side.
xplm_device_MCDU_2 19 Airbus MCDU, copilot side.
xplm_device_MCDU_3 24 Airbus MCDU 3.
XPLMWindowLayer

XPLMWindowLayer describes where in the ordering of windows X-Plane should place a particular window. Windows in higher layers cover windows in lower layers. So, a given window might be at the top of its particular layer, but it might still be obscured by a window in a higher layer. (This happens frequently when floating windows, like X-Plane's map, are covered by a modal alert.) Your window's layer can only be specified when you create the window (in the XPLMCreateWindow_t you pass to XPLMCreateWindowEx()). For this reason, layering only applies to windows created with new X-Plane 11 GUI features. (Windows created using the older XPLMCreateWindow(), or windows compiled against a pre-XPLM300 version of the SDK will simply be placed in the flight overlay window layer.)

Constant Value Description
xplm_WindowLayerFlightOverlay 0 The lowest layer, used for HUD-like displays while flying.
xplm_WindowLayerFloatingWindows 1 Windows that "float" over the sim, like the X-Plane 11 map does. If you are not sure which layer to create your window in, choose floating.
xplm_WindowLayerModal 2 An interruptive modal that covers the sim with a transparent black overlay to draw the user's focus to the alert
xplm_WindowLayerGrowlNotifications 3 "Growl"-style notifications that are visible in a corner of the screen, even over modals
XPLMWindowDecoration

XPLMWindowDecoration describes how "modern" windows will be displayed. This impacts both how X-Plane draws your window as well as certain mouse handlers. Your window's decoration can only be specified when you create the window (in the XPLMCreateWindow_t you pass to XPLMCreateWindowEx()).

Constant Value Description
xplm_WindowDecorationNone 0 X-Plane will draw no decoration for your window, and apply no automatic click handlers. The window will not stop click from passing through its bounds. This is suitable for "windows" which request, say, the full screen bounds, then only draw in a small portion of the available area.
xplm_WindowDecorationRoundRectangle 1 The default decoration for "native" windows, like the map. Provides a solid background, as well as click handlers for resizing and dragging the window.
xplm_WindowDecorationSelfDecorated 2 X-Plane will draw no decoration for your window, nor will it provide resize handlers for your window edges, but it will stop clicks from passing through your windows bounds.
xplm_WindowDecorationSelfDecoratedResizable 3 Like self-decorated, but with resizing; X-Plane will draw no decoration for your window, but it will stop clicks from passing through your windows bounds, and provide automatic mouse handlers for resizing.
XPLMWindowContentType

XPLMWindowContentType describes how content for this window is provided.

Constant Value Description
xplm_WindowContentTypePanelGraphics 1 The window is drawn by calling back your plugin, which will draw using panel graphics APIs. You provide mouse and keyboard hooks for interaction.
xplm_WindowContentTypeBrowser 2 The window content is specified using a web page.
XPLMWindowPositioningMode

XPLMWindowPositionMode describes how X-Plane will position your window on the user's screen. X-Plane will maintain this positioning mode even as the user resizes their window or adds/removes full-screen monitors. Positioning mode can only be set for "modern" windows (that is, windows created using XPLMCreateWindowEx() and compiled against the XPLM300 SDK). Windows created using the deprecated XPLMCreateWindow(), or windows compiled against a pre-XPLM300 version of the SDK will simply get the "free" positioning mode.

Constant Value Description
xplm_WindowPositionFree 0 The default positioning mode. Set the window geometry and its future position will be determined by its window gravity, resizing limits, and user interactions.
xplm_WindowCenterOnMonitor 1 Keep the window centered on the monitor you specify
xplm_WindowFullScreenOnMonitor 2 Keep the window full screen on the monitor you specify
xplm_WindowFullScreenOnAllMonitors 3 Like gui_window_full_screen_on_monitor, but stretches over all monitors and popout windows. This is an obscure one... unless you have a very good reason to need it, you probably don't!
xplm_WindowPopOut 4 A first-class window in the operating system, completely separate from the X-Plane window(s)
xplm_WindowVR 5 A floating window visible on the VR headset

Functions

XLuaRegisterAvionicsCallbacksEx({k})

Returns: XPLMAvionicsID

This routine registers your callbacks for a built-in device. This returns a handle. If the returned handle is NULL, there was a problem interpreting your input, most likely the struct size was wrong for your SDK version. If the returned handle is not NULL, your callbacks will be called according to schedule as long as your plugin is not deactivated, or unloaded, or you call XPLMUnregisterAvionicsCallbacks(). Note that you cannot register new callbacks for a device that is not a built-in one (for example a device that you have created, or a device another plugin has created).

Argument Type Notes
params {k} Hash table — {{ field = value, ... }} (see SDK docs for fields)
XLuaGetAvionicsHandle(deviceID)

Returns: XPLMAvionicsID

This routine registers no callbacks for a built-in cockpit device, but returns a handle which allows you to interact with it using the Avionics Device API. Use this if you do not wish to intercept drawing, clicks and touchscreen calls to a device, but want to interact with its popup programmatically. This is equivalent to calling XPLMRegisterAvionicsCallbackEx() with NULL for all callbacks.

Argument Type Notes
deviceID XPLMDeviceID Enum — use a constant from XPLMDeviceID
XLuaUnregisterAvionicsCallbacks(avionicsId)

Returns: (returns nothing)

This routine unregisters your callbacks for a built-in device. You should only call this for handles you acquired from XPLMRegisterAvionicsCallbacksEx(). They will no longer be called.

Argument Type Notes
avionicsId XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
XLuaCreateAvionicsEx({k})

Returns: XPLMAvionicsID

Creates a new cockpit device to be used in the 3D cockpit. You can call this at any time: if an aircraft referencing your device is loaded before your plugin, the simulator will make sure to retroactively map your display into it. When you are done with the device, and at least before your plugin is unloaded, you should destroy the device using XPLMDestroyAvionics().

Argument Type Notes
params {k} Hash table — {{ field = value, ... }} (see SDK docs for fields)
XLuaDestroyAvionics(handle)

Returns: (returns nothing)

Destroys the cockpit device and deallocates its screen's memory. You should only ever call this for devices that you created using XPLMCreateAvionicsEx(), not X-Plane' built-ine devices you have customised.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
XLuaIsAvionicsBound(handle)

Returns: boolean

Returns true (1) if the cockpit device with the given handle is used by the current aircraft.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
XLuaSetAvionicsBrightnessRheo(handle, brightness)

Returns: (returns nothing)

Sets the brightness setting's value, between 0 and 1, for the screen of the cockpit device with the given handle. If the device is bound to the current aircraft, this is a shortcut to setting the brightness rheostat value using the sim/cockpit2/switches/instrument_brightness_ratio[] dataref; this sets the slot in the instrument_brightness_ratio array to which the device is bound. If the device is not currently bound, the device keeps track of its own screen brightness rheostat, allowing you to control the brightness even though it isn't connected to the instrument_brightness_ratio dataref.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
brightness number
XLuaGetAvionicsBrightnessRheo(handle)

Returns: number

Returns the brightness setting value, between 0 and 1, for the screen of the cockpit device with the given handle. If the device is bound to the current aircraft, this is a shortcut to getting the brightness rheostat value from the sim/cockpit2/switches/instrument_brightness_ratio[] dataref; this gets the slot in the instrument_brightness_ratio array to which the device is bound. If the device is not currently bound, this returns the device's own brightness rheostat value.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
XLuaGetAvionicsBusVoltsRatio(handle)

Returns: number

Returns the ratio of the nominal voltage (1.0 means full nominal voltage) of the electrical bus to which the given avionics device is bound, or -1 if the device is not bound to the current aircraft.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
XLuaIsCursorOverAvionics(handle)

Returns: boolean, {k} with keys: x, y

Returns true (1) if the mouse is currently over the screen of cockpit device with the given handle. If they are not NULL, the optional x and y arguments are filled with the co-ordinates of the mouse cursor in device co-ordinates.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID

Output table keys:

Key Type
x number
y number
XLuaAvionicsNeedsDrawing(handle)

Returns: (returns nothing)

Tells X-Plane that your device's screen needs to be re-drawn. If your device is marked for on-demand drawing, X-Plane will call your screen drawing callback before drawing the next simulator frame. If your device is already drawn every frame, this has no effect.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
XLuaSetAvionicsPopupVisible(handle, visible)

Returns: (returns nothing)

Shows or hides the popup window for a cockpit device. Visibility is independent of where the popup is drawn (in the X-Plane window, popped out as an OS window, or mapped to a VR floating window): the popup always remains in whichever target mode you most recently selected, and toggling visibility just shows or hides it there.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
visible boolean
XLuaIsAvionicsPopupVisible(handle)

Returns: boolean

Returns true (1) if the popup window for a cockpit device is visible.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
XLuaPopOutAvionics(handle)

Returns: (returns nothing)

Pops out the window for a cockpit device, making it a first-class window in the operating system, separate from the X-Plane window. Popping out and being mapped to VR are mutually exclusive: if the device is currently mapped to VR (XPLMIsAvionicsMappedToVR() is true), calling this routine clears its VR mapping before popping out.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
XLuaIsAvionicsPoppedOut(handle)

Returns: boolean

Returns true (1) if the popup window for a cockpit device is popped out as a first-class OS window. This is true if and only if you have most recently asked the popup to be popped out (via XPLMPopOutAvionics()) and it has not since been mapped to VR (via XPLMSetAvionicsMappedToVR()).

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
XLuaSetAvionicsMappedToVR(handle, mapped)

Returns: (returns nothing)

Maps a custom cockpit device's popup window to a VR floating window in the headset, or returns it from VR back to the X-Plane window. Pass 1 to map to VR, 0 to unmap. The VR window shows the device's bezel and screen at their intrinsic size, as supplied via XPLMCreateAvionicsEx(). Avionics in VR are not user-resizable. Mapping to VR and being popped out as an OS window are mutually exclusive: calling this with inMapped=1 on a popped-out device clears its pop-out state, and calling XPLMPopOutAvionics() on a VR-mapped device clears its VR mapping. This mirrors the relationship between xplm_WindowPopOut and xplm_WindowVR for XPLMWindow. VR mapping is independent of popup visibility (XPLMSetAvionicsPopupVisible). Mapping a hidden popup to VR leaves it hidden until you make it visible. Has no effect (and logs a warning) if VR is not currently running on the headset, or if the device was not created via XPLMCreateAvionicsEx() (built-in avionics cannot be VR-mapped).

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
mapped boolean
XLuaIsAvionicsMappedToVR(handle)

Returns: boolean

Returns true (1) if the popup window for a cockpit device is currently mapped to a VR floating window. This is true if and only if you have most recently asked the device to be mapped to VR (via XPLMSetAvionicsMappedToVR()) and it has not since been unmapped, popped out, or had VR shut down beneath it.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
XLuaTakeAvionicsKeyboardFocus(handle)

Returns: (returns nothing)

This routine gives keyboard focus to the popup window of a custom cockpit device, if it is visible.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
XLuaHasAvionicsKeyboardFocus(handle)

Returns: boolean

Returns true (1) if the popup window for a cockpit device has keyboard focus.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
XLuaGetAvionicsGeometry(handle)

Returns: {k} with keys: left, top, right, bottom

Returns the bounds of a cockpit device's popup window in the X-Plane coordinate system.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID

Output table keys:

Key Type
left number
top number
right number
bottom number
XLuaSetAvionicsGeometry(handle, left, top, right, bottom)

Returns: (returns nothing)

Sets the size and position of a cockpit device's popup window in the X-Plane coordinate system.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
left integer
top integer
right integer
bottom integer
XLuaGetAvionicsGeometryOS(handle)

Returns: {k} with keys: left, top, right, bottom

Returns the bounds of a cockpit device's popped-out window.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID

Output table keys:

Key Type
left number
top number
right number
bottom number
XLuaSetAvionicsGeometryOS(handle, left, top, right, bottom)

Returns: (returns nothing)

Sets the size and position of a cockpit device's popped-out window.

Argument Type Notes
handle XPLMAvionicsID Enum — use a constant from XPLMAvionicsID
left integer
top integer
right integer
bottom integer
XLuaCreateWindowEx({k})

Returns: XPLMWindowID

This routine creates a new "modern" window. You pass in an XPLMCreateWindow_t structure with all of the fields set in. You must set the structSize of the structure to the size of the actual structure you used. Also, you must provide functions for every callback---you may not leave them null! (If you do not support the cursor or mouse wheel, use functions that return the default values.)

Argument Type Notes
params {k} Hash table — {{ field = value, ... }} (see SDK docs for fields)
XLuaDestroyWindow(windowID)

Returns: (returns nothing)

This routine destroys a window. The window's callbacks are not called after this call. Keyboard focus is removed from the window before destroying it.

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
XLuaWindowSetURL(windowID, uRL)

Returns: (returns nothing)

Loads a URL into a browser-content-type window. Safe to call before the underlying webview has finished initialising; the load is queued and applied as soon as the browser is ready, so plugins may call this immediately after XPLMCreateWindowEx. Subsequent calls replace the pending or current page.

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
uRL string
XLuaWindowRefresh(windowID, ignoreCache)

Returns: (returns nothing)

Reloads the current URL in a browser-content-type window. Pass true for inIgnoreCache to bypass the HTTP cache (the equivalent of a shift-reload).

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
ignoreCache boolean
XLuaWindowInjectScript(windowID, script)

Returns: (returns nothing)

Executes a JavaScript snippet in the browser window's main frame. The script is run once; it has access to the same xplane.* namespace exposed to the page itself (so it can call functions registered via XPLMWindowAddBrowserFunction). If injected before the page has finished loading, the script may run against an empty document.

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
script string
XLuaWindowAddBrowserFunction(windowID, name, callback, refcon)

Returns: (returns nothing)

Registers a callback that the page running in this browser window can invoke as xplane.<inName>(arg). The JS call returns a Promise that resolves to the value your XPLMBrowserCallback_f returns (parsed as JSON -- see that callback's desc for the contract). Multiple registrations against the same name on the same window overwrite each other. Each window has its own independent xplane.* namespace; functions registered on window A are not callable from window B.

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
name string
function function Callback — a Lua function you define
refcon any Any Lua value; passed through to your callback unchanged
XLuaGetScreenSize()

Returns: {k} with keys: width, height

This routine returns the size of the main X-Plane OpenGL window in pixels. This number can be used to get a rough idea of the amount of detail the user will be able to see when drawing in 3-d.

Output table keys:

Key Type
width number
height number
XLuaGetScreenBoundsGlobal()

Returns: {k} with keys: left, top, right, bottom

This routine returns the bounds of the "global" X-Plane desktop, in boxels. Unlike the non-global version XPLMGetScreenSize(), this is multi-monitor aware. There are three primary consequences of multimonitor awareness. First, if the user is running X-Plane in full-screen on two or more monitors (typically configured using one full-screen window per monitor), the global desktop will be sized to include all X-Plane windows. Second, the origin of the screen coordinates is not guaranteed to be (0, 0). Suppose the user has two displays side-by-side, both running at 1080p. Suppose further that they've configured their OS to make the left display their "primary" monitor, and that X-Plane is running in full-screen on their right monitor only. In this case, the global desktop bounds would be the rectangle from (1920, 0) to (3840, 1080). If the user later asked X-Plane to draw on their primary monitor as well, the bounds would change to (0, 0) to (3840, 1080). Finally, if the usable area of the virtual desktop is not a perfect rectangle (for instance, because the monitors have different resolutions or because one monitor is configured in the operating system to be above and to the right of the other), the global desktop will include any wasted space. Thus, if you have two 1080p monitors, and monitor 2 is configured to have its bottom left touch monitor 1's upper right, your global desktop area would be the rectangle from (0, 0) to (3840, 2160). Note that popped-out windows (windows drawn in their own operating system windows, rather than "floating" within X-Plane) are not included in these bounds.

Output table keys:

Key Type
left number
top number
right number
bottom number
XLuaGetAllMonitorBoundsGlobal(callback, refcon)

Returns: (returns nothing)

This routine immediately calls you back with the bounds (in boxels) of each full-screen X-Plane window within the X-Plane global desktop space. Note that if a monitor is not covered by an X-Plane window, you cannot get its bounds this way. Likewise, monitors with only an X-Plane window (not in full-screen mode) will not be included. If X-Plane is running in full-screen and your monitors are of the same size and configured contiguously in the OS, then the combined global bounds of all full-screen monitors will match the total global desktop bounds, as returned by XPLMGetScreenBoundsGlobal(). (Of course, if X-Plane is running in windowed mode, this will not be the case. Likewise, if you have differently sized monitors, the global desktop space will include wasted space.) Note that this function's monitor indices match those provided by XPLMGetAllMonitorBoundsOS(), but the coordinates are different (since the X-Plane global desktop may not match the operating system's global desktop, and one X-Plane boxel may be larger than one pixel due to 150% or 200% scaling).

Argument Type Notes
monitorBoundsCallback function Callback — a Lua function you define
refcon any Any Lua value; passed through to your callback unchanged
XLuaGetAllMonitorBoundsOS(callback, refcon)

Returns: (returns nothing)

This routine immediately calls you back with the bounds (in pixels) of each monitor within the operating system's global desktop space. Note that unlike XPLMGetAllMonitorBoundsGlobal(), this may include monitors that have no X-Plane window on them. Note that this function's monitor indices match those provided by XPLMGetAllMonitorBoundsGlobal(), but the coordinates are different (since the X-Plane global desktop may not match the operating system's global desktop, and one X-Plane boxel may be larger than one pixel).

Argument Type Notes
monitorBoundsCallback function Callback — a Lua function you define
refcon any Any Lua value; passed through to your callback unchanged
XLuaGetMouseLocationGlobal()

Returns: {k} with keys: x, y

Returns the current mouse location in global desktop boxels. Unlike XPLMGetMouseLocation(), the bottom left of the main X-Plane window is not guaranteed to be (0, 0)---instead, the origin is the lower left of the entire global desktop space. In addition, this routine gives the real mouse location when the mouse goes to X-Plane windows other than the primary display. Thus, it can be used with both pop-out windows and secondary monitors. This is the mouse location function to use with modern windows (i.e., those created by XPLMCreateWindowEx()). Pass NULL to not receive info about either parameter.

Output table keys:

Key Type
x number
y number
XLuaGetWindowGeometry(windowID)

Returns: {k} with keys: left, top, right, bottom

This routine returns the position and size of a window. The units and coordinate system vary depending on the type of window you have. If this is a legacy window (one compiled against a pre-XPLM300 version of the SDK, or an XPLM300 window that was not created using XPLMCreateWindowEx()), the units are pixels relative to the main X-Plane display. If, on the other hand, this is a new X-Plane 11-style window (compiled against the XPLM300 SDK and created using XPLMCreateWindowEx()), the units are global desktop boxels. Pass NULL to not receive any paramter.

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID

Output table keys:

Key Type
left number
top number
right number
bottom number
XLuaSetWindowGeometry(windowID, left, top, right, bottom)

Returns: (returns nothing)

This routine allows you to set the position and size of a window. The units and coordinate system match those of XPLMGetWindowGeometry(). That is, modern windows use global desktop boxel coordinates, while legacy windows use pixels relative to the main X-Plane display. Note that this only applies to "floating" windows (that is, windows that are drawn within the X-Plane simulation windows, rather than being "popped out" into their own first-class operating system windows). To set the position of windows whose positioning mode is xplm_WindowPopOut, you'll need to instead use XPLMSetWindowGeometryOS().

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
left integer
top integer
right integer
bottom integer
XLuaGetWindowGeometryOS(windowID)

Returns: {k} with keys: left, top, right, bottom

This routine returns the position and size of a "popped out" window (i.e., a window whose positioning mode is xplm_WindowPopOut), in operating system pixels. Pass NULL to not receive any parameter.

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID

Output table keys:

Key Type
left number
top number
right number
bottom number
XLuaSetWindowGeometryOS(windowID, left, top, right, bottom)

Returns: (returns nothing)

This routine allows you to set the position and size, in operating system pixel coordinates, of a popped out window (that is, a window whose positioning mode is xplm_WindowPopOut, which exists outside the X-Plane simulation window, in its own first-class operating system window). Note that you are responsible for ensuring both that your window is popped out (using XPLMWindowIsPoppedOut()) and that a monitor really exists at the OS coordinates you provide (using XPLMGetAllMonitorBoundsOS()).

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
left integer
top integer
right integer
bottom integer
XLuaGetWindowGeometryVR(windowID)

Returns: {k} with keys: widthBoxels, heightBoxels

Returns the width and height, in boxels, of a window in VR. Note that you are responsible for ensuring your window is in VR (using XPLMWindowIsInVR()).

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID

Output table keys:

Key Type
widthBoxels number
heightBoxels number
XLuaSetWindowGeometryVR(windowID, widthBoxels, heightBoxels)

Returns: (returns nothing)

This routine allows you to set the size, in boxels, of a window in VR (that is, a window whose positioning mode is xplm_WindowVR). Note that you are responsible for ensuring your window is in VR (using XPLMWindowIsInVR()).

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
widthBoxels integer
heightBoxels integer
XLuaGetWindowIsVisible(windowID)

Returns: boolean

Returns true (1) if the specified window is visible.

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
XLuaSetWindowIsVisible(windowID, isVisible)

Returns: (returns nothing)

This routine shows or hides a window.

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
isVisible boolean
XLuaWindowIsPoppedOut(windowID)

Returns: boolean

True if this window has been popped out (making it a first-class window in the operating system), which in turn is true if and only if you have set the window's positioning mode to xplm_WindowPopOut. Only applies to modern windows. (Windows created using the deprecated XPLMCreateWindow(), or windows compiled against a pre-XPLM300 version of the SDK cannot be popped out.)

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
XLuaWindowIsInVR(windowID)

Returns: boolean

True if this window has been moved to the virtual reality (VR) headset, which in turn is true if and only if you have set the window's positioning mode to xplm_WindowVR. Only applies to modern windows. (Windows created using the deprecated XPLMCreateWindow(), or windows compiled against a pre-XPLM301 version of the SDK cannot be moved to VR.)

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
XLuaSetWindowGravity(windowID, leftGravity, topGravity, rightGravity, bottomGravity)

Returns: (returns nothing)

A window's "gravity" controls how the window shifts as the whole X-Plane window resizes. A gravity of 1 means the window maintains its positioning relative to the right or top edges, 0 the left/bottom, and 0.5 keeps it centered. Default gravity is (0, 1, 0, 1), meaning your window will maintain its position relative to the top left and will not change size as its containing window grows. If you wanted, say, a window that sticks to the top of the screen (with a constant height), but which grows to take the full width of the window, you would pass (0, 1, 1, 1). Because your left and right edges would maintain their positioning relative to their respective edges of the screen, the whole width of your window would change with the X-Plane window. Only applies to modern windows. (Windows created using the deprecated XPLMCreateWindow(), or windows compiled against a pre-XPLM300 version of the SDK will simply get the default gravity.)

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
leftGravity number
topGravity number
rightGravity number
bottomGravity number
XLuaSetWindowResizingLimits(windowID, minWidthBoxels, minHeightBoxels, maxWidthBoxels, maxHeightBoxels)

Returns: (returns nothing)

Sets the minimum and maximum size of the client rectangle of the given window. (That is, it does not include any window styling that you might have asked X-Plane to apply on your behalf.) All resizing operations are constrained to these sizes. Only applies to modern windows. (Windows created using the deprecated XPLMCreateWindow(), or windows compiled against a pre-XPLM300 version of the SDK will have no minimum or maximum size.)

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
minWidthBoxels integer
minHeightBoxels integer
maxWidthBoxels integer
maxHeightBoxels integer
XLuaSetWindowPositioningMode(windowID, positioningMode, monitorIndex)

Returns: (returns nothing)

Sets the policy for how X-Plane will position your window. Some positioning modes apply to a particular monitor. For those modes, you can pass a negative monitor index to position the window on the main X-Plane monitor (the screen with the X-Plane menu bar at the top). Or, if you have a specific monitor you want to position your window on, you can pass a real monitor index as received from, e.g., XPLMGetAllMonitorBoundsOS(). Only applies to modern windows. (Windows created using the deprecated XPLMCreateWindow(), or windows compiled against a pre-XPLM300 version of the SDK will always use xplm_WindowPositionFree.)

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
positioningMode XPLMWindowPositioningMode Enum — use a constant from XPLMWindowPositioningMode
monitorIndex integer
XLuaSetWindowTitle(windowID, windowTitle)

Returns: (returns nothing)

Sets the name for a window. This only applies to windows that opted-in to styling as an X-Plane 11 floating window (i.e., with styling mode xplm_WindowDecorationRoundRectangle) when they were created using XPLMCreateWindowEx().

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
windowTitle string
XLuaGetWindowRefCon(windowID)

Returns: userdata

Returns a window's reference constant, the unique value you can use for your own purposes.

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
XLuaSetWindowRefCon(windowID, refcon)

Returns: (returns nothing)

Sets a window's reference constant. Use this to pass data to yourself in the callbacks.

Argument Type Notes
windowID XPLMWindowID Enum — use a constant from XPLMWindowID
refcon any Any Lua value; passed through to your callback unchanged
XLuaTakeKeyboardFocus(window)

Returns: (returns nothing)

This routine gives a specific window keyboard focus. Keystrokes will be sent to that window. Pass a window ID of 0 to remove keyboard focus from any plugin-created windows and instead pass keyboard strokes directly to X-Plane.

Argument Type Notes
window XPLMWindowID Enum — use a constant from XPLMWindowID
XLuaHasKeyboardFocus(window)

Returns: boolean

Returns true (1) if the indicated window has keyboard focus. Pass a window ID of 0 to see if no plugin window has focus, and all keystrokes will go directly to X-Plane.

Argument Type Notes
window XPLMWindowID Enum — use a constant from XPLMWindowID
XLuaBringWindowToFront(window)

Returns: (returns nothing)

This routine brings the window to the front of the Z-order for its layer. Windows are brought to the front automatically when they are created. Beyond that, you should make sure you are front before handling mouse clicks. Note that this only brings your window to the front of its layer (XPLMWindowLayer). Thus, if you have a window in the floating window layer (xplm_WindowLayerFloatingWindows), but there is a modal window (in layer xplm_WindowLayerModal) above you, you would still not be the true frontmost window after calling this. (After all, the window layers are strictly ordered, and no window in a lower layer can ever be above any window in a higher one.)

Argument Type Notes
window XPLMWindowID Enum — use a constant from XPLMWindowID
XLuaIsWindowInFront(window)

Returns: boolean

This routine returns true if the window you passed in is the frontmost visible window in its layer (XPLMWindowLayer). Thus, if you have a window at the front of the floating window layer (xplm_WindowLayerFloatingWindows), this will return true even if there is a modal window (in layer xplm_WindowLayerModal) above you. (Not to worry, though: in such a case, X-Plane will not pass clicks or keyboard input down to your layer until the window above stops "eating" the input.) Note that legacy windows are always placed in layer xplm_WindowLayerFlightOverlay, while modern-style windows default to xplm_WindowLayerFloatingWindows. This means it's perfectly consistent to have two different plugin-created windows (one legacy, one modern) both be in the front (of their different layers!) at the same time.

Argument Type Notes
window XPLMWindowID Enum — use a constant from XPLMWindowID

Examples

Examples coming soon.