Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSScreen

Inherits from
Package
com.apple.cocoa.application
Companion guide
The Drawing Environment

Overview

An NSScreen object describes the attributes of a computer’s monitor, or screen. An application may use an NSScreen object to retrieve information about a screen and use this information to decide what to display upon that screen. For example, an application may use the deepestScreen method to find out which of the available screens can best represent color and then may choose to display all of its windows on that screen.

The application object should be created before you use the methods in this class, so that the application object can make the necessary connection to the window system. You can make sure the application object exists by invoking NSApplication’s sharedApplication method, which creates it if necessary. If you created your application with Xcode, the application object is automatically created for you during initialization.

Note: NSScreen is for getting information about the available displays only. If you need additional information or want to change the attributes relating to a display, you must use Quartz Services. For more information, see Quartz Display Services Reference.

Tasks

Constructors

Getting NSScreens

Reading Screen Information

Constructors

NSScreen

Throws an exception.

public NSScreen()

Discussion

Use mainScreen instead.

Static Methods

deepestScreen

Returns an NSScreen object representing the screen that can best represent color.

public static NSScreen deepestScreen()

Discussion

This method always returns an object, even if there is only one screen and it is not a color screen.

mainScreen

Returns an NSScreen object representing the main screen.

public static NSScreen mainScreen()

Discussion

The main screen is the screen with the key window. To obtain the menu bar screen use NSScreen.screens().objectAtIndex(0) (after checking that the screens array is not empty).

screens

Returns an array of NSScreen objects representing all of the screens available on the system.

public static NSArray screens()

Discussion

Throws a WindowServerCommunicationException if the screen’s information can’t be obtained from the window system. When the display configuration is changed, ApplicationDidChangeScreenParametersNotification is sent by the default notification center.

The first screen in the screens array is always the “zero” screen. To obtain the menu bar screen use NSScreen.screens().objectAtIndex(0) (after checking that the screens array is not empty).

The array should not be cached, as screens can be dynamically reconfigured, and a display can be added or removed.

Instance Methods

depth

Returns the receiver’s current depth, including whether it can display color.

public int depth()

Discussion

The return value is not directly usable; you must pass it to one of the static methods of the NSGraphics class to obtain concrete values.

See Also

deviceDescription

Returns the device dictionary for the screen.

public NSDictionary deviceDescription()

Discussion

See “Constants” for the list of keys you can use to retrieve values from the returned dictionary.

frame

Returns the dimensions and location of the receiver in an NSRect.

public NSRect frame()

Discussion

This method returns the full screen rectangle at the current resolution and includes any space currently occupied by the menu bar and dock.

See Also

supportedWindowDepths

Returns a zero-terminated array of the window depths supported by the receiver.

public int[] supportedWindowDepths()

userSpaceScaleFactor

Returns the scaling factor from user space to device space on the screen represented by the receiver.

public float userSpaceScaleFactor()

Discussion

This factor is in pixels per point, where a point is always equal to 1/72 of an inch. For example, a scaling factor of 2.0 indicates the display has a resolution of 144 pixels-per-inch.

Availability

visibleFrame

Returns the current location and dimensions of the visible screen.

public NSRect visibleFrame()

Discussion

The returned rectangle represents the portion of the screen in which it is currently safe to draw your application content. This rectangle is always based on the current user-interface settings and does not include the area currently occupied by the dock and menu bar. Because it is based on the current user -interface settings, the returned rectangle can change between calls and should not be cached.

Note: Even when dock hiding is enabled, the rectangle returned by this method may be smaller than the full screen. The system uses a small boundary area to determine when it should display the dock.

See Also

Constants

The following constants are used as keys to retrieve attributes from the display device dictionary.

Constant

Value

NSDeviceBitsPerSample

An NSNumber containing an integer that indicates the current bit depth of each color sample in the device (2-bit, 8-bit, and so on).

NSDeviceColorSpaceName

The device’s current color space name. See the NSGraphics Java class specification or the NSGraphics.h header file for a list of possible values.

NSDeviceIsPrinter

“YES” (a string), if present, indicating the device is a printer.

NSDeviceIsScreen

“YES” (a string), if present, indicating the device is a screen.

NSDeviceResolution

An NSValue that contains an NSSize which indicates the device’s current resolution in dots per inch (dpi).

NSDeviceSize

An NSValue that contains an NSSize which indicates the device’s current size in points.

@"NSScreenNumber"

An NSNumber that contains the CGDirectDisplayID for the screen device. This key is only valid for the device description dictionary for an NSScreen.



Next Page > Hide TOC


© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-01)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.