Fix a few mac windowed mode settings (#14942)

* 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)
This commit is contained in:
warmenhoven 2023-02-03 01:32:30 -05:00 committed by GitHub
parent 02f0a829ed
commit ac2cceb905
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 113 additions and 20 deletions

View File

@ -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;

View File

@ -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},
@ -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 },

View File

@ -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,

View File

@ -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
@ -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

View File

@ -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

View File

@ -511,6 +511,59 @@ static ui_application_t ui_application_cocoa = {
@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;
@ -537,6 +590,7 @@ static ui_application_t ui_application_cocoa = {
#ifdef HAVE_COCOA_METAL
_listener = [WindowListener new];
_listener.window = self.window;
[self.window setNextResponder:_listener];
self.window.delegate = _listener;
@ -635,6 +689,7 @@ static ui_application_t ui_application_cocoa = {
if (!is_fullscreen)
{
[self.window toggleFullScreen:self];
self.window.alphaValue = 1;
return;
}
}
@ -642,12 +697,51 @@ static ui_application_t ui_application_cocoa = {
{
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