download qdesktopwidget_x11.cpp
Language: C++
License: GPL
Copyright: (C) 1992-2002 Trolltech AS. All rights reserved.
LOC: 224
Project Info
FacturaLUX
Server: SourceForge
Type: cvs
...rototipo\src\qt\src\kernel\
   makepsheader.pl
   q1xcompatibility.h
   qabstractlayout.cpp
   qabstractlayout.h
   qaccel.cpp
   qaccel.h
   qaccessible.cpp
   qaccessible.h
   qapplication.cpp
   qapplication.h
   qapplication_p.h
   qapplication_x11.cpp
   qasyncimageio.cpp
   qasyncimageio.h
   qasyncio.cpp
   qasyncio.h
   qbitmap.cpp
   qbitmap.h
   qbrush.h
   qclipboard.cpp
   qclipboard.h
   qclipboard_x11.cpp
   qcolor.cpp
   qcolor.h
   qcolor_p.cpp
   qcolor_p.h
   qcolor_x11.cpp
   qcomplextext.cpp
   qcomplextext_p.h
   qconnection.cpp
   qconnection.h
   qcursor.cpp
   qcursor.h
   qcursor_x11.cpp
   qdesktopwidget.h
   qdesktopwidget_x11.cpp
   qdnd_x11.cpp
   qdragobject.cpp
   qdragobject.h
   qdrawutil.cpp
   qdrawutil.h
   qdropsite.cpp
   qdropsite.h
   qevent.cpp
   qevent.h
   qeventloop.cpp
   qeventloop.h
   qeventloop_p.h
   qeventloop_unix.cpp
   qeventloop_x11.cpp
   qfocusdata.cpp
   qfocusdata.h
   qfont.cpp
   qfont.h
   qfont_x11.cpp
   qfontdata_p.h
   qfontdatabase.cpp
   qfontdatabase.h
   qfontdatabase_x11.cpp
   qfontengine_p.h
   qfontengine_x11.cpp
   qfontinfo.h
   qfontmetrics.h
   qgif.h
   qgplugin.cpp
   qgplugin.h
   qguardedptr.cpp
   qguardedptr.h
   qiconset.cpp
   qiconset.h
   qimage.cpp
   qimage.h
   qimageformatinterface_p.h
   qimageformatplugin.cpp
   qimageformatplugin.h
   qinputcontext_p.h
   qinputcontext_x11.cpp
   qinternal.cpp
   qinternal_p.h
   qjpegio.cpp
   qjpegio.h
   qkeycode.h
   qkeysequence.cpp
   qkeysequence.h
   qlayout.cpp
   qlayout.h
   qlayoutengine.cpp
   qlayoutengine_p.h
   qlocalfs.cpp
   qlocalfs.h
   qlock.cpp
   qlock_p.h
   qmetaobject.cpp
   qmetaobject.h
   qmime.cpp
   qmime.h
   qmngio.cpp
   qmngio.h
   qmotifdnd_x11.cpp
   qmovie.cpp
   qmovie.h
   qnamespace.h
   qnetworkprotocol.cpp
   qnetworkprotocol.h
   qobject.cpp
   qobject.h
   qobjectcleanuphandler.cpp
   qobjectcleanuphandler.h
   qobjectdefs.h
   qobjectdict.h
   qobjectlist.h
   qpaintdevice.h
   qpaintdevice_x11.cpp
   qpaintdevicedefs.h
   qpaintdevicemetrics.cpp
   qpaintdevicemetrics.h
   qpainter.cpp
   qpainter.h
   qpainter_p.h
   qpainter_x11.cpp
   qpalette.cpp
   qpalette.h
   qpen.h
   qpicture.cpp
   qpicture.h
   qpixmap.cpp
   qpixmap.h
   qpixmap_x11.cpp
   qpixmapcache.cpp
   qpixmapcache.h
   qpngio.cpp
   qpngio.h
   qpoint.cpp
   qpoint.h
   qpointarray.cpp
   qpointarray.h
   qpolygonscanner.cpp
   qpolygonscanner.h
   qprinter.cpp
   qprinter.h
   qprinter_p.h
   qprinter_unix.cpp
   qprocess.cpp
   qprocess.h
   qprocess_unix.cpp
   qpsprinter.cpp
   qpsprinter.ps
   qpsprinter_p.h
   qrect.cpp
   qrect.h
   qregion.cpp
   qregion.h
   qregion_x11.cpp
   qrichtext.cpp
   qrichtext_p.cpp
   qrichtext_p.h
   qscriptengine.cpp
   qscriptengine_p.h
   qscriptengine_x11.cpp
   qsession.h
   qsessionmanager.h
   qsharedmemory_p.cpp
   qsharedmemory_p.h
   qsignal.cpp
   qsignal.h
   qsignalmapper.cpp
   qsignalmapper.h
   qsignalslotimp.h
   qsimplerichtext.cpp
   qsimplerichtext.h
   qsize.cpp
   qsize.h
   qsizegrip.cpp
   qsizegrip.h
   qsizepolicy.h
   qsocketnotifier.cpp
   qsocketnotifier.h
   qsound.cpp
   qsound.h
   qsound_x11.cpp
   qstyle.cpp
   qstyle.h
   qstylesheet.cpp
   qstylesheet.h
   qt.h
   qt_compat.pri
   qt_gfx.pri
   qt_kernel.pri
   qt_x11.pri
   qt_x11_p.h
   qtaddons_x11.cpp
   qtextengine.cpp
   qtextengine_p.h
   qtextengine_unix.cpp
   qtextlayout.cpp
   qtextlayout_p.h
   qthread.cpp
   qthread.h
   qthread_unix.cpp
   qtimer.cpp
   qtimer.h
   qtranslator.cpp
   qtranslator.h
   qucomextra.cpp
   qucomextra_p.h
   qurl.cpp
   qurl.h
   qurlinfo.cpp
   qurlinfo.h
   qurloperator.cpp
   qurloperator.h
   qvariant.cpp
   qvariant.h
   qvfbhdr.h
   qwidget.cpp
   qwidget.h
   qwidget_p.h
   qwidget_x11.cpp
   qwidgetcreate_x11.cpp
   qwidgetintdict.h
   qwidgetlist.h
   qwindow.cpp
   qwindow.h
   qwindowdefs.h
   qwmatrix.cpp
   qwmatrix.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/****************************************************************************
** $Id: qdesktopwidget_x11.cpp,v 1.1 2003/12/04 08:17:55 falbujer Exp $
**
** Implementation of QDesktopWidget class.
**
** Copyright (C) 1992-2002 Trolltech AS.  All rights reserved.
**
** This file is part of the kernel module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
** licenses for Unix/X11 may use this file in accordance with the Qt Commercial
** License Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
**   information about Qt Commercial License Agreements.
** See http://www.trolltech.com/qpl/ for QPL licensing information.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/

#include "qdesktopwidget.h"
#include "qapplication.h"
#include "qobjectlist.h"
#include "qt_x11_p.h"

// defined in qwidget_x11.cpp
extern int qt_x11_create_desktop_on_screen;

// defined in qapplication_x11.cpp
extern Atom qt_net_workarea;
extern bool qt_net_supports(Atom atom);

// function to update the workarea of the screen
static bool qt_desktopwidget_workarea_dirty = TRUE;
void qt_desktopwidget_update_workarea()
{
    qt_desktopwidget_workarea_dirty = TRUE;
}


class QSingleDesktopWidget : public QWidget
{
public:
    QSingleDesktopWidget();
    ~QSingleDesktopWidget();
};

QSingleDesktopWidget::QSingleDesktopWidget()
    : QWidget( 0, "desktop", WType_Desktop )
{
}

QSingleDesktopWidget::~QSingleDesktopWidget()
{
    while ( children() )
        removeChild( children()->getFirst() );
}


class QDesktopWidgetPrivate
{
public:
    QDesktopWidgetPrivate();
    ~QDesktopWidgetPrivate();

    void init();

    bool use_xinerama;
    int defaultScreen;
    int screenCount;

    QWidget **screens;
    QRect *rects;
    QRect *workareas;
};

QDesktopWidgetPrivate::QDesktopWidgetPrivate()
    : use_xinerama(FALSE), defaultScreen(0), screenCount(1),
      screens( 0 ), rects( 0 ), workareas( 0 )
{
}

QDesktopWidgetPrivate::~QDesktopWidgetPrivate()
{
    if ( screens ) {
	for ( int i = 0; i < screenCount; ++i ) {
	    if (i == defaultScreen) continue;
	    delete screens[i];
	    screens[i] = 0;
	}

	delete [] screens;
    }

    if ( rects )     delete [] rects;
    if ( workareas ) delete [] workareas;
}

void QDesktopWidgetPrivate::init()
{
    // get the screen count
#ifndef QT_NO_XINERAMA
    XineramaScreenInfo *xinerama_screeninfo = 0;
    int unused;
    use_xinerama = (XineramaQueryExtension(QPaintDevice::x11AppDisplay(),
					   &unused, &unused) &&
		    XineramaIsActive(QPaintDevice::x11AppDisplay()));

    if (use_xinerama) {
	xinerama_screeninfo =
	    XineramaQueryScreens(QPaintDevice::x11AppDisplay(), &screenCount);
	defaultScreen = 0;
    } else
#endif // QT_NO_XINERAMA
    {
	defaultScreen = DefaultScreen(QPaintDevice::x11AppDisplay());
	screenCount = ScreenCount(QPaintDevice::x11AppDisplay());
    }

    delete [] rects;
    rects     = new QRect[ screenCount ];
    delete [] workareas;
    workareas = new QRect[ screenCount ];

    // get the geometry of each screen
    int i, x, y, w, h;
    for ( i = 0; i < screenCount; i++ ) {

#ifndef QT_NO_XINERAMA
	if (use_xinerama) {
	    x = xinerama_screeninfo[i].x_org;
	    y = xinerama_screeninfo[i].y_org;
	    w = xinerama_screeninfo[i].width;
	    h = xinerama_screeninfo[i].height;
	} else
#endif // QT_NO_XINERAMA
	    {
		x = 0;
		y = 0;
		w = WidthOfScreen(ScreenOfDisplay(QPaintDevice::x11AppDisplay(), i));
		h = HeightOfScreen(ScreenOfDisplay(QPaintDevice::x11AppDisplay(), i));
	    }

	rects[i].setRect(x, y, w, h);
	workareas[i] = QRect();
    }

#ifndef QT_NO_XINERAMA
    if (xinerama_screeninfo)
	XFree(xinerama_screeninfo);
#endif // QT_NO_XINERAMA

}

// the QDesktopWidget itself will be created on the default screen
// as qt_x11_create_desktop_on_screen defaults to -1
QDesktopWidget::QDesktopWidget()
    : QWidget( 0, "desktop", WType_Desktop )
{
    d = new QDesktopWidgetPrivate();

    /*
      we don't call d->init() here, since the initial resize event
      will end up calling init() a second time, which is inefficient.
      instead, for the sending of all posted event to the desktop
      widget (including the initial resize event, which calls
      d->init()).
    */
    QApplication::sendPostedEvents( this, 0 );
}

QDesktopWidget::~QDesktopWidget()
{
    delete d;
}

bool QDesktopWidget::isVirtualDesktop() const
{
    return d->use_xinerama;
}

int QDesktopWidget::primaryScreen() const
{
    return d->defaultScreen;
}

int QDesktopWidget::numScreens() const
{
    return d->screenCount;
}

QWidget *QDesktopWidget::screen( int screen )
{
    if (d->use_xinerama)
	return this;

    if ( screen < 0 || screen >= d->screenCount )
	screen = d->defaultScreen;

    if ( ! d->screens ) {
	d->screens = new QWidget*[ d->screenCount ];
	memset( d->screens, 0, d->screenCount * sizeof( QWidget * ) );
	d->screens[ d->defaultScreen ] = this;
    }

    if ( ! d->screens[screen] ||               // not created yet
	 ! d->screens[screen]->isDesktop() ) { // reparented away
	qt_x11_create_desktop_on_screen = screen;
	d->screens[screen] = new QSingleDesktopWidget;
	qt_x11_create_desktop_on_screen = -1;
    }

    return d->screens[screen];
}

const QRect& QDesktopWidget::availableGeometry( int screen ) const
{
    if ( qt_desktopwidget_workarea_dirty ) {
	// the workareas are dirty, invalidate them
	for ( int i = 0; i < d->screenCount; ++i )
	    d->workareas[i] = QRect();
	qt_desktopwidget_workarea_dirty = FALSE;
    }

    if ( screen < 0 || screen >= d->screenCount )
	screen = d->defaultScreen;

    if ( d->workareas[screen].isValid() )
	return d->workareas[screen];

    if ( ! isVirtualDesktop() && qt_net_supports( qt_net_workarea ) ) {
	Atom ret;
	int format, e;
	unsigned char *data = 0;
	unsigned long nitems, after;

	e = XGetWindowProperty( QPaintDevice::x11AppDisplay(),
				QPaintDevice::x11AppRootWindow( screen ),
				qt_net_workarea, 0, 4, False, XA_CARDINAL,
				&ret, &format, &nitems, &after, &data );

	if (e == Success && ret == XA_CARDINAL &&
	    format == 32 && nitems == 4) {
	    long *workarea = (long *) data;
	    d->workareas[screen].setRect( workarea[0], workarea[1],
					  workarea[2], workarea[3] );
	} else {
	    d->workareas[screen] = screenGeometry(screen);
	}
	if ( data )
	    XFree( data );
    } else {
	d->workareas[screen] = screenGeometry(screen);
    }

    return d->workareas[screen];
}

const QRect& QDesktopWidget::screenGeometry( int screen ) const
{
    if ( screen < 0 || screen >= d->screenCount )
	screen = d->defaultScreen;

    return d->rects[ screen ];
}

int QDesktopWidget::screenNumber( QWidget *widget ) const
{
    if ( !widget )
	return d->defaultScreen;

#ifndef QT_NO_XINERAMA
    if (d->use_xinerama) {
	// this is how we do it for xinerama
	QRect frame = widget->frameGeometry();
	if ( !widget->isTopLevel() )
	    frame.moveTopLeft( widget->mapToGlobal( QPoint( 0, 0 ) ) );

	int maxSize = -1;
	int maxScreen = -1;

	for ( int i = 0; i < d->screenCount; ++i ) {
	    QRect sect = d->rects[i].intersect( frame );
	    int size = sect.width() * sect.height();
	    if ( size > maxSize && sect.width() > 0 && sect.height() > 0 ) {
		maxSize = size;
		maxScreen = i;
	    }
	}
	return maxScreen;
    }
#endif // QT_NO_XINERAMA

    return widget->x11Screen();
}

int QDesktopWidget::screenNumber( const QPoint &point ) const
{
    for ( int i = 0; i < d->screenCount; ++i ) {
	if ( d->rects[i].contains( point ) )
	    return i;
    }
    return -1;
}

void QDesktopWidget::resizeEvent( QResizeEvent *event )
{
    d->init();
    qt_desktopwidget_workarea_dirty = TRUE;
    QWidget::resizeEvent( event );
}

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us