Skip to content

Commit ed62d6e

Browse files
committed
cocoa: Set the titled flag on fullscreen space windows
For some reason, fullscreen space windows won't get any mouse button events unless the NSWindowStyleMaskTitled flag is set when entering fullscreen, even though they successfully become key and receive mouse motion events. Make sure the flag is always set when entering fullscreen space state.
1 parent b4b5dbd commit ed62d6e

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/video/cocoa/SDL_cocoawindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ typedef enum
140140
@property(nonatomic) SDL_CocoaVideoData *videodata;
141141
@property(nonatomic) SDL_bool send_floating_size;
142142
@property(nonatomic) SDL_bool send_floating_position;
143+
@property(nonatomic) SDL_bool border_toggled;
143144
@property(nonatomic) BOOL checking_zoom;
144145
#ifdef SDL_VIDEO_OPENGL_EGL
145146
@property(nonatomic) EGLSurface egl_surface;

src/video/cocoa/SDL_cocoawindow.m

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,18 +1140,12 @@ - (void)windowDidChangeScreen:(NSNotification *)aNotification
11401140
- (void)windowWillEnterFullScreen:(NSNotification *)aNotification
11411141
{
11421142
SDL_Window *window = _data.window;
1143-
NSUInteger flags = NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable;
1143+
const NSUInteger flags = NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable | NSWindowStyleMaskTitled;
11441144

1145-
/* Don't set the titled flag on a fullscreen window if the windowed-mode window
1146-
* is borderless, or the window can wind up in a weird, pseudo-decorated state
1147-
* when leaving fullscreen if the border flag was toggled on.
1145+
/* For some reason, the fullscreen window won't get any mouse button events
1146+
* without the NSWindowStyleMaskTitled flag being set when entering fullscreen,
1147+
* so it's needed even if the window is borderless.
11481148
*/
1149-
if (!(window->flags & SDL_WINDOW_BORDERLESS)) {
1150-
flags |= NSWindowStyleMaskTitled;
1151-
} else {
1152-
flags |= NSWindowStyleMaskBorderless;
1153-
}
1154-
11551149
SetWindowStyle(window, flags);
11561150

11571151
_data.was_zoomed = !!(window->flags & SDL_WINDOW_MAXIMIZED);
@@ -1212,24 +1206,31 @@ - (void)windowDidEnterFullScreen:(NSNotification *)aNotification
12121206

12131207
- (void)windowWillExitFullScreen:(NSNotification *)aNotification
12141208
{
1209+
SDL_Window *window = _data.window;
1210+
1211+
/* If the windowed mode borders were toggled on while in a fullscreen space,
1212+
* NSWindowStyleMaskTitled has to be cleared here, or the window can end up
1213+
* in a weird, semi-decorated state upon returning to windowed mode.
1214+
*/
1215+
if (_data.border_toggled && !(window->flags & SDL_WINDOW_BORDERLESS)) {
1216+
const NSUInteger flags = NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable;
1217+
1218+
SetWindowStyle(window, flags);
1219+
_data.border_toggled = SDL_FALSE;
1220+
}
1221+
12151222
isFullscreenSpace = NO;
12161223
inFullscreenTransition = YES;
12171224
}
12181225

12191226
- (void)windowDidFailToExitFullScreen:(NSNotification *)aNotification
12201227
{
12211228
SDL_Window *window = _data.window;
1222-
NSUInteger flags = NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable;
1229+
const NSUInteger flags = NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable;
12231230

12241231
if (window->is_destroying) {
12251232
return;
12261233
}
1227-
1228-
if (!(window->flags & SDL_WINDOW_BORDERLESS)) {
1229-
flags |= NSWindowStyleMaskTitled;
1230-
} else {
1231-
flags |= NSWindowStyleMaskBorderless;
1232-
}
12331234

12341235
SetWindowStyle(window, flags);
12351236

@@ -2455,6 +2456,8 @@ void Cocoa_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window *window, SDL_boo
24552456
Cocoa_SetWindowTitle(_this, window); /* this got blanked out. */
24562457
}
24572458
}
2459+
} else {
2460+
data.border_toggled = SDL_TRUE;
24582461
}
24592462
}
24602463
}

0 commit comments

Comments
 (0)