show OTC icon in the window bar on linux

This commit is contained in:
Eduardo Bart 2011-11-22 23:16:14 -02:00
parent 18c122c71e
commit 8f2ad83756
4 changed files with 28 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

View File

@ -45,6 +45,7 @@ public:
void sleep(ulong ms);
bool createWindow(int x, int y, int width, int height, int minWidth, int minHeight, bool maximized);
void setWindowIcon(const std::string& pngIcon);
void destroyWindow();
void showWindow();
void hideWindow();

View File

@ -34,6 +34,9 @@
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <framework/thirdparty/apngloader.h>
#include <framework/core/resourcemanager.h>
struct X11PlatformPrivate {
Display *display;
XVisualInfo *visual;
@ -695,6 +698,28 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i
return true;
}
void Platform::setWindowIcon(const std::string& pngIcon)
{
apng_data apng;
std::stringstream fin;
g_resources.loadFile(pngIcon, fin);
if(load_apng(fin, &apng) == 0) {
int n = apng.width * apng.height;
std::vector<unsigned long int> iconData(n + 2);
iconData[0] = apng.width;
iconData[1] = apng.height;
for(int i=0; i < n;++i)
iconData[2 + i] = *(uint32_t*)(apng.pdata + (i * 4));
Atom property = XInternAtom(x11.display, "_NET_WM_ICON", 0);
if(!XChangeProperty(x11.display, x11.window, property, XA_CARDINAL, 32, PropModeReplace, (const unsigned char*)&iconData[0], iconData.size()))
logError("could not set app icon");
free_apng(&apng);
} else
logError("could not load app icon");
}
void Platform::destroyWindow()
{
if(x11.glxContext) {

View File

@ -64,6 +64,7 @@ void OTClient::init(std::vector<std::string> args)
loadConfigurations();
// create the client window
//TODO: bind these functions and move to otclient module
int minWidth = 550;
int minHeight = 450;
int windowX = Fw::fromstring(g_configs.get("window x"), 0);
@ -73,6 +74,7 @@ void OTClient::init(std::vector<std::string> args)
bool maximized = Fw::fromstring(g_configs.get("window maximized"), false);
g_platform.createWindow(windowX, windowY, windowWidth, windowHeight, minWidth, minHeight, maximized);
g_platform.setWindowTitle(Otc::AppName);
g_platform.setWindowIcon("otclient/otcicon.png");
// initialize graphics
g_graphics.init();