/**
* This method generates a dictionary containing information * about the screen device. The resulting dictionary will have the following * entires: NSScreenNumber, NSDeviceSize, NSDeviceResolution, NSDeviceBitsPerSample, * NSDeviceColorSpaceName. *
*/ - (NSDictionary*) deviceDescription { if (_reserved == 0) { NSMutableDictionary *devDesc; int bps = 0; NSSize screenResolution; NSString *colorSpaceName = nil; CGFloat scaleFactor; /* * This method generates a dictionary from the * information we have gathered from the screen. */ // Set the screen number in the current object. devDesc = [[NSMutableDictionary alloc] initWithCapacity: 8]; [devDesc setObject: [NSNumber numberWithInt: _screenNumber] forKey: @"NSScreenNumber"]; // This is assumed since we are in NSScreen. [devDesc setObject: @"YES" forKey: NSDeviceIsScreen]; // Add the NSDeviceSize dictionary item [devDesc setObject: [NSValue valueWithSize: _frame.size] forKey: NSDeviceSize]; // Add the NSDeviceResolution dictionary item scaleFactor = [self userSpaceScaleFactor]; screenResolution = NSMakeSize(72.0 * scaleFactor, 72.0 * scaleFactor); [devDesc setObject: [NSValue valueWithSize: screenResolution] forKey: NSDeviceResolution]; // Add the bits per sample entry bps = NSBitsPerSampleFromDepth(_depth); [devDesc setObject: [NSNumber numberWithInt: bps] forKey: NSDeviceBitsPerSample]; // Add the color space entry. colorSpaceName = NSColorSpaceFromDepth(_depth); [devDesc setObject: colorSpaceName forKey: NSDeviceColorSpaceName]; _reserved = (void*)[devDesc copy]; RELEASE(devDesc); } return (NSDictionary*)_reserved; } // Mac OS X methods /** * Returns the window depths this screen will support. */ - (const NSWindowDepth*) supportedWindowDepths { // If the variable isn't initialized, get the info and // store it for the future. if (_supportedWindowDepths == NULL) { _supportedWindowDepths = (NSWindowDepth*)[GSCurrentServer() availableDepthsForScreen: _screenNumber]; // Check the results if (_supportedWindowDepths == NULL) { NSLog(@"Internal error: no depth list returned from window server."); return NULL; } } return _supportedWindowDepths; } /** * Returns the NSRect representing the visible area of the screen. */ - (NSRect) visibleFrame { NSRect visFrame = _frame; float menuHeight; switch (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil)) { case NSMacintoshInterfaceStyle: if ([NSApp mainMenu] == nil) { // No menu yet ... assume a standard height menuHeight = [NSMenuView menuBarHeight]; } else { menuHeight = [[[NSApp mainMenu] window] frame].size.height; } visFrame.size.height -= menuHeight; break; case GSWindowMakerInterfaceStyle: case NSNextStepInterfaceStyle: /* FIXME: Menu width will vary from app to app and there is no * fixed position for the menu ... should we be making room for * a menu top left, or something else? */ #if 0 if ([NSApp mainMenu] != nil) { float menuWidth = [[[NSApp mainMenu] window] frame].size.width; visFrame.size.width -= menuWidth; visFrame.origin.x += menuWidth; } #endif break; default: break; } return visFrame; } /** Returns the screen number */ - (int) screenNumber { return _screenNumber; } // Release the memory for the depths array. - (void) dealloc { // _supportedWindowDepths can be NULL since it may or may not // be necessary to get this info. The most common use of NSScreen // is to get the depth and frame attributes. if (_supportedWindowDepths != NULL) { NSZoneFree(NSDefaultMallocZone(), _supportedWindowDepths); } if (_reserved != 0) { [(id)_reserved release]; } [super dealloc]; } - (CGFloat) userSpaceScaleFactor { NSNumber *factor = [[NSUserDefaults standardUserDefaults] objectForKey: @"GSScaleFactor"]; if (factor != nil) { return [factor floatValue]; } else { GSDisplayServer *srv = GSCurrentServer(); if (srv != nil) { NSSize dpi = [GSCurrentServer() resolutionForScreen: _screenNumber]; // average the width and height return (dpi.width + dpi.height) / 144.0; } else { return 1.0; } } } - (CGFloat) backingScaleFactor { return 1.0; } @end