26 #include <tqapplication.h>
27 #include <kxerrorhandler.h>
32 #include <X11/extensions/shape.h>
33 #include <X11/Xatom.h>
36 #include "notifications.h"
39 #include <Qt/qx11info_x11.h>
44 namespace KWinInternal
52 int Shape::kwin_shape_version = 0;
53 int Shape::kwin_shape_event = 0;
56 bool Shape::hasShape( WId w)
58 int xws, yws, xbs, ybs;
59 unsigned int wws, hws, wbs, hbs;
60 int boundingShaped = 0, clipShaped = 0;
63 XShapeQueryExtents(qt_xdisplay(), w,
64 &boundingShaped, &xws, &yws, &wws, &hws,
65 &clipShaped, &xbs, &ybs, &wbs, &hbs);
66 return boundingShaped != 0;
69 int Shape::shapeEvent()
71 return kwin_shape_event;
76 kwin_shape_version = 0;
78 if( !XShapeQueryExtension(qt_xdisplay(), &kwin_shape_event, &dummy))
81 if( !XShapeQueryVersion( qt_xdisplay(), &major, &minor ))
83 kwin_shape_version = major * 0x10 + minor;
86 void Motif::readFlags( WId w,
bool& noborder,
bool& resize,
bool& move,
87 bool& minimize,
bool& maximize,
bool& close )
91 unsigned long length, after;
94 if ( XGetWindowProperty( qt_xdisplay(), w, atoms->motif_wm_hints, 0, 5,
95 FALSE, atoms->motif_wm_hints, &type, &format,
96 &length, &after, &data ) == Success )
99 hints = (MwmHints*) data;
110 if ( hints->flags & MWM_HINTS_FUNCTIONS )
113 bool set_value = (( hints->functions & MWM_FUNC_ALL ) == 0 );
114 resize = move = minimize = maximize = close = !set_value;
115 if( hints->functions & MWM_FUNC_RESIZE )
117 if( hints->functions & MWM_FUNC_MOVE )
119 if( hints->functions & MWM_FUNC_MINIMIZE )
120 minimize = set_value;
121 if( hints->functions & MWM_FUNC_MAXIMIZE )
122 maximize = set_value;
123 if( hints->functions & MWM_FUNC_CLOSE )
126 if ( hints->flags & MWM_HINTS_DECORATIONS )
128 if ( hints->decorations == 0 )
139 KWinSelectionOwner::KWinSelectionOwner(
int screen_P )
140 : KSelectionOwner( make_selection_atom( screen_P ), screen_P )
144 Atom KWinSelectionOwner::make_selection_atom(
int screen_P )
147 screen_P = DefaultScreen( qt_xdisplay());
149 sprintf( tmp,
"WM_S%d", screen_P );
150 return XInternAtom( qt_xdisplay(), tmp, False );
153 void KWinSelectionOwner::getAtoms()
155 KSelectionOwner::getAtoms();
156 if( xa_version == None )
159 const char*
const names[] =
161 XInternAtoms( qt_xdisplay(), const_cast< char** >( names ), 1, False, atoms );
162 xa_version = atoms[ 0 ];
166 void KWinSelectionOwner::replyTargets( Atom property_P, Window requestor_P )
168 KSelectionOwner::replyTargets( property_P, requestor_P );
169 Atom atoms[ 1 ] = { xa_version };
171 XChangeProperty( qt_xdisplay(), requestor_P, property_P, XA_ATOM, 32, PropModeAppend,
172 reinterpret_cast< unsigned char* >( atoms ), 1 );
175 bool KWinSelectionOwner::genericReply( Atom target_P, Atom property_P, Window requestor_P )
177 if( target_P == xa_version )
179 long version[] = { 2, 0 };
180 XChangeProperty( qt_xdisplay(), requestor_P, property_P, XA_INTEGER, 32,
181 PropModeReplace, reinterpret_cast< unsigned char* >( &version ), 2 );
184 return KSelectionOwner::genericReply( target_P, property_P, requestor_P );
188 Atom KWinSelectionOwner::xa_version = None;
191 TQCString getStringProperty(WId w, Atom prop,
char separator)
195 unsigned long nitems = 0;
196 unsigned long extra = 0;
197 unsigned char *data = 0;
198 TQCString result =
"";
199 KXErrorHandler handler;
200 status = XGetWindowProperty( qt_xdisplay(), w, prop, 0, 10000,
201 FALSE, XA_STRING, &type, &format,
202 &nitems, &extra, &data );
203 if ( status == Success)
205 if (data && separator)
207 for (
int i=0; i<(int)nitems; i++)
208 if (!data[i] && i+1<(
int)nitems)
212 result = (
const char*) data;
218 static Time next_x_time;
219 static Bool update_x_time_predicate( Display*, XEvent* event, XPointer )
221 if( next_x_time != CurrentTime )
224 switch ( event->type ) {
228 next_x_time =
event->xbutton.time;
231 next_x_time =
event->xmotion.time;
236 next_x_time =
event->xkey.time;
239 next_x_time =
event->xproperty.time;
243 next_x_time =
event->xcrossing.time;
246 next_x_time =
event->xselectionclear.time;
264 static TQWidget* w = 0;
268 XChangeProperty(qt_xdisplay(), w->winId(), atoms->kwin_running, atoms->kwin_running, 32,
269 PropModeAppend, (
unsigned char*) &data, 1);
270 next_x_time = CurrentTime;
272 XCheckIfEvent( qt_xdisplay(), &dummy, update_x_time_predicate, NULL );
273 if( next_x_time == CurrentTime )
275 XSync( qt_xdisplay(), False );
276 XCheckIfEvent( qt_xdisplay(), &dummy, update_x_time_predicate, NULL );
278 assert( next_x_time != CurrentTime );
279 SET_QT_X_TIME(next_x_time);
281 XWindowEvent( qt_xdisplay(), w->winId(), PropertyChangeMask, &ev );
284 static int server_grab_count = 0;
288 if( ++server_grab_count == 1 )
289 XGrabServer( qt_xdisplay());
294 assert( server_grab_count > 0 );
295 if( --server_grab_count == 0 )
297 XUngrabServer( qt_xdisplay());
298 XFlush( qt_xdisplay());
299 Notify::sendPendingEvents();
303 bool grabbedXServer()
305 return server_grab_count > 0;
310 bool isLocalMachine(
const TQCString& host )
313 char hostnamebuf[HOST_NAME_MAX];
315 char hostnamebuf[256];
317 if (gethostname (hostnamebuf,
sizeof hostnamebuf) >= 0)
319 hostnamebuf[
sizeof(hostnamebuf)-1] = 0;
320 if (host == hostnamebuf)
322 if(
char *dot = strchr(hostnamebuf,
'.'))
325 if( host == hostnamebuf )
330 struct addrinfo hints, *res, *addr;
331 bool is_local =
false;
333 memset (&hints, 0,
sizeof (hints));
334 hints.ai_family = PF_UNSPEC;
335 hints.ai_socktype = SOCK_STREAM;
336 hints.ai_flags |= AI_CANONNAME;
338 if( getaddrinfo( host, NULL, &hints, &res ) != 0)
340 for(addr = res; !is_local && addr; addr = addr->ai_next)
342 if( addr->ai_canonname &&
343 host == TQCString( addr->ai_canonname ))
354 ShortcutDialog::ShortcutDialog(
const KShortcut& cut )
355 : KShortcutDialog( cut, false )
358 XSetWindowAttributes attrs;
359 attrs.override_redirect = True;
360 XChangeWindowAttributes( qt_xdisplay(), winId(), CWOverrideRedirect, &attrs );
361 setWFlags( WType_Popup );
364 void ShortcutDialog::accept()
370 KKeySequence seq = shortcut().seq( i );
373 if( seq.key( 0 ) == Key_Escape )
378 if( seq.key( 0 ) == Key_Space )
380 setShortcut( KShortcut());
381 KShortcutDialog::accept();
384 if( seq.key( 0 ).modFlags() == 0 )
386 KShortcut cut = shortcut();
387 cut.setSeq( i, KKeySequence());
392 KShortcutDialog::accept();
399 void ShortcutDialog::hide()
402 return KShortcutDialog::hide();