• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • kdeui
  • util
kxutils.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the KDE libraries
3  Copyright (C) 2008 Lubos Lunak (l.lunak@kde.org)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "kxutils.h"
22 
23 #include <config.h>
24 
25 #ifdef Q_WS_X11
26 
27 #include <kxerrorhandler.h>
28 #include <qbitmap.h>
29 #include <qpixmap.h>
30 
31 #ifdef HAVE_XRENDER
32 #include <X11/extensions/Xrender.h>
33 #endif
34 
35 namespace KXUtils
36 {
37 
38 // Create QPixmap from X pixmap. Take care of different depths if needed.
39 QPixmap createPixmapFromHandle( WId pixmap, WId pixmap_mask )
40 {
41  Display* dpy = QX11Info::display();
42  KXErrorHandler handler;
43  Window root;
44  int x, y;
45  unsigned int w = 0;
46  unsigned int h = 0;
47  unsigned int border_w, depth;
48  if( XGetGeometry( dpy, pixmap, &root, &x, &y, &w, &h, &border_w, &depth )
49  && !handler.error( false ) && w > 0 && h > 0 )
50  {
51  QPixmap pm( w, h );
52  // Always detach before doing something behind QPixmap's back.
53  pm.detach();
54 #ifdef HAVE_XRENDER
55  if( int( depth ) != pm.depth() && depth != 1 && pm.x11PictureHandle() != None )
56  {
57  XRenderPictFormat tmpl;
58  tmpl.type = PictTypeDirect;
59  tmpl.depth = depth;
60  XRenderPictFormat* format = XRenderFindFormat( dpy, PictFormatType | PictFormatDepth, &tmpl, 0 );
61  Picture pic = XRenderCreatePicture( dpy, pixmap, format, 0, NULL );
62  XRenderComposite( dpy, PictOpSrc, pic, None, pm.x11PictureHandle(), 0, 0, 0, 0, 0, 0, w, h );
63  XRenderFreePicture( dpy, pic );
64  }
65  else
66 #endif
67  { // the normal X11 way
68  GC gc = XCreateGC( dpy, pixmap, 0, NULL );
69  if( depth == 1 )
70  {
71  QBitmap bm( w, h );
72  XCopyArea( dpy, pixmap, bm.handle(), gc, 0, 0, w, h, 0, 0 );
73  pm = bm;
74  }
75  else // depth == pm.depth()
76  XCopyArea( dpy, pixmap, pm.handle(), gc, 0, 0, w, h, 0, 0 );
77  XFreeGC( dpy, gc );
78  }
79 
80  if( pixmap_mask != None )
81  {
82  QBitmap bm( w, h );
83  bm.detach();
84  GC gc = XCreateGC( dpy, pixmap_mask, 0, NULL );
85  XCopyArea( dpy, pixmap_mask, bm.handle(), gc, 0, 0, w, h, 0, 0 );
86  pm.setMask( bm );
87  XFreeGC( dpy, gc );
88  }
89  if( !handler.error( true )) // sync, check for error
90  return pm;
91  }
92  return QPixmap();
93 }
94 
95 // Functions for X timestamp comparing. For Time being 32bit they're fairly simple
96 // (the #if 0 part), but on 64bit architectures Time is 64bit unsigned long,
97 // so there special care needs to be taken to always use only the lower 32bits.
98 #if 0
99 int timestampCompare( Time time1, Time time2 ) // like strcmp()
100  {
101  if( time1 == time2 )
102  return 0;
103  return ( time1 - time2 ) < 0x7fffffffU ? 1 : -1; // time1 > time2 -> 1, handle wrapping
104  }
105 
106 Time timestampDiff( Time time1, Time time2 ) // returns time2 - time1
107  { // no need to handle wrapping?
108  return time2 - time1;
109  }
110 #else
111 int timestampCompare( unsigned long time1_, unsigned long time2_ ) // like strcmp()
112  {
113  quint32 time1 = time1_;
114  quint32 time2 = time2_;
115  if( time1 == time2 )
116  return 0;
117  return quint32( time1 - time2 ) < 0x7fffffffU ? 1 : -1; // time1 > time2 -> 1, handle wrapping
118  }
119 
120 int timestampDiff( unsigned long time1_, unsigned long time2_ ) // returns time2 - time1
121  { // no need to handle wrapping?
122  quint32 time1 = time1_;
123  quint32 time2 = time2_;
124  return quint32( time2 - time1 );
125  }
126 #endif
127 
128 
129 } // namespace
130 
131 #endif
QPixmap::detach
void detach()
KXErrorHandler::error
bool error(bool sync) const
This function returns true if the error flag is set (i.e.
Definition: kxerrorhandler.cpp:99
QX11Info::display
Display * display()
quint32
KXUtils::timestampCompare
int timestampCompare(unsigned long time1_, unsigned long time2_)
Compares two X timestamps, taking into account wrapping and 64bit architectures.
Definition: kxutils.cpp:111
QBitmap
None
KXUtils::timestampDiff
int timestampDiff(unsigned long time1_, unsigned long time2_)
Returns a difference of two X timestamps, time2 - time1, where time2 must be later than time1...
Definition: kxutils.cpp:120
KXErrorHandler
This class simplifies handling of X errors.
Definition: kxerrorhandler.h:62
QPixmap::depth
int depth() const
QPixmap::handle
Qt::HANDLE handle() const
kxerrorhandler.h
QPixmap
QPixmap::setMask
void setMask(const QBitmap &mask)
Window
QPixmap::x11PictureHandle
Qt::HANDLE x11PictureHandle() const
kxutils.h
KXUtils::createPixmapFromHandle
QPixmap createPixmapFromHandle(WId pixmap, WId pixmap_mask)
Creates a QPixmap that contains a copy of the pixmap given by the X handle pixmap and optionally also...
Definition: kxutils.cpp:39
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:00 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal