1 /****************************************************************************
3 ** This file is based on sources of the Qt GUI Toolkit, used under the terms
4 ** of the GNU General Public License version 2 (see the original copyright
6 ** All further contributions to this file are (and are required to be)
7 ** licensed under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 of the License, or
9 ** (at your option) any later version.
11 ** The original Qt license header follows:
14 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
16 ** This file is part of the kernel module of the Qt GUI Toolkit.
18 ** This file may be distributed under the terms of the Q Public License
19 ** as defined by Trolltech AS of Norway and appearing in the file
20 ** LICENSE.QPL included in the packaging of this file.
22 ** This file may be distributed and/or modified under the terms of the
23 ** GNU General Public License version 2 as published by the Free Software
24 ** Foundation and appearing in the file LICENSE.GPL included in the
25 ** packaging of this file.
27 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
28 ** licenses may use this file in accordance with the Qt Commercial License
29 ** Agreement provided with the Software.
31 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
32 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
34 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
35 ** information about Qt Commercial License Agreements.
36 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
37 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
39 ** Contact info@trolltech.com if any conditions of this licensing are
42 **********************************************************************/
44 #include <config-workspace.h>
45 #include <config-X11.h>
47 #include "qnamespace.h"
54 extern "C" { // for older XFree86 versions
55 #include <X11/extensions/Xinerama.h>
65 Colormap spl_colormap
;
68 static Display
* appDpy
;
69 static int appScreenCount
;
71 static QRect totalScreenRect
;
72 static vector
<QRect
> screenRects
;
80 QRect
totalScreenGeometry()
82 return totalScreenRect
;
85 QRect
screenGeometry(int screen
)
87 if (screen
< 0 || screen
> screens
- 1)
91 return screenRects
[screen
];
94 void detectScreenGeometry()
96 Display
* dpy
= x11Display();
97 totalScreenRect
= QRect(0,
99 WidthOfScreen( ScreenOfDisplay( dpy
, DefaultScreen( dpy
))),
100 HeightOfScreen( ScreenOfDisplay( dpy
, DefaultScreen( dpy
))));
102 // Xinerama code from Qt
103 XineramaScreenInfo
*xinerama_screeninfo
= 0;
105 bool use_xinerama
= XineramaQueryExtension( dpy
, &unused
, &unused
)
106 && XineramaIsActive( dpy
);
109 xinerama_screeninfo
= XineramaQueryScreens( dpy
, &screens
);
113 for (int s
= 0; s
< screens
; ++s
)
115 QRect
cs(xinerama_screeninfo
[s
].x_org
,
116 xinerama_screeninfo
[s
].y_org
,
117 xinerama_screeninfo
[s
].width
,
118 xinerama_screeninfo
[s
].height
);
119 screenRects
.push_back(cs
);
126 screenRects
.push_back(totalScreenRect
);
130 void createColormap()
132 // use default colormap
133 XStandardColormap
*stdcmap
;
135 XVisualIDFromVisual((Visual
*) spl_visual
);
139 Display
* appDpy
= spl_dpy
;
140 int screen
= spl_screen
;
142 if ( true /*|| ! serverVendor.contains( "Hewlett-Packard" )*/ ) {
143 // on HPUX 10.20 local displays, the RGB_DEFAULT_MAP colormap
144 // doesn't give us correct colors. Why this happens, I have
145 // no clue, so we disable this for HPUX
146 if (XGetRGBColormaps(appDpy
,
147 RootWindow(spl_dpy
,spl_screen
)/*QPaintDevice::x11AppRootWindow( screen )*/,
148 &stdcmap
, &count
, XA_RGB_DEFAULT_MAP
)) {
152 if (stdcmap
[i
].visualid
== vid
) {
159 XFree( (char *)stdcmap
);
163 if (spl_colormap
== 0) {
165 DefaultColormap(appDpy
, screen
);
170 int x11ErrorHandler(Display
*d
, XErrorEvent
*e
)
172 char msg
[80], req
[80], number
[80];
173 XGetErrorText(d
, e
->error_code
, msg
, sizeof(msg
));
174 sprintf(number
, "%d", e
->request_code
);
175 XGetErrorDatabaseText(d
, "XRequest", number
, "<unknown>", req
, sizeof(req
));
177 fprintf(stderr
, "%s(0x%lx): %s\n", req
, e
->resourceid
, msg
);
183 spl_dpy
= XOpenDisplay( NULL
);
184 if( spl_dpy
== NULL
)
186 XSetErrorHandler( x11ErrorHandler
);
187 spl_screen
= DefaultScreen( spl_dpy
);
188 spl_depth
= DefaultDepth( spl_dpy
, spl_screen
);
189 spl_visual
= DefaultVisual( spl_dpy
, spl_screen
);
190 spl_cells
= DisplayCells( spl_dpy
, spl_screen
);
191 appScreenCount
= ScreenCount( spl_dpy
);
194 detectScreenGeometry();
195 QColor::initialize();
201 XCloseDisplay( spl_dpy
);
204 static GC
* app_gc_ro
= 0; // read-only GC
205 static GC
* app_gc_tmp
= 0; // temporary GC
206 static GC
* app_gc_ro_m
= 0; // read-only GC (monochrome)
207 static GC
* app_gc_tmp_m
= 0; // temporary GC (monochrome)
209 static GC
create_gc( int scrn
, bool monochrome
)
213 Pixmap pm
= XCreatePixmap( appDpy
, RootWindow( appDpy
, scrn
), 8, 8, 1 );
214 gc
= XCreateGC( appDpy
, pm
, 0, 0 );
215 XFreePixmap( appDpy
, pm
);
217 if ( QPaintDevice::x11AppDefaultVisual( scrn
) ) {
218 gc
= XCreateGC( appDpy
, RootWindow( appDpy
, scrn
), 0, 0 );
221 XSetWindowAttributes a
;
222 a
.background_pixel
= Qt::black
.pixel( scrn
);
223 a
.border_pixel
= Qt::black
.pixel( scrn
);
224 a
.colormap
= QPaintDevice::x11AppColormap( scrn
);
225 w
= XCreateWindow( appDpy
, RootWindow( appDpy
, scrn
), 0, 0, 100, 100,
226 0, QPaintDevice::x11AppDepth( scrn
), InputOutput
,
227 (Visual
*)QPaintDevice::x11AppVisual( scrn
),
228 CWBackPixel
|CWBorderPixel
|CWColormap
, &a
);
229 gc
= XCreateGC( appDpy
, w
, 0, 0 );
230 XDestroyWindow( appDpy
, w
);
233 XSetGraphicsExposures( appDpy
, gc
, False
);
237 GC
qt_xget_readonly_gc( int scrn
, bool monochrome
) // get read-only GC
239 if ( scrn
< 0 || scrn
>= appScreenCount
) {
241 qDebug("invalid screen %d %d", scrn
, appScreenCount
);
243 bla
->setName("hello");
248 if ( !app_gc_ro_m
) // create GC for bitmap
249 memset( (app_gc_ro_m
= new GC
[appScreenCount
]), 0, appScreenCount
* sizeof( GC
) );
250 if ( !app_gc_ro_m
[scrn
] )
251 app_gc_ro_m
[scrn
] = create_gc( scrn
, true );
252 gc
= app_gc_ro_m
[scrn
];
253 } else { // create standard GC
255 memset( (app_gc_ro
= new GC
[appScreenCount
]), 0, appScreenCount
* sizeof( GC
) );
256 if ( !app_gc_ro
[scrn
] )
257 app_gc_ro
[scrn
] = create_gc( scrn
, false );
258 gc
= app_gc_ro
[scrn
];
263 GC
qt_xget_temp_gc( int scrn
, bool monochrome
) // get temporary GC
265 if ( scrn
< 0 || scrn
>= appScreenCount
) {
267 qDebug("invalid screen (tmp) %d %d", scrn
, appScreenCount
);
269 bla
->setName("hello");
274 if ( !app_gc_tmp_m
) // create GC for bitmap
275 memset( (app_gc_tmp_m
= new GC
[appScreenCount
]), 0, appScreenCount
* sizeof( GC
) );
276 if ( !app_gc_tmp_m
[scrn
] )
277 app_gc_tmp_m
[scrn
] = create_gc( scrn
, true );
278 gc
= app_gc_tmp_m
[scrn
];
279 } else { // create standard GC
281 memset( (app_gc_tmp
= new GC
[appScreenCount
]), 0, appScreenCount
* sizeof( GC
) );
282 if ( !app_gc_tmp
[scrn
] )
283 app_gc_tmp
[scrn
] = create_gc( scrn
, false );
284 gc
= app_gc_tmp
[scrn
];