diff --git a/modules/otclient/otcicon.png b/modules/otclient/otcicon.png new file mode 100644 index 00000000..e804eb1f Binary files /dev/null and b/modules/otclient/otcicon.png differ diff --git a/src/framework/platform/platform.h b/src/framework/platform/platform.h index 409b8aba..1ac0020f 100644 --- a/src/framework/platform/platform.h +++ b/src/framework/platform/platform.h @@ -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(); diff --git a/src/framework/platform/x11platform.cpp b/src/framework/platform/x11platform.cpp index f2380371..40b13a84 100644 --- a/src/framework/platform/x11platform.cpp +++ b/src/framework/platform/x11platform.cpp @@ -34,6 +34,9 @@ #include #include +#include +#include + 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 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) { diff --git a/src/otclient/otclient.cpp b/src/otclient/otclient.cpp index 9929dec7..4fd3cc3b 100644 --- a/src/otclient/otclient.cpp +++ b/src/otclient/otclient.cpp @@ -64,6 +64,7 @@ void OTClient::init(std::vector 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 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();