From 8f2ad83756a8ff5700b7ac06ca24574bade38bed Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Tue, 22 Nov 2011 23:16:14 -0200 Subject: [PATCH] show OTC icon in the window bar on linux --- modules/otclient/otcicon.png | Bin 0 -> 248 bytes src/framework/platform/platform.h | 1 + src/framework/platform/x11platform.cpp | 25 +++++++++++++++++++++++++ src/otclient/otclient.cpp | 2 ++ 4 files changed, 28 insertions(+) create mode 100644 modules/otclient/otcicon.png diff --git a/modules/otclient/otcicon.png b/modules/otclient/otcicon.png new file mode 100644 index 0000000000000000000000000000000000000000..e804eb1f666a4866d33f22203698e8d86ebf61ad GIT binary patch literal 248 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85sEH0P$_BmUPZ!4!i_^&o3j_>|3=9k`SW^F} zyMJyhHI|4>nDaM#`Q#-x4J{@&f&lC62miKS=G>In(0R!~!ZhIuL(dcspQ5&vjY~bc ejD?rlB``3|k&;rZ?U`8yveVPm&t;ucLK6U57EP-F literal 0 HcmV?d00001 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();