From c0974ca09cb87184a41c37f4c6d12a2b8f56e398 Mon Sep 17 00:00:00 2001 From: Ioannis Tsakpinis Date: Mon, 7 Sep 2015 16:21:27 +0300 Subject: [PATCH] Implement glfwSetWindowIcons on Linux --- src/x11_init.c | 2 ++ src/x11_platform.h | 1 + src/x11_window.c | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/x11_init.c b/src/x11_init.c index 033a06987..4af5f352c 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -443,6 +443,8 @@ static void detectEWMH(void) getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_FULLSCREEN_MONITORS"); _glfw.x11.NET_WM_NAME = getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_NAME"); + _glfw.x11.NET_WM_ICON = + getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_ICON"); _glfw.x11.NET_WM_ICON_NAME = getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_ICON_NAME"); _glfw.x11.NET_WM_PID = diff --git a/src/x11_platform.h b/src/x11_platform.h index b17478f83..240728a67 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -129,6 +129,7 @@ typedef struct _GLFWlibraryX11 Atom WM_STATE; Atom WM_DELETE_WINDOW; Atom NET_WM_NAME; + Atom NET_WM_ICON; Atom NET_WM_ICON_NAME; Atom NET_WM_PID; Atom NET_WM_PING; diff --git a/src/x11_window.c b/src/x11_window.c index 0f78fdae2..ad6a7d1b0 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1647,7 +1647,39 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window, void _glfwPlatformSetWindowIcons(_GLFWwindow* window, GLFWimage* icons, int count) { - // TODO: Implement this + int i, d, p; + long* data; + + // calculate number of elements + int nelements = count * 2; // width & height per icon + for (i = 0, nelements = 0; i < count; i++) + nelements += icons[i].width * icons[i].height; // pixel data + + data = (long*)malloc(sizeof(long), nelements); + + // build property data + for (i = 0, d = 0; i < count; i++) + { + data[d++] = icons[i].width; + data[d++] = icons[i].height; + + for (p = 0; p < icons[i].width * icons[i].height; p++) + { + unsigned char* pixel = icons[i].pixels + p * 4; + data[d++] = // pack to ARGB integer + (pixel[3] << 24) | + (pixel[0] << 16) | + (pixel[1] << 8) | + (pixel[2] << 0) ; + } + } + + XChangeProperty(_glfw.x11.display, window->x11.handle, + _glfw.x11.NET_WM_ICON, + XA_CARDINAL, + 32, PropModeReplace, (unsigned char*)data, nelements); + + free(data); } void _glfwPlatformIconifyWindow(_GLFWwindow* window)