From 6dd025ae7bdf4c7bb900a8d2db27b87d9335f32b Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 8 Aug 2018 18:45:32 -0300 Subject: [PATCH] x11/skia: Add Display::setIcons() impl --- src/she/skia/skia_display.cpp | 4 +++- src/she/x11/window.cpp | 40 +++++++++++++++++++++++++++++++++++ src/she/x11/window.h | 2 ++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/she/skia/skia_display.cpp b/src/she/skia/skia_display.cpp index 3e7f9b8de..e51fada48 100644 --- a/src/she/skia/skia_display.cpp +++ b/src/she/skia/skia_display.cpp @@ -139,7 +139,9 @@ void SkiaDisplay::setTitleBar(const std::string& title) void SkiaDisplay::setIcons(const SurfaceList& icons) { - // TODO copy the Allegro impl +#if !defined(_WIN32) && !defined(__APPLE__) + m_window.setIcons(icons); +#endif } NativeCursor SkiaDisplay::nativeMouseCursor() diff --git a/src/she/x11/window.cpp b/src/she/x11/window.cpp index 0a2962729..512f98ace 100644 --- a/src/she/x11/window.cpp +++ b/src/she/x11/window.cpp @@ -201,6 +201,46 @@ void X11Window::setTitle(const std::string& title) XSetWMName(m_display, m_window, &prop); } +void X11Window::setIcons(const SurfaceList& icons) +{ + if (!m_display || !m_window) + return; + + bool first = true; + for (Surface* icon : icons) { + const int w = icon->width(); + const int h = icon->height(); + + SurfaceFormatData format; + icon->getFormat(&format); + + std::vector data(w*h+2); + int i = 0; + data[i++] = w; + data[i++] = h; + for (int y=0; ygetData(0, y); + for (int x=0; x> format.blueShift ) ) | + (((c & format.greenMask) >> format.greenShift) << 8) | + (((c & format.redMask ) >> format.redShift ) << 16) | + (((c & format.alphaMask) >> format.alphaShift) << 24); + } + } + + Atom _NET_WM_ICON = XInternAtom(m_display, "_NET_WM_ICON", False); + XChangeProperty( + m_display, m_window, _NET_WM_ICON, XA_CARDINAL, 32, + first ? PropModeReplace: + PropModeAppend, + (const unsigned char*)&data[0], data.size()); + + first = false; + } +} + gfx::Size X11Window::clientSize() const { Window root; diff --git a/src/she/x11/window.h b/src/she/x11/window.h index c3a2c87e0..cdff8f752 100644 --- a/src/she/x11/window.h +++ b/src/she/x11/window.h @@ -11,6 +11,7 @@ #include "gfx/fwd.h" #include "gfx/size.h" #include "she/native_cursor.h" +#include "she/surface_list.h" #include #include @@ -34,6 +35,7 @@ public: void setScale(const int scale); void setTitle(const std::string& title); + void setIcons(const SurfaceList& icons); gfx::Size clientSize() const; gfx::Size restoredSize() const;