Implement QXcbWindow::setWindowIcon

Change-Id: I1908cbef0c20d3725423b559f234bd6d3ddd4167
Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
Reviewed-by: Uli Schlachter <psychon@znc.in>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
This commit is contained in:
Corentin Jabot 2012-05-25 12:11:58 +02:00 committed by Qt by Nokia
parent 074224eca0
commit 6131b90953
4 changed files with 49 additions and 0 deletions

View File

@ -906,6 +906,7 @@ static const char * xcb_atomnames = {
// Property formats // Property formats
"TEXT\0" "TEXT\0"
"UTF8_STRING\0" "UTF8_STRING\0"
"CARDINAL\0"
// xdnd // xdnd
"XdndEnter\0" "XdndEnter\0"

View File

@ -183,6 +183,7 @@ namespace QXcbAtom {
// Property formats // Property formats
TEXT, TEXT,
UTF8_STRING, UTF8_STRING,
CARDINAL,
// Xdnd // Xdnd
XdndEnter, XdndEnter,

View File

@ -43,12 +43,14 @@
#include <QtDebug> #include <QtDebug>
#include <QScreen> #include <QScreen>
#include <QtGui/QIcon>
#include "qxcbconnection.h" #include "qxcbconnection.h"
#include "qxcbscreen.h" #include "qxcbscreen.h"
#include "qxcbdrag.h" #include "qxcbdrag.h"
#include "qxcbkeyboard.h" #include "qxcbkeyboard.h"
#include "qxcbwmsupport.h" #include "qxcbwmsupport.h"
#include "qxcbimage.h"
#include <qpa/qplatformintegration.h> #include <qpa/qplatformintegration.h>
@ -1122,6 +1124,49 @@ void QXcbWindow::setWindowTitle(const QString &title)
ba.constData())); ba.constData()));
} }
void QXcbWindow::setWindowIcon(const QIcon &icon)
{
QVector<quint32> icon_data;
if (!icon.isNull()) {
QList<QSize> availableSizes = icon.availableSizes();
if (availableSizes.isEmpty()) {
// try to use default sizes since the icon can be a scalable image like svg.
availableSizes.push_back(QSize(16,16));
availableSizes.push_back(QSize(32,32));
availableSizes.push_back(QSize(64,64));
availableSizes.push_back(QSize(128,128));
}
for (int i = 0; i < availableSizes.size(); ++i) {
QSize size = availableSizes.at(i);
QPixmap pixmap = icon.pixmap(size);
if (!pixmap.isNull()) {
QImage image = pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
int pos = icon_data.size();
icon_data.resize(pos + 2 + image.width()*image.height());
icon_data[pos++] = image.width();
icon_data[pos++] = image.height();
memcpy(icon_data.data() + pos, image.bits(), image.width()*image.height()*4);
}
}
}
if (!icon_data.isEmpty()) {
Q_XCB_CALL(xcb_change_property(xcb_connection(),
XCB_PROP_MODE_REPLACE,
m_window,
atom(QXcbAtom::_NET_WM_ICON),
atom(QXcbAtom::CARDINAL),
32,
icon_data.size(),
(unsigned char *) icon_data.data()));
} else {
Q_XCB_CALL(xcb_delete_property(xcb_connection(),
m_window,
atom(QXcbAtom::_NET_WM_ICON)));
}
}
void QXcbWindow::raise() void QXcbWindow::raise()
{ {
const quint32 mask = XCB_CONFIG_WINDOW_STACK_MODE; const quint32 mask = XCB_CONFIG_WINDOW_STACK_MODE;

View File

@ -55,6 +55,7 @@ QT_BEGIN_NAMESPACE
class QXcbScreen; class QXcbScreen;
class QXcbEGLSurface; class QXcbEGLSurface;
class QIcon;
class QXcbWindow : public QXcbObject, public QPlatformWindow class QXcbWindow : public QXcbObject, public QPlatformWindow
{ {
@ -88,6 +89,7 @@ public:
bool isExposed() const; bool isExposed() const;
void setWindowTitle(const QString &title); void setWindowTitle(const QString &title);
void setWindowIcon(const QIcon &icon);
void raise(); void raise();
void lower(); void lower();
void propagateSizeHints(); void propagateSizeHints();