20#include <tdestartupinfo.h>
22#include <X11/extensions/shape.h>
24#include "notifications.h"
38 XWindowAttributes attr;
39 if( !XGetWindowAttributes(tqt_xdisplay(), w, &attr))
45 postpone_geometry_updates = 1;
46 pending_geometry_update =
true;
48 embedClient( w, attr );
52 bool init_minimize =
false;
53 XWMHints * hints = XGetWMHints(tqt_xdisplay(), w );
54 if (hints && (hints->flags & StateHint) && hints->initial_state == IconicState)
59 init_minimize =
false;
61 unsigned long properties[ 2 ];
62 properties[ WinInfo::PROTOCOLS ] =
73 properties[ WinInfo::PROTOCOLS2 ] =
76 NET::WM2ExtendedStrut |
79 info =
new WinInfo(
this, tqt_xdisplay(), client, tqt_xrootwin(), properties, 2 );
84 if ( XGetClassHint( tqt_xdisplay(), client, &classHint ) )
88 resource_name = TQCString( classHint.res_name ).lower();
89 resource_class = TQCString( classHint.res_class ).lower();
90 XFree( classHint.res_name );
91 XFree( classHint.res_class );
93 ignore_focus_stealing = options->checkIgnoreFocusStealing(
this );
101 cap_normal = readName();
102 setupWindowRules(
false );
103 setCaption( cap_normal,
true );
109 modal = ( info->state() & NET::Modal ) != 0;
112 getWindowProtocols();
118 original_skip_taskbar = skip_taskbar = ( info->state() & NET::SkipTaskbar) != 0;
119 skip_pager = ( info->state() & NET::SkipPager) != 0;
121 TDEStartupInfoId asn_id;
122 TDEStartupInfoData asn_data;
123 bool asn_valid = workspace()->checkStartupNotification( window(), asn_id, asn_data );
125 workspace()->updateClientLayer(
this );
127 SessionInfo* session = workspace()->takeSessionInfo(
this );
131 if ( session->minimized )
132 init_minimize =
true;
133 setUserNoBorder( session->userNoBorder , session->userNoBorderForced );
137 setUserNoBorder(
false,
false );
140 setShortcut( rules()->checkShortcut( session ? session->shortcut : TQString::null,
true ));
142 init_minimize = rules()->checkMinimize( init_minimize, !isMapped );
145 checkAndSetInitialRuledOpacity();
150 desk = session->desktop;
151 if( session->onAllDesktops )
152 desk = NET::OnAllDesktops;
161 ClientList mainclients = mainClients();
162 bool on_current =
false;
165 for( ClientList::ConstIterator it = mainclients.begin();
166 it != mainclients.end();
169 if( mainclients.count() > 1 && (*it)->isSpecialWindow())
172 if( (*it)->isOnCurrentDesktop())
176 desk = workspace()->currentDesktop();
177 else if( maincl != NULL )
180 if ( info->desktop() )
181 desk = info->desktop();
182 if(
desktop() == 0 && asn_valid && asn_data.desktop() != 0 )
183 desk = asn_data.desktop();
186 desk = workspace()->currentDesktop();
187 desk = rules()->checkDesktop( desk, !isMapped );
188 if( desk != NET::OnAllDesktops )
189 desk = KMAX( 1, KMIN( workspace()->numberOfDesktops(), desk ));
190 info->setDesktop( desk );
191 workspace()->updateOnAllDesktopsOfTransients(
this );
194 TQRect geom( attr.x, attr.y, attr.width, attr.height );
195 bool placementDone =
false;
198 geom = session->geometry;
201 bool partial_keep_in_area = isMapped || session;
202 if( isMapped || session )
203 area = workspace()->clientArea( FullArea, geom.center(),
desktop());
204 else if( options->xineramaPlacementEnabled )
206 int screen = options->xineramaPlacementScreen;
208 screen = asn_data.xinerama() == -1 ? workspace()->activeScreen() : asn_data.xinerama();
209 area = workspace()->clientArea( PlacementArea, workspace()->screenGeometry( screen ).center(),
desktop());
212 area = workspace()->clientArea( PlacementArea, TQCursor::pos(),
desktop());
214 if(
int type = checkFullScreenHack( geom ))
216 fullscreen_mode = FullScreenHack;
217 if( rules()->checkStrictGeometry(
false ))
220 ? workspace()->clientArea( FullArea, geom.center(),
desktop())
221 : workspace()->clientArea( ScreenArea, geom.center(),
desktop());
224 geom = workspace()->clientArea( FullScreenArea, geom.center(),
desktop());
225 placementDone =
true;
231 geom = workspace()->clientArea( FullArea, geom.center(),
desktop());
232 placementDone =
true;
235 bool usePosition =
false;
236 if ( isMapped || session || placementDone )
237 placementDone =
true;
238 else if( isTransient() && !isUtility() && !isDialog() && !isSplash())
240 else if( isTransient() && !hasNETSupport())
242 else if( isDialog() && hasNETSupport())
246 if( mainClients().count() >= 1 )
267 if( !rules()->checkIgnoreGeometry( !usePosition ))
269 bool ignorePPosition = ( options->ignorePositionClasses.contains(TQString::fromLatin1(resourceClass())));
271 if ( ( (xSizeHint.flags & PPosition) && !ignorePPosition ) ||
272 (xSizeHint.flags & USPosition) )
274 placementDone =
true;
276 area = workspace()->clientArea( PlacementArea, geom.center(),
desktop());
280 if ( (xSizeHint.flags & USSize) || (xSizeHint.flags & PSize) )
285 if (xSizeHint.flags & PMaxSize)
286 geom.setSize( geom.size().boundedTo(
287 rules()->checkMaxSize( TQSize(xSizeHint.max_width, xSizeHint.max_height ) ) ) );
288 if (xSizeHint.flags & PMinSize)
289 geom.setSize( geom.size().expandedTo(
290 rules()->checkMinSize( TQSize(xSizeHint.min_width, xSizeHint.min_height ) ) ) );
294 if( geom.x() > area.right() || geom.y() > area.bottom())
295 placementDone =
false;
299 move( geom.x(), geom.y() );
301 updateDecoration(
false );
303 plainResize( rules()->checkSize( sizeForClientSize( geom.size()), !isMapped ));
305 TQPoint forced_pos = rules()->checkPosition( invalidPoint, !isMapped );
306 if( forced_pos != invalidPoint )
309 placementDone =
true;
311 partial_keep_in_area =
true;
312 area = workspace()->clientArea( FullArea, geom.center(),
desktop());
316 workspace()->place(
this, area );
317 placementDone =
true;
320 if(( !isSpecialWindow() || isToolbar()) &&
isMovable())
321 keepInArea( area, partial_keep_in_area );
323 XShapeSelectInput( tqt_xdisplay(), window(), ShapeNotifyMask );
324 is_shape = Shape::hasShape( window());
330 if( init_minimize && isTransient())
332 ClientList mainclients = mainClients();
333 for( ClientList::ConstIterator it = mainclients.begin();
334 it != mainclients.end();
336 if( (*it)->isShown(
true ))
337 init_minimize =
false;
340 if( !init_minimize && isTransient() && mainClients().count() > 0 )
342 bool visible_parent =
false;
343 ClientList mainclients = mainClients();
344 for( ClientList::ConstIterator it = mainclients.begin();
345 it != mainclients.end();
347 if( (*it)->isShown(
true ))
348 visible_parent =
true;
349 if( !visible_parent )
351 init_minimize =
true;
361 bool doNotShow =
false;
362 if ( workspace()->isNotManaged(
caption() ) )
370 setKeepAbove( session->keepAbove );
371 setKeepBelow( session->keepBelow );
372 setSkipTaskbar( session->skipTaskbar,
true );
373 setSkipPager( session->skipPager );
374 setShade( session->shaded ? ShadeNormal : ShadeNone );
375 setShadowed( session->shadowed );
376 if( session->maximized != MaximizeRestore )
378 maximize( (MaximizeMode) session->maximized );
379 geom_restore = session->restore;
381 if( session->fullscreen == FullScreenHack )
383 else if( session->fullscreen != FullScreenNone )
385 setFullScreen(
true,
false );
386 geom_fs_restore = session->fsrestore;
391 geom_restore = geometry();
393 && ( width() >= area.width() || height() >= area.height() ) )
397 if ( width() >= area.width() && height() >= area.height() )
399 maximize( Client::MaximizeFull );
400 geom_restore = TQRect();
402 else if ( width() >= area.width() )
404 maximize( Client::MaximizeHorizontal );
405 geom_restore = TQRect();
406 geom_restore.setY( y());
407 geom_restore.setHeight( height());
409 else if ( height() >= area.height() )
411 maximize( Client::MaximizeVertical );
412 geom_restore = TQRect();
413 geom_restore.setX( x());
414 geom_restore.setWidth( width());
421 MaximizeMode maxmode =
static_cast< MaximizeMode
>
422 ((( info->state() & NET::MaxVert ) ? MaximizeVertical : 0 )
423 | (( info->state() & NET::MaxHoriz ) ? MaximizeHorizontal : 0 ));
424 MaximizeMode forced_maxmode = rules()->checkMaximize( maxmode, !isMapped );
427 if( forced_maxmode != MaximizeRestore || maxmode != MaximizeRestore )
428 maximize( forced_maxmode );
431 setShade( rules()->checkShade( info->state() & NET::Shaded ? ShadeNormal : ShadeNone, !isMapped ));
432 setKeepAbove( rules()->checkKeepAbove( info->state() & NET::KeepAbove, !isMapped ));
433 setKeepBelow( rules()->checkKeepBelow( info->state() & NET::KeepBelow, !isMapped ));
434 setSkipTaskbar( rules()->checkSkipTaskbar( info->state() & NET::SkipTaskbar, !isMapped ),
true );
435 setSkipPager( rules()->checkSkipPager( info->state() & NET::SkipPager, !isMapped ));
436 if( info->state() & NET::DemandsAttention )
438 if( info->state() & NET::Modal )
440 if( fullscreen_mode != FullScreenHack && isFullScreenable())
441 setFullScreen( rules()->checkFullScreen( info->state() & NET::FullScreen, !isMapped ),
false );
444 updateAllowedActions(
true );
449 XLowerWindow( tqt_xdisplay(), frameId());
452 user_time = readUserTimeMapTimestamp( asn_valid ? &asn_id : NULL, asn_valid ? &asn_data : NULL, session );
453 group()->updateUserTime( user_time );
458 if( isShown(
true ) && !doNotShow )
461 Notify::raise( Notify::TransNew );
462 if( isNormalWindow())
463 Notify::raise( Notify::New );
467 allow = session->active
468 && ( !workspace()->wasUserInteraction()
469 || workspace()->activeClient() == NULL || workspace()->activeClient()->isDesktop());
471 allow = workspace()->allowClientActivation(
this, userTime(),
false );
475 if( !isOnCurrentDesktop() && !isMapped && !session && ( allow || workspace()->sessionSaving()))
476 workspace()->setCurrentDesktop(
desktop());
478 bool belongs_to_desktop =
false;
479 for( ClientList::ConstIterator it = group()->members().begin();
480 it != group()->members().end();
482 if( (*it)->isDesktop())
484 belongs_to_desktop =
true;
487 if( !belongs_to_desktop && workspace()->showingDesktop())
488 workspace()->resetShowingDesktop( options->showDesktopIsMinimizeAll );
490 if( isOnCurrentDesktop() && !isMapped && !allow )
491 workspace()->restackClientUnderActive(
this );
493 workspace()->raiseClient(
this );
499 if( allow && isOnCurrentDesktop())
501 if( !isSpecialWindow())
502 if ( options->focusPolicyIsReasonable() && wantsTabFocus() )
503 workspace()->requestFocus(
this );
507 if( !session && !isSpecialWindow())
512 else if( !doNotShow )
519 setMappingState( IconicState );
521 assert( mappingState() != WithdrawnState );
523 if( user_time == CurrentTime || user_time == -1U )
525 user_time = get_tqt_x_time() - 1000000;
526 if( user_time == CurrentTime || user_time == -1U )
527 user_time = get_tqt_x_time() - 1000000 + 10;
530 updateWorkareaDiffs();
538 client_rules.discardTemporary();
540 workspace()->discardUsedWindowRules(
this,
false );
556void Client::embedClient( Window w,
const XWindowAttributes &attr )
558 assert( client == None );
559 assert( frame == None );
560 assert( wrapper == None );
563 XAddToSaveSet( tqt_xdisplay(), client );
564 XSelectInput( tqt_xdisplay(), client, NoEventMask );
565 XUnmapWindow( tqt_xdisplay(), client );
568 XConfigureWindow( tqt_xdisplay(), client, CWBorderWidth, &wc );
570 XSetWindowAttributes swa;
571 swa.colormap = attr.colormap;
572 swa.background_pixmap = None;
573 swa.border_pixel = 0;
575 frame = XCreateWindow( tqt_xdisplay(), tqt_xrootwin(), 0, 0, 1, 1, 0,
576 attr.depth, InputOutput, attr.visual,
577 CWColormap | CWBackPixmap | CWBorderPixel, &swa );
578 wrapper = XCreateWindow( tqt_xdisplay(), frame, 0, 0, 1, 1, 0,
579 attr.depth, InputOutput, attr.visual,
580 CWColormap | CWBackPixmap | CWBorderPixel, &swa );
582 XDefineCursor( tqt_xdisplay(), frame, TQt::arrowCursor.handle());
584 XDefineCursor( tqt_xdisplay(), wrapper, TQt::arrowCursor.handle());
585 XReparentWindow( tqt_xdisplay(), client, wrapper, 0, 0 );
586 XSelectInput( tqt_xdisplay(), frame,
587 KeyPressMask | KeyReleaseMask |
588 ButtonPressMask | ButtonReleaseMask |
592 EnterWindowMask | LeaveWindowMask |
596 StructureNotifyMask | SubstructureRedirectMask );
597 XSelectInput( tqt_xdisplay(), wrapper, ClientWinMask | SubstructureNotifyMask );
598 XSelectInput( tqt_xdisplay(), client,
602 EnterWindowMask | LeaveWindowMask |
603 KeyPressMask | KeyReleaseMask
The Client class encapsulates a window decoration frame.
bool manage(Window w, bool isMapped)
void minimize(bool avoid_animation=false)
static TQCString staticWindowRole(WId)
TQString caption(bool full=true) const
void move(int x, int y, ForceGeometry_t force=NormalGeometrySet)