1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the gui module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
31
#include "qx11info_x11.h"
36
\brief The QX11Info class provides information about the X display
39
The class provides two APIs: a set of non-static functions that
40
provide information about a specific widget or pixmap, and a set
41
of static functions that provide the default information for the
44
\warning This class is only available on X11.
46
\sa QWidget::x11Info(), QPixmap::x11Info(), QDesktopWidget
50
Constructs an empty QX11Info object.
58
Constructs a copy of \a other.
60
QX11Info::QX11Info(const QX11Info &other)
62
x11data = other.x11data;
67
Assigns \a other to this object and returns a reference to this
70
QX11Info &QX11Info::operator=(const QX11Info &other)
72
QX11InfoData *x = other.x11data;
74
x = qAtomicSetPtr(&x11data, x);
81
Destroys the QX11Info object.
85
if (x11data && !--x11data->ref)
91
Makes a shallow copy of the X11-specific data of \a fromDevice, if it is not
92
null. Otherwise this function sets it to null.
95
void QX11Info::copyX11Data(const QPaintDevice *fromDevice)
99
if (fromDevice->devType() == QInternal::Widget)
100
xd = static_cast<const QWidget *>(fromDevice)->x11Info().x11data;
101
else if (fromDevice->devType() == QInternal::Pixmap)
102
xd = static_cast<const QPixmap *>(fromDevice)->x11Info().x11data;
109
Makes a deep copy of the X11-specific data of \a fromDevice, if it is not
110
null. Otherwise this function sets it to null.
113
void QX11Info::cloneX11Data(const QPaintDevice *fromDevice)
118
if (fromDevice->devType() == QInternal::Widget) {
119
xd = static_cast<const QWidget *>(fromDevice)->x11Info().x11data;
121
Q_ASSERT(fromDevice->devType() == QInternal::Pixmap);
122
xd = static_cast<const QPixmap *>(fromDevice)->x11Info().x11data;
124
d = new QX11InfoData(*xd);
132
Makes a shallow copy of the X11-specific data \a d and assigns it to this
133
class. This function increments the reference code of \a d.
136
void QX11Info::setX11Data(const QX11InfoData* d)
138
if (x11data && !--x11data->ref)
140
x11data = (QX11InfoData *)d;
148
If \a def is false, returns a deep copy of the x11Data, or 0 if x11Data is 0.
149
If \a def is true, makes a QX11Data struct filled with the default
152
In either case the caller is responsible for deleting the returned
153
struct. But notice that the struct is a shared class, so other
154
classes might also have a reference to it. The reference count of
155
the returned QX11Data* is 0.
158
QX11InfoData* QX11Info::getX11Data(bool def) const
160
QX11InfoData* res = 0;
162
res = new QX11InfoData;
163
res->screen = appScreen();
164
res->depth = appDepth();
165
res->cells = appCells();
166
res->colormap = colormap();
167
res->defaultColormap = appDefaultColormap();
168
res->visual = (Visual*) appVisual();
169
res->defaultVisual = appDefaultVisual();
170
} else if (x11data) {
171
res = new QX11InfoData;
179
Returns the horizontal resolution of the given \a screen in terms of the
180
number of dots per inch.
182
\sa setAppDpiX(), appDpiY()
184
int QX11Info::appDpiX(int screen)
189
screen = X11->defaultScreen;
190
if (screen > X11->screenCount)
192
return X11->screens[screen].dpiX;
196
Sets the horizontal resolution of the given \a screen to the number of
197
dots per inch specified by \a xdpi.
199
\sa appDpiX(), setAppDpiY()
202
void QX11Info::setAppDpiX(int screen, int xdpi)
207
screen = X11->defaultScreen;
208
if (screen > X11->screenCount)
210
X11->screens[screen].dpiX = xdpi;
214
Returns the vertical resolution of the given \a screen in terms of the
215
number of dots per inch.
217
\sa setAppDpiY(), appDpiX()
220
int QX11Info::appDpiY(int screen)
225
screen = X11->defaultScreen;
226
if (screen > X11->screenCount)
228
return X11->screens[screen].dpiY;
232
Sets the vertical resolution of the given \a screen to the number of
233
dots per inch specified by \a ydpi.
235
\sa appDpiY(), setAppDpiX()
237
void QX11Info::setAppDpiY(int screen, int ydpi)
242
screen = X11->defaultScreen;
243
if (screen > X11->screenCount)
245
X11->screens[screen].dpiY = ydpi;
249
Returns the X11 time.
251
\sa setAppTime(), appUserTime()
253
unsigned long QX11Info::appTime()
255
return X11 ? X11->time : 0;
259
Sets the X11 time to the value specified by \a time.
261
\sa appTime(), setAppUserTime()
263
void QX11Info::setAppTime(unsigned long time)
271
Returns the X11 user time.
273
\sa setAppUserTime(), appTime()
275
unsigned long QX11Info::appUserTime()
277
return X11 ? X11->userTime : 0;
281
Sets the X11 user time as specified by \a time.
283
\sa appUserTime(), setAppTime()
285
void QX11Info::setAppUserTime(unsigned long time)
288
X11->userTime = time;
294
\fn const char *QX11Info::appClass()
296
Returns the X11 application class.
302
Returns the default display for the application.
307
Display *QX11Info::display()
309
return X11 ? X11->display : 0;
313
Returns the number of the screen where the application is being
316
\sa display(), screen()
318
int QX11Info::appScreen()
320
return X11 ? X11->defaultScreen : 0;
324
Returns a handle for the application's color map on the given \a screen.
326
\sa colormap(), defaultColormap()
328
Qt::HANDLE QX11Info::appColormap(int screen)
330
return X11->screens[screen == -1 ? X11->defaultScreen : screen].colormap;
334
Returns the current visual used by the application on the given
337
\sa visual(), defaultVisual()
340
void *QX11Info::appVisual(int screen)
342
return X11->screens[screen == -1 ? X11->defaultScreen : screen].visual;
346
Returns a handle for the applications root window on the given \a screen.
348
\sa QApplication::desktop()
350
Qt::HANDLE QX11Info::appRootWindow(int screen)
352
return RootWindow(X11->display, screen == -1 ? X11->defaultScreen : screen);
356
Returns the color depth (bits per pixel) used by the application on the
362
int QX11Info::appDepth(int screen)
364
return X11->screens[screen == -1 ? X11->defaultScreen : screen].depth; }
367
Returns the number of cells used by the application on the given \a screen.
372
int QX11Info::appCells(int screen)
373
{ return X11->screens[screen == -1 ? X11->defaultScreen : screen].cells; }
376
Returns true if the application has a default color map on the given
377
\a screen; otherwise returns false.
379
bool QX11Info::appDefaultColormap(int screen)
380
{ return X11->screens[screen == -1 ? X11->defaultScreen : screen].defaultColormap; }
383
Returns true if the application has a default visual on the given \a screen;
384
otherwise returns false.
386
bool QX11Info::appDefaultVisual(int screen)
387
{ return X11->screens[screen == -1 ? X11->defaultScreen : screen].defaultVisual; }
390
Returns the number of the screen currently in use.
394
int QX11Info::screen() const
395
{ return x11data ? x11data->screen : QX11Info::appScreen(); }
398
Returns the color depth (bits per pixel) of the X display.
403
int QX11Info::depth() const
404
{ return x11data ? x11data->depth : QX11Info::appDepth(); }
407
Returns the number of cells.
412
int QX11Info::cells() const
413
{ return x11data ? x11data->cells : QX11Info::appCells(); }
416
Returns a handle for the color map.
418
\sa defaultColormap()
421
Qt::HANDLE QX11Info::colormap() const
422
{ return x11data ? x11data->colormap : QX11Info::appColormap(); }
425
Returns true if there is a default color map; otherwise returns false.
430
bool QX11Info::defaultColormap() const
431
{ return x11data ? x11data->defaultColormap : QX11Info::appDefaultColormap(); }
434
Returns the current visual.
436
\sa appVisual(), defaultVisual()
439
void *QX11Info::visual() const
440
{ return x11data ? x11data->visual : QX11Info::appVisual(); }
443
Returns true if there is a default visual; otherwise returns false.
445
\sa visual(), appVisual()
448
bool QX11Info::defaultVisual() const
449
{ return x11data ? x11data->defaultVisual : QX11Info::appDefaultVisual(); }