Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MacOS icon #2858

Merged
merged 1 commit into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,9 +890,8 @@ def run(self):
data_files = [('pygame', ["src_py/freesansbold.ttf",
"src_py/pygame.ico",
"src_py/pygame_icon.icns",
"src_py/pygame_icon.svg",
"src_py/pygame_icon.bmp",
"src_py/pygame_icon.tiff"])]
"src_py/pygame_icon_mac.bmp"])]


PACKAGEDATA = {
Expand Down
12 changes: 9 additions & 3 deletions src_c/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ _display_state_cleanup(_DisplayState *state)
}
}


#if !defined(__APPLE__)
static char *icon_defaultname = "pygame_icon.bmp";
static int icon_colorkey = 0;
#else
static char *icon_defaultname = "pygame_icon_mac.bmp";
static int icon_colorkey = -1;
#endif

static char *pkgdatamodule_name = "pygame.pkgdata";
static char *imagemodule_name = "pygame.image";
static char *resourcefunc_name = "getResource";
Expand Down Expand Up @@ -1311,8 +1317,8 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
state->icon = pg_display_resource(icon_defaultname);
if (!state->icon)
PyErr_Clear();
else {
SDL_SetColorKey(pgSurface_AsSurface(state->icon), SDL_TRUE, 0);
else if (icon_colorkey != -1) {
SDL_SetColorKey(pgSurface_AsSurface(state->icon), SDL_TRUE, icon_colorkey);
}
}
if (state->icon)
Expand Down
54 changes: 0 additions & 54 deletions src_c/sdlmain_osx.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
extern OSErr CPSSetFrontProcess(CPSProcessSerNum *psn);
extern OSErr CPSSetProcessName(CPSProcessSerNum *psn, const char *processname);

static bool HasInstalledApplication = 0;

static NSString *
getApplicationName(void)
{
Expand Down Expand Up @@ -95,20 +93,6 @@
Py_RETURN_TRUE;
}

static PyObject *
_RunningFromBundleWithNSApplication(PyObject* self)
{
if (HasInstalledApplication)
Py_RETURN_TRUE;

CFBundleRef MainBundle = CFBundleGetMainBundle();
if (MainBundle) {
if (CFBundleGetDataPointerForName(MainBundle, CFSTR("NSApp")))
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}

//#############################################################################
// Defining the NSApplication class we will use
//#############################################################################
Expand Down Expand Up @@ -201,42 +185,6 @@ - (void)terminate:(id)sender
[windowMenuItem release];
}

static PyObject *
_InstallNSApplication(PyObject *self, PyObject *arg)
{
char *icon_data = NULL;
int data_len = 0;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

[PYGSDLApplication sharedApplication];

[NSApp setMainMenu:[[NSMenu alloc] init]];
setApplicationMenu();
setupWindowMenu();

[NSApp finishLaunching];
[NSApp updateWindows];
[NSApp activateIgnoringOtherApps:true];

HasInstalledApplication = 1;

_WMEnable(NULL);

if (!PyArg_ParseTuple(arg, "|z#", &icon_data, &data_len)) {
[pool release];
return NULL;
}

NSData *image_data = [NSData dataWithBytes:icon_data length:data_len];
NSImage *icon_img = [[NSImage alloc] initWithData:image_data];
if (icon_img)
[NSApp setApplicationIconImage:icon_img];


[pool release];
Py_RETURN_TRUE;
}

static PyObject *
_ScrapInit(PyObject *self)
{
Expand Down Expand Up @@ -382,8 +330,6 @@ - (void)terminate:(id)sender
static PyMethodDef macosx_builtins[] =
{
{"WMEnable", (PyCFunction)_WMEnable, METH_NOARGS, "Enables Foreground Operation when Window Manager is not available" },
{"RunningFromBundleWithNSApplication", (PyCFunction) _RunningFromBundleWithNSApplication, METH_NOARGS, "Returns true if we are running from an AppBundle with a variable named NSApp" },
{"InstallNSApplication", _InstallNSApplication, METH_VARARGS, "Creates an NSApplication with the right behaviors for SDL" },
{"ScrapInit", (PyCFunction)_ScrapInit, METH_NOARGS, "Initialize scrap for osx" },
{"ScrapGet", (PyCFunction)_ScrapGet, METH_VARARGS, "Get a element from the scrap for osx" },
{"ScrapPut", (PyCFunction)_ScrapPut, METH_VARARGS, "Set a element from the scrap for osx" },
Expand Down
2 changes: 1 addition & 1 deletion src_py/__pyinstaller/hook-pygame.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _append_to_datas(file_path):
# First append the font file, then based on the OS, append pygame icon file
_append_to_datas("freesansbold.ttf")
if platform.system() == "Darwin":
_append_to_datas("pygame_icon.tiff")
_append_to_datas("pygame_icon_mac.bmp")
else:
_append_to_datas("pygame_icon.bmp")

Expand Down
8 changes: 0 additions & 8 deletions src_py/macosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
def Video_AutoInit():
"""Called from the base.c just before display module is initialized."""
if "Darwin" in platform.platform():
if not sdlmain_osx.RunningFromBundleWithNSApplication():
default_icon_data = None
try:
with getResource("pygame_icon.tiff") as file_resource:
default_icon_data = file_resource.read()
except (IOError, NotImplementedError):
pass
sdlmain_osx.InstallNSApplication(default_icon_data)
if (os.getcwd() == "/") and len(sys.argv) > 1:
os.chdir(os.path.dirname(sys.argv[0]))
return True
Binary file modified src_py/pygame_icon.icns
Binary file not shown.