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>
31 #include <X11/extensions/shape.h>
34 #include <X11/extensions/Xrender.h>
37 #include <X11/extensions/Xfixes.h>
40 #include <X11/extensions/Xdamage.h>
43 #include <X11/extensions/Xrandr.h>
45 #ifdef HAVE_XCOMPOSITE
46 #include <X11/extensions/Xcomposite.h>
52 #include <X11/extensions/sync.h>
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
;
87 void Extensions::init()
89 int event_base
, error_base
;
92 if( XShapeQueryExtension( display(), &shape_event_base
, &error_base
))
95 if( XShapeQueryVersion( display(), &major
, &minor
))
97 shape_version
= major
* 0x10 + minor
;
102 has_randr
= XRRQueryExtension( display(), &randr_event_base
, &error_base
);
106 XRRQueryVersion( display(), &major
, &minor
);
107 has_randr
= ( major
> 1 || ( major
== 1 && minor
>= 1 ) );
114 has_damage
= XDamageQueryExtension( display(), &damage_event_base
, &error_base
);
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" );
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
;
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
;
152 has_glx
= glXQueryExtension( display(), &event_base
, &error_base
);
157 if( XSyncQueryExtension( display(), &sync_event_base
, &error_base
))
159 int major
= 0, minor
= 0;
160 if( XSyncInitialize( display(), &major
, &minor
))
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())
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()
208 return randr_event_base
+ RRScreenChangeNotify
;
214 int Extensions::damageNotifyEvent()
217 return damage_event_base
+ XDamageNotify
;
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()
236 return sync_event_base
+ XSyncAlarmNotify
;