00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "client.h"
00019 #include "workspace.h"
00020 #include "atoms.h"
00021 #include "tabbox.h"
00022 #include "group.h"
00023 #include "rules.h"
00024
00025 #include <qwhatsthis.h>
00026 #include <kkeynative.h>
00027 #include <qapplication.h>
00028
00029 #include <X11/extensions/shape.h>
00030 #include <X11/Xatom.h>
00031
00032 extern Time qt_x_time;
00033 extern Atom qt_window_role;
00034
00035 namespace KWinInternal
00036 {
00037
00038
00039
00040
00041
00042 WinInfo::WinInfo( Client * c, Display * display, Window window,
00043 Window rwin, const unsigned long pr[], int pr_size )
00044 : NETWinInfo( display, window, rwin, pr, pr_size, NET::WindowManager ), m_client( c )
00045 {
00046 }
00047
00048 void WinInfo::changeDesktop(int desktop)
00049 {
00050 m_client->workspace()->sendClientToDesktop( m_client, desktop, true );
00051 }
00052
00053 void WinInfo::changeState( unsigned long state, unsigned long mask )
00054 {
00055 mask &= ~NET::Sticky;
00056 mask &= ~NET::Hidden;
00057 state &= mask;
00058
00059 if(( mask & NET::FullScreen ) != 0 && ( state & NET::FullScreen ) == 0 )
00060 m_client->setFullScreen( false, false );
00061 if ( (mask & NET::Max) == NET::Max )
00062 m_client->setMaximize( state & NET::MaxVert, state & NET::MaxHoriz );
00063 else if ( mask & NET::MaxVert )
00064 m_client->setMaximize( state & NET::MaxVert, m_client->maximizeMode() & Client::MaximizeHorizontal );
00065 else if ( mask & NET::MaxHoriz )
00066 m_client->setMaximize( m_client->maximizeMode() & Client::MaximizeVertical, state & NET::MaxHoriz );
00067
00068 if ( mask & NET::Shaded )
00069 m_client->setShade( state & NET::Shaded ? ShadeNormal : ShadeNone );
00070 if ( mask & NET::KeepAbove)
00071 m_client->setKeepAbove( (state & NET::KeepAbove) != 0 );
00072 if ( mask & NET::KeepBelow)
00073 m_client->setKeepBelow( (state & NET::KeepBelow) != 0 );
00074 if( mask & NET::SkipTaskbar )
00075 m_client->setSkipTaskbar( ( state & NET::SkipTaskbar ) != 0, true );
00076 if( mask & NET::SkipPager )
00077 m_client->setSkipPager( ( state & NET::SkipPager ) != 0 );
00078 if( mask & NET::DemandsAttention )
00079 m_client->demandAttention(( state & NET::DemandsAttention ) != 0 );
00080 if( mask & NET::Modal )
00081 m_client->setModal( ( state & NET::Modal ) != 0 );
00082
00083 if(( mask & NET::FullScreen ) != 0 && ( state & NET::FullScreen ) != 0 )
00084 m_client->setFullScreen( true, false );
00085 }
00086
00087
00088
00089
00090
00091
00092 RootInfo::RootInfo( Workspace* ws, Display *dpy, Window w, const char *name, unsigned long pr[], int pr_num, int scr )
00093 : NETRootInfo4( dpy, w, name, pr, pr_num, scr )
00094 {
00095 workspace = ws;
00096 }
00097
00098 void RootInfo::changeNumberOfDesktops(int n)
00099 {
00100 workspace->setNumberOfDesktops( n );
00101 }
00102
00103 void RootInfo::changeCurrentDesktop(int d)
00104 {
00105 workspace->setCurrentDesktop( d );
00106 }
00107
00108 void RootInfo::changeActiveWindow( Window w, NET::RequestSource src, Time timestamp, Window active_window )
00109 {
00110 if( Client* c = workspace->findClient( WindowMatchPredicate( w )))
00111 {
00112 if( timestamp == CurrentTime )
00113 timestamp = c->userTime();
00114 if( src != NET::FromApplication && src != FromTool )
00115 src = NET::FromTool;
00116 if( src == NET::FromTool )
00117 workspace->activateClient( c, true );
00118 else
00119 {
00120 Client* c2;
00121 if( workspace->allowClientActivation( c, timestamp ))
00122 workspace->activateClient( c );
00123
00124 else if( active_window != None
00125 && ( c2 = workspace->findClient( WindowMatchPredicate( active_window ))) != NULL
00126 && workspace->allowClientActivation( c2,
00127 timestampCompare( timestamp, c2->userTime() > 0 ? timestamp : c2->userTime())))
00128 workspace->activateClient( c );
00129 else
00130 c->demandAttention();
00131 }
00132 }
00133 }
00134
00135 void RootInfo::restackWindow( Window w, RequestSource src, Window above, int detail, Time timestamp )
00136 {
00137 if( Client* c = workspace->findClient( WindowMatchPredicate( w )))
00138 {
00139 if( timestamp == CurrentTime )
00140 timestamp = c->userTime();
00141 if( src != NET::FromApplication && src != FromTool )
00142 src = NET::FromTool;
00143 c->restackWindow( above, detail, src, timestamp, true );
00144 }
00145 }
00146
00147 void RootInfo::gotTakeActivity( Window w, Time timestamp, long flags )
00148 {
00149 if( Client* c = workspace->findClient( WindowMatchPredicate( w )))
00150 workspace->handleTakeActivity( c, timestamp, flags );
00151 }
00152
00153 void RootInfo::closeWindow(Window w)
00154 {
00155 Client* c = workspace->findClient( WindowMatchPredicate( w ));
00156 if ( c )
00157 c->closeWindow();
00158 }
00159
00160 void RootInfo::moveResize(Window w, int x_root, int y_root, unsigned long direction)
00161 {
00162 Client* c = workspace->findClient( WindowMatchPredicate( w ));
00163 if ( c )
00164 {
00165 updateXTime();
00166 c->NETMoveResize( x_root, y_root, (Direction)direction);
00167 }
00168 }
00169
00170 void RootInfo::moveResizeWindow(Window w, int flags, int x, int y, int width, int height )
00171 {
00172 Client* c = workspace->findClient( WindowMatchPredicate( w ));
00173 if ( c )
00174 c->NETMoveResizeWindow( flags, x, y, width, height );
00175 }
00176
00177 void RootInfo::gotPing( Window w, Time timestamp )
00178 {
00179 if( Client* c = workspace->findClient( WindowMatchPredicate( w )))
00180 c->gotPing( timestamp );
00181 }
00182
00183 void RootInfo::changeShowingDesktop( bool showing )
00184 {
00185 workspace->setShowingDesktop( showing );
00186 }
00187
00188
00189
00190
00191
00195 bool Workspace::workspaceEvent( XEvent * e )
00196 {
00197 if ( mouse_emulation && (e->type == ButtonPress || e->type == ButtonRelease ) )
00198 {
00199 mouse_emulation = FALSE;
00200 XUngrabKeyboard( qt_xdisplay(), qt_x_time );
00201 }
00202
00203 if ( e->type == PropertyNotify || e->type == ClientMessage )
00204 {
00205 if ( netCheck( e ) )
00206 return TRUE;
00207 }
00208
00209
00210 switch (e->type)
00211 {
00212 case ButtonPress:
00213 case ButtonRelease:
00214 was_user_interaction = true;
00215
00216 case MotionNotify:
00217 if ( tab_grab || control_grab )
00218 {
00219 tab_box->handleMouseEvent( e );
00220 return TRUE;
00221 }
00222 break;
00223 case KeyPress:
00224 {
00225 was_user_interaction = true;
00226 KKeyNative keyX( (XEvent*)e );
00227 uint keyQt = keyX.keyCodeQt();
00228 kdDebug(125) << "Workspace::keyPress( " << keyX.key().toString() << " )" << endl;
00229 if (movingClient)
00230 {
00231 movingClient->keyPressEvent(keyQt);
00232 return true;
00233 }
00234 if( tab_grab || control_grab )
00235 {
00236 tabBoxKeyPress( keyX );
00237 return true;
00238 }
00239 break;
00240 }
00241 case KeyRelease:
00242 was_user_interaction = true;
00243 if( tab_grab || control_grab )
00244 {
00245 tabBoxKeyRelease( e->xkey );
00246 return true;
00247 }
00248 break;
00249 };
00250
00251 if( Client* c = findClient( WindowMatchPredicate( e->xany.window )))
00252 {
00253 if( c->windowEvent( e ))
00254 return true;
00255 }
00256 else if( Client* c = findClient( WrapperIdMatchPredicate( e->xany.window )))
00257 {
00258 if( c->windowEvent( e ))
00259 return true;
00260 }
00261 else if( Client* c = findClient( FrameIdMatchPredicate( e->xany.window )))
00262 {
00263 if( c->windowEvent( e ))
00264 return true;
00265 }
00266 else
00267 {
00268 Window special = findSpecialEventWindow( e );
00269 if( special != None )
00270 if( Client* c = findClient( WindowMatchPredicate( special )))
00271 {
00272 if( c->windowEvent( e ))
00273 return true;
00274 }
00275 }
00276 if( movingClient != NULL && movingClient->moveResizeGrabWindow() == e->xany.window
00277 && ( e->type == MotionNotify || e->type == ButtonPress || e->type == ButtonRelease ))
00278 {
00279 if( movingClient->windowEvent( e ))
00280 return true;
00281 }
00282
00283 switch (e->type)
00284 {
00285 case CreateNotify:
00286 if ( e->xcreatewindow.parent == root &&
00287 !QWidget::find( e->xcreatewindow.window) &&
00288 !e->xcreatewindow.override_redirect )
00289 {
00290
00291 XChangeProperty(qt_xdisplay(), e->xcreatewindow.window,
00292 atoms->kde_net_wm_user_creation_time, XA_CARDINAL,
00293 32, PropModeReplace, (unsigned char *)&qt_x_time, 1);
00294 }
00295 break;
00296
00297 case UnmapNotify:
00298 {
00299
00300 if ( removeSystemTrayWin( e->xunmap.window, true ) )
00301 {
00302
00303
00304
00305
00306
00307
00308
00309 XEvent ev;
00310 WId w = e->xunmap.window;
00311 if ( XCheckTypedWindowEvent (qt_xdisplay(), w,
00312 ReparentNotify, &ev) )
00313 {
00314 if ( ev.xreparent.parent != root )
00315 {
00316 XReparentWindow( qt_xdisplay(), w, root, 0, 0 );
00317 addSystemTrayWin( w );
00318 }
00319 }
00320 return TRUE;
00321 }
00322
00323 return ( e->xunmap.event != e->xunmap.window );
00324 }
00325 case MapNotify:
00326
00327 return ( e->xmap.event != e->xmap.window );
00328
00329 case ReparentNotify:
00330 {
00331
00332
00333 return TRUE;
00334 }
00335 case DestroyNotify:
00336 {
00337 if ( removeSystemTrayWin( e->xdestroywindow.window, false ) )
00338 return TRUE;
00339 return false;
00340 }
00341 case MapRequest:
00342 {
00343 updateXTime();
00344
00345
00346
00347 Client* c = findClient( WindowMatchPredicate( e->xmaprequest.window ));
00348 if ( !c )
00349 {
00350
00351
00352
00353
00354
00355
00356
00357
00358 if ( addSystemTrayWin( e->xmaprequest.window ) )
00359 return TRUE;
00360 c = createClient( e->xmaprequest.window, false );
00361 if ( c != NULL && root != qt_xrootwin() )
00362 {
00363
00364 XReparentWindow( qt_xdisplay(), c->frameId(), root, 0, 0 );
00365 }
00366 if( c == NULL )
00367 XMapRaised( qt_xdisplay(), e->xmaprequest.window );
00368 return true;
00369 }
00370 if( c )
00371 {
00372 c->windowEvent( e );
00373 updateFocusChains( c, FocusChainUpdate );
00374 return true;
00375 }
00376 break;
00377 }
00378 case EnterNotify:
00379 {
00380 if ( QWhatsThis::inWhatsThisMode() )
00381 {
00382 QWidget* w = QWidget::find( e->xcrossing.window );
00383 if ( w )
00384 QWhatsThis::leaveWhatsThisMode();
00385 }
00386 if( electricBorder(e))
00387 return true;
00388 break;
00389 }
00390 case LeaveNotify:
00391 {
00392 if ( !QWhatsThis::inWhatsThisMode() )
00393 break;
00394
00395 Client* c = findClient( FrameIdMatchPredicate( e->xcrossing.window ));
00396 if ( c && e->xcrossing.detail != NotifyInferior )
00397 QWhatsThis::leaveWhatsThisMode();
00398 break;
00399 }
00400 case ConfigureRequest:
00401 {
00402 if ( e->xconfigurerequest.parent == root )
00403 {
00404 XWindowChanges wc;
00405 wc.border_width = e->xconfigurerequest.border_width;
00406 wc.x = e->xconfigurerequest.x;
00407 wc.y = e->xconfigurerequest.y;
00408 wc.width = e->xconfigurerequest.width;
00409 wc.height = e->xconfigurerequest.height;
00410 wc.sibling = None;
00411 wc.stack_mode = Above;
00412 unsigned int value_mask = e->xconfigurerequest.value_mask
00413 & ( CWX | CWY | CWWidth | CWHeight | CWBorderWidth );
00414 XConfigureWindow( qt_xdisplay(), e->xconfigurerequest.window, value_mask, &wc );
00415 return true;
00416 }
00417 break;
00418 }
00419 case KeyPress:
00420 if ( mouse_emulation )
00421 return keyPressMouseEmulation( e->xkey );
00422 break;
00423 case KeyRelease:
00424 if ( mouse_emulation )
00425 return FALSE;
00426 break;
00427 case FocusIn:
00428 if( e->xfocus.window == rootWin()
00429 && ( e->xfocus.detail == NotifyDetailNone || e->xfocus.detail == NotifyPointerRoot ))
00430 {
00431 updateXTime();
00432 Window focus;
00433 int revert;
00434 XGetInputFocus( qt_xdisplay(), &focus, &revert );
00435 if( focus == None || focus == PointerRoot )
00436 {
00437
00438 Client *c = mostRecentlyActivatedClient();
00439 if( c != NULL )
00440 requestFocus( c, true );
00441 else if( activateNextClient( NULL ))
00442 ;
00443 else
00444 focusToNull();
00445 }
00446 }
00447
00448 case FocusOut:
00449 return true;
00450 case ClientMessage:
00451 if( electricBorder( e ))
00452 return true;
00453 break;
00454 case MappingNotify:
00455 XRefreshKeyboardMapping( &e->xmapping );
00456 tab_box->updateKeyMapping();
00457 break;
00458 default:
00459 break;
00460 }
00461 return FALSE;
00462 }
00463
00464
00465
00466
00467 Window Workspace::findSpecialEventWindow( XEvent* e )
00468 {
00469 switch( e->type )
00470 {
00471 case CreateNotify:
00472 return e->xcreatewindow.window;
00473 case DestroyNotify:
00474 return e->xdestroywindow.window;
00475 case UnmapNotify:
00476 return e->xunmap.window;
00477 case MapNotify:
00478 return e->xmap.window;
00479 case MapRequest:
00480 return e->xmaprequest.window;
00481 case ReparentNotify:
00482 return e->xreparent.window;
00483 case ConfigureNotify:
00484 return e->xconfigure.window;
00485 case GravityNotify:
00486 return e->xgravity.window;
00487 case ConfigureRequest:
00488 return e->xconfigurerequest.window;
00489 case CirculateNotify:
00490 return e->xcirculate.window;
00491 case CirculateRequest:
00492 return e->xcirculaterequest.window;
00493 default:
00494 return None;
00495 };
00496 }
00497
00501 bool Workspace::netCheck( XEvent* e )
00502 {
00503 unsigned int dirty = rootInfo->event( e );
00504
00505 if ( dirty & NET::DesktopNames )
00506 saveDesktopSettings();
00507
00508 return dirty != 0;
00509 }
00510
00511
00512
00513
00514
00515
00519 bool Client::windowEvent( XEvent* e )
00520 {
00521 if( e->xany.window == window())
00522 {
00523 unsigned long dirty[ 2 ];
00524 info->event( e, dirty, 2 );
00525
00526 if ( ( dirty[ WinInfo::PROTOCOLS ] & NET::WMName ) != 0 )
00527 fetchName();
00528 if ( ( dirty[ WinInfo::PROTOCOLS ] & NET::WMIconName ) != 0 )
00529 fetchIconicName();
00530 if ( ( dirty[ WinInfo::PROTOCOLS ] & NET::WMStrut ) != 0
00531 || ( dirty[ WinInfo::PROTOCOLS2 ] & NET::WM2ExtendedStrut ) != 0 )
00532 {
00533 if( isTopMenu())
00534 checkWorkspacePosition();
00535 workspace()->updateClientArea();
00536 }
00537 if ( ( dirty[ WinInfo::PROTOCOLS ] & NET::WMIcon) != 0 )
00538 getIcons();
00539
00540
00541
00542 if(( dirty[ WinInfo::PROTOCOLS2 ] & NET::WM2UserTime ) != 0 )
00543 {
00544 workspace()->setWasUserInteraction();
00545 updateUserTime( info->userTime());
00546 }
00547 if(( dirty[ WinInfo::PROTOCOLS2 ] & NET::WM2StartupId ) != 0 )
00548 startupIdChanged();
00549 if( dirty[ WinInfo::PROTOCOLS ] & NET::WMIconGeometry )
00550 {
00551 if( demandAttentionKNotifyTimer != NULL )
00552 demandAttentionKNotify();
00553 }
00554 }
00555
00556
00557 switch (e->type)
00558 {
00559 case UnmapNotify:
00560 unmapNotifyEvent( &e->xunmap );
00561 break;
00562 case DestroyNotify:
00563 destroyNotifyEvent( &e->xdestroywindow );
00564 break;
00565 case MapRequest:
00566
00567 return mapRequestEvent( &e->xmaprequest );
00568 case ConfigureRequest:
00569 configureRequestEvent( &e->xconfigurerequest );
00570 break;
00571 case PropertyNotify:
00572 propertyNotifyEvent( &e->xproperty );
00573 break;
00574 case KeyPress:
00575 updateUserTime();
00576 workspace()->setWasUserInteraction();
00577 break;
00578 case ButtonPress:
00579 updateUserTime();
00580 workspace()->setWasUserInteraction();
00581 buttonPressEvent( e->xbutton.window, e->xbutton.button, e->xbutton.state,
00582 e->xbutton.x, e->xbutton.y, e->xbutton.x_root, e->xbutton.y_root );
00583 break;
00584 case KeyRelease:
00585
00586
00587
00588 break;
00589 case ButtonRelease:
00590
00591
00592
00593 buttonReleaseEvent( e->xbutton.window, e->xbutton.button, e->xbutton.state,
00594 e->xbutton.x, e->xbutton.y, e->xbutton.x_root, e->xbutton.y_root );
00595 break;
00596 case MotionNotify:
00597 motionNotifyEvent( e->xmotion.window, e->xmotion.state,
00598 e->xmotion.x, e->xmotion.y, e->xmotion.x_root, e->xmotion.y_root );
00599 break;
00600 case EnterNotify:
00601 enterNotifyEvent( &e->xcrossing );
00602
00603
00604
00605
00606
00607 motionNotifyEvent( e->xcrossing.window, e->xcrossing.state,
00608 e->xcrossing.x, e->xcrossing.y, e->xcrossing.x_root, e->xcrossing.y_root );
00609 break;
00610 case LeaveNotify:
00611 motionNotifyEvent( e->xcrossing.window, e->xcrossing.state,
00612 e->xcrossing.x, e->xcrossing.y, e->xcrossing.x_root, e->xcrossing.y_root );
00613 leaveNotifyEvent( &e->xcrossing );
00614 break;
00615 case FocusIn:
00616 focusInEvent( &e->xfocus );
00617 break;
00618 case FocusOut:
00619 focusOutEvent( &e->xfocus );
00620 break;
00621 case ReparentNotify:
00622 break;
00623 case ClientMessage:
00624 clientMessageEvent( &e->xclient );
00625 break;
00626 case ColormapChangeMask:
00627 if( e->xany.window == window())
00628 {
00629 cmap = e->xcolormap.colormap;
00630 if ( isActive() )
00631 workspace()->updateColormap();
00632 }
00633 break;
00634 case VisibilityNotify:
00635 visibilityNotifyEvent( &e->xvisibility );
00636 break;
00637 default:
00638 if( e->xany.window == window())
00639 {
00640 if( e->type == Shape::shapeEvent() )
00641 {
00642 is_shape = Shape::hasShape( window());
00643 updateShape();
00644 }
00645 }
00646 break;
00647 }
00648 return true;
00649 }
00650
00654 bool Client::mapRequestEvent( XMapRequestEvent* e )
00655 {
00656 if( e->window != window())
00657 {
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670 if( e->parent == wrapperId())
00671 return false;
00672 return true;
00673 }
00674 if( isTopMenu() && workspace()->managingTopMenus())
00675 return true;
00676 switch ( mappingState() )
00677 {
00678 case WithdrawnState:
00679 assert( false );
00680
00681 break;
00682 case IconicState:
00683
00684 if( isMinimized())
00685 unminimize();
00686 if( isShade())
00687 setShade( ShadeNone );
00688 if( !isOnCurrentDesktop())
00689 {
00690 if( workspace()->allowClientActivation( this ))
00691 workspace()->activateClient( this );
00692 else
00693 demandAttention();
00694 }
00695 break;
00696 case NormalState:
00697
00698 break;
00699 }
00700 return true;
00701 }
00702
00706 void Client::unmapNotifyEvent( XUnmapEvent* e )
00707 {
00708 if( e->window != window())
00709 return;
00710 if( e->event != wrapperId())
00711 {
00712 bool ignore = true;
00713 if( e->event == workspace()->rootWin() && e->send_event )
00714 ignore = false;
00715 if( ignore )
00716 return;
00717 }
00718 switch( mappingState())
00719 {
00720 case IconicState:
00721 releaseWindow();
00722 return;
00723 case NormalState:
00724
00725 XEvent ev;
00726 if( XCheckTypedWindowEvent (qt_xdisplay(), window(),
00727 DestroyNotify, &ev) )
00728 {
00729 destroyClient();
00730 return;
00731 }
00732 releaseWindow();
00733 break;
00734 default:
00735 assert( false );
00736 }
00737 }
00738
00739 void Client::destroyNotifyEvent( XDestroyWindowEvent* e )
00740 {
00741 if( e->window != window())
00742 return;
00743 destroyClient();
00744 }
00745
00746
00747 bool blockAnimation = FALSE;
00748
00752 void Client::clientMessageEvent( XClientMessageEvent* e )
00753 {
00754 if( e->window != window())
00755 return;
00756
00757 if ( e->message_type == atoms->kde_wm_change_state )
00758 {
00759 if( isTopMenu() && workspace()->managingTopMenus())
00760 return;
00761 if( e->data.l[ 1 ] )
00762 blockAnimation = true;
00763 if( e->data.l[ 0 ] == IconicState )
00764 minimize();
00765 else if( e->data.l[ 0 ] == NormalState )
00766 {
00767 if( isMinimized())
00768 unminimize();
00769 if( isShade())
00770 setShade( ShadeNone );
00771 if( !isOnCurrentDesktop())
00772 {
00773 if( workspace()->allowClientActivation( this ))
00774 workspace()->activateClient( this );
00775 else
00776 demandAttention();
00777 }
00778 }
00779 blockAnimation = false;
00780 }
00781 else if ( e->message_type == atoms->wm_change_state)
00782 {
00783 if( isTopMenu() && workspace()->managingTopMenus())
00784 return;
00785 if ( e->data.l[0] == IconicState )
00786 minimize();
00787 return;
00788 }
00789 }
00790
00791
00795 void Client::configureRequestEvent( XConfigureRequestEvent* e )
00796 {
00797 if( e->window != window())
00798 return;
00799 if ( isResize() || isMove())
00800 return;
00801
00802 if( fullscreen_mode == FullScreenNormal )
00803 {
00804 sendSyntheticConfigureNotify();
00805 return;
00806 }
00807 if( isSplash()
00808 || isTopMenu())
00809 {
00810 sendSyntheticConfigureNotify();
00811 return;
00812 }
00813
00814 if ( e->value_mask & CWBorderWidth )
00815 {
00816
00817 XWindowChanges wc;
00818 unsigned int value_mask = 0;
00819
00820 wc.border_width = 0;
00821 value_mask = CWBorderWidth;
00822 XConfigureWindow( qt_xdisplay(), window(), value_mask, & wc );
00823 }
00824
00825 if( e->value_mask & ( CWX | CWY | CWHeight | CWWidth ))
00826 configureRequest( e->value_mask, e->x, e->y, e->width, e->height, 0, false );
00827
00828 if ( e->value_mask & CWStackMode )
00829 restackWindow( e->above, e->detail, NET::FromApplication, userTime(), false );
00830
00831
00832
00833
00834
00835
00836 sendSyntheticConfigureNotify();
00837
00838
00839
00840 }
00841
00842
00846 void Client::propertyNotifyEvent( XPropertyEvent* e )
00847 {
00848 if( e->window != window())
00849 return;
00850 switch ( e->atom )
00851 {
00852 case XA_WM_NORMAL_HINTS:
00853 getWmNormalHints();
00854 break;
00855 case XA_WM_NAME:
00856 fetchName();
00857 break;
00858 case XA_WM_ICON_NAME:
00859 fetchIconicName();
00860 break;
00861 case XA_WM_TRANSIENT_FOR:
00862 readTransient();
00863 break;
00864 case XA_WM_HINTS:
00865 getWMHints();
00866 getIcons();
00867 break;
00868 default:
00869 if ( e->atom == atoms->wm_protocols )
00870 getWindowProtocols();
00871 else if (e->atom == atoms->wm_client_leader )
00872 getWmClientLeader();
00873 else if( e->atom == qt_window_role )
00874 window_role = staticWindowRole( window());
00875 else if( e->atom == atoms->motif_wm_hints )
00876 getMotifHints();
00877 break;
00878 }
00879 }
00880
00881
00882 void Client::enterNotifyEvent( XCrossingEvent* e )
00883 {
00884 if( e->window != frameId())
00885 return;
00886 if( e->mode == NotifyNormal ||
00887 ( !options->focusPolicyIsReasonable() &&
00888 e->mode == NotifyUngrab ) )
00889 {
00890
00891 if (options->shadeHover && isShade())
00892 {
00893 delete shadeHoverTimer;
00894 shadeHoverTimer = new QTimer( this );
00895 connect( shadeHoverTimer, SIGNAL( timeout() ), this, SLOT( shadeHover() ));
00896 shadeHoverTimer->start( options->shadeHoverInterval, TRUE );
00897 }
00898
00899 if ( options->focusPolicy == Options::ClickToFocus )
00900 return;
00901
00902 if ( options->autoRaise && !isDesktop() &&
00903 !isDock() && !isTopMenu() && workspace()->focusChangeEnabled() &&
00904 workspace()->topClientOnDesktop( workspace()->currentDesktop()) != this )
00905 {
00906 delete autoRaiseTimer;
00907 autoRaiseTimer = new QTimer( this );
00908 connect( autoRaiseTimer, SIGNAL( timeout() ), this, SLOT( autoRaise() ) );
00909 autoRaiseTimer->start( options->autoRaiseInterval, TRUE );
00910 }
00911
00912 if ( options->focusPolicy != Options::FocusStrictlyUnderMouse && ( isDesktop() || isDock() || isTopMenu() ) )
00913 return;
00914 if ( options->delayFocus )
00915 workspace()->requestDelayFocus( this );
00916 else
00917 workspace()->requestFocus( this );
00918
00919 return;
00920 }
00921 }
00922
00923 void Client::leaveNotifyEvent( XCrossingEvent* e )
00924 {
00925 if( e->window != frameId())
00926 return;
00927 if ( e->mode == NotifyNormal )
00928 {
00929 if ( !buttonDown )
00930 {
00931 mode = PositionCenter;
00932 setCursor( arrowCursor );
00933 }
00934 bool lostMouse = !rect().contains( QPoint( e->x, e->y ) );
00935
00936
00937
00938
00939
00940
00941
00942 if ( !lostMouse && e->detail != NotifyInferior )
00943 {
00944 int d1, d2, d3, d4;
00945 unsigned int d5;
00946 Window w, child;
00947 if( XQueryPointer( qt_xdisplay(), frameId(), &w, &child, &d1, &d2, &d3, &d4, &d5 ) == False
00948 || child == None )
00949 lostMouse = true;
00950 }
00951 if ( lostMouse )
00952 {
00953 cancelAutoRaise();
00954 workspace()->cancelDelayFocus();
00955 cancelShadeHover();
00956 if ( shade_mode == ShadeHover && !moveResizeMode && !buttonDown )
00957 setShade( ShadeNormal );
00958 }
00959 if ( options->focusPolicy == Options::FocusStrictlyUnderMouse )
00960 if ( isActive() && lostMouse )
00961 workspace()->requestFocus( 0 ) ;
00962 return;
00963 }
00964 }
00965
00966 #define XCapL KKeyNative::modXLock()
00967 #define XNumL KKeyNative::modXNumLock()
00968 #define XScrL KKeyNative::modXScrollLock()
00969 void Client::grabButton( int modifier )
00970 {
00971 unsigned int mods[ 8 ] =
00972 {
00973 0, XCapL, XNumL, XNumL | XCapL,
00974 XScrL, XScrL | XCapL,
00975 XScrL | XNumL, XScrL | XNumL | XCapL
00976 };
00977 for( int i = 0;
00978 i < 8;
00979 ++i )
00980 XGrabButton( qt_xdisplay(), AnyButton,
00981 modifier | mods[ i ],
00982 wrapperId(), FALSE, ButtonPressMask,
00983 GrabModeSync, GrabModeAsync, None, None );
00984 }
00985
00986 void Client::ungrabButton( int modifier )
00987 {
00988 unsigned int mods[ 8 ] =
00989 {
00990 0, XCapL, XNumL, XNumL | XCapL,
00991 XScrL, XScrL | XCapL,
00992 XScrL | XNumL, XScrL | XNumL | XCapL
00993 };
00994 for( int i = 0;
00995 i < 8;
00996 ++i )
00997 XUngrabButton( qt_xdisplay(), AnyButton,
00998 modifier | mods[ i ], wrapperId());
00999 }
01000 #undef XCapL
01001 #undef XNumL
01002 #undef XScrL
01003
01004
01005
01006
01007
01008
01009
01010 void Client::updateMouseGrab()
01011 {
01012 if( workspace()->globalShortcutsDisabled())
01013 {
01014 XUngrabButton( qt_xdisplay(), AnyButton, AnyModifier, wrapperId());
01015
01016 if( !( !options->clickRaise || not_obscured ))
01017 grabButton( None );
01018 return;
01019 }
01020 if( isActive() && !workspace()->forcedGlobalMouseGrab())
01021 {
01022
01023
01024 if( !options->clickRaise || not_obscured )
01025 ungrabButton( None );
01026 else
01027 grabButton( None );
01028 ungrabButton( ShiftMask );
01029 ungrabButton( ControlMask );
01030 ungrabButton( ControlMask | ShiftMask );
01031 }
01032 else
01033 {
01034 XUngrabButton( qt_xdisplay(), AnyButton, AnyModifier, wrapperId());
01035
01036 XGrabButton(qt_xdisplay(), AnyButton, AnyModifier, wrapperId(), FALSE,
01037 ButtonPressMask,
01038 GrabModeSync, GrabModeAsync,
01039 None, None );
01040 }
01041 }
01042
01043 int qtToX11Button( Qt::ButtonState button )
01044 {
01045 if( button == Qt::LeftButton )
01046 return Button1;
01047 else if( button == Qt::MidButton )
01048 return Button2;
01049 else if( button == Qt::RightButton )
01050 return Button3;
01051 return AnyButton;
01052 }
01053
01054 int qtToX11State( Qt::ButtonState state )
01055 {
01056 int ret = 0;
01057 if( state & Qt::LeftButton )
01058 ret |= Button1Mask;
01059 if( state & Qt::MidButton )
01060 ret |= Button2Mask;
01061 if( state & Qt::RightButton )
01062 ret |= Button3Mask;
01063 if( state & Qt::ShiftButton )
01064 ret |= ShiftMask;
01065 if( state & Qt::ControlButton )
01066 ret |= ControlMask;
01067 if( state & Qt::AltButton )
01068 ret |= KKeyNative::modX(KKey::ALT);
01069 if( state & Qt::MetaButton )
01070 ret |= KKeyNative::modX(KKey::WIN);
01071 return ret;
01072 }
01073
01074
01075
01076 bool Client::eventFilter( QObject* o, QEvent* e )
01077 {
01078 if( decoration == NULL
01079 || o != decoration->widget())
01080 return false;
01081 if( e->type() == QEvent::MouseButtonPress )
01082 {
01083 QMouseEvent* ev = static_cast< QMouseEvent* >( e );
01084 return buttonPressEvent( decorationId(), qtToX11Button( ev->button()), qtToX11State( ev->state()),
01085 ev->x(), ev->y(), ev->globalX(), ev->globalY() );
01086 }
01087 if( e->type() == QEvent::MouseButtonRelease )
01088 {
01089 QMouseEvent* ev = static_cast< QMouseEvent* >( e );
01090 return buttonReleaseEvent( decorationId(), qtToX11Button( ev->button()), qtToX11State( ev->state()),
01091 ev->x(), ev->y(), ev->globalX(), ev->globalY() );
01092 }
01093 if( e->type() == QEvent::MouseMove )
01094 {
01095 QMouseEvent* ev = static_cast< QMouseEvent* >( e );
01096 return motionNotifyEvent( decorationId(), qtToX11State( ev->state()),
01097 ev->x(), ev->y(), ev->globalX(), ev->globalY() );
01098 }
01099 if( e->type() == QEvent::Wheel )
01100 {
01101 QWheelEvent* ev = static_cast< QWheelEvent* >( e );
01102 bool r = buttonPressEvent( decorationId(), ev->delta() > 0 ? Button4 : Button5, qtToX11State( ev->state()),
01103 ev->x(), ev->y(), ev->globalX(), ev->globalY() );
01104 r = r || buttonReleaseEvent( decorationId(), ev->delta() > 0 ? Button4 : Button5, qtToX11State( ev->state()),
01105 ev->x(), ev->y(), ev->globalX(), ev->globalY() );
01106 return r;
01107 }
01108 if( e->type() == QEvent::Resize )
01109 {
01110 QResizeEvent* ev = static_cast< QResizeEvent* >( e );
01111
01112
01113
01114
01115 if( ev->size() != size())
01116 return true;
01117 }
01118 return false;
01119 }
01120
01121
01122 bool Client::buttonPressEvent( Window w, int button, int state, int x, int y, int x_root, int y_root )
01123 {
01124 if (buttonDown)
01125 {
01126 if( w == wrapperId())
01127 XAllowEvents(qt_xdisplay(), SyncPointer, CurrentTime );
01128 return true;
01129 }
01130
01131 if( w == wrapperId() || w == frameId() || w == decorationId())
01132 {
01133 updateUserTime();
01134 workspace()->setWasUserInteraction();
01135 uint keyModX = (options->keyCmdAllModKey() == Qt::Key_Meta) ?
01136 KKeyNative::modX(KKey::WIN) :
01137 KKeyNative::modX(KKey::ALT);
01138 bool bModKeyHeld = keyModX != 0 && ( state & KKeyNative::accelModMaskX()) == keyModX;
01139
01140 if( isSplash()
01141 && button == Button1 && !bModKeyHeld )
01142 {
01143 hideClient( true );
01144 if( w == wrapperId())
01145 XAllowEvents(qt_xdisplay(), SyncPointer, CurrentTime );
01146 return true;
01147 }
01148
01149 Options::MouseCommand com = Options::MouseNothing;
01150 bool was_action = false;
01151 bool perform_handled = false;
01152 if ( bModKeyHeld )
01153 {
01154 was_action = true;
01155 switch (button)
01156 {
01157 case Button1:
01158 com = options->commandAll1();
01159 break;
01160 case Button2:
01161 com = options->commandAll2();
01162 break;
01163 case Button3:
01164 com = options->commandAll3();
01165 break;
01166 case Button4:
01167 case Button5:
01168 com = options->operationWindowMouseWheel( button == Button4 ? 120 : -120 );
01169 break;
01170 }
01171 }
01172 else
01173 {
01174 if( !isActive() && w == wrapperId())
01175 {
01176 was_action = true;
01177 perform_handled = true;
01178 switch (button)
01179 {
01180 case Button1:
01181 com = options->commandWindow1();
01182 break;
01183 case Button2:
01184 com = options->commandWindow2();
01185 break;
01186 case Button3:
01187 com = options->commandWindow3();
01188 break;
01189 default:
01190 com = Options::MouseActivateAndPassClick;
01191 }
01192 }
01193
01194 if( isActive() && w == wrapperId()
01195 && options->clickRaise && button < 4 )
01196 {
01197 com = Options::MouseActivateRaiseAndPassClick;
01198 was_action = true;
01199 perform_handled = true;
01200 }
01201 }
01202 if( was_action )
01203 {
01204 bool replay = performMouseCommand( com, QPoint( x_root, y_root), perform_handled );
01205
01206 if ( isSpecialWindow())
01207 replay = TRUE;
01208
01209 if( w == wrapperId())
01210 XAllowEvents(qt_xdisplay(), replay? ReplayPointer : SyncPointer, CurrentTime );
01211 return true;
01212 }
01213 }
01214
01215 if( w == wrapperId())
01216 {
01217 XAllowEvents(qt_xdisplay(), ReplayPointer, CurrentTime );
01218 return true;
01219 }
01220 if( w == decorationId())
01221 return false;
01222 if( w == frameId())
01223 processDecorationButtonPress( button, state, x, y, x_root, y_root );
01224 return true;
01225 }
01226
01227
01228
01229
01230 void Client::processDecorationButtonPress( int button, int , int x, int y, int x_root, int y_root )
01231 {
01232 Options::MouseCommand com = Options::MouseNothing;
01233 bool active = isActive();
01234 if ( !wantsInput() )
01235 active = TRUE;
01236
01237 if ( button == Button1 )
01238 com = active ? options->commandActiveTitlebar1() : options->commandInactiveTitlebar1();
01239 else if ( button == Button2 )
01240 com = active ? options->commandActiveTitlebar2() : options->commandInactiveTitlebar2();
01241 else if ( button == Button3 )
01242 com = active ? options->commandActiveTitlebar3() : options->commandInactiveTitlebar3();
01243 if( button == Button1
01244 && com != Options::MouseOperationsMenu
01245 && com != Options::MouseMinimize )
01246 {
01247 mode = mousePosition( QPoint( x, y ));
01248 buttonDown = TRUE;
01249 moveOffset = QPoint( x, y );
01250 invertedMoveOffset = rect().bottomRight() - moveOffset;
01251 unrestrictedMoveResize = false;
01252 setCursor( mode );
01253 }
01254 performMouseCommand( com, QPoint( x_root, y_root ));
01255 }
01256
01257
01258 void Client::processMousePressEvent( QMouseEvent* e )
01259 {
01260 if( e->type() != QEvent::MouseButtonPress )
01261 {
01262 kdWarning() << "processMousePressEvent()" << endl;
01263 return;
01264 }
01265 int button;
01266 switch( e->button())
01267 {
01268 case LeftButton:
01269 button = Button1;
01270 break;
01271 case MidButton:
01272 button = Button2;
01273 break;
01274 case RightButton:
01275 button = Button3;
01276 break;
01277 default:
01278 return;
01279 }
01280 processDecorationButtonPress( button, e->state(), e->x(), e->y(), e->globalX(), e->globalY());
01281 }
01282
01283
01284 bool Client::buttonReleaseEvent( Window w, int , int state, int x, int y, int x_root, int y_root )
01285 {
01286 if( w == decorationId() && !buttonDown)
01287 return false;
01288 if( w == wrapperId())
01289 {
01290 XAllowEvents(qt_xdisplay(), SyncPointer, CurrentTime );
01291 return true;
01292 }
01293 if( w != frameId() && w != decorationId() && w != moveResizeGrabWindow())
01294 return true;
01295 x = this->x();
01296 y = this->y();
01297 if ( (state & ( Button1Mask & Button2Mask & Button3Mask )) == 0 )
01298 {
01299 buttonDown = FALSE;
01300 if ( moveResizeMode )
01301 {
01302 finishMoveResize( false );
01303
01304 QPoint mousepos( x_root - x, y_root - y );
01305 mode = mousePosition( mousepos );
01306 }
01307 setCursor( mode );
01308 }
01309 return true;
01310 }
01311
01312 static bool was_motion = false;
01313 static Time next_motion_time = CurrentTime;
01314
01315
01316
01317
01318
01319
01320
01321 static Bool motion_predicate( Display*, XEvent* ev, XPointer )
01322 {
01323 if( ev->type == MotionNotify )
01324 {
01325 was_motion = true;
01326 next_motion_time = ev->xmotion.time;
01327 }
01328 return False;
01329 }
01330
01331 static bool waitingMotionEvent()
01332 {
01333
01334
01335
01336 if( next_motion_time != CurrentTime
01337 && timestampCompare( qt_x_time, next_motion_time ) < 0 )
01338 return true;
01339 was_motion = false;
01340 XSync( qt_xdisplay(), False );
01341 XEvent dummy;
01342 XCheckIfEvent( qt_xdisplay(), &dummy, motion_predicate, NULL );
01343 return was_motion;
01344 }
01345
01346
01347 bool Client::motionNotifyEvent( Window w, int , int x, int y, int x_root, int y_root )
01348 {
01349 if( w != frameId() && w != decorationId() && w != moveResizeGrabWindow())
01350 return true;
01351 if ( !buttonDown )
01352 {
01353 Position newmode = mousePosition( QPoint( x, y ));
01354 if( newmode != mode )
01355 setCursor( newmode );
01356 mode = newmode;
01357
01358
01359 next_motion_time = CurrentTime;
01360 return false;
01361 }
01362 if( w == moveResizeGrabWindow())
01363 {
01364 x = this->x();
01365 y = this->y();
01366 }
01367 if( !waitingMotionEvent())
01368 handleMoveResize( x, y, x_root, y_root );
01369 return true;
01370 }
01371
01372 void Client::focusInEvent( XFocusInEvent* e )
01373 {
01374 if( e->window != window())
01375 return;
01376 if ( e->mode == NotifyUngrab )
01377 return;
01378 if ( e->detail == NotifyPointer )
01379 return;
01380 if( !isShown( false ) || !isOnCurrentDesktop())
01381 return;
01382
01383 bool activate = workspace()->allowClientActivation( this, -1U, true );
01384 workspace()->gotFocusIn( this );
01385 if( activate )
01386 setActive( TRUE );
01387 else
01388 {
01389 workspace()->restoreFocus();
01390 demandAttention();
01391 }
01392 }
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408 static bool follows_focusin = false;
01409 static bool follows_focusin_failed = false;
01410 static Bool predicate_follows_focusin( Display*, XEvent* e, XPointer arg )
01411 {
01412 if( follows_focusin || follows_focusin_failed )
01413 return False;
01414 Client* c = ( Client* ) arg;
01415 if( e->type == FocusIn && c->workspace()->findClient( WindowMatchPredicate( e->xfocus.window )))
01416 {
01417 follows_focusin = true;
01418 return False;
01419 }
01420
01421
01422 if( e->type == FocusIn || e->type == FocusOut || e->type == KeymapNotify )
01423 return False;
01424 follows_focusin_failed = true;
01425 return False;
01426 }
01427
01428 static bool check_follows_focusin( Client* c )
01429 {
01430 follows_focusin = follows_focusin_failed = false;
01431 XEvent dummy;
01432
01433
01434
01435 XCheckIfEvent( qt_xdisplay(), &dummy, predicate_follows_focusin, (XPointer)c );
01436 return follows_focusin;
01437 }
01438
01439
01440 void Client::focusOutEvent( XFocusOutEvent* e )
01441 {
01442 if( e->window != window())
01443 return;
01444 if ( e->mode == NotifyGrab )
01445 return;
01446 if ( isShade() )
01447 return;
01448 if ( e->detail != NotifyNonlinear
01449 && e->detail != NotifyNonlinearVirtual )
01450
01451 return;
01452 if ( QApplication::activePopupWidget() )
01453 return;
01454 if( !check_follows_focusin( this ))
01455 setActive( FALSE );
01456 }
01457
01458 void Client::visibilityNotifyEvent( XVisibilityEvent * e)
01459 {
01460 if( e->window != frameId())
01461 return;
01462 bool new_not_obscured = e->state == VisibilityUnobscured;
01463 if( not_obscured == new_not_obscured )
01464 return;
01465 not_obscured = new_not_obscured;
01466 updateMouseGrab();
01467 }
01468
01469
01470 void Client::NETMoveResize( int x_root, int y_root, NET::Direction direction )
01471 {
01472 if( direction == NET::Move )
01473 performMouseCommand( Options::MouseMove, QPoint( x_root, y_root ));
01474 else if( moveResizeMode && direction == NET::MoveResizeCancel )
01475 {
01476 finishMoveResize( true );
01477 buttonDown = FALSE;
01478 setCursor( mode );
01479 }
01480 else if( direction >= NET::TopLeft && direction <= NET::Left )
01481 {
01482 static const Position convert[] =
01483 {
01484 PositionTopLeft,
01485 PositionTop,
01486 PositionTopRight,
01487 PositionRight,
01488 PositionBottomRight,
01489 PositionBottom,
01490 PositionBottomLeft,
01491 PositionLeft
01492 };
01493 if(!isResizable() || isShade())
01494 return;
01495 if( moveResizeMode )
01496 finishMoveResize( false );
01497 buttonDown = TRUE;
01498 moveOffset = QPoint( x_root - x(), y_root - y());
01499 invertedMoveOffset = rect().bottomRight() - moveOffset;
01500 unrestrictedMoveResize = false;
01501 mode = convert[ direction ];
01502 setCursor( mode );
01503 if( !startMoveResize())
01504 {
01505 buttonDown = false;
01506 setCursor( mode );
01507 }
01508 }
01509 else if( direction == NET::KeyboardMove )
01510 {
01511 QCursor::setPos( geometry().center() );
01512 performMouseCommand( Options::MouseUnrestrictedMove, geometry().center());
01513 }
01514 else if( direction == NET::KeyboardSize )
01515 {
01516 QCursor::setPos( geometry().bottomRight());
01517 performMouseCommand( Options::MouseUnrestrictedResize, geometry().bottomRight());
01518 }
01519 }
01520
01521 void Client::keyPressEvent( uint key_code )
01522 {
01523 updateUserTime();
01524 if ( !isMove() && !isResize() )
01525 return;
01526 bool is_control = key_code & Qt::CTRL;
01527 bool is_alt = key_code & Qt::ALT;
01528 key_code = key_code & 0xffff;
01529 int delta = is_control?1:is_alt?32:8;
01530 QPoint pos = QCursor::pos();
01531 switch ( key_code )
01532 {
01533 case Key_Left:
01534 pos.rx() -= delta;
01535 break;
01536 case Key_Right:
01537 pos.rx() += delta;
01538 break;
01539 case Key_Up:
01540 pos.ry() -= delta;
01541 break;
01542 case Key_Down:
01543 pos.ry() += delta;
01544 break;
01545 case Key_Space:
01546 case Key_Return:
01547 case Key_Enter:
01548 finishMoveResize( false );
01549 buttonDown = FALSE;
01550 setCursor( mode );
01551 break;
01552 case Key_Escape:
01553 finishMoveResize( true );
01554 buttonDown = FALSE;
01555 setCursor( mode );
01556 break;
01557 default:
01558 return;
01559 }
01560 QCursor::setPos( pos );
01561 }
01562
01563
01564
01565
01566
01567 bool Group::groupEvent( XEvent* e )
01568 {
01569 unsigned long dirty[ 2 ];
01570 leader_info->event( e, dirty, 2 );
01571 if ( ( dirty[ WinInfo::PROTOCOLS ] & NET::WMIcon) != 0 )
01572 getIcons();
01573 if(( dirty[ WinInfo::PROTOCOLS2 ] & NET::WM2StartupId ) != 0 )
01574 startupIdChanged();
01575 return false;
01576 }
01577
01578
01579 }