1
0
Fork 0

Platform/Unix/X11Display: Implement setIcon()

This commit is contained in:
Henrik Hautakoski 2020-10-27 17:04:10 +01:00
parent 3d9dda64ca
commit f5d80aa46f
2 changed files with 37 additions and 1 deletions

View file

@ -1,6 +1,7 @@
#include <Spectre/Display/DisplayDescription.h> // Prevents conflict with X.h defining "None"
#include <Spectre/System/Log.h>
#include <Spectre/Graphics/Image.h>
#include "X11WindowEventHandler.h"
#include "X11SharedDisplay.h"
#include "GLXContext.h"
@ -116,9 +117,41 @@ void X11Display::setCaption(const std::string& caption)
::XStoreName(m_disp, m_win, caption.c_str());
}
// TODO: Move this up to the non-platform layer.
void X11Display::setIcon(const std::string& icon)
{
// TODO: Implement
Image img;
if (img.loadFromFile(icon)) {
setIcon(img.getWidth(), img.getHeight(), img.getPixels());
}
}
void X11Display::setIcon(unsigned int width, unsigned int height, const uint8_t *pixels)
{
::Atom net_wm_icon = getAtom("_NET_WM_ICON", False);
::Atom cardinal = getAtom("CARDINAL", False);
std::vector<uint64_t> buffer(2 + width * height);
uint64_t *ptr = &buffer[0];
*ptr++ = width;
*ptr++ = height;
// TODO: Conversion between differnet formats should be defined as functions in Graphics/PixelFormat.h
for (std::size_t i = 0; i < width * height; i++) {
*ptr++ = (pixels[i * 4 + 2] << 0)
| (pixels[i * 4 + 1] << 8)
| (pixels[i * 4 + 0] << 16)
| (pixels[i * 4 + 3] << 24);
}
::XChangeProperty(m_disp, m_win,
net_wm_icon, cardinal, 32,
PropModeReplace,
reinterpret_cast<const unsigned char*>(&buffer[0]),
2 + width * height);
XFlush(m_disp);
}
void X11Display::createHiddenCursor()

View file

@ -6,6 +6,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <cstdint>
#include <Platform/PlatformDisplay.h>
namespace sp {
@ -35,6 +36,8 @@ public :
virtual void setIcon(const std::string& icon);
virtual void setIcon(unsigned int width, unsigned int height, const uint8_t *pixels);
virtual void showCursor(bool value);
void processEvent(const ::XEvent& event);