kwin Library API Documentation

killwindow.cpp

00001 /***************************************************************** 00002 KWin - the KDE window manager 00003 This file is part of the KDE project. 00004 00005 Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org> 00006 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org> 00007 00008 You can Freely distribute this program under the GNU General Public 00009 License. See the file "COPYING" for the exact licensing terms. 00010 ******************************************************************/ 00011 00012 //#ifndef QT_CLEAN_NAMESPACE 00013 //#define QT_CLEAN_NAMESPACE 00014 //#endif 00015 #include "killwindow.h" 00016 #include <qcursor.h> 00017 #include <X11/Xlib.h> 00018 #include <X11/keysym.h> 00019 #include <X11/keysymdef.h> 00020 #include <X11/cursorfont.h> 00021 00022 namespace KWinInternal 00023 { 00024 00025 KillWindow::KillWindow( Workspace* ws ) 00026 : workspace( ws ) 00027 { 00028 } 00029 00030 KillWindow::~KillWindow() 00031 { 00032 } 00033 00034 void KillWindow::start() 00035 { 00036 static Cursor kill_cursor = 0; 00037 if (!kill_cursor) 00038 kill_cursor = XCreateFontCursor(qt_xdisplay(), XC_pirate); 00039 00040 if (XGrabPointer(qt_xdisplay(), qt_xrootwin(), False, 00041 ButtonPressMask | ButtonReleaseMask | 00042 PointerMotionMask | 00043 EnterWindowMask | LeaveWindowMask, 00044 GrabModeAsync, GrabModeAsync, None, 00045 kill_cursor, CurrentTime) == GrabSuccess) 00046 { 00047 XGrabKeyboard(qt_xdisplay(), qt_xrootwin(), False, 00048 GrabModeAsync, GrabModeAsync, CurrentTime); 00049 00050 XEvent ev; 00051 int return_pressed = 0; 00052 int escape_pressed = 0; 00053 int button_released = 0; 00054 00055 grabXServer(); 00056 00057 while (!return_pressed && !escape_pressed && !button_released) 00058 { 00059 XMaskEvent(qt_xdisplay(), KeyPressMask | ButtonPressMask | 00060 ButtonReleaseMask | PointerMotionMask, &ev); 00061 00062 if (ev.type == KeyPress) 00063 { 00064 int kc = XKeycodeToKeysym(qt_xdisplay(), ev.xkey.keycode, 0); 00065 int mx = 0; 00066 int my = 0; 00067 return_pressed = (kc == XK_Return) || (kc == XK_space); 00068 escape_pressed = (kc == XK_Escape); 00069 if (kc == XK_Left) mx = -10; 00070 if (kc == XK_Right) mx = 10; 00071 if (kc == XK_Up) my = -10; 00072 if (kc == XK_Down) my = 10; 00073 if (ev.xkey.state & ControlMask) 00074 { 00075 mx /= 10; 00076 my /= 10; 00077 } 00078 QCursor::setPos(QCursor::pos()+QPoint(mx, my)); 00079 } 00080 00081 if (ev.type == ButtonRelease) 00082 { 00083 button_released = (ev.xbutton.button == Button1); 00084 if ( ev.xbutton.button == Button3 ) 00085 { 00086 escape_pressed = TRUE; 00087 break; 00088 } 00089 workspace->killWindowId(ev.xbutton.subwindow); 00090 } 00091 continue; 00092 } 00093 if (return_pressed) 00094 { 00095 Window root, child; 00096 int dummy1, dummy2, dummy3, dummy4; 00097 unsigned int dummy5; 00098 if( XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child, 00099 &dummy1, &dummy2, &dummy3, &dummy4, &dummy5 ) == true 00100 && child != None ) 00101 workspace->killWindowId( child ); 00102 } 00103 00104 ungrabXServer(); 00105 00106 XUngrabKeyboard(qt_xdisplay(), CurrentTime); 00107 XUngrabPointer(qt_xdisplay(), CurrentTime); 00108 } 00109 } 00110 00111 } // namespace
KDE Logo
This file is part of the documentation for kwin Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Aug 31 00:02:13 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003