24 #include <sys/socket.h>
28 #include <tqapplication.h>
29 #include <kxerrorhandler.h>
34 #include <X11/extensions/shape.h>
35 #include <X11/Xatom.h>
38 #include "notifications.h"
41 #include <Qt/qx11info_x11.h>
46 namespace KWinInternal
54 int Shape::twin_shape_version = 0;
55 int Shape::twin_shape_event = 0;
58 bool Shape::hasShape( WId w)
60 int xws, yws, xbs, ybs;
61 unsigned int wws, hws, wbs, hbs;
62 int boundingShaped = 0, clipShaped = 0;
65 XShapeQueryExtents(tqt_xdisplay(), w,
66 &boundingShaped, &xws, &yws, &wws, &hws,
67 &clipShaped, &xbs, &ybs, &wbs, &hbs);
68 return boundingShaped != 0;
71 int Shape::shapeEvent()
73 return twin_shape_event;
78 twin_shape_version = 0;
80 if( !XShapeQueryExtension(tqt_xdisplay(), &twin_shape_event, &dummy))
83 if( !XShapeQueryVersion( tqt_xdisplay(), &major, &minor ))
85 twin_shape_version = major * 0x10 + minor;
88 void Motif::readFlags( WId w,
bool& noborder,
bool& resize,
bool& move,
89 bool& minimize,
bool& maximize,
bool& close )
93 unsigned long length, after;
96 if ( XGetWindowProperty( tqt_xdisplay(), w, atoms->motif_wm_hints, 0, 5,
97 FALSE, atoms->motif_wm_hints, &type, &format,
98 &length, &after, &data ) == Success )
101 hints = (MwmHints*) data;
112 if ( hints->flags & MWM_HINTS_FUNCTIONS )
115 bool set_value = (( hints->functions & MWM_FUNC_ALL ) == 0 );
116 resize = move = minimize = maximize = close = !set_value;
117 if( hints->functions & MWM_FUNC_RESIZE )
119 if( hints->functions & MWM_FUNC_MOVE )
121 if( hints->functions & MWM_FUNC_MINIMIZE )
122 minimize = set_value;
123 if( hints->functions & MWM_FUNC_MAXIMIZE )
124 maximize = set_value;
125 if( hints->functions & MWM_FUNC_CLOSE )
128 if ( hints->flags & MWM_HINTS_DECORATIONS )
130 if ( hints->decorations == 0 )
141 KWinSelectionOwner::KWinSelectionOwner(
int screen_P )
142 : TDESelectionOwner( make_selection_atom( screen_P ), screen_P )
146 Atom KWinSelectionOwner::make_selection_atom(
int screen_P )
149 screen_P = DefaultScreen( tqt_xdisplay());
151 sprintf( tmp,
"WM_S%d", screen_P );
152 return XInternAtom( tqt_xdisplay(), tmp, False );
155 void KWinSelectionOwner::getAtoms()
157 TDESelectionOwner::getAtoms();
158 if( xa_version == None )
161 const char*
const names[] =
163 XInternAtoms( tqt_xdisplay(), const_cast< char** >( names ), 1, False, atoms );
164 xa_version = atoms[ 0 ];
168 void KWinSelectionOwner::replyTargets( Atom property_P, Window requestor_P )
170 TDESelectionOwner::replyTargets( property_P, requestor_P );
171 Atom atoms[ 1 ] = { xa_version };
173 XChangeProperty( tqt_xdisplay(), requestor_P, property_P, XA_ATOM, 32, PropModeAppend,
174 reinterpret_cast< unsigned char* >( atoms ), 1 );
177 bool KWinSelectionOwner::genericReply( Atom target_P, Atom property_P, Window requestor_P )
179 if( target_P == xa_version )
181 long version[] = { 2, 0 };
182 XChangeProperty( tqt_xdisplay(), requestor_P, property_P, XA_INTEGER, 32,
183 PropModeReplace, reinterpret_cast< unsigned char* >( &version ), 2 );
186 return TDESelectionOwner::genericReply( target_P, property_P, requestor_P );
190 Atom KWinSelectionOwner::xa_version = None;
193 TQCString getStringProperty(WId w, Atom prop,
char separator)
197 unsigned long nitems = 0;
198 unsigned long extra = 0;
199 unsigned char *data = 0;
200 TQCString result =
"";
201 KXErrorHandler handler;
202 status = XGetWindowProperty( tqt_xdisplay(), w, prop, 0, 10000,
203 FALSE, XA_STRING, &type, &format,
204 &nitems, &extra, &data );
205 if ( status == Success)
207 if (data && separator)
209 for (
int i=0; i<(int)nitems; i++)
210 if (!data[i] && i+1<(
int)nitems)
214 result = (
const char*) data;
220 static Time next_x_time;
221 static Bool update_x_time_predicate( Display*, XEvent* event, XPointer )
223 if( next_x_time != CurrentTime )
226 switch ( event->type ) {
230 next_x_time =
event->xbutton.time;
233 next_x_time =
event->xmotion.time;
238 next_x_time =
event->xkey.time;
241 next_x_time =
event->xproperty.time;
245 next_x_time =
event->xcrossing.time;
248 next_x_time =
event->xselectionclear.time;
266 static TQWidget* w = 0;
270 XChangeProperty(tqt_xdisplay(), w->winId(), atoms->twin_running, atoms->twin_running, 32,
271 PropModeAppend, (
unsigned char*) &data, 1);
272 next_x_time = CurrentTime;
274 XCheckIfEvent( tqt_xdisplay(), &dummy, update_x_time_predicate, NULL );
275 if( next_x_time == CurrentTime )
277 XSync( tqt_xdisplay(), False );
278 XCheckIfEvent( tqt_xdisplay(), &dummy, update_x_time_predicate, NULL );
280 assert( next_x_time != CurrentTime );
281 SET_QT_X_TIME(next_x_time);
283 XWindowEvent( tqt_xdisplay(), w->winId(), PropertyChangeMask, &ev );
286 static int server_grab_count = 0;
290 if( ++server_grab_count == 1 )
291 XGrabServer( tqt_xdisplay());
296 assert( server_grab_count > 0 );
297 if( --server_grab_count == 0 )
299 XUngrabServer( tqt_xdisplay());
300 XFlush( tqt_xdisplay());
301 Notify::sendPendingEvents();
305 bool grabbedXServer()
307 return server_grab_count > 0;
312 bool isLocalMachine(
const TQCString& host )
315 char hostnamebuf[HOST_NAME_MAX];
317 char hostnamebuf[256];
319 if (gethostname (hostnamebuf,
sizeof hostnamebuf) >= 0)
321 hostnamebuf[
sizeof(hostnamebuf)-1] = 0;
322 if (host == hostnamebuf)
324 if(
char *dot = strchr(hostnamebuf,
'.'))
327 if( host == hostnamebuf )
332 struct addrinfo hints, *res, *addr;
333 bool is_local =
false;
335 memset (&hints, 0,
sizeof (hints));
336 hints.ai_family = PF_UNSPEC;
337 hints.ai_socktype = SOCK_STREAM;
338 hints.ai_flags |= AI_CANONNAME;
340 if( getaddrinfo( host, NULL, &hints, &res ) != 0)
342 for(addr = res; !is_local && addr; addr = addr->ai_next)
344 if( addr->ai_canonname &&
345 host == TQCString( addr->ai_canonname ))
356 ShortcutDialog::ShortcutDialog(
const TDEShortcut& cut )
357 : TDEShortcutDialog( cut, false )
360 XSetWindowAttributes attrs;
361 attrs.override_redirect = True;
362 XChangeWindowAttributes( tqt_xdisplay(), winId(), CWOverrideRedirect, &attrs );
363 setWFlags( WType_Popup );
366 void ShortcutDialog::accept()
372 KKeySequence seq = shortcut().seq( i );
375 if( seq.key( 0 ) == Key_Escape )
380 if( seq.key( 0 ) == Key_Space )
382 setShortcut( TDEShortcut());
383 TDEShortcutDialog::accept();
386 if( seq.key( 0 ).modFlags() == 0 )
388 TDEShortcut cut = shortcut();
389 cut.setSeq( i, KKeySequence());
394 TDEShortcutDialog::accept();
401 void ShortcutDialog::hide()
404 return TDEShortcutDialog::hide();