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 default:
00455 break;
00456 }
00457 return FALSE;
00458 }
00459
00460
00461
00462
00463 Window Workspace::findSpecialEventWindow( XEvent* e )
00464 {
00465 switch( e->type )
00466 {
00467 case CreateNotify:
00468 return e->xcreatewindow.window;
00469 case DestroyNotify:
00470 return e->xdestroywindow.window;
00471 case UnmapNotify:
00472 return e->xunmap.window;
00473 case MapNotify:
00474 return e->xmap.window;
00475 case MapRequest:
00476 return e->xmaprequest.window;
00477 case ReparentNotify:
00478 return e->xreparent.window;
00479 case ConfigureNotify:
00480 return e->xconfigure.window;
00481 case GravityNotify:
00482 return e->xgravity.window;
00483 case ConfigureRequest:
00484 return e->xconfigurerequest.window;
00485 case CirculateNotify:
00486 return e->xcirculate.window;
00487 case CirculateRequest:
00488 return e->xcirculaterequest.window;
00489 default:
00490 return None;
00491 };
00492 }
00493
00497 bool Workspace::netCheck( XEvent* e )
00498 {
00499 unsigned int dirty = rootInfo->event( e );
00500
00501 if ( dirty & NET::DesktopNames )
00502 saveDesktopSettings();
00503
00504 return dirty != 0;
00505 }
00506
00507
00508
00509
00510
00511
00515 bool Client::windowEvent( XEvent* e )
00516 {
00517 if( e->xany.window == window())
00518 {
00519 unsigned long dirty[ 2 ];
00520 info->event( e, dirty, 2 );
00521
00522 if ( ( dirty[ WinInfo::PROTOCOLS ] & NET::WMName ) != 0 )
00523 fetchName();
00524 if ( ( dirty[ WinInfo::PROTOCOLS ] & NET::WMIconName ) != 0 )
00525 fetchIconicName();
00526 if ( ( dirty[ WinInfo::PROTOCOLS ] & NET::WMStrut ) != 0
00527 || ( dirty[ WinInfo::PROTOCOLS2 ] & NET::WM2ExtendedStrut ) != 0 )
00528 {
00529 if( isTopMenu())
00530 checkWorkspacePosition();
00531 workspace()->updateClientArea();
00532 }
00533 if ( ( dirty[ WinInfo::PROTOCOLS ] & NET::WMIcon) != 0 )
00534 getIcons();
00535
00536
00537
00538 if(( dirty[ WinInfo::PROTOCOLS2 ] & NET::WM2UserTime ) != 0 )
00539 {
00540 workspace()->setWasUserInteraction();
00541 updateUserTime( info->userTime());
00542 }
00543 if(( dirty[ WinInfo::PROTOCOLS2 ] & NET::WM2StartupId ) != 0 )
00544 startupIdChanged();
00545 if( dirty[ WinInfo::PROTOCOLS ] & NET::WMIconGeometry )
00546 {
00547 if( demandAttentionKNotifyTimer != NULL )
00548 demandAttentionKNotify();
00549 }
00550 }
00551
00552
00553 switch (e->type)
00554 {
00555 case UnmapNotify:
00556 unmapNotifyEvent( &e->xunmap );
00557 break;
00558 case DestroyNotify:
00559 destroyNotifyEvent( &e->xdestroywindow );
00560 break;
00561 case MapRequest:
00562
00563 return mapRequestEvent( &e->xmaprequest );
00564 case ConfigureRequest:
00565 configureRequestEvent( &e->xconfigurerequest );
00566 break;
00567 case PropertyNotify:
00568 propertyNotifyEvent( &e->xproperty );
00569 break;
00570 case KeyPress:
00571 updateUserTime();
00572 workspace()->setWasUserInteraction();
00573 break;
00574 case ButtonPress:
00575 updateUserTime();
00576 workspace()->setWasUserInteraction();
00577 buttonPressEvent( e->xbutton.window, e->xbutton.button, e->xbutton.state,
00578 e->xbutton.x, e->xbutton.y, e->xbutton.x_root, e->xbutton.y_root );
00579 break;
00580 case KeyRelease:
00581
00582
00583
00584 break;
00585 case ButtonRelease:
00586
00587
00588
00589 buttonReleaseEvent( e->xbutton.window, e->xbutton.button, e->xbutton.state,
00590 e->xbutton.x, e->xbutton.y, e->xbutton.x_root, e->xbutton.y_root );
00591 break;
00592 case MotionNotify:
00593 motionNotifyEvent( e->xmotion.window, e->xmotion.state,
00594 e->xmotion.x, e->xmotion.y, e->xmotion.x_root, e->xmotion.y_root );
00595 break;
00596 case EnterNotify:
00597 enterNotifyEvent( &e->xcrossing );
00598
00599
00600
00601
00602
00603 motionNotifyEvent( e->xcrossing.window, e->xcrossing.state,
00604 e->xcrossing.x, e->xcrossing.y, e->xcrossing.x_root, e->xcrossing.y_root );
00605 break;
00606 case LeaveNotify:
00607 motionNotifyEvent( e->xcrossing.window, e->xcrossing.state,
00608 e->xcrossing.x, e->xcrossing.y, e->xcrossing.x_root, e->xcrossing.y_root );
00609 leaveNotifyEvent( &e->xcrossing );
00610 break;
00611 case FocusIn:
00612 focusInEvent( &e->xfocus );
00613 break;
00614 case FocusOut:
00615 focusOutEvent( &e->xfocus );
00616 break;
00617 case ReparentNotify:
00618 break;
00619 case ClientMessage:
00620 clientMessageEvent( &e->xclient );
00621 break;
00622 case ColormapChangeMask:
00623 if( e->xany.window == window())
00624 {
00625 cmap = e->xcolormap.colormap;
00626 if ( isActive() )
00627 workspace()->updateColormap();
00628 }
00629 break;
00630 default:
00631 if( e->xany.window == window())
00632 {
00633 if( e->type == Shape::shapeEvent() )
00634 {
00635 is_shape = Shape::hasShape( window());
00636 updateShape();
00637 }
00638 }
00639 break;
00640 }
00641 return true;
00642 }
00643
00647 bool Client::mapRequestEvent( XMapRequestEvent* e )
00648 {
00649 if( e->window != window())
00650 {
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663 if( e->parent == wrapperId())
00664 return false;
00665 return true;
00666 }
00667 if( isTopMenu() && workspace()->managingTopMenus())
00668 return true;
00669 switch ( mappingState() )
00670 {
00671 case WithdrawnState:
00672 assert( false );
00673
00674 break;
00675 case IconicState:
00676
00677 if( isMinimized())
00678 unminimize();
00679 if( isShade())
00680 setShade( ShadeNone );
00681 if( !isOnCurrentDesktop())
00682 {
00683 if( workspace()->allowClientActivation( this ))
00684 workspace()->activateClient( this );
00685 else
00686 demandAttention();
00687 }
00688 break;
00689 case NormalState:
00690
00691 break;
00692 }
00693 return true;
00694 }
00695
00699 void Client::unmapNotifyEvent( XUnmapEvent* e )
00700 {
00701 if( e->window != window())
00702 return;
00703 if( e->event != wrapperId())
00704 {
00705 bool ignore = true;
00706 if( e->event == workspace()->rootWin() && e->send_event )
00707 ignore = false;
00708 if( ignore )
00709 return;
00710 }
00711 switch( mappingState())
00712 {
00713 case IconicState:
00714 releaseWindow();
00715 return;
00716 case NormalState:
00717
00718 XEvent ev;
00719 if( XCheckTypedWindowEvent (qt_xdisplay(), window(),
00720 DestroyNotify, &ev) )
00721 {
00722 destroyClient();
00723 return;
00724 }
00725 releaseWindow();
00726 break;
00727 default:
00728 assert( false );
00729 }
00730 }
00731
00732 void Client::destroyNotifyEvent( XDestroyWindowEvent* e )
00733 {
00734 if( e->window != window())
00735 return;
00736 destroyClient();
00737 }
00738
00739
00740 bool blockAnimation = FALSE;
00741
00745 void Client::clientMessageEvent( XClientMessageEvent* e )
00746 {
00747 if( e->window != window())
00748 return;
00749
00750 if ( e->message_type == atoms->kde_wm_change_state )
00751 {
00752 if( isTopMenu() && workspace()->managingTopMenus())
00753 return;
00754 if( e->data.l[ 1 ] )
00755 blockAnimation = true;
00756 if( e->data.l[ 0 ] == IconicState )
00757 minimize();
00758 else if( e->data.l[ 0 ] == NormalState )
00759 {
00760 if( isMinimized())
00761 unminimize();
00762 if( isShade())
00763 setShade( ShadeNone );
00764 if( !isOnCurrentDesktop())
00765 {
00766 if( workspace()->allowClientActivation( this ))
00767 workspace()->activateClient( this );
00768 else
00769 demandAttention();
00770 }
00771 }
00772 blockAnimation = false;
00773 }
00774 else if ( e->message_type == atoms->wm_change_state)
00775 {
00776 if( isTopMenu() && workspace()->managingTopMenus())
00777 return;
00778 if ( e->data.l[0] == IconicState )
00779 minimize();
00780 return;
00781 }
00782 }
00783
00784
00788 void Client::configureRequestEvent( XConfigureRequestEvent* e )
00789 {
00790 if( e->window != window())
00791 return;
00792 if ( isResize() || isMove())
00793 return;
00794
00795 if( fullscreen_mode == FullScreenNormal )
00796 {
00797 sendSyntheticConfigureNotify();
00798 return;
00799 }
00800 if( isSplash()
00801 || isTopMenu())
00802 {
00803 sendSyntheticConfigureNotify();
00804 return;
00805 }
00806
00807 if ( e->value_mask & CWBorderWidth )
00808 {
00809
00810 XWindowChanges wc;
00811 unsigned int value_mask = 0;
00812
00813 wc.border_width = 0;
00814 value_mask = CWBorderWidth;
00815 XConfigureWindow( qt_xdisplay(), window(), value_mask, & wc );
00816 }
00817
00818 if( e->value_mask & ( CWX | CWY | CWHeight | CWWidth ))
00819 configureRequest( e->value_mask, e->x, e->y, e->width, e->height, 0, false );
00820
00821 if ( e->value_mask & CWStackMode )
00822 restackWindow( e->above, e->detail, NET::FromApplication, userTime(), false );
00823
00824
00825
00826
00827
00828
00829 sendSyntheticConfigureNotify();
00830
00831
00832
00833 }
00834
00835
00839 void Client::propertyNotifyEvent( XPropertyEvent* e )
00840 {
00841 if( e->window != window())
00842 return;
00843 switch ( e->atom )
00844 {
00845 case XA_WM_NORMAL_HINTS:
00846 getWmNormalHints();
00847 break;
00848 case XA_WM_NAME:
00849 fetchName();
00850 break;
00851 case XA_WM_ICON_NAME:
00852 fetchIconicName();
00853 break;
00854 case XA_WM_TRANSIENT_FOR:
00855 readTransient();
00856 break;
00857 case XA_WM_HINTS:
00858 getWMHints();
00859 getIcons();
00860 break;
00861 default:
00862 if ( e->atom == atoms->wm_protocols )
00863 getWindowProtocols();
00864 else if (e->atom == atoms->wm_client_leader )
00865 getWmClientLeader();
00866 else if( e->atom == qt_window_role )
00867 window_role = staticWindowRole( window());
00868 else if( e->atom == atoms->motif_wm_hints )
00869 getMotifHints();
00870 break;
00871 }
00872 }
00873
00874
00875 void Client::enterNotifyEvent( XCrossingEvent* e )
00876 {
00877 if( e->window != frameId())
00878 return;
00879 if( e->mode == NotifyNormal ||
00880 ( !options->focusPolicyIsReasonable() &&
00881 e->mode == NotifyUngrab ) )
00882 {
00883
00884 if (options->shadeHover && isShade())
00885 {
00886 delete shadeHoverTimer;
00887 shadeHoverTimer = new QTimer( this );
00888 connect( shadeHoverTimer, SIGNAL( timeout() ), this, SLOT( shadeHover() ));
00889 shadeHoverTimer->start( options->shadeHoverInterval, TRUE );
00890 }
00891
00892 if ( options->focusPolicy == Options::ClickToFocus )
00893 return;
00894
00895 if ( options->autoRaise && !isDesktop() &&
00896 !isDock() && !isTopMenu() && workspace()->focusChangeEnabled() &&
00897 workspace()->topClientOnDesktop( workspace()->currentDesktop()) != this )
00898 {
00899 delete autoRaiseTimer;
00900 autoRaiseTimer = new QTimer( this );
00901 connect( autoRaiseTimer, SIGNAL( timeout() ), this, SLOT( autoRaise() ) );
00902 autoRaiseTimer->start( options->autoRaiseInterval, TRUE );
00903 }
00904
00905 if ( options->focusPolicy != Options::FocusStrictlyUnderMouse && ( isDesktop() || isDock() || isTopMenu() ) )
00906 return;
00907 if ( options->delayFocus )
00908 workspace()->requestDelayFocus( this );
00909 else
00910 workspace()->requestFocus( this );
00911
00912 return;
00913 }
00914 }
00915
00916 void Client::leaveNotifyEvent( XCrossingEvent* e )
00917 {
00918 if( e->window != frameId())
00919 return;
00920 if ( e->mode == NotifyNormal )
00921 {
00922 if ( !buttonDown )
00923 {
00924 mode = PositionCenter;
00925 setCursor( arrowCursor );
00926 }
00927 bool lostMouse = !rect().contains( QPoint( e->x, e->y ) );
00928
00929
00930
00931
00932
00933
00934
00935 if ( !lostMouse && e->detail != NotifyInferior )
00936 {
00937 int d1, d2, d3, d4;
00938 unsigned int d5;
00939 Window w, child;
00940 if( XQueryPointer( qt_xdisplay(), frameId(), &w, &child, &d1, &d2, &d3, &d4, &d5 ) == False
00941 || child == None )
00942 lostMouse = true;
00943 }
00944 if ( lostMouse )
00945 {
00946 cancelAutoRaise();
00947 workspace()->cancelDelayFocus();
00948 cancelShadeHover();
00949 if ( shade_mode == ShadeHover && !moveResizeMode && !buttonDown )
00950 setShade( ShadeNormal );
00951 }
00952 if ( options->focusPolicy == Options::FocusStrictlyUnderMouse )
00953 if ( isActive() && lostMouse )
00954 workspace()->requestFocus( 0 ) ;
00955 return;
00956 }
00957 }
00958
00959 #define XCapL KKeyNative::modXLock()
00960 #define XNumL KKeyNative::modXNumLock()
00961 #define XScrL KKeyNative::modXScrollLock()
00962 void Client::grabButton( int modifier )
00963 {
00964 unsigned int mods[ 8 ] =
00965 {
00966 0, XCapL, XNumL, XNumL | XCapL,
00967 XScrL, XScrL | XCapL,
00968 XScrL | XNumL, XScrL | XNumL | XCapL
00969 };
00970 for( int i = 0;
00971 i < 8;
00972 ++i )
00973 XGrabButton( qt_xdisplay(), AnyButton,
00974 modifier | mods[ i ],
00975 wrapperId(), FALSE, ButtonPressMask,
00976 GrabModeSync, GrabModeAsync, None, None );
00977 }
00978
00979 void Client::ungrabButton( int modifier )
00980 {
00981 unsigned int mods[ 8 ] =
00982 {
00983 0, XCapL, XNumL, XNumL | XCapL,
00984 XScrL, XScrL | XCapL,
00985 XScrL | XNumL, XScrL | XNumL | XCapL
00986 };
00987 for( int i = 0;
00988 i < 8;
00989 ++i )
00990 XUngrabButton( qt_xdisplay(), AnyButton,
00991 modifier | mods[ i ], wrapperId());
00992 }
00993 #undef XCapL
00994 #undef XNumL
00995 #undef XScrL
00996
00997
00998
00999
01000
01001
01002
01003 void Client::updateMouseGrab()
01004 {
01005 if( isActive() && !workspace()->forcedGlobalMouseGrab())
01006 {
01007
01008
01009
01010
01011 bool not_obscured = workspace()->topClientOnDesktop( workspace()->currentDesktop(), true, false ) == this;
01012 if( !options->clickRaise || not_obscured )
01013 ungrabButton( None );
01014 else
01015 grabButton( None );
01016 ungrabButton( ShiftMask );
01017 ungrabButton( ControlMask );
01018 ungrabButton( ControlMask | ShiftMask );
01019 }
01020 else
01021 {
01022 XUngrabButton( qt_xdisplay(), AnyButton, AnyModifier, wrapperId());
01023
01024 XGrabButton(qt_xdisplay(), AnyButton, AnyModifier, wrapperId(), FALSE,
01025 ButtonPressMask,
01026 GrabModeSync, GrabModeAsync,
01027 None, None );
01028 }
01029 }
01030
01031 int qtToX11Button( Qt::ButtonState button )
01032 {
01033 if( button == Qt::LeftButton )
01034 return Button1;
01035 else if( button == Qt::MidButton )
01036 return Button2;
01037 else if( button == Qt::RightButton )
01038 return Button3;
01039 return AnyButton;
01040 }
01041
01042 int qtToX11State( Qt::ButtonState state )
01043 {
01044 int ret = 0;
01045 if( state & Qt::LeftButton )
01046 ret |= Button1Mask;
01047 if( state & Qt::MidButton )
01048 ret |= Button2Mask;
01049 if( state & Qt::RightButton )
01050 ret |= Button3Mask;
01051 if( state & Qt::ShiftButton )
01052 ret |= ShiftMask;
01053 if( state & Qt::ControlButton )
01054 ret |= ControlMask;
01055 if( state & Qt::AltButton )
01056 ret |= KKeyNative::modX(KKey::ALT);
01057 if( state & Qt::MetaButton )
01058 ret |= KKeyNative::modX(KKey::WIN);
01059 return ret;
01060 }
01061
01062
01063
01064 bool Client::eventFilter( QObject* o, QEvent* e )
01065 {
01066 if( decoration == NULL
01067 || o != decoration->widget())
01068 return false;
01069 if( e->type() == QEvent::MouseButtonPress )
01070 {
01071 QMouseEvent* ev = static_cast< QMouseEvent* >( e );
01072 return buttonPressEvent( decorationId(), qtToX11Button( ev->button()), qtToX11State( ev->state()),
01073 ev->x(), ev->y(), ev->globalX(), ev->globalY() );
01074 }
01075 if( e->type() == QEvent::MouseButtonRelease )
01076 {
01077 QMouseEvent* ev = static_cast< QMouseEvent* >( e );
01078 return buttonReleaseEvent( decorationId(), qtToX11Button( ev->button()), qtToX11State( ev->state()),
01079 ev->x(), ev->y(), ev->globalX(), ev->globalY() );
01080 }
01081 if( e->type() == QEvent::MouseMove )
01082 {
01083 QMouseEvent* ev = static_cast< QMouseEvent* >( e );
01084 return motionNotifyEvent( decorationId(), qtToX11State( ev->state()),
01085 ev->x(), ev->y(), ev->globalX(), ev->globalY() );
01086 }
01087 if( e->type() == QEvent::Wheel )
01088 {
01089 QWheelEvent* ev = static_cast< QWheelEvent* >( e );
01090 bool r = buttonPressEvent( decorationId(), ev->delta() > 0 ? Button4 : Button5, qtToX11State( ev->state()),
01091 ev->x(), ev->y(), ev->globalX(), ev->globalY() );
01092 r = r || buttonReleaseEvent( decorationId(), ev->delta() > 0 ? Button4 : Button5, qtToX11State( ev->state()),
01093 ev->x(), ev->y(), ev->globalX(), ev->globalY() );
01094 return r;
01095 }
01096 if( e->type() == QEvent::Resize )
01097 {
01098 QResizeEvent* ev = static_cast< QResizeEvent* >( e );
01099
01100
01101
01102
01103 if( ev->size() != size())
01104 return true;
01105 }
01106 return false;
01107 }
01108
01109
01110 bool Client::buttonPressEvent( Window w, int button, int state, int x, int y, int x_root, int y_root )
01111 {
01112 if (buttonDown)
01113 {
01114 if( w == wrapperId())
01115 XAllowEvents(qt_xdisplay(), SyncPointer, CurrentTime );
01116 return true;
01117 }
01118
01119 if( w == wrapperId() || w == frameId() || w == decorationId())
01120 {
01121 updateUserTime();
01122 workspace()->setWasUserInteraction();
01123 uint keyModX = (options->keyCmdAllModKey() == Qt::Key_Meta) ?
01124 KKeyNative::modX(KKey::WIN) :
01125 KKeyNative::modX(KKey::ALT);
01126 bool bModKeyHeld = keyModX != 0 && ( state & KKeyNative::accelModMaskX()) == keyModX;
01127
01128 if( isSplash()
01129 && button == Button1 && !bModKeyHeld )
01130 {
01131 hideClient( true );
01132 if( w == wrapperId())
01133 XAllowEvents(qt_xdisplay(), SyncPointer, CurrentTime );
01134 return true;
01135 }
01136
01137 Options::MouseCommand com = Options::MouseNothing;
01138 bool was_action = false;
01139 bool perform_handled = false;
01140 if ( bModKeyHeld )
01141 {
01142 was_action = true;
01143 switch (button)
01144 {
01145 case Button1:
01146 com = options->commandAll1();
01147 break;
01148 case Button2:
01149 com = options->commandAll2();
01150 break;
01151 case Button3:
01152 com = options->commandAll3();
01153 break;
01154 case Button4:
01155 case Button5:
01156 com = options->operationWindowMouseWheel( button == Button4 ? 120 : -120 );
01157 break;
01158 }
01159 }
01160 else
01161 {
01162 if( !isActive() && w == wrapperId())
01163 {
01164 was_action = true;
01165 perform_handled = true;
01166 switch (button)
01167 {
01168 case Button1:
01169 com = options->commandWindow1();
01170 break;
01171 case Button2:
01172 com = options->commandWindow2();
01173 break;
01174 case Button3:
01175 com = options->commandWindow3();
01176 break;
01177 default:
01178 com = Options::MouseActivateAndPassClick;
01179 }
01180 }
01181
01182 if( isActive() && w == wrapperId()
01183 && options->clickRaise && button < 4 )
01184 {
01185 com = Options::MouseActivateRaiseAndPassClick;
01186 was_action = true;
01187 perform_handled = true;
01188 }
01189 }
01190 if( was_action )
01191 {
01192 bool replay = performMouseCommand( com, QPoint( x_root, y_root), perform_handled );
01193
01194 if ( isSpecialWindow())
01195 replay = TRUE;
01196
01197 if( w == wrapperId())
01198 XAllowEvents(qt_xdisplay(), replay? ReplayPointer : SyncPointer, CurrentTime );
01199 return true;
01200 }
01201 }
01202
01203 if( w == wrapperId())
01204 {
01205 XAllowEvents(qt_xdisplay(), ReplayPointer, CurrentTime );
01206 return true;
01207 }
01208 if( w == decorationId())
01209 return false;
01210 if( w == frameId())
01211 processDecorationButtonPress( button, state, x, y, x_root, y_root );
01212 return true;
01213 }
01214
01215
01216
01217
01218 void Client::processDecorationButtonPress( int button, int , int x, int y, int x_root, int y_root )
01219 {
01220 Options::MouseCommand com = Options::MouseNothing;
01221 bool active = isActive();
01222 if ( !wantsInput() )
01223 active = TRUE;
01224
01225 if ( button == Button1 )
01226 com = active ? options->commandActiveTitlebar1() : options->commandInactiveTitlebar1();
01227 else if ( button == Button2 )
01228 com = active ? options->commandActiveTitlebar2() : options->commandInactiveTitlebar2();
01229 else if ( button == Button3 )
01230 com = active ? options->commandActiveTitlebar3() : options->commandInactiveTitlebar3();
01231 if( button == Button1
01232 && com != Options::MouseOperationsMenu
01233 && com != Options::MouseMinimize )
01234 {
01235 mode = mousePosition( QPoint( x, y ));
01236 buttonDown = TRUE;
01237 moveOffset = QPoint( x, y );
01238 invertedMoveOffset = rect().bottomRight() - moveOffset;
01239 unrestrictedMoveResize = false;
01240 setCursor( mode );
01241 }
01242 performMouseCommand( com, QPoint( x_root, y_root ));
01243 }
01244
01245
01246 void Client::processMousePressEvent( QMouseEvent* e )
01247 {
01248 if( e->type() != QEvent::MouseButtonPress )
01249 {
01250 kdWarning() << "processMousePressEvent()" << endl;
01251 return;
01252 }
01253 int button;
01254 switch( e->button())
01255 {
01256 case LeftButton:
01257 button = Button1;
01258 break;
01259 case MidButton:
01260 button = Button2;
01261 break;
01262 case RightButton:
01263 button = Button3;
01264 break;
01265 default:
01266 return;
01267 }
01268 processDecorationButtonPress( button, e->state(), e->x(), e->y(), e->globalX(), e->globalY());
01269 }
01270
01271
01272 bool Client::buttonReleaseEvent( Window w, int , int state, int x, int y, int x_root, int y_root )
01273 {
01274 if( w == decorationId() && !buttonDown)
01275 return false;
01276 if( w == wrapperId())
01277 {
01278 XAllowEvents(qt_xdisplay(), SyncPointer, CurrentTime );
01279 return true;
01280 }
01281 if( w != frameId() && w != decorationId() && w != moveResizeGrabWindow())
01282 return true;
01283 x = this->x();
01284 y = this->y();
01285 if ( (state & ( Button1Mask & Button2Mask & Button3Mask )) == 0 )
01286 {
01287 buttonDown = FALSE;
01288 if ( moveResizeMode )
01289 {
01290 finishMoveResize( false );
01291
01292 QPoint mousepos( x_root - x, y_root - y );
01293 mode = mousePosition( mousepos );
01294 }
01295 setCursor( mode );
01296 }
01297 return true;
01298 }
01299
01300 static bool was_motion = false;
01301 static Time next_motion_time = CurrentTime;
01302
01303
01304
01305
01306
01307
01308
01309 static Bool motion_predicate( Display*, XEvent* ev, XPointer )
01310 {
01311 if( ev->type == MotionNotify )
01312 {
01313 was_motion = true;
01314 next_motion_time = ev->xmotion.time;
01315 }
01316 return False;
01317 }
01318
01319 static bool waitingMotionEvent()
01320 {
01321
01322
01323
01324 if( next_motion_time != CurrentTime
01325 && timestampCompare( qt_x_time, next_motion_time ) < 0 )
01326 return true;
01327 was_motion = false;
01328 XSync( qt_xdisplay(), False );
01329 XEvent dummy;
01330 XCheckIfEvent( qt_xdisplay(), &dummy, motion_predicate, NULL );
01331 return was_motion;
01332 }
01333
01334
01335 bool Client::motionNotifyEvent( Window w, int , int x, int y, int x_root, int y_root )
01336 {
01337 if( w != frameId() && w != decorationId() && w != moveResizeGrabWindow())
01338 return true;
01339 if ( !buttonDown )
01340 {
01341 Position newmode = mousePosition( QPoint( x, y ));
01342 if( newmode != mode )
01343 setCursor( newmode );
01344 mode = newmode;
01345
01346
01347 next_motion_time = CurrentTime;
01348 return false;
01349 }
01350 if( w == moveResizeGrabWindow())
01351 {
01352 x = this->x();
01353 y = this->y();
01354 }
01355 if( !waitingMotionEvent())
01356 handleMoveResize( x, y, x_root, y_root );
01357 return true;
01358 }
01359
01360 void Client::focusInEvent( XFocusInEvent* e )
01361 {
01362 if( e->window != window())
01363 return;
01364 if ( e->mode == NotifyUngrab )
01365 return;
01366 if ( e->detail == NotifyPointer )
01367 return;
01368 if( !isShown( false ) || !isOnCurrentDesktop())
01369 return;
01370
01371 bool activate = workspace()->allowClientActivation( this, -1U, true );
01372 workspace()->gotFocusIn( this );
01373 if( activate )
01374 setActive( TRUE );
01375 else
01376 {
01377 workspace()->restoreFocus();
01378 demandAttention();
01379 }
01380 }
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396 static bool follows_focusin = false;
01397 static bool follows_focusin_failed = false;
01398 static Bool predicate_follows_focusin( Display*, XEvent* e, XPointer arg )
01399 {
01400 if( follows_focusin || follows_focusin_failed )
01401 return False;
01402 Client* c = ( Client* ) arg;
01403 if( e->type == FocusIn && c->workspace()->findClient( WindowMatchPredicate( e->xfocus.window )))
01404 {
01405 follows_focusin = true;
01406 return False;
01407 }
01408
01409
01410 if( e->type == FocusIn || e->type == FocusOut || e->type == KeymapNotify )
01411 return False;
01412 follows_focusin_failed = true;
01413 return False;
01414 }
01415
01416 static bool check_follows_focusin( Client* c )
01417 {
01418 follows_focusin = follows_focusin_failed = false;
01419 XEvent dummy;
01420
01421
01422
01423 XCheckIfEvent( qt_xdisplay(), &dummy, predicate_follows_focusin, (XPointer)c );
01424 return follows_focusin;
01425 }
01426
01427
01428 void Client::focusOutEvent( XFocusOutEvent* e )
01429 {
01430 if( e->window != window())
01431 return;
01432 if ( e->mode == NotifyGrab )
01433 return;
01434 if ( isShade() )
01435 return;
01436 if ( e->detail != NotifyNonlinear
01437 && e->detail != NotifyNonlinearVirtual )
01438
01439 return;
01440 if ( QApplication::activePopupWidget() )
01441 return;
01442 if( !check_follows_focusin( this ))
01443 setActive( FALSE );
01444 }
01445
01446
01447 void Client::NETMoveResize( int x_root, int y_root, NET::Direction direction )
01448 {
01449 if( direction == NET::Move )
01450 performMouseCommand( Options::MouseMove, QPoint( x_root, y_root ));
01451 else if( moveResizeMode && direction == NET::MoveResizeCancel )
01452 {
01453 finishMoveResize( true );
01454 buttonDown = FALSE;
01455 setCursor( mode );
01456 }
01457 else if( direction >= NET::TopLeft && direction <= NET::Left )
01458 {
01459 static const Position convert[] =
01460 {
01461 PositionTopLeft,
01462 PositionTop,
01463 PositionTopRight,
01464 PositionRight,
01465 PositionBottomRight,
01466 PositionBottom,
01467 PositionBottomLeft,
01468 PositionLeft
01469 };
01470 if(!isResizable() || isShade())
01471 return;
01472 if( moveResizeMode )
01473 finishMoveResize( false );
01474 buttonDown = TRUE;
01475 moveOffset = QPoint( x_root - x(), y_root - y());
01476 invertedMoveOffset = rect().bottomRight() - moveOffset;
01477 unrestrictedMoveResize = false;
01478 mode = convert[ direction ];
01479 setCursor( mode );
01480 if( !startMoveResize())
01481 {
01482 buttonDown = false;
01483 setCursor( mode );
01484 }
01485 }
01486 else if( direction == NET::KeyboardMove )
01487 {
01488 QCursor::setPos( geometry().center() );
01489 performMouseCommand( Options::MouseUnrestrictedMove, geometry().center());
01490 }
01491 else if( direction == NET::KeyboardSize )
01492 {
01493 QCursor::setPos( geometry().bottomRight());
01494 performMouseCommand( Options::MouseUnrestrictedResize, geometry().bottomRight());
01495 }
01496 }
01497
01498 void Client::keyPressEvent( uint key_code )
01499 {
01500 updateUserTime();
01501 if ( !isMove() && !isResize() )
01502 return;
01503 bool is_control = key_code & Qt::CTRL;
01504 bool is_alt = key_code & Qt::ALT;
01505 key_code = key_code & 0xffff;
01506 int delta = is_control?1:is_alt?32:8;
01507 QPoint pos = QCursor::pos();
01508 switch ( key_code )
01509 {
01510 case Key_Left:
01511 pos.rx() -= delta;
01512 break;
01513 case Key_Right:
01514 pos.rx() += delta;
01515 break;
01516 case Key_Up:
01517 pos.ry() -= delta;
01518 break;
01519 case Key_Down:
01520 pos.ry() += delta;
01521 break;
01522 case Key_Space:
01523 case Key_Return:
01524 case Key_Enter:
01525 finishMoveResize( false );
01526 buttonDown = FALSE;
01527 setCursor( mode );
01528 break;
01529 case Key_Escape:
01530 finishMoveResize( true );
01531 buttonDown = FALSE;
01532 setCursor( mode );
01533 break;
01534 default:
01535 return;
01536 }
01537 QCursor::setPos( pos );
01538 }
01539
01540
01541
01542
01543
01544 bool Group::groupEvent( XEvent* e )
01545 {
01546 unsigned long dirty[ 2 ];
01547 leader_info->event( e, dirty, 2 );
01548 if ( ( dirty[ WinInfo::PROTOCOLS ] & NET::WMIcon) != 0 )
01549 getIcons();
01550 if(( dirty[ WinInfo::PROTOCOLS2 ] & NET::WM2StartupId ) != 0 )
01551 startupIdChanged();
01552 return false;
01553 }
01554
01555
01556 }