1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 1999, 2000 Matthias Ettrich <[email protected]>
Copyright (C) 2003 Lubos Lunak <[email protected]>
You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
******************************************************************/
#include "killwindow.h"
#include <tqcursor.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <X11/keysym.h>
#include <X11/keysymdef.h>
#include <X11/cursorfont.h>
namespace KWinInternal
{
KillWindow::KillWindow( Workspace* ws )
: workspace( ws )
{
}
KillWindow::~KillWindow()
{
}
void KillWindow::start()
{
static Cursor kill_cursor = 0;
if (!kill_cursor)
kill_cursor = XCreateFontCursor(tqt_xdisplay(), XC_pirate);
if (XGrabPointer(tqt_xdisplay(), tqt_xrootwin(), False,
ButtonPressMask | ButtonReleaseMask |
PointerMotionMask |
EnterWindowMask | LeaveWindowMask,
GrabModeAsync, GrabModeAsync, None,
kill_cursor, CurrentTime) == GrabSuccess)
{
XGrabKeyboard(tqt_xdisplay(), tqt_xrootwin(), False,
GrabModeAsync, GrabModeAsync, CurrentTime);
XEvent ev;
int return_pressed = 0;
int escape_pressed = 0;
int button_released = 0;
grabXServer();
while (!return_pressed && !escape_pressed && !button_released)
{
XMaskEvent(tqt_xdisplay(), KeyPressMask | ButtonPressMask |
ButtonReleaseMask | PointerMotionMask, &ev);
if (ev.type == KeyPress)
{
int kc = XkbKeycodeToKeysym(tqt_xdisplay(), ev.xkey.keycode, 0, 0);
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;
}
TQCursor::setPos(TQCursor::pos()+TQPoint(mx, my));
}
if (ev.type == ButtonRelease)
{
button_released = (ev.xbutton.button == Button1);
if ( ev.xbutton.button == Button3 )
{
escape_pressed = TRUE;
break;
}
if( ev.xbutton.button == Button1 || ev.xbutton.button == Button2 )
workspace->killWindowId(ev.xbutton.subwindow);
}
continue;
}
if (return_pressed)
{
Window root, child;
int dummy1, dummy2, dummy3, dummy4;
unsigned int dummy5;
if( XQueryPointer( tqt_xdisplay(), tqt_xrootwin(), &root, &child,
&dummy1, &dummy2, &dummy3, &dummy4, &dummy5 ) == true
&& child != None )
workspace->killWindowId( child );
}
ungrabXServer();
XUngrabKeyboard(tqt_xdisplay(), CurrentTime);
XUngrabPointer(tqt_xdisplay(), CurrentTime);
}
}
} // namespace
|