Class Desktop
The desktop a windowed application runs on: the monitors attached to it and the
Window instances open on them.
This sits alongside Display rather than replacing any of it. Display answers
"how big is the application's main surface", which is the only question a phone
has; Desktop answers "what screens exist and what windows are open", which only
a windowing system can answer.
Every method degrades safely on a platform with no windowing system:
#getWindows() returns an empty array, #getMonitors() returns a single monitor
describing the main display, and #getFocusedWindow() returns null. Only
constructing a Window throws.
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a listener notified when a monitor is attached, removed or reconfigured.voidAdds a listener notified when any window is shown, hidden, moved or resized.Returns the union of every monitor's bounds.Returns the window that currently holds keyboard focus.static DesktopReturns the singleton instance.getMonitorAt(int x, int y) Returns the monitor containing the given desktop coordinate.getMonitorFor(TopLevelContainer topLevel) Returns the monitor a top level is currently displayed on.Monitor[]Returns every monitor attached to the desktop.Returns the monitor the platform treats as the origin of the desktop.Returns the native window peer owning the given component, or null when it belongs to the application's main surface.Window[]Returns every window currently open, not counting the application's main form.static booleanIndicates whether this platform has a windowing system, and therefore whetherWindowcan be used at all.booleanisWindowInputBlocked(int windowId) Whether input aimed at the given window is currently blocked by a modal.voidNotifies Codename One that the set of attached monitors changed.voidRemoves a previously added monitor listener.voidRemoves a previously added window listener.voidwindowActivationFailed(int windowId) Notifies Codename One that the platform refused to create a window's native surface, so the window will never appear.windowById(int windowId) Returns the window carrying the given framework assigned id, which is how an event that arrived off the event dispatch thread is routed back to its tree.voidwindowClosedNatively(int windowId) Notifies Codename One that the platform has already destroyed a window's native surface, so the window is gone whatever the application would prefer.voidwindowCloseRequested(int windowId) Notifies Codename One that the user activated a native window's close control.com.codename1.impl.PointerDragActivationwindowDragActivation(int windowId) The drag-activation filter belonging to one window, which the implementation applies to that window's pointer moves.intwindowDragRegionStatus(int windowId, int x, int y) Indicates whether input aimed at the given window is currently blocked by a modal window above it.voidwindowFocusChanged(int windowId, boolean gained) Notifies Codename One that a native window gained or lost keyboard focus.intwindowHeight(int windowId) The height of one of the additional native windows, or 0 when there is no such window.voidwindowHideNotify(int windowId) Notifies Codename One that a native window stopped being visible.voidwindowKeyPressed(int windowId, int keyCode) Pushes a key press event aimed at one native window into Codename One.voidwindowKeyReleased(int windowId, int keyCode) Pushes a key release aimed at one native window into Codename One.voidwindowMagnifyGesture(int windowId, int x, int y, float scale) Dispatches a magnify (pinch) gesture that arrived over a native window.voidwindowMonitorChanged(int windowId) Notifies Codename One that a native window moved to a monitor with different characteristics, so that its scale and layout are recomputed.booleanwindowMouseWheelEvent(int windowId, int x, int y, int scrollX, int scrollY, boolean precise, int modifiers) Dispatches a wheel event that arrived over a native window.voidwindowMoved(int windowId) Notifies Codename One that the user moved a native window.voidwindowPointerDragged(int windowId, int[] x, int[] y) Pushes a pointer drag aimed at one native window into Codename One.voidwindowPointerHover(int windowId, int[] x, int[] y) Pushes a pointer hover event that arrived over a specific native window.voidwindowPointerHoverPressed(int windowId, int[] x, int[] y) Pushes a hover press aimed at one native window into Codename One.voidwindowPointerHoverReleased(int windowId, int[] x, int[] y) Pushes a hover release aimed at one native window into Codename One.voidwindowPointerPressed(int windowId, int[] x, int[] y) Pushes a pointer press aimed at one native window into Codename One.voidwindowPointerReleased(int windowId, int[] x, int[] y) Pushes a pointer release aimed at one native window into Codename One.voidwindowRotationGesture(int windowId, int x, int y, float radians) Dispatches a rotation (twist) gesture that arrived over a native window.voidwindowShowNotify(int windowId) Notifies Codename One that a native window became visible.voidwindowSizeChanged(int windowId, int w, int h) Notifies Codename One that a native window changed size.intwindowWidth(int windowId) The width of one of the additional native windows, or 0 when there is no such window.
-
Method Details
-
getInstance
Returns the singleton instance.
Returns
the desktop instance
-
isSupported
public static boolean isSupported()Indicates whether this platform has a windowing system, and therefore whether
Windowcan be used at all.Returns
true if additional native windows can be opened
-
getMonitors
Returns every monitor attached to the desktop.
On a platform with no windowing system this reports a single monitor covering the main display, so layout code that positions against a monitor works everywhere.
Returns
the monitors, never empty and never null
-
getPrimaryMonitor
Returns the monitor the platform treats as the origin of the desktop.
Returns
the primary monitor
-
getMonitorAt
Returns the monitor containing the given desktop coordinate.
Parameters
-
x: the x coordinate in desktop space -
y: the y coordinate in desktop space
Returns
the monitor containing that point, or the primary monitor when none does
-
-
getMonitorFor
Returns the monitor a top level is currently displayed on.
Parameters
topLevel: the form or window to locate
Returns
the monitor it sits on, or the primary monitor when that cannot be determined
-
getDesktopBounds
Returns the union of every monitor's bounds.
Returns
the whole desktop area
-
getWindows
Returns every window currently open, not counting the application's main form.
Returns
the open windows, empty when there are none or the platform has no windows
-
getFocusedWindow
Returns the window that currently holds keyboard focus.
Returns
the focused window, or null when the main form has focus or none is open
-
addMonitorListener
Adds a listener notified when a monitor is attached, removed or reconfigured.
Parameters
l: the listener to add
-
removeMonitorListener
Removes a previously added monitor listener.
Parameters
l: the listener to remove
-
addWindowListener
Adds a listener notified when any window is shown, hidden, moved or resized.
This is the multi-window counterpart of
Display#addWindowListener(com.codename1.ui.events.ActionListener), which continues to report only the application's main window.Parameters
l: the listener to add
-
removeWindowListener
Removes a previously added window listener.
Parameters
l: the listener to remove
-
windowById
Returns the window carrying the given framework assigned id, which is how an event that arrived off the event dispatch thread is routed back to its tree.
Parameters
windowId: the id fromWindow#getWindowId()
Returns
the matching window, or null when none is open with that id
-
isWindowInputBlocked
public boolean isWindowInputBlocked(int windowId) Whether input aimed at the given window is currently blocked by a modal.
Public because the implementation needs it: a wheel gesture is played as four steps queued on the event dispatch thread, and a listener can show a modal between the first check and the last step.
Parameters
windowId: the id the port was given when the window was created
Returns
true when input to that window is currently blocked
-
windowShowNotify
public void windowShowNotify(int windowId) Notifies Codename One that a native window became visible.
Parameters
windowId: the id the port was given when the window was created
-
windowHideNotify
public void windowHideNotify(int windowId) Notifies Codename One that a native window stopped being visible.
Parameters
windowId: the id the port was given when the window was created
-
windowFocusChanged
public void windowFocusChanged(int windowId, boolean gained) Notifies Codename One that a native window gained or lost keyboard focus. Marshalled onto the event dispatch thread, since it runs application code.
Parameters
-
windowId: the id the port was given when the window was created -
gained: true when the window gained focus
-
-
windowCloseRequested
public void windowCloseRequested(int windowId) Notifies Codename One that the user activated a native window's close control. Marshalled onto the event dispatch thread, since it runs application code and may dispose the window.
Parameters
windowId: the id the port was given when the window was created
-
windowClosedNatively
public void windowClosedNatively(int windowId) Notifies Codename One that the platform has already destroyed a window's native surface, so the window is gone whatever the application would prefer.
Distinct from
#windowCloseRequested(int), which asks. Some platforms do not offer the close control as a question: a Mac Catalyst scene is disconnected after the fact, with nothing left to veto. Reporting that as a request would letDO_NOTHING_ON_CLOSEleave a registered window painting into a surface that no longer exists, so it is reported as what it is and the window is disposed.Parameters
windowId: the id the port was given when the window was created
-
windowActivationFailed
public void windowActivationFailed(int windowId) Notifies Codename One that the platform refused to create a window's native surface, so the window will never appear.
Separate from
#windowHideNotify(int)because that one means "minimized", which keeps a modal window's registration: a modal that never appeared would otherwise block input to every other window whileshowModal()waited for it.Parameters
windowId: the window whose native surface could not be created
-
windowMoved
public void windowMoved(int windowId) Notifies Codename One that the user moved a native window.
Separate from
#windowMonitorChanged(int), which is only for a move that carried the window onto a different display: an ordinary move within one monitor still has to reach the listeners, or nothing can persist a window's position.Parameters
windowId: the id the port was given when the window was created
-
windowMonitorChanged
public void windowMonitorChanged(int windowId) Notifies Codename One that a native window moved to a monitor with different characteristics, so that its scale and layout are recomputed.
Parameters
windowId: the id the port was given when the window was created
-
windowSizeChanged
public void windowSizeChanged(int windowId, int w, int h) Notifies Codename One that a native window changed size. Invoked by the implementation.
Parameters
-
windowId: the id the port was given when the window was created -
w: the new drawable width -
h: the new drawable height
-
-
monitorsChanged
public void monitorsChanged()Notifies Codename One that the set of attached monitors changed. -
windowDragRegionStatus
public int windowDragRegionStatus(int windowId, int x, int y) Indicates whether input aimed at the given window is currently blocked by a modal window above it. The drag-region status at a point inside one of the additional native windows, used by the implementation's drag activation filter.
Parameters
-
windowId: the window to ask -
x: x in the window's coordinates -
y: y in the window's coordinates
Returns
the drag region status, or
Component#DRAG_REGION_NOT_DRAGGABLEwhen there is no such window -
-
windowWidth
public int windowWidth(int windowId) The width of one of the additional native windows, or 0 when there is no such window.
Parameters
windowId: the window to ask
Returns
the window's width in Codename One coordinates
-
windowHeight
public int windowHeight(int windowId) The height of one of the additional native windows, or 0 when there is no such window.
Parameters
windowId: the window to ask
Returns
the window's height in Codename One coordinates
-
windowKeyPressed
public void windowKeyPressed(int windowId, int keyCode) Pushes a key press event aimed at one native window into Codename One. Invoked by the implementation, off the event dispatch thread.
Parameters
-
windowId: the id the port was given when the window was created -
keyCode: keycode of the key event
-
-
windowKeyReleased
public void windowKeyReleased(int windowId, int keyCode) Pushes a key release aimed at one native window into Codename One. Invoked by the implementation, off the event dispatch thread.
Parameters
-
windowId: the id the port was given when the window was created -
keyCode: keycode of the key event
-
-
windowPointerHoverPressed
public void windowPointerHoverPressed(int windowId, int[] x, int[] y) Pushes a hover press aimed at one native window into Codename One. Invoked by the implementation, off the event dispatch thread.
Parameters
-
windowId: the id the port was given when the window was created -
x: the x position of the pointer, in window coordinates -
y: the y position of the pointer, in window coordinates
-
-
windowPointerHoverReleased
public void windowPointerHoverReleased(int windowId, int[] x, int[] y) Pushes a hover release aimed at one native window into Codename One. Invoked by the implementation, off the event dispatch thread.
Parameters
-
windowId: the id the port was given when the window was created -
x: the x position of the pointer, in window coordinates -
y: the y position of the pointer, in window coordinates
-
-
windowMouseWheelEvent
public boolean windowMouseWheelEvent(int windowId, int x, int y, int scrollX, int scrollY, boolean precise, int modifiers) Dispatches a wheel event that arrived over a native window.
A port with desktop windows has to route the wheel explicitly: the main surface version resolves the component from the current form, so a wheel over a second window would either do nothing or scroll the main form instead.
Parameters
-
windowId: the id the port was given when the window was created, or 0 for the application's main surface -
x: the pointer x position in window pixels -
y: the pointer y position in window pixels -
scrollX: the horizontal scroll amount in display pixels -
scrollY: the vertical scroll amount in display pixels -
precise: true if the deltas come from a high resolution device such as a trackpad -
modifiers: bitmask of the held keyboard modifiers
Returns
true if a listener consumed the wheel event
-
-
windowMagnifyGesture
public void windowMagnifyGesture(int windowId, int x, int y, float scale) Dispatches a magnify (pinch) gesture that arrived over a native window. Window 0 is the application's main surface.
Parameters
-
windowId: the id the port was given when the window was created -
x: the gesture x position in pixels, relative to that window -
y: the gesture y position in pixels, relative to that window -
scale: the magnification scale, larger than 1 zooms in and smaller than 1 zooms out
-
-
windowRotationGesture
public void windowRotationGesture(int windowId, int x, int y, float radians) Dispatches a rotation (twist) gesture that arrived over a native window. Window 0 is the application's main surface.
Parameters
-
windowId: the id the port was given when the window was created -
x: the gesture x position in pixels, relative to that window -
y: the gesture y position in pixels, relative to that window -
radians: the incremental rotation in radians, positive is clockwise
-
-
windowDragActivation
public com.codename1.impl.PointerDragActivation windowDragActivation(int windowId) The drag-activation filter belonging to one window, which the implementation applies to that window's pointer moves.
Parameters
windowId: the id the port was given when the window was created
Returns
the window's filter, or null when no window holds that id
-
getWindowPeerForComponent
Returns the native window peer owning the given component, or null when it belongs to the application's main surface. Ports use this to place native peers and native text editors into the correct window.
It lives here rather than on
Displaybecause this class owns the windows;Displayanswers for the application's single main surface and knowing which window a component is in is not a question about that surface.Parameters
cmp: the component to locate
Returns
the owning window's native peer, or null for the main surface
-
windowPointerDragged
public void windowPointerDragged(int windowId, int[] x, int[] y) Pushes a pointer drag aimed at one native window into Codename One. Invoked by the implementation, off the event dispatch thread.
Parameters
-
windowId: the id the port was given when the window was created -
x: the x positions of the pointer -
y: the y positions of the pointer
-
-
windowPointerHover
public void windowPointerHover(int windowId, int[] x, int[] y) Pushes a pointer hover event that arrived over a specific native window.
A port with desktop windows has to say which window the pointer was over, or hovering a second window sends the event to whatever the main form has at the same coordinates -- so the window gets no tooltips and the main form gets spurious ones.
Parameters
-
windowId: the id the port was given when the window was created -
x: the x position of the pointer, in window coordinates -
y: the y position of the pointer, in window coordinates
-
-
windowPointerPressed
public void windowPointerPressed(int windowId, int[] x, int[] y) Pushes a pointer press aimed at one native window into Codename One. Invoked by the implementation, off the event dispatch thread.
Parameters
-
windowId: the id the port was given when the window was created -
x: the x positions of the pointer -
y: the y positions of the pointer
-
-
windowPointerReleased
public void windowPointerReleased(int windowId, int[] x, int[] y) Pushes a pointer release aimed at one native window into Codename One. Invoked by the implementation, off the event dispatch thread.
Parameters
-
windowId: the id the port was given when the window was created -
x: the x positions of the pointer -
y: the y positions of the pointer
-
-