From 7cf5df31ea517c6dacb9456d7aee28c648c7e045 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Thu, 4 May 2000 18:28:00 +0000 Subject: [PATCH] NSScreen fixes git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6560 72102866-910b-0410-8b05-ffd578937521 --- Headers/gnustep/gui/NSGraphics.h | 3 +- Headers/gnustep/gui/NSScreen.h | 4 +- Source/NSScreen.m | 71 +++++++++++++++++++++++++------- 3 files changed, 58 insertions(+), 20 deletions(-) diff --git a/Headers/gnustep/gui/NSGraphics.h b/Headers/gnustep/gui/NSGraphics.h index dcfeea344..80f0f89b1 100644 --- a/Headers/gnustep/gui/NSGraphics.h +++ b/Headers/gnustep/gui/NSGraphics.h @@ -30,6 +30,7 @@ @class NSString; @class NSColor; +@class NSGraphicsContext; /* * Colorspace Names @@ -119,8 +120,6 @@ int NSBitsPerSampleFromDepth(NSWindowDepth depth); NSString *NSColorSpaceFromDepth(NSWindowDepth depth); int NSNumberOfColorComponents(NSString *colorSpaceName); BOOL NSPlanarFromDepth(NSWindowDepth depth); -NSWindowDepth GSWindowDepthForScreen(int screen); -const NSWindowDepth *GSAvailableDepthsForScreen(int screen); /* * Read the Color at a Screen Position diff --git a/Headers/gnustep/gui/NSScreen.h b/Headers/gnustep/gui/NSScreen.h index 03617c9f3..0b236b3e8 100644 --- a/Headers/gnustep/gui/NSScreen.h +++ b/Headers/gnustep/gui/NSScreen.h @@ -38,7 +38,6 @@ @class NSArray; @class NSDictionary; -@class NSMutableDictionary; @interface NSScreen : NSObject { @@ -46,8 +45,7 @@ NSWindowDepth _depth; NSRect _frame; int _screenNumber; - - void *_reserved; + NSWindowDepth *_supportedWindowDepths; } /* diff --git a/Source/NSScreen.m b/Source/NSScreen.m index 77e67e8bd..8046802eb 100644 --- a/Source/NSScreen.m +++ b/Source/NSScreen.m @@ -38,7 +38,18 @@ #include #include #include +#include +/* + * Forward references + */ +NSWindowDepth GSWindowDepthForScreen(NSGraphicsContext *ctxt, int screen); +const NSWindowDepth *GSAvailableDepthsForScreen(NSGraphicsContext *ctxt, + int screen); + +/* + * Returns a list of the screens attached to the system. + */ static int* _screenNumbers(int *count) { @@ -106,12 +117,13 @@ _screenNumbers(int *count) RELEASE(self); return nil; } - + // Fill in all of the i-vars with appropriate values. _screenNumber = screen; - DPScurrentwindowbounds(ctxt, screen, &x, &y, &w, &h); + DPScurrentwindowbounds(ctxt, _screenNumber, &x, &y, &w, &h); _frame = NSMakeRect(x, y, w, h); - _depth = GSWindowDepthForScreen(screen); + _depth = GSWindowDepthForScreen(ctxt, _screenNumber); + _supportedWindowDepths = NULL; return self; } @@ -148,8 +160,8 @@ _screenNumbers(int *count) NSString *colorSpaceName = nil; /* - * Testing of this method on OS4.2 indicates that the - * dictionary is re-created every time this method is called. + * This method generates a dictionary from the + * information we have gathered from the screen. */ // Set the screen number in the current object. @@ -186,14 +198,23 @@ _screenNumbers(int *count) // Mac OS X methods - (const NSWindowDepth*) supportedWindowDepths { - /* - * Skeletal implementation - * NSWindowDepth* retval = NSZoneMalloc([self zone], sizeof(NSWindowDepth)*2); - * retval[1] = _depth; - * retval[2] = 0; - * return retval; - */ - return GSAvailableDepthsForScreen(_screenNumber); + // If the variable isn't initialized, get the info and + // store it for the future. + if (_supportedWindowDepths == NULL) + { + NSGraphicsContext *ctxt = GSCurrentContext(); + _supportedWindowDepths = + (NSWindowDepth *)GSAvailableDepthsForScreen(ctxt, _screenNumber); + + // Check the results + if (_supportedWindowDepths == NULL) + { + NSLog(@"Internal error: no depth list returned from window server."); + return NULL; + } + } + + return _supportedWindowDepths; } - (NSRect) visibleFrame @@ -280,9 +301,14 @@ _screenNumbers(int *count) // Get the number of screens. windows = _screenNumbers(&count); - // If the list is empty quit... + // If the list is empty throw the appropriate exception and quit... if (windows == NULL) - return nil; // something is wrong. This shouldn't happen. + { + [NSException + raise:NSWindowServerCommunicationException + format:@"Unable to retrieve list of screens from window server."]; + return nil; // something is wrong. This shouldn't happen. + } // Iterate over the list for (index = 0; index < count; index++) @@ -297,6 +323,21 @@ _screenNumbers(int *count) return [NSArray arrayWithArray: screenArray]; } + +// 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); + } + + [super dealloc]; +} + @end