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
25 #include "killwindow.h"
28 #include <X11/keysym.h>
29 #include <X11/keysymdef.h>
30 #include <X11/cursorfont.h>
36 KillWindow::KillWindow( Workspace
* ws
)
41 KillWindow::~KillWindow()
45 void KillWindow::start()
47 static Cursor kill_cursor
= 0;
49 kill_cursor
= XCreateFontCursor(display(), XC_pirate
);
51 if (XGrabPointer(display(), rootWindow(), False
,
52 ButtonPressMask
| ButtonReleaseMask
|
54 EnterWindowMask
| LeaveWindowMask
,
55 GrabModeAsync
, GrabModeAsync
, None
,
56 kill_cursor
, CurrentTime
) == GrabSuccess
)
61 int return_pressed
= 0;
62 int escape_pressed
= 0;
63 int button_released
= 0;
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);
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
)
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;
99 if( ev
.xbutton
.button
== Button1
|| ev
.xbutton
.button
== Button2
)
100 workspace
->killWindowId(ev
.xbutton
.subwindow
);
107 int dummy1
, dummy2
, dummy3
, dummy4
;
109 if( XQueryPointer( display(), rootWindow(), &root
, &child
,
110 &dummy1
, &dummy2
, &dummy3
, &dummy4
, &dummy5
) == true
112 workspace
->killWindowId( child
);
117 XUngrabPointer(display(), CurrentTime
);