00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "client.h"
00019
00020 #include <kstartupinfo.h>
00021 #include <kglobal.h>
00022 #include <X11/extensions/shape.h>
00023
00024 #include "notifications.h"
00025 #include "rules.h"
00026 #include "group.h"
00027
00028 extern Time qt_x_time;
00029
00030 namespace KWinInternal
00031 {
00032
00038 bool Client::manage( Window w, bool isMapped )
00039 {
00040 XWindowAttributes attr;
00041 if( !XGetWindowAttributes(qt_xdisplay(), w, &attr))
00042 return false;
00043
00044 grabXServer();
00045
00046
00047 postpone_geometry_updates = 1;
00048 pending_geometry_update = true;
00049
00050 embedClient( w, attr );
00051
00052
00053
00054 bool init_minimize = false;
00055 XWMHints * hints = XGetWMHints(qt_xdisplay(), w );
00056 if (hints && (hints->flags & StateHint) && hints->initial_state == IconicState)
00057 init_minimize = true;
00058 if (hints)
00059 XFree(hints);
00060 if( isMapped )
00061 init_minimize = false;
00062
00063 unsigned long properties[ 2 ];
00064 properties[ WinInfo::PROTOCOLS ] =
00065 NET::WMDesktop |
00066 NET::WMState |
00067 NET::WMWindowType |
00068 NET::WMStrut |
00069 NET::WMName |
00070 NET::WMIconGeometry |
00071 NET::WMIcon |
00072 NET::WMPid |
00073 NET::WMIconName |
00074 0;
00075 properties[ WinInfo::PROTOCOLS2 ] =
00076 NET::WM2UserTime |
00077 NET::WM2StartupId |
00078 NET::WM2ExtendedStrut |
00079 0;
00080
00081 info = new WinInfo( this, qt_xdisplay(), client, qt_xrootwin(), properties, 2 );
00082
00083 cmap = attr.colormap;
00084
00085 XClassHint classHint;
00086 if ( XGetClassHint( qt_xdisplay(), client, &classHint ) )
00087 {
00088
00089
00090 resource_name = QCString( classHint.res_name ).lower();
00091 resource_class = QCString( classHint.res_class ).lower();
00092 XFree( classHint.res_name );
00093 XFree( classHint.res_class );
00094 }
00095 ignore_focus_stealing = options->checkIgnoreFocusStealing( this );
00096
00097 window_role = staticWindowRole( w );
00098 getWmClientLeader();
00099 getWmClientMachine();
00100
00101
00102
00103 cap_normal = readName();
00104 setupWindowRules( false );
00105 setCaption( cap_normal, true );
00106
00107 detectNoBorder();
00108 detectShapable();
00109 fetchIconicName();
00110 getWMHints();
00111 modal = ( info->state() & NET::Modal ) != 0;
00112 readTransient();
00113 getIcons();
00114 getWindowProtocols();
00115 getWmNormalHints();
00116 getMotifHints();
00117
00118
00119
00120 original_skip_taskbar = skip_taskbar = ( info->state() & NET::SkipTaskbar) != 0;
00121 skip_pager = ( info->state() & NET::SkipPager) != 0;
00122
00123 KStartupInfoId asn_id;
00124 KStartupInfoData asn_data;
00125 bool asn_valid = workspace()->checkStartupNotification( window(), asn_id, asn_data );
00126
00127 workspace()->updateClientLayer( this );
00128
00129 SessionInfo* session = workspace()->takeSessionInfo( this );
00130
00131 if ( session )
00132 {
00133 if ( session->minimized )
00134 init_minimize = true;
00135 if( session->userNoBorder )
00136 setUserNoBorder( true );
00137 }
00138
00139 setShortcut( rules()->checkShortcut( session ? session->shortcut : QString::null, true ));
00140
00141 init_minimize = rules()->checkMinimize( init_minimize, !isMapped );
00142 if( rules()->checkNoBorder( false, !isMapped ))
00143 setUserNoBorder( true );
00144
00145 checkAndSetInitialRuledOpacity();
00146
00147
00148 if ( session )
00149 {
00150 desk = session->desktop;
00151 if( session->onAllDesktops )
00152 desk = NET::OnAllDesktops;
00153 }
00154 else
00155 {
00156
00157
00158
00159 if( isTransient())
00160 {
00161 ClientList mainclients = mainClients();
00162 bool on_current = false;
00163 Client* maincl = NULL;
00164
00165 for( ClientList::ConstIterator it = mainclients.begin();
00166 it != mainclients.end();
00167 ++it )
00168 {
00169 if( (*it)->isSpecialWindow())
00170 continue;
00171 maincl = *it;
00172 if( (*it)->isOnCurrentDesktop())
00173 on_current = true;
00174 }
00175 if( on_current )
00176 desk = workspace()->currentDesktop();
00177 else if( maincl != NULL )
00178 desk = maincl->desktop();
00179 }
00180 if ( info->desktop() )
00181 desk = info->desktop();
00182 if( desktop() == 0 && asn_valid && asn_data.desktop() != 0 )
00183 desk = asn_data.desktop();
00184 }
00185 if ( desk == 0 )
00186 desk = workspace()->currentDesktop();
00187 desk = rules()->checkDesktop( desk, !isMapped );
00188 if( desk != NET::OnAllDesktops )
00189 desk = KMAX( 1, KMIN( workspace()->numberOfDesktops(), desk ));
00190 info->setDesktop( desk );
00191 workspace()->updateOnAllDesktopsOfTransients( this );
00192
00193
00194 QRect geom( attr.x, attr.y, attr.width, attr.height );
00195 bool placementDone = FALSE;
00196
00197 if ( session )
00198 geom = session->geometry;
00199
00200 QRect area;
00201 bool partial_keep_in_area = isMapped || session;
00202 if( isMapped || session )
00203 area = workspace()->clientArea( FullArea, geom.center(), desktop());
00204 else if( options->xineramaPlacementEnabled )
00205 area = workspace()->clientArea( PlacementArea, QCursor::pos(), desktop());
00206 else
00207 area = workspace()->clientArea( PlacementArea, geom.center(), desktop());
00208
00209 if( int type = checkFullScreenHack( geom ))
00210 {
00211 fullscreen_mode = FullScreenHack;
00212 if( rules()->checkStrictGeometry( false ))
00213 {
00214 geom = type == 2
00215 ? workspace()->clientArea( FullArea, geom.center(), desktop())
00216 : workspace()->clientArea( ScreenArea, geom.center(), desktop());
00217 }
00218 else
00219 geom = workspace()->clientArea( FullScreenArea, geom.center(), desktop());
00220 placementDone = true;
00221 }
00222
00223 if ( isDesktop() )
00224 {
00225
00226 geom = workspace()->clientArea( FullArea, geom.center(), desktop());
00227 placementDone = true;
00228 }
00229
00230 bool usePosition = false;
00231 if ( isMapped || session || placementDone )
00232 placementDone = true;
00233 else if( isTransient() && !isUtility() && !isDialog() && !isSplash())
00234 usePosition = true;
00235 else if( isTransient() && !hasNETSupport())
00236 usePosition = true;
00237 else if( isDialog() && hasNETSupport())
00238
00239
00240 {
00241 if( mainClients().count() >= 1 )
00242 {
00243 #if 1
00244
00245
00246
00247
00248
00249
00250 usePosition = true;
00251 #else
00252 ;
00253 #endif
00254 }
00255 else
00256 usePosition = true;
00257 }
00258 else if( isSplash())
00259 ;
00260 else
00261 usePosition = true;
00262 if( !rules()->checkIgnoreGeometry( !usePosition ))
00263 {
00264 bool ignorePPosition = ( options->ignorePositionClasses.contains(QString::fromLatin1(resourceClass())));
00265
00266 if ( ( (xSizeHint.flags & PPosition) && !ignorePPosition ) ||
00267 (xSizeHint.flags & USPosition) )
00268 {
00269 placementDone = TRUE;
00270
00271 area = workspace()->clientArea( PlacementArea, geom.center(), desktop());
00272 }
00273 }
00274 if( true )
00275 if ( (xSizeHint.flags & USSize) || (xSizeHint.flags & PSize) )
00276 {
00277
00278 }
00279
00280 if (xSizeHint.flags & PMaxSize)
00281 geom.setSize( geom.size().boundedTo(
00282 rules()->checkMaxSize( QSize(xSizeHint.max_width, xSizeHint.max_height ) ) ) );
00283 if (xSizeHint.flags & PMinSize)
00284 geom.setSize( geom.size().expandedTo(
00285 rules()->checkMinSize( QSize(xSizeHint.min_width, xSizeHint.min_height ) ) ) );
00286
00287 if( isMovable())
00288 {
00289 if( geom.x() > area.right() || geom.y() > area.bottom())
00290 placementDone = FALSE;
00291 }
00292
00293 if ( placementDone )
00294 move( geom.x(), geom.y() );
00295
00296 updateDecoration( false );
00297
00298 plainResize( rules()->checkSize( sizeForClientSize( geom.size()), !isMapped ));
00299
00300 QPoint forced_pos = rules()->checkPosition( invalidPoint, !isMapped );
00301 if( forced_pos != invalidPoint )
00302 {
00303 move( forced_pos );
00304 placementDone = true;
00305
00306 partial_keep_in_area = true;
00307 area = workspace()->clientArea( FullArea, geom.center(), desktop());
00308 }
00309 if( !placementDone )
00310 {
00311 workspace()->place( this, area );
00312 placementDone = TRUE;
00313 }
00314
00315 if(( !isSpecialWindow() || isToolbar()) && isMovable())
00316 keepInArea( area, partial_keep_in_area );
00317
00318 XShapeSelectInput( qt_xdisplay(), window(), ShapeNotifyMask );
00319 is_shape = Shape::hasShape( window());
00320 updateShape();
00321
00322
00323
00324
00325 if( init_minimize && isTransient())
00326 {
00327 ClientList mainclients = mainClients();
00328 for( ClientList::ConstIterator it = mainclients.begin();
00329 it != mainclients.end();
00330 ++it )
00331 if( (*it)->isShown( true ))
00332 init_minimize = false;
00333 }
00334
00335 if( !init_minimize && isTransient() && mainClients().count() > 0 )
00336 {
00337 bool visible_parent = false;
00338 ClientList mainclients = mainClients();
00339 for( ClientList::ConstIterator it = mainclients.begin();
00340 it != mainclients.end();
00341 ++it )
00342 if( (*it)->isShown( true ))
00343 visible_parent = true;
00344 if( !visible_parent )
00345 {
00346 init_minimize = true;
00347 demandAttention();
00348 }
00349 }
00350
00351 if( init_minimize )
00352 minimize( true );
00353
00354
00355
00356 bool doNotShow = false;
00357 if ( workspace()->isNotManaged( caption() ) )
00358 doNotShow = TRUE;
00359
00360
00361 if ( session )
00362 {
00363
00364
00365 setKeepAbove( session->keepAbove );
00366 setKeepBelow( session->keepBelow );
00367 setSkipTaskbar( session->skipTaskbar, true );
00368 setSkipPager( session->skipPager );
00369 setShade( session->shaded ? ShadeNormal : ShadeNone );
00370 if( session->maximized != MaximizeRestore )
00371 {
00372 maximize( (MaximizeMode) session->maximized );
00373 geom_restore = session->restore;
00374 }
00375 if( session->fullscreen == FullScreenHack )
00376 ;
00377 else if( session->fullscreen != FullScreenNone )
00378 {
00379 setFullScreen( true, false );
00380 geom_fs_restore = session->fsrestore;
00381 }
00382 }
00383 else
00384 {
00385 geom_restore = geometry();
00386 if ( isMaximizable()
00387 && ( width() >= area.width() || height() >= area.height() ) )
00388 {
00389
00390
00391 if ( width() >= area.width() && height() >= area.height() )
00392 {
00393 maximize( Client::MaximizeFull );
00394 geom_restore = QRect();
00395 }
00396 else if ( width() >= area.width() )
00397 {
00398 maximize( Client::MaximizeHorizontal );
00399 geom_restore = QRect();
00400 geom_restore.setY( y());
00401 geom_restore.setHeight( height());
00402 }
00403 else if ( height() >= area.height() )
00404 {
00405 maximize( Client::MaximizeVertical );
00406 geom_restore = QRect();
00407 geom_restore.setX( x());
00408 geom_restore.setWidth( width());
00409 }
00410 }
00411
00412
00413
00414
00415 MaximizeMode maxmode = static_cast< MaximizeMode >
00416 ((( info->state() & NET::MaxVert ) ? MaximizeVertical : 0 )
00417 | (( info->state() & NET::MaxHoriz ) ? MaximizeHorizontal : 0 ));
00418 MaximizeMode forced_maxmode = rules()->checkMaximize( maxmode, !isMapped );
00419
00420
00421 if( forced_maxmode != MaximizeRestore || maxmode != MaximizeRestore )
00422 maximize( forced_maxmode );
00423
00424
00425 setShade( rules()->checkShade( info->state() & NET::Shaded ? ShadeNormal : ShadeNone, !isMapped ));
00426 setKeepAbove( rules()->checkKeepAbove( info->state() & NET::KeepAbove, !isMapped ));
00427 setKeepBelow( rules()->checkKeepBelow( info->state() & NET::KeepBelow, !isMapped ));
00428 setSkipTaskbar( rules()->checkSkipTaskbar( info->state() & NET::SkipTaskbar, !isMapped ), true );
00429 setSkipPager( rules()->checkSkipPager( info->state() & NET::SkipPager, !isMapped ));
00430 if( info->state() & NET::DemandsAttention )
00431 demandAttention();
00432 if( info->state() & NET::Modal )
00433 setModal( true );
00434 if( fullscreen_mode != FullScreenHack && isFullScreenable())
00435 setFullScreen( rules()->checkFullScreen( info->state() & NET::FullScreen, !isMapped ), false );
00436 }
00437
00438 updateAllowedActions( true );
00439
00440
00441
00442
00443 XLowerWindow( qt_xdisplay(), frameId());
00444
00445
00446 user_time = readUserTimeMapTimestamp( asn_valid ? &asn_id : NULL, asn_valid ? &asn_data : NULL, session );
00447 group()->updateUserTime( user_time );
00448
00449 if( isTopMenu())
00450 hideClient( true );
00451
00452 if( isShown( true ) && !doNotShow )
00453 {
00454 if( isDialog())
00455 Notify::raise( Notify::TransNew );
00456 if( isNormalWindow())
00457 Notify::raise( Notify::New );
00458
00459 bool allow;
00460 if( session )
00461 allow = session->active
00462 && ( !workspace()->wasUserInteraction()
00463 || workspace()->activeClient() == NULL || workspace()->activeClient()->isDesktop());
00464 else
00465 allow = workspace()->allowClientActivation( this, userTime(), false );
00466
00467
00468
00469 if( !isOnCurrentDesktop() && !isMapped && !session && ( allow || workspace()->sessionSaving()))
00470 workspace()->setCurrentDesktop( desktop());
00471
00472 bool belongs_to_desktop = false;
00473 for( ClientList::ConstIterator it = group()->members().begin();
00474 it != group()->members().end();
00475 ++it )
00476 if( (*it)->isDesktop())
00477 {
00478 belongs_to_desktop = true;
00479 break;
00480 }
00481 if( !belongs_to_desktop && workspace()->showingDesktop())
00482 workspace()->resetShowingDesktop( options->showDesktopIsMinimizeAll );
00483
00484 if( isOnCurrentDesktop() && !isMapped && !allow )
00485 workspace()->restackClientUnderActive( this );
00486 else
00487 workspace()->raiseClient( this );
00488
00489 updateVisibility();
00490
00491 if( !isMapped )
00492 {
00493 if( allow && isOnCurrentDesktop())
00494 {
00495 if( !isSpecialWindow())
00496 if ( options->focusPolicyIsReasonable() && wantsTabFocus() )
00497 workspace()->requestFocus( this );
00498 }
00499 else
00500 {
00501 if( !session && !isSpecialWindow())
00502 demandAttention();
00503 }
00504 }
00505 }
00506 else if( !doNotShow )
00507 {
00508 updateVisibility();
00509 }
00510 else
00511 {
00512 hideClient( true );
00513 setMappingState( IconicState );
00514 }
00515 assert( mappingState() != WithdrawnState );
00516
00517 if( user_time == CurrentTime || user_time == -1U )
00518 {
00519 user_time = qt_x_time - 1000000;
00520 if( user_time == CurrentTime || user_time == -1U )
00521 user_time = qt_x_time - 1000000 + 10;
00522 }
00523
00524 updateWorkareaDiffs();
00525
00526
00527
00528 delete session;
00529
00530 ungrabXServer();
00531
00532 client_rules.discardTemporary();
00533 applyWindowRules();
00534 workspace()->discardUsedWindowRules( this, false );
00535 updateWindowRules();
00536
00537
00538
00539
00540 return true;
00541 }
00542
00543
00544 void Client::embedClient( Window w, const XWindowAttributes &attr )
00545 {
00546 assert( client == None );
00547 assert( frame == None );
00548 assert( wrapper == None );
00549 client = w;
00550
00551 XAddToSaveSet( qt_xdisplay(), client );
00552 XSelectInput( qt_xdisplay(), client, NoEventMask );
00553 XUnmapWindow( qt_xdisplay(), client );
00554 XWindowChanges wc;
00555 wc.border_width = 0;
00556 XConfigureWindow( qt_xdisplay(), client, CWBorderWidth, &wc );
00557
00558 XSetWindowAttributes swa;
00559 swa.colormap = attr.colormap;
00560 swa.background_pixmap = None;
00561 swa.border_pixel = 0;
00562
00563 frame = XCreateWindow( qt_xdisplay(), qt_xrootwin(), 0, 0, 1, 1, 0,
00564 attr.depth, InputOutput, attr.visual,
00565 CWColormap | CWBackPixmap | CWBorderPixel, &swa );
00566 wrapper = XCreateWindow( qt_xdisplay(), frame, 0, 0, 1, 1, 0,
00567 attr.depth, InputOutput, attr.visual,
00568 CWColormap | CWBackPixmap | CWBorderPixel, &swa );
00569
00570 XDefineCursor( qt_xdisplay(), frame, arrowCursor.handle());
00571
00572 XDefineCursor( qt_xdisplay(), wrapper, arrowCursor.handle());
00573 XReparentWindow( qt_xdisplay(), client, wrapper, 0, 0 );
00574 XSelectInput( qt_xdisplay(), frame,
00575 KeyPressMask | KeyReleaseMask |
00576 ButtonPressMask | ButtonReleaseMask |
00577 KeymapStateMask |
00578 ButtonMotionMask |
00579 PointerMotionMask |
00580 EnterWindowMask | LeaveWindowMask |
00581 FocusChangeMask |
00582 ExposureMask |
00583 PropertyChangeMask |
00584 StructureNotifyMask | SubstructureRedirectMask );
00585 XSelectInput( qt_xdisplay(), wrapper, ClientWinMask | SubstructureNotifyMask );
00586 XSelectInput( qt_xdisplay(), client,
00587 FocusChangeMask |
00588 PropertyChangeMask |
00589 ColormapChangeMask |
00590 EnterWindowMask | LeaveWindowMask |
00591 KeyPressMask | KeyReleaseMask
00592 );
00593 updateMouseGrab();
00594 }
00595
00596 }