kdeu: get rid of KXUtils::createPixmapFromHandle()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2016-08-15 14:53:16 +00:00
parent bc1e1c3eb4
commit 412fd65b4f
3 changed files with 2 additions and 82 deletions

View file

@ -20,77 +20,11 @@
#include "kxutils.h"
#include <config.h>
#ifdef Q_WS_X11
#include <kxerrorhandler.h>
#include <qbitmap.h>
#include <qpixmap.h>
#ifdef HAVE_XRENDER
#include <X11/extensions/Xrender.h>
#endif
namespace KXUtils
{
// Create QPixmap from X pixmap. Take care of different depths if needed.
QPixmap createPixmapFromHandle( WId pixmap, WId pixmap_mask )
{
Display* dpy = QX11Info::display();
KXErrorHandler handler;
Window root;
int x, y;
unsigned int w = 0;
unsigned int h = 0;
unsigned int border_w, depth;
if( XGetGeometry( dpy, pixmap, &root, &x, &y, &w, &h, &border_w, &depth )
&& !handler.error( false ) && w > 0 && h > 0 )
{
QPixmap pm( w, h );
// Always detach before doing something behind QPixmap's back.
pm.detach();
#ifdef HAVE_XRENDER
if( int( depth ) != pm.depth() && depth != 1 && pm.x11PictureHandle() != None )
{
XRenderPictFormat tmpl;
tmpl.type = PictTypeDirect;
tmpl.depth = depth;
XRenderPictFormat* format = XRenderFindFormat( dpy, PictFormatType | PictFormatDepth, &tmpl, 0 );
Picture pic = XRenderCreatePicture( dpy, pixmap, format, 0, NULL );
XRenderComposite( dpy, PictOpSrc, pic, None, pm.x11PictureHandle(), 0, 0, 0, 0, 0, 0, w, h );
XRenderFreePicture( dpy, pic );
}
else
#endif
{ // the normal X11 way
GC gc = XCreateGC( dpy, pixmap, 0, NULL );
if( depth == 1 )
{
QBitmap bm( w, h );
XCopyArea( dpy, pixmap, bm.handle(), gc, 0, 0, w, h, 0, 0 );
pm = bm;
}
else // depth == pm.depth()
XCopyArea( dpy, pixmap, pm.handle(), gc, 0, 0, w, h, 0, 0 );
XFreeGC( dpy, gc );
}
if( pixmap_mask != None )
{
QBitmap bm( w, h );
bm.detach();
GC gc = XCreateGC( dpy, pixmap_mask, 0, NULL );
XCopyArea( dpy, pixmap_mask, bm.handle(), gc, 0, 0, w, h, 0, 0 );
pm.setMask( bm );
XFreeGC( dpy, gc );
}
if( !handler.error( true )) // sync, check for error
return pm;
}
return QPixmap();
}
// Functions for X timestamp comparing. For Time being 32bit they're fairly simple
// (the #if 0 part), but on 64bit architectures Time is 64bit unsigned long,

View file

@ -21,8 +21,7 @@
#ifndef KXUTILS_H
#define KXUTILS_H
#include <QtGui/QWidget>
#include <QtGui/QPixmap>
#include <QtCore/qglobal.h>
#ifdef Q_WS_X11
@ -33,15 +32,6 @@
*/
namespace KXUtils
{
/**
* Creates a QPixmap that contains a copy of the pixmap given by the X handle @p pixmap
* and optionally also mask given as another X handle @mask. This function tries to
* also handle the case when the depth of the pixmap differs from the native QPixmap depth.
* @since 4.0.2
*/
KDEUI_EXPORT QPixmap createPixmapFromHandle( WId pixmap, WId mask = 0 );
/**
* Compares two X timestamps, taking into account wrapping and 64bit architectures.
* Return value is like with strcmp(), 0 for equal, -1 for time1 < time2, 1 for time1 > time2.

View file

@ -659,20 +659,16 @@ QPixmap KWindowSystem::icon( WId win, int width, int height, bool scale, int fla
if( flags & WMHints ) {
Pixmap p = None;
Pixmap p_mask = None;
XWMHints *hints = XGetWMHints(QX11Info::display(), win );
if (hints && (hints->flags & IconPixmapHint)){
p = hints->icon_pixmap;
}
if (hints && (hints->flags & IconMaskHint)){
p_mask = hints->icon_mask;
}
if (hints)
XFree((char*)hints);
if (p != None){
QPixmap pm = KXUtils::createPixmapFromHandle( p, p_mask );
QPixmap pm = QPixmap::fromX11Pixmap( p );
if ( scale && width > 0 && height > 0 && !pm.isNull()
&& ( pm.width() != width || pm.height() != height) ){
result = QPixmap::fromImage( pm.toImage().scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );