Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / kwin / lib / kwinglobals.cpp
blob5c30fe4e4820015055a393f234a78db2181282cf
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
21 #include "kwinglobals.h"
23 #include <config-workspace.h>
24 #include <config-X11.h>
26 #include <assert.h>
28 #include <kdebug.h>
30 #include <X11/Xlib.h>
31 #include <X11/extensions/shape.h>
33 #ifdef HAVE_XRENDER
34 #include <X11/extensions/Xrender.h>
35 #endif
36 #ifdef HAVE_XFIXES
37 #include <X11/extensions/Xfixes.h>
38 #endif
39 #ifdef HAVE_XDAMAGE
40 #include <X11/extensions/Xdamage.h>
41 #endif
42 #ifdef HAVE_XRANDR
43 #include <X11/extensions/Xrandr.h>
44 #endif
45 #ifdef HAVE_XCOMPOSITE
46 #include <X11/extensions/Xcomposite.h>
47 #endif
48 #ifdef HAVE_OPENGL
49 #include <GL/glx.h>
50 #endif
51 #ifdef HAVE_XSYNC
52 #include <X11/extensions/sync.h>
53 #endif
55 namespace KWin
58 int Extensions::shape_version = 0;
59 int Extensions::shape_event_base = 0;
60 bool Extensions::has_randr = false;
61 int Extensions::randr_event_base = 0;
62 bool Extensions::has_damage = false;
63 int Extensions::damage_event_base = 0;
64 int Extensions::composite_version = 0;
65 int Extensions::fixes_version = 0;
66 int Extensions::render_version = 0;
67 bool Extensions::has_glx = false;
68 bool Extensions::has_sync = false;
69 int Extensions::sync_event_base = 0;
70 // for fillExtensionsData()
71 const char* Extensions::data_extensions[ 32 ];
72 int Extensions::data_nextensions;
73 int Extensions::data_opcodes[ 32 ];
74 int Extensions::data_error_bases[ 32 ];
76 void Extensions::addData( const char* name )
78 assert( data_nextensions < 32 );
79 int opcode, event_base, error_base;
80 XQueryExtension( display(), name, &opcode, &event_base, &error_base );
81 data_extensions[ data_nextensions ] = name;
82 data_opcodes[ data_nextensions ] = opcode;
83 data_error_bases[ data_nextensions ] = error_base;
84 ++data_nextensions;
87 void Extensions::init()
89 int event_base, error_base;
90 data_nextensions = 0;
91 shape_version = 0;
92 if( XShapeQueryExtension( display(), &shape_event_base, &error_base ))
94 int major, minor;
95 if( XShapeQueryVersion( display(), &major, &minor ))
97 shape_version = major * 0x10 + minor;
98 addData( "SHAPE" );
101 #ifdef HAVE_XRANDR
102 has_randr = XRRQueryExtension( display(), &randr_event_base, &error_base );
103 if( has_randr )
105 int major, minor;
106 XRRQueryVersion( display(), &major, &minor );
107 has_randr = ( major > 1 || ( major == 1 && minor >= 1 ) );
108 addData( "RANDR" );
110 #else
111 has_randr = false;
112 #endif
113 #ifdef HAVE_XDAMAGE
114 has_damage = XDamageQueryExtension( display(), &damage_event_base, &error_base );
115 if( has_damage )
116 addData( "DAMAGE" );
117 #else
118 has_damage = false;
119 #endif
120 composite_version = 0;
121 #ifdef HAVE_XCOMPOSITE
122 if( XCompositeQueryExtension( display(), &event_base, &error_base ))
124 int major = 0, minor = 0;
125 XCompositeQueryVersion( display(), &major, &minor );
126 composite_version = major * 0x10 + minor;
127 addData( "Composite" );
129 #endif
130 fixes_version = 0;
131 #ifdef HAVE_XFIXES
132 if( XFixesQueryExtension( display(), &event_base, &error_base ))
134 int major = 0, minor = 0;
135 XFixesQueryVersion( display(), &major, &minor );
136 fixes_version = major * 0x10 + minor;
137 addData( "XFIXES" );
139 #endif
140 render_version = 0;
141 #ifdef HAVE_XRENDER
142 if( XRenderQueryExtension( display(), &event_base, &error_base ))
144 int major = 0, minor = 0;
145 XRenderQueryVersion( display(), &major, &minor );
146 render_version = major * 0x10 + minor;
147 addData( "RENDER" );
149 #endif
150 has_glx = false;
151 #ifdef HAVE_OPENGL
152 has_glx = glXQueryExtension( display(), &event_base, &error_base );
153 if( has_glx )
154 addData( "GLX" );
155 #endif
156 #ifdef HAVE_XSYNC
157 if( XSyncQueryExtension( display(), &sync_event_base, &error_base ))
159 int major = 0, minor = 0;
160 if( XSyncInitialize( display(), &major, &minor ))
162 has_sync = true;
163 addData( "SYNC" );
166 #endif
167 kDebug( 1212 ) << "Extensions: shape: 0x" << QString::number( shape_version, 16 )
168 << " composite: 0x" << QString::number( composite_version, 16 )
169 << " render: 0x" << QString::number( render_version, 16 )
170 << " fixes: 0x" << QString::number( fixes_version, 16 ) << endl;
173 void Extensions::fillExtensionsData( const char**& extensions, int& nextensions, int*&opcodes, int*& error_bases )
175 extensions = data_extensions;
176 nextensions = data_nextensions;
177 opcodes = data_opcodes;
178 error_bases = data_error_bases;
181 int Extensions::shapeNotifyEvent()
183 return shape_event_base + ShapeNotify;
186 // does the window w need a shape combine mask around it?
187 bool Extensions::hasShape( Window w )
189 int xws, yws, xbs, ybs;
190 unsigned int wws, hws, wbs, hbs;
191 int boundingShaped = 0, clipShaped = 0;
192 if( !shapeAvailable())
193 return false;
194 XShapeQueryExtents(display(), w,
195 &boundingShaped, &xws, &yws, &wws, &hws,
196 &clipShaped, &xbs, &ybs, &wbs, &hbs);
197 return boundingShaped != 0;
200 bool Extensions::shapeInputAvailable()
202 return shape_version >= 0x11; // 1.1
205 int Extensions::randrNotifyEvent()
207 #ifdef HAVE_XRANDR
208 return randr_event_base + RRScreenChangeNotify;
209 #else
210 return 0;
211 #endif
214 int Extensions::damageNotifyEvent()
216 #ifdef HAVE_XDAMAGE
217 return damage_event_base + XDamageNotify;
218 #else
219 return 0;
220 #endif
223 bool Extensions::compositeOverlayAvailable()
225 return composite_version >= 0x03; // 0.3
228 bool Extensions::fixesRegionAvailable()
230 return fixes_version >= 0x30; // 3
233 int Extensions::syncAlarmNotifyEvent()
235 #ifdef HAVE_XSYNC
236 return sync_event_base + XSyncAlarmNotify;
237 #else
238 return 0;
239 #endif
242 } // namespace