add more spacing
[personal-kdebase.git] / workspace / kwin / killwindow.cpp
blobcca6f85991d2fe8f842206576162dc0aa61d602f
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
6 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *********************************************************************/
22 //#ifndef QT_CLEAN_NAMESPACE
23 //#define QT_CLEAN_NAMESPACE
24 //#endif
25 #include "killwindow.h"
26 #include <QCursor>
27 #include <X11/Xlib.h>
28 #include <X11/keysym.h>
29 #include <X11/keysymdef.h>
30 #include <X11/cursorfont.h>
31 #include <QX11Info>
33 namespace KWin
36 KillWindow::KillWindow( Workspace* ws )
37 : workspace( ws )
41 KillWindow::~KillWindow()
45 void KillWindow::start()
47 static Cursor kill_cursor = 0;
48 if (!kill_cursor)
49 kill_cursor = XCreateFontCursor(display(), XC_pirate);
51 if (XGrabPointer(display(), rootWindow(), False,
52 ButtonPressMask | ButtonReleaseMask |
53 PointerMotionMask |
54 EnterWindowMask | LeaveWindowMask,
55 GrabModeAsync, GrabModeAsync, None,
56 kill_cursor, CurrentTime) == GrabSuccess)
58 grabXKeyboard();
60 XEvent ev;
61 int return_pressed = 0;
62 int escape_pressed = 0;
63 int button_released = 0;
65 grabXServer();
67 while (!return_pressed && !escape_pressed && !button_released)
69 XMaskEvent(display(), KeyPressMask | ButtonPressMask |
70 ButtonReleaseMask | PointerMotionMask, &ev);
72 if (ev.type == KeyPress)
74 int kc = XKeycodeToKeysym(display(), ev.xkey.keycode, 0);
75 int mx = 0;
76 int my = 0;
77 return_pressed = (kc == XK_Return) || (kc == XK_space);
78 escape_pressed = (kc == XK_Escape);
79 if (kc == XK_Left) mx = -10;
80 if (kc == XK_Right) mx = 10;
81 if (kc == XK_Up) my = -10;
82 if (kc == XK_Down) my = 10;
83 if (ev.xkey.state & ControlMask)
85 mx /= 10;
86 my /= 10;
88 QCursor::setPos(cursorPos()+QPoint(mx, my));
91 if (ev.type == ButtonRelease)
93 button_released = (ev.xbutton.button == Button1);
94 if ( ev.xbutton.button == Button3 )
96 escape_pressed = true;
97 break;
99 if( ev.xbutton.button == Button1 || ev.xbutton.button == Button2 )
100 workspace->killWindowId(ev.xbutton.subwindow);
102 continue;
104 if (return_pressed)
106 Window root, child;
107 int dummy1, dummy2, dummy3, dummy4;
108 unsigned int dummy5;
109 if( XQueryPointer( display(), rootWindow(), &root, &child,
110 &dummy1, &dummy2, &dummy3, &dummy4, &dummy5 ) == true
111 && child != None )
112 workspace->killWindowId( child );
115 ungrabXServer();
116 ungrabXKeyboard();
117 XUngrabPointer(display(), CurrentTime);
121 } // namespace