src/video/cocoa/SDL_cocoamodes.m
changeset 6836 b0ca1571caf3
parent 6809 54cca01b6006
child 6885 700f1b25f77f
equal deleted inserted replaced
6835:c259f0817583 6836:b0ca1571caf3
   223 static const char *
   223 static const char *
   224 Cocoa_GetDisplayName(CGDirectDisplayID displayID)
   224 Cocoa_GetDisplayName(CGDirectDisplayID displayID)
   225 {
   225 {
   226     NSDictionary *deviceInfo = (NSDictionary *)IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
   226     NSDictionary *deviceInfo = (NSDictionary *)IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
   227     NSDictionary *localizedNames = [deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
   227     NSDictionary *localizedNames = [deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
   228 
   228     const char* displayName = NULL;
       
   229     
   229     if ([localizedNames count] > 0) {
   230     if ([localizedNames count] > 0) {
   230         return [[localizedNames objectForKey:[[localizedNames allKeys] objectAtIndex:0]] UTF8String];
   231         displayName = SDL_strdup([[localizedNames objectForKey:[[localizedNames allKeys] objectAtIndex:0]] UTF8String]);
   231     }
   232     }
   232     return NULL;
   233     [deviceInfo release];
       
   234     return displayName;
   233 }
   235 }
   234 
   236 
   235 void
   237 void
   236 Cocoa_InitModes(_THIS)
   238 Cocoa_InitModes(_THIS)
   237 {
   239 {
   300                 continue;
   302                 continue;
   301             }
   303             }
   302             displaydata->display = displays[i];
   304             displaydata->display = displays[i];
   303 
   305 
   304             SDL_zero(display);
   306             SDL_zero(display);
       
   307             // this returns a stddup'ed string
   305             display.name = (char *)Cocoa_GetDisplayName(displays[i]);
   308             display.name = (char *)Cocoa_GetDisplayName(displays[i]);
   306             if (!GetDisplayMode (_this, moderef, &mode)) {
   309             if (!GetDisplayMode (_this, moderef, &mode)) {
   307                 Cocoa_ReleaseDisplayMode(_this, moderef);
   310                 Cocoa_ReleaseDisplayMode(_this, moderef);
       
   311                 if (display.name) SDL_free(display.name);
   308                 SDL_free(displaydata);
   312                 SDL_free(displaydata);
   309                 continue;
   313                 continue;
   310             }
   314             }
   311 
   315 
   312             display.desktop_mode = mode;
   316             display.desktop_mode = mode;
   313             display.current_mode = mode;
   317             display.current_mode = mode;
   314             display.driverdata = displaydata;
   318             display.driverdata = displaydata;
   315             SDL_AddVideoDisplay(&display);
   319             SDL_AddVideoDisplay(&display);
       
   320             if (display.name) SDL_free(display.name);
   316         }
   321         }
   317     }
   322     }
   318     SDL_stack_free(displays);
   323     SDL_stack_free(displays);
   319     [pool release];
   324     [pool release];
   320 }
   325 }