~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/kernel/qx11info_x11.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the gui module of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "qwidget.h"
 
30
#include "qpixmap.h"
 
31
#include "qx11info_x11.h"
 
32
#include "qt_x11_p.h"
 
33
 
 
34
/*!
 
35
    \class QX11Info
 
36
    \brief The QX11Info class provides information about the X display
 
37
    configuration.
 
38
 
 
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
 
42
    application.
 
43
 
 
44
    \warning This class is only available on X11.
 
45
 
 
46
    \sa QWidget::x11Info(), QPixmap::x11Info(), QDesktopWidget
 
47
*/
 
48
 
 
49
/*!
 
50
    Constructs an empty QX11Info object.
 
51
*/
 
52
QX11Info::QX11Info()
 
53
    : x11data(0)
 
54
{
 
55
}
 
56
 
 
57
/*!
 
58
    Constructs a copy of \a other.
 
59
*/
 
60
QX11Info::QX11Info(const QX11Info &other)
 
61
{
 
62
    x11data = other.x11data;
 
63
    ++x11data->ref;
 
64
}
 
65
 
 
66
/*!
 
67
    Assigns \a other to this object and returns a reference to this
 
68
    object.
 
69
*/
 
70
QX11Info &QX11Info::operator=(const QX11Info &other)
 
71
{
 
72
    QX11InfoData *x = other.x11data;
 
73
    ++x->ref;
 
74
    x = qAtomicSetPtr(&x11data, x);
 
75
    if (x && !--x->ref)
 
76
        delete x;
 
77
    return *this;
 
78
}
 
79
 
 
80
/*!
 
81
    Destroys the QX11Info object.
 
82
*/
 
83
QX11Info::~QX11Info()
 
84
{
 
85
    if (x11data && !--x11data->ref)
 
86
        delete x11data;
 
87
}
 
88
 
 
89
/*!
 
90
    \internal
 
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.
 
93
*/
 
94
 
 
95
void QX11Info::copyX11Data(const QPaintDevice *fromDevice)
 
96
{
 
97
    QX11InfoData *xd = 0;
 
98
    if (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;
 
103
    }
 
104
    setX11Data(xd);
 
105
}
 
106
 
 
107
/*!
 
108
    \internal
 
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.
 
111
*/
 
112
 
 
113
void QX11Info::cloneX11Data(const QPaintDevice *fromDevice)
 
114
{
 
115
    QX11InfoData *d = 0;
 
116
    if (fromDevice) {
 
117
        QX11InfoData *xd;
 
118
        if (fromDevice->devType() == QInternal::Widget) {
 
119
            xd = static_cast<const QWidget *>(fromDevice)->x11Info().x11data;
 
120
        } else {
 
121
            Q_ASSERT(fromDevice->devType() == QInternal::Pixmap);
 
122
            xd = static_cast<const QPixmap *>(fromDevice)->x11Info().x11data;
 
123
        }
 
124
        d = new QX11InfoData(*xd);
 
125
        d->ref = 0;
 
126
    }
 
127
    setX11Data(d);
 
128
}
 
129
 
 
130
/*!
 
131
    \internal
 
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.
 
134
*/
 
135
 
 
136
void QX11Info::setX11Data(const QX11InfoData* d)
 
137
{
 
138
    if (x11data && !--x11data->ref)
 
139
        delete x11data;
 
140
    x11data = (QX11InfoData *)d;
 
141
    if (x11data)
 
142
        ++x11data->ref;
 
143
}
 
144
 
 
145
 
 
146
/*!
 
147
    \internal
 
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
 
150
    values.
 
151
 
 
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.
 
156
*/
 
157
 
 
158
QX11InfoData* QX11Info::getX11Data(bool def) const
 
159
{
 
160
    QX11InfoData* res = 0;
 
161
    if (def) {
 
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;
 
172
        *res = *x11data;
 
173
    }
 
174
    res->ref = 0;
 
175
    return res;
 
176
}
 
177
 
 
178
/*!
 
179
    Returns the horizontal resolution of the given \a screen in terms of the
 
180
    number of dots per inch.
 
181
 
 
182
    \sa setAppDpiX(), appDpiY()
 
183
*/
 
184
int QX11Info::appDpiX(int screen)
 
185
{
 
186
    if (!X11)
 
187
        return 75;
 
188
    if (screen < 0)
 
189
        screen = X11->defaultScreen;
 
190
    if (screen > X11->screenCount)
 
191
        return 0;
 
192
    return X11->screens[screen].dpiX;
 
193
}
 
194
 
 
195
/*!
 
196
    Sets the horizontal resolution of the given \a screen to the number of
 
197
    dots per inch specified by \a xdpi.
 
198
 
 
199
    \sa appDpiX(), setAppDpiY()
 
200
*/
 
201
 
 
202
void QX11Info::setAppDpiX(int screen, int xdpi)
 
203
{
 
204
    if (!X11)
 
205
        return;
 
206
    if (screen < 0)
 
207
        screen = X11->defaultScreen;
 
208
    if (screen > X11->screenCount)
 
209
        return;
 
210
    X11->screens[screen].dpiX = xdpi;
 
211
}
 
212
 
 
213
/*!
 
214
    Returns the vertical resolution of the given \a screen in terms of the
 
215
    number of dots per inch.
 
216
 
 
217
    \sa setAppDpiY(), appDpiX()
 
218
*/
 
219
 
 
220
int QX11Info::appDpiY(int screen)
 
221
{
 
222
    if (!X11)
 
223
        return 75;
 
224
    if (screen < 0)
 
225
        screen = X11->defaultScreen;
 
226
    if (screen > X11->screenCount)
 
227
        return 0;
 
228
    return X11->screens[screen].dpiY;
 
229
}
 
230
 
 
231
/*!
 
232
    Sets the vertical resolution of the given \a screen to the number of
 
233
    dots per inch specified by \a ydpi.
 
234
 
 
235
    \sa appDpiY(), setAppDpiX()
 
236
*/
 
237
void QX11Info::setAppDpiY(int screen, int ydpi)
 
238
{
 
239
    if (!X11)
 
240
        return;
 
241
    if (screen < 0)
 
242
        screen = X11->defaultScreen;
 
243
    if (screen > X11->screenCount)
 
244
        return;
 
245
    X11->screens[screen].dpiY = ydpi;
 
246
}
 
247
 
 
248
/*!
 
249
    Returns the X11 time.
 
250
 
 
251
    \sa setAppTime(), appUserTime()
 
252
*/
 
253
unsigned long QX11Info::appTime()
 
254
{
 
255
    return X11 ? X11->time : 0;
 
256
}
 
257
 
 
258
/*!
 
259
    Sets the X11 time to the value specified by \a time.
 
260
 
 
261
    \sa appTime(), setAppUserTime()
 
262
*/
 
263
void QX11Info::setAppTime(unsigned long time)
 
264
{
 
265
    if (X11) {
 
266
        X11->time = time;
 
267
    }
 
268
}
 
269
 
 
270
/*!
 
271
    Returns the X11 user time.
 
272
 
 
273
    \sa setAppUserTime(), appTime()
 
274
*/
 
275
unsigned long QX11Info::appUserTime()
 
276
{
 
277
    return X11 ? X11->userTime : 0;
 
278
}
 
279
 
 
280
/*!
 
281
    Sets the X11 user time as specified by \a time.
 
282
 
 
283
    \sa appUserTime(), setAppTime()
 
284
*/
 
285
void QX11Info::setAppUserTime(unsigned long time)
 
286
{
 
287
    if (X11) {
 
288
        X11->userTime = time;
 
289
    }
 
290
}
 
291
 
 
292
 
 
293
/*!
 
294
    \fn const char *QX11Info::appClass()
 
295
 
 
296
    Returns the X11 application class.
 
297
 
 
298
    \sa display()
 
299
*/
 
300
 
 
301
/*!
 
302
    Returns the default display for the application.
 
303
 
 
304
    \sa appScreen()
 
305
*/
 
306
 
 
307
Display *QX11Info::display()
 
308
{
 
309
    return X11 ? X11->display : 0;
 
310
}
 
311
 
 
312
/*!
 
313
    Returns the number of the screen where the application is being
 
314
    displayed.
 
315
 
 
316
    \sa display(), screen()
 
317
*/
 
318
int QX11Info::appScreen()
 
319
{
 
320
    return X11 ? X11->defaultScreen : 0;
 
321
}
 
322
 
 
323
/*!
 
324
    Returns a handle for the application's color map on the given \a screen.
 
325
 
 
326
    \sa colormap(), defaultColormap()
 
327
*/
 
328
Qt::HANDLE QX11Info::appColormap(int screen)
 
329
{
 
330
    return X11->screens[screen == -1 ? X11->defaultScreen : screen].colormap;
 
331
}
 
332
 
 
333
/*!
 
334
    Returns the current visual used by the application on the given
 
335
    \a screen.
 
336
 
 
337
    \sa visual(), defaultVisual()
 
338
*/
 
339
 
 
340
void *QX11Info::appVisual(int screen)
 
341
{
 
342
    return X11->screens[screen == -1 ? X11->defaultScreen : screen].visual;
 
343
}
 
344
 
 
345
/*!
 
346
    Returns a handle for the applications root window on the given \a screen.
 
347
 
 
348
    \sa QApplication::desktop()
 
349
*/
 
350
Qt::HANDLE QX11Info::appRootWindow(int screen)
 
351
{
 
352
    return RootWindow(X11->display, screen == -1 ? X11->defaultScreen : screen);
 
353
}
 
354
 
 
355
/*!
 
356
    Returns the color depth (bits per pixel) used by the application on the
 
357
    given \a screen.
 
358
 
 
359
    \sa depth()
 
360
*/
 
361
 
 
362
int QX11Info::appDepth(int screen)
 
363
{
 
364
    return X11->screens[screen == -1 ? X11->defaultScreen : screen].depth; }
 
365
 
 
366
/*!
 
367
    Returns the number of cells used by the application on the given \a screen.
 
368
 
 
369
    \sa cells()
 
370
*/
 
371
 
 
372
int QX11Info::appCells(int screen)
 
373
{ return X11->screens[screen == -1 ? X11->defaultScreen : screen].cells; }
 
374
 
 
375
/*!
 
376
    Returns true if the application has a default color map on the given
 
377
    \a screen; otherwise returns false.
 
378
*/
 
379
bool QX11Info::appDefaultColormap(int screen)
 
380
{ return X11->screens[screen == -1 ? X11->defaultScreen : screen].defaultColormap; }
 
381
 
 
382
/*!
 
383
    Returns true if the application has a default visual on the given \a screen;
 
384
    otherwise returns false.
 
385
*/
 
386
bool QX11Info::appDefaultVisual(int screen)
 
387
{ return X11->screens[screen == -1 ? X11->defaultScreen : screen].defaultVisual; }
 
388
 
 
389
/*!
 
390
    Returns the number of the screen currently in use.
 
391
 
 
392
    \sa appScreen()
 
393
*/
 
394
int QX11Info::screen() const
 
395
{ return x11data ? x11data->screen : QX11Info::appScreen(); }
 
396
 
 
397
/*!
 
398
    Returns the color depth (bits per pixel) of the X display.
 
399
 
 
400
    \sa appDepth()
 
401
*/
 
402
 
 
403
int QX11Info::depth() const
 
404
{ return x11data ? x11data->depth : QX11Info::appDepth(); }
 
405
 
 
406
/*!
 
407
    Returns the number of cells.
 
408
 
 
409
    \sa appCells()
 
410
*/
 
411
 
 
412
int QX11Info::cells() const
 
413
{ return x11data ? x11data->cells : QX11Info::appCells(); }
 
414
 
 
415
/*!
 
416
    Returns a handle for the color map.
 
417
 
 
418
    \sa defaultColormap()
 
419
*/
 
420
 
 
421
Qt::HANDLE QX11Info::colormap() const
 
422
{ return x11data ? x11data->colormap : QX11Info::appColormap(); }
 
423
 
 
424
/*!
 
425
    Returns true if there is a default color map; otherwise returns false.
 
426
 
 
427
    \sa colormap()
 
428
*/
 
429
 
 
430
bool QX11Info::defaultColormap() const
 
431
{ return x11data ? x11data->defaultColormap : QX11Info::appDefaultColormap(); }
 
432
 
 
433
/*!
 
434
    Returns the current visual.
 
435
 
 
436
    \sa appVisual(), defaultVisual()
 
437
*/
 
438
 
 
439
void *QX11Info::visual() const
 
440
{ return x11data ? x11data->visual : QX11Info::appVisual(); }
 
441
 
 
442
/*!
 
443
    Returns true if there is a default visual; otherwise returns false.
 
444
 
 
445
    \sa visual(), appVisual()
 
446
*/
 
447
 
 
448
bool QX11Info::defaultVisual() const
 
449
{ return x11data ? x11data->defaultVisual : QX11Info::appDefaultVisual(); }