Platform/Unix/X11Display: Implement setIcon()
This commit is contained in:
parent
3d9dda64ca
commit
f5d80aa46f
2 changed files with 37 additions and 1 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue