andlabs / libui

Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.
Other
10.67k stars 614 forks source link

Set window icon #185

Open emersion opened 7 years ago

emersion commented 7 years ago

Maybe related to the images issue (#2). On GTK there is gtk_window_set_icon. If possible, setting a list of icons with different sizes would be nice to have (gtk_window_set_icon_list).

jandoerntlein commented 7 years ago

+1 for this suggestion. On Windows, it should also be easily possible to change the default icon. This feature would help a lot making the libui-interface feel more "native".

duckbrain commented 7 years ago

Window icons for Windows only accept the ico format. I don't know what the other systems use. https://msdn.microsoft.com/en-us/library/windows/desktop/ms632643(v=vs.85).aspx

For cross-platform, I'd think that having a few formats and converting/scaling them at run-time may be a good option. Personally, I'd like to see SVG, but that would require rasterizing, then converting format. A large PNG could be scaled down as well, but you'd probably want a small image that looks good scaled down as well. Keeping in mind that these icons can be displayed in the Alt+Tab, Taskbar, and other places on various systems.

andlabs commented 7 years ago

I was considering just doing what Windows Explorer does and taking the first icon out of the executable to use for all window icons.

Someguynamedpie commented 7 years ago

Don't support a specific format, just take a pixel buffer; for Windows, look how SDL does it: https://github.com/spurious/SDL-mirror/blob/e1e235cb9012f8edc705d2cb61df9e8a5b0a4047/src/video/windows/SDL_windowswindow.c#L402

andlabs commented 7 years ago

@Someguynamedpie what do you mean?

jwells89 commented 7 years ago

Note that under OS X, an icon in the titlebar typically represents the document/directory displayed in the window, e.g. if you have an RTF document open you'll see a little RTF icon in the titlebar. As such I would recommend not displaying titlebar icons under OS X unless the window in question has its representedDocument set.

More info is at https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/WinPanel/Tasks/SettingWindowTitle.html

andlabs commented 7 years ago

Yep; for now I'm going to have this special code on Windows only. Not sure how GTK+ would handle it, or if that's intrinsically tied to .desktop files.

Someguynamedpie commented 7 years ago

Whoops didn't see you replied. I meant an array of RGB[A] pixels. SDL has an implementation for X11 window icons as well if you want to use that as a reference: https://github.com/spurious/SDL-mirror/blob/e1e235cb9012f8edc705d2cb61df9e8a5b0a4047/src/video/x11/SDL_x11window.c#L739

dotnetcomgazio commented 4 years ago

Why don't set an other name than IDI_APPLICATION like LIBUI_ICON and set a default icon in the libui.dll as res ?

andlabs commented 4 years ago

That could happen. After Alpha 5 is finished I plan on writing a tool for handling situations that cannot be done in source code, presumably called uires, which will handle things like this.

However, making the program icon the first icon in the Windows resource section would be compatible with other programs like Explorer that also do this.