Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions macos_window.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#import <AppKit/AppKit.h>
#include <QWindow>

// Disable macOS native fullscreen on the given QWindow.
// Must be called after the window is shown so the NSWindow exists.
// This makes the green button zoom/maximize instead of triggering the
// native fullscreen transition (which crashes the OpenGL context on ARM64).
void disableNativeFullscreen(QWindow *window) {
NSView *nsView = (NSView *)window->winId();
if (!nsView) return;
NSWindow *nsWindow = [nsView window];
if (!nsWindow) return;
NSWindowCollectionBehavior behavior = [nsWindow collectionBehavior];
behavior &= ~NSWindowCollectionBehaviorFullScreenPrimary;
behavior &= ~NSWindowCollectionBehaviorFullScreenAuxiliary;
[nsWindow setCollectionBehavior:behavior];
}
32 changes: 31 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include <unistd.h>
#include <sys/types.h>

#ifdef __APPLE__
void disableNativeFullscreen(QWindow *window);
#endif

lua_State *L;

int dscount;
Expand Down Expand Up @@ -806,6 +810,12 @@ DrawStringCmd::DrawStringCmd(float X, float Y, int Align, int Size, int Font, co
case 2:
fontName = "Liberation Sans Bold";
break;
case 3: // FONTIN
case 4: // FONTIN ITALIC
case 5: // FONTIN SC
case 6: // FONTIN SC ITALIC
fontName = "Liberation Sans";
break;
case 0:
default:
fontName = "Bitstream Vera Sans Mono";
Expand Down Expand Up @@ -882,7 +892,7 @@ static int l_DrawString(lua_State* L)
pobwindow->LAssert(L, lua_isstring(L, 5), "DrawString() argument 5: expected string, got %t", 5);
pobwindow->LAssert(L, lua_isstring(L, 6), "DrawString() argument 6: expected string, got %t", 6);
static const char* alignMap[6] = { "LEFT", "CENTER", "RIGHT", "CENTER_X", "RIGHT_X", nullptr };
static const char* fontMap[4] = { "FIXED", "VAR", "VAR BOLD", nullptr };
static const char* fontMap[8] = { "FIXED", "VAR", "VAR BOLD", "FONTIN", "FONTIN ITALIC", "FONTIN SC", "FONTIN SC ITALIC", nullptr };
pobwindow->AppendCmd(std::make_unique<DrawStringCmd>(
(float)lua_tonumber(L, 1), (float)lua_tonumber(L, 2), luaL_checkoption(L, 3, "LEFT", alignMap),
(int)lua_tointeger(L, 4), luaL_checkoption(L, 5, "FIXED", fontMap), lua_tostring(L, 6)
Expand All @@ -906,6 +916,10 @@ static int l_DrawStringWidth(lua_State* L)
} else if (fontName == "VAR BOLD") {
fontName = "Liberation Sans Bold";
fontKey = "2";
} else if (fontName == "FONTIN" || fontName == "FONTIN ITALIC" ||
fontName == "FONTIN SC" || fontName == "FONTIN SC ITALIC") {
fontName = "Liberation Sans";
fontKey = "3";
} else {
fontName = "Bitstream Vera Sans Mono";
}
Expand Down Expand Up @@ -942,6 +956,9 @@ static int l_DrawStringCursorIndex(lua_State* L)
fontName = "Liberation Sans";
} else if (fontName == "VAR BOLD") {
fontName = "Liberation Sans Bold";
} else if (fontName == "FONTIN" || fontName == "FONTIN ITALIC" ||
fontName == "FONTIN SC" || fontName == "FONTIN SC ITALIC") {
fontName = "Liberation Sans";
} else {
fontName = "Bitstream Vera Sans Mono";
}
Expand Down Expand Up @@ -1633,6 +1650,13 @@ int main(int argc, char **argv)
luaL_openlibs(L);
luaJIT_setmode(L, 0, LUAJIT_MODE_ENGINE|LUAJIT_MODE_OFF);

// Store debug.traceback in registry so l_PCall's error handler works.
// Without this, "traceback" is nil and PCall errors cause LUA_ERRERR -> PANIC.
lua_getglobal(L, "debug");
lua_getfield(L, -1, "traceback");
lua_setfield(L, LUA_REGISTRYINDEX, "traceback");
lua_pop(L, 1); // pop debug table

// Callbacks
lua_newtable(L); // Callbacks table
lua_pushvalue(L, -1); // Push callbacks table
Expand Down Expand Up @@ -1767,6 +1791,12 @@ int main(int argc, char **argv)
pobwindow->resize(800, 600);
pobwindow->show();

#ifdef __APPLE__
// Disable native fullscreen after the event loop has fully set up the NSWindow.
// Must NOT be called inside initializeGL() — winId() there disrupts the GL surface.
QTimer::singleShot(500, []() { disableNativeFullscreen(pobwindow); });
#endif

// Add the bundled fonts
QFontDatabase::addApplicationFont(QDir::currentPath() + "/VeraMono.ttf");
QFontDatabase::addApplicationFont(QDir::currentPath() + "/LiberationSans-Regular.ttf");
Expand Down
24 changes: 15 additions & 9 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
project('POB Frontend', 'cpp', default_options : ['cpp_std=c++17'])
project('POB Frontend', 'cpp', 'objcpp', default_options : ['cpp_std=c++17'])

qt5_dep = dependency('qt5', modules : ['Gui','Core','Widgets'])
lua_dep = dependency('luajit')
# NB on OSX you also need to invoke meson like so, because luajit:
# LDFLAGS="-pagezero_size 10000 -image_base 100000000" meson pobfrontend build
# (Note: on ARM64/Apple Silicon the above flags are NOT needed — LuaJIT uses GC64 mode)
if build_machine.system() == 'darwin'
gl_dep = dependency('appleframeworks', modules: ['OpenGL'])
gl_dep = dependency('appleframeworks', modules: ['OpenGL', 'AppKit'])
else
gl_dep = dependency('gl')
endif
Expand All @@ -14,21 +15,26 @@ curl_dep = dependency('libcurl')

# Added flag based on https://stackoverflow.com/a/37729971/319066
# and arguments based on https://mesonbuild.com/Adding-arguments.html
compiler_arguments = ['-mmacosx-version-min=10.12', '-isysroot', '/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk']
add_project_arguments(compiler_arguments , language : 'c')
add_project_arguments(compiler_arguments, language : 'cpp')
if build_machine.system() == 'darwin'
sdk_path = run_command('xcrun', '--sdk', 'macosx', '--show-sdk-path', check: true).stdout().strip()
compiler_arguments = ['-mmacosx-version-min=10.12', '-isysroot', sdk_path]
add_project_arguments(compiler_arguments, language : 'c')
add_project_arguments(compiler_arguments, language : 'cpp')
add_project_arguments(compiler_arguments, language : 'objcpp')

linker_arguments = ['-mmacosx-version-min=10.12', '-isysroot', '/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk']
add_project_link_arguments(linker_arguments, language : 'c')
add_project_link_arguments(linker_arguments, language : 'cpp')
linker_arguments = ['-mmacosx-version-min=10.12', '-isysroot', sdk_path]
add_project_link_arguments(linker_arguments, language : 'c')
add_project_link_arguments(linker_arguments, language : 'cpp')
add_project_link_arguments(linker_arguments, language : 'objcpp')
endif

# Import the extension module that knows how
# to invoke Qt tools.
qt5 = import('qt5')
prep = qt5.preprocess(moc_headers : ['subscript.hpp', 'pobwindow.hpp'])

executable('PathOfBuilding',
sources : ['main.cpp', prep],
sources : ['main.cpp', 'macos_window.mm', prep],
dependencies : [qt5_dep, gl_dep, zlib_dep, lua_dep, curl_dep],
install : true)

Expand Down
3 changes: 3 additions & 0 deletions pobwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class POBWindow : public QOpenGLWindow {

connect(&updateTimer, &QTimer::timeout, this, QOverload<>::of(&POBWindow::triggerUpdate));
updateTimer.start(100);

// macOS: disable native fullscreen (causes OpenGL context crash); green button will zoom/maximize instead
setFlag(Qt::WindowFullscreenButtonHint, false);
}

// POBWindow() : QOpenGLWindow() {
Expand Down