Commit fc4e798d7986a3e492c340e37fe2080471daaae3

Sam Lantinga 2014-07-07T12:48:25

Fixed bug 2631 - Mac: minor code cleanup Alex Szpakowski Some minor changes to the Mac-specific backend code: - Fixed up some code style issues (mostly brace style inconsistencies). - Fixed a compiler warning in SDL_cocoaevents.m. - Removed some useless code now that the 10.7 SDK is required to build SDL. - Removed Gestalt(gestaltSystemVersion, ...) call and switched to NSAppKitVersionNumber for version checking code. Using Gestalt with gestaltSystemVersion will give 0x1090 in Mac OS 10.10+, and the whole Gestalt function was deprecated in Mac OS 10.8.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
diff --git a/src/file/cocoa/SDL_rwopsbundlesupport.m b/src/file/cocoa/SDL_rwopsbundlesupport.m
index 682bd74..f6a65a9 100644
--- a/src/file/cocoa/SDL_rwopsbundlesupport.m
+++ b/src/file/cocoa/SDL_rwopsbundlesupport.m
@@ -37,8 +37,7 @@ FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode)
     FILE* fp = NULL;
 
     /* If the file mode is writable, skip all the bundle stuff because generally the bundle is read-only. */
-    if(strcmp("r", mode) && strcmp("rb", mode))
-    {
+    if(strcmp("r", mode) && strcmp("rb", mode)) {
         return fopen(file, mode);
     }
 
@@ -51,12 +50,10 @@ FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode)
     NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
 
     NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
-    if([file_manager fileExistsAtPath:full_path_with_file_to_try])
-    {
+    if([file_manager fileExistsAtPath:full_path_with_file_to_try]) {
         fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
     }
-    else
-    {
+    else {
         fp = fopen(file, mode);
     }
 
diff --git a/src/haptic/darwin/SDL_syshaptic.c b/src/haptic/darwin/SDL_syshaptic.c
index 81282d6..408b81a 100644
--- a/src/haptic/darwin/SDL_syshaptic.c
+++ b/src/haptic/darwin/SDL_syshaptic.c
@@ -257,21 +257,18 @@ MacHaptic_MaybeAddDevice( io_object_t device )
                                                kCFAllocatorDefault,
                                                kNilOptions);
     if ((result == KERN_SUCCESS) && hidProperties) {
-        refCF =
-        CFDictionaryGetValue(hidProperties,
-                             CFSTR(kIOHIDPrimaryUsagePageKey));
+        refCF = CFDictionaryGetValue(hidProperties,
+                                     CFSTR(kIOHIDPrimaryUsagePageKey));
         if (refCF) {
-            if (!CFNumberGetValue(refCF, kCFNumberLongType,
-                                  &item->usagePage))
-                SDL_SetError
-                ("Haptic: Recieving device's usage page.");
-            refCF =
-            CFDictionaryGetValue(hidProperties,
-                                 CFSTR(kIOHIDPrimaryUsageKey));
+            if (!CFNumberGetValue(refCF, kCFNumberLongType, &item->usagePage)) {
+                SDL_SetError("Haptic: Recieving device's usage page.");
+            }
+            refCF = CFDictionaryGetValue(hidProperties,
+                                         CFSTR(kIOHIDPrimaryUsageKey));
             if (refCF) {
-                if (!CFNumberGetValue(refCF, kCFNumberLongType,
-                                      &item->usage))
+                if (!CFNumberGetValue(refCF, kCFNumberLongType, &item->usage)) {
                     SDL_SetError("Haptic: Recieving device's usage.");
+                }
             }
         }
         CFRelease(hidProperties);
@@ -377,24 +374,21 @@ HIDGetDeviceProduct(io_service_t dev, char *name)
 
 
             /* Get product name */
-            refCF =
-                CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey));
-            if (!refCF)
-                refCF =
-                    CFDictionaryGetValue(usbProperties,
-                                         CFSTR("USB Product Name"));
+            refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey));
+            if (!refCF) {
+                refCF = CFDictionaryGetValue(usbProperties,
+                                             CFSTR("USB Product Name"));
+            }
             if (refCF) {
                 if (!CFStringGetCString(refCF, name, 256,
                                         CFStringGetSystemEncoding())) {
-                    return SDL_SetError
-                        ("Haptic: CFStringGetCString error retrieving pDevice->product.");
+                    return SDL_SetError("Haptic: CFStringGetCString error retrieving pDevice->product.");
                 }
             }
 
             CFRelease(usbProperties);
         } else {
-            return SDL_SetError
-                ("Haptic: IORegistryEntryCreateCFProperties failed to create usbProperties.");
+            return SDL_SetError("Haptic: IORegistryEntryCreateCFProperties failed to create usbProperties.");
         }
 
         /* Release stuff. */
@@ -457,9 +451,9 @@ GetSupportedFeatures(SDL_Haptic * haptic)
     /* Check if supports gain. */
     ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_FFGAIN,
                                            &val, sizeof(val));
-    if (ret == FF_OK)
+    if (ret == FF_OK) {
         supported |= SDL_HAPTIC_GAIN;
-    else if (ret != FFERR_UNSUPPORTED) {
+    } else if (ret != FFERR_UNSUPPORTED) {
         return SDL_SetError("Haptic: Unable to get if device supports gain: %s.",
                             FFStrError(ret));
     }
@@ -467,9 +461,9 @@ GetSupportedFeatures(SDL_Haptic * haptic)
     /* Checks if supports autocenter. */
     ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_AUTOCENTER,
                                            &val, sizeof(val));
-    if (ret == FF_OK)
+    if (ret == FF_OK) {
         supported |= SDL_HAPTIC_AUTOCENTER;
-    else if (ret != FFERR_UNSUPPORTED) {
+    } else if (ret != FFERR_UNSUPPORTED) {
         return SDL_SetError
             ("Haptic: Unable to get if device supports autocenter: %s.",
              FFStrError(ret));
@@ -604,8 +598,9 @@ SDL_SYS_HapticMouse(void)
 int
 SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
 {
-    if (joystick->hwdata->ffservice != 0)
+    if (joystick->hwdata->ffservice != 0) {
         return SDL_TRUE;
+    }
     return SDL_FALSE;
 }
 
@@ -617,8 +612,9 @@ int
 SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
 {
     if (IOObjectIsEqualTo((io_object_t) ((size_t)haptic->hwdata->device),
-                          joystick->hwdata->ffservice))
+                          joystick->hwdata->ffservice)) {
         return 1;
+    }
     return 0;
 }
 
@@ -739,18 +735,22 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes)
     case SDL_HAPTIC_CARTESIAN:
         effect->dwFlags |= FFEFF_CARTESIAN;
         rglDir[0] = dir->dir[0];
-        if (naxes > 1)
+        if (naxes > 1) {
             rglDir[1] = dir->dir[1];
-        if (naxes > 2)
+        }
+        if (naxes > 2) {
             rglDir[2] = dir->dir[2];
+        }
         return 0;
     case SDL_HAPTIC_SPHERICAL:
         effect->dwFlags |= FFEFF_SPHERICAL;
         rglDir[0] = dir->dir[0];
-        if (naxes > 1)
+        if (naxes > 1) {
             rglDir[1] = dir->dir[1];
-        if (naxes > 2)
+        }
+        if (naxes > 2) {
             rglDir[2] = dir->dir[2];
+        }
         return 0;
 
     default:
@@ -767,8 +767,7 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes)
  * Creates the FFEFFECT from a SDL_HapticEffect.
  */
 static int
-SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest,
-                   SDL_HapticEffect * src)
+SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
 {
     int i;
     FFCONSTANTFORCE *constant;
@@ -1269,8 +1268,7 @@ SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
 {
     HRESULT ret;
 
-    ret =
-        FFDeviceReleaseEffect(haptic->hwdata->device, effect->hweffect->ref);
+    ret = FFDeviceReleaseEffect(haptic->hwdata->device, effect->hweffect->ref);
     if (ret != FF_OK) {
         SDL_SetError("Haptic: Error removing the effect from the device: %s.",
                      FFStrError(ret));
@@ -1299,8 +1297,9 @@ SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
         return -1;
     }
 
-    if (status == 0)
+    if (status == 0) {
         return SDL_FALSE;
+    }
     return SDL_TRUE;            /* Assume it's playing or emulated. */
 }
 
@@ -1315,9 +1314,8 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
     Uint32 val;
 
     val = gain * 100;           /* Mac OS X uses 0 to 10,000 */
-    ret =
-        FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
-                                         FFPROP_FFGAIN, &val);
+    ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
+                                           FFPROP_FFGAIN, &val);
     if (ret != FF_OK) {
         return SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret));
     }
@@ -1336,10 +1334,11 @@ SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
     Uint32 val;
 
     /* Mac OS X only has 0 (off) and 1 (on) */
-    if (autocenter == 0)
+    if (autocenter == 0) {
         val = 0;
-    else
+    } else {
         val = 1;
+    }
 
     ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
                                            FFPROP_AUTOCENTER, &val);
diff --git a/src/joystick/darwin/SDL_sysjoystick.c b/src/joystick/darwin/SDL_sysjoystick.c
index 12c1048..f0bd5b8 100644
--- a/src/joystick/darwin/SDL_sysjoystick.c
+++ b/src/joystick/darwin/SDL_sysjoystick.c
@@ -406,17 +406,13 @@ JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDevic
     s_bDeviceAdded = SDL_TRUE;
 
     /* Add device to the end of the list */
-    if ( !gpDeviceList )
-    {
+    if ( !gpDeviceList ) {
         gpDeviceList = device;
-    }
-    else
-    {
+    } else {
         recDevice *curdevice;
 
         curdevice = gpDeviceList;
-        while ( curdevice->pNext )
-        {
+        while ( curdevice->pNext ) {
             curdevice = curdevice->pNext;
         }
         curdevice->pNext = device;
diff --git a/src/video/cocoa/SDL_cocoaclipboard.m b/src/video/cocoa/SDL_cocoaclipboard.m
index 495c934..c2f3be7 100644
--- a/src/video/cocoa/SDL_cocoaclipboard.m
+++ b/src/video/cocoa/SDL_cocoaclipboard.m
@@ -28,9 +28,7 @@
 static NSString *
 GetTextFormat(_THIS)
 {
-    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
-
-    if (data->osversion >= 0x1060) {
+    if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) {
         return NSPasteboardTypeString;
     } else {
         return NSStringPboardType;
@@ -96,7 +94,7 @@ Cocoa_HasClipboardText(_THIS)
     char *text = Cocoa_GetClipboardText(_this);
     if (text) {
         result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
-    SDL_free(text);
+        SDL_free(text);
     }
     return result;
 }
diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m
index 11b5ee1..3474d15 100644
--- a/src/video/cocoa/SDL_cocoaevents.m
+++ b/src/video/cocoa/SDL_cocoaevents.m
@@ -27,16 +27,6 @@
 #include "../../events/SDL_events_c.h"
 #include "SDL_assert.h"
 
-#if !defined(UsrActivity) && defined(__LP64__) && !defined(__POWER__)
-/*
- * Workaround for a bug in the 10.5 SDK: By accident, OSService.h does
- * not include Power.h at all when compiling in 64bit mode. This has
- * been fixed in 10.6, but for 10.5, we manually define UsrActivity
- * to ensure compilation works.
- */
-#define UsrActivity 1
-#endif
-
 @interface SDLApplication : NSApplication
 
 - (void)terminate:(id)sender;
@@ -58,7 +48,7 @@
 - (void)setAppleMenu:(NSMenu *)menu;
 @end
 
-@interface SDLAppDelegate : NSObject {
+@interface SDLAppDelegate : NSObject <NSApplicationDelegate> {
 @public
     BOOL seenFirstActivate;
 }
@@ -70,7 +60,6 @@
 - (id)init
 {
     self = [super init];
-
     if (self) {
         seenFirstActivate = NO;
         [[NSNotificationCenter defaultCenter] addObserver:self
@@ -101,15 +90,12 @@
     }
 
     SDL_VideoDevice *device = SDL_GetVideoDevice();
-    if (device && device->windows)
-    {
+    if (device && device->windows) {
         SDL_Window *window = device->windows;
         int i;
-        for (i = 0; i < device->num_displays; ++i)
-        {
+        for (i = 0; i < device->num_displays; ++i) {
             SDL_Window *fullscreen_window = device->displays[i].fullscreen_window;
-            if (fullscreen_window)
-            {
+            if (fullscreen_window) {
                 if (fullscreen_window->flags & SDL_WINDOW_MINIMIZED) {
                     SDL_RestoreWindow(fullscreen_window);
                 }
@@ -140,11 +126,13 @@ GetApplicationName(void)
 
     /* Determine the application name */
     appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
-    if (!appName)
+    if (!appName) {
         appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
+    }
 
-    if (![appName length])
+    if (![appName length]) {
         appName = [[NSProcessInfo processInfo] processName];
+    }
 
     return appName;
 }
@@ -294,7 +282,7 @@ Cocoa_RegisterApp(void)
          * termination into SDL_Quit, and we can't handle application:openFile:
          */
         if (![NSApp delegate]) {
-            [NSApp setDelegate:appDelegate];
+            [(NSApplication *)NSApp setDelegate:appDelegate];
         } else {
             appDelegate->seenFirstActivate = YES;
         }
diff --git a/src/video/cocoa/SDL_cocoakeyboard.m b/src/video/cocoa/SDL_cocoakeyboard.m
index c68ee8b..53f5886 100644
--- a/src/video/cocoa/SDL_cocoakeyboard.m
+++ b/src/video/cocoa/SDL_cocoakeyboard.m
@@ -32,33 +32,7 @@
 /*#define DEBUG_IME NSLog */
 #define DEBUG_IME(...)
 
-#ifndef NX_DEVICERCTLKEYMASK
-    #define NX_DEVICELCTLKEYMASK    0x00000001
-#endif
-#ifndef NX_DEVICELSHIFTKEYMASK
-    #define NX_DEVICELSHIFTKEYMASK  0x00000002
-#endif
-#ifndef NX_DEVICERSHIFTKEYMASK
-    #define NX_DEVICERSHIFTKEYMASK  0x00000004
-#endif
-#ifndef NX_DEVICELCMDKEYMASK
-    #define NX_DEVICELCMDKEYMASK    0x00000008
-#endif
-#ifndef NX_DEVICERCMDKEYMASK
-    #define NX_DEVICERCMDKEYMASK    0x00000010
-#endif
-#ifndef NX_DEVICELALTKEYMASK
-    #define NX_DEVICELALTKEYMASK    0x00000020
-#endif
-#ifndef NX_DEVICERALTKEYMASK
-    #define NX_DEVICERALTKEYMASK    0x00000040
-#endif
-#ifndef NX_DEVICERCTLKEYMASK
-    #define NX_DEVICERCTLKEYMASK    0x00002000
-#endif
-
-@interface SDLTranslatorResponder : NSView <NSTextInput>
-{
+@interface SDLTranslatorResponder : NSView <NSTextInput> {
     NSString *_markedText;
     NSRange   _markedRange;
     NSRange   _selectedRange;
@@ -83,10 +57,11 @@
 
     /* Could be NSString or NSAttributedString, so we have
      * to test and convert it before return as SDL event */
-    if ([aString isKindOfClass: [NSAttributedString class]])
+    if ([aString isKindOfClass: [NSAttributedString class]]) {
         str = [[aString string] UTF8String];
-    else
+    } else {
         str = [aString UTF8String];
+    }
 
     SDL_SendKeyboardText(str);
 }
@@ -117,17 +92,16 @@
 - (void) setMarkedText:(id) aString
          selectedRange:(NSRange) selRange
 {
-    if ([aString isKindOfClass: [NSAttributedString class]])
+    if ([aString isKindOfClass: [NSAttributedString class]]) {
         aString = [aString string];
+    }
 
-    if ([aString length] == 0)
-    {
+    if ([aString length] == 0) {
         [self unmarkText];
         return;
     }
 
-    if (_markedText != aString)
-    {
+    if (_markedText != aString) {
         [_markedText release];
         _markedText = [aString retain];
     }
@@ -443,10 +417,11 @@ UpdateKeymap(SDL_VideoData *data)
 
     /* Try Unicode data first */
     CFDataRef uchrDataRef = TISGetInputSourceProperty(key_layout, kTISPropertyUnicodeKeyLayoutData);
-    if (uchrDataRef)
+    if (uchrDataRef) {
         chr_data = CFDataGetBytePtr(uchrDataRef);
-    else
+    } else {
         goto cleanup;
+    }
 
     if (chr_data) {
         UInt32 keyboard_type = LMGetKbdType();
@@ -470,8 +445,9 @@ UpdateKeymap(SDL_VideoData *data)
                                   0, keyboard_type,
                                   kUCKeyTranslateNoDeadKeysMask,
                                   &dead_key_state, 8, &len, s);
-            if (err != noErr)
+            if (err != noErr) {
                 continue;
+            }
 
             if (len > 0 && s[0] != 0x10) {
                 keymap[scancode] = s[0];
@@ -508,8 +484,9 @@ Cocoa_StartTextInput(_THIS)
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     SDL_Window *window = SDL_GetKeyboardFocus();
     NSWindow *nswindow = nil;
-    if (window)
+    if (window) {
         nswindow = ((SDL_WindowData*)window->driverdata)->nswindow;
+    }
 
     NSView *parentView = [nswindow contentView];
 
@@ -523,8 +500,7 @@ Cocoa_StartTextInput(_THIS)
             [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
     }
 
-    if (![[data->fieldEdit superview] isEqual: parentView])
-    {
+    if (![[data->fieldEdit superview] isEqual: parentView]) {
         /* DEBUG_IME(@"add fieldEdit to window contentView"); */
         [data->fieldEdit removeFromSuperview];
         [parentView addSubview: data->fieldEdit];
@@ -554,8 +530,8 @@ Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect)
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
 
     if (!rect) {
-    SDL_InvalidParamError("rect");
-    return;
+        SDL_InvalidParamError("rect");
+        return;
     }
 
     [data->fieldEdit setInputRect: rect];
@@ -579,10 +555,10 @@ Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
         /* see comments in SDL_cocoakeys.h */
         scancode = 60 - scancode;
     }
+
     if (scancode < SDL_arraysize(darwin_scancode_table)) {
         code = darwin_scancode_table[scancode];
-    }
-    else {
+    } else {
         /* Hmm, does this ever happen?  If so, need to extend the keymap... */
         code = SDL_SCANCODE_UNKNOWN;
     }
diff --git a/src/video/cocoa/SDL_cocoamessagebox.m b/src/video/cocoa/SDL_cocoamessagebox.m
index f022fcf..2ed7d90 100644
--- a/src/video/cocoa/SDL_cocoamessagebox.m
+++ b/src/video/cocoa/SDL_cocoamessagebox.m
@@ -22,13 +22,6 @@
 
 #if SDL_VIDEO_DRIVER_COCOA
 
-#if defined(__APPLE__) && defined(__POWERPC__) && !defined(__APPLE_ALTIVEC__)
-#include <altivec.h>
-#undef bool
-#undef vector
-#undef pixel
-#endif
-
 #include "SDL_events.h"
 #include "SDL_timer.h"
 #include "SDL_messagebox.h"
@@ -125,13 +118,10 @@ Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
 
     int returnValue = 0;
     NSInteger clicked = presenter->clicked;
-    if (clicked >= NSAlertFirstButtonReturn)
-    {
+    if (clicked >= NSAlertFirstButtonReturn) {
         clicked -= NSAlertFirstButtonReturn;
         *buttonid = buttons[clicked].buttonid;
-    }
-    else
-    {
+    } else {
         returnValue = SDL_SetError("Did not get a valid `clicked button' id: %ld", (long)clicked);
     }
 
diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m
index 68a1cff..a98d376 100644
--- a/src/video/cocoa/SDL_cocoamodes.m
+++ b/src/video/cocoa/SDL_cocoamodes.m
@@ -43,10 +43,11 @@ Cocoa_ToggleMenuBar(const BOOL show)
      *  we can just simply do without it on newer OSes...
      */
 #if (MAC_OS_X_VERSION_MIN_REQUIRED < 1070) && !defined(__LP64__)
-    if (show)
+    if (show) {
         ShowMenuBar();
-    else
+    } else {
         HideMenuBar();
+    }
 #endif
 }
 
@@ -60,12 +61,12 @@ Cocoa_ToggleMenuBar(const BOOL show)
 #endif
 
 static BOOL
-IS_SNOW_LEOPARD_OR_LATER(_THIS)
+IS_SNOW_LEOPARD_OR_LATER()
 {
 #if FORCE_OLD_API
     return NO;
 #else
-    return ((((SDL_VideoData *) _this->driverdata))->osversion >= 0x1060);
+    return floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5;
 #endif
 }
 
@@ -127,7 +128,7 @@ GetDisplayMode(_THIS, const void *moderef, SDL_DisplayMode *mode)
     }
     data->moderef = moderef;
 
-    if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
+    if (IS_SNOW_LEOPARD_OR_LATER()) {
         CGDisplayModeRef vidmode = (CGDisplayModeRef) moderef;
         CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode);
         width = (long) CGDisplayModeGetWidth(vidmode);
@@ -148,7 +149,7 @@ GetDisplayMode(_THIS, const void *moderef, SDL_DisplayMode *mode)
     }
 
     #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
-    if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
+    if (!IS_SNOW_LEOPARD_OR_LATER()) {
         CFNumberRef number;
         CFDictionaryRef vidmode = (CFDictionaryRef) moderef;
         number = CFDictionaryGetValue(vidmode, kCGDisplayWidth);
@@ -184,7 +185,7 @@ GetDisplayMode(_THIS, const void *moderef, SDL_DisplayMode *mode)
 static void
 Cocoa_ReleaseDisplayMode(_THIS, const void *moderef)
 {
-    if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
+    if (IS_SNOW_LEOPARD_OR_LATER()) {
         CGDisplayModeRelease((CGDisplayModeRef) moderef);  /* NULL is ok */
     }
 }
@@ -192,7 +193,7 @@ Cocoa_ReleaseDisplayMode(_THIS, const void *moderef)
 static void
 Cocoa_ReleaseDisplayModeList(_THIS, CFArrayRef modelist)
 {
-    if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
+    if (IS_SNOW_LEOPARD_OR_LATER()) {
         CFRelease(modelist);  /* NULL is ok */
     }
 }
@@ -257,12 +258,12 @@ Cocoa_InitModes(_THIS)
                 continue;
             }
 
-            if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
+            if (IS_SNOW_LEOPARD_OR_LATER()) {
                 moderef = CGDisplayCopyDisplayMode(displays[i]);
             }
 
             #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
-            if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
+            if (!IS_SNOW_LEOPARD_OR_LATER()) {
                 moderef = CGDisplayCurrentMode(displays[i]);
             }
             #endif
@@ -319,12 +320,12 @@ Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
     SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
     CFArrayRef modes = NULL;
 
-    if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
+    if (IS_SNOW_LEOPARD_OR_LATER()) {
         modes = CGDisplayCopyAllDisplayModes(data->display, NULL);
     }
 
     #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
-    if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
+    if (!IS_SNOW_LEOPARD_OR_LATER()) {
         modes = CGDisplayAvailableModes(data->display);
     }
     #endif
@@ -337,7 +338,7 @@ Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
             const void *moderef = CFArrayGetValueAtIndex(modes, i);
             SDL_DisplayMode mode;
             if (GetDisplayMode(_this, moderef, &mode)) {
-                if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
+                if (IS_SNOW_LEOPARD_OR_LATER()) {
                     CGDisplayModeRetain((CGDisplayModeRef) moderef);
                 }
                 SDL_AddDisplayMode(display, &mode);
@@ -351,12 +352,12 @@ Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
 static CGError
 Cocoa_SwitchMode(_THIS, CGDirectDisplayID display, const void *mode)
 {
-    if (IS_SNOW_LEOPARD_OR_LATER(_this)) {
+    if (IS_SNOW_LEOPARD_OR_LATER()) {
         return CGDisplaySetDisplayMode(display, (CGDisplayModeRef) mode, NULL);
     }
  
     #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
-    if (!IS_SNOW_LEOPARD_OR_LATER(_this)) {
+    if (!IS_SNOW_LEOPARD_OR_LATER()) {
         return CGDisplaySwitchToMode(display, (CFDictionaryRef) mode);
     }
     #endif
diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m
index 287dcd7..4ea420d 100644
--- a/src/video/cocoa/SDL_cocoamouse.m
+++ b/src/video/cocoa/SDL_cocoamouse.m
@@ -120,8 +120,7 @@ Cocoa_CreateSystemCursor(SDL_SystemCursor id)
     NSCursor *nscursor = NULL;
     SDL_Cursor *cursor = NULL;
 
-    switch(id)
-    {
+    switch(id) {
     case SDL_SYSTEM_CURSOR_ARROW:
         nscursor = [NSCursor arrowCursor];
         break;
@@ -212,8 +211,7 @@ static void
 Cocoa_WarpMouse(SDL_Window * window, int x, int y)
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
-    if ([data->listener isMoving])
-    {
+    if ([data->listener isMoving]) {
         DLog("Postponing warp, window being moved.");
         [data->listener setPendingMoveX:x
                                       Y:y];
@@ -370,8 +368,7 @@ Cocoa_InitMouse(_THIS)
 void
 Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
 {
-    switch ([event type])
-    {
+    switch ([event type]) {
         case NSMouseMoved:
         case NSLeftMouseDragged:
         case NSRightMouseDragged:
@@ -415,8 +412,7 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
     float deltaX = [event deltaX];
     float deltaY = [event deltaY];
 
-    if (seenWarp)
-    {
+    if (seenWarp) {
         deltaX += (lastMoveX - driverdata->lastWarpX);
         deltaY += ((CGDisplayPixelsHigh(kCGDirectMainDisplay) - lastMoveY) - driverdata->lastWarpY);
 
diff --git a/src/video/cocoa/SDL_cocoamousetap.m b/src/video/cocoa/SDL_cocoamousetap.m
index 9cf531c..c274289 100644
--- a/src/video/cocoa/SDL_cocoamousetap.m
+++ b/src/video/cocoa/SDL_cocoamousetap.m
@@ -67,8 +67,7 @@ Cocoa_MouseTapCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event
     NSRect windowRect;
     CGPoint eventLocation;
 
-    switch (type)
-    {
+    switch (type) {
         case kCGEventTapDisabledByTimeout:
         case kCGEventTapDisabledByUserInput:
             {
diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m
index d9fb244..0bbbbcb 100644
--- a/src/video/cocoa/SDL_cocoaopengl.m
+++ b/src/video/cocoa/SDL_cocoaopengl.m
@@ -35,16 +35,6 @@
 
 #define DEFAULT_OPENGL  "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
 
-#ifndef NSOpenGLPFAOpenGLProfile
-#define NSOpenGLPFAOpenGLProfile 99
-#endif
-#ifndef NSOpenGLProfileVersionLegacy
-#define NSOpenGLProfileVersionLegacy 0x1000
-#endif
-#ifndef NSOpenGLProfileVersion3_2Core
-#define NSOpenGLProfileVersion3_2Core 0x3200
-#endif
-
 @implementation SDLOpenGLContext : NSOpenGLContext
 
 - (id)initWithFormat:(NSOpenGLPixelFormat *)format
@@ -161,10 +151,10 @@ Cocoa_GL_UnloadLibrary(_THIS)
 SDL_GLContext
 Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
 {
-    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     NSAutoreleasePool *pool;
     SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
+    SDL_bool lion_or_later = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
     NSOpenGLPixelFormatAttribute attr[32];
     NSOpenGLPixelFormat *fmt;
     SDLOpenGLContext *context;
@@ -178,7 +168,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
         SDL_SetError ("OpenGL ES is not supported on this platform");
         return NULL;
     }
-    if ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) && (data->osversion < 0x1070)) {
+    if ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) && !lion_or_later) {
         SDL_SetError ("OpenGL Core Profile is not supported on this platform version");
         return NULL;
     }
@@ -186,7 +176,7 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
     pool = [[NSAutoreleasePool alloc] init];
 
     /* specify a profile if we're on Lion (10.7) or later. */
-    if (data->osversion >= 0x1070) {
+    if (lion_or_later) {
         NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
         if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
             profile = NSOpenGLProfileVersion3_2Core;
diff --git a/src/video/cocoa/SDL_cocoashape.m b/src/video/cocoa/SDL_cocoashape.m
index 0fe7fb6..61d800b 100644
--- a/src/video/cocoa/SDL_cocoashape.m
+++ b/src/video/cocoa/SDL_cocoashape.m
@@ -30,7 +30,8 @@
 #include "SDL_assert.h"
 
 SDL_WindowShaper*
-Cocoa_CreateShaper(SDL_Window* window) {
+Cocoa_CreateShaper(SDL_Window* window)
+{
     SDL_WindowData* windata = (SDL_WindowData*)window->driverdata;
     [windata->nswindow setOpaque:NO];
 
@@ -63,7 +64,8 @@ typedef struct {
 } SDL_CocoaClosure;
 
 void
-ConvertRects(SDL_ShapeTree* tree,void* closure) {
+ConvertRects(SDL_ShapeTree* tree, void* closure)
+{
     SDL_CocoaClosure* data = (SDL_CocoaClosure*)closure;
     if(tree->kind == OpaqueShape) {
         NSRect rect = NSMakeRect(tree->data.shape.x,data->window->h - tree->data.shape.y,tree->data.shape.w,tree->data.shape.h);
@@ -72,7 +74,8 @@ ConvertRects(SDL_ShapeTree* tree,void* closure) {
 }
 
 int
-Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
+Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
+{
     SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
     SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
     SDL_CocoaClosure closure;
@@ -102,7 +105,8 @@ Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShape
 }
 
 int
-Cocoa_ResizeWindowShape(SDL_Window *window) {
+Cocoa_ResizeWindowShape(SDL_Window *window)
+{
     SDL_ShapeData* data = window->shaper->driverdata;
     SDL_assert(data != NULL);
     return 0;
diff --git a/src/video/cocoa/SDL_cocoavideo.h b/src/video/cocoa/SDL_cocoavideo.h
index f194e1f..288c41f 100644
--- a/src/video/cocoa/SDL_cocoavideo.h
+++ b/src/video/cocoa/SDL_cocoavideo.h
@@ -45,7 +45,6 @@
 
 typedef struct SDL_VideoData
 {
-    SInt32 osversion;
     int allow_spaces;
     unsigned int modifierFlags;
     void *key_layout;
diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m
index 4167037..ad4f14c 100644
--- a/src/video/cocoa/SDL_cocoavideo.m
+++ b/src/video/cocoa/SDL_cocoavideo.m
@@ -22,13 +22,6 @@
 
 #if SDL_VIDEO_DRIVER_COCOA
 
-#if defined(__APPLE__) && defined(__POWERPC__) && !defined(__APPLE_ALTIVEC__)
-#include <altivec.h>
-#undef bool
-#undef vector
-#undef pixel
-#endif
-
 #include "SDL.h"
 #include "SDL_endian.h"
 #include "SDL_cocoavideo.h"
@@ -76,9 +69,6 @@ Cocoa_CreateDevice(int devindex)
     }
     device->driverdata = data;
 
-    /* Find out what version of Mac OS X we're running */
-    Gestalt(gestaltSystemVersion, &data->osversion);
-
     /* Set the function pointers */
     device->VideoInit = Cocoa_VideoInit;
     device->VideoQuit = Cocoa_VideoQuit;
@@ -156,7 +146,7 @@ Cocoa_VideoInit(_THIS)
     Cocoa_InitMouse(_this);
 
     const char *hint = SDL_GetHint(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
-    data->allow_spaces = ( (data->osversion >= 0x1070) && (!hint || (*hint != '0')) );
+    data->allow_spaces = ( (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) && (!hint || (*hint != '0')) );
 
     return 0;
 }
diff --git a/src/video/cocoa/SDL_cocoawindow.h b/src/video/cocoa/SDL_cocoawindow.h
index de75092..65a2c2f 100644
--- a/src/video/cocoa/SDL_cocoawindow.h
+++ b/src/video/cocoa/SDL_cocoawindow.h
@@ -97,13 +97,7 @@ typedef enum
 -(void) touchesCancelledWithEvent:(NSEvent *) theEvent;
 
 /* Touch event handling */
-typedef enum {
-    COCOA_TOUCH_DOWN,
-    COCOA_TOUCH_UP,
-    COCOA_TOUCH_MOVE,
-    COCOA_TOUCH_CANCELLED
-} cocoaTouchType;
--(void) handleTouches:(cocoaTouchType)type withEvent:(NSEvent*) event;
+-(void) handleTouches:(NSTouchPhase) phase withEvent:(NSEvent*) theEvent;
 
 @end
 /* *INDENT-ON* */
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index efcf26f..5141a5b 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -362,8 +362,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
        !!! FIXME:   http://bugzilla.libsdl.org/show_bug.cgi?id=1825
     */
     windows = [NSApp orderedWindows];
-    for (NSWindow *win in windows)
-    {
+    for (NSWindow *win in windows) {
         if (win == window) {
             continue;
         }
@@ -386,8 +385,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
 
 - (void)windowDidFinishMoving
 {
-    if ([self isMoving])
-    {
+    if ([self isMoving]) {
         isMoving = NO;
 
         SDL_Mouse *mouse = SDL_GetMouse();
@@ -859,48 +857,29 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
 
 - (void)touchesBeganWithEvent:(NSEvent *) theEvent
 {
-    [self handleTouches:COCOA_TOUCH_DOWN withEvent:theEvent];
+    [self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
 }
 
 - (void)touchesMovedWithEvent:(NSEvent *) theEvent
 {
-    [self handleTouches:COCOA_TOUCH_MOVE withEvent:theEvent];
+    [self handleTouches:NSTouchPhaseMoved withEvent:theEvent];
 }
 
 - (void)touchesEndedWithEvent:(NSEvent *) theEvent
 {
-    [self handleTouches:COCOA_TOUCH_UP withEvent:theEvent];
+    [self handleTouches:NSTouchPhaseEnded withEvent:theEvent];
 }
 
 - (void)touchesCancelledWithEvent:(NSEvent *) theEvent
 {
-    [self handleTouches:COCOA_TOUCH_CANCELLED withEvent:theEvent];
+    [self handleTouches:NSTouchPhaseCancelled withEvent:theEvent];
 }
 
-- (void)handleTouches:(cocoaTouchType)type withEvent:(NSEvent *)event
+- (void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
 {
-    NSSet *touches = 0;
-    NSEnumerator *enumerator;
-    NSTouch *touch;
-
-    switch (type) {
-        case COCOA_TOUCH_DOWN:
-            touches = [event touchesMatchingPhase:NSTouchPhaseBegan inView:nil];
-            break;
-        case COCOA_TOUCH_UP:
-            touches = [event touchesMatchingPhase:NSTouchPhaseEnded inView:nil];
-            break;
-        case COCOA_TOUCH_CANCELLED:
-            touches = [event touchesMatchingPhase:NSTouchPhaseCancelled inView:nil];
-            break;
-        case COCOA_TOUCH_MOVE:
-            touches = [event touchesMatchingPhase:NSTouchPhaseMoved inView:nil];
-            break;
-    }
+    NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
 
-    enumerator = [touches objectEnumerator];
-    touch = (NSTouch*)[enumerator nextObject];
-    while (touch) {
+    for (NSTouch *touch in touches) {
         const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
         if (!SDL_GetTouch(touchId)) {
             if (SDL_AddTouch(touchId, "") < 0) {
@@ -914,20 +893,20 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
         /* Make the origin the upper left instead of the lower left */
         y = 1.0f - y;
 
-        switch (type) {
-        case COCOA_TOUCH_DOWN:
+        switch (phase) {
+        case NSTouchPhaseBegan:
             SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f);
             break;
-        case COCOA_TOUCH_UP:
-        case COCOA_TOUCH_CANCELLED:
+        case NSTouchPhaseEnded:
+        case NSTouchPhaseCancelled:
             SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f);
             break;
-        case COCOA_TOUCH_MOVE:
+        case NSTouchPhaseMoved:
             SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f);
             break;
+        default:
+            break;
         }
-
-        touch = (NSTouch*)[enumerator nextObject];
     }
 }
 
@@ -1065,23 +1044,20 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
     NSRect rect;
     SDL_Rect bounds;
     unsigned int style;
+    NSArray *screens = [NSScreen screens];
 
     Cocoa_GetDisplayBounds(_this, display, &bounds);
     rect.origin.x = window->x;
     rect.origin.y = window->y;
     rect.size.width = window->w;
     rect.size.height = window->h;
-    ConvertNSRect([[NSScreen screens] objectAtIndex:0], (window->flags & FULLSCREEN_MASK), &rect);
+    ConvertNSRect([screens objectAtIndex:0], (window->flags & FULLSCREEN_MASK), &rect);
 
     style = GetWindowStyle(window);
 
     /* Figure out which screen to place this window */
-    NSArray *screens = [NSScreen screens];
     NSScreen *screen = nil;
-    NSScreen *candidate;
-    int i, count = [screens count];
-    for (i = 0; i < count; ++i) {
-        candidate = [screens objectAtIndex:i];
+    for (NSScreen *candidate in screens) {
         NSRect screenRect = [candidate frame];
         if (rect.origin.x >= screenRect.origin.x &&
             rect.origin.x < screenRect.origin.x + screenRect.size.width &&
@@ -1104,7 +1080,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
     [nswindow setBackgroundColor:[NSColor blackColor]];
 
     if (videodata->allow_spaces) {
-        SDL_assert(videodata->osversion >= 0x1070);
+        SDL_assert(floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6);
         SDL_assert([nswindow respondsToSelector:@selector(toggleFullScreen:)]);
         /* we put FULLSCREEN_DESKTOP windows in their own Space, without a toggle button or menubar, later */
         if (window->flags & SDL_WINDOW_RESIZABLE) {