31
31
#include < float.h>
32
32
#include < string.h>
33
33
34
- // Returns the style mask corresponding to the window settings
35
- //
36
- static NSUInteger getStyleMask (_GLFWwindow* window)
37
- {
38
- NSUInteger styleMask = NSWindowStyleMaskMiniaturizable;
39
-
40
- if (window->monitor || !window->decorated )
41
- styleMask |= NSWindowStyleMaskBorderless;
42
- else
43
- {
44
- styleMask |= NSWindowStyleMaskTitled |
45
- NSWindowStyleMaskClosable;
46
-
47
- if (window->resizable )
48
- styleMask |= NSWindowStyleMaskResizable;
49
- }
50
-
51
- return styleMask;
52
- }
53
-
54
34
// Returns whether the cursor is in the content area of the specified window
55
35
//
56
36
static GLFWbool cursorInContentArea (_GLFWwindow* window)
@@ -809,9 +789,21 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
809
789
else
810
790
contentRect = NSMakeRect (0 , 0 , wndconfig->width , wndconfig->height );
811
791
792
+ NSUInteger styleMask = NSWindowStyleMaskMiniaturizable;
793
+
794
+ if (window->monitor || !window->decorated )
795
+ styleMask |= NSWindowStyleMaskBorderless;
796
+ else
797
+ {
798
+ styleMask |= (NSWindowStyleMaskTitled | NSWindowStyleMaskClosable);
799
+
800
+ if (window->resizable )
801
+ styleMask |= NSWindowStyleMaskResizable;
802
+ }
803
+
812
804
window->ns .object = [[GLFWWindow alloc ]
813
805
initWithContentRect: contentRect
814
- styleMask: getStyleMask (window)
806
+ styleMask: styleMask
815
807
backing: NSBackingStoreBuffered
816
808
defer: NO ];
817
809
@@ -1241,9 +1233,10 @@ void _glfwSetWindowMonitorCocoa(_GLFWwindow* window,
1241
1233
{
1242
1234
const NSRect contentRect =
1243
1235
NSMakeRect (xpos, _glfwTransformYCocoa (ypos + height - 1 ), width, height);
1236
+ const NSUInteger styleMask = [window->ns.object styleMask ];
1244
1237
const NSRect frameRect =
1245
1238
[window->ns.object frameRectForContentRect: contentRect
1246
- styleMask: getStyleMask (window) ];
1239
+ styleMask: styleMask ];
1247
1240
1248
1241
[window->ns.object setFrame: frameRect display: YES ];
1249
1242
}
@@ -1260,7 +1253,27 @@ void _glfwSetWindowMonitorCocoa(_GLFWwindow* window,
1260
1253
// TODO: Solve this in a less terrible way
1261
1254
_glfwPollEventsCocoa ();
1262
1255
1263
- const NSUInteger styleMask = getStyleMask (window);
1256
+ NSUInteger styleMask = [window->ns.object styleMask ];
1257
+
1258
+ if (window->monitor )
1259
+ {
1260
+ styleMask &= ~(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable);
1261
+ styleMask |= NSWindowStyleMaskBorderless;
1262
+ }
1263
+ else
1264
+ {
1265
+ if (window->decorated )
1266
+ {
1267
+ styleMask &= ~NSWindowStyleMaskBorderless;
1268
+ styleMask |= (NSWindowStyleMaskTitled | NSWindowStyleMaskClosable);
1269
+ }
1270
+
1271
+ if (window->resizable )
1272
+ styleMask |= NSWindowStyleMaskResizable;
1273
+ else
1274
+ styleMask &= ~NSWindowStyleMaskResizable;
1275
+ }
1276
+
1264
1277
[window->ns.object setStyleMask: styleMask];
1265
1278
// HACK: Changing the style mask can cause the first responder to be cleared
1266
1279
[window->ns.object makeFirstResponder: window->ns.view];
@@ -1391,17 +1404,18 @@ void _glfwSetWindowResizableCocoa(_GLFWwindow* window, GLFWbool enabled)
1391
1404
{
1392
1405
@autoreleasepool {
1393
1406
1394
- [window->ns.object setStyleMask: getStyleMask (window)];
1395
-
1407
+ const NSUInteger styleMask = [window->ns.object styleMask ];
1396
1408
if (enabled)
1397
1409
{
1410
+ [window->ns.object setStyleMask: (styleMask | NSWindowStyleMaskResizable)];
1398
1411
const NSWindowCollectionBehavior behavior =
1399
1412
NSWindowCollectionBehaviorFullScreenPrimary |
1400
1413
NSWindowCollectionBehaviorManaged;
1401
1414
[window->ns.object setCollectionBehavior: behavior];
1402
1415
}
1403
1416
else
1404
1417
{
1418
+ [window->ns.object setStyleMask: (styleMask & ~NSWindowStyleMaskResizable)];
1405
1419
const NSWindowCollectionBehavior behavior =
1406
1420
NSWindowCollectionBehaviorFullScreenNone;
1407
1421
[window->ns.object setCollectionBehavior: behavior];
@@ -1413,8 +1427,22 @@ void _glfwSetWindowResizableCocoa(_GLFWwindow* window, GLFWbool enabled)
1413
1427
void _glfwSetWindowDecoratedCocoa (_GLFWwindow* window, GLFWbool enabled)
1414
1428
{
1415
1429
@autoreleasepool {
1416
- [window->ns.object setStyleMask: getStyleMask (window)];
1430
+
1431
+ NSUInteger styleMask = [window->ns.object styleMask ];
1432
+ if (enabled)
1433
+ {
1434
+ styleMask |= (NSWindowStyleMaskTitled | NSWindowStyleMaskClosable);
1435
+ styleMask &= ~NSWindowStyleMaskBorderless;
1436
+ }
1437
+ else
1438
+ {
1439
+ styleMask |= NSWindowStyleMaskBorderless;
1440
+ styleMask &= ~(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable);
1441
+ }
1442
+
1443
+ [window->ns.object setStyleMask: styleMask];
1417
1444
[window->ns.object makeFirstResponder: window->ns.view];
1445
+
1418
1446
} // autoreleasepool
1419
1447
}
1420
1448
0 commit comments