Skip to content

Commit

Permalink
Move browser-panel ObjC code to Objective-C file; Add more null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
gxalpha committed May 3, 2023
1 parent 594115a commit 5e4865a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
4 changes: 4 additions & 0 deletions cmake/feature-panels.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ target_compile_definitions(browser-panels INTERFACE BROWSER_AVAILABLE)
target_sources(obs-browser PRIVATE panel/browser-panel-client.hpp panel/browser-panel-internal.hpp
panel/browser-panel.cpp panel/browser-panel-client.cpp)

if(OS_MACOS)
target_sources(obs-browser PRIVATE panel/browser-panel-macos.m)
endif()

target_link_libraries(obs-browser PRIVATE OBS::browser-panels Qt::Widgets)

set_target_properties(
Expand Down
1 change: 1 addition & 0 deletions cmake/legacy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ if(ENABLE_BROWSER_PANELS)
target_link_libraries(obs-browser-panels INTERFACE CEF::Wrapper)

if(OS_MACOS)
target_sources(obs-browser PRIVATE panel/browser-panel-macos.m)
target_link_libraries(obs-browser-panels INTERFACE objc)
endif()

Expand Down
15 changes: 15 additions & 0 deletions panel/browser-panel-macos.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#import <AppKit/AppKit.h>

void RemoveNSViewFromSuperview(void *view)
{
if (!view)
return;

if (!*((bool *)view))
return;

// CefBrowserHostView is a subclass of NSView
// and we just need the superclass here
NSView *nsview = (NSView *)view;
[nsview removeFromSuperview];
}
14 changes: 6 additions & 8 deletions panel/browser-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
#include <QThread>
#endif

#ifdef __APPLE__
#include <objc/objc.h>
#endif

#include <obs-module.h>
#include <util/threading.h>
#include <util/base.h>
Expand Down Expand Up @@ -161,6 +157,10 @@ QCefWidgetInternal::~QCefWidgetInternal()
closeBrowser();
}

#ifdef __APPLE__
extern "C" void RemoveNSViewFromSuperview(void *view);
#endif

void QCefWidgetInternal::closeBrowser()
{
CefRefPtr<CefBrowser> browser = cefBrowser;
Expand Down Expand Up @@ -203,10 +203,8 @@ void QCefWidgetInternal::closeBrowser()
}
#elif __APPLE__
// felt hacky, might delete later
void *view = (id)cefBrowser->GetHost()->GetWindowHandle();
if (*((bool *)view))
((void (*)(id, SEL))objc_msgSend)(
(id)view, sel_getUid("removeFromSuperview"));
void *view = cefBrowser->GetHost()->GetWindowHandle();
RemoveNSViewFromSuperview(view);
#endif

destroyBrowser(browser);
Expand Down

0 comments on commit 5e4865a

Please sign in to comment.