How to set a custom icon for an app

I’m building an app and I want to have a custom icon, instead of the OF icon that apperas on the window bar. I searched this forum and the net, but couldn’t find anything for Linux, which is my OS. Also, most threads are old, and I guess it’s likely they won’t work with recent OS versions, even for macOS and Windows.
So, my initial question is: how do I set a custon icon from a .png file on Linux?
My second question is: how do I set a custon icon on other OSes?


I only did on macOS. you have to convert somehow your PNG to icns file format.
After this you can add to the Project.xcconfig, or maybe the optional App.xcconfig the lines for custom icon


VERSION = 0.0.4

ICON_NAME = room.icns

Hm, that doesn’t seem to work on Linux. .icns seems to be a macOS file type. I tried to put the last two line of the config file you posted to config.make, with my .png file, but nothing happened.

That was not meant to work on Linux. Maybe I answered your second question?

1 Like

Hi @alexandrosdrymonitis ! Hey did you see the following thread:

And pull request:

It looks like ofAppGLFWWindow::setWindowIcon() should be a public method now in the nightly build, where it used to be private.

Also, if you can figure out where the OF icon file is stored, I wonder if you could just replace its file with another .png file with the same name. That might be a hacky solution though.

Yes setWindowIcon() now works…you may need to get latest from github though, it doesn’t look like the change is in 0.11.2


@TimChi the nightly build for Linux doens’t include this change. As soon as I put the lines from Setting Icons in 0.8.0 I got an error saying that it is not public.

@grimus I downloaded the GitHub version, but compiling OF from there is not as straight forward as it is with the stable versions from OF’s site. Any hints on how to compile it?

Hum… are you using an RPi with the legacy build option?

Lines 154 - 161 in ofAppGLFWWindow.h should have the following in the nightly build:

	Display* 	getX11Display();
	Window  	getX11Window();
	XIC			getX11XIC();

	void setWindowIcon(const std::string & path);
	void setWindowIcon(const ofPixels & iconPixels);

It works OK on my Mint laptop with a nightly build from Dec 22. Here is my main.cpp:

int main( ){
    ofGLWindowSettings settings;
    settings.setSize(1024, 768);
    settings.windowMode = OF_WINDOW; //can also be OF_FULLSCREEN
    auto window = ofCreateWindow(settings);

    ofAppGLFWWindow* win;
    win = dynamic_cast<ofAppGLFWWindow *> (ofGetWindowPtr());

    ofRunApp(window, make_shared<ofApp>());

But, I’m not sure what to do for a RPi with the legacy build (no GLFW window).

@alexandrosdrymonitis if you don’t want to deal with the nightly build, you just need to make that function public. If you compare the ofAppGLFWWindow.h with the latest changes, you should be able to figure it out…i.e. you can make the same changes in your 0.11.2 build.

The exact changes that need to be made are here:

First of all, I was putting the code to set the icon in the ofApp.cpp file, as I didn’t notice it has to go to the main.cpp file. Also, @TimChi I’m not on a Pi this time :slight_smile: .
I realised what’s wrong. I copied my project from the stable release to the nightly build, but the compiler draws sources from the stable release, even when I’m trying to compile from the nightly build. I guess there’s some file where I need to change something, but which one is that?

Hey have you tried importing the copied project in the PG? Qt Creator has a similar option to import a project. The PG has seemingly magical powers to restore and renew a project. I find this is particularly true with Xcode, where there are a ton of IDE-related things that need to be setup correctly.

To copy a project, I typically make a new, empty one with the PG (or with Qt Creator) and then copy only the contents of the /src and /bin/data folders from the old project to the new one. This helps to keep all of the IDE stuff correct for each project.

1 Like

Finally I got it to work! I tried the project generator but it didn’t either. Perhaps some shared object that was copied from the original app, or some other file was causing the compiler to draw sources from the stable release. I copied the source code only, and the rest of the stuff from the emptyExample, and it compiled with my logo on it!
Does this process apply to all OSes, or is it just Linux?

Thank you everyone for the help!

1 Like

Ugh the magical powers of the PG failed! But hey that’s great that you got it working. I do like copying (only) the source code and data folder into an empty project; it’s quick and IDE-agnostic. Make is common to all platforms though (I think), so a process that uses make should be similar for all of them.

1 Like