• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KWin

killwindow.cpp

Go to the documentation of this file.
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 This program is free software; you can redistribute it and/or modify
00009 it under the terms of the GNU General Public License as published by
00010 the Free Software Foundation; either version 2 of the License, or
00011 (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 *********************************************************************/
00021 
00022 //#ifndef QT_CLEAN_NAMESPACE
00023 //#define QT_CLEAN_NAMESPACE
00024 //#endif
00025 #include "killwindow.h"
00026 #include <QCursor>
00027 #include <X11/Xlib.h>
00028 #include <X11/keysym.h>
00029 #include <X11/keysymdef.h>
00030 #include <X11/cursorfont.h>
00031 #include <QX11Info>
00032 
00033 namespace KWin
00034 {
00035 
00036 KillWindow::KillWindow( Workspace* ws )
00037     : workspace( ws )
00038     {
00039     }
00040 
00041 KillWindow::~KillWindow()
00042     {
00043     }
00044 
00045 void KillWindow::start() 
00046     {
00047     static Cursor kill_cursor = 0;
00048     if (!kill_cursor)
00049         kill_cursor = XCreateFontCursor(display(), XC_pirate);
00050 
00051     if (XGrabPointer(display(), rootWindow(), False,
00052                      ButtonPressMask | ButtonReleaseMask |
00053                      PointerMotionMask |
00054                      EnterWindowMask | LeaveWindowMask,
00055                      GrabModeAsync, GrabModeAsync, None,
00056                      kill_cursor, CurrentTime) == GrabSuccess) 
00057         {
00058         grabXKeyboard();
00059 
00060         XEvent ev;
00061         int return_pressed  = 0;
00062         int escape_pressed  = 0;
00063         int button_released = 0;
00064 
00065         grabXServer();
00066 
00067         while (!return_pressed && !escape_pressed && !button_released) 
00068             {
00069             XMaskEvent(display(), KeyPressMask | ButtonPressMask |
00070                        ButtonReleaseMask | PointerMotionMask, &ev);
00071 
00072             if (ev.type == KeyPress)    
00073                 {
00074                 int kc = XKeycodeToKeysym(display(), ev.xkey.keycode, 0);
00075                 int mx = 0;
00076                 int my = 0;
00077                 return_pressed = (kc == XK_Return) || (kc == XK_space);
00078                 escape_pressed = (kc == XK_Escape);
00079                 if (kc == XK_Left)  mx = -10;
00080                 if (kc == XK_Right) mx = 10;
00081                 if (kc == XK_Up)    my = -10;
00082                 if (kc == XK_Down)  my = 10;
00083                 if (ev.xkey.state & ControlMask) 
00084                     {
00085                     mx /= 10;
00086                     my /= 10;
00087                     }
00088                 QCursor::setPos(cursorPos()+QPoint(mx, my));
00089                 }
00090 
00091             if (ev.type == ButtonRelease) 
00092                 {
00093                 button_released = (ev.xbutton.button == Button1);
00094                 if ( ev.xbutton.button == Button3 ) 
00095                     {
00096                     escape_pressed = true;
00097                     break;
00098                     }
00099                 if( ev.xbutton.button == Button1 || ev.xbutton.button == Button2 )
00100                     workspace->killWindowId(ev.xbutton.subwindow);
00101                 }
00102             continue;
00103             }
00104         if (return_pressed) 
00105             {
00106             Window root, child;
00107             int dummy1, dummy2, dummy3, dummy4;
00108             unsigned int dummy5;
00109             if( XQueryPointer( display(), rootWindow(), &root, &child,
00110                 &dummy1, &dummy2, &dummy3, &dummy4, &dummy5 ) == true
00111                 && child != None )
00112                 workspace->killWindowId( child );
00113             }
00114 
00115         ungrabXServer();
00116         ungrabXKeyboard();
00117         XUngrabPointer(display(), CurrentTime);
00118         }
00119     }
00120 
00121 } // namespace

KWin

Skip menu "KWin"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal