Skip to content

Commit

Permalink
Fix a few mac windowed mode settings (#14942)
Browse files Browse the repository at this point in the history
* Use "Remember window position and size" setting (fixes #14806)
* Implement window opacity
* Enable "Show window decorations" toggle
* Hide "Disable composition" option (osx does not support disabling composition)
  • Loading branch information
warmenhoven committed Feb 3, 2023
1 parent 02f0a82 commit ac2cceb
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 20 deletions.
3 changes: 2 additions & 1 deletion gfx/video_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -3338,7 +3338,8 @@ bool video_driver_init_internal(bool *video_is_threaded, bool verbosity_enabled)
else
#endif
{
#if defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__)
#if (defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__)) || \
(defined(HAVE_COCOA_METAL) && !defined(HAVE_COCOATOUCH))
bool window_custom_size_enable = settings->bools.video_window_save_positions;
#else
bool window_custom_size_enable = settings->bools.video_window_custom_size_enable;
Expand Down
8 changes: 6 additions & 2 deletions menu/menu_displaylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -8591,7 +8591,9 @@ unsigned menu_displaylist_build_list(
{MENU_ENUM_LABEL_MOUSE_ENABLE, PARSE_ONLY_BOOL, true},
{MENU_ENUM_LABEL_POINTER_ENABLE, PARSE_ONLY_BOOL, true},
{MENU_ENUM_LABEL_THREADED_DATA_RUNLOOP_ENABLE, PARSE_ONLY_BOOL, true},
#if !defined(OSX)
{MENU_ENUM_LABEL_VIDEO_DISABLE_COMPOSITION, PARSE_ONLY_BOOL, true},
#endif
#if defined(HAVE_QT) || defined(HAVE_COCOA)
{MENU_ENUM_LABEL_UI_COMPANION_ENABLE, PARSE_ONLY_BOOL, true},
{MENU_ENUM_LABEL_UI_COMPANION_START_ON_BOOT, PARSE_ONLY_BOOL, true},
Expand Down Expand Up @@ -8677,13 +8679,15 @@ unsigned menu_displaylist_build_list(
break;
case DISPLAYLIST_VIDEO_WINDOWED_MODE_SETTINGS_LIST:
{
#if defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__)
#if (defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__)) || \
(defined(HAVE_COCOA_METAL) && !defined(HAVE_COCOATOUCH))
bool window_custom_size_enable = settings->bools.video_window_save_positions;
#else
bool window_custom_size_enable = settings->bools.video_window_custom_size_enable;
#endif
menu_displaylist_build_info_selective_t build_list[] = {
#if defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__)
#if (defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__)) || \
(defined(HAVE_COCOA_METAL) && !defined(HAVE_COCOATOUCH))
{MENU_ENUM_LABEL_VIDEO_WINDOW_SAVE_POSITION, PARSE_ONLY_BOOL, true },
#else
{MENU_ENUM_LABEL_VIDEO_WINDOW_CUSTOM_SIZE_ENABLE, PARSE_ONLY_BOOL, true },
Expand Down
3 changes: 3 additions & 0 deletions menu/menu_setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -12535,7 +12535,10 @@ static bool setting_append_list(
general_read_handler,
SD_FLAG_NONE);
MENU_SETTINGS_LIST_CURRENT_ADD_CMD(list, list_info, CMD_EVENT_REINIT);
#endif

#if (defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__)) || \
(defined(HAVE_COCOA_METAL) && !defined(HAVE_COCOATOUCH))
CONFIG_BOOL(
list, list_info,
&settings->bools.video_window_save_positions,
Expand Down
4 changes: 4 additions & 0 deletions ui/drivers/cocoa/apple_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ typedef enum apple_view_type

#if defined(HAVE_COCOA_METAL) && !defined(HAVE_COCOATOUCH)
@interface WindowListener : NSResponder<NSWindowDelegate>
@property (nonatomic) NSWindow* window;
@end
#endif

Expand All @@ -37,6 +38,9 @@ typedef enum apple_view_type
* the displays should not sleep.
*/
- (bool)setDisableDisplaySleep:(bool)disable;
#if defined(HAVE_COCOA_METAL) && !defined(HAVE_COCOATOUCH)
- (void)updateWindowedMode;
#endif
@end

#endif
Expand Down
13 changes: 0 additions & 13 deletions ui/drivers/cocoa/cocoa_common.m
Original file line number Diff line number Diff line change
Expand Up @@ -647,16 +647,3 @@ bool cocoa_get_metrics(
return true;
}
#endif

#if defined(HAVE_COCOA_METAL) && !defined(HAVE_COCOATOUCH)
@implementation WindowListener

/* Similarly to SDL, we'll respond to key events
* by doing nothing so we don't beep.
*/
- (void)flagsChanged:(NSEvent *)event { }
- (void)keyDown:(NSEvent *)event { }
- (void)keyUp:(NSEvent *)event { }

@end
#endif
102 changes: 98 additions & 4 deletions ui/drivers/ui_cocoa.m
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,59 @@ - (void)sendEvent:(NSEvent *)event {

@end

#if defined(HAVE_COCOA_METAL)
@implementation WindowListener

/* Similarly to SDL, we'll respond to key events
* by doing nothing so we don't beep.
*/
- (void)flagsChanged:(NSEvent *)event { }
- (void)keyDown:(NSEvent *)event { }
- (void)keyUp:(NSEvent *)event { }

- (void)windowDidBecomeKey:(NSNotification *)notification
{
[apple_platform updateWindowedMode];
}

- (void)windowDidMove:(NSNotification *)notification
{
settings_t *settings = config_get_ptr();
bool window_save_positions = settings->bools.video_window_save_positions;
BOOL is_fullscreen = (self.window.styleMask
& NSWindowStyleMaskFullScreen) == NSWindowStyleMaskFullScreen;

if (!window_save_positions || is_fullscreen)
return;

NSRect frame = self.window.frame;
settings->uints.window_position_x = (unsigned)frame.origin.x;
settings->uints.window_position_y = (unsigned)frame.origin.y;
settings->uints.window_position_width = (unsigned)frame.size.width;
settings->uints.window_position_height = (unsigned)frame.size.height;
}

- (void)windowDidResize:(NSNotification *)notification
{
settings_t *settings = config_get_ptr();
bool window_save_positions = settings->bools.video_window_save_positions;
BOOL is_fullscreen = (self.window.styleMask
& NSWindowStyleMaskFullScreen) == NSWindowStyleMaskFullScreen;

if (!window_save_positions || is_fullscreen)
return;

NSRect frame = self.window.frame;
settings->uints.window_position_x = (unsigned)frame.origin.x;
settings->uints.window_position_y = (unsigned)frame.origin.y;
settings->uints.window_position_width = (unsigned)frame.size.width;
settings->uints.window_position_height = (unsigned)frame.size.height;
}

@end
#endif


@implementation RetroArch_OSX

@synthesize window = _window;
Expand All @@ -537,6 +590,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification

#ifdef HAVE_COCOA_METAL
_listener = [WindowListener new];
_listener.window = self.window;

[self.window setNextResponder:_listener];
self.window.delegate = _listener;
Expand Down Expand Up @@ -635,19 +689,59 @@ - (void)setVideoMode:(gfx_ctx_mode_t)mode
if (!is_fullscreen)
{
[self.window toggleFullScreen:self];
self.window.alphaValue = 1;
return;
}
}
else
{
if (is_fullscreen)
[self.window toggleFullScreen:self];
[self updateWindowedSize:mode];
[self updateWindowedMode];
}

/* HACK(sgc): ensure MTKView posts a drawable resize event */
if (mode.width > 0)
[self.window setContentSize:NSMakeSize(mode.width-1, mode.height)];
[self.window setContentSize:NSMakeSize(mode.width, mode.height)];
[self.window displayIfNeeded];
}

- (void)updateWindowedSize:(gfx_ctx_mode_t)mode
{
settings_t *settings = config_get_ptr();
bool windowed_full = settings->bools.video_windowed_fullscreen;
bool window_save_positions = settings->bools.video_window_save_positions;

if (windowed_full)
return;

if (window_save_positions)
{
NSRect frame;
frame.origin.x = settings->uints.window_position_x;
frame.origin.y = settings->uints.window_position_y;
frame.size.width = settings->uints.window_position_width;
frame.size.height = settings->uints.window_position_height;
[self.window setFrame:frame display:YES];
}
else
[self.window setContentSize:NSMakeSize(mode.width, mode.height)];
}

- (void)updateWindowedMode
{
settings_t *settings = config_get_ptr();
bool windowed_full = settings->bools.video_windowed_fullscreen;
bool show_decorations = settings->bools.video_window_show_decorations;
CGFloat opacity = (CGFloat)settings->uints.video_window_opacity / (CGFloat)100.0;

if (windowed_full || !self.window.keyWindow)
return;

if (show_decorations)
self.window.styleMask |= NSWindowStyleMaskTitled;
else
self.window.styleMask &= ~NSWindowStyleMaskTitled;

self.window.alphaValue = opacity;
}

- (void)setCursorVisible:(bool)v
Expand Down

0 comments on commit ac2cceb

Please sign in to comment.