add more spacing
[personal-kdebase.git] / workspace / ksplash / ksplashx / x11_defs.cpp
blobd39c5cc82143078f6d3c800d73523e372b332e35
1 /****************************************************************************
2 **
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
5 ** notice below).
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
40 ** not clear to you.
42 **********************************************************************/
44 #include <config-workspace.h>
45 #include <config-X11.h>
47 #include "qnamespace.h"
48 #include "qcolor.h"
49 #include "x11_defs.h"
50 #include <vector>
51 #include <string.h>
53 #ifdef HAVE_XINERAMA
54 extern "C" { // for older XFree86 versions
55 #include <X11/extensions/Xinerama.h>
57 #endif
59 using namespace std;
61 Display* spl_dpy;
62 int spl_screen;
63 void* spl_visual;
64 int spl_depth;
65 Colormap spl_colormap;
66 int spl_cells;
68 static Display* appDpy;
69 static int appScreenCount;
71 static QRect totalScreenRect;
72 static vector<QRect> screenRects;
73 static int screens;
75 int screenCount()
77 return screens;
80 QRect totalScreenGeometry()
82 return totalScreenRect;
85 QRect screenGeometry(int screen)
87 if (screen < 0 || screen > screens - 1)
89 abort();
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 ))));
101 #ifdef HAVE_XINERAMA
102 // Xinerama code from Qt
103 XineramaScreenInfo *xinerama_screeninfo = 0;
104 int unused;
105 bool use_xinerama = XineramaQueryExtension( dpy, &unused, &unused )
106 && XineramaIsActive( dpy );
107 if (use_xinerama)
109 xinerama_screeninfo = XineramaQueryScreens( dpy, &screens );
110 QRect sg;
111 QRect total;
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);
122 else
123 #endif
125 screens = 1;
126 screenRects.push_back(totalScreenRect);
130 void createColormap()
132 // use default colormap
133 XStandardColormap *stdcmap;
134 VisualID vid =
135 XVisualIDFromVisual((Visual *) spl_visual );
136 int i, count;
138 spl_colormap = 0;
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)) {
149 i = 0;
150 while (i < count &&
151 spl_colormap == 0) {
152 if (stdcmap[i].visualid == vid) {
153 spl_colormap =
154 stdcmap[i].colormap;
156 i++;
159 XFree( (char *)stdcmap );
163 if (spl_colormap == 0) {
164 spl_colormap =
165 DefaultColormap(appDpy, screen);
169 static
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);
178 return 0;
181 bool openDisplay()
183 spl_dpy = XOpenDisplay( NULL );
184 if( spl_dpy == NULL )
185 return false;
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 );
192 appDpy = spl_dpy;
193 createColormap();
194 detectScreenGeometry();
195 QColor::initialize();
196 return true;
199 void closeDisplay()
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 )
211 GC gc;
212 if ( monochrome ) {
213 Pixmap pm = XCreatePixmap( appDpy, RootWindow( appDpy, scrn ), 8, 8, 1 );
214 gc = XCreateGC( appDpy, pm, 0, 0 );
215 XFreePixmap( appDpy, pm );
216 } else {
217 if ( QPaintDevice::x11AppDefaultVisual( scrn ) ) {
218 gc = XCreateGC( appDpy, RootWindow( appDpy, scrn ), 0, 0 );
219 } else {
220 Window w;
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 );
234 return gc;
237 GC qt_xget_readonly_gc( int scrn, bool monochrome ) // get read-only GC
239 if ( scrn < 0 || scrn >= appScreenCount ) {
240 #if 0
241 qDebug("invalid screen %d %d", scrn, appScreenCount );
242 QWidget* bla = 0;
243 bla->setName("hello");
244 #endif
246 GC gc;
247 if ( monochrome ) {
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
254 if ( !app_gc_ro )
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];
260 return gc;
263 GC qt_xget_temp_gc( int scrn, bool monochrome ) // get temporary GC
265 if ( scrn < 0 || scrn >= appScreenCount ) {
266 #if 0
267 qDebug("invalid screen (tmp) %d %d", scrn, appScreenCount );
268 QWidget* bla = 0;
269 bla->setName("hello");
270 #endif
272 GC gc;
273 if ( monochrome ) {
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
280 if ( !app_gc_tmp )
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];
286 return gc;