Qt 4.8
qx11info_x11.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qwidget.h"
43 #include "qpixmap.h"
44 #include "qx11info_x11.h"
45 #include "qt_x11_p.h"
46 
48 
74  : x11data(0)
75 {
76 }
77 
82 {
83  x11data = other.x11data;
84  if (x11data)
85  ++x11data->ref;
86 }
87 
93 {
94  if (other.x11data)
95  ++other.x11data->ref;
96  if (x11data && !--x11data->ref)
97  delete x11data;
98  x11data = other.x11data;
99  return *this;
100 }
101 
106 {
107  if (x11data && !--x11data->ref)
108  delete x11data;
109 }
110 
120 void QX11Info::copyX11Data(const QPaintDevice *fromDevice)
121 {
122  QX11InfoData *xd = 0;
123  if (fromDevice) {
124  if (fromDevice->devType() == QInternal::Widget)
125  xd = static_cast<const QWidget *>(fromDevice)->x11Info().x11data;
126  else if (fromDevice->devType() == QInternal::Pixmap)
127  xd = static_cast<const QPixmap *>(fromDevice)->x11Info().x11data;
128  }
129  setX11Data(xd);
130 }
131 
141 void QX11Info::cloneX11Data(const QPaintDevice *fromDevice)
142 {
143  QX11InfoData *d = 0;
144  if (fromDevice) {
145  QX11InfoData *xd;
146  if (fromDevice->devType() == QInternal::Widget) {
147  xd = static_cast<const QWidget *>(fromDevice)->x11Info().x11data;
148  } else {
149  Q_ASSERT(fromDevice->devType() == QInternal::Pixmap);
150  xd = static_cast<const QPixmap *>(fromDevice)->x11Info().x11data;
151  }
152  d = new QX11InfoData(*xd);
153  d->ref = 0;
154  }
155  setX11Data(d);
156 }
157 
168 {
169  if (x11data && !--x11data->ref)
170  delete x11data;
171  x11data = (QX11InfoData *)d;
172  if (x11data)
173  ++x11data->ref;
174 }
175 
176 
190 {
191  QX11InfoData* res = 0;
192  if (def) {
193  res = new QX11InfoData;
194  res->ref = 0;
195  res->screen = appScreen();
196  res->depth = appDepth();
197  res->cells = appCells();
198  res->colormap = colormap();
200  res->visual = (Visual*) appVisual();
202  } else if (x11data) {
203  res = new QX11InfoData;
204  *res = *x11data;
205  res->ref = 0;
206  }
207  return res;
208 }
209 
222 {
223  if (!X11)
224  return 75;
225  if (screen < 0)
226  screen = X11->defaultScreen;
227  if (screen > X11->screenCount)
228  return 0;
229  return X11->screens[screen].dpiX;
230 }
231 
244 void QX11Info::setAppDpiX(int screen, int xdpi)
245 {
246  if (!X11)
247  return;
248  if (screen < 0)
249  screen = X11->defaultScreen;
250  if (screen > X11->screenCount)
251  return;
252  X11->screens[screen].dpiX = xdpi;
253 }
254 
268 {
269  if (!X11)
270  return 75;
271  if (screen < 0)
272  screen = X11->defaultScreen;
273  if (screen > X11->screenCount)
274  return 0;
275  return X11->screens[screen].dpiY;
276 }
277 
289 void QX11Info::setAppDpiY(int screen, int ydpi)
290 {
291  if (!X11)
292  return;
293  if (screen < 0)
294  screen = X11->defaultScreen;
295  if (screen > X11->screenCount)
296  return;
297  X11->screens[screen].dpiY = ydpi;
298 }
299 
305 unsigned long QX11Info::appTime()
306 {
307  return X11 ? X11->time : 0;
308 }
309 
315 void QX11Info::setAppTime(unsigned long time)
316 {
317  if (X11) {
318  X11->time = time;
319  }
320 }
321 
327 unsigned long QX11Info::appUserTime()
328 {
329  return X11 ? X11->userTime : 0;
330 }
331 
337 void QX11Info::setAppUserTime(unsigned long time)
338 {
339  if (X11) {
340  X11->userTime = time;
341  }
342 }
343 
344 
360 {
361  return X11 ? X11->display : 0;
362 }
363 
371 {
372  return X11 ? X11->defaultScreen : 0;
373 }
374 
386 {
387  return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].colormap : 0;
388 }
389 
403 {
404  return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].visual : 0;
405 }
406 
418 {
419  return X11 ? RootWindow(X11->display, screen == -1 ? X11->defaultScreen : screen) : 0;
420 }
421 
435 {
436  return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].depth : 32;
437 }
438 
451 { return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].cells : 0; }
452 
463 { return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].defaultColormap : true; }
464 
475 { return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].defaultVisual : true; }
476 
487 int QX11Info::screen() const
488 { return x11data ? x11data->screen : QX11Info::appScreen(); }
489 
496 int QX11Info::depth() const
497 { return x11data ? x11data->depth : QX11Info::appDepth(); }
498 
505 int QX11Info::cells() const
506 { return x11data ? x11data->cells : QX11Info::appCells(); }
507 
516 
525 
532 void *QX11Info::visual() const
533 { return x11data ? x11data->visual : QX11Info::appVisual(); }
534 
543 
544 
554 {
555  return X11 ? X11->compositingManagerRunning : false;
556 }
557 
double d
Definition: qnumeric_p.h:62
int depth() const
Returns the color depth (bits per pixel) of the X display.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static int appScreen()
Returns the number of the screen where the application is being displayed.
static unsigned long appUserTime()
Returns the X11 user time.
int cells() const
Returns the number of cells.
static int appDepth(int screen=-1)
Returns the color depth (bits per pixel) used by the application on the given screen.
static void setAppTime(unsigned long time)
Sets the X11 time to the value specified by time.
static bool appDefaultVisual(int screen=-1)
Returns true if the application has a default visual on the given screen; otherwise returns false...
static Qt::HANDLE appRootWindow(int screen=-1)
Returns a handle for the applications root window on the given screen.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define X11
Definition: qt_x11_p.h:724
virtual int devType() const
Definition: qpaintdevice.h:167
QX11InfoData * x11data
Definition: qx11info_x11.h:105
static unsigned long appTime()
Returns the X11 time.
static bool isCompositingManagerRunning()
Returns true if there is a compositing manager running.
void cloneX11Data(const QPaintDevice *)
Makes a deep copy of the X11-specific data of fromDevice, if it is not null.
QX11InfoData * getX11Data(bool def=false) const
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
~QX11Info()
Destroys the QX11Info object.
static int appDpiX(int screen=-1)
Returns the horizontal resolution of the given screen in terms of the number of dots per inch...
static void setAppDpiY(int screen, int dpi)
Sets the vertical resolution of the given screen to the number of dots per inch specified by ydpi...
static bool appDefaultColormap(int screen=-1)
Returns true if the application has a default color map on the given screen; otherwise returns false...
bool defaultVisual() const
Returns true if there is a default visual; otherwise returns false.
static void setAppUserTime(unsigned long time)
Sets the X11 user time as specified by time.
Qt::HANDLE colormap() const
Returns a handle for the color map.
void * HANDLE
Definition: qnamespace.h:1671
void * visual() const
Returns the current visual.
static Qt::HANDLE appColormap(int screen=-1)
Returns a handle for the application&#39;s color map on the given screen.
QX11Info()
Constructs an empty QX11Info object.
Visual * visual
Definition: qt_x11_p.h:318
void copyX11Data(const QPaintDevice *)
Makes a shallow copy of the X11-specific data of fromDevice, if it is not null.
struct _XDisplay Display
Definition: qwindowdefs.h:115
The QX11Info class provides information about the X display configuration.
Definition: qx11info_x11.h:63
static void * appVisual(int screen=-1)
Returns the current visual used by the application on the given screen.
bool defaultColormap() const
Returns true if there is a default color map; otherwise returns false.
Colormap colormap
Definition: qt_x11_p.h:317
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QX11Info & operator=(const QX11Info &other)
Assigns other to this object and returns a reference to this object.
void setX11Data(const QX11InfoData *)
Makes a shallow copy of the X11-specific data d and assigns it to this class.
bool defaultColormap
Definition: qt_x11_p.h:319
static int appCells(int screen=-1)
Returns the number of cells used by the application on the given screen.
static void setAppDpiX(int screen, int dpi)
Sets the horizontal resolution of the given screen to the number of dots per inch specified by xdpi...
static Display * display()
Returns the default display for the application.
int screen() const
Returns the number of the screen currently in use.
bool defaultVisual
Definition: qt_x11_p.h:320
static int appDpiY(int screen=-1)
Returns the vertical resolution of the given screen in terms of the number of dots per inch...