Friday, August 7, 2020

Setting Icons

The new feature

GWindow's can detect window events and set a window's name, but it cannot set the window's icon. The goal of the new feature is to enable developers to set the icon. It should also be as simple as calling SetIcon() while passing in an array of pixels.


Research

Windows, Mac, and Linux platforms are all going to need an implementation of this feature. I started by researching how the icon can be set dynamically on each platform. I specifically want to know what commonalities there are between platforms, to inform the paraments SetIcon() will require.


Windows

On Windows, the icons on the window, alt-tab display, and taskbar can be changed at runtime. The window icon is 16x16, while the alt-tab and taskbar icons are 24x24. All of these icons are changed when the first message is sent to Windows to change it. As a result, icons get stretched or squashed when they are not the right size for where they are displayed. Fortunately, two separate messages can be sent for different icon sizes. This means we can set the window's icon separate from the icon for the alt-tab display and taskbar. Enabling developers to keep their icons looking crisp by using multiple premade icons of different sizes. 


Linux

Like Windows, a message can be sent to X11 to change the window, alt-tab display, and taskbar icons. However, there is only one message to set icons, and all icons are set in that single message. Also, like Windows, squashing and stretching occurs depending on where icons are displayed. Unfortunately, I will not be able to test if the window icon changes on my computer because my version of Linux Mint doesn't have them.


Mac

Just as with Linux, the windows on Mac do not have icons. The dock icon can be set, but I haven't been able to find if the alt-tab icon can also be set. Icons can be a range of sizes upwards of 1024x1024. The maximum size appears to change every few years. 


Parameters

Every platform will require, at some point, a size (width and height) and an array of pixels before setting the icon. Therefore, the function is going to end up looking something like SetIcon(unsigned int width, unsigned int height, void* pixels).


In progress

Adding this feature seems simple so far. However, the implementation of it on each platform is going to vary. The challenge will be in keeping the result of calling the SetIcon() function the same across each platform. 

No comments:

Post a Comment