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"
42 namespace KWinInternal
50 int Shape::twin_shape_version = 0;
51 int Shape::twin_shape_event = 0;
54 bool Shape::hasShape( WId w)
56 int xws, yws, xbs, ybs;
57 unsigned int wws, hws, wbs, hbs;
58 int boundingShaped = 0, clipShaped = 0;
61 XShapeQueryExtents(tqt_xdisplay(), w,
62 &boundingShaped, &xws, &yws, &wws, &hws,
63 &clipShaped, &xbs, &ybs, &wbs, &hbs);
64 return boundingShaped != 0;
67 int Shape::shapeEvent()
69 return twin_shape_event;
74 twin_shape_version = 0;
76 if( !XShapeQueryExtension(tqt_xdisplay(), &twin_shape_event, &dummy))
79 if( !XShapeQueryVersion( tqt_xdisplay(), &major, &minor ))
81 twin_shape_version = major * 0x10 + minor;
84 void Motif::readFlags( WId w,
bool& noborder,
bool& resize,
bool& move,
85 bool& minimize,
bool& maximize,
bool& close )
89 unsigned long length, after;
92 if ( XGetWindowProperty( tqt_xdisplay(), w, atoms->motif_wm_hints, 0, 5,
93 FALSE, atoms->motif_wm_hints, &type, &format,
94 &length, &after, &data ) == Success )
97 hints = (MwmHints*) data;
108 if ( hints->flags & MWM_HINTS_FUNCTIONS )
111 bool set_value = (( hints->functions & MWM_FUNC_ALL ) == 0 );
112 resize = move = minimize = maximize = close = !set_value;
113 if( hints->functions & MWM_FUNC_RESIZE )
115 if( hints->functions & MWM_FUNC_MOVE )
117 if( hints->functions & MWM_FUNC_MINIMIZE )
118 minimize = set_value;
119 if( hints->functions & MWM_FUNC_MAXIMIZE )
120 maximize = set_value;
121 if( hints->functions & MWM_FUNC_CLOSE )
124 if ( hints->flags & MWM_HINTS_DECORATIONS )
126 if ( hints->decorations == 0 )
137 KWinSelectionOwner::KWinSelectionOwner(
int screen_P )
138 : TDESelectionOwner( make_selection_atom( screen_P ), screen_P )
142 Atom KWinSelectionOwner::make_selection_atom(
int screen_P )
145 screen_P = DefaultScreen( tqt_xdisplay());
147 sprintf( tmp,
"WM_S%d", screen_P );
148 return XInternAtom( tqt_xdisplay(), tmp, False );
151 void KWinSelectionOwner::getAtoms()
153 TDESelectionOwner::getAtoms();
154 if( xa_version == None )
157 const char*
const names[] =
159 XInternAtoms( tqt_xdisplay(),
const_cast< char**
>( names ), 1, False, atoms );
160 xa_version = atoms[ 0 ];
164 void KWinSelectionOwner::replyTargets( Atom property_P, Window requestor_P )
166 TDESelectionOwner::replyTargets( property_P, requestor_P );
167 Atom atoms[ 1 ] = { xa_version };
169 XChangeProperty( tqt_xdisplay(), requestor_P, property_P, XA_ATOM, 32, PropModeAppend,
170 reinterpret_cast< unsigned char*
>( atoms ), 1 );
173 bool KWinSelectionOwner::genericReply( Atom target_P, Atom property_P, Window requestor_P )
175 if( target_P == xa_version )
177 long version[] = { 2, 0 };
178 XChangeProperty( tqt_xdisplay(), requestor_P, property_P, XA_INTEGER, 32,
179 PropModeReplace,
reinterpret_cast< unsigned char*
>( &version ), 2 );
182 return TDESelectionOwner::genericReply( target_P, property_P, requestor_P );
186 Atom KWinSelectionOwner::xa_version = None;
189 TQCString getStringProperty(WId w, Atom prop,
char separator)
193 unsigned long nitems = 0;
194 unsigned long extra = 0;
195 unsigned char *data = 0;
196 TQCString result =
"";
197 KXErrorHandler handler;
198 status = XGetWindowProperty( tqt_xdisplay(), w, prop, 0, 10000,
199 FALSE, XA_STRING, &type, &format,
200 &nitems, &extra, &data );
201 if ( status == Success)
203 if (data && separator)
205 for (
int i=0; i<(int)nitems; i++)
206 if (!data[i] && i+1<(
int)nitems)
210 result = (
const char*) data;
216 static Time next_x_time;
217 static Bool update_x_time_predicate( Display*, XEvent* event, XPointer )
219 if( next_x_time != CurrentTime )
222 switch ( event->type ) {
226 next_x_time =
event->xbutton.time;
229 next_x_time =
event->xmotion.time;
234 next_x_time =
event->xkey.time;
237 next_x_time =
event->xproperty.time;
241 next_x_time =
event->xcrossing.time;
244 next_x_time =
event->xselectionclear.time;
262 static TQWidget* w = 0;
266 XChangeProperty(tqt_xdisplay(), w->winId(), atoms->twin_running, atoms->twin_running, 32,
267 PropModeAppend, (
unsigned char*) &data, 1);
268 next_x_time = CurrentTime;
270 XCheckIfEvent( tqt_xdisplay(), &dummy, update_x_time_predicate, NULL );
271 if( next_x_time == CurrentTime )
273 XSync( tqt_xdisplay(), False );
274 XCheckIfEvent( tqt_xdisplay(), &dummy, update_x_time_predicate, NULL );
276 assert( next_x_time != CurrentTime );
277 set_tqt_x_time(next_x_time);
279 XWindowEvent( tqt_xdisplay(), w->winId(), PropertyChangeMask, &ev );
282 static int server_grab_count = 0;
286 if( ++server_grab_count == 1 )
287 XGrabServer( tqt_xdisplay());
292 assert( server_grab_count > 0 );
293 if( --server_grab_count == 0 )
295 XUngrabServer( tqt_xdisplay());
296 XFlush( tqt_xdisplay());
297 Notify::sendPendingEvents();
301 bool grabbedXServer()
303 return server_grab_count > 0;
308 bool isLocalMachine(
const TQCString& host )
311 char hostnamebuf[HOST_NAME_MAX];
313 char hostnamebuf[256];
315 if (gethostname (hostnamebuf,
sizeof hostnamebuf) >= 0)
317 hostnamebuf[
sizeof(hostnamebuf)-1] = 0;
318 if (host == hostnamebuf)
320 if(
char *dot = strchr(hostnamebuf,
'.'))
323 if( host == hostnamebuf )
328 struct addrinfo hints, *res, *addr;
329 bool is_local =
false;
331 memset (&hints, 0,
sizeof (hints));
332 hints.ai_family = PF_UNSPEC;
333 hints.ai_socktype = SOCK_STREAM;
334 hints.ai_flags |= AI_CANONNAME;
336 if( getaddrinfo( host, NULL, &hints, &res ) != 0)
338 for(addr = res; !is_local && addr; addr = addr->ai_next)
340 if( addr->ai_canonname &&
341 host == TQCString( addr->ai_canonname ))
352 ShortcutDialog::ShortcutDialog(
const TDEShortcut& cut )
353 : TDEShortcutDialog( cut, false )
356 XSetWindowAttributes attrs;
357 attrs.override_redirect = True;
358 XChangeWindowAttributes( tqt_xdisplay(), winId(), CWOverrideRedirect, &attrs );
359 setWFlags( WType_Popup );
362 void ShortcutDialog::accept()
368 KKeySequence seq = shortcut().seq( i );
371 if( seq.key( 0 ) == Key_Escape )
376 if( seq.key( 0 ) == Key_Space )
378 setShortcut( TDEShortcut());
379 TDEShortcutDialog::accept();
382 if( seq.key( 0 ).modFlags() == 0 )
384 TDEShortcut cut = shortcut();
385 cut.setSeq( i, KKeySequence());
390 TDEShortcutDialog::accept();
397 void ShortcutDialog::hide()
400 return TDEShortcutDialog::hide();