A WFavicon is an object that represents a favicon that can be set for the application. Changing the favicon can be used to notify the user that something happened on the application, even when the user is looking at another tab. This is less intrusive than a WNotification, and does not require permission from the user.
You can change the favicon to any image that a browser accepts
as a favicon (e.g. PNG, JPEG, ICO). This will only modify the
favicon for the application, so it will only affect the user.
You can go back to the default favicon of the application by
setting the favicon of the application to nullptr.
Tips: You can set the default favicon for an application when
adding the entry point for the application, or you can
configure the default favicon in thewt_config.xml,
by setting the property named favicon.
A WFavicon has 2 states: the default state and the
updated state. This state can be changed using the
update() and reset() methods. Basic
WFavicon are the same image in both states, but
a WFaviconPair is a favicon that shows a different
WFavicon in each state.
#include <Wt/WApplication.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WDocRootDataInfo.h>
#include <Wt/WFaviconPair.h>
#include <Wt/WPushButton.h>
#include <Wt/WResourceFavicon.h>
auto container = std::make_unique<Wt::WContainerWidget>();
auto setCustomFaviconButton = container->addWidget(std::make_unique<Wt::WPushButton>("Set custom favicon"));
auto updateFaviconButton = container->addWidget(std::make_unique<Wt::WPushButton>("Update favicon"));
auto resetFaviconButton = container->addWidget(std::make_unique<Wt::WPushButton>("Reset favicon"));
setCustomFaviconButton->clicked().connect([=](){
auto defaultFavicon = std::make_unique<Wt::WResourceFavicon>(Wt::WDocRootDataInfo("icons/wt.png").filePath());
auto updatedFavicon = std::make_unique<Wt::WResourceFavicon>(Wt::WDocRootDataInfo("icons/wt-update.png").filePath());
auto faviconPair = std::make_unique<Wt::WFaviconPair>(std::move(defaultFavicon), std::move(updatedFavicon));
Wt::WApplication::instance()->setFavicon(std::move(faviconPair));
});
updateFaviconButton->clicked().connect([=](){
Wt::WApplication::instance()->favicon()->update();
});
resetFaviconButton->clicked().connect([=](){
Wt::WApplication::instance()->favicon()->reset();
});