Skip to content

Commit

Permalink
Merge pull request xbmc#17234 from kambala-decapitator/ios-safe-area-GUI
Browse files Browse the repository at this point in the history
[ios] apply safe area insets to Kodi GUI
  • Loading branch information
kambala-decapitator authored and Maven85 committed Aug 7, 2020
1 parent acfa965 commit 3622a7e
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 12 deletions.
2 changes: 1 addition & 1 deletion xbmc/platform/darwin/ios/IOSEAGLView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ + (Class) layerClass
//--------------------------------------------------------------
- (void) resizeFrameBuffer
{
auto frame = currentScreen == UIScreen.mainScreen ? self.bounds : currentScreen.bounds;
auto frame = currentScreen.bounds;
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)[self layer];
//allow a maximum framebuffer size of 1080p
//needed for tvout on iPad3/4 and iphone4/5 and maybe AppleTV3
Expand Down
1 change: 1 addition & 0 deletions xbmc/platform/darwin/ios/IOSScreenManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ - (void) setScreen:(unsigned int) screenIdx withMode:(UIScreenMode *)mode
{
[[IOSScreenManager sharedInstance] fadeFromBlack:timeSwitchingToInternalSecs];
}
[g_xbmcController setGUIInsetsFromMainThread:YES];

int w = [[newScreen currentMode] size].width;
int h = [[newScreen currentMode] size].height;
Expand Down
1 change: 1 addition & 0 deletions xbmc/platform/darwin/ios/XBMCController.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
- (void) observeDefaultCenterStuff: (NSNotification *) notification;
- (CGRect)fullscreenSubviewFrame;
- (void)onXbmcAlive;
- (void)setGUIInsetsFromMainThread:(BOOL)isMainThread;
- (void) setFramebuffer;
- (bool) presentFramebuffer;
- (CGSize) getScreenSize;
Expand Down
37 changes: 35 additions & 2 deletions xbmc/platform/darwin/ios/XBMCController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "music/tags/MusicInfoTag.h"
#include "playlists/PlayList.h"
#include "settings/AdvancedSettings.h"
#include "settings/DisplaySettings.h"
#include "settings/Settings.h"
#include "settings/SettingsComponent.h"
#include "settings/lib/ISettingCallback.h"
Expand Down Expand Up @@ -604,8 +605,7 @@ - (void)loadView
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view.autoresizesSubviews = YES;

m_glView = [[IOSEAGLView alloc] initWithFrame:[self fullscreenSubviewFrame]
withScreen:UIScreen.mainScreen];
m_glView = [[IOSEAGLView alloc] initWithFrame:self.view.bounds withScreen:UIScreen.mainScreen];
[[IOSScreenManager sharedInstance] setView:m_glView];
[m_glView setMultipleTouchEnabled:YES];

Expand Down Expand Up @@ -712,6 +712,39 @@ - (CGRect)fullscreenSubviewFrame
- (void)onXbmcAlive
{
m_debugLogSharingPresenter = std::make_unique<DebugLogSharingPresenter>();
[self setGUIInsetsFromMainThread:NO];
}
//--------------------------------------------------------------
- (void)setGUIInsetsFromMainThread:(BOOL)isMainThread
{
auto& guiInsets = CDisplaySettings::GetInstance().GetCurrentResolutionInfo().guiInsets;

// disable insets for external screen
if ([[IOSScreenManager sharedInstance] isExternalScreen])
{
guiInsets = EdgeInsets{};
return;
}

// apply safe area to Kodi GUI
UIEdgeInsets __block insets;
auto getInsets = ^{
insets = m_window.safeAreaInsets;
};
if (isMainThread)
getInsets();
else
dispatch_sync(dispatch_get_main_queue(), getInsets);

CLog::Log(LOGDEBUG, "insets: {}\nwindow: {}\nscreen: {}",
NSStringFromUIEdgeInsets(insets).UTF8String, m_window.description.UTF8String,
m_glView.currentScreen.description.UTF8String);
if (UIEdgeInsetsEqualToEdgeInsets(insets, UIEdgeInsetsZero))
return;

auto scale = [m_glView getScreenScale:m_glView.currentScreen];
guiInsets = EdgeInsets(insets.left * scale, insets.top * scale, insets.right * scale,
insets.bottom * scale);
}
//--------------------------------------------------------------
- (void) setFramebuffer
Expand Down
8 changes: 4 additions & 4 deletions xbmc/windowing/GraphicContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,10 +675,10 @@ void CGraphicContext::GetGUIScaling(const RESOLUTION_INFO &res, float &scaleX, f
RESOLUTION_INFO info = GetResInfo();
float fFromWidth = (float)res.iWidth;
float fFromHeight = (float)res.iHeight;
float fToPosX = (float)info.Overscan.left;
float fToPosY = (float)info.Overscan.top;
float fToWidth = (float)info.Overscan.right - fToPosX;
float fToHeight = (float)info.Overscan.bottom - fToPosY;
auto fToPosX = info.Overscan.left + info.guiInsets.left;
auto fToPosY = info.Overscan.top + info.guiInsets.top;
auto fToWidth = info.Overscan.right - info.guiInsets.right - fToPosX;
auto fToHeight = info.Overscan.bottom - info.guiInsets.bottom - fToPosY;

float fZoom = (100 + CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_LOOKANDFEEL_SKINZOOM)) * 0.01f;

Expand Down
15 changes: 10 additions & 5 deletions xbmc/windowing/Resolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

#include <cstdlib>

EdgeInsets::EdgeInsets(float l, float t, float r, float b) : left(l), top(t), right(r), bottom(b)
{
}

RESOLUTION_INFO::RESOLUTION_INFO(int width, int height, float aspect, const std::string &mode) :
strMode(mode)
{
Expand All @@ -34,11 +38,12 @@ RESOLUTION_INFO::RESOLUTION_INFO(int width, int height, float aspect, const std:
dwFlags = iSubtitles = 0;
}

RESOLUTION_INFO::RESOLUTION_INFO(const RESOLUTION_INFO& res) :
Overscan(res.Overscan),
strMode(res.strMode),
strOutput(res.strOutput),
strId(res.strId)
RESOLUTION_INFO::RESOLUTION_INFO(const RESOLUTION_INFO& res)
: Overscan(res.Overscan),
guiInsets(res.guiInsets),
strMode(res.strMode),
strOutput(res.strOutput),
strId(res.strId)
{
bFullScreen = res.bFullScreen;
iWidth = res.iWidth; iHeight = res.iHeight;
Expand Down
12 changes: 12 additions & 0 deletions xbmc/windowing/Resolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,21 @@ struct OVERSCAN
}
};

struct EdgeInsets
{
float left = 0.0f;
float top = 0.0f;
float right = 0.0f;
float bottom = 0.0f;

EdgeInsets() = default;
EdgeInsets(float l, float t, float r, float b);
};

struct RESOLUTION_INFO
{
OVERSCAN Overscan;
EdgeInsets guiInsets;
bool bFullScreen;
int iWidth;
int iHeight;
Expand Down

0 comments on commit 3622a7e

Please sign in to comment.