OpenTTD Source 20260129-master-g2bb01bd0e4
macos.mm File Reference

Code related to MacOSX. More...

#include "../../stdafx.h"
#include "../../core/bitmath_func.hpp"
#include "../../rev.h"
#include "macos.h"
#include "../../string_func.h"
#include "../../fileio_func.h"
#include <pthread.h>
#include "macos_objective_c.h"

Go to the source code of this file.

Functions

std::tuple< int, int, int > GetMacOSVersion ()
 Get the version of the MacOS we are running under.
 
void ShowMacDialog (std::string_view title, std::string_view message, std::string_view buttonLabel)
 Show the system dialogue message, uses Cocoa if available and console otherwise.
 
void ShowOSErrorBox (std::string_view buf, bool system)
 Show an error message.
 
void OSOpenBrowser (const std::string &url)
 Opens browser on MacOS.
 
std::optional< std::string > GetCurrentLocale (const char *)
 Determine and return the current user's charset.
 
bool IsMonospaceFont (CFStringRef name)
 Check if a font is a monospace font.
 
void MacOSSetThreadName (const std::string &name)
 Set the name of the current thread for the debugger.
 
uint64_t MacOSGetPhysicalMemory ()
 Ask OS how much RAM it has physically attached.
 

Detailed Description

Code related to MacOSX.

This file contains objective C. Apple uses objective C instead of plain C to interact with OS specific/native functions.

Definition in file macos.mm.

Function Documentation

◆ GetCurrentLocale()

std::optional< std::string > GetCurrentLocale ( const char *  )

Determine and return the current user's charset.

Returns
String containing current charset, or std::nullopt if not-determinable.

Definition at line 85 of file macos.mm.

◆ GetMacOSVersion()

std::tuple< int, int, int > GetMacOSVersion ( )

Get the version of the MacOS we are running under.

Returns
Tuple with major, minor and patch of the MacOS version.

Definition at line 32 of file macos.mm.

◆ IsMonospaceFont()

bool IsMonospaceFont ( CFStringRef  name)

Check if a font is a monospace font.

Parameters
nameName of the font.
Returns
True if the font is a monospace font.

Definition at line 167 of file macos.mm.

◆ MacOSGetPhysicalMemory()

uint64_t MacOSGetPhysicalMemory ( )

Ask OS how much RAM it has physically attached.

Returns
Number of available bytes.

Definition at line 192 of file macos.mm.

◆ MacOSSetThreadName()

void MacOSSetThreadName ( const std::string &  name)

Set the name of the current thread for the debugger.

Parameters
nameThe new name of the current thread.

Definition at line 178 of file macos.mm.

Referenced by SetCurrentThreadName().

◆ OSOpenBrowser()

void OSOpenBrowser ( const std::string &  url)

Opens browser on MacOS.

Parameters
urlWeb page address to open.

Definition at line 76 of file macos.mm.

◆ ShowMacDialog()

void ShowMacDialog ( std::string_view  title,
std::string_view  message,
std::string_view  buttonLabel 
)

Show the system dialogue message, uses Cocoa if available and console otherwise.

Helper function displaying a message the best possible way.

Parameters
titleWindow title.
messageMessage text.
buttonLabelButton text.

Definition at line 48 of file macos.mm.

References CocoaDialog().

Referenced by CrashLogOSX::DisplayCrashDialog(), HandleCrash(), and ShowOSErrorBox().

◆ ShowOSErrorBox()

void ShowOSErrorBox ( std::string_view  buf,
bool  system 
)

Show an error message.

Parameters
bufText with error message.
systemWhether message text originates from OS.

Definition at line 62 of file macos.mm.