JUCE
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Desktop Class Reference

Describes and controls aspects of the computer's desktop. More...

Inheritance diagram for Desktop:

Public Types

enum  DisplayOrientation {
  upright = 1, upsideDown = 2, rotatedClockwise = 4, rotatedAntiClockwise = 8,
  allOrientations = 1 + 2 + 4 + 8
}
 In a tablet/mobile device which can be turned around, this is used to indicate the orientation. More...
 

Public Member Functions

int getMouseButtonClickCounter () const noexcept
 Returns the number of times the mouse button has been clicked since the app started. More...
 
int getMouseWheelMoveCounter () const noexcept
 Returns the number of times the mouse wheel has been moved since the app started. More...
 
void addGlobalMouseListener (MouseListener *listener)
 Registers a MouseListener that will receive all mouse events that occur on any component. More...
 
void removeGlobalMouseListener (MouseListener *listener)
 Unregisters a MouseListener that was added with the addGlobalMouseListener() method. More...
 
void addFocusChangeListener (FocusChangeListener *listener)
 Registers a MouseListener that will receive a callback whenever the focused component changes. More...
 
void removeFocusChangeListener (FocusChangeListener *listener)
 Unregisters a listener that was added with addFocusChangeListener(). More...
 
void setKioskModeComponent (Component *componentToUse, bool allowMenusAndBars=true)
 Takes a component and makes it full-screen, removing the taskbar, dock, etc. More...
 
ComponentgetKioskModeComponent () const noexcept
 Returns the component that is currently being used in kiosk-mode. More...
 
int getNumComponents () const noexcept
 Returns the number of components that are currently active as top-level desktop windows. More...
 
ComponentgetComponent (int index) const noexcept
 Returns one of the top-level desktop window components. More...
 
ComponentfindComponentAt (Point< int > screenPosition) const
 Finds the component at a given screen location. More...
 
ComponentAnimatorgetAnimator () noexcept
 The Desktop object has a ComponentAnimator instance which can be used for performing your animations. More...
 
LookAndFeelgetDefaultLookAndFeel () noexcept
 Returns the current default look-and-feel for components which don't have one explicitly set. More...
 
void setDefaultLookAndFeel (LookAndFeel *newDefaultLookAndFeel)
 Changes the default look-and-feel. More...
 
const Array< MouseInputSource > & getMouseSources () const noexcept
 Provides access to the array of mouse sources, for iteration. More...
 
int getNumMouseSources () const noexcept
 Returns the number of MouseInputSource objects the system has at its disposal. More...
 
MouseInputSourcegetMouseSource (int index) const noexcept
 Returns one of the system's MouseInputSource objects. More...
 
MouseInputSource getMainMouseSource () const noexcept
 Returns the main mouse input device that the system is using. More...
 
int getNumDraggingMouseSources () const noexcept
 Returns the number of mouse-sources that are currently being dragged. More...
 
MouseInputSourcegetDraggingMouseSource (int index) const noexcept
 Returns one of the mouse sources that's currently being dragged. More...
 
void beginDragAutoRepeat (int millisecondsBetweenCallbacks)
 Ensures that a non-stop stream of mouse-drag events will be sent during the current mouse-drag operation. More...
 
DisplayOrientation getCurrentOrientation () const
 In a tablet device which can be turned around, this returns the current orientation. More...
 
void setOrientationsEnabled (int allowedOrientations)
 Sets which orientations the display is allowed to auto-rotate to. More...
 
int getOrientationsEnabled () const noexcept
 Returns the set of orientations the display is allowed to rotate to. More...
 
bool isOrientationEnabled (DisplayOrientation orientation) const noexcept
 Returns whether the display is allowed to auto-rotate to the given orientation. More...
 
const DisplaysgetDisplays () const noexcept
 
void setGlobalScaleFactor (float newScaleFactor) noexcept
 Sets a global scale factor to be used for all desktop windows. More...
 
float getGlobalScaleFactor () const noexcept
 Returns the current global scale factor, as set by setGlobalScaleFactor(). More...
 

Static Public Member Functions

static Desktop &JUCE_CALLTYPE getInstance ()
 There's only one desktop object, and this method will return it. More...
 
static Point< intgetMousePosition ()
 Returns the mouse position. More...
 
static void setMousePosition (Point< int > newPosition)
 Makes the mouse pointer jump to a given location. More...
 
static Point< intgetLastMouseDownPosition ()
 Returns the last position at which a mouse button was pressed. More...
 
static void setScreenSaverEnabled (bool isEnabled)
 This lets you prevent the screensaver from becoming active. More...
 
static bool isScreenSaverEnabled ()
 Returns true if the screensaver has not been turned off. More...
 
static bool canUseSemiTransparentWindows () noexcept
 True if the OS supports semitransparent windows. More...
 
static bool isOSXDarkModeActive ()
 OSX-specific function to check for the "dark" title-bar and menu mode. More...
 

Detailed Description

Describes and controls aspects of the computer's desktop.

Member Enumeration Documentation

◆ DisplayOrientation

In a tablet/mobile device which can be turned around, this is used to indicate the orientation.

Enumerator
upright 

Indicates that the device is the normal way up.

upsideDown 

Indicates that the device is upside-down.

rotatedClockwise 

Indicates that the device is turned 90 degrees clockwise from its upright position.

rotatedAntiClockwise 

Indicates that the device is turned 90 degrees anti-clockwise from its upright position.

allOrientations 

A combination of all the orientation values.

Member Function Documentation

◆ getInstance()

static Desktop& JUCE_CALLTYPE Desktop::getInstance ( )
static

There's only one desktop object, and this method will return it.

Referenced by StandalonePluginHolder::getInstance().

◆ getMousePosition()

static Point<int> Desktop::getMousePosition ( )
static

Returns the mouse position.

The coordinates are relative to the top-left of the main monitor.

Note that this is just a shortcut for calling getMainMouseSource().getScreenPosition(), and you should only resort to grabbing the global mouse position if there's really no way to get the coordinates via a mouse event callback instead.

◆ setMousePosition()

static void Desktop::setMousePosition ( Point< int newPosition)
static

Makes the mouse pointer jump to a given location.

The coordinates are relative to the top-left of the main monitor. Note that this is a pretty old method, kept around mainly for backwards-compatibility, and you should use the MouseInputSource class directly in new code.

◆ getLastMouseDownPosition()

static Point<int> Desktop::getLastMouseDownPosition ( )
static

Returns the last position at which a mouse button was pressed.

Note that this is just a shortcut for calling getMainMouseSource().getLastMouseDownPosition(), and in a multi-touch environment, it doesn't make much sense. ALWAYS prefer to get this information via other means, such as MouseEvent::getMouseDownScreenPosition() if possible, and only ever call this as a last resort.

◆ getMouseButtonClickCounter()

int Desktop::getMouseButtonClickCounter ( ) const
noexcept

Returns the number of times the mouse button has been clicked since the app started.

Each mouse-down event increments this number by 1.

See also
getMouseWheelMoveCounter

◆ getMouseWheelMoveCounter()

int Desktop::getMouseWheelMoveCounter ( ) const
noexcept

Returns the number of times the mouse wheel has been moved since the app started.

Each mouse-wheel event increments this number by 1.

See also
getMouseButtonClickCounter

◆ setScreenSaverEnabled()

static void Desktop::setScreenSaverEnabled ( bool  isEnabled)
static

This lets you prevent the screensaver from becoming active.

Handy if you're running some sort of presentation app where having a screensaver appear would be annoying.

Pass false to disable the screensaver, and true to re-enable it. (Note that this won't enable a screensaver unless the user has actually set one up).

The disablement will only happen while the JUCE application is the foreground process - if another task is running in front of it, then the screensaver will be unaffected.

See also
isScreenSaverEnabled

◆ isScreenSaverEnabled()

static bool Desktop::isScreenSaverEnabled ( )
static

Returns true if the screensaver has not been turned off.

This will return the last value passed into setScreenSaverEnabled(). Note that it won't tell you whether the user is actually using a screen saver, just whether this app is deliberately preventing one from running.

See also
setScreenSaverEnabled

◆ addGlobalMouseListener()

void Desktop::addGlobalMouseListener ( MouseListener listener)

Registers a MouseListener that will receive all mouse events that occur on any component.

See also
removeGlobalMouseListener

◆ removeGlobalMouseListener()

void Desktop::removeGlobalMouseListener ( MouseListener listener)

Unregisters a MouseListener that was added with the addGlobalMouseListener() method.

See also
addGlobalMouseListener

◆ addFocusChangeListener()

void Desktop::addFocusChangeListener ( FocusChangeListener listener)

Registers a MouseListener that will receive a callback whenever the focused component changes.

◆ removeFocusChangeListener()

void Desktop::removeFocusChangeListener ( FocusChangeListener listener)

Unregisters a listener that was added with addFocusChangeListener().

◆ setKioskModeComponent()

void Desktop::setKioskModeComponent ( Component componentToUse,
bool  allowMenusAndBars = true 
)

Takes a component and makes it full-screen, removing the taskbar, dock, etc.

The component must already be on the desktop for this method to work. It will be resized to completely fill the screen and any extraneous taskbars, menu bars, etc will be hidden.

To exit kiosk mode, just call setKioskModeComponent (nullptr). When this is called, the component that's currently being used will be resized back to the size and position it was in before being put into this mode.

If allowMenusAndBars is true, things like the menu and dock (on mac) are still allowed to pop up when the mouse moves onto them. If this is false, it'll try to hide as much on-screen paraphernalia as possible.

◆ getKioskModeComponent()

Component* Desktop::getKioskModeComponent ( ) const
noexcept

Returns the component that is currently being used in kiosk-mode.

This is the component that was last set by setKioskModeComponent(). If none has been set, this returns nullptr.

◆ getNumComponents()

int Desktop::getNumComponents ( ) const
noexcept

Returns the number of components that are currently active as top-level desktop windows.

See also
getComponent, Component::addToDesktop

◆ getComponent()

Component* Desktop::getComponent ( int  index) const
noexcept

Returns one of the top-level desktop window components.

The index is from 0 to getNumComponents() - 1. This could return 0 if the index is out-of-range.

See also
getNumComponents, Component::addToDesktop

◆ findComponentAt()

Component* Desktop::findComponentAt ( Point< int screenPosition) const

Finds the component at a given screen location.

This will drill down into top-level windows to find the child component at the given position.

Returns nullptr if the coordinates are inside a non-JUCE window.

◆ getAnimator()

ComponentAnimator& Desktop::getAnimator ( )
noexcept

The Desktop object has a ComponentAnimator instance which can be used for performing your animations.

Having a single shared ComponentAnimator object makes it more efficient when multiple components are being moved around simultaneously. It's also more convenient than having to manage your own instance of one.

See also
ComponentAnimator

◆ getDefaultLookAndFeel()

LookAndFeel& Desktop::getDefaultLookAndFeel ( )
noexcept

Returns the current default look-and-feel for components which don't have one explicitly set.

See also
setDefaultLookAndFeel

◆ setDefaultLookAndFeel()

void Desktop::setDefaultLookAndFeel ( LookAndFeel newDefaultLookAndFeel)

Changes the default look-and-feel.

Parameters
newDefaultLookAndFeelthe new look-and-feel object to use - if this is set to nullptr, it will revert to using the system's default one. The object passed-in must be deleted by the caller when it's no longer needed.
See also
getDefaultLookAndFeel

◆ getMouseSources()

const Array<MouseInputSource>& Desktop::getMouseSources ( ) const
noexcept

Provides access to the array of mouse sources, for iteration.

In a traditional single-mouse system, there might be only one MouseInputSource. On a multi-touch system, there could be one input source per potential finger. The number of mouse sources returned here may increase dynamically as the program runs. To find out how many mouse events are currently happening, use getNumDraggingMouseSources().

◆ getNumMouseSources()

int Desktop::getNumMouseSources ( ) const
noexcept

Returns the number of MouseInputSource objects the system has at its disposal.

In a traditional single-mouse system, there might be only one MouseInputSource. On a multi-touch system, there could be one input source per potential finger. The number of mouse sources returned here may increase dynamically as the program runs. To find out how many mouse events are currently happening, use getNumDraggingMouseSources().

See also
getMouseSource

◆ getMouseSource()

MouseInputSource* Desktop::getMouseSource ( int  index) const
noexcept

Returns one of the system's MouseInputSource objects.

The index should be from 0 to getNumMouseSources() - 1. Out-of-range indexes will return a null pointer. In a traditional single-mouse system, there might be only one object. On a multi-touch system, there could be one input source per potential finger.

◆ getMainMouseSource()

MouseInputSource Desktop::getMainMouseSource ( ) const
noexcept

Returns the main mouse input device that the system is using.

See also
getNumMouseSources()

◆ getNumDraggingMouseSources()

int Desktop::getNumDraggingMouseSources ( ) const
noexcept

Returns the number of mouse-sources that are currently being dragged.

In a traditional single-mouse system, this will be 0 or 1, depending on whether a JUCE component has the button down on it. In a multi-touch system, this could be any number from 0 to the number of simultaneous touches that can be detected.

◆ getDraggingMouseSource()

MouseInputSource* Desktop::getDraggingMouseSource ( int  index) const
noexcept

Returns one of the mouse sources that's currently being dragged.

The index should be between 0 and getNumDraggingMouseSources() - 1. If the index is out of range, or if no mice or fingers are down, this will return a null pointer.

◆ beginDragAutoRepeat()

void Desktop::beginDragAutoRepeat ( int  millisecondsBetweenCallbacks)

Ensures that a non-stop stream of mouse-drag events will be sent during the current mouse-drag operation.

This allows you to make sure that mouseDrag() events are sent continuously, even when the mouse isn't moving. This can be useful for things like auto-scrolling components when the mouse is near an edge.

Call this method during a mouseDown() or mouseDrag() callback, specifying the minimum interval between consecutive mouse drag callbacks. The callbacks will continue until the mouse is released, and then the interval will be reset, so you need to make sure it's called every time you begin a drag event. Passing an interval of 0 or less will cancel the auto-repeat.

See also
mouseDrag

◆ getCurrentOrientation()

DisplayOrientation Desktop::getCurrentOrientation ( ) const

In a tablet device which can be turned around, this returns the current orientation.

◆ setOrientationsEnabled()

void Desktop::setOrientationsEnabled ( int  allowedOrientations)

Sets which orientations the display is allowed to auto-rotate to.

For devices that support rotating desktops, this lets you specify which of the orientations your app can use.

The parameter is a bitwise or-ed combination of the values in DisplayOrientation, and must contain at least one set bit.

◆ getOrientationsEnabled()

int Desktop::getOrientationsEnabled ( ) const
noexcept

Returns the set of orientations the display is allowed to rotate to.

See also
setOrientationsEnabled

◆ isOrientationEnabled()

bool Desktop::isOrientationEnabled ( DisplayOrientation  orientation) const
noexcept

Returns whether the display is allowed to auto-rotate to the given orientation.

Each orientation can be enabled using setOrientationEnabled(). By default, all orientations are allowed.

◆ getDisplays()

const Displays& Desktop::getDisplays ( ) const
noexcept

◆ setGlobalScaleFactor()

void Desktop::setGlobalScaleFactor ( float  newScaleFactor)
noexcept

Sets a global scale factor to be used for all desktop windows.

Setting this will also scale the monitor sizes that are returned by getDisplays().

◆ getGlobalScaleFactor()

float Desktop::getGlobalScaleFactor ( ) const
noexcept

Returns the current global scale factor, as set by setGlobalScaleFactor().

See also
setGlobalScaleFactor

◆ canUseSemiTransparentWindows()

static bool Desktop::canUseSemiTransparentWindows ( )
staticnoexcept

True if the OS supports semitransparent windows.

◆ isOSXDarkModeActive()

static bool Desktop::isOSXDarkModeActive ( )
static

OSX-specific function to check for the "dark" title-bar and menu mode.


The documentation for this class was generated from the following file: