19 #include "workspace.h"
25 #include <tqwhatsthis.h>
26 #include <kkeynative.h>
27 #include <tqapplication.h>
29 #include <X11/extensions/shape.h>
30 #include <X11/Xatom.h>
33 extern Atom tqt_window_role;
35 namespace KWinInternal
42 WinInfo::WinInfo( Client * c, Display * display, Window window,
43 Window rwin,
const unsigned long pr[],
int pr_size )
44 : NETWinInfo( display, window, rwin, pr, pr_size, NET::WindowManager ), m_client( c )
48 void WinInfo::changeDesktop(
int desktop)
50 m_client->workspace()->sendClientToDesktop( m_client, desktop,
true );
53 void WinInfo::changeState(
unsigned long state,
unsigned long mask )
59 if(( mask & NET::FullScreen ) != 0 && ( state & NET::FullScreen ) == 0 )
60 m_client->setFullScreen(
false,
false );
61 if ( (mask & NET::Max) == NET::Max )
62 m_client->setMaximize( state & NET::MaxVert, state & NET::MaxHoriz );
63 else if ( mask & NET::MaxVert )
64 m_client->setMaximize( state & NET::MaxVert, m_client->maximizeMode() & Client::MaximizeHorizontal );
65 else if ( mask & NET::MaxHoriz )
66 m_client->setMaximize( m_client->maximizeMode() & Client::MaximizeVertical, state & NET::MaxHoriz );
68 if ( mask & NET::Shaded )
69 m_client->setShade( state & NET::Shaded ? ShadeNormal : ShadeNone );
70 if ( mask & NET::KeepAbove)
71 m_client->setKeepAbove( (state & NET::KeepAbove) != 0 );
72 if ( mask & NET::KeepBelow)
73 m_client->setKeepBelow( (state & NET::KeepBelow) != 0 );
74 if( mask & NET::SkipTaskbar )
75 m_client->setSkipTaskbar( ( state & NET::SkipTaskbar ) != 0,
true );
76 if( mask & NET::SkipPager )
77 m_client->setSkipPager( ( state & NET::SkipPager ) != 0 );
78 if( mask & NET::DemandsAttention )
79 m_client->demandAttention(( state & NET::DemandsAttention ) != 0 );
80 if( mask & NET::Modal )
81 m_client->setModal( ( state & NET::Modal ) != 0 );
83 if(( mask & NET::FullScreen ) != 0 && ( state & NET::FullScreen ) != 0 )
84 m_client->setFullScreen(
true,
false );
92 RootInfo::RootInfo( Workspace* ws, Display *dpy, Window w,
const char *name,
unsigned long pr[],
int pr_num,
int scr )
93 : NETRootInfo4( dpy, w, name, pr, pr_num, scr )
98 void RootInfo::changeNumberOfDesktops(
int n)
100 workspace->setNumberOfDesktops( n );
103 void RootInfo::changeCurrentDesktop(
int d)
105 workspace->setCurrentDesktop( d );
108 void RootInfo::changeActiveWindow( Window w, NET::RequestSource src, Time timestamp, Window active_window )
110 if( Client* c = workspace->findClient( WindowMatchPredicate( w )))
112 if( timestamp == CurrentTime )
113 timestamp = c->userTime();
114 if( src != NET::FromApplication && src != FromTool )
116 if( src == NET::FromTool )
117 workspace->activateClient( c,
true );
121 if( workspace->allowClientActivation( c, timestamp ))
122 workspace->activateClient( c );
124 else if( active_window != None
125 && ( c2 = workspace->findClient( WindowMatchPredicate( active_window ))) != NULL
126 && workspace->allowClientActivation( c2,
127 timestampCompare( timestamp, c2->userTime() > 0 ? timestamp : c2->userTime())))
128 workspace->activateClient( c );
130 c->demandAttention();
135 void RootInfo::restackWindow( Window w, RequestSource src, Window above,
int detail, Time timestamp )
137 if( Client* c = workspace->findClient( WindowMatchPredicate( w )))
139 if( timestamp == CurrentTime )
140 timestamp = c->userTime();
141 if( src != NET::FromApplication && src != FromTool )
143 c->restackWindow( above, detail, src, timestamp,
true );
147 void RootInfo::gotTakeActivity( Window w, Time timestamp,
long flags )
149 if( Client* c = workspace->findClient( WindowMatchPredicate( w )))
150 workspace->handleTakeActivity( c, timestamp, flags );
153 void RootInfo::closeWindow(Window w)
155 Client* c = workspace->findClient( WindowMatchPredicate( w ));
160 void RootInfo::moveResize(Window w,
int x_root,
int y_root,
unsigned long direction)
162 Client* c = workspace->findClient( WindowMatchPredicate( w ));
166 c->NETMoveResize( x_root, y_root, (Direction)direction);
170 void RootInfo::moveResizeWindow(Window w,
int flags,
int x,
int y,
int width,
int height )
172 Client* c = workspace->findClient( WindowMatchPredicate( w ));
174 c->NETMoveResizeWindow( flags, x, y, width, height );
177 void RootInfo::gotPing( Window w, Time timestamp )
179 if( Client* c = workspace->findClient( WindowMatchPredicate( w )))
180 c->gotPing( timestamp );
183 void RootInfo::changeShowingDesktop(
bool showing )
185 workspace->setShowingDesktop( showing );
195 bool Workspace::workspaceEvent( XEvent * e )
197 if ( mouse_emulation && (e->type == ButtonPress || e->type == ButtonRelease ) )
199 mouse_emulation = FALSE;
200 XUngrabKeyboard( tqt_xdisplay(), get_tqt_x_time() );
203 if( e->type == PropertyNotify || e->type == ClientMessage )
205 unsigned long dirty[ NETRootInfo::PROPERTIES_SIZE ];
206 rootInfo->event( e, dirty, NETRootInfo::PROPERTIES_SIZE );
207 if( dirty[ NETRootInfo::PROTOCOLS ] & NET::DesktopNames )
208 saveDesktopSettings();
209 if( dirty[ NETRootInfo::PROTOCOLS2 ] & NET::WM2DesktopLayout )
210 updateDesktopLayout();
218 was_user_interaction =
true;
221 if ( tab_grab || control_grab )
223 tab_box->handleMouseEvent( e );
229 was_user_interaction =
true;
230 KKeyNative keyX( (XEvent*)e );
231 uint keyQt = keyX.keyCodeQt();
232 kdDebug(125) <<
"Workspace::keyPress( " << keyX.key().toString() <<
" )" << endl;
235 movingClient->keyPressEvent(keyQt);
238 if( tab_grab || control_grab )
240 tabBoxKeyPress( keyX );
246 was_user_interaction =
true;
247 if( tab_grab || control_grab )
249 tabBoxKeyRelease( e->xkey );
255 if( Client* c = findClient( WindowMatchPredicate( e->xany.window )))
257 if( c->windowEvent( e ))
260 else if( Client* c = findClient( WrapperIdMatchPredicate( e->xany.window )))
262 if( c->windowEvent( e ))
265 else if( Client* c = findClient( FrameIdMatchPredicate( e->xany.window )))
267 if( c->windowEvent( e ))
272 Window special = findSpecialEventWindow( e );
273 if( special != None )
274 if( Client* c = findClient( WindowMatchPredicate( special )))
276 if( c->windowEvent( e ))
280 if( movingClient != NULL && movingClient->moveResizeGrabWindow() == e->xany.window
281 && ( e->type == MotionNotify || e->type == ButtonPress || e->type == ButtonRelease ))
283 if( movingClient->windowEvent( e ))
290 if ( e->xcreatewindow.parent == root &&
291 !TQWidget::find( e->xcreatewindow.window) &&
292 !e->xcreatewindow.override_redirect )
295 Time my_qtx_time = get_tqt_x_time();
296 XChangeProperty(tqt_xdisplay(), e->xcreatewindow.window,
297 atoms->kde_net_wm_user_creation_time, XA_CARDINAL,
298 32, PropModeReplace, (
unsigned char *)&my_qtx_time, 1);
299 set_tqt_x_time(my_qtx_time);
306 if ( removeSystemTrayWin( e->xunmap.window,
true ) )
316 WId w = e->xunmap.window;
317 if ( XCheckTypedWindowEvent (tqt_xdisplay(), w,
318 ReparentNotify, &ev) )
320 if ( ev.xreparent.parent != root )
322 XReparentWindow( tqt_xdisplay(), w, root, 0, 0 );
323 addSystemTrayWin( w );
329 return ( e->xunmap.event != e->xunmap.window );
333 return ( e->xmap.event != e->xmap.window );
343 if ( removeSystemTrayWin( e->xdestroywindow.window,
false ) )
353 Client* c = findClient( WindowMatchPredicate( e->xmaprequest.window ));
364 if ( addSystemTrayWin( e->xmaprequest.window ) )
366 c = createClient( e->xmaprequest.window,
false );
367 if ( c != NULL && root != tqt_xrootwin() )
370 XReparentWindow( tqt_xdisplay(), c->frameId(), root, 0, 0 );
373 XMapRaised( tqt_xdisplay(), e->xmaprequest.window );
379 updateFocusChains( c, FocusChainUpdate );
386 if ( TQWhatsThis::inWhatsThisMode() )
388 TQWidget* w = TQWidget::find( e->xcrossing.window );
390 TQWhatsThis::leaveWhatsThisMode();
392 if (activeBorderEvent(e))
398 if ( !TQWhatsThis::inWhatsThisMode() )
401 Client* c = findClient( FrameIdMatchPredicate( e->xcrossing.window ));
402 if ( c && e->xcrossing.detail != NotifyInferior )
403 TQWhatsThis::leaveWhatsThisMode();
406 case ConfigureRequest:
408 if ( e->xconfigurerequest.parent == root )
411 wc.border_width = e->xconfigurerequest.border_width;
412 wc.x = e->xconfigurerequest.x;
413 wc.y = e->xconfigurerequest.y;
414 wc.width = e->xconfigurerequest.width;
415 wc.height = e->xconfigurerequest.height;
417 wc.stack_mode = Above;
418 unsigned int value_mask = e->xconfigurerequest.value_mask
419 & ( CWX | CWY | CWWidth | CWHeight | CWBorderWidth );
420 XConfigureWindow( tqt_xdisplay(), e->xconfigurerequest.window, value_mask, &wc );
426 if ( mouse_emulation )
427 return keyPressMouseEmulation( e->xkey );
430 if ( mouse_emulation )
434 if( e->xfocus.window == rootWin() && TQCString( getenv(
"TDE_MULTIHEAD")).lower() !=
"true"
435 && ( e->xfocus.detail == NotifyDetailNone || e->xfocus.detail == NotifyPointerRoot ))
440 XGetInputFocus( tqt_xdisplay(), &focus, &revert );
441 if( focus == None || focus == PointerRoot )
444 Client *c = mostRecentlyActivatedClient();
446 requestFocus( c,
true );
447 else if( activateNextClient( NULL ))
457 if (activeBorderEvent(e))
469 Window Workspace::findSpecialEventWindow( XEvent* e )
474 return e->xcreatewindow.window;
476 return e->xdestroywindow.window;
478 return e->xunmap.window;
480 return e->xmap.window;
482 return e->xmaprequest.window;
484 return e->xreparent.window;
485 case ConfigureNotify:
486 return e->xconfigure.window;
488 return e->xgravity.window;
489 case ConfigureRequest:
490 return e->xconfigurerequest.window;
491 case CirculateNotify:
492 return e->xcirculate.window;
493 case CirculateRequest:
494 return e->xcirculaterequest.window;
507 bool Client::windowEvent( XEvent* e )
509 if( e->xany.window == window())
511 unsigned long dirty[ 2 ];
512 info->event( e, dirty, 2 );
514 if ( ( dirty[ WinInfo::PROTOCOLS ] & NET::WMName ) != 0 )
516 if ( ( dirty[ WinInfo::PROTOCOLS ] & NET::WMIconName ) != 0 )
518 if ( ( dirty[ WinInfo::PROTOCOLS ] & NET::WMStrut ) != 0
519 || ( dirty[ WinInfo::PROTOCOLS2 ] & NET::WM2ExtendedStrut ) != 0 )
522 checkWorkspacePosition();
523 workspace()->updateClientArea();
525 if ( ( dirty[ WinInfo::PROTOCOLS ] & NET::WMIcon) != 0 )
530 if(( dirty[ WinInfo::PROTOCOLS2 ] & NET::WM2UserTime ) != 0 )
532 workspace()->setWasUserInteraction();
533 updateUserTime( info->userTime());
535 if(( dirty[ WinInfo::PROTOCOLS2 ] & NET::WM2StartupId ) != 0 )
537 if( dirty[ WinInfo::PROTOCOLS ] & NET::WMIconGeometry )
539 if( demandAttentionKNotifyTimer != NULL )
540 demandAttentionKNotify();
548 unmapNotifyEvent( &e->xunmap );
551 destroyNotifyEvent( &e->xdestroywindow );
555 return mapRequestEvent( &e->xmaprequest );
556 case ConfigureRequest:
557 configureRequestEvent( &e->xconfigurerequest );
560 propertyNotifyEvent( &e->xproperty );
564 workspace()->setWasUserInteraction();
568 workspace()->setWasUserInteraction();
569 buttonPressEvent( e->xbutton.window, e->xbutton.button, e->xbutton.state,
570 e->xbutton.x, e->xbutton.y, e->xbutton.x_root, e->xbutton.y_root );
581 buttonReleaseEvent( e->xbutton.window, e->xbutton.button, e->xbutton.state,
582 e->xbutton.x, e->xbutton.y, e->xbutton.x_root, e->xbutton.y_root );
585 motionNotifyEvent( e->xmotion.window, e->xmotion.state,
586 e->xmotion.x, e->xmotion.y, e->xmotion.x_root, e->xmotion.y_root );
587 workspace()->updateFocusMousePosition( TQPoint( e->xmotion.x_root, e->xmotion.y_root ));
590 enterNotifyEvent( &e->xcrossing );
596 motionNotifyEvent( e->xcrossing.window, e->xcrossing.state,
597 e->xcrossing.x, e->xcrossing.y, e->xcrossing.x_root, e->xcrossing.y_root );
598 workspace()->updateFocusMousePosition( TQPoint( e->xcrossing.x_root, e->xcrossing.y_root ));
601 motionNotifyEvent( e->xcrossing.window, e->xcrossing.state,
602 e->xcrossing.x, e->xcrossing.y, e->xcrossing.x_root, e->xcrossing.y_root );
603 leaveNotifyEvent( &e->xcrossing );
608 focusInEvent( &e->xfocus );
611 focusOutEvent( &e->xfocus );
616 clientMessageEvent( &e->xclient );
618 case ColormapChangeMask:
619 if( e->xany.window == window())
621 cmap = e->xcolormap.colormap;
623 workspace()->updateColormap();
627 if( e->xany.window == window())
629 if( e->type == Shape::shapeEvent() )
631 is_shape = Shape::hasShape( window());
643 bool Client::mapRequestEvent( XMapRequestEvent* e )
645 if( e->window != window())
659 if( e->parent == wrapperId())
663 if( isTopMenu() && workspace()->managingTopMenus())
665 switch ( mappingState() )
676 setShade( ShadeNone );
677 if( !isOnCurrentDesktop())
679 if( workspace()->allowClientActivation(
this ))
680 workspace()->activateClient(
this );
695 void Client::unmapNotifyEvent( XUnmapEvent* e )
697 if( e->window != window())
699 if( e->event != wrapperId())
702 if( e->event == workspace()->rootWin() && e->send_event )
707 switch( mappingState())
715 if( XCheckTypedWindowEvent (tqt_xdisplay(), window(),
716 DestroyNotify, &ev) )
728 void Client::destroyNotifyEvent( XDestroyWindowEvent* e )
730 if( e->window != window())
736 bool blockAnimation = FALSE;
741 void Client::clientMessageEvent( XClientMessageEvent* e )
743 if( e->window != window())
746 if ( e->message_type == atoms->kde_wm_change_state )
748 if( isTopMenu() && workspace()->managingTopMenus())
751 blockAnimation =
true;
752 if( e->data.l[ 0 ] == IconicState )
754 else if( e->data.l[ 0 ] == NormalState )
759 setShade( ShadeNone );
760 if( !isOnCurrentDesktop())
762 if( workspace()->allowClientActivation(
this ))
763 workspace()->activateClient(
this );
768 blockAnimation =
false;
770 else if ( e->message_type == atoms->wm_change_state)
772 if( isTopMenu() && workspace()->managingTopMenus())
774 if ( e->data.l[0] == IconicState )
784 void Client::configureRequestEvent( XConfigureRequestEvent* e )
786 if( e->window != window())
788 if ( isResize() || isMove() || inhibitConfigureRequests)
792 sendSyntheticConfigureNotify();
796 if( fullscreen_mode == FullScreenNormal )
798 sendSyntheticConfigureNotify();
804 sendSyntheticConfigureNotify();
808 if ( e->value_mask & CWBorderWidth )
812 unsigned int value_mask = 0;
815 value_mask = CWBorderWidth;
816 XConfigureWindow( tqt_xdisplay(), window(), value_mask, & wc );
819 if( e->value_mask & ( CWX | CWY | CWHeight | CWWidth ))
820 configureRequest( e->value_mask, e->x, e->y, e->width, e->height, 0,
false );
822 if ( e->value_mask & CWStackMode )
823 restackWindow( e->above, e->detail, NET::FromApplication, userTime(),
false );
830 sendSyntheticConfigureNotify();
840 void Client::propertyNotifyEvent( XPropertyEvent* e )
842 if( e->window != window())
846 case XA_WM_NORMAL_HINTS:
852 case XA_WM_ICON_NAME:
855 case XA_WM_TRANSIENT_FOR:
863 if ( e->atom == atoms->wm_protocols )
864 getWindowProtocols();
865 else if (e->atom == atoms->wm_client_leader )
867 else if( e->atom == tqt_window_role )
868 window_role = staticWindowRole( window());
869 else if( e->atom == atoms->motif_wm_hints )
876 void Client::enterNotifyEvent( XCrossingEvent* e )
878 if( e->window != frameId())
880 if( e->mode == NotifyNormal ||
881 ( !options->focusPolicyIsReasonable() &&
882 e->mode == NotifyUngrab ) )
885 if (options->shadeHover && isShade())
887 delete shadeHoverTimer;
888 shadeHoverTimer =
new TQTimer(
this );
889 connect( shadeHoverTimer, TQ_SIGNAL( timeout() ),
this, TQ_SLOT( shadeHover() ));
890 shadeHoverTimer->start( options->shadeHoverInterval, TRUE );
893 if ( options->focusPolicy == Options::ClickToFocus )
896 if ( options->autoRaise && !isDesktop() &&
897 !isDock() && !isTopMenu() && workspace()->focusChangeEnabled() &&
898 workspace()->topClientOnDesktop( workspace()->currentDesktop()) !=
this )
900 delete autoRaiseTimer;
901 autoRaiseTimer =
new TQTimer(
this );
902 connect( autoRaiseTimer, TQ_SIGNAL( timeout() ),
this, TQ_SLOT( autoRaise() ) );
903 autoRaiseTimer->start( options->autoRaiseInterval, TRUE );
906 TQPoint currentPos( e->x_root, e->y_root );
907 if ( options->focusPolicy != Options::FocusStrictlyUnderMouse && ( isDesktop() || isDock() || isTopMenu() ) )
911 if( options->focusPolicy != Options::FocusFollowsMouse
912 || currentPos != workspace()->focusMousePosition())
914 if ( options->delayFocus )
915 workspace()->requestDelayFocus(
this );
917 workspace()->requestFocus(
this );
923 void Client::leaveNotifyEvent( XCrossingEvent* e )
925 if( e->window != frameId())
927 if ( e->mode == NotifyNormal )
931 mode = PositionCenter;
932 setCursor( TQt::arrowCursor );
934 bool lostMouse = !rect().contains( TQPoint( e->x, e->y ) );
942 if ( !lostMouse && e->detail != NotifyInferior )
947 if( XQueryPointer( tqt_xdisplay(), frameId(), &w, &child, &d1, &d2, &d3, &d4, &d5 ) == False
954 workspace()->cancelDelayFocus();
956 if ( shade_mode == ShadeHover && !moveResizeMode && !buttonDown )
957 setShade( ShadeNormal );
959 if ( options->focusPolicy == Options::FocusStrictlyUnderMouse )
960 if ( isActive() && lostMouse )
961 workspace()->requestFocus( 0 ) ;
966 #define XCapL KKeyNative::modXLock()
967 #define XNumL KKeyNative::modXNumLock()
968 #define XScrL KKeyNative::modXScrollLock()
969 void Client::grabButton(
int modifier )
971 unsigned int mods[ 8 ] =
973 0, XCapL, XNumL, XNumL | XCapL,
974 XScrL, XScrL | XCapL,
975 XScrL | XNumL, XScrL | XNumL | XCapL
980 XGrabButton( tqt_xdisplay(), AnyButton,
981 modifier | mods[ i ],
982 wrapperId(), FALSE, ButtonPressMask,
983 GrabModeSync, GrabModeAsync, None, None );
986 void Client::ungrabButton(
int modifier )
988 unsigned int mods[ 8 ] =
990 0, XCapL, XNumL, XNumL | XCapL,
991 XScrL, XScrL | XCapL,
992 XScrL | XNumL, XScrL | XNumL | XCapL
997 XUngrabButton( tqt_xdisplay(), AnyButton,
998 modifier | mods[ i ], wrapperId());
1010 void Client::updateMouseGrab()
1012 if( workspace()->globalShortcutsDisabled())
1014 XUngrabButton( tqt_xdisplay(), AnyButton, AnyModifier, wrapperId());
1016 bool not_obscured = workspace()->topClientOnDesktop( workspace()->currentDesktop(),
true,
false ) ==
this;
1017 if( !( !options->clickRaise || not_obscured ))
1021 if( isActive() && !workspace()->forcedGlobalMouseGrab())
1024 XGrabButton(tqt_xdisplay(), AnyButton, AnyModifier, wrapperId(), FALSE,
1026 GrabModeSync, GrabModeAsync,
1032 bool not_obscured = workspace()->topClientOnDesktop( workspace()->currentDesktop(),
true,
false ) ==
this;
1033 if( !options->clickRaise || not_obscured )
1034 ungrabButton( None );
1037 ungrabButton( ShiftMask );
1038 ungrabButton( ControlMask );
1039 ungrabButton( ControlMask | ShiftMask );
1043 XUngrabButton( tqt_xdisplay(), AnyButton, AnyModifier, wrapperId());
1045 XGrabButton(tqt_xdisplay(), AnyButton, AnyModifier, wrapperId(), FALSE,
1047 GrabModeSync, GrabModeAsync,
1052 int qtToX11Button( TQt::ButtonState button )
1054 if( button == TQt::LeftButton )
1056 else if( button == TQt::MidButton )
1058 else if( button == TQt::RightButton )
1063 int qtToX11State( TQt::ButtonState state )
1066 if( state & TQt::LeftButton )
1068 if( state & TQt::MidButton )
1070 if( state & TQt::RightButton )
1072 if( state & TQt::ShiftButton )
1074 if( state & TQt::ControlButton )
1076 if( state & TQt::AltButton )
1077 ret |= KKeyNative::modX(KKey::ALT);
1078 if( state & TQt::MetaButton )
1079 ret |= KKeyNative::modX(KKey::WIN);
1085 bool Client::eventFilter( TQObject* o, TQEvent* e )
1087 if (o == shadowWidget)
1089 if (e->type() == TQEvent::MouseButtonRelease)
1091 int buttonMask, buttonPressed, x, y, x_root, y_root;
1093 TQMouseEvent *qe = (TQMouseEvent *)e;
1094 Window inner_window, parent_window, pointer_window, root_window;
1098 switch (qe->button())
1100 case TQt::MidButton:
1101 buttonMask = Button2Mask;
1102 buttonPressed = Button2;
1104 case TQt::RightButton:
1105 buttonMask = Button3Mask;
1106 buttonPressed = Button3;
1109 buttonMask = Button1Mask;
1110 buttonPressed = Button1;
1116 root_window = tqt_xrootwin();
1117 XQueryPointer(tqt_xdisplay(), root_window, &root_window,
1118 &pointer_window, &x_root, &y_root, &x, &y, &mask);
1120 if (pointer_window != None)
1126 parent_window = pointer_window;
1127 XQueryPointer(tqt_xdisplay(), parent_window, &root_window,
1128 &pointer_window, &x_root, &y_root, &x, &y, &mask);
1129 inner_window = pointer_window;
1131 while (pointer_window != None)
1137 parent_window = pointer_window;
1138 XQueryPointer(tqt_xdisplay(), parent_window, &root_window,
1139 &pointer_window, &x_root, &y_root, &x, &y, &mask);
1141 pointer_window = parent_window;
1144 inner_window = None;
1147 xe.type = ButtonPress;
1148 xe.display = tqt_xdisplay();
1149 xe.root = tqt_xrootwin();
1150 xe.subwindow = None;
1151 xe.time = CurrentTime;
1157 xe.button = buttonPressed;
1158 xe.same_screen = True;
1159 if (inner_window != None && inner_window != pointer_window)
1161 xe.window = inner_window;
1162 XSendEvent(tqt_xdisplay(), inner_window, True, ButtonPressMask,
1165 xe.window = pointer_window;
1166 XSendEvent(tqt_xdisplay(), pointer_window, True, ButtonPressMask,
1170 xe.type = ButtonRelease;
1171 xe.display = tqt_xdisplay();
1172 xe.root = tqt_xrootwin();
1173 xe.subwindow = None;
1174 xe.time = CurrentTime;
1179 xe.state = buttonMask;
1180 xe.button = buttonPressed;
1181 xe.same_screen = True;
1182 if (inner_window != None && inner_window != pointer_window)
1184 xe.window = inner_window;
1185 XSendEvent(tqt_xdisplay(), inner_window, True, ButtonReleaseMask,
1188 xe.window = pointer_window;
1189 XSendEvent(tqt_xdisplay(), pointer_window, True, ButtonReleaseMask,
1192 drawDelayedShadow();
1196 else if (e->type() == TQEvent::Wheel)
1198 int x, y, x_root, y_root;
1199 unsigned int buttonMask, buttonPressed, mask;
1200 TQWheelEvent *wheelEvent = (TQWheelEvent *)e;
1201 Window inner_window, parent_window, pointer_window,
1209 buttonMask = wheelEvent->delta() > 0 ? Button4Mask : Button5Mask;
1210 buttonPressed = wheelEvent->delta() > 0 ? Button4 : Button5;
1214 root_window = tqt_xrootwin();
1215 XQueryPointer(tqt_xdisplay(), root_window, &root_window,
1216 &pointer_window, &x_root, &y_root, &x, &y, &mask);
1218 if (pointer_window != None)
1224 parent_window = pointer_window;
1225 XQueryPointer(tqt_xdisplay(), parent_window, &root_window,
1226 &pointer_window, &x_root, &y_root, &x, &y, &mask);
1227 inner_window = pointer_window;
1229 while (pointer_window != None)
1235 parent_window = pointer_window;
1236 XQueryPointer(tqt_xdisplay(), parent_window, &root_window,
1237 &pointer_window, &x_root, &y_root, &x, &y, &mask);
1239 pointer_window = parent_window;
1242 inner_window = None;
1245 xe.type = ButtonPress;
1246 xe.display = tqt_xdisplay();
1247 xe.root = tqt_xrootwin();
1248 xe.subwindow = None;
1249 xe.time = CurrentTime;
1255 xe.same_screen = True;
1256 if (inner_window != None && inner_window != pointer_window)
1258 xe.button = buttonPressed;
1259 xe.window = inner_window;
1260 XSendEvent(tqt_xdisplay(), inner_window, True, ButtonPressMask,
1263 xe.button = buttonPressed;
1264 xe.window = pointer_window;
1265 XSendEvent(tqt_xdisplay(), pointer_window, True, ButtonPressMask,
1269 xe.type = ButtonRelease;
1270 xe.display = tqt_xdisplay();
1271 xe.root = tqt_xrootwin();
1272 xe.subwindow = None;
1273 xe.time = CurrentTime;
1278 xe.same_screen = True;
1279 if (inner_window != None && inner_window != pointer_window)
1281 xe.window = inner_window;
1282 xe.state = buttonMask;
1283 xe.button = buttonPressed;
1284 XSendEvent(tqt_xdisplay(), inner_window, True, ButtonReleaseMask,
1287 xe.state = buttonMask;
1288 xe.button = buttonPressed;
1289 xe.window = pointer_window;
1290 XSendEvent(tqt_xdisplay(), pointer_window, True, ButtonReleaseMask,
1293 drawDelayedShadow();
1298 if( decoration == NULL
1299 || o != decoration->widget())
1301 if( e->type() == TQEvent::MouseButtonPress )
1303 TQMouseEvent* ev =
static_cast<TQMouseEvent*
>( e );
1304 return buttonPressEvent( decorationId(), qtToX11Button( ev->button()), qtToX11State( ev->state()),
1305 ev->x(), ev->y(), ev->globalX(), ev->globalY() );
1307 if( e->type() == TQEvent::MouseButtonRelease )
1309 TQMouseEvent* ev =
static_cast<TQMouseEvent*
>( e );
1310 return buttonReleaseEvent( decorationId(), qtToX11Button( ev->button()), qtToX11State( ev->state()),
1311 ev->x(), ev->y(), ev->globalX(), ev->globalY() );
1313 if( e->type() == TQEvent::MouseMove )
1315 TQMouseEvent* ev =
static_cast<TQMouseEvent*
>( e );
1316 return motionNotifyEvent( decorationId(), qtToX11State( ev->state()),
1317 ev->x(), ev->y(), ev->globalX(), ev->globalY() );
1319 if( e->type() == TQEvent::Wheel )
1321 TQWheelEvent* ev =
static_cast<TQWheelEvent*
>( e );
1322 bool r = buttonPressEvent( decorationId(), ev->delta() > 0 ? Button4 : Button5, qtToX11State( ev->state()),
1323 ev->x(), ev->y(), ev->globalX(), ev->globalY() );
1324 r = r || buttonReleaseEvent( decorationId(), ev->delta() > 0 ? Button4 : Button5, qtToX11State( ev->state()),
1325 ev->x(), ev->y(), ev->globalX(), ev->globalY() );
1328 if( e->type() == TQEvent::Resize )
1330 TQResizeEvent* ev =
static_cast<TQResizeEvent*
>( e );
1335 if( ev->size() != size())
1342 bool Client::buttonPressEvent( Window w,
int button,
int state,
int x,
int y,
int x_root,
int y_root )
1346 if( w == wrapperId())
1347 XAllowEvents(tqt_xdisplay(), SyncPointer, CurrentTime );
1351 if( w == wrapperId() || w == frameId() || w == decorationId())
1355 workspace()->setWasUserInteraction();
1356 uint keyModX = (options->keyCmdAllModKey() == TQt::Key_Meta) ?
1357 KKeyNative::modX(KKey::WIN) :
1358 KKeyNative::modX(KKey::ALT);
1359 bool bModKeyHeld = keyModX != 0 && ( state & KKeyNative::accelModMaskX()) == keyModX;
1362 && button == Button1 && !bModKeyHeld )
1365 if( w == wrapperId())
1366 XAllowEvents(tqt_xdisplay(), SyncPointer, CurrentTime );
1370 Options::MouseCommand com = Options::MouseNothing;
1371 bool was_action =
false;
1372 bool perform_handled =
false;
1379 com = options->commandAll1();
1382 com = options->commandAll2();
1385 com = options->commandAll3();
1389 com = options->operationWindowMouseWheel( button == Button4 ? 120 : -120 );
1395 if( !isActive() && w == wrapperId())
1398 perform_handled =
true;
1402 com = options->commandWindow1();
1405 com = options->commandWindow2();
1408 com = options->commandWindow3();
1411 com = Options::MouseActivateAndPassClick;
1415 if( isActive() && w == wrapperId()
1416 && options->clickRaise && button < 4 )
1418 com = Options::MouseActivateRaiseAndPassClick;
1420 perform_handled =
true;
1425 bool replay = performMouseCommand( com, TQPoint( x_root, y_root), perform_handled );
1427 if ( isSpecialWindow())
1430 if( w == wrapperId())
1431 XAllowEvents(tqt_xdisplay(), replay? ReplayPointer : SyncPointer, CurrentTime );
1436 if( w == wrapperId())
1438 XAllowEvents(tqt_xdisplay(), ReplayPointer, CurrentTime );
1441 if( w == decorationId())
1444 processDecorationButtonPress( button, state, x, y, x_root, y_root );
1451 void Client::processDecorationButtonPress(
int button,
int ,
int x,
int y,
int x_root,
int y_root )
1453 Options::MouseCommand com = Options::MouseNothing;
1454 bool active = isActive();
1455 if ( !wantsInput() )
1458 if ( button == Button1 )
1459 com = active ? options->commandActiveTitlebar1() : options->commandInactiveTitlebar1();
1460 else if ( button == Button2 )
1461 com = active ? options->commandActiveTitlebar2() : options->commandInactiveTitlebar2();
1462 else if ( button == Button3 )
1463 com = active ? options->commandActiveTitlebar3() : options->commandInactiveTitlebar3();
1464 if( button == Button1
1465 && com != Options::MouseOperationsMenu
1466 && com != Options::MouseMinimize )
1468 mode = mousePosition( TQPoint( x, y ));
1470 moveOffset = TQPoint( x, y );
1471 invertedMoveOffset = rect().bottomRight() - moveOffset;
1472 unrestrictedMoveResize =
false;
1475 performMouseCommand( com, TQPoint( x_root, y_root ));
1479 void Client::processMousePressEvent( TQMouseEvent* e )
1481 if( e->type() != TQEvent::MouseButtonPress )
1483 kdWarning() <<
"processMousePressEvent()" << endl;
1487 switch( e->button())
1489 case TQt::LeftButton:
1492 case TQt::MidButton:
1495 case TQt::RightButton:
1501 processDecorationButtonPress( button, e->state(), e->x(), e->y(), e->globalX(), e->globalY());
1505 bool Client::buttonReleaseEvent( Window w,
int ,
int state,
int x,
int y,
int x_root,
int y_root )
1507 if( w == decorationId() && !buttonDown)
1509 if( w == wrapperId())
1511 XAllowEvents(tqt_xdisplay(), SyncPointer, CurrentTime );
1514 if( w != frameId() && w != decorationId() && w != moveResizeGrabWindow())
1518 if ( (state & ( Button1Mask & Button2Mask & Button3Mask )) == 0 )
1521 if ( moveResizeMode )
1523 finishMoveResize(
false );
1525 TQPoint mousepos( x_root - x, y_root - y );
1526 mode = mousePosition( mousepos );
1533 static bool was_motion =
false;
1534 static Time next_motion_time = CurrentTime;
1542 static Bool motion_predicate( Display*, XEvent* ev, XPointer )
1544 if( ev->type == MotionNotify )
1547 next_motion_time = ev->xmotion.time;
1552 static bool waitingMotionEvent()
1557 if( next_motion_time != CurrentTime
1558 && timestampCompare( get_tqt_x_time(), next_motion_time ) < 0 )
1561 XSync( tqt_xdisplay(), False );
1563 XCheckIfEvent( tqt_xdisplay(), &dummy, motion_predicate, NULL );
1568 bool Client::motionNotifyEvent( Window w,
int ,
int x,
int y,
int x_root,
int y_root )
1570 if( w != frameId() && w != decorationId() && w != moveResizeGrabWindow())
1574 Position newmode = mousePosition( TQPoint( x, y ));
1575 if( newmode != mode )
1576 setCursor( newmode );
1580 next_motion_time = CurrentTime;
1583 if( w == moveResizeGrabWindow())
1588 if( !waitingMotionEvent())
1589 handleMoveResize( x, y, x_root, y_root );
1593 void Client::focusInEvent( XFocusInEvent* e )
1595 if( e->window != window())
1597 if ( e->mode == NotifyUngrab )
1599 if ( e->detail == NotifyPointer )
1601 if( !isShown(
false ) || !isOnCurrentDesktop())
1604 bool activate = workspace()->allowClientActivation(
this, -1U,
true );
1605 workspace()->gotFocusIn(
this );
1610 workspace()->restoreFocus();
1629 static bool follows_focusin =
false;
1630 static bool follows_focusin_failed =
false;
1631 static Bool predicate_follows_focusin( Display*, XEvent* e, XPointer arg )
1633 if( follows_focusin || follows_focusin_failed )
1635 Client* c = ( Client* ) arg;
1636 if( e->type == FocusIn && c->workspace()->findClient( WindowMatchPredicate( e->xfocus.window )))
1638 follows_focusin =
true;
1643 if( e->type == FocusIn || e->type == FocusOut || e->type == KeymapNotify )
1645 follows_focusin_failed =
true;
1649 static bool check_follows_focusin( Client* c )
1651 follows_focusin = follows_focusin_failed =
false;
1656 XCheckIfEvent( tqt_xdisplay(), &dummy, predicate_follows_focusin, (XPointer)c );
1657 return follows_focusin;
1661 void Client::focusOutEvent( XFocusOutEvent* e )
1663 if( e->window != window())
1665 if ( e->mode == NotifyGrab )
1669 if ( e->detail != NotifyNonlinear
1670 && e->detail != NotifyNonlinearVirtual )
1673 if ( TQApplication::activePopupWidget() )
1675 if( !check_follows_focusin(
this ))
1680 void Client::NETMoveResize(
int x_root,
int y_root, NET::Direction direction )
1682 if( direction == NET::Move )
1683 performMouseCommand( Options::MouseMove, TQPoint( x_root, y_root ));
1684 else if( moveResizeMode && direction == NET::MoveResizeCancel )
1686 finishMoveResize(
true );
1690 else if( direction >= NET::TopLeft && direction <= NET::Left )
1692 static const Position convert[] =
1698 PositionBottomRight,
1703 if(!isResizable() || isShade())
1705 if( moveResizeMode )
1706 finishMoveResize(
false );
1708 moveOffset = TQPoint( x_root - x(), y_root - y());
1709 invertedMoveOffset = rect().bottomRight() - moveOffset;
1710 unrestrictedMoveResize =
false;
1711 mode = convert[ direction ];
1713 if( !startMoveResize())
1719 else if( direction == NET::KeyboardMove )
1721 TQCursor::setPos( geometry().center() );
1722 performMouseCommand( Options::MouseUnrestrictedMove, geometry().center());
1724 else if( direction == NET::KeyboardSize )
1726 TQCursor::setPos( geometry().bottomRight());
1727 performMouseCommand( Options::MouseUnrestrictedResize, geometry().bottomRight());
1731 void Client::keyPressEvent( uint key_code )
1734 if ( !isMove() && !isResize() )
1736 bool is_control = key_code & TQt::CTRL;
1737 bool is_alt = key_code & TQt::ALT;
1738 key_code = key_code & 0xffff;
1739 int delta = is_control?1:is_alt?32:8;
1740 TQPoint pos = TQCursor::pos();
1758 finishMoveResize(
false );
1763 finishMoveResize(
true );
1770 TQCursor::setPos( pos );
1777 bool Group::groupEvent( XEvent* e )
1779 unsigned long dirty[ 2 ];
1780 leader_info->event( e, dirty, 2 );
1781 if ( ( dirty[ WinInfo::PROTOCOLS ] & NET::WMIcon) != 0 )
1783 if(( dirty[ WinInfo::PROTOCOLS2 ] & NET::WM2StartupId ) != 0 )