2000-06-19 10:46:08 +00:00
|
|
|
/*****************************************************************
|
2003-09-16 19:28:03 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2000-06-19 10:46:08 +00:00
|
|
|
|
|
|
|
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
2003-09-16 19:28:03 +00:00
|
|
|
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
2000-06-19 10:46:08 +00:00
|
|
|
******************************************************************/
|
|
|
|
|
2000-07-29 07:59:24 +00:00
|
|
|
//#ifndef QT_CLEAN_NAMESPACE
|
|
|
|
//#define QT_CLEAN_NAMESPACE
|
|
|
|
//#endif
|
2000-06-19 10:46:08 +00:00
|
|
|
#include "killwindow.h"
|
2006-05-13 16:33:18 +00:00
|
|
|
#include <QCursor>
|
2000-06-19 10:46:08 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include <X11/keysymdef.h>
|
|
|
|
#include <X11/cursorfont.h>
|
2005-07-28 14:59:42 +00:00
|
|
|
#include <QX11Info>
|
2000-06-19 10:46:08 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
namespace KWinInternal
|
|
|
|
{
|
2001-02-20 01:20:38 +00:00
|
|
|
|
2000-06-19 10:46:08 +00:00
|
|
|
KillWindow::KillWindow( Workspace* ws )
|
2003-09-16 19:28:03 +00:00
|
|
|
: workspace( ws )
|
|
|
|
{
|
|
|
|
}
|
2000-06-19 10:46:08 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
KillWindow::~KillWindow()
|
|
|
|
{
|
|
|
|
}
|
2000-06-19 10:46:08 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
void KillWindow::start()
|
|
|
|
{
|
2000-06-19 10:46:08 +00:00
|
|
|
static Cursor kill_cursor = 0;
|
|
|
|
if (!kill_cursor)
|
2006-07-04 19:36:19 +00:00
|
|
|
kill_cursor = XCreateFontCursor(display(), XC_pirate);
|
2000-06-19 10:46:08 +00:00
|
|
|
|
2006-07-04 19:36:19 +00:00
|
|
|
if (XGrabPointer(display(), rootWindow(), False,
|
2000-06-19 10:46:08 +00:00
|
|
|
ButtonPressMask | ButtonReleaseMask |
|
|
|
|
PointerMotionMask |
|
|
|
|
EnterWindowMask | LeaveWindowMask,
|
|
|
|
GrabModeAsync, GrabModeAsync, None,
|
2003-09-16 19:28:03 +00:00
|
|
|
kill_cursor, CurrentTime) == GrabSuccess)
|
|
|
|
{
|
2006-07-04 19:36:19 +00:00
|
|
|
XGrabKeyboard(display(), rootWindow(), False,
|
2003-09-16 19:28:03 +00:00
|
|
|
GrabModeAsync, GrabModeAsync, CurrentTime);
|
|
|
|
|
|
|
|
XEvent ev;
|
|
|
|
int return_pressed = 0;
|
|
|
|
int escape_pressed = 0;
|
|
|
|
int button_released = 0;
|
|
|
|
|
2003-12-04 13:54:10 +00:00
|
|
|
grabXServer();
|
2003-09-16 19:28:03 +00:00
|
|
|
|
|
|
|
while (!return_pressed && !escape_pressed && !button_released)
|
|
|
|
{
|
2006-07-04 19:36:19 +00:00
|
|
|
XMaskEvent(display(), KeyPressMask | ButtonPressMask |
|
2003-09-16 19:28:03 +00:00
|
|
|
ButtonReleaseMask | PointerMotionMask, &ev);
|
|
|
|
|
|
|
|
if (ev.type == KeyPress)
|
|
|
|
{
|
2006-07-04 19:36:19 +00:00
|
|
|
int kc = XKeycodeToKeysym(display(), ev.xkey.keycode, 0);
|
2003-09-16 19:28:03 +00:00
|
|
|
int mx = 0;
|
|
|
|
int my = 0;
|
|
|
|
return_pressed = (kc == XK_Return) || (kc == XK_space);
|
|
|
|
escape_pressed = (kc == XK_Escape);
|
|
|
|
if (kc == XK_Left) mx = -10;
|
|
|
|
if (kc == XK_Right) mx = 10;
|
|
|
|
if (kc == XK_Up) my = -10;
|
|
|
|
if (kc == XK_Down) my = 10;
|
|
|
|
if (ev.xkey.state & ControlMask)
|
|
|
|
{
|
|
|
|
mx /= 10;
|
|
|
|
my /= 10;
|
|
|
|
}
|
2007-01-15 12:19:44 +00:00
|
|
|
QCursor::setPos(QCursor::pos()+QPoint(mx, my));
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ev.type == ButtonRelease)
|
|
|
|
{
|
|
|
|
button_released = (ev.xbutton.button == Button1);
|
|
|
|
if ( ev.xbutton.button == Button3 )
|
|
|
|
{
|
2006-02-19 01:33:48 +00:00
|
|
|
escape_pressed = true;
|
2003-09-16 19:28:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-01-15 12:19:44 +00:00
|
|
|
if( ev.xbutton.button == Button1 || ev.xbutton.button == Button2 )
|
|
|
|
workspace->killWindowId(ev.xbutton.subwindow);
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (return_pressed)
|
|
|
|
{
|
2002-10-15 13:41:37 +00:00
|
|
|
Window root, child;
|
|
|
|
int dummy1, dummy2, dummy3, dummy4;
|
|
|
|
unsigned int dummy5;
|
2006-07-04 19:36:19 +00:00
|
|
|
if( XQueryPointer( display(), rootWindow(), &root, &child,
|
2002-10-15 13:41:37 +00:00
|
|
|
&dummy1, &dummy2, &dummy3, &dummy4, &dummy5 ) == true
|
|
|
|
&& child != None )
|
|
|
|
workspace->killWindowId( child );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2000-06-19 10:46:08 +00:00
|
|
|
|
2003-12-04 13:54:10 +00:00
|
|
|
ungrabXServer();
|
2000-06-19 10:46:08 +00:00
|
|
|
|
2006-07-04 19:36:19 +00:00
|
|
|
XUngrabKeyboard(display(), CurrentTime);
|
|
|
|
XUngrabPointer(display(), CurrentTime);
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
2000-06-19 10:46:08 +00:00
|
|
|
}
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
} // namespace
|